Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: e4ba19b7ad19178fb076f1fff698aef3ff264784 (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
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
/*
   base/patrol.h
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#ifndef __INCLUDED_BASE_PATROL_H__
#define __INCLUDED_BASE_PATROL_H__

#include "core/entity.h"
#include "base/faction.h"
#include "base/cargo.h"
#include "base/npc.h"
#include "base/npctype.h"

namespace game
{

/**
 * @brief a patrol entity manages a group of NPCs.
 * A Patrol instance is a server-side entity used to manage
 * a group of NPC ships. It manages group purpose, group commands
 * and respawning by giving orders to the member NPCs.
 * A Patrol can manage any kind of NPC group:
 * be it a patrol, a trade convoy or a player wing.
 * */
class Patrol: public core::Entity {

public:
	
	/* --- WayPoint -------------------------------------------- */
	
	/**
	 * @brief a node in the patrol's travel path
	 * */
	class WayPoint {
	public:
		WayPoint();
		~WayPoint();
		
		inline core::Entity *target()
		{
			return waypoint_target;
		}
		
		inline const std::string & target_label() const {
			return waypoint_target_label;
		}
		
		inline const bool dock() const {
			return waypoint_dock;
		}
		
		inline const Cargo *cargo() const {
			return waypoint_cargo;
		}
		
		void set_target(core::Entity *entity);
		
 		void set_target_label(const std::string &label);
		
		void set_cargo(Cargo *cargo);
		
		void set_dock(const bool dock);

	private:
		std::string	waypoint_target_label;
		
		core::Entity	*waypoint_target;
		
		Cargo		*waypoint_cargo;
		
		bool 		waypoint_dock;
	};
		
	/* --- Patrol ---------------------------------------------- */
	
	typedef std::list<WayPoint *> WayPoints;
	
	typedef std::list<NPCType *> NPCTypes;
	
	typedef std::list<NPC *> Members;
		
	Patrol();
	virtual ~Patrol();
	
	inline const NPC::Profile profile() const {
		return patrol_profile;
	}
	
	inline WayPoint * waypoint() const {
		if (patrol_waypoint_current == patrol_waypoints.end()) {
			return 0;
		} else {
			return (*patrol_waypoint_current);
		}
	}
	
	inline NPC *leader() const {
		return patrol_leader;
	}
	
	inline Faction *faction() const {
		return patrol_faction;
	}

	void set_profile(const NPC::Profile profile);
	
	void set_faction(Faction *faction);
	
	WayPoint *add_waypoint();
	
	NPCType *add_npctype();

	virtual void validate();
	
	virtual void frame(const unsigned long elapsed);
	
	void add_member(NPC *npc);
	
	void erase_member(NPC *npc);		

private:
	void set_leader();
	
	bool route_alive() const;
	
	WayPoints		patrol_waypoints;
	
	WayPoints::iterator	patrol_waypoint_current;
	
	Members			patrol_members;
	
	NPCTypes		patrol_npctypes;
	
	NPC::Profile		patrol_profile;
	
	NPC			*patrol_leader;
	
	unsigned long		patrol_launch_timeout;
	
	Faction			*patrol_faction;
};

} // namespace game

#endif // __INCLUDED_BASE_PATROL_H__