00001 /* 00002 * Copyright (C) 2004 emuWorks 00003 * http://games.technoplaza.net/ 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 // $Id: SaveSlot.hh,v 1.5 2004/12/05 02:59:28 technoplaza Exp $ 00021 00022 #ifndef _SAVE_SLOT_HH 00023 #define _SAVE_SLOT_HH 00024 00025 #include "../view/MainFrame.hh" 00026 00027 /// SRAM offset for the primary checksum 00028 #define CHECKSUM_OFFSET 0x00 00029 00030 /// SRAM offset for the moon phases 00031 #define MOON_OFFSET 0x01 00032 00033 /// SRAM offset for the hero's name 00034 #define NAME_OFFSET 0x02 00035 00036 /// Starting SRAM offset for virtues 00037 #define VIRTUE_OFFSET 0x0C 00038 00039 /// SRAM offset for partial avatarhoods 00040 #define AVATAR_OFFSET 0x14 00041 00042 /// Starting SRAM offset for the party members 00043 #define MEMBER_OFFSET 0x15 00044 00045 /// SRAM offset for Stones 00046 #define STONES_OFFSET 0x19 00047 00048 /// SRAM offset for Runes 00049 #define RUNES_OFFSET 0x1A 00050 00051 /// Starting SRAM offset for magic 00052 #define MAGIC_OFFSET 0x1B 00053 00054 /// Starting SRAM offset for herbs 00055 #define HERB_OFFSET 0x1F 00056 00057 /// SRAM offset for gold 00058 #define GOLD_OFFSET 0x27 00059 00060 /// Starting SRAM offset for tools 00061 #define TOOL_OFFSET 0x29 00062 00063 /// Starting SRAM offset for equipment 00064 #define EQUIPMENT_OFFSET 0x39 00065 00066 /// Starting SRAM offset for chracater levels 00067 #define LEVEL_OFFSET 0x69 00068 00069 /// Starting SRAM offset for chracater current HP 00070 #define CURRENT_HP_OFFSET 0x71 00071 00072 /// Starting SRAM offset for chracater max HP 00073 #define MAX_HP_OFFSET 0x81 00074 00075 /// Starting SRAM offset for chracater current MP 00076 #define CURRENT_MP_OFFSET 0x91 00077 00078 /// Starting SRAM offset for chracater max MP 00079 #define MAX_MP_OFFSET 0x99 00080 00081 /// Starting SRAM offset for chracater strength 00082 #define STRENGTH_OFFSET 0xA1 00083 00084 /// Starting SRAM offset for chracater intelligence 00085 #define INTELLIGENCE_OFFSET 0xA9 00086 00087 /// Starting SRAM offset for chracater dexterity 00088 #define DEXTERITY_OFFSET 0xB1 00089 00090 /// Starting SRAM offset for chracater experience 00091 #define EXPERIENCE_OFFSET 0xB9 00092 00093 namespace hack4u { 00094 /// The two moons of Ultima 00095 enum Moons {TRAMMEL, FELUCCA}; 00096 00097 /// The eight cities of virtue 00098 enum City {MOONGLOW, BRITAIN, JHELOM, YEW, 00099 MINOC, TRINSIC, SKARABRAE, MAGINCIA}; 00100 00101 /// The eight virtues 00102 enum Virtues {HONESTY, COMPASSION, VALOR, JUSTICE, 00103 SACRIFICE, HONOR, SPIRITUALITY, HUMILITY}; 00104 00105 /// The eight characters 00106 enum Characters {MAGE, BARD, FIGHTER, DRUID, 00107 TINKER, PALADIN, RANGER, SHEPHERD}; 00108 00109 /// The possible magic in the game 00110 enum Magic {LIGHT, MISSILE, AWAKEN, CURE, WIND, HEAL, FIRE, EXIT, DISPEL, 00111 VIEW, PROTECT, ICE, BLINK, ENERGY, QUICK, INVALID1, SLEEP, 00112 REFLECT, NEGATE, INVALID2, DESTROY, JINX, SQUISH, GATE, 00113 TREMOR, LIFE, INVALID3, DEFEAT}; 00114 00115 /// The eight herbs (reagents) 00116 enum Herbs {ASH, GINSENG, GARLIC, SILKWEB, MOSS, PEARL, FUNGUS, MANROOT}; 00117 00118 /// The tools 00119 enum Tools {TORCH, GEM, KEY, OIL, SEXTANT, SCALE, FLUTE, CANDLE, BOOK, 00120 BELL, WHEEL, HORN, SKULL, TRUTHKEY, COURAGEKEY, LOVEKEY}; 00121 00122 class MainFrame; 00123 00124 /** 00125 * A class representing a single game save slot. 00126 */ 00127 class SaveSlot { 00128 public: 00129 /** 00130 * Constructor for a SaveSlot. 00131 * 00132 * @param data The SRAM data 00133 */ 00134 SaveSlot(const unsigned char *data); 00135 00136 /** 00137 * Destructor for a SaveSlot. 00138 */ 00139 ~SaveSlot(); 00140 00141 /** 00142 * Generates the checksum for the current data. 00143 * 00144 * @return The checksum. 00145 */ 00146 unsigned char checksum() const; 00147 00148 /** 00149 * Queries if this save slot is valid. Initially determined by 00150 * generating a checksum on the provided data and checking it against 00151 * the contained checksum, just like the real game. 00152 * 00153 * @return true if valid; false otherwise. 00154 */ 00155 bool isValid() const { return valid; } 00156 00157 /** 00158 * Queries if this SaveSlot has been modified. 00159 * 00160 * @return true if modified; false otherwise. 00161 */ 00162 bool isModified() const { return modified; } 00163 00164 /** 00165 * Gets the current phase of one of the moons. Valid values are either 00166 * TRAMMEL or FELUCCA. 00167 * 00168 * @param moon The moon whose phase to return. 00169 * 00170 * @return The phase of the moon. Note that felucca's phase depends upon 00171 * trammel's phase and can be only 0, 1, or 2 representing one 00172 * of the three destination cities. Trammel's phase will always 00173 * be one of the eight cities of virtue. 00174 */ 00175 int getPhase(int moon) const; 00176 00177 /** 00178 * Sets the phases of the moons. 00179 * 00180 * @param trammel The phase for trammel. Must be one of the eight cities 00181 * of virtue. 00182 * @param felucca The phase for felucca. Must be 0, 1, or 2 representing 00183 * one of the three destination cities from Trammel. 00184 */ 00185 void setPhase(int trammel, int felucca); 00186 00187 /** 00188 * Gets the Hero's Name. 00189 * 00190 * @return wxString with the name of the Hero translated to a proper 00191 * PC alphabet. 00192 */ 00193 wxString getHerosName() const; 00194 00195 /** 00196 * Sets the Hero's Name. 00197 * 00198 * @param name The new name of the hero. Valid values must not exceed 5 00199 * characters. Excess lengths will be ignored. 00200 */ 00201 void setHerosName(wxString &name); 00202 00203 /** 00204 * Gets the value for one of the eight virtues. 00205 * 00206 * @param virtue The virtue whose value to retrieve. Must be one of the 00207 * eight virtues in the Virtues enumeration. 00208 * 00209 * @return The value for the particular virtue. 00210 */ 00211 int getVirtue(int virtue) const; 00212 00213 /** 00214 * Sets the value for one of the eight virtues. 00215 * 00216 * @param virtue The virtue to set. Must be one of the eight virtues in 00217 * the Virtues enumeration. 00218 * @param value The new value for the virtue. 00219 */ 00220 void setVirtue(int virtue, unsigned char value); 00221 00222 /** 00223 * Gets the party member at a given position. 00224 * 00225 * @param position The party position number (0-3). 00226 * 00227 * @return The character at that position. Return values range between 00228 * 0 and 1 + one of the character values in the Characters 00229 * enumeration. 1 = Mage, 8 = Shepherd, 0 = No one. 00230 */ 00231 int getMember(int position) const; 00232 00233 /** 00234 * Sets the party member at a given position. 00235 * 00236 * @param position The party position number (0-3). 00237 * @param character What character class should be here, or 0 for no 00238 * one. Use the Characters enumeration + 1 for proper 00239 * character values (e.g. MAGE + 1). 00240 */ 00241 void setMember(int position, int character); 00242 00243 /** 00244 * Queries if the party has a particular stone in their inventory. 00245 * 00246 * @param stone The stone to check for. Valid values are one of the 00247 * eight virtues in the Virtues enumeration. 00248 * 00249 * @return true if they have the stone; false otherwise. 00250 */ 00251 bool hasStone(int stone) const; 00252 00253 /** 00254 * Sets whether the party has a particular stone or not. 00255 * 00256 * @param stone The stone. Valid values are one of the eight virtues in 00257 * the Virtues enumeration. 00258 * @param give true to give the stone; false to take it away. 00259 */ 00260 void setStone(int stone, bool give = true); 00261 00262 /** 00263 * Queries whether the party has a particular rune or not. 00264 * 00265 * @param rune The rune. Valid values are one of the eight virtues in 00266 * the Virtues enumeration. 00267 * 00268 * @return true if they have the rune; false otherwise. 00269 */ 00270 bool hasRune(int rune) const; 00271 00272 /** 00273 * Sets whether the party has a particular rune of not. 00274 * 00275 * @param rune The rune. Valid values are one of the eight virtues in 00276 * the Virtues enumeration. 00277 * @param give true to give the rune; false to take it away. 00278 */ 00279 void setRune(int rune, bool give = true); 00280 00281 /** 00282 * Queries whether the party has a particular magic or not. 00283 */ 00284 bool hasMagic(int magic) const; 00285 00286 /** 00287 * Sets whether the party has a particular magic of not. 00288 * 00289 * @param magic The magic. Valid values are any of the members in the 00290 * Magic enumeration other than INVALID. 00291 * @param give true to give the magic; false to take it away. 00292 */ 00293 void setMagic(int magic, bool give = true); 00294 00295 /** 00296 * Gets the current amount of a particular herb the party has. 00297 * 00298 * @param herb The herb whose value to get. Valid values are any of the 00299 * members of the Herbs enumeration. 00300 * 00301 * @return The amount of the particular herb the party has. 00302 */ 00303 int getHerb(int herb) const; 00304 00305 /** 00306 * Sets the amount of a particular herb the party has. 00307 * 00308 * @param herb The herb whose value to set. Valid values are any of the 00309 * members of the Herbs enumeration. 00310 * @param value The new value. 00311 */ 00312 void setHerb(int herb, unsigned char value); 00313 00314 /** 00315 * Gets the amount of gold held by the party. 00316 * 00317 * @return The amount of gold. 00318 */ 00319 wxInt16 getGold() const; 00320 00321 /** 00322 * Sets the amount of gold held by the party. 00323 * 00324 * @param gold The new amount of gold. 00325 */ 00326 void setGold(wxInt16 gold); 00327 00328 /** 00329 * Gets the amount of a tool the party has. 00330 * 00331 * @param tool The tool to get the amount of. 00332 * 00333 * @return The amount of the particular tool. 00334 */ 00335 int getTool(int tool) const; 00336 00337 /** 00338 * Sets the amount of a tool the party has. 00339 * 00340 * @param tool The tool to set the amount of. 00341 * @param value The new amount. 00342 */ 00343 void setTool(int tool, unsigned char value = 1); 00344 00345 /** 00346 * Gets the item held by a particular player in a particular slot. 00347 * 00348 * @param character The character whose equipment to get. Valid values 00349 * are in the Character enumeration. 00350 * @param slot The inventory slot (0-5). 00351 * 00352 * @return The equipment item. 00353 */ 00354 int getEquipment(int character, int slot) const; 00355 00356 /** 00357 * Sets the item held by a particular player in a particular slot. 00358 * 00359 * @param character The character whose equipment to set. Valid values 00360 * are in the Character enumeration. 00361 * @param slot The inventory slot (0-5). 00362 * @param value The new item value. 00363 */ 00364 void setEquipment(int character, int slot, unsigned char value); 00365 00366 /** 00367 * Gets the level of a character. 00368 * 00369 * @param character The character. Valid values are in the Character 00370 * enumeration. 00371 * 00372 * @return The character's level. 00373 */ 00374 int getLevel(int character) const; 00375 00376 /** 00377 * Sets the level of a character. 00378 * 00379 * @param character The character. Valid values are in the Character 00380 * enumeration. 00381 * @param value The new level. 00382 */ 00383 void setLevel(int character, unsigned char value); 00384 00385 /** 00386 * Gets the current HP of a character. 00387 * 00388 * @param character The character. Valid values are in the Character 00389 * enumeration. 00390 * 00391 * @return The current HP. 00392 */ 00393 wxInt16 getCurrentHP(int character) const; 00394 00395 /** 00396 * Sets the current HP of a character. 00397 * 00398 * @param character The character. Valid values are in the Character 00399 * enumeration. 00400 * @param value The new current HP. 00401 */ 00402 void setCurrentHP(int character, wxInt16 value); 00403 00404 /** 00405 * Gets the max HP of a character. 00406 * 00407 * @param character The character. Valid values are in the Character 00408 * enumeration. 00409 * 00410 * @return The Max HP. 00411 */ 00412 wxInt16 getMaxHP(int character) const; 00413 00414 /** 00415 * Sets the max HP of a character. 00416 * 00417 * @param character The character. Valid values are in the Character 00418 * enumeration. 00419 * @param value The new max HP. 00420 */ 00421 void setMaxHP(int character, wxInt16 value); 00422 00423 /** 00424 * Gets the current MP of a character. 00425 * 00426 * @param character The character. Valid values are in the Character 00427 * enumeration. 00428 * 00429 * @return The current MP. 00430 */ 00431 int getCurrentMP(int character) const; 00432 00433 /** 00434 * Sets the current MP of a character. 00435 * 00436 * @param character The character. Valid values are in the Character 00437 * enumeration. 00438 * @param value The new current MP. 00439 */ 00440 void setCurrentMP(int character, unsigned char value); 00441 00442 /** 00443 * Gets the max MP of a character. 00444 * 00445 * @param character The character. Valid values are in the Character 00446 * enumeration. 00447 * 00448 * @return The max MP. 00449 */ 00450 int getMaxMP(int character) const; 00451 00452 /** 00453 * Sets the max MP of a charcter. 00454 * 00455 * @param character The character. Valid values are in the Character 00456 * enumeration. 00457 * @param value The new max MP. 00458 */ 00459 void setMaxMP(int character, unsigned char value); 00460 00461 /** 00462 * Gets the strength of a character. 00463 * 00464 * @param character The character. Valid values are in the Character 00465 * enumeration. 00466 * 00467 * @return The strength. 00468 */ 00469 int getStrength(int character) const; 00470 00471 /** 00472 * Sets the strength of a charater. 00473 * 00474 * @param character The character. Valid values are in the Character 00475 * enumeration. 00476 * @param value The new strength. 00477 */ 00478 void setStrength(int character, unsigned char value); 00479 00480 /** 00481 * Gets the intelligence of a character. 00482 * 00483 * @param character The character. Valid values are in the Character 00484 * enumeration. 00485 * 00486 * @return The intelligence. 00487 */ 00488 int getIntelligence(int character) const; 00489 00490 /** 00491 * Sets the intelligence of a character. 00492 * 00493 * @param character The character. Valid values are in the Character 00494 * enumeration. 00495 * @param value The new intelligence. 00496 */ 00497 void setIntelligence(int character, unsigned char value); 00498 00499 /** 00500 * Gets the dexterity of a character. 00501 * 00502 * @param character The character. Valid values are in the Character 00503 * enumeration. 00504 * 00505 * @return The dexterity. 00506 */ 00507 int getDexterity(int character) const; 00508 00509 /** 00510 * Sets the dexterity of a character. 00511 * 00512 * @param character The character. Valid values are in the Character 00513 * enumeration. 00514 * @param value The new dexterity. 00515 */ 00516 void setDexterity(int character, unsigned char value); 00517 00518 /** 00519 * Gets the experience of a character. 00520 * 00521 * @param character The character. Valid values are in the Character 00522 * enumeration. 00523 * 00524 * @return The experience. 00525 */ 00526 wxInt16 getExperience(int character) const; 00527 00528 /** 00529 * Sets the experience of a character. 00530 * 00531 * @param character The character. Valid values are in the Character 00532 * enumeration. 00533 * @param value The new experience. 00534 */ 00535 void setExperience(int character, wxInt16 value); 00536 00537 friend class MainFrame; 00538 private: 00539 /** 00540 * Sets whether this slot is modified or not. 00541 * 00542 * @param modified true if modified; false otherwise. 00543 */ 00544 void setModified(bool modified = true); 00545 00546 /** 00547 * Translates an ASCII character to the Ultima alphabet. 00548 * 00549 * @param letter The letter to translate. 00550 * 00551 * @return The translated character. 00552 */ 00553 static unsigned char toNES(char letter); 00554 00555 /** 00556 * Translates an Ultima alphabet character to ASCII. 00557 * 00558 * @param letter The letter to translate. 00559 * 00560 * @return The translated character. 00561 */ 00562 static char fromNES(unsigned char letter); 00563 00564 unsigned char *nvram; 00565 bool valid; 00566 bool modified; 00567 00568 /// Array of checksum xors used by the sanity algorithm. 00569 static const int CHECKSUM_XORS[]; 00570 }; 00571 } 00572 00573 #endif 00574