forked from opentibia/yatc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.h
174 lines (151 loc) · 3.9 KB
/
objects.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __OBJECTS_H
#define __OBJECTS_H
#include <stdlib.h>
#include <stdio.h>
#include "stdinttypes.h"
#include <string.h>
#include <vector>
template<typename A>
class Array{
public:
Array(uint32_t n){
m_data = (A*)malloc(sizeof(A)*n);
memset(m_data, 0, sizeof(A)*n);
m_size = n;
};
~Array(){
free(m_data);
};
A getElement(uint32_t id){
if(id < m_size){
return m_data[id];
}
else{
return 0;
}
};
void addElement(A a, uint32_t pos){
#define INCREASE 1024
if(pos >= m_size){
m_data = (A*)realloc(m_data, sizeof(A)*(pos + INCREASE));
memset(m_data + m_size, 0, sizeof(A)*(pos + INCREASE - m_size));
m_size = pos + INCREASE;
}
m_data[pos] = a;
};
uint32_t size(){return m_size;}
private:
A* m_data;
uint32_t m_size;
};
class Sprite;
class ObjectType
{
public:
ObjectType(uint16_t _id);
~ObjectType();
// item only functions (perhaps later they will apply for effects too)
void loadGfx();
void unloadGfx();
bool isGfxLoaded() const;
const std::vector<Sprite*>& getGfx() const;
int instancesOnMap; // how many times itemUI for this one was spawned
uint16_t id;
bool ground;
uint16_t speed;
uint16_t alwaysOnTopOrder;
bool alwaysOnTop;
bool container;
bool stackable;
bool useable;
bool rune;
bool readable;
bool writeable;
bool fluidContainer;
bool splash;
bool blockSolid;
bool moveable;
bool blockProjectile;
bool blockPathFind;
bool pickupable;
bool isHangable;
bool isHorizontal;
bool isVertical;
bool rotatable;
bool idleAnim;
//items with 0x06 property
bool alwaysUsed;
uint16_t lightLevel;
uint16_t lightColor;
uint16_t xOffset;
uint16_t yOffset;
bool hasHeight;
uint16_t mapColor;
bool lookThrough;
uint16_t width;
uint16_t height;
uint16_t rendersize;
uint16_t blendframes;
uint16_t xdiv;
uint16_t ydiv;
uint16_t zdiv;
uint16_t animcount;
uint16_t numsprites;
uint16_t* imageData;
static uint16_t minItemId;
static uint16_t maxItemId;
static uint16_t minOutfitId;
static uint16_t maxOutfitId;
static uint16_t minEffectId;
static uint16_t maxEffectId;
static uint16_t minDistanceId;
static uint16_t maxDistanceId;
private:
std::vector<Sprite*> m_gfx;
};
class Objects
{
public:
Objects();
~Objects();
static Objects* getInstance();
static void destroyInstance() { delete m_instance; m_instance = NULL; }
bool unloadDat();
void unloadGfx();
bool loadDat(const char* filename);
ObjectType* getItemType(uint16_t id);
ObjectType* getOutfitType(uint16_t id);
ObjectType* getEffectType(uint16_t id);
ObjectType* getDistanceType(uint16_t id);
bool isLoaded() { return m_datLoaded; }
protected:
bool load780plus(const char* filename);
bool load76_77series(const char* filename);
bool load74_75series(const char* filename);
bool m_datLoaded;
static Objects* m_instance;
Array<ObjectType*> m_item;
Array<ObjectType*> m_outfit;
Array<ObjectType*> m_effect;
Array<ObjectType*> m_distance;
};
#endif