Skip to content

Commit c3bb652

Browse files
committed
Adjustments to TechnoClass::Can_Fire
1 parent bcb93ad commit c3bb652

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/extensions/techno/technoext_hooks.cpp

+13-17
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,15 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
630630
if (ext->SpawnManager && ext->SpawnManager->Preparing_Count())
631631
return FIRE_BUSY;
632632

633-
ObjectClass* object = Target_As_Techno(target);
633+
TechnoClass* techno = Target_As_Techno(target);
634+
CellClass* cptr = &Map[target->Center_Coord()];
634635

635636
/**
636637
* If the object is completely cloaked, then you can't fire on it.
637638
*/
638-
if (object && object->Visual_Character(true, House) == VISUAL_HIDDEN
639-
&& !Map[target->Center_Coord()].Sensed_By(static_cast<HousesType>(House->Get_Heap_ID()))
640-
&& object->Owning_House() != House
641-
&& (Combat_Damage() > 0 || !object->Owning_House()->Is_Ally(House)))
639+
if (techno != NULL && techno->Visual_Character(true, House) == VISUAL_HIDDEN
640+
&& !cptr->Sensed_By((HousesType)House->ID) && techno->House != House
641+
&& (Combat_Damage() > 0 || !techno->House->Is_Ally(House)))
642642
{
643643
return FIRE_CANT;
644644
}
@@ -654,12 +654,10 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
654654
*/
655655
if (Is_Immobilized())
656656
{
657-
if (What_Am_I() != RTTI_UNIT
658-
|| !(reinterpret_cast<UnitClass*>(this)->Class->IsLargeVisceroid
659-
|| reinterpret_cast<UnitClass*>(this)->Class->IsSmallVisceroid))
660-
{
657+
if (Kind_Of() != RTTI_UNIT)
658+
return FIRE_CANT;
659+
if (!reinterpret_cast<UnitClass*>(this)->Class->IsLargeVisceroid && !reinterpret_cast<UnitClass*>(this)->Class->IsSmallVisceroid)
661660
return FIRE_CANT;
662-
}
663661
}
664662

665663
/**
@@ -692,7 +690,7 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
692690
/**
693691
* If the weapon is a spawner, it needs to have an object ready to spawn.
694692
*/
695-
if (weapon && Extension::Fetch<WeaponTypeClassExtension>(weapon)->IsSpawner)
693+
if (techno && weapon && Extension::Fetch<WeaponTypeClassExtension>(weapon)->IsSpawner)
696694
{
697695
const auto techno_ext = Extension::Fetch<TechnoClassExtension>(this);
698696

@@ -738,7 +736,7 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
738736
* Check if the unit has synchronized shooting.
739737
*/
740738
bool check_rearm = true;
741-
if (which != WEAPON_SLOT_SECONDARY && What_Am_I() == RTTI_UNIT)
739+
if (which != WEAPON_SLOT_SECONDARY && Kind_Of() == RTTI_UNIT)
742740
{
743741
const auto unit = reinterpret_cast<UnitClass*>(this);
744742
const int burst = CurrentBurstIndex % weapon->Burst;
@@ -747,7 +745,7 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
747745
if (unit->Class->FiringSyncFrame[burst] != -1
748746
&& unit->FiringSyncDelay != -1)
749747
{
750-
if (unit->Class->FiringSyncFrame[burst] != unit->FiringSyncDelay)
748+
if (unit->FiringSyncDelay != unit->Class->FiringSyncFrame[burst])
751749
return FIRE_REARM;
752750

753751
check_rearm = false;
@@ -770,10 +768,8 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
770768
/**
771769
* If the object has an armor type that this unit's warhead is forbidden to fire at, bail.
772770
*/
773-
if (object && !Verses::Get_ForceFire(object->Techno_Type_Class()->Armor, weapon->WarheadPtr))
774-
{
771+
if (techno && !Verses::Get_ForceFire(techno->Techno_Type_Class()->Armor, weapon->WarheadPtr))
775772
return FIRE_ILLEGAL;
776-
}
777773

778774
/**
779775
* If there is no ammo left, then it can't fire.
@@ -784,7 +780,7 @@ FireErrorType TechnoClassExt::_Can_Fire(TARGET target, WeaponSlotType which)
784780
/**
785781
* If cloaked, then firing is disabled.
786782
*/
787-
if (Cloak != UNCLOAKED && (What_Am_I() != RTTI_AIRCRAFT || Cloak == CLOAKED))
783+
if (Cloak != UNCLOAKED && (Kind_Of() != RTTI_AIRCRAFT || Cloak == CLOAKED))
788784
return FIRE_CLOAKED;
789785

790786
/**

0 commit comments

Comments
 (0)