|
1 | | -#include "Body.h" |
| 1 | +#include "Body.h" |
2 | 2 |
|
3 | 3 | #include <Ext/Anim/Body.h> |
4 | 4 | #include <Ext/Building/Body.h> |
@@ -199,59 +199,68 @@ DEFINE_HOOK(0x6F3432, TechnoClass_WhatWeaponShouldIUse_Gattling, 0xA) |
199 | 199 | auto const pTargetTechno = abstract_cast<TechnoClass*>(pTarget); |
200 | 200 | const int oddWeaponIndex = 2 * pThis->CurrentGattlingStage; |
201 | 201 | const int evenWeaponIndex = oddWeaponIndex + 1; |
202 | | - int chosenWeaponIndex = oddWeaponIndex; |
203 | 202 | const int eligibleWeaponIndex = TechnoExt::PickWeaponIndex(pThis, pTargetTechno, pTarget, oddWeaponIndex, evenWeaponIndex, true); |
204 | 203 |
|
205 | 204 | if (eligibleWeaponIndex != -1) |
206 | 205 | { |
207 | | - chosenWeaponIndex = eligibleWeaponIndex; |
| 206 | + R->EAX(eligibleWeaponIndex); |
| 207 | + return UseWeaponIndex; |
208 | 208 | } |
209 | | - else if (pTargetTechno) |
| 209 | + |
| 210 | + int chosenWeaponIndex = oddWeaponIndex; |
| 211 | + |
| 212 | + if (pTargetTechno) |
210 | 213 | { |
211 | 214 | auto const pTargetExt = TechnoExt::ExtMap.Find(pTargetTechno); |
212 | | - auto const pWeaponOdd = pThis->GetWeapon(oddWeaponIndex)->WeaponType; |
213 | 215 | auto const pWeaponEven = pThis->GetWeapon(evenWeaponIndex)->WeaponType; |
214 | | - bool skipRemainingChecks = false; |
| 216 | + auto const pShield = pTargetExt->Shield.get(); |
| 217 | + auto const armor = pTargetTechno->GetTechnoType()->Armor; |
| 218 | + const bool inAir = pTargetTechno->IsInAir(); |
| 219 | + const bool isUnderground = pTargetTechno->InWhichLayer() == Layer::Underground; |
215 | 220 |
|
216 | | - if (const auto pShield = pTargetExt->Shield.get()) |
217 | | - { |
218 | | - if (pShield->IsActive() && !pShield->CanBeTargeted(pWeaponOdd)) |
| 221 | + auto isWeaponValid = [&](WeaponTypeClass* pWeapon) |
219 | 222 | { |
220 | | - chosenWeaponIndex = evenWeaponIndex; |
221 | | - skipRemainingChecks = true; |
222 | | - } |
| 223 | + if (pShield && pShield->IsActive() && !pShield->CanBeTargeted(pWeapon)) |
| 224 | + return false; |
| 225 | + if (GeneralUtils::GetWarheadVersusArmor(pWeapon->Warhead, armor) == 0.0) |
| 226 | + return false; |
| 227 | + if (isUnderground && !BulletTypeExt::ExtMap.Find(pWeapon->Projectile)->AU) |
| 228 | + return false; |
| 229 | + if (inAir && !pWeapon->Projectile->AA) |
| 230 | + return false; |
| 231 | + return true; |
| 232 | + }; |
| 233 | + |
| 234 | + // check even weapon first |
| 235 | + |
| 236 | + if (!isWeaponValid(pWeaponEven)) |
| 237 | + { |
| 238 | + R->EAX(chosenWeaponIndex); |
| 239 | + return UseWeaponIndex; |
223 | 240 | } |
224 | 241 |
|
225 | | - if (!skipRemainingChecks) |
| 242 | + // handle naval targeting |
| 243 | + |
| 244 | + if (!pTargetTechno->OnBridge && !inAir) |
226 | 245 | { |
227 | | - if (GeneralUtils::GetWarheadVersusArmor(pWeaponOdd->Warhead, pTargetTechno->GetTechnoType()->Armor) == 0.0) |
228 | | - { |
229 | | - chosenWeaponIndex = evenWeaponIndex; |
230 | | - } |
231 | | - else if (pTargetTechno->InWhichLayer() == Layer::Underground) |
| 246 | + auto const landType = pTargetTechno->GetCell()->LandType; |
| 247 | + |
| 248 | + if (landType == LandType::Water || landType == LandType::Beach) |
232 | 249 | { |
233 | | - if (BulletTypeExt::ExtMap.Find(pWeaponEven->Projectile)->AU && !BulletTypeExt::ExtMap.Find(pWeaponOdd->Projectile)->AU) |
| 250 | + if (pThis->SelectNavalTargeting(pTargetTechno) != 1) |
234 | 251 | chosenWeaponIndex = evenWeaponIndex; |
235 | | - } |
236 | | - else |
237 | | - { |
238 | | - auto const landType = pTargetTechno->GetCell()->LandType; |
239 | | - const bool isOnWater = (landType == LandType::Water || landType == LandType::Beach) && !pTargetTechno->IsInAir(); |
240 | 252 |
|
241 | | - if (!pTargetTechno->OnBridge && isOnWater && pThis->SelectNavalTargeting(pTargetTechno) == 2) |
242 | | - { |
243 | | - chosenWeaponIndex = evenWeaponIndex; |
244 | | - } |
245 | | - else if (pTargetTechno->IsInAir() && !pWeaponOdd->Projectile->AA && pWeaponEven->Projectile->AA) |
246 | | - { |
247 | | - chosenWeaponIndex = evenWeaponIndex; |
248 | | - } |
249 | | - else if (pThis->GetTechnoType()->LandTargeting == LandTargetingType::Land_Secondary) |
250 | | - { |
251 | | - chosenWeaponIndex = evenWeaponIndex; |
252 | | - } |
| 253 | + R->EAX(chosenWeaponIndex); |
| 254 | + return UseWeaponIndex; |
253 | 255 | } |
254 | 256 | } |
| 257 | + |
| 258 | + // check odd weapon |
| 259 | + |
| 260 | + auto const pWeaponOdd = pThis->GetWeapon(oddWeaponIndex)->WeaponType; |
| 261 | + |
| 262 | + if (!isWeaponValid(pWeaponOdd) || pThis->GetTechnoType()->LandTargeting == LandTargetingType::Land_Secondary) |
| 263 | + chosenWeaponIndex = evenWeaponIndex; |
255 | 264 | } |
256 | 265 |
|
257 | 266 | R->EAX(chosenWeaponIndex); |
|
0 commit comments