Ticket #1537: chasing.6.diff
File chasing.6.diff, 11.7 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
1706 1706 // Check the target is still alive and attackable 1707 1707 if (this.TargetIsAlive(target) && this.CanAttack(target, this.order.data.forceResponse || null)) 1708 1708 { 1709 // Check we can still reach the target1710 if (this. CheckTargetAttackRange(target, IID_Attack, this.order.data.attackType))1709 // If we are hunting, first update the target position of the gather order so we know where will be the killed animal 1710 if (this.order.data.hunting && this.orderQueue[1] && this.orderQueue[1].data.lastPos) 1711 1711 { 1712 // If we are hunting, first update the target position of the gather order so we know where will be the killed animal1713 if ( this.order.data.hunting && this.orderQueue[1] && this.orderQueue[1].data.lastPos)1712 var cmpPosition = Engine.QueryInterface(this.order.data.target, IID_Position); 1713 if (cmpPosition && cmpPosition.IsInWorld()) 1714 1714 { 1715 var cmpPosition = Engine.QueryInterface(this.order.data.target, IID_Position); 1716 if (cmpPosition && cmpPosition.IsInWorld()) 1717 { 1718 // Store the initial position, so that we can find the rest of the herd later 1719 if (!this.orderQueue[1].data.initPos) 1720 this.orderQueue[1].data.initPos = this.orderQueue[1].data.lastPos; 1721 this.orderQueue[1].data.lastPos = cmpPosition.GetPosition(); 1722 // We still know where the animal is, so we shouldn't give up before going there 1723 this.orderQueue[1].data.secondTry = undefined; 1724 } 1715 // Store the initial position, so that we can find the rest of the herd later 1716 if (!this.orderQueue[1].data.initPos) 1717 this.orderQueue[1].data.initPos = this.orderQueue[1].data.lastPos; 1718 this.orderQueue[1].data.lastPos = cmpPosition.GetPosition(); 1719 // We still know where the animal is, so we shouldn't give up before going there 1720 this.orderQueue[1].data.secondTry = undefined; 1725 1721 } 1722 } 1726 1723 1727 1728 1724 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 1725 this.lastAttacked = cmpTimer.GetTime() - msg.lateness; 1729 1726 1730 1731 1732 1727 this.FaceTowardsTarget(target); 1728 var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); 1729 cmpAttack.PerformAttack(this.order.data.attackType, target); 1733 1730 1731 1732 // Check we can still reach the target for the next attack 1733 if (this.CheckTargetAttackRange(target, IID_Attack, this.order.data.attackType)) 1734 { 1734 1735 if (this.resyncAnimation) 1735 1736 { 1736 1737 this.SetAnimationSync(this.attackTimers.repeat, this.attackTimers.repeat); -
binaries/data/mods/public/simulation/templates/template_unit_cavalry_ranged.xml
11 11 <Pierce>10.0</Pierce> 12 12 <Crush>0.0</Crush> 13 13 <MaxRange>16.0</MaxRange> 14 <MinRange> 0.0</MinRange>14 <MinRange>20.0</MinRange> 15 15 <ProjectileSpeed>25.0</ProjectileSpeed> 16 16 <PrepareTime>900</PrepareTime> 17 17 <RepeatTime>1500</RepeatTime> -
binaries/data/mods/public/simulation/templates/template_unit_cavalry_ranged_archer.xml
6 6 <Pierce>20.0</Pierce> 7 7 <Crush>0.0</Crush> 8 8 <MaxRange>56.0</MaxRange> 9 <MinRange>0.0</MinRange>10 9 <ProjectileSpeed>75.0</ProjectileSpeed> 11 10 <PrepareTime>1200</PrepareTime> 12 11 <RepeatTime>2000</RepeatTime> -
binaries/data/mods/public/simulation/templates/template_unit_cavalry_ranged_javelinist.xml
6 6 <Pierce>25.0</Pierce> 7 7 <Crush>0.0</Crush> 8 8 <MaxRange>44</MaxRange> 9 <MinRange>0.0</MinRange>10 9 <ProjectileSpeed>50.0</ProjectileSpeed> 11 10 <PrepareTime>1200</PrepareTime> 12 11 <RepeatTime>2000</RepeatTime> -
source/simulation2/components/CCmpObstruction.cpp
442 442 return m_Tag; 443 443 } 444 444 445 virtual bool GetPreviousObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) 446 { 447 return GetObstructionSquare(out, true); 448 } 449 445 450 virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) 446 451 { 452 return GetObstructionSquare(out, false); 453 } 454 455 virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out, bool previousPosition) 456 { 447 457 CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); 448 458 if (!cmpPosition) 449 459 return false; // error … … 455 465 if (!cmpPosition->IsInWorld()) 456 466 return false; // no obstruction square 457 467 458 CFixedVector2D pos = cmpPosition->GetPosition2D(); 468 CFixedVector2D pos; 469 if (previousPosition) 470 pos = cmpPosition->GetPreviousPosition2D(); 471 else 472 pos = cmpPosition->GetPosition2D(); 459 473 if (m_Type == STATIC) 460 474 out = cmpObstructionManager->GetStaticShapeObstruction(pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1); 461 475 else if (m_Type == UNIT) -
source/simulation2/components/CCmpUnitMotion.cpp
107 107 static const CColor OVERLAY_COLOUR_LONG_PATH(1, 1, 1, 1); 108 108 static const CColor OVERLAY_COLOUR_SHORT_PATH(1, 0, 0, 1); 109 109 110 static const entity_pos_t g_GoalDelta = entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/ 4; // for extending the goal outwards/inwards a little bit110 static const entity_pos_t g_GoalDelta = entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/2; // for extending the goal outwards/inwards a little bit 111 111 112 112 class CCmpUnitMotion : public ICmpUnitMotion 113 113 { … … 995 995 } 996 996 else 997 997 { 998 // check if target was reached in case of a moving target 999 CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_TargetEntity); 1000 if 1001 ( 1002 cmpUnitMotion && 1003 cmpUnitMotion->IsMoving() && 1004 MoveToTargetRange(m_TargetEntity, m_TargetMinRange, m_TargetMaxRange) 1005 ) 1006 return; 1007 998 1008 // Not in formation, so just finish moving 999 1000 1009 StopMoving(); 1010 m_State = STATE_IDLE; 1011 MoveSucceeded(); 1001 1012 1002 1003 1013 if (m_FacePointAfterMove) 1004 1014 FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); 1005 1015 // TODO: if the goal was a square building, we ought to point towards the … … 1508 1518 1509 1519 entity_pos_t distance = Geometry::DistanceToSquare(pos - CFixedVector2D(obstruction.x, obstruction.z), obstruction.u, obstruction.v, halfSize); 1510 1520 1511 if (distance < minRange) 1521 // compare with previous obstruction 1522 ICmpObstructionManager::ObstructionSquare previousObstruction; 1523 cmpObstruction->GetPreviousObstructionSquare(previousObstruction); 1524 entity_pos_t previousDistance = Geometry::DistanceToSquare(pos - CFixedVector2D(previousObstruction.x, previousObstruction.z), obstruction.u, obstruction.v, halfSize); 1525 1526 if (distance < minRange && previousDistance < minRange) 1512 1527 { 1513 1528 // Too close to the square - need to move away 1514 1529 … … 1523 1538 goal.hw = obstruction.hw + delta; 1524 1539 goal.hh = obstruction.hh + delta; 1525 1540 } 1526 else if (maxRange < entity_pos_t::Zero() || distance < maxRange )1541 else if (maxRange < entity_pos_t::Zero() || distance < maxRange || previousDistance < maxRange) 1527 1542 { 1528 1543 // We're already in range - no need to move anywhere 1529 1544 if (m_FacePointAfterMove) … … 1554 1569 return false; 1555 1570 } 1556 1571 1572 entity_pos_t previousCircleDistance = (pos - CFixedVector2D(previousObstruction.x, previousObstruction.z)).Length() - circleRadius; 1573 1574 if (previousCircleDistance < maxRange) 1575 { 1576 // We're already in range - no need to move anywhere 1577 if (m_FacePointAfterMove) 1578 FaceTowardsPointFromPos(pos, goal.x, goal.z); 1579 return false; 1580 } 1581 1582 1557 1583 entity_pos_t goalDistance = maxRange - g_GoalDelta; 1558 1584 1559 1585 goal.type = ICmpPathfinder::Goal::CIRCLE; … … 1626 1652 CFixedVector2D halfSize(obstruction.hw, obstruction.hh); 1627 1653 entity_pos_t distance = Geometry::DistanceToSquare(pos - CFixedVector2D(obstruction.x, obstruction.z), obstruction.u, obstruction.v, halfSize); 1628 1654 1655 // compare with previous obstruction 1656 ICmpObstructionManager::ObstructionSquare previousObstruction; 1657 cmpObstruction->GetPreviousObstructionSquare(previousObstruction); 1658 entity_pos_t previousDistance = Geometry::DistanceToSquare(pos - CFixedVector2D(previousObstruction.x, previousObstruction.z), obstruction.u, obstruction.v, halfSize); 1659 1629 1660 // See if we're too close to the target square 1630 if (distance < minRange )1661 if (distance < minRange && previousDistance < minRange) 1631 1662 return false; 1632 1663 1633 1664 // See if we're close enough to the target square 1634 if (maxRange < entity_pos_t::Zero() || distance <= maxRange )1665 if (maxRange < entity_pos_t::Zero() || distance <= maxRange || previousDistance <= maxRange) 1635 1666 return true; 1636 1667 1637 1668 entity_pos_t circleRadius = halfSize.Length(); … … 1645 1676 1646 1677 if (circleDistance <= maxRange) 1647 1678 return true; 1679 // also check circle around previous position 1680 circleDistance = (pos - CFixedVector2D(previousObstruction.x, previousObstruction.z)).Length() - circleRadius; 1681 1682 if (circleDistance <= maxRange) 1683 return true; 1648 1684 } 1649 1685 1650 1686 return false; … … 1655 1691 if (!cmpTargetPosition || !cmpTargetPosition->IsInWorld()) 1656 1692 return false; 1657 1693 1658 CFixedVector2D targetPos = cmpTargetPosition->GetP osition2D();1694 CFixedVector2D targetPos = cmpTargetPosition->GetPreviousPosition2D(); 1659 1695 1660 1696 entity_pos_t distance = (pos - targetPos).Length(); 1661 1697 1662 if (minRange <= distance && (maxRange < entity_pos_t::Zero() || distance <= maxRange)) 1663 return true; 1664 1665 return false; 1698 return minRange <= distance && 1699 (maxRange < entity_pos_t::Zero() || distance <= maxRange); 1666 1700 } 1667 1701 } 1668 1702 -
source/simulation2/components/ICmpObstruction.h
47 47 */ 48 48 virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) = 0; 49 49 50 /** 51 * Same as the method above, but returns an obstruction shape for the previous turn 52 */ 53 virtual bool GetPreviousObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) = 0; 54 50 55 virtual entity_pos_t GetUnitRadius() = 0; 51 56 52 57 virtual bool IsControlPersistent() = 0;