File: combat.h

package info (click to toggle)
exult 1.12.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 43,608 kB
  • sloc: cpp: 169,917; xml: 7,400; yacc: 2,850; makefile: 2,419; java: 1,901; ansic: 1,654; lex: 673; sh: 539; objc: 416
file content (137 lines) | stat: -rw-r--r-- 5,076 bytes parent folder | download | duplicates (2)
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
/*
 *  combat.h - Combat scheduling.
 *
 *  Copyright (C) 2000-2022  The Exult Team
 *
 *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef COMBAT_H
#define COMBAT_H 1

#include "schedule.h"

#include <list>

class Actor;
class Game_object;
class Spellbook_object;

/*
 *  Combat schedule:
 */
class Combat_schedule : public Schedule {
public:
	enum Phase {            // We'll be a finite-state-machine.
		initial     = 0,    // Just constructed.
		approach    = 1,    // Approaching a foe to attack.
		retreat     = 2,    // Avoiding a foe.
		flee        = 3,    // Run away!
		strike      = 4,    // In the process of striking.
		fire        = 5,    // In process of firing range weapon.
		parry       = 6,    // In the process of parrying a blow.
		stunned     = 7,    // Just been hit.
		wait_return = 8     // Wait for boomerang.
	};

protected:
	static unsigned long        battle_time;        // Time when battle started.
	static unsigned long        battle_end_time;    // And when it ended.
	Phase                       state;
	Schedule_types              prev_schedule;      // Before going into combat.
	std::list<Game_object_weak> opponents;          // Possible opponents.
	Game_object*                practice_target;    // Only for duel schedule.
	Game_object*                weapon;
	int               weapon_shape;    // Weapon's shape in shapes.vga.
	Spellbook_object* spellbook;       // If readied.
	// Ranges in tiles.
	//   0 means not applicable.
	bool          no_blocking;       // Weapon/ammo goes through walls.
	unsigned char yelled;            // Yell when first opponent targeted.
	bool          started_battle;    // 1st opponent targeted.
	unsigned char fleed;             // Incremented when fleeing.
	bool          can_yell;
	int           failures;         // # failures to find opponent.
	unsigned int  teleport_time;    // Next time we can teleport.
	unsigned int  summon_time;
	unsigned int  invisible_time;
	unsigned int  dex_points;       // Need these to attack.
	unsigned int strike_blocked;    // # failures to get a clear path to strike.
	int          alignment;         // So we can tell if it changed.

	void         start_battle();    // Play music at start of battle.
	bool         teleport();        // For monsters that can.
	bool         summon();
	bool         be_invisible();
	virtual void find_opponents();
	// Find attacker of protected member.
	std::list<Game_object_weak>::iterator find_weakest_opponent();
	std::list<Game_object_weak>::iterator find_strongest_opponent();
	std::list<Game_object_weak>::iterator find_nearest_opponent();
	std::list<Game_object_weak>::iterator find_random_opponent();
	std::list<Game_object_weak>::iterator find_attacked_opponent();
	std::list<Game_object_weak>::iterator find_protected_attacker();
	Game_object* find_foe(int mode);    // Find a new opponent.
	Game_object* find_foe();
	// Back off when being attacked.
	static void back_off(Actor* npc, Game_object* attacker);
	void        approach_foe(bool for_projectile = false);    // Approach foe.
	void        wander_for_attack();
	void        start_strike();
	void        run_away();
	Spellbook_object* readied_spellbook();

public:
	Combat_schedule(Actor* n, Schedule_types prev_sched);
	static void monster_died();    // Checks for victory.
	static void stop_attacking_npc(Game_object* npc);
	static void stop_attacking_invisible(Game_object* npc);
	void        now_what() override;    // Npc calls this when it's done
	void im_dormant() override;         // Npc calls this when it goes dormant.
	void ending(int newtype) override;    // Switching to another schedule.
	void set_weapon(bool removed = false) override;    // Set weapon info.
	void set_hand_to_hand();

	bool has_started_battle() const {
		return started_battle;
	}

	void set_state(Phase s) {
		state = s;
	}

	static bool attack_target(
			Game_object* attacker, Game_object* target, const Tile_coord& tile,
			int weapon, bool combat = false);
	static bool is_enemy(int align, int other);
};

/*
 *  Dueling is like combat, but nobody gets hurt.
 */

class Duel_schedule : public Combat_schedule {
	Tile_coord start;      // Starting position.
	int        attacks;    // Count strikes.
	void       find_opponents() override;

public:
	Duel_schedule(Actor* n);
	void now_what() override;
};

bool In_ammo_family(int shnum, int family);    // Yow, a global function.

#endif