Ticket #1833: faceTowardsPoint.diff
File faceTowardsPoint.diff, 5.2 KB (added by , 11 years ago) |
---|
-
source/simulation2/components/ICmpUnitMotion.cpp
35 35 DEFINE_INTERFACE_METHOD_0("IsMoving", bool, ICmpUnitMotion, IsMoving) 36 36 DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed) 37 37 DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed) 38 DEFINE_INTERFACE_METHOD_1("SetFacePointAfterMove", void, ICmpUnitMotion, SetFacePointAfterMove, bool) 38 39 DEFINE_INTERFACE_METHOD_1("SetUnitRadius", void, ICmpUnitMotion, SetUnitRadius, fixed) 39 40 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool) 40 41 END_INTERFACE_WRAPPER(UnitMotion) … … 104 105 return m_Script.Call<fixed>("GetRunSpeed"); 105 106 } 106 107 108 virtual void SetFacePointAfterMove(bool facePointAfterMove) 109 { 110 m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove); 111 } 112 107 113 virtual ICmpPathfinder::pass_class_t GetPassabilityClass() 108 114 { 109 115 return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass"); -
source/simulation2/components/CCmpUnitMotion.cpp
129 129 130 130 entity_pos_t m_Radius; 131 131 bool m_Moving; 132 bool m_FacePointAfterMove; 132 133 133 134 enum State 134 135 { … … 281 282 m_FormationController = paramNode.GetChild("FormationController").ToBool(); 282 283 283 284 m_Moving = false; 285 m_FacePointAfterMove = true; 286 284 287 m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed(); 285 288 m_Speed = m_WalkSpeed; 286 289 m_CurSpeed = fixed::Zero(); … … 342 345 serialize.NumberFixed_Unbounded("speed", m_Speed); 343 346 344 347 serialize.Bool("moving", m_Moving); 348 serialize.Bool("facePointAfterMove", m_FacePointAfterMove); 345 349 346 350 SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints); 347 351 SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints); … … 428 432 m_Speed = speed; 429 433 } 430 434 435 virtual void SetFacePointAfterMove(bool facePointAfterMove) 436 { 437 m_FacePointAfterMove = facePointAfterMove; 438 } 439 431 440 virtual void SetDebugOverlay(bool enabled) 432 441 { 433 442 m_DebugOverlayEnabled = enabled; … … 963 972 964 973 StopMoving(); 965 974 966 FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); 975 976 if (m_FacePointAfterMove) 977 FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); 967 978 // TODO: if the goal was a square building, we ought to point towards the 968 979 // nearest point on the square, not towards its center 969 980 } … … 1312 1323 else 1313 1324 { 1314 1325 // We're already in range - no need to move anywhere 1315 FaceTowardsPointFromPos(pos, x, z); 1326 if (m_FacePointAfterMove) 1327 FaceTowardsPointFromPos(pos, x, z); 1316 1328 return false; 1317 1329 } 1318 1330 … … 1474 1486 else if (maxRange < entity_pos_t::Zero() || distance < maxRange) 1475 1487 { 1476 1488 // We're already in range - no need to move anywhere 1477 FaceTowardsPointFromPos(pos, goal.x, goal.z); 1489 if (m_FacePointAfterMove) 1490 FaceTowardsPointFromPos(pos, goal.x, goal.z); 1478 1491 return false; 1479 1492 } 1480 1493 else … … 1496 1509 if (circleDistance < maxRange) 1497 1510 { 1498 1511 // We're already in range - no need to move anywhere 1499 FaceTowardsPointFromPos(pos, goal.x, goal.z); 1512 if (m_FacePointAfterMove) 1513 FaceTowardsPointFromPos(pos, goal.x, goal.z); 1500 1514 return false; 1501 1515 } 1502 1516 -
source/simulation2/components/ICmpUnitMotion.h
110 110 virtual fixed GetRunSpeed() = 0; 111 111 112 112 /** 113 * Set the FaceTowardsPoint after the move 114 */ 115 virtual void SetFacePointAfterMove(bool facePointAfterMove) = 0; 116 117 /** 113 118 * Get the unit's passability class. 114 119 */ 115 120 virtual ICmpPathfinder::pass_class_t GetPassabilityClass() = 0; -
binaries/data/mods/public/simulation/components/UnitAI.js
2431 2431 this.MoveRandomly(+this.template.RoamDistance); 2432 2432 // Set a random timer to switch to feeding state 2433 2433 this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); 2434 this.SetFacePointAfterMove(false); 2434 2435 }, 2435 2436 2436 2437 "leave": function() { 2437 2438 this.StopTimer(); 2439 this.SetFacePointAfterMove(true); 2438 2440 }, 2439 2441 2440 2442 "LosRangeUpdate": function(msg) { … … 4583 4585 cmpMotion.MoveToPointRange(tx, tz, distance, distance); 4584 4586 }; 4585 4587 4588 UnitAI.prototype.SetFacePointAfterMove = function(val) 4589 { 4590 var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); 4591 if (cmpMotion) 4592 cmpMotion.SetFacePointAfterMove(val); 4593 }; 4594 4586 4595 UnitAI.prototype.AttackEntitiesByPreference = function(ents) 4587 4596 { 4588 4597 var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);