-
Notifications
You must be signed in to change notification settings - Fork 4
/
item.h
224 lines (187 loc) · 5.23 KB
/
item.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifndef _ITEM_H_
#define _ITEM_H_
#define ITEM_INGREDIENT_NUM 4
#define RESEARCH_INGREDIENT_NUM 4
typedef enum {
ITT_EMPTY = -1,
ITT_ERROR = 0,
ITT_BEAMGUN1 = 1000,
ITT_BEAMGUN2 = 1001,
ITT_BEAMGUN3 = 1002,
ITT_BEAMGUN4 = 1003,
ITT_BLASTER = 1100,
ITT_HEAL_BLASTER = 1110,
ITT_DEBRIS_SOIL = 2000,
ITT_DEBRIS_ROCK = 2001,
ITT_DEBRIS_IRONORE = 2010,
ITT_DEBRIS_RAREMETALORE = 2020,
ITT_DEBRIS_HARDROCK = 2030,
// glossaries
ITT_APPLE = 3000,
ITT_ENERGY_PARTICE = 3005,
ITT_MICROBE = 3010,
ITT_WEED_SEED = 3020,
ITT_TREE_SEED = 3030,
ITT_ARTIFACT = 3100,
ITT_HYPER_PARTICLE = 3110,
ITT_DARK_MATTER_PARTICLE = 3120,
ITT_IRON_PLATE = 3200,
ITT_RAREMETAL_CRYSTAL = 3210,
ITT_BATTERY1 = 3300,
ITT_BATTERY2 = 3301,
ITT_SHIELD = 3400,
ITT_ACCELERATOR = 3500,
ITT_SHOVEL = 3600,
ITT_HP_POTION = 3700,
// put to use
ITT_BRICK_PANEL = 4000,
ITT_TURRET = 4040,
ITT_REACTOR = 4100,
ITT_POLE = 4110,
ITT_EXCHANGE = 4120,
ITT_CABLE = 4121,
ITT_PORTAL = 4122,
ITT_FENCE = 4130,
} ITEMTYPE;
class Ingredient {
public:
ITEMTYPE itt;
int n;
Ingredient() : itt(ITT_EMPTY), n(0) {}
};
class ItemConf {
public:
ITEMTYPE itt;
char name[32];
TileDeck *deck;
int index;
int stack_max;
bool puttable;
Ingredient ingredients[ITEM_INGREDIENT_NUM];
Ingredient research_ingredients[ITEM_INGREDIENT_NUM];
int required_ene;
int dur;
int level;
int is_beamgun;
int hp_recover_amount;
bool is_passive_mod;
ItemConf( ITEMTYPE itt, int lv, const char *nm, TileDeck *deck, int index, int stack_max, bool puttable ) : itt(itt), deck(deck),index(index), stack_max(stack_max), puttable(puttable), required_ene(0), dur(0), level(lv), is_beamgun(false), hp_recover_amount(0), is_passive_mod(false) {
snprintf(name,sizeof(name),"%s", nm );
}
ItemConf() : itt(ITT_ERROR){}
void addIngredient( ITEMTYPE itt, int n );
void addResearchIngredient( ITEMTYPE itt, int n );
static ItemConf *getItemConf( ITEMTYPE itt );
static ItemConf *getByIndex( int index );
static ItemConf *getCraftable( int ind );
static int countCraftable();
};
class ResearchIngredient : public Ingredient {
public:
int current;
ResearchIngredient() : Ingredient(), current(0) {}
};
class ResearchState {
public:
ITEMTYPE itt;
ResearchIngredient ingrs[4];
bool locked;
ResearchState() : itt(ITT_EMPTY), locked(true) {}
bool isComplete();
static void unlock( ITEMTYPE itt );
static ResearchState *getResearchState( ITEMTYPE itt );
static bool itemIsLocked( ITEMTYPE itt );
static void unlockAll();
static void resetAllProgress();
};
#define ITEM_CONF_NUM 128
extern ResearchState g_research_state[ITEM_CONF_NUM];
int getBeamgunEne( ItemConf *itc );
class ItemDump {
public:
int itt;
int num;
int dur;
};
void setupItemConf();
class Item {
public:
ITEMTYPE itt;
int num;
int dur;
ItemConf *conf;
Item(){init();}
void init(){ itt = ITT_EMPTY; num = 0; conf = NULL; }
void set( ITEMTYPE itt, int n, int dur ){
this->itt = itt;
this->num = n;
this->dur = dur;
this->conf = ItemConf::getItemConf(itt);
}
void set( ITEMTYPE itt, int n ) {
this->itt = itt;
this->num = n;
this->conf = ItemConf::getItemConf(itt);
this->dur = this->conf->dur;
}
bool isDamaged() {
if( conf->dur == 0 ) return false; else return ( conf->dur > dur );
}
bool isEmpty(){
return ( itt == ITT_EMPTY );
}
void setEmpty(){
itt = ITT_EMPTY;
num = 0;
conf = NULL;
}
void dec(int n){
assert( num>=n);
num -= n;
if(num==0){
itt = ITT_EMPTY;
conf = NULL;
}
}
int room() {
return conf->stack_max - num;
}
bool validate() {
bool ret;
if( itt == ITT_ERROR ) {
ret = false;
} else if( itt == ITT_EMPTY ) {
ret = ( num == 0 && (conf == NULL || conf->itt == ITT_EMPTY ) );
} else {
ret = ( num > 0 && conf != NULL );
}
if(!ret) print("Item::validate: fail. itt:%d num:%d dur:%d conf:%p(%d)", itt, num, dur, conf, conf ? conf->itt : 0 );
return ret;
}
void dump() {
print("itt:%d num:%d dur:%d conf:%p", itt, num, dur, conf );
}
};
ITEMTYPE blockTypeToItemId( BLOCKTYPE bt );
BLOCKTYPE itemIDToBlockType( ITEMTYPE itt );
class ItemOwner {
public:
Item *items;
int item_num;
int stack_multiply;
ItemOwner( int num, int stackmul );
int countItem(ITEMTYPE itt);
int findItemType(ITEMTYPE itt );
bool decItem(ITEMTYPE itt, int n );
bool incItem(ITEMTYPE itt, int n, int ofs_index, bool dry );
bool incItemIndex( int ind, ITEMTYPE itt, int n );
void dumpItem();
void decItemIndex( int index, int n );
void clearItemID(ITEMTYPE id);
void clearItems();
void swapItem( int from_index, int to_index );
bool stackItem( int from_index, int to_index );
bool merge( ItemOwner *to_merge );
virtual void onItemUpdated( int index ) {};
};
#endif