1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, In, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ultima/ultima1/core/party.h"
24 #include "ultima/ultima1/core/resources.h"
25 #include "ultima/ultima1/game.h"
26
27 namespace Ultima {
28 namespace Ultima1 {
29
Party(Ultima1Game * game)30 Party::Party(Ultima1Game *game) {
31 add(new Character(game));
32 }
33
setup()34 void Party::setup() {
35 static_cast<Character *>(_characters.front())->setup();
36 }
37
38 /*-------------------------------------------------------------------*/
39
Character(Ultima1Game * game)40 Character::Character(Ultima1Game *game) : Shared::Character(),
41 _weaponHands(game, this, WEAPON_HANDS),
42 _weaponDagger(game, this, WEAPON_DAGGER),
43 _weaponMace(game, this, WEAPON_MACE),
44 _weaponAxe(game, this, WEAPON_AXE),
45 _weaponRopeSpikes(game, this, WEAPON_ROPE_SPIKES),
46 _weaponSword(game, this, WEAPON_SWORD),
47 _weaponGreatSword(game, this, WEAPON_GREAT_SWORD),
48 _weaponBowArrows(game, this, WEAPON_BOW_ARROWS),
49 _weaponAmulet(game, this, WEAPON_AMULET),
50 _weaponWand(game, this, WEAPON_WAND),
51 _weaponStaff(game, this, WEAPON_STAFF),
52 _weaponTriangle(game, this, WEAPON_TRIANGLE),
53 _weaponPistol(game, this, WEAPON_PISTOL),
54 _weaponLightSword(game, this, WEAPON_LIGHT_SWORD),
55 _weaponPhazor(game, this, WEAPON_PHAZOR),
56 _weaponBlaster(game, this, WEAPON_BLASTER),
57
58 _armourSkin(game, this, ARMOR_SKIN),
59 _armourLeatherArmor(game, this, ARMOR_LEATHER_armour),
60 _armourChainMail(game, this, ARMOR_CHAIN_MAIL),
61 _armourPlateMail(game, this, ARMOR_PLATE_MAIL),
62 _armourVacuumSuit(game, this, ARMOR_VACUUM_SUIT),
63 _armourReflectSuit(game, this, ARMOR_REFLECT_SUIT),
64
65 _spellBlink(game, this),
66 _spellCreate(game, this),
67 _spellDestroy(game, this),
68 _spellKill(game, this),
69 _spellLadderDown(game, this),
70 _spellLadderUp(game, this),
71 _spellMagicMissile(game, this),
72 _spellOpen(game, this),
73 _spellPrayer(game, this),
74 _spellSteal(game, this),
75 _spellUnlock(game, this) {
76 setup();
77 }
78
setup()79 void Character::setup() {
80 // Weapons setup
81 _weapons.push_back(&_weaponHands);
82 _weapons.push_back(&_weaponDagger);
83 _weapons.push_back(&_weaponMace);
84 _weapons.push_back(&_weaponAxe);
85 _weapons.push_back(&_weaponRopeSpikes);
86 _weapons.push_back(&_weaponSword);
87 _weapons.push_back(&_weaponGreatSword);
88 _weapons.push_back(&_weaponBowArrows);
89 _weapons.push_back(&_weaponAmulet);
90 _weapons.push_back(&_weaponWand);
91 _weapons.push_back(&_weaponStaff);
92 _weapons.push_back(&_weaponTriangle);
93 _weapons.push_back(&_weaponPistol);
94 _weapons.push_back(&_weaponLightSword);
95 _weapons.push_back(&_weaponPhazor);
96 _weapons.push_back(&_weaponBlaster);
97
98 // Armor setup
99 _armour.push_back(&_armourSkin);
100 _armour.push_back(&_armourLeatherArmor);
101 _armour.push_back(&_armourChainMail);
102 _armour.push_back(&_armourPlateMail);
103 _armour.push_back(&_armourVacuumSuit);
104 _armour.push_back(&_armourReflectSuit);
105
106 // Spells setup
107 _spells.push_back(&_spellPrayer);
108 _spells.push_back(&_spellOpen);
109 _spells.push_back(&_spellUnlock);
110 _spells.push_back(&_spellMagicMissile);
111 _spells.push_back(&_spellSteal);
112 _spells.push_back(&_spellLadderDown);
113 _spells.push_back(&_spellLadderUp);
114 _spells.push_back(&_spellBlink);
115 _spells.push_back(&_spellCreate);
116 _spells.push_back(&_spellDestroy);
117 _spells.push_back(&_spellKill);
118 }
119
120 /*-------------------------------------------------------------------*/
121
Weapon(Ultima1Game * game,Character * c,WeaponType weaponType)122 Weapon::Weapon(Ultima1Game *game, Character *c, WeaponType weaponType) :
123 _game(game), _character(c), _type(weaponType) {
124 _longName = game->_res->WEAPON_NAMES_UPPERCASE[weaponType];
125 _shortName = game->_res->WEAPON_NAMES_LOWERCASE[weaponType];
126 _distance = game->_res->WEAPON_DISTANCES[weaponType];
127
128 if (weaponType == WEAPON_HANDS)
129 _quantity = 0xffff;
130 }
131
132
getMagicDamage() const133 uint Weapon::getMagicDamage() const {
134 uint damage = _game->getRandomNumber(1, _character->_intelligence);
135
136 switch (_type) {
137 case WEAPON_WAND:
138 damage *= 2;
139 break;
140 case WEAPON_AMULET:
141 damage = (damage * 3) / 2;
142 break;
143 case WEAPON_STAFF:
144 case WEAPON_TRIANGLE:
145 damage *= 3;
146 break;
147 default:
148 break;
149 }
150
151 return damage;
152 }
153
getBuyCost() const154 uint Weapon::getBuyCost() const {
155 return ((255 - _character->_intelligence) * _type * _type) / 256 + 5;
156 }
157
getSellCost() const158 uint Weapon::getSellCost() const {
159 return ((_character->_intelligence + 40) * _type * _type) / 256 + 1;
160 }
161
162 /*-------------------------------------------------------------------*/
163
Armour(Ultima1Game * game,Character * c,ArmorType armorType)164 Armour::Armour(Ultima1Game *game, Character *c, ArmorType armorType) :
165 _character(c), _type(armorType) {
166 _name = game->_res->ARMOR_NAMES[armorType];
167
168 if (armorType == ARMOR_SKIN)
169 _quantity = 0xffff;
170 }
171
getBuyCost() const172 uint Armour::getBuyCost() const {
173 return (200 - _character->_intelligence) / 4 * _type;
174 }
175
getSellCost() const176 uint Armour::getSellCost() const {
177 return (_character->_charisma / 4) * _type;
178 }
179
180 } // End of namespace Ultima1
181 } // End of namespace Ultima
182