Skip to content

Commit

Permalink
Bug/centaur catch (#51)
Browse files Browse the repository at this point in the history
* Make GetAttackRiding() cope with centaurs and camels properly

* Make camels easier to catch in attacks
  • Loading branch information
sgb authored and artyomtrityak committed Oct 2, 2019
1 parent 7f58d9d commit c2da970
Showing 1 changed file with 76 additions and 13 deletions.
89 changes: 76 additions & 13 deletions unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void Unit::ConsumeSharedMoney(int n)

int Unit::GetAttackRiding()
{
int riding = 0;
int riding = 0;
if (type == U_WMON) {
forlist(&items) {
Item *i = (Item *) elem;
Expand All @@ -1006,25 +1006,57 @@ int Unit::GetAttackRiding()
}
return riding;
} else {
riding = GetSkill(S_RIDING);
int lowriding = 0;
int attackriding = 0;
int minweight = 10000;
AString skname;
forlist(&items) {
Item *i = (Item *)elem;
if (ItemDefs[i->type].type & IT_MAN)
if (ItemDefs[i->type].weight < minweight)
minweight = ItemDefs[i->type].weight;
}
forlist_reuse (&items) {
MountType *mount;
int skill, maxBonus;
Item *i = (Item *)elem;
if (ItemDefs[i->type].fly - ItemDefs[i->type].weight >= minweight)
return riding;
if (ItemDefs[i->type].ride-ItemDefs[i->type].weight >= minweight) {
if (riding <= 3) return riding;
lowriding = 3;
}
}
return lowriding;
if (!(ItemDefs[i->type].type & IT_MOUNT))
continue;
mount = FindMount(ItemDefs[i->type].abr);
if (!mount)
continue;
maxBonus = mount->maxBonus;
/*
* This code applies terrain restrictions to the attack riding
* calculations, but given that these have never been applied
* historically we probably don't want to start now.
* Thus: for reference only.
int canRide = TerrainDefs[object->region->type].flags & TerrainType::RIDINGMOUNTS;
int canFly = TerrainDefs[object->region->type].flags & TerrainType::FLYINGMOUNTS;
if (canRide && !canFly)
maxBonus = mount->maxHamperedBonus;
if (!canRide && !canFly)
maxBonus = 0;
*/
skname = mount->skill;
skill = LookupSkill(&skname);
if (skill == -1) {
// This mount doesn't require skill to use.
// I guess the rider gets the max bonus!
if (attackriding < maxBonus)
attackriding = maxBonus;
} else {
riding = GetSkill(skill);
if ((ItemDefs[i->type].type & IT_MAN)
|| (ItemDefs[i->type].fly - ItemDefs[i->type].weight >= minweight)
|| (ItemDefs[i->type].ride - ItemDefs[i->type].weight >= minweight)) {
if (riding > maxBonus)
riding = maxBonus;
if (attackriding < riding)
attackriding = riding;
}
}
}
return attackriding;
}
}

Expand All @@ -1035,8 +1067,39 @@ int Unit::GetDefenseRiding()
int riding = 0;
int weight = Weight();

if (CanFly(weight)) riding = 5;
else if (CanRide(weight)) riding = 3;
if (CanFly(weight)) {
riding = 5;
// Limit riding to the slowest flying mount
forlist(&items) {
Item *i = (Item *)elem;
if (ItemDefs[i->type].type & IT_MOUNT && ItemDefs[i->type].fly) {
MountType *mount;
mount = FindMount(ItemDefs[i->type].abr);
if (mount) {
// If we wanted to apply terrain restrictions,
// we'd do it here
if (mount->maxBonus < riding)
riding = mount->maxBonus;
}
}
}
} else if (CanRide(weight)) {
riding = 3;
// Limit riding to the slowest riding mount
forlist(&items) {
Item *i = (Item *)elem;
if (ItemDefs[i->type].type & IT_MOUNT && ItemDefs[i->type].ride) {
MountType *mount;
mount = FindMount(ItemDefs[i->type].abr);
if (mount) {
// If we wanted to apply terrain restrictions,
// we'd also do it here
if (mount->maxBonus < riding)
riding = mount->maxBonus;
}
}
}
}

if (GetMen()) {
int manriding = GetSkill(S_RIDING);
Expand Down

0 comments on commit c2da970

Please sign in to comment.