Line data Source code
1 : /* Copyright (C) 2021 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #ifndef INCLUDED_ICMPOBSTRUCTION
19 : #define INCLUDED_ICMPOBSTRUCTION
20 :
21 : #include "simulation2/system/Interface.h"
22 :
23 : #include "simulation2/components/ICmpObstructionManager.h"
24 :
25 : /**
26 : * Flags an entity as obstructing movement for other units,
27 : * and handles the processing of collision queries.
28 : */
29 14 : class ICmpObstruction : public IComponent
30 : {
31 : public:
32 :
33 : enum EFoundationCheck {
34 : FOUNDATION_CHECK_SUCCESS,
35 : FOUNDATION_CHECK_FAIL_ERROR,
36 : FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION,
37 : FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION,
38 : FOUNDATION_CHECK_FAIL_TERRAIN_CLASS
39 : };
40 :
41 : enum EObstructionType {
42 : STATIC,
43 : UNIT,
44 : CLUSTER
45 : };
46 :
47 : virtual ICmpObstructionManager::tag_t GetObstruction() const = 0;
48 :
49 : /**
50 : * Gets the square corresponding to this obstruction shape.
51 : * @return true and updates @p out on success;
52 : * false on failure (e.g. object not in the world).
53 : */
54 : virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) const = 0;
55 :
56 : /**
57 : * Same as the method above, but returns an obstruction shape for the previous turn
58 : */
59 : virtual bool GetPreviousObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) const = 0;
60 :
61 : /**
62 : * @return the size of the obstruction (either the clearance or a circumscribed circle).
63 : */
64 : virtual entity_pos_t GetSize() const = 0;
65 :
66 : /**
67 : * @return the size of the static obstruction or (0,0) for a unit shape.
68 : */
69 : virtual CFixedVector2D GetStaticSize() const = 0;
70 :
71 : virtual EObstructionType GetObstructionType() const = 0;
72 :
73 : virtual void SetUnitClearance(const entity_pos_t& clearance) = 0;
74 :
75 : virtual bool IsControlPersistent() const = 0;
76 :
77 : /**
78 : * Test whether the front of the obstruction square is in the water and the back is on the shore.
79 : */
80 : virtual bool CheckShorePlacement() const = 0;
81 :
82 : /**
83 : * Test whether this entity is colliding with any obstruction that are set to
84 : * block the creation of foundations.
85 : * @param ignoredEntities List of entities to ignore during the test.
86 : * @return FOUNDATION_CHECK_SUCCESS if check passes, else an EFoundationCheck
87 : * value describing the type of failure.
88 : */
89 : virtual EFoundationCheck CheckFoundation(const std::string& className) const = 0;
90 : virtual EFoundationCheck CheckFoundation(const std::string& className, bool onlyCenterPoint) const = 0;
91 :
92 : /**
93 : * CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck.
94 : * @return "success" if check passes, else a string describing the type of failure.
95 : */
96 : virtual std::string CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint) const;
97 :
98 : /**
99 : * Test whether this entity is colliding with any obstructions that share its
100 : * control groups and block the creation of foundations.
101 : * @return true if foundation is valid (not obstructed)
102 : */
103 : virtual bool CheckDuplicateFoundation() const = 0;
104 :
105 : /**
106 : * Returns a list of entities that have an obstruction matching the given flag and intersect the current obstruction.
107 : * @return vector of blocking entities
108 : */
109 : virtual std::vector<entity_id_t> GetEntitiesByFlags(ICmpObstructionManager::flags_t flags) const = 0;
110 :
111 : /**
112 : * Returns a list of entities that are blocking movement.
113 : * @return vector of blocking entities
114 : */
115 : virtual std::vector<entity_id_t> GetEntitiesBlockingMovement() const = 0;
116 :
117 : /**
118 : * Returns a list of entities that are blocking construction of a foundation.
119 : * @return vector of blocking entities
120 : */
121 : virtual std::vector<entity_id_t> GetEntitiesBlockingConstruction() const = 0;
122 :
123 : /**
124 : * Returns a list of entities that shall be deleted when a construction on this obstruction starts,
125 : * for example sheep carcasses.
126 : */
127 : virtual std::vector<entity_id_t> GetEntitiesDeletedUponConstruction() const = 0;
128 :
129 : /**
130 : * Detects collisions between foundation-blocking entities and
131 : * tries to fix them by setting control groups, if appropriate.
132 : */
133 : virtual void ResolveFoundationCollisions() const = 0;
134 :
135 : virtual void SetActive(bool active) = 0;
136 :
137 : virtual void SetMovingFlag(bool enabled) = 0;
138 :
139 : virtual void SetDisableBlockMovementPathfinding(bool movementDisabled, bool pathfindingDisabled, int32_t shape) = 0;
140 :
141 : /**
142 : * @param templateOnly - whether to return the raw template value or the current value.
143 : */
144 : virtual bool GetBlockMovementFlag(bool templateOnly) const = 0;
145 :
146 : /**
147 : * Change the control group that the entity belongs to.
148 : * Control groups are used to let units ignore collisions with other units from
149 : * the same group. Default is the entity's own ID.
150 : */
151 : virtual void SetControlGroup(entity_id_t group) = 0;
152 :
153 : /// See SetControlGroup.
154 : virtual entity_id_t GetControlGroup() const = 0;
155 :
156 : virtual void SetControlGroup2(entity_id_t group2) = 0;
157 : virtual entity_id_t GetControlGroup2() const = 0;
158 :
159 181 : DECLARE_INTERFACE_TYPE(Obstruction)
160 : };
161 :
162 : #endif // INCLUDED_ICMPOBSTRUCTION
|