I found this in: ctp2_code\gs\gameobj\unitdata.cpp
I'm not a coder but I'm trying to learn, but I cant see where in this code that it only makes bombardment one-square away. Can anyone see where it says that or what the problem is?
Code:
sint32 UnitData::CanBombard(CellUnitList &defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); double r = rec->GetBombardRange() + 0.5; double rsq = r * r; MapPoint dpos; defender.GetPos(dpos); if(GetDistance(dpos, m_pos, (sint32)r) > rsq) return FALSE; if (rec->GetCanBombardLand()) if (defender.IsAtLeastOneMoveLand()) return TRUE; if (rec->GetCanBombardWater()) if (defender.IsAtLeastOneMoveWater() || defender.IsAtLeastOneMoveShallowWater()) return TRUE; if (rec->GetCanBombardAir()) if (defender.IsAtLeastOneMoveAir()) return TRUE; if (rec->GetCanBombardSpace()) if (defender.IsAtLeastOneMoveSpace()) return TRUE; if (rec->GetCanBombardMountain()) if (defender.IsAtLeastOneMoveMountain()) return TRUE; return FALSE; } sint32 UnitData::CanCounterBombard(CellUnitList &defender) const { if (g_theUnitDB->Get(m_type)->GetCanCounterBombard()) { return CanBombard(defender); } else { return FALSE; } } sint32 UnitData::CanActivelyDefend(CellUnitList &attacker) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); if(rec->GetActiveDefenseRange() <= 0) return 0; BOOL movesMatch = FALSE; if(attacker.IsAtLeastOneMoveLand() && rec->GetDefendLand()) movesMatch = 0; if(attacker.IsAtLeastOneMoveWater() && rec->GetDefendWater()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveAir() && rec->GetDefendAir()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveSpace() && rec->GetDefendSpace()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveMountain() && rec->GetDefendMountain()) movesMatch = TRUE; if(movesMatch) { if(rec->GetActiveDefenseOnlyWhenCarryingEnablers()) { sint32 numEnablers = 0; sint32 i; for(i = 0; i < m_cargo_list->Num(); i++) { if(m_cargo_list->Access(i).GetDBRec()->GetEnableCarrierDefenses()) numEnablers++; } return numEnablers; } return 1; } return 0; } double UnitData::GetAttack(const UnitRecord *rec, const Unit defender) const { MapPoint dpos; double attack, baseattack; const UnitRecord *defrec = defender.GetDBRec(); defender.GetPos(dpos); attack = baseattack = rec->GetAttack(); if(!(rec->GetCanAttack() & defender.GetDBRec()->GetMovementType())) { return 0; } if(defrec->GetWoodenShip()) { attack += baseattack * rec->GetAttackWoodenShipBonus(); } if(g_theWorld->GetCell(dpos)->GetCity().m_id != (0)) { attack += baseattack * rec->GetAttackCityBonus(); } if(defrec->GetIsSubmarine()) { attack += baseattack * rec->GetAttackBonusSubmarine(); } return attack; } void UnitData::Bombard(const UnitRecord *rec, Unit defender, BOOL isCounterBombardment) { double prob; sint32 f = (sint32)(rec->GetFirepower() / g_theUnitDB->Get(defender.GetType())->GetArmor()); sint32 n; bool canBombard = rec->GetBombRounds(n); Assert(canBombard); if(!canBombard) n = 0; double hp = defender.GetHP(); sint32 p; sint32 i; g_slicEngine->RunCounterBombardmentTriggers(defender, Unit(m_id)); double defenseStrength = defender.GetDefense(Unit(m_id)); double attack = rec->GetZBRangeAttack(); prob = attack / (attack + defenseStrength); p = sint32(prob * 100); double dmr = 1.0/defender.GetHPModifier(); if (IsVeteran()) p += sint32(double(p) * g_theConstDB->GetVetCoef()); for (i=0; iNext(100) < p) { hp -= f * dmr; } } defender.SetHP(hp); if(isCounterBombardment) { g_slicEngine->RunCounterBombardmentTriggers(Unit(m_id), defender); } else { g_slicEngine->RunBombardmentTriggers(Unit(m_id), defender); } } void UnitData::BombardOneRound(const UnitRecord *rec, Unit &defender, double dbonus, double dmr) { sint32 p = rec->GetProbOfBombHit(); sint32 f = rec->GetZBRangeAttack(); double hp = defender.GetHP(); if (IsVeteran()) p += sint32(double(p) * g_theConstDB->GetVetCoef()); p = int (p *(1.0 + dbonus)); if (g_rand->Next(100) < p) { hp -= f * dmr; } defender.SetHP(hp); } BOOL UnitData::CanBombardType(const Unit & defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); if (rec->GetCanBombardLand() || rec->GetDefendLand()) { if (defender.GetMovementTypeLand()) { return TRUE; } } if (rec->GetCanBombardWater() || rec->GetDefendWater()) { if (defender.GetMovementTypeSea() || defender.GetMovementTypeShallowWater()) { return TRUE; } } if (rec->GetCanBombardAir() || rec->GetDefendAir()) { if (defender.GetMovementTypeAir()) { return TRUE; } } if (rec->GetCanBombardSpace() || rec->GetDefendSpace()) { if (defender.GetMovementTypeSpace()){ return TRUE; } } if (rec->GetCanBombardMountain() || rec->GetDefendMountain()) { if (defender.GetMovementTypeMountain()) { return TRUE; } } return FALSE; } BOOL UnitData::Bombard(CellUnitList &defender, BOOL isCounterBombardment) { const UnitRecord *rec = g_theUnitDB->Get(m_type); sint32 i, j, r; Assert(0 < defender.Num()); r = g_rand->Next(defender.Num()); for (i=r, j=0; j < defender.Num(); i = ((i + 1) % defender.Num()), j++) { if(!(defender[i].GetVisibility() & (1 << m_owner)) && !g_theWorld->GetCity(defender[i].RetPos()).IsValid()) continue; if (CanBombardType(defender[i]) || rec->GetSingleUse()) { Bombard(rec, defender[i], isCounterBombardment); return TRUE; } } return FALSE; }
I'm not a coder but I'm trying to learn, but I cant see where in this code that it only makes bombardment one-square away. Can anyone see where it says that or what the problem is?
Comment