Line data Source code
1 : /* Copyright (C) 2026 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_ICMPFOOTPRINT 19 : #define INCLUDED_ICMPFOOTPRINT 20 : 21 : #include "simulation2/helpers/Position.h" 22 : #include "simulation2/system/Component.h" 23 : #include "simulation2/system/Entity.h" 24 : #include "simulation2/system/Interface.h" 25 : 26 : #include <js/Value.h> 27 : 28 : class CFixedVector3D; 29 : 30 : /** 31 : * Footprints - an approximation of the entity's shape, used for collision detection and for 32 : * rendering selection outlines. 33 : * A footprint is either a circle (of some radius) or square (of some width and depth (actually 34 : * it's a rectangle)), horizontally aligned, extruded to a given height. 35 : */ 36 195 : class ICmpFootprint : public IComponent 37 : { 38 : public: 39 : enum EShape 40 : { 41 : CIRCLE, 42 : SQUARE 43 : }; 44 : 45 : /** 46 : * Return the shape of this footprint. 47 : * Shapes are horizontal circles or squares, extended vertically upwards to make cylinders or boxes. 48 : * @param[out] shape either CIRCLE or SQUARE 49 : * @param[out] size0 if CIRCLE then radius, else width (size in X axis) 50 : * @param[out] size1 if CIRCLE then radius, else depth (size in Z axis) 51 : * @param[out] height size in Y axis 52 : */ 53 : virtual void GetShape(EShape& shape, entity_pos_t& size0, entity_pos_t& size1, entity_pos_t& height) const = 0; 54 : 55 : /** 56 : * GetShape wrapper for script calls. 57 : * Returns { "type": "circle", "radius": 5.0, "height": 1.0 } 58 : * or { "type": "square", "width": 5.0, "depth": 5.0, "height": 1.0 } 59 : */ 60 : JS::Value GetShape_wrapper() const; 61 : 62 : /** 63 : * Pick a sensible position to place a newly-spawned entity near this footprint, 64 : * such that it won't be in an invalid (obstructed) location regardless of the spawned unit's 65 : * orientation. 66 : * @return the X and Z coordinates of the spawn point, with Y = 0; or the special value (-1, -1, -1) if there's no space 67 : */ 68 : virtual CFixedVector3D PickSpawnPoint(entity_id_t spawned) const = 0; 69 : 70 : /** 71 : * Pick a sensible position to place a newly-spawned entity near this footprint, 72 : * at the intersection between the footprint passability and the entity one. 73 : * @return the X and Z coordinates of the spawn point, with Y = 0; or the special value (-1, -1, -1) if there's no space 74 : */ 75 : virtual CFixedVector3D PickSpawnPointBothPass(entity_id_t spawned) const = 0; 76 : 77 : /** 78 : * Get the grid tiles covered by this footprint: every tile whose center lies inside 79 : * the footprint (boundary included), plus the tile containing the entity position, 80 : * which is always included. 81 : * @param tileSize The size of each tile in world units. 82 : * @param tilesW Width of the grid. 83 : * @param tilesH Height of the grid. 84 : * @param[out] tiles Vector to fill with (i, j) tile coordinates covered by the footprint. 85 : * The vector is cleared before being filled. Reusing a caller-provided 86 : * vector avoids per-entity allocations when processing many entities. 87 : */ 88 : virtual void GetGridTiles( 89 : const entity_pos_t& tileSize, 90 : const std::uint16_t tilesW, 91 : const std::uint16_t tilesH, 92 : std::vector<std::pair<std::uint16_t, std::uint16_t>>& tiles) const = 0; 93 : 94 2 : DECLARE_INTERFACE_TYPE(Footprint) 95 : }; 96 : 97 : #endif // INCLUDED_ICMPFOOTPRINT