Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpPathfinder.cpp
Context not available. | |||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include "simulation2/helpers/Rasterize.h" | #include "simulation2/helpers/Rasterize.h" | ||||
#include "simulation2/serialization/SerializeTemplates.h" | #include "simulation2/serialization/SerializeTemplates.h" | ||||
#include "simulation2/components/ICmpPosition.h" | |||||
#include "simulation2/components/ICmpUnitMotion.h" | |||||
REGISTER_COMPONENT_TYPE(Pathfinder) | REGISTER_COMPONENT_TYPE(Pathfinder) | ||||
Context not available. | |||||
return it->second; | return it->second; | ||||
} | } | ||||
/** | |||||
* Assuming we're a ship, check if we're near the shore. | |||||
*/ | |||||
bool CCmpPathfinder::CheckNearShore(entity_id_t ent, fixed pickupRange) const | |||||
{ | |||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), ent); | |||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | |||||
return false; | |||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), ent); | |||||
if (!cmpUnitMotion) | |||||
return false; | |||||
CFixedVector2D pos = cmpPosition->GetPosition2D(); | |||||
fixed x = pos.X; | |||||
fixed z = pos.Y; | |||||
pass_class_t passClass = cmpUnitMotion->GetPassabilityClass(); | |||||
fixed hw = pickupRange; | |||||
// If we can move freely around the border of a square centered on the current position, then we're not on the shore. | |||||
bool test = Pathfinding::CheckLineMovement(x-hw, z-hw, x+hw, z-hw, passClass, *m_TerrainOnlyGrid) | |||||
&& Pathfinding::CheckLineMovement(x+hw, z-hw, x+hw, z+hw, passClass, *m_TerrainOnlyGrid) | |||||
&& Pathfinding::CheckLineMovement(x+hw, z+hw, x-hw, z+hw, passClass, *m_TerrainOnlyGrid) | |||||
&& Pathfinding::CheckLineMovement(x-hw, z+hw, x-hw, z-hw, passClass, *m_TerrainOnlyGrid); | |||||
return !test; | |||||
} | |||||
void CCmpPathfinder::GetPassabilityClasses(std::map<std::string, pass_class_t>& passClasses) const | void CCmpPathfinder::GetPassabilityClasses(std::map<std::string, pass_class_t>& passClasses) const | ||||
{ | { | ||||
passClasses = m_PassClassMasks; | passClasses = m_PassClassMasks; | ||||
Context not available. | |||||
vladislavbelov: Do not use count if you only search a value, use `reachable.find(landRegion) != reachable`. | |||||
Done Inline Actions... != reachable.end(). vladislavbelov: `... != reachable.end()`. | |||||
Done Inline ActionsUnecessary variable, you could just return a value: if (...) return true; // after loop return false; vladislavbelov: Unecessary variable, you could just return a value:
```lang=cpp
if (...)
return true;
//… | |||||
Done Inline ActionsSpaces around = and below too. vladislavbelov: Spaces around `=` and below too. | |||||
Done Inline ActionsCouldn't we replace set by unordered_set in future? vladislavbelov: Couldn't we replace `set` by `unordered_set` in future? | |||||
Not Done Inline ActionsI'd rather use cmpObstruction::GetSize for that. It would let players construct tunnels (which wouldn't have Motion) or something like that. wraitii: I'd rather use cmpObstruction::GetSize for that. It would let players construct tunnels (which… | |||||
Done Inline ActionsIt sounds like a stationary tunnel would work more like building garrison, so it wouldn't need to call this function. causative: It sounds like a stationary tunnel would work more like building garrison, so it wouldn't need… | |||||
Done Inline ActionsI think you should also check right under the "ship" entity, to make this function more general (again, thinking of the "Roc" use-case from AoM) wraitii: I think you should also check right under the "ship" entity, to make this function more general… |
Wildfire Games · Phabricator
Do not use count if you only search a value, use reachable.find(landRegion) != reachable.