00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "toten.h"
00026
00027 @implementation TItem : TObject
00028
00029 - init:(int)level:(int)hp_max:(int)price:(int)weight:(char *)weight_unit:(char *)name:(char *)desc
00030 {
00031 [super init];
00032
00033 if(level > 0) {
00034 self->lvl = level;
00035 }
00036
00037 if(hp_max > 0) {
00038 self->hp_max = hp_max;
00039 self->hp = self->hp_max;
00040 }
00041
00042 if(price >= 0) {
00043 self->price = price;
00044 }
00045
00046 if(weight >= 0) {
00047 self->weight = weight;
00048 }
00049
00050 if(weight_unit) {
00051 self->weight_unit = strdup(weight_unit);
00052 }
00053 else {
00054 self->weight_unit = NULL;
00055 }
00056
00057 if(name) {
00058 self->name = strdup(name);
00059 }
00060 else {
00061 self->name = NULL;
00062 }
00063
00064 if(desc) {
00065 self->desc = strdup(desc);
00066 }
00067 else {
00068 self->desc = NULL;
00069 }
00070
00071 }
00072
00073 - free
00074 {
00075 if(self->weight_unit)
00076 free(self->weight_unit);
00077
00078 if(self->name)
00079 free(self->name);
00080
00081 if(self->desc)
00082 free(self->desc);
00083 }
00084
00085 - (int)get_lvl
00086 {
00087 return self->lvl;
00088 }
00089
00090 - (char *)get_name
00091 {
00092 return self->name;
00093 }
00094
00095 - (int)get_hp
00096 {
00097 return self->hp;
00098 }
00099
00100 - (int)get_hp_max
00101 {
00102 return self->hp_max;
00103 }
00104
00105 - (char *)get_description
00106 {
00107 return self->desc;
00108 }
00109
00110 - (int)get_price
00111 {
00112 return self->price;
00113 }
00114
00115 - (int)get_weight
00116 {
00117 return self->weight;
00118 }
00119
00120 - (char *)get_weight_unit
00121 {
00122 return self->weight_unit;
00123 }
00124
00125 - (void)set_properties:(int)hp:(int)price
00126 {
00127 if(hp > 0 && hp <= self->hp_max) {
00128 self->hp = hp;
00129 }
00130
00131 if(price >= 0) {
00132 self->price = price;
00133 }
00134 }
00135
00136 - (void)set_description:(char *)description
00137 {
00138 if(description) {
00139 self->desc = strdup(description);
00140 }
00141 }
00142
00143 - (void)set_equipable_locations:(int *)locations:(int)len
00144 {
00145 if(self->equipable_locations) {
00146 free(self->equipable_locations);
00147 self->len = 0;
00148 }
00149
00150 if(locations) {
00151 self->len = len;
00152 memcpy(self->equipable_locations,locations,len);
00153 }
00154 }
00155
00156 @end
00157
00158 @implementation TConsumable : TItem
00159
00160 - init:(int)level:(int)hp:(int)price:(int)weight:(char *)weight_units:(char *)name:(char *)desc:(int)lvl_mod:
00161 (int)hp_mod:(int)str_mod:(int)cons_mod:(int)intel_mod:(int)wis_mod:(int)charisma_mod:(int)dex_mod:(int)speed_mod:(int)exp_mod
00162 {
00163
00164 [super init:level:hp:price:weight:weight_unit:name:desc];
00165
00166 self->lvl_mod = lvl_mod;
00167 self->hp_mod = hp_mod;
00168 self->str_mod = str_mod;
00169 self->cons_mod = cons_mod;
00170 self->intel_mod = intel_mod;
00171 self->wis_mod = wis_mod;
00172 self->charisma_mod = charisma_mod;
00173 self->dex_mod = dex_mod;
00174 self->speed_mod = speed_mod;
00175
00176
00177 if(exp_mod >= 0) {
00178 self->exp_mod = exp_mod;
00179 }
00180 else {
00181 self->exp_mod = 0;
00182 }
00183 }
00184
00185 - free
00186 {
00187 [super free];
00188 }
00189
00190 - (int)get_lvl_mod
00191 {
00192 return self->lvl_mod;
00193 }
00194
00195 - (int)get_hp_mod
00196 {
00197 return self->hp_mod;
00198 }
00199
00200 - (int)get_str_mod
00201 {
00202 return self->str_mod;
00203 }
00204
00205 - (int)get_cons_mod
00206 {
00207 return self->cons_mod;
00208 }
00209
00210 - (int)get_intel_mod
00211 {
00212 return self->intel_mod;
00213 }
00214
00215 - (int)get_wis_mod
00216 {
00217 return self->wis_mod;
00218 }
00219
00220 - (int)get_charisma_mod
00221 {
00222 return self->charisma_mod;
00223 }
00224
00225 - (int)get_dex_mod
00226 {
00227 return self->dex_mod;
00228 }
00229
00230 - (int)get_speed_mod
00231 {
00232 return self->speed_mod;
00233 }
00234
00235 - (int)get_exp_mod
00236 {
00237 return self->exp_mod;
00238 }
00239
00240 @end
00241
00242 @implementation TFood : TConsumable
00243
00244 - init:(int)level:(int)hp:(int)price:(int)weight:(char *)weight_units:(char *)name:(char *)desc:(int)lvl_mod:
00245 (int)hp_mod:(int)str_mod:(int)cons_mod:(int)intel_mod:(int)wis_mod:(int)charisma_mod:(int)dex_mod:(int)speed_mod:
00246 (int)exp_mod:(int)hunger_mod
00247 {
00248 [super init:level:hp:price:weight:weight_units:name:desc:lvl_mod:hp_mod:str_mod:cons_mod:intel_mod:wis_mod:charisma_mod:dex_mod:speed_mod:exp_mod];
00249
00250 self->hunger_mod = hunger_mod;
00251 }
00252
00253 - free
00254 {
00255 [super free];
00256 }
00257
00258 - (int)get_hunger_mod
00259 {
00260 return hunger_mod;
00261 }
00262
00263 @end
00264
00265 @implementation TDrug : TFood
00266
00267 - init:(int)level:(int)hp:(int)price:(int)weight:(char *)weight_units:(char *)name:(char *)desc:(int)lvl_mod:
00268 (int)hp_mod:(int)str_mod:(int)cons_mod:(int)intel_mod:(int)wis_mod:(int)charisma_mod:(int)dex_mod:(int)speed_mod:
00269 (int)exp_mod:(int)effect_timeout
00270 {
00271 [super init:level:hp:price:weight:weight_units:name:desc:lvl_mod:hp_mod:str_mod:cons_mod:intel_mod:wis_mod:charisma_mod:dex_mod:speed_mod:exp_mod];
00272
00273 if(effect_timeout > 0) {
00274 self->effect_timeout = effect_timeout;
00275 }
00276 else {
00277 self->effect_timeout = 1;
00278 }
00279 }
00280
00281 - free
00282 {
00283 [super free];
00284 }
00285
00286 - (int)get_effect_timeout
00287 {
00288 return self->effect_timeout;
00289 }
00290
00291 @end
00292
00293 @implementation TDrink : TConsumable
00294
00295 - init:(int)level:(int)hp:(int)price:(int)weight:(char *)weight_units:(char *)name:(char *)desc:(int)lvl_mod:
00296 (int)hp_mod:(int)str_mod:(int)cons_mod:(int)intel_mod:(int)wis_mod:(int)charisma_mod:(int)dex_mod:(int)speed_mod:
00297 (int)exp_mod:(int)thirst_mod
00298 {
00299 [super init:level:hp:price:weight:weight_units:name:desc:lvl_mod:hp_mod:str_mod:cons_mod:intel_mod:wis_mod:charisma_mod:dex_mod:speed_mod:exp_mod];
00300
00301 self->thirst_mod = thirst_mod;
00302
00303 }
00304
00305 - free
00306 {
00307 [super free];
00308 }
00309
00310 - (int)get_thirst_mod
00311 {
00312 return self->thirst_mod;
00313 }
00314
00315 @end
00316
00317 @implementation TAlcohol : TDrink
00318
00319 - init:(int)level:(int)hp:(int)price:(int)weight:(char *)weight_units:(char *)name:(char *)desc:(int)lvl_mod:
00320 (int)hp_mod:(int)str_mod:(int)cons_mod:(int)intel_mod:(int)wis_mod:(int)charisma_mod:(int)dex_mod:(int)speed_mod:
00321 (int)exp_mod:(int)effect_timeout
00322 {
00323 [super init:level:hp:price:weight:weight_units:name:desc:lvl_mod:hp_mod:str_mod:cons_mod:intel_mod:wis_mod:charisma_mod:dex_mod:speed_mod:exp_mod];
00324
00325 if(effect_timeout > 0) {
00326 self->effect_timeout = effect_timeout;
00327 }
00328 else {
00329 self->effect_timeout = 1;
00330 }
00331
00332 }
00333
00334 - free
00335 {
00336 [super free];
00337 }
00338
00339 - (int)get_effect_timeout
00340 {
00341 return self->effect_timeout;
00342 }
00343
00344 @end
00345