1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MM1_DATA_CHAR_H
#define MM1_DATA_CHAR_H
#include "common/array.h"
#include "common/serializer.h"
#include "mm/mm1/data/items.h"
#include "mm/shared/xeen/sprites.h"
namespace MM {
namespace MM1 {
#define INVENTORY_COUNT 6
#define MAX_LEVEL 200
#define NUM_PORTRAITS 12
enum CharacterClass {
KNIGHT = 1, PALADIN = 2, ARCHER = 3, CLERIC = 4,
SORCERER = 5, ROBBER = 6, NONE = 0
};
enum Race {
HUMAN = 1, ELF = 2, DWARF = 3, GNOME = 4, HALF_ORC = 5
};
enum Alignment {
GOOD = 1, NEUTRAL = 2, EVIL = 3
};
enum Sex {
MALE = 1, FEMALE = 2, YES_PLEASE = 3
};
enum Condition {
FINE = 0, BAD_CONDITION = 0x80, ERADICATED = 0xff,
DEAD = 0x40, STONE = 0x20,
UNCONSCIOUS = 0x40, PARALYZED = 0x20, POISONED = 0x10,
DISEASED = 8, SILENCED = 4, BLINDED = 2, ASLEEP = 1
};
enum ConditionEnum {
HEART_BROKEN = 1,
C_BLINDED = 2, // WEAK condition in Xeen
C_POISONED = 3,
C_DISEASED = 4,
C_ASLEEP = 8,
DEPRESSED = 9,
C_SILENCED = 10, // CONFUSED condition in Xeen
C_PARALYZED = 11,
C_UNCONSCIOUS = 12,
C_DEAD = 13,
C_STONE = 14,
C_ERADICATED = 15,
C_GOOD = 16
};
enum Resistance {
RESISTANCE_MAGIC = 0, RESISTANCE_FIRE = 1, RESISTANCE_COLD = 2,
RESISTANCE_ELECTRICITY = 3, RESISTANCE_ACID = 4,
RESISTANCE_FEAR = 5, RESISTANCE_POISON = 6,
RESISTANCE_PSYCHIC = 7, RESISTANCE_15 = 15
};
enum CharFlags0 {
CHARFLAG0_COURIER1 = 1,
CHARFLAG0_COURIER2 = 2,
CHARFLAG0_COURIER3 = 4,
CHARFLAG0_ZOM_CLUE = 8,
CHARFLAG0_ZAM_CLUE = 0x10,
CHARFLAG0_FOUND_CHEST = 0x20,
CHARFLAG0_40 = 0x40,
CHARFLAG0_DOG_STATUE = 0x80
};
enum CharFlags1 {
CHARFLAG1_1 = 1,
CHARFLAG1_2 = 2,
CHARFLAG1_4 = 4,
CHARFLAG1_8 = 8,
CHARFLAG1_10 = 0x10,
CHARFLAG1_20 = 0x20,
CHARFLAG1_40 = 0x40,
CHARFLAG1_WORTHY = 0x80
};
enum CharFlags2 {
CHARFLAG2_1 = 1,
CHARFLAG2_2 = 2,
CHARFLAG2_4 = 4,
CHARFLAG2_8 = 8,
CHARFLAG2_10 = 0x10,
CHARFLAG2_20 = 0x20,
CHARFLAG2_40 = 0x40,
CHARFLAG2_80 = 0x80
};
enum CharFlags4 {
CHARFLAG4_ASSIGNED = 8,
CHARFLAG4_SIGN = 7,
CHARFLAG4_COLOR = 0xf,
CHARFLAG4_80 = 0x80
};
enum CharFlags5 {
CHARFLAG5_1 = 1,
CHARFLAG5_2 = 2,
CHARFLAG5_4 = 4,
CHARFLAG5_8 = 8,
CHARFLAG5_10 = 0x10,
CHARFLAG5_20 = 0x20,
CHARFLAG5_40 = 0x40,
CHARFLAG5_80 = 0x80
};
enum CharFlags6 {
CHARFLAG6_1 = 1,
CHARFLAG6_2 = 2,
CHARFLAG6_4 = 4,
CHARFLAG6_8 = 8,
CHARFLAG6_10 = 0x10,
CHARFLAG6_20 = 0x20,
CHARFLAG6_40 = 0x40,
CHARFLAG6_80 = 0x80
};
enum CharFlags7 {
CHARFLAG7_1 = 1,
CHARFLAG7_2 = 2,
CHARFLAG7_4 = 4,
CHARFLAG7_8 = 8,
CHARFLAG7_10 = 0x10,
CHARFLAG7_20 = 0x20,
CHARFLAG7_40 = 0x40,
CHARFLAG7_80 = 0x80
};
enum CharFlags8 {
CHARFLAG8_1 = 1,
CHARFLAG8_2 = 2,
CHARFLAG8_4 = 4,
CHARFLAG8_8 = 8,
CHARFLAG8_10 = 0x10,
CHARFLAG8_20 = 0x20,
CHARFLAG8_40 = 0x40,
CHARFLAG8_80 = 0x80
};
enum CharFlags9 {
CHARFLAG9_1 = 1,
CHARFLAG9_2 = 2,
CHARFLAG9_4 = 4,
CHARFLAG9_8 = 8,
CHARFLAG9_10 = 0x10,
CHARFLAG9_20 = 0x20,
CHARFLAG9_40 = 0x40,
CHARFLAG9_80 = 0x80
};
enum CharFlags10 {
CHARFLAG10_1 = 1,
CHARFLAG10_2 = 2,
CHARFLAG10_4 = 4,
CHARFLAG10_8 = 8,
CHARFLAG10_10 = 0x10,
CHARFLAG10_20 = 0x20,
CHARFLAG10_40 = 0x40,
CHARFLAG10_80 = 0x80
};
enum CharFlags11 {
CHARFLAG11_GOT_ENDURANCE = 1,
CHARFLAG11_PERSONALITY = 2,
CHARFLAG11_GOT_INTELLIGENCE = 4,
CHARFLAG11_GOT_MIGHT = 8,
CHARFLAG11_GOT_ACCURACY = 0x10,
CHARFLAG11_GOT_SPEED = 0x20,
CHARFLAG11_GOT_LUCK = 0x40,
CHARFLAG11_CLERICS = 0x80
};
enum CharFlags12 {
CHARFLAG12_1 = 1,
CHARFLAG12_2 = 2,
CHARFLAG12_4 = 4,
CHARFLAG12_8 = 8,
CHARFLAG12_10 = 0x10,
CHARFLAG12_20 = 0x20,
CHARFLAG12_40 = 0x40,
CHARFLAG12_80 = 0x80
};
enum CharFlags13 {
CHARFLAG13_1 = 1,
CHARFLAG13_2 = 2,
CHARFLAG13_4 = 4,
CHARFLAG13_8 = 8,
CHARFLAG13_10 = 0x10,
CHARFLAG13_20 = 0x20,
CHARFLAG13_ALAMAR = 0x40,
CHARFLAG13_80 = 0x80
};
class Inventory {
public:
struct Entry {
byte _id = 0;
byte _charges = 0;
operator bool() const { return _id != 0; }
// bool operator!() const { return !_id; }
// operator byte() const { return _id; }
};
private:
Common::Array<Entry> _items;
/**
* Used to test if the inventory has a category of item
*/
typedef bool (*CategoryFn)(byte id);
bool hasCategory(CategoryFn fn) const;
/**
* Returns the index of a free slot
*/
int getFreeSlot() const;
public:
Inventory() {
clear();
}
Entry &operator[](uint idx) {
assert(idx < INVENTORY_COUNT);
return _items[idx];
}
const Entry &operator[](uint idx) const {
assert(idx < INVENTORY_COUNT);
return _items[idx];
}
/**
* Saves or loads the inventory data
*/
void synchronize(Common::Serializer &s, bool ids);
/**
* Clears the inventory
*/
void clear();
/**
* Returns true if the inventory is empty
*/
bool empty() const;
/**
* Returns true if the inventory is full
*/
bool full() const;
/**
* Returns the size of the backpack that's filled in
*/
uint size() const;
/**
* Adds an item to the inventory
*/
uint add(byte id, byte charges);
/**
* Removes an index from the inventory
*/
void removeAt(uint idx);
/**
* Remove an entry from the inventory
*/
void remove(Entry *e);
/**
* Returns the index of a given entry
*/
int indexOf(Entry *e) const;
/**
* Returns the index of an entry with a given id
*/
int indexOf(byte itemId) const;
/**
* Decreases the charge on a magic item, and removes
* it if the charges have run out
*/
void removeCharge(Entry *e);
/**
* The following methods return true if any of
* the contained items are of the given category
*/
bool hasWeapon() const { return hasCategory(isWeapon); }
bool hasMissile() const { return hasCategory(isMissile); }
bool hasTwoHanded() const { return hasCategory(isTwoHanded); }
bool hasArmor() const { return hasCategory(isArmor); }
bool hasShield() const { return hasCategory(isShield); }
size_t getPerformanceTotal() const;
};
/**
* Attribute pair representing it's base value and the
* current temporary value
*/
struct AttributePair {
uint8 _current = 0;
uint8 _base = 0;
operator uint8() const { return _current; }
AttributePair &operator=(byte v) {
_base = _current = v;
return *this;
}
AttributePair &operator++() {
if (_base < 255)
_current = ++_base;
return *this;
}
AttributePair &operator--() {
if (_base > 0)
_current = --_base;
return *this;
}
void clear() { _current = _base = 0; }
void reset() { _current = _base; }
void synchronize(Common::Serializer &s) {
s.syncAsByte(_base);
s.syncAsByte(_current);
}
size_t getPerformanceTotal() const {
return (size_t)_base + (size_t)_current;
}
};
struct AttributePair16 {
uint16 _current = 0;
uint16 _base = 0;
void clear() { _current = _base = 0; }
AttributePair16 &operator=(byte v) {
_base = _current = v;
return *this;
}
operator uint16() const {
return _current;
}
void synchronize(Common::Serializer &s) {
s.syncAsUint16LE(_base);
s.syncAsUint16LE(_current);
}
size_t getPerformanceTotal() const {
return (_base & 0xff) + (_base >> 8) +
(_current & 0xff) + (_current >> 8);
}
};
struct ResistanceFields {
AttributePair _magic;
AttributePair _fire;
AttributePair _cold;
AttributePair _electricity;
AttributePair _acid;
AttributePair _fear;
AttributePair _poison;
AttributePair _psychic;
};
union Resistances {
ResistanceFields _s;
AttributePair _arr[8];
Resistances();
/**
* Handles save/loading resistances
*/
void synchronize(Common::Serializer &s);
size_t getPerformanceTotal() const;
};
struct PrimaryAttributes {
public:
AttributePair _intelligence;
AttributePair _might;
AttributePair _personality;
AttributePair _endurance;
AttributePair _speed;
AttributePair _accuracy;
AttributePair _luck;
AttributePair _level;
AttributePair &getAttribute(uint i) {
return *_attributes[i];
}
private:
AttributePair *_attributes[8] = {
&_intelligence, &_might, &_personality, &_endurance,
&_speed, &_accuracy, &_luck, &_level
};
};
struct Character : public PrimaryAttributes {
char _name[16] = { 0 };
Sex _sex = MALE;
Alignment _alignmentInitial = GOOD;
Alignment _alignment = GOOD;
Race _race = HUMAN;
CharacterClass _class = NONE;
byte _age = 0;
int _ageDayCtr = 0;
AttributePair16 _sp;
AttributePair _spellLevel;
AttributePair _ac;
uint32 _exp = 0;
uint16 _gems = 0;
uint16 _hpCurrent = 0, _hp = 0, _hpMax = 0;
uint32 _gold = 0;
uint8 _food = 0;
uint8 _condition = 0;
Inventory _equipped;
Inventory _backpack;
Resistances _resistances;
AttributePair _physicalAttr, _missileAttr;
byte _trapCtr = 0;
byte _quest = 0;
byte _worthiness = 0;
byte _alignmentCtr = 0;
byte _flags[14];
byte _portrait = 0;
Shared::Xeen::SpriteResource _faceSprites;
// Non persistent fields
byte _numDrinks = 0;
// Combat fields
bool _checked = false;
bool _canAttack = false;
int _nonCombatSpell = -1;
int _combatSpell = -1;
/**
* Get the selected combat/noncombat spell number
*/
int spellNumber() const;
/**
* Sets the selected spell
*/
void setSpellNumber(int spellNum);
Character();
/**
* Handles save/loading a character
* @param portraitNum Override for portrait to use for
* a character being loaded from the game defaults
*/
void synchronize(Common::Serializer &s, int portraitNum = -1);
/**
* Equality test
*/
bool operator==(const Character &rhs) const {
return !strcmp(_name, rhs._name);
}
/**
* Clearing the character
*/
void clear();
/**
* Gathers the party gold into the character
*/
void gatherGold();
/**
* Trade an item to another
*/
enum TradeResult { TRADE_SUCCESS, TRADE_NO_ITEM, TRADE_FULL };
TradeResult trade(int whoTo, int itemIndex);
/**
* Increase the character's level by 1 at a trainer
*/
struct LevelIncrease {
int _numHP;
int _numSpells;
};
LevelIncrease increaseLevel();
/**
* Buy an item
*/
enum BuyResult { BUY_SUCCESS, BUY_NOT_ENOUGH_GOLD, BUY_BACKPACK_FULL };
BuyResult buyItem(byte itemId);
/**
* Updates the current attribute levels to match
* their base values
*/
void updateAttributes();
/**
* Updates the character's AC
*/
void updateAC();
/**
* Updates the character's SP
*/
void updateSP();
void updateResistances();
/**
* Gets a character's condition string
*/
Common::String getConditionString() const;
/**
* Rest the character
*/
void rest();
/**
* Returns true if the character has a given item
*/
bool hasItem(byte itemId) const;
/**
* Gets the numeric value of every property a character
* has and totals it up to give a stupid 'performance'
* value for the party at the end of the game
*/
size_t getPerformanceTotal() const;
/**
* Loads the face sprites for the character
*/
void loadFaceSprites();
/**
* Returns the color to use in enhanced mode to
* represent the color of a character attribute
*/
byte statColor(int amount, int threshold) const;
/**
* Returns the condition color for display
*/
byte conditionColor() const;
/**
* Returns the worst condition, if any, a character
* currently has.
*/
ConditionEnum worstCondition() const;
/**
* Returns a string for a given condition
*/
static Common::String getConditionString(ConditionEnum cond);
/**
* Returns true if the character has a fatal condition
*/
bool hasBadCondition() const {
return (_condition & BAD_CONDITION) != 0;
}
};
} // namespace MM1
} // namespace MM
#endif
|