00001 /* 00002 * hack4u 00003 * Copyright (C) 2004-2006 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.17 2006/03/21 12:00:18 technoplaza Exp $ 00024 00025 #ifndef _SAVESLOT_HH 00026 #define _SAVESLOT_HH 00027 00028 #include <utility> 00029 00030 #include <wx/string.h> 00031 00032 #include "model/SRAMFile.hh" 00033 00034 namespace hack4u { 00035 /** 00036 * A class representing a single game save slot. 00037 */ 00038 class SaveSlot { 00039 friend void SRAMFile::save(const wxString &); 00040 00041 private: 00042 unsigned char *nvram; 00043 bool modified; 00044 00045 /// Array of checksum xors used by the sanity algorithm. 00046 static const int CHECKSUM_XORS[]; 00047 00048 /** 00049 * Sets whether this slot is modified or not. 00050 * 00051 * @param modified true if modified; false otherwise. 00052 */ 00053 void setModified(bool modified = true); 00054 00055 /** 00056 * Translates an Ultima alphabet character to ASCII. 00057 * 00058 * @param letter The letter to translate. 00059 * 00060 * @return The translated character. 00061 */ 00062 static char fromNES(unsigned char letter); 00063 00064 /** 00065 * Translates an ASCII character to the Ultima alphabet. 00066 * 00067 * @param letter The letter to translate. 00068 * 00069 * @return The translated character. 00070 */ 00071 static unsigned char toNES(char letter); 00072 00073 public: 00074 /** 00075 * Constructor for a SaveSlot. 00076 * 00077 * @param data The SRAM data 00078 */ 00079 SaveSlot(const char *data); 00080 00081 /** 00082 * Destructor for a SaveSlot. 00083 */ 00084 ~SaveSlot(); 00085 00086 /** 00087 * Gets the location of the Balloon. 00088 * 00089 * @return The Balloon's location (latitude, longitude). 00090 */ 00091 std::pair<int, int> getBalloonLocation() const; 00092 00093 /** 00094 * Sets the baloon's location. 00095 * 00096 * @param location The new location (latitude, longitude). 00097 */ 00098 void setBalloonLocation(std::pair<int, int> location); 00099 00100 /** 00101 * Gets the current HP of a character. 00102 * 00103 * @param character The character. 00104 * 00105 * @return The current HP. 00106 */ 00107 wxInt16 getCurrentHP(enum Character character) const; 00108 00109 /** 00110 * Sets the current HP of a character. 00111 * 00112 * @param character The character. 00113 * @param value The new current HP. 00114 */ 00115 void setCurrentHP(enum Character character, wxInt16 value); 00116 00117 /** 00118 * Gets the current MP of a character. 00119 * 00120 * @param character The character. 00121 * 00122 * @return The current MP. 00123 */ 00124 int getCurrentMP(enum Character character) const; 00125 00126 /** 00127 * Sets the current MP of a character. 00128 * 00129 * @param character The character. 00130 * @param value The new current MP. 00131 */ 00132 void setCurrentMP(enum Character character, unsigned char value); 00133 00134 /** 00135 * Gets the dexterity of a character. 00136 * 00137 * @param character The character. 00138 * 00139 * @return The dexterity. 00140 */ 00141 int getDexterity(enum Character character) const; 00142 00143 /** 00144 * Sets the dexterity of a character. 00145 * 00146 * @param character The character. 00147 * @param value The new dexterity. 00148 */ 00149 void setDexterity(enum Character character, unsigned char value); 00150 00151 /** 00152 * Gets the item held by a particular player in a particular slot. 00153 * 00154 * @param character The character whose equipment to get. 00155 * @param slot The inventory slot (0-5). 00156 * 00157 * @return The equipment item. 00158 */ 00159 int getEquipment(enum Character character, int slot) const; 00160 00161 /** 00162 * Sets the item held by a particular player in a particular slot. 00163 * 00164 * @param character The character whose equipment to set. 00165 * @param slot The inventory slot (0-5). 00166 * @param value The new item value. 00167 */ 00168 void setEquipment(enum Character character, 00169 int slot, unsigned char value); 00170 00171 /** 00172 * Gets the experience of a character. 00173 * 00174 * @param character The character. 00175 * 00176 * @return The experience. 00177 */ 00178 wxInt16 getExperience(enum Character character) const; 00179 00180 /** 00181 * Sets the experience of a character. 00182 * 00183 * @param character The character. 00184 * @param value The new experience. 00185 */ 00186 void setExperience(enum Character character, wxInt16 value); 00187 00188 /** 00189 * Gets the amount of gold held by the party. 00190 * 00191 * @return The amount of gold. 00192 */ 00193 wxInt16 getGold() const; 00194 00195 /** 00196 * Sets the amount of gold held by the party. 00197 * 00198 * @param gold The new amount of gold. 00199 */ 00200 void setGold(wxInt16 gold); 00201 00202 /** 00203 * Gets the current amount of a particular herb the party has. 00204 * 00205 * @param herb The herb whose value to get. 00206 * 00207 * @return The amount of the particular herb the party has. 00208 */ 00209 int getHerb(enum Herb herb) const; 00210 00211 /** 00212 * Sets the amount of a particular herb the party has. 00213 * 00214 * @param herb The herb whose value to set. 00215 * @param value The new value. 00216 */ 00217 void setHerb(enum Herb herb, unsigned char value); 00218 00219 /** 00220 * Gets the Hero's Name. 00221 * 00222 * @return wxString with the name of the Hero translated to a proper 00223 * PC alphabet. 00224 */ 00225 wxString getHerosName() const; 00226 00227 /** 00228 * Sets the Hero's Name. 00229 * 00230 * @param name The new name of the hero. Valid values must not exceed 5 00231 * characters. Excess lengths will be ignored. 00232 */ 00233 void setHerosName(const wxString &name); 00234 00235 /** 00236 * Gets the intelligence of a character. 00237 * 00238 * @param character The character. 00239 * 00240 * @return The intelligence. 00241 */ 00242 int getIntelligence(enum Character character) const; 00243 00244 /** 00245 * Sets the intelligence of a character. 00246 * 00247 * @param character The character. 00248 * @param value The new intelligence. 00249 */ 00250 void setIntelligence(enum Character character, unsigned char value); 00251 00252 /** 00253 * Checks if a character has joined the party or not. 00254 * 00255 * @param character The character. 00256 * 00257 * @return true if the character has joined; false otherwise. 00258 */ 00259 bool hasJoined(enum Character character) const; 00260 00261 /** 00262 * Sets whether a character has joined the party or not. 00263 * 00264 * @param character The character. 00265 * @param value true if joined; false otherwise. 00266 */ 00267 void setJoined(enum Character character, bool value); 00268 00269 /** 00270 * Gets the level of a character. 00271 * 00272 * @param character The character. 00273 * 00274 * @return The character's level. 00275 */ 00276 int getLevel(enum Character character) const; 00277 00278 /** 00279 * Sets the level of a character. 00280 * 00281 * @param character The character. 00282 * @param value The new level. 00283 */ 00284 void setLevel(enum Character character, unsigned char value); 00285 00286 /** 00287 * Queries whether the party has a particular magic or not. 00288 * 00289 * @param magic The magic to check for. 00290 */ 00291 bool hasMagic(enum Magic magic) const; 00292 00293 /** 00294 * Sets whether the party has a particular magic of not. 00295 * 00296 * @param magic The magic. Valid values are any of the members in the 00297 * Magic enumeration other than INVALIDx. 00298 * @param give true to give the magic; false to take it away. 00299 */ 00300 void setMagic(enum Magic magic, bool give = true); 00301 00302 /** 00303 * Gets the max HP of a character. 00304 * 00305 * @param character The character. 00306 * 00307 * @return The Max HP. 00308 */ 00309 wxInt16 getMaxHP(enum Character character) const; 00310 00311 /** 00312 * Sets the max HP of a character. 00313 * 00314 * @param character The character. 00315 * @param value The new max HP. 00316 */ 00317 void setMaxHP(enum Character character, wxInt16 value); 00318 00319 /** 00320 * Gets the max MP of a character. 00321 * 00322 * @param character The character. 00323 * 00324 * @return The max MP. 00325 */ 00326 int getMaxMP(enum Character character) const; 00327 00328 /** 00329 * Sets the max MP of a charcter. 00330 * 00331 * @param character The character. 00332 * @param value The new max MP. 00333 */ 00334 void setMaxMP(enum Character character, unsigned char value); 00335 00336 /** 00337 * Gets the party member at a given position. 00338 * 00339 * @param position The party position number (0-3). 00340 * 00341 * @return The character at that position. Return values range between 00342 * 0 and 1 + one of the character values in the Characters 00343 * enumeration. 1 = Mage, 8 = Shepherd, 0 = No one. 00344 */ 00345 int getMember(int position) const; 00346 00347 /** 00348 * Sets the party member at a given position. 00349 * 00350 * @param position The party position number (0-3). 00351 * @param character What character class should be here, or 0 for no 00352 * one. Use the Characters enumeration + 1 for proper 00353 * character values (e.g. MAGE + 1). 00354 */ 00355 void setMember(int position, int character); 00356 00357 /** 00358 * Queries if this SaveSlot has been modified. 00359 * 00360 * @return true if modified; false otherwise. 00361 */ 00362 bool isModified() const; 00363 00364 /** 00365 * Gets the current phase of one of the moons. Valid values are either 00366 * TRAMMEL or FELUCCA. 00367 * 00368 * @param moon The moon whose phase to return. 00369 * 00370 * @return The phase of the moon. Note that felucca's phase depends upon 00371 * trammel's phase and can be only 0, 1, or 2 representing one 00372 * of the three destination cities. Trammel's phase will always 00373 * be one of the eight cities of virtue. 00374 */ 00375 int getPhase(enum Moon moon) const; 00376 00377 /** 00378 * Sets the phases of the moons. 00379 * 00380 * @param trammel The phase for trammel. Must be one of the eight cities 00381 * of virtue. 00382 * @param felucca The phase for felucca. Must be 0, 1, or 2 representing 00383 * one of the three destination cities from Trammel. 00384 */ 00385 void setPhase(enum City trammel, int felucca); 00386 00387 /** 00388 * Checks if the party has captured a particular ship. 00389 * 00390 * @param ship The ship to check for. 00391 * 00392 * @return true if the ship has been taken; false otherwise. 00393 */ 00394 bool hasPirateShip(enum PirateShip ship) const; 00395 00396 /** 00397 * Sets whether the party has a particular pirate ship or not. 00398 * 00399 * @param ship The pirate ship. 00400 * @param give true to give the ship; false otherwise. 00401 */ 00402 void setPirateShip(enum PirateShip ship, bool give); 00403 00404 /** 00405 * Gets the location of one of the captured pirate ships. 00406 * 00407 * @param ship The ship. 00408 * 00409 * @return The location of the ship (latitude, longitude). 00410 */ 00411 std::pair<int, int> getPirateShipLocation(enum PirateShip ship) const; 00412 00413 /** 00414 * Sets the location of a captured pirate ship. 00415 * 00416 * @param ship The pirate ship. 00417 * @param location The location (latitude, longitude). 00418 */ 00419 void setPirateShipLocation(enum PirateShip ship, 00420 std::pair<int, int> location); 00421 00422 /** 00423 * Queries whether the party has a particular rune or not. 00424 * 00425 * @param rune The rune. 00426 * 00427 * @return true if they have the rune; false otherwise. 00428 */ 00429 bool hasRune(enum Virtue rune) const; 00430 00431 /** 00432 * Sets whether the party has a particular rune of not. 00433 * 00434 * @param rune The rune. 00435 * @param give true to give the rune; false to take it away. 00436 */ 00437 void setRune(enum Virtue rune, bool give = true); 00438 00439 /** 00440 * Gets the start location. 00441 * 00442 * @return The start location. 00443 */ 00444 enum StartLocation getStartLocation() const; 00445 00446 /** 00447 * Sets the start location. 00448 * 00449 * @param location The start location. 00450 */ 00451 void setStartLocation(enum StartLocation location); 00452 00453 /** 00454 * Queries if the party has a particular stone in their inventory. 00455 * 00456 * @param stone The stone to check for. 00457 * 00458 * @return true if they have the stone; false otherwise. 00459 */ 00460 bool hasStone(enum Virtue stone) const; 00461 00462 /** 00463 * Sets whether the party has a particular stone or not. 00464 * 00465 * @param stone The stone. 00466 * @param give true to give the stone; false to take it away. 00467 */ 00468 void setStone(enum Virtue stone, bool give = true); 00469 00470 /** 00471 * Gets the strength of a character. 00472 * 00473 * @param character The character. 00474 * 00475 * @return The strength. 00476 */ 00477 int getStrength(enum Character character) const; 00478 00479 /** 00480 * Sets the strength of a charater. 00481 * 00482 * @param character The character. 00483 * @param value The new strength. 00484 */ 00485 void setStrength(enum Character character, unsigned char value); 00486 00487 /** 00488 * Gets the amount of a tool the party has. 00489 * 00490 * @param tool The tool to get the amount of. 00491 * 00492 * @return The amount of the particular tool. 00493 */ 00494 int getTool(enum Tool tool) const; 00495 00496 /** 00497 * Sets the amount of a tool the party has. 00498 * 00499 * @param tool The tool to set the amount of. 00500 * @param value The new amount. 00501 */ 00502 void setTool(enum Tool tool, unsigned char value = 1); 00503 00504 /** 00505 * Gets the value for one of the eight virtues. 00506 * 00507 * @param virtue The virtue whose value to retrieve. 00508 * 00509 * @return The value for the particular virtue. 00510 */ 00511 int getVirtue(enum Virtue virtue) const; 00512 00513 /** 00514 * Sets the value for one of the eight virtues. 00515 * 00516 * @param virtue The virtue to set. 00517 * @param value The new value for the virtue. 00518 */ 00519 void setVirtue(enum Virtue virtue, unsigned char value); 00520 00521 /** 00522 * Gets the location of the whirlpool. 00523 * 00524 * @return The location. 00525 */ 00526 std::pair<int, int> getWhirlpoolLocation() const; 00527 00528 /** 00529 * Sets the location of the whirlpool. 00530 * 00531 * @param location The location. 00532 */ 00533 void setWhirlpoolLocation(std::pair<int, int> location); 00534 00535 /** 00536 * Generates the checksum for the current data. 00537 * 00538 * @return The checksum. 00539 */ 00540 unsigned char checksum() const; 00541 }; 00542 00543 inline bool SaveSlot::isModified() const { return modified; } 00544 } 00545 00546 #endif 00547