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