1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_NODE_H
20 #define OPENXCOM_NODE_H
21 
22 #include "../Battlescape/Position.h"
23 #include <yaml-cpp/yaml.h>
24 
25 namespace OpenXcom
26 {
27 
28 enum NodeRank{NR_SCOUT=0, NR_XCOM, NR_SOLDIER, NR_NAVIGATOR, NR_LEADER, NR_ENGINEER, NR_MISC1, NR_MEDIC, NR_MISC2};
29 
30 /**
31  * Represents a node/spawnpoint in the battlescape, loaded from RMP files.
32  * @sa http://www.ufopaedia.org/index.php?title=ROUTES
33  */
34 class Node
35 {
36 private:
37 	int _id;
38 	Position _pos;
39 	int _segment;
40 	std::vector<int> _nodeLinks;
41 	int _type;
42 	int _rank;
43 	int _flags;
44 	int _reserved;
45 	int _priority;
46 	bool _allocated;
47 public:
48 	static const int CRAFTSEGMENT = 1000;
49 	static const int UFOSEGMENT = 2000;
50 	static const int TYPE_FLYING = 0x01; // non-flying unit can not spawn here when this bit is set
51 	static const int TYPE_SMALL = 0x02; // large unit can not spawn here when this bit is set
52 	static const int TYPE_DANGEROUS = 0x04; // an alien was shot here, stop patrolling to it like an idiot with a death wish
53 	static const int nodeRank[8][7]; // maps alien ranks to node (.RMP) ranks
54 	/// Creates a Node.
55 	Node();
56 	Node(int id, Position pos, int segment, int type, int rank, int flags, int reserved, int priority);
57 	/// Cleans up the Node.
58 	~Node();
59 	/// Loads the node from YAML.
60 	void load(const YAML::Node& node);
61 	/// Saves the node to YAML.
62 	YAML::Node save() const;
63 	/// get the node's id
64 	int getID() const;
65 	/// get the node's paths
66 	std::vector<int> *getNodeLinks();
67 	/// Gets node's rank.
68 	NodeRank getRank() const;
69 	/// Gets node's priority.
70 	int getPriority() const;
71 	/// Gets the node's position.
72 	const Position& getPosition() const;
73 	/// Gets the node's segment.
74 	int getSegment() const;
75 	/// Gets the node's type.
76 	int getType() const;
77 	/// Sets the node's type, surprisingly
78 	void setType(int type);
79 	/// gets "flags" variable, which is really the patrolling desirability value
getFlags()80 	int getFlags() { return _flags; }
81 	/// compares the _flags variables of the nodes (for the purpose of patrol decisions!)
82 	bool operator<(Node &b) { return _flags < b.getFlags(); };
83 	bool isAllocated() const;
84 	void allocateNode();
85 	void freeNode();
86 	bool isTarget() const;
87 
88 };
89 
90 }
91 
92 #endif
93