Skip to content

Commit

Permalink
Equipped items can now affect attack range
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Jan 9, 2019
1 parent 5698700 commit d79b571
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 56 deletions.
32 changes: 1 addition & 31 deletions src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ void AnimateActionAttack(CUnit &unit, COrder &order)
//Wyrmgus end
// Removed, Dying handled by action routine.
order->SetGoal(&target);
//Wyrmgus start
// order->Range = attacker.Stats->Variables[ATTACKRANGE_INDEX].Max;
order->Range = attacker.GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
order->MinRange = attacker.Type->MinAttackRange;
if (attacker.Player->AiEnabled && attacker.Variable[SPEED_INDEX].Value > target.Variable[SPEED_INDEX].Value && attacker.GetModifiedVariable(ATTACKRANGE_INDEX) > target.GetModifiedVariable(ATTACKRANGE_INDEX)) { //makes fast AI ranged units move away from slower targets that have smaller range
order->MinRange = attacker.GetModifiedVariable(ATTACKRANGE_INDEX);
Expand Down Expand Up @@ -158,11 +155,8 @@ void AnimateActionAttack(CUnit &unit, COrder &order)
//Wyrmgus end
// FIXME: look into action_attack.cpp about this ugly problem
order->goalPos = dest;
//Wyrmgus start
order->MapLayer = z;
// order->Range = attacker.Stats->Variables[ATTACKRANGE_INDEX].Max;
order->Range = attacker.GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
order->MinRange = attacker.Type->MinAttackRange;
} else {
order->goalPos = dest;
Expand All @@ -183,9 +177,7 @@ void AnimateActionAttack(CUnit &unit, COrder &order)
order->goalPos = dest;
//Wyrmgus start
order->MapLayer = z;
// order->Range = attacker.Stats->Variables[ATTACKRANGE_INDEX].Max;
order->Range = attacker.GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
order->MinRange = attacker.Type->MinAttackRange;

return order;
Expand Down Expand Up @@ -446,10 +438,7 @@ bool COrder_Attack::CheckForTargetInRange(CUnit &unit)
if (unit.Player->AiEnabled && unit.Variable[SPEED_INDEX].Value > goal->Variable[SPEED_INDEX].Value && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > goal->GetModifiedVariable(ATTACKRANGE_INDEX)) { //makes fast AI ranged units move away from slower targets that have smaller range
this->MinRange = unit.GetModifiedVariable(ATTACKRANGE_INDEX);
}
//Wyrmgus start
// this->Range = unit.Stats->Variables[ATTACKRANGE_INDEX].Max;
this->Range = unit.GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
this->goalPos = goal->tilePos;
this->MapLayer = goal->MapLayer->ID;
this->State |= WEAK_TARGET; // weak target
Expand Down Expand Up @@ -523,10 +512,7 @@ void COrder_Attack::MoveToTarget(CUnit &unit)
// Look if we have reached the target.
if (err == 0 && !this->HasGoal()) {
// Check if we're in range when attacking a location and we are waiting
//Wyrmgus start
// if (unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
if (unit.MapDistanceTo(this->goalPos, this->MapLayer) <= unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
//Wyrmgus end
//Wyrmgus start
// if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) {
if (!Map.IsLayerUnderground(MapLayer) || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldAirUnpassable, MapLayer)) {
Expand All @@ -544,10 +530,7 @@ void COrder_Attack::MoveToTarget(CUnit &unit)
if (err == PF_REACHED) {
CUnit *goal = this->GetGoal();
// Have reached target? FIXME: could use the new return code?
//Wyrmgus start
// if (goal && unit.MapDistanceTo(*goal) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
if (goal && unit.MapDistanceTo(*goal) <= unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
//Wyrmgus end
//Wyrmgus start
// if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) {
if (!Map.IsLayerUnderground(this->MapLayer) || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldAirUnpassable, MapLayer)) {
Expand Down Expand Up @@ -579,10 +562,7 @@ void COrder_Attack::MoveToTarget(CUnit &unit)
// || (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround)))
|| (!goal && (this->Action == UnitActionAttackGround || Map.WallOnMap(this->goalPos, this->MapLayer))))
//Wyrmgus end
//Wyrmgus start
// && unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
&& unit.MapDistanceTo(this->goalPos, this->MapLayer) <= unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
//Wyrmgus end
//Wyrmgus start
// if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) {
if (!Map.IsLayerUnderground(this->MapLayer) || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldAirUnpassable, MapLayer)) {
Expand Down Expand Up @@ -701,10 +681,7 @@ void COrder_Attack::AttackTarget(CUnit &unit)
if (unit.Player->AiEnabled && unit.Variable[SPEED_INDEX].Value > goal->Variable[SPEED_INDEX].Value && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > goal->GetModifiedVariable(ATTACKRANGE_INDEX)) { //makes fast AI ranged units move away from slower targets that have smaller range
this->MinRange = unit.GetModifiedVariable(ATTACKRANGE_INDEX);
}
//Wyrmgus start
// this->Range = unit.Stats->Variables[ATTACKRANGE_INDEX].Max;
this->Range = unit.GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
this->State |= WEAK_TARGET;

// Have a weak target, try a better target.
Expand All @@ -731,10 +708,7 @@ void COrder_Attack::AttackTarget(CUnit &unit)

// Still near to target, if not goto target.
const int dist = unit.MapDistanceTo(*goal);
//Wyrmgus start
// if (dist > unit.Stats->Variables[ATTACKRANGE_INDEX].Max
if (dist > unit.GetModifiedVariable(ATTACKRANGE_INDEX)
//Wyrmgus end
//Wyrmgus start
// || (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, goal->tilePos, MapFieldRocks | MapFieldForest) == false)) {
|| (Map.IsLayerUnderground(this->MapLayer) && CheckObstaclesBetweenTiles(unit.tilePos, goal->tilePos, MapFieldAirUnpassable, MapLayer) == false)) {
Expand Down Expand Up @@ -840,9 +814,8 @@ void COrder_Attack::AttackTarget(CUnit &unit)
const int dist = goal.MapDistanceTo(unit);

if (unit.Type->MinAttackRange < dist &&
//Wyrmgus start
// dist <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
dist <= unit.GetModifiedVariable(ATTACKRANGE_INDEX)
//Wyrmgus start
&& !(unit.Player->AiEnabled && dist < unit.GetModifiedVariable(ATTACKRANGE_INDEX) && unit.Variable[SPEED_INDEX].Value > goal.Variable[SPEED_INDEX].Value && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > goal.GetModifiedVariable(ATTACKRANGE_INDEX)) //makes fast AI ranged units move away from slower targets that have smaller range
) {
//Wyrmgus end
Expand Down Expand Up @@ -873,10 +846,7 @@ void COrder_Attack::AttackTarget(CUnit &unit)
}
//Wyrmgus start
// add instance for attack ground without moving
//Wyrmgus start
// } else if (this->Action == UnitActionAttackGround && unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
} else if (this->Action == UnitActionAttackGround && unit.MapDistanceTo(this->goalPos, this->MapLayer) <= unit.GetModifiedVariable(ATTACKRANGE_INDEX) && unit.Type->MinAttackRange < unit.MapDistanceTo(this->goalPos, this->MapLayer)) {
//Wyrmgus end
if (!Map.IsLayerUnderground(this->MapLayer) || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldAirUnpassable, MapLayer)) {
// Reached wall or ground, now attacking it
unsigned char oldDir = unit.Direction;
Expand Down
6 changes: 0 additions & 6 deletions src/action/action_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ class IsTargetInRange
bool IsDistanceCorrect(int distance) const
{
return attacker->Type->MinAttackRange < distance
//Wyrmgus start
// && distance <= attacker->Stats->Variables[ATTACKRANGE_INDEX].Max;
&& distance <= attacker->GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end
}
private:
const CUnit *attacker;
Expand Down Expand Up @@ -444,10 +441,7 @@ bool COrder_Still::AutoAttackStand(CUnit &unit)
}
// If unit is removed, use container's x and y
const CUnit *firstContainer = unit.GetFirstContainer();
//Wyrmgus start
// if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
//Wyrmgus end
return false;
}
//Wyrmgus start
Expand Down
3 changes: 0 additions & 3 deletions src/animation/animation_spawnmissile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@
Vec2i destTilePos = Map.MapPixelPosToTilePos(dest, unit.MapLayer->ID);
const int dist = goal->MapDistanceTo(destTilePos, unit.MapLayer->ID);
if ((flags & SM_Ranged) && !(flags & SM_Pixel)
//Wyrmgus start
// && dist > goal->Stats->Variables[ATTACKRANGE_INDEX].Max
&& dist > goal->GetModifiedVariable(ATTACKRANGE_INDEX)
//Wyrmgus end
&& dist < goal->Type->MinAttackRange) {
} else {
Missile *missile = MakeMissile(*mtype, start, dest, unit.MapLayer->ID);
Expand Down
9 changes: 6 additions & 3 deletions src/stratagus/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ std::string GetItemEffectsString(const std::string &item_ident)
|| var == AIRRESISTANCE_INDEX || var == EARTHRESISTANCE_INDEX || var == WATERRESISTANCE_INDEX || var == ACIDRESISTANCE_INDEX
|| var == HACKRESISTANCE_INDEX || var == PIERCERESISTANCE_INDEX || var == BLUNTRESISTANCE_INDEX
|| var == ACCURACY_INDEX || var == EVASION_INDEX || var == SPEED_INDEX || var == CHARGEBONUS_INDEX || var == BACKSTAB_INDEX
|| var == HITPOINTHEALING_INDEX || var == HITPOINTBONUS_INDEX || var == SIGHTRANGE_INDEX || var == DAYSIGHTRANGEBONUS_INDEX || var == NIGHTSIGHTRANGEBONUS_INDEX || var == HP_INDEX || var == MANA_INDEX)
|| var == HITPOINTHEALING_INDEX || var == HITPOINTBONUS_INDEX || var == SIGHTRANGE_INDEX || var == DAYSIGHTRANGEBONUS_INDEX || var == NIGHTSIGHTRANGEBONUS_INDEX || var == HP_INDEX || var == MANA_INDEX
|| var == ATTACKRANGE_INDEX)
) {
continue;
}
Expand Down Expand Up @@ -610,7 +611,8 @@ std::string GetUniqueItemEffectsString(const std::string &item_ident)
|| var == GIVERESOURCE_INDEX || var == TIMEEFFICIENCYBONUS_INDEX || var == RESEARCHSPEEDBONUS_INDEX || var == GARRISONEDRANGEBONUS_INDEX
|| var == KNOWLEDGEMAGIC_INDEX || var == KNOWLEDGEWARFARE_INDEX || var == KNOWLEDGEMINING_INDEX
|| var == BONUSAGAINSTMOUNTED_INDEX|| var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX
|| var == SUPPLY_INDEX || var == ETHEREALVISION_INDEX)
|| var == SUPPLY_INDEX || var == ETHEREALVISION_INDEX
|| var == ATTACKRANGE_INDEX)
) {
continue;
}
Expand Down Expand Up @@ -695,7 +697,8 @@ std::string GetUniqueItemEffectsString(const std::string &item_ident)
|| var == GIVERESOURCE_INDEX || var == TIMEEFFICIENCYBONUS_INDEX || var == RESEARCHSPEEDBONUS_INDEX || var == GARRISONEDRANGEBONUS_INDEX
|| var == KNOWLEDGEMAGIC_INDEX || var == KNOWLEDGEWARFARE_INDEX || var == KNOWLEDGEMINING_INDEX
|| var == BONUSAGAINSTMOUNTED_INDEX|| var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX
|| var == SUPPLY_INDEX)
|| var == SUPPLY_INDEX
|| var == ATTACKRANGE_INDEX)
) {
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ void CUnit::EquipItem(CUnit &item, bool affect_character)
|| i == AIRRESISTANCE_INDEX || i == EARTHRESISTANCE_INDEX || i == WATERRESISTANCE_INDEX || i == ACIDRESISTANCE_INDEX
|| i == HACKRESISTANCE_INDEX || i == PIERCERESISTANCE_INDEX || i == BLUNTRESISTANCE_INDEX
|| i == ACCURACY_INDEX || i == EVASION_INDEX || i == SPEED_INDEX || i == CHARGEBONUS_INDEX || i == BACKSTAB_INDEX
|| i == ATTACKRANGE_INDEX
) {
Variable[i].Value += item.Variable[i].Value;
Variable[i].Max += item.Variable[i].Max;
Expand Down Expand Up @@ -1585,6 +1586,7 @@ void CUnit::DeequipItem(CUnit &item, bool affect_character)
|| i == AIRRESISTANCE_INDEX || i == EARTHRESISTANCE_INDEX || i == WATERRESISTANCE_INDEX || i == ACIDRESISTANCE_INDEX
|| i == HACKRESISTANCE_INDEX || i == PIERCERESISTANCE_INDEX || i == BLUNTRESISTANCE_INDEX
|| i == ACCURACY_INDEX || i == EVASION_INDEX || i == SPEED_INDEX || i == CHARGEBONUS_INDEX || i == BACKSTAB_INDEX
|| i == ATTACKRANGE_INDEX
) {
Variable[i].Value -= item.Variable[i].Value;
Variable[i].Max -= item.Variable[i].Max;
Expand Down Expand Up @@ -6623,10 +6625,7 @@ int ThreatCalculate(const CUnit &unit, const CUnit &dest)

const int d = unit.MapDistanceTo(dest);

//Wyrmgus start
// if (d <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max && d >= type.MinAttackRange) {
if (d <= unit.GetModifiedVariable(ATTACKRANGE_INDEX) && d >= type.MinAttackRange) {
//Wyrmgus end
cost += d * INRANGE_FACTOR;
cost -= INRANGE_BONUS;
} else {
Expand Down
10 changes: 0 additions & 10 deletions src/unit/unit_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,7 @@ class BestTargetFinder
const CPlayer &player = *attacker->Player;
const CUnitType &type = *attacker->Type;
const CUnitType &dtype = *dest->Type;
//Wyrmgus start
// const int attackrange = attacker->Stats->Variables[ATTACKRANGE_INDEX].Max;
int attackrange = attacker->GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end

//Wyrmgus start
// if (!player.IsEnemy(*dest) // a friend or neutral
Expand Down Expand Up @@ -1264,10 +1261,7 @@ class BestRangeTargetFinder
d = attacker->MapDistanceTo(*dest);
}

//Wyrmgus start
// int attackrange = attacker->Stats->Variables[ATTACKRANGE_INDEX].Max;
int attackrange = attacker->GetModifiedVariable(ATTACKRANGE_INDEX);
//Wyrmgus end

//Wyrmgus start
// if (d <= attackrange ||
Expand Down Expand Up @@ -1598,12 +1592,8 @@ CUnit *AttackUnitsInDistance(const CUnit &unit, int range, bool circle, bool inc
*/
CUnit *AttackUnitsInRange(const CUnit &unit, CUnitFilter pred)
{
//Wyrmgus start
// Assert(unit.Type->CanAttack);
Assert(unit.CanAttack());
// return AttackUnitsInDistance(unit, unit.Stats->Variables[ATTACKRANGE_INDEX].Max, pred);
return AttackUnitsInDistance(unit, unit.GetModifiedVariable(ATTACKRANGE_INDEX), pred);
//Wyrmgus end
}

CUnit *AttackUnitsInRange(const CUnit &unit)
Expand Down

0 comments on commit d79b571

Please sign in to comment.