character.m

00001 /*
00002     toten
00003     Copyright (C) 2004,2005 Toten Developers
00004 
00005     Toten is the legal property of its developers, whose names are
00006     too numerous to list here.  Please refer to the COPYRIGHT file
00007     for the full text of this license and to the AUTHORS file for
00008     the complete list of developers.
00009 
00010     This program is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this program; if not, write to the Free Software
00022     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023 */
00024 
00025 #include "toten.h"
00026 
00027 @implementation TCharacterClass : TObject
00028 
00029 - init:(char *)name_race:(char *)name_class:(int)start_lvl:(int)start_hp_max:(int)start_str:(int)start_cons:
00030         (int)start_intel:(int)start_wis:(int)start_charisma:(int)start_dex:(int)start_speed:(int)lvl_exp_increment:
00031         (int)exp_increment:(float)exp_bonus:(float)hp_bonus:(float)str_bonus:(float)cons_bonus:(float)intel_bonus:
00032         (float)wis_bonus:(float)charisma_bonus:(float)dex_bonus:(float)speed_bonus:(int)hunger_speed:(int)thirst_speed
00033 {
00034         [super init];
00035         
00036         /* set all the variables appropriatly. */
00037 
00038         if(name_race) {
00039                 self->name_race = strdup(name_race);
00040         }
00041         else {
00042                 self->name_race = NULL;
00043         }
00044 
00045         if(name_class) {
00046                 self->name_class = strdup(name_class);
00047         }
00048         else {
00049                 self->name_class = NULL;
00050         }
00051 
00052         self->name_class = strdup(name_class);
00053         self->start_lvl = start_lvl;
00054         self->start_hp_max = start_hp_max;
00055         self->start_str = start_str;
00056         self->start_cons = start_cons;
00057         self->start_intel = start_intel;
00058         self->start_wis = start_wis;
00059         self->start_charisma = start_charisma;
00060         self->start_dex = start_dex;
00061         self->start_speed = start_speed;
00062         self->lvl_exp_increment = lvl_exp_increment;
00063         self->exp_increment = exp_increment;
00064         self->exp_bonus = exp_bonus;
00065         self->hp_bonus = hp_bonus;
00066         self->str_bonus = str_bonus;
00067         self->cons_bonus = cons_bonus;
00068         self->intel_bonus = intel_bonus;
00069         self->wis_bonus = wis_bonus;
00070         self->charisma_bonus = charisma_bonus;
00071         self->dex_bonus = dex_bonus;
00072         self->speed_bonus = speed_bonus;
00073         self->hunger_speed = hunger_speed;
00074         self->thirst_speed = thirst_speed;
00075 
00076 }
00077 
00078 - free
00079 {
00080         if(self->name_race)
00081                 free(self->name_race);
00082 
00083         if(self->name_class)
00084                 free(self->name_class);
00085 
00086         [super free];
00087 }
00088 
00089 - (void)setskillset:(TSkillSet *)skillset
00090 {
00091         self->skillset = [skillset deepCopy];   
00092 }
00093 
00094 @end
00095 
00096 @implementation TCharacter : TObject
00097 
00098 - init:(TCharacterClass *)charclass
00099 {
00100         [super init];
00101 
00102         if(charclass) { 
00103                 self->charclass = [charclass deepCopy];
00104                 
00105                 if(charclass->skillset)
00106                         self->skillset = [charclass->skillset deepCopy];        
00107         }
00108 }
00109 
00110 - free
00111 {
00112         if(self->charclass)
00113                 [self->charclass release];
00114 
00115         if(self->skillset)
00116                 [self->skillset release];       
00117         
00118         if(self->first_name)
00119                 free(self->first_name);
00120 
00121         if(self->last_name)
00122                 free(self->last_name);
00123 
00124         if(self->height_unit)
00125                 free(self->height_unit);
00126 
00127         if(self->weight_unit)
00128                 free(self->weight_unit);
00129 
00130         if(self->eye_color)
00131                 free(self->eye_color);
00132 
00133         if(self->hair_color)
00134                 free(self->hair_color);
00135 
00136         if(self->bio)
00137                 free(self->bio);
00138 }
00139 
00140 - (void)set_phys_properties:(char *)first_name:(char *)last_name:(unsigned int)height:(unsigned int)weight:
00141 (char *)height_unit:(char *)weight_unit:(char *)eye_color:(char *)hair_color:
00142                         (unsigned short int)sex: (char *)bio
00143 {
00144         if(first_name) {
00145                 self->first_name = strdup(first_name);
00146         }
00147         else {
00148                 self->first_name = NULL;
00149         }
00150 
00151         if(last_name) {
00152                 self->last_name = strdup(last_name);
00153         }
00154         else {
00155                 self->last_name = NULL;
00156         }
00157         
00158         self->height = height;
00159         self->weight = weight;
00160         
00161         if(height_unit) {
00162                 self->height_unit = strdup(height_unit);
00163         }
00164         else {
00165                 self->height_unit = NULL;
00166         }
00167 
00168         if(weight_unit) {
00169                 self->weight_unit = strdup(weight_unit);
00170         }
00171         else {
00172                 self->weight_unit = NULL;
00173         }
00174 
00175         if(eye_color) {
00176                 self->eye_color = strdup(eye_color);
00177         }
00178         else {
00179                 self->eye_color = NULL;
00180         }
00181 
00182         if(hair_color) {
00183                 self->hair_color = strdup(hair_color);
00184         }
00185         else {
00186                 self->hair_color = NULL;
00187         }
00188 
00189         self->sex = sex;
00190         
00191         if(bio) {
00192                 self->bio = strdup(bio);
00193         }
00194         else {
00195                 self->bio = NULL;
00196         }
00197 }
00198 
00199 - (int)gain_exp:(int)add_exp
00200 {
00201         self->exp += add_exp;
00202 
00203         if(self->exp >= self->charclass->lvl_exp_increment) {
00204                 [self lvl_up];
00205         }
00206 
00207         return self->exp;       
00208 }
00209 
00210 - (int)lvl_up
00211 {
00212         self->charclass->lvl_exp_increment += self->charclass->exp_increment + (self->charclass->exp_bonus * self->lvl);
00213         
00214         self->hp_max += self->charclass->hp_bonus * self->lvl;
00215         self->str += self->charclass->str_bonus * self->lvl;
00216         self->cons += self->charclass->cons_bonus * self->lvl;
00217         self->intel += self->charclass->intel_bonus * self->lvl;
00218         self->wis += self->charclass->wis_bonus * self->lvl;
00219         self->charisma += self->charclass->charisma_bonus * self->lvl;
00220         self->dex += self->charclass->dex_bonus * self->lvl;
00221         self->speed += self->charclass->speed_bonus * self->lvl;
00222         
00223         self->lvl++;
00224 }
00225 
00226 - (char *)get_first_name
00227 {
00228         return self->first_name;
00229 }
00230 
00231 - (char *)get_last_name
00232 {
00233         return self->last_name; 
00234 }
00235 
00236 - (char *)get_eye_color
00237 {
00238         return self->eye_color; 
00239 }
00240 
00241 - (char *)get_hair_color
00242 {
00243         return self->hair_color;
00244 }
00245 
00246 - (char *)get_bio
00247 {
00248         return self->bio;       
00249 }
00250 
00251 - (int)get_lvl
00252 {
00253         return self->lvl;
00254 }
00255 
00256 - (int)get_hp
00257 {
00258         return self->hp;
00259 }
00260 
00261 - (int)get_hp_max
00262 {
00263         return self->hp_max;
00264 }
00265 
00266 - (int)get_str
00267 {
00268         return self->str;
00269 }
00270 
00271 - (int)get_cons
00272 {
00273         return self->cons;
00274 }
00275 
00276 - (int)get_intel
00277 {
00278         return self->intel;
00279 }
00280 
00281 - (int)get_wis
00282 {
00283         return self->wis;
00284 }
00285 
00286 - (int)get_charisma
00287 {
00288         return self->charisma;
00289 }
00290 
00291 - (int)get_dex
00292 {
00293         return self->dex;       
00294 }
00295 
00296 - (int)get_speed
00297 {
00298         return self->speed;
00299 }
00300 
00301 - (int)get_exp
00302 {
00303         return self->exp;
00304 }
00305 
00306 
00307 - (void)set_hp:(int)hp
00308 {
00309         if(hp >= 0 && hp <= self->hp_max) {
00310                 self->hp = hp;
00311         }
00312 }
00313 
00314 - (TItem *)equip:(TItem *)item:(int)location /* returns what was previously there */
00315 {
00316 
00317 }
00318 
00319 - (TItem *)get_item_equipped_at_location:(int)location
00320 {
00321         
00322 }
00323 
00324 - (void)consume:(TConsumable *)consumable
00325 {
00326 }
00327 
00328 - (void)eat:(TFood *)food
00329 {
00330 }
00331 
00332 - (void)drink:(TDrink *)drink
00333 {
00334 }
00335 
00336 @end
00337 
00338 

Generated on Wed Dec 21 13:16:07 2005 for Toten by  doxygen 1.4.5 SourceForge.net Logo