aboutsummaryrefslogtreecommitdiff
path: root/engines/lure/fights.h
blob: 89f49d8c6d952aac7ae26334a2ac4f79aedebb43 (plain)
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
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef LURE_FIGHT_H
#define LURE_FIGHT_H

#include "lure/luredefs.h"
#include "lure/hotspots.h"
#include "lure/palette.h"

#include "common/singleton.h"
#include "common/endian.h"
#include "common/random.h"

namespace Lure {

struct FighterRecord {
	uint16 fwheader_list;
	uint16 fwweapon;
	uint16 fwdie_seq;
	uint16 fwhit_value;
	uint16 fwhit_rate;
	int16 fwtrue_x;
	int16 fwtrue_y;
	uint16 fwblocking;
	uint16 fwattack_table;
	uint16 fwdef_len;
	uint16 fwdefend_table;
	uint16 fwnot_near;
	uint16 fwdefend_adds;
	uint16 fwseq_no;
	uint16 fwdist;
	uint16 fwwalk_roll;
	uint16 fwmove_number;
	uint16 fwhits;
	uint16 fwseq_ad;
	uint16 fwenemy_ad;
};

// Constant references into the fight data
#define FIGHT_TBL_1 0x8b8
#define FIGHT_PLAYER_MOVE_TABLE 0xDAA
#define FIGHT_PLAYER_INIT 0xDC8
#define FIGHT_PLAYER_DIES 0xF46

#define FIGHT_DISTANCE 32

enum KeyStatus {KS_UP, KS_KEYDOWN_1, KS_KEYDOWN_2};

class FightsManager {
private:
	MemoryBlock *_fightData;
	Common::RandomSource &_rnd;
	uint8 _mouseFlags;
	KeyStatus _keyDown;
	FighterRecord _fighterList[3];

	FighterRecord &getDetails(uint16 hotspotId);
	uint16 fetchFighterDistance(FighterRecord &f1, FighterRecord &f2);
	void removeWeapon(uint16 weaponId);
	void enemyKilled();
	uint16 getFighterMove(FighterRecord &rec, uint16 baseOffset);
	void checkEvents();
	void fightHandler(Hotspot &h, uint16 moveOffset);

	inline uint16 getWord(uint16 offset) {
		if (!_fightData)
			_fightData = Disk::getReference().getEntry(FIGHT_DATA_RESOURCE_ID);
		if (offset >= _fightData->size() - 1) error("Invalid fight data index");
		return READ_LE_UINT16(_fightData->data() + offset);
	}
	inline uint8 getByte(uint16 offset) {
		if (!_fightData)
			_fightData = Disk::getReference().getEntry(FIGHT_DATA_RESOURCE_ID);
		if (offset >= _fightData->size()) error("Invalid fight data index");
		return _fightData->data()[offset];
	}
public:
	FightsManager();
	~FightsManager();
	static FightsManager &getReference();

	void setupPigFight();
	void setupSkorlFight();
	bool isFighting();
	void fightLoop();
	void saveToStream(Common::WriteStream *stream);
	void loadFromStream(Common::ReadStream *stream);
	void reset();

	void fighterAnimHandler(Hotspot &h);
	void playerAnimHandler(Hotspot &h);
};

#define Fights FightsManager::getReference()

} // End of namespace Lure

#endif