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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef WORLD_ACTORS_MAINACTOR_H
24 #define WORLD_ACTORS_MAINACTOR_H
25 
26 #include "ultima/ultima8/world/actors/actor.h"
27 
28 namespace Ultima {
29 namespace Ultima8 {
30 
31 class Debugger;
32 struct WeaponOverlayFrame;
33 
34 class MainActor : public Actor {
35 	friend class Debugger;
36 public:
37 	enum CruBatteryType {
38 		NoBattery = 0,
39 		ChemicalBattery = 1,
40 		FissionBattery = 2,
41 		FusionBattery = 3
42 	};
43 
44 	MainActor();
45 	~MainActor() override;
46 
47 	bool CanAddItem(Item *item, bool checkwghtvol = false) override;
48 	bool addItem(Item *item, bool checkwghtvol = false) override;
49 
50 	//! Get the ShapeInfo object for this MainActor.  Overrided because it changes
51 	//! when Crusader is kneeling.
52 	const ShapeInfo *getShapeInfoFromGameInstance() const override;
53 
54 	void move(int32 X, int32 Y, int32 Z) override;
55 
56 	//! Add item to avatar's inventory, but with some extra logic to do things like combine
57 	//! ammo and credits, use batteries, etc.
58 	int16 addItemCru(Item *item, bool showtoast);
59 
60 	//! Remove a single item - only called from an intrinsic
61 	bool removeItemCru(Item *item);
62 
63 	//! teleport to the given location on the given map
64 	void teleport(int mapNum, int32 x, int32 y, int32 z) override;
65 
66 	//! teleport to a teleport-destination egg
67 	//! \param mapnum The map to teleport to
68 	//! \param teleport_id The ID of the egg to teleport to
69 	void teleport(int mapNum, int teleport_id); // to teleportegg
70 
hasJustTeleported()71 	bool hasJustTeleported() const {
72 		return _justTeleported;
73 	}
setJustTeleported(bool t)74 	void setJustTeleported(bool t) {
75 		_justTeleported = t;
76 	}
77 
78 	//! accumulate a little bit of strength. When you reach 650 you gain
79 	//! one strength point. (There's a chance you gain strength sooner)
80 	void accumulateStr(int n);
81 
82 	//! accumulate a little bit of dexterity. When you reach 650 you gain
83 	//! one dex. point. (There's a chance you gain dex. sooner)
84 	void accumulateDex(int n);
85 
86 	//! accumulate a little bit of intelligence. When you reach 650 you gain
87 	//! one int. point. (There's a chance you gain int. sooner)
88 	void accumulateInt(int n);
89 
90 	//! Get the GravityProcess of this Item, creating it if necessary
91 	GravityProcess *ensureGravityProcess() override;
92 
93 	uint32 getArmourClass() const override;
94 	uint16 getDefenseType() const override;
95 	int16 getAttackingDex() const override;
96 	int16 getDefendingDex() const override;
97 
98 	uint16 getDamageType() const override;
99 	int getDamageAmount() const override;
100 
toggleInCombat()101 	void toggleInCombat() {
102 		if (isInCombat())
103 			clearInCombat();
104 		else
105 			setInCombat(0);
106 	}
107 
108 	// Note: activity num parameter is ignored for Avatar.
109 	void setInCombat(int activity) override;
110 	void clearInCombat() override;
111 
112 	ProcId die(uint16 damageType, uint16 damagePts, Direction srcDir) override;
113 
getName()114 	const Std::string &getName() const {
115 		return _name;
116 	}
setName(const Std::string & name)117 	void setName(const Std::string &name) {
118 		_name = name;
119 	}
120 
121 	int16 getMaxEnergy();
122 
getBatteryType()123 	CruBatteryType getBatteryType() const {
124 		return _cruBatteryType;
125 	}
setBatteryType(CruBatteryType newbattery)126 	void setBatteryType(CruBatteryType newbattery) {
127 		_cruBatteryType = newbattery;
128 		setMana(getMaxEnergy());
129 	}
130 
setShieldType(uint16 shieldtype)131 	void setShieldType(uint16 shieldtype) {
132 		_shieldType = shieldtype;
133 	}
134 
getShieldType()135 	uint16 getShieldType() {
136 		return _shieldType;
137 	}
138 
139 	bool hasKeycard(int num) const;
140 	void addKeycard(int bitno);
141 
clrKeycards()142 	void clrKeycards() {
143 		_keycards = 0;
144 	}
145 
getActiveInvItem()146 	uint16 getActiveInvItem() const {
147 		return _activeInvItem;
148 	}
149 
150 	//! Swap to the next active weapon (Crusader)
151 	void nextWeapon();
152 
153 	//! Swap to the next inventory item (Crusader)
154 	void nextInvItem();
155 
156 	//! Check if we can absorb a hit with the shield. Returns the modified damage value.
157 	int receiveShieldHit(int damage, uint16 damage_type) override;
158 
159 	//! Detonate used bomb (Crusader)
160 	void detonateBomb();
161 
162 	bool loadData(Common::ReadStream *rs, uint32 version);
163 	void saveData(Common::WriteStream *ws) override;
164 
165 	ENABLE_RUNTIME_CLASSTYPE()
166 
167 	INTRINSIC(I_teleportToEgg);
168 	INTRINSIC(I_accumulateStrength);
169 	INTRINSIC(I_accumulateDexterity);
170 	INTRINSIC(I_accumulateIntelligence);
171 	INTRINSIC(I_clrAvatarInCombat);
172 	INTRINSIC(I_setAvatarInCombat);
173 	INTRINSIC(I_isAvatarInCombat);
174 	INTRINSIC(I_getMaxEnergy);
175 	INTRINSIC(I_hasKeycard);
176 	INTRINSIC(I_clrKeycards);
177 	INTRINSIC(I_addItemCru);
178 	INTRINSIC(I_getNumberOfCredits);
179 	INTRINSIC(I_switchMap);
180 	INTRINSIC(I_removeItemCru);
181 
182 	void getWeaponOverlay(const WeaponOverlayFrame *&frame, uint32 &shape);
183 
184 
185 protected:
186 	void useInventoryItem(uint32 shapenum);
187 	void useInventoryItem(Item *item);
188 
189 	bool _justTeleported;
190 
191 	int _accumStr;
192 	int _accumDex;
193 	int _accumInt;
194 
195 	uint32 _keycards;
196 	CruBatteryType _cruBatteryType;
197 	uint16 _activeInvItem;
198 
199 	Std::string _name;
200 
201 	//! Process for a shield zap animation sprite
202 	uint16 _shieldSpriteProc;
203 	//! Type of shield (only used in Crusader)
204 	uint16 _shieldType;
205 
206 	static ShapeInfo *_kneelingShapeInfo;
207 
208 };
209 
210 } // End of namespace Ultima8
211 } // End of namespace Ultima
212 
213 #endif
214