Skip to content

Commit 664fda4

Browse files
revolucasXottab-DUTY
authored andcommitted
* fix npcs getting stuck in action_take_cover
* added a return to WeaponMagazined.cpp for when inventory_owner doesn't have active_item
1 parent 797eacf commit 664fda4

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

src/xrGame/WeaponMagazined.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ void CWeaponMagazined::state_Fire(float dt)
518518
Log("next_state", GetNextState());
519519
Log("item_sect", cNameSect().c_str());
520520
Log("H_Parent", H_Parent()->cNameSect().c_str());
521+
StopShooting();
522+
return; //Alundaio: This is not supposed to happen but it does. GSC was aware but why no return here? Known to cause crash on game load if NPC immediately enters combat.
521523
}
522524

523525
CEntity* E = smart_cast<CEntity*>(H_Parent());

src/xrGame/alife_online_offline_group.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -366,24 +366,6 @@ void CSE_ALifeOnlineOfflineGroup::force_change_position(Fvector position)
366366
// m_tGraphID = new_graph_vertex;
367367
}
368368

369-
//Alundaio: force new graph location
370-
/*
371-
void CSE_ALifeOnlineOfflineGroup::force_change_game_vertex_id(GameGraph::_GRAPH_ID game_vertex_id)
372-
{
373-
if (game_vertex_id && ai().game_graph().valid_vertex_id(game_vertex_id))
374-
{
375-
m_tNodeID = ai().game_graph().vertex(game_vertex_id)->level_vertex_id();
376-
o_Position = ai().game_graph().vertex(game_vertex_id)->level_point();
377-
378-
if (m_tGraphID != game_vertex_id)
379-
{
380-
alife().graph().change(this, m_tGraphID, game_vertex_id);
381-
}
382-
}
383-
}
384-
*/
385-
//Alundaio: END
386-
387369
void CSE_ALifeOnlineOfflineGroup::on_failed_switch_online()
388370
{
389371
MEMBERS::const_iterator I = m_members.begin();

src/xrGame/stalker_combat_actions.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,22 @@ void CStalkerActionKillEnemy::execute()
436436
inherited::execute();
437437
//Alundaio: Prevent Stalkers from shooting at walls for prolonged periods due to kill if not visible
438438
const CEntityAlive* enemy = object().memory().enemy().selected();
439-
if (!enemy || !enemy->g_Alive())
440-
return;
441-
442-
CMemoryInfo mem_object = object().memory().memory(enemy);
443-
if (!mem_object.m_object)
444-
return;
445-
446-
object().best_cover(mem_object.m_object_params.m_position);
447-
448-
u32 last_time_seen = object().memory().visual().visible_object_time_last_seen(enemy);
449-
if (last_time_seen != u32(-1) && Device.dwTimeGlobal - last_time_seen <= 2000)
439+
if (enemy && enemy->g_Alive())
450440
{
451-
object().sight().setup(CSightAction(enemy, true, true));
452-
fire();
441+
CMemoryInfo mem_object = object().memory().memory(enemy);
442+
if (mem_object.m_object)
443+
object().best_cover(mem_object.m_object_params.m_position);
444+
u32 last_time_seen = object().memory().visual().visible_object_time_last_seen(enemy);
445+
446+
//Here NPC will only fire at not visible enemy for no more than 3 seconds instead of shooting at walls like morons
447+
if (last_time_seen != u32(-1) && Device.dwTimeGlobal - last_time_seen <= 3000)
448+
{
449+
object().sight().setup(CSightAction(enemy, true, true));
450+
fire();
451+
}
453452
}
453+
else
454+
object().sight().setup(CSightAction(SightManager::eSightTypePathDirection, true, true));
454455
//Alundaio: END
455456
}
456457

@@ -502,6 +503,7 @@ void CStalkerActionTakeCover::execute()
502503

503504
inherited::execute();
504505

506+
//Alundaio:
505507
const CEntityAlive* enemy = object().memory().enemy().selected();
506508
if (!enemy)
507509
return;
@@ -536,9 +538,15 @@ void CStalkerActionTakeCover::execute()
536538
// if (object().memory().visual().visible_now(object().memory().enemy().selected()) && object().can_kill_enemy())
537539
// if (object().memory().visual().visible_now(object().memory().enemy().selected()))
538540

539-
//Alundaio: Fix shooting at walls or aiming at ceiling or floor during this action
541+
if (object().movement().path_completed()) // && (object().memory().enemy().selected()->Position().distance_to_sqr(object().Position()) >= 10.f))
542+
{
543+
object().best_cover_can_try_advance();
544+
m_storage->set_property(eWorldPropertyInCover, true);
545+
}
546+
547+
//Don't shoot if enemy not visible for longer than 3 seconds
540548
u32 last_time_seen = object().memory().visual().visible_object_time_last_seen(enemy);
541-
if (last_time_seen != u32(-1) && Device.dwTimeGlobal - last_time_seen <= 2000 && fire_make_sense())
549+
if (last_time_seen != u32(-1) && Device.dwTimeGlobal - last_time_seen <= 3000 && fire_make_sense())
542550
{
543551
fire();
544552
}
@@ -643,6 +651,8 @@ void CStalkerActionLookOut::execute()
643651
}
644652
else
645653
object().sight().setup(CSightAction(SightManager::eSightTypePosition, mem_object.m_object_params.m_position, true));
654+
655+
object().best_cover(mem_object.m_object_params.m_position);
646656
//-Alundaio
647657

648658
if (current_cover(m_object) >= 3.f)
@@ -675,8 +685,6 @@ void CStalkerActionLookOut::execute()
675685
// m_storage->set_property (eWorldPropertyLookedOut,true);
676686
// object().movement().set_nearest_accessible_position ();
677687
// }
678-
679-
object().best_cover(mem_object.m_object_params.m_position);
680688
}
681689

682690
//////////////////////////////////////////////////////////////////////////
@@ -715,6 +723,14 @@ void CStalkerActionHoldPosition::execute()
715723

716724
inherited::execute();
717725

726+
//Alundaio: Cleaned up
727+
/*
728+
Possible TODO : This action is a good place to prevent stalkers staring at walls.
729+
A simple ray query each execute can do the trick by rotating the stalker until
730+
the differences between the last query and new query are larger than some defined threshold.
731+
This way you can detect edges of walls and would give the illusion of stalkers looking at corridors or chokepoints instead of through a wall.
732+
*/
733+
718734
const CEntityAlive* enemy = object().memory().enemy().selected();
719735
if (!enemy)
720736
return;
@@ -723,6 +739,8 @@ void CStalkerActionHoldPosition::execute()
723739
if (!mem_object.m_object)
724740
return;
725741

742+
object().best_cover(mem_object.m_object_params.m_position);
743+
726744
if (current_cover(m_object) < 3.f)
727745
m_storage->set_property(eWorldPropertyLookedOut, false);
728746

@@ -756,16 +774,7 @@ void CStalkerActionHoldPosition::execute()
756774
{
757775
aim_ready();
758776
}
759-
760-
if (object().memory().enemy().selected())
761-
{
762-
CMemoryInfo mem_object = object().memory().memory(object().memory().enemy().selected());
763-
764-
if (mem_object.m_object)
765-
{
766-
object().best_cover(mem_object.m_object_params.m_position);
767-
}
768-
}
777+
//-Alundaio
769778
}
770779

771780
//////////////////////////////////////////////////////////////////////////
@@ -799,13 +808,13 @@ void CStalkerActionDetourEnemy::initialize()
799808

800809
object().agent_manager().member().member(m_object).cover(0);
801810

802-
//#ifndef SILENT_COMBAT
803-
//Alundaio: Sanity
811+
//#ifndef SILENT_COMBAT
812+
//Alundaio: Added sanity to make sure enemy exists
804813
if (object().memory().enemy().selected() && object().memory().enemy().selected()->human_being() && object().agent_manager().member().group_behaviour())
805814
//Alundaio: END
806815
//object().sound().play(eStalkerSoundNeedBackup);
807816
object().sound().play(eStalkerSoundDetour);
808-
//#endif
817+
//#endif
809818
}
810819

811820
void CStalkerActionDetourEnemy::finalize()
@@ -887,7 +896,7 @@ void CStalkerActionPostCombatWait::initialize()
887896
if (object().movement().current_params().cover())
888897
return;
889898

890-
object().movement().set_movement_type(eMovementTypeRun); //Alundaio. Was eMovementTypeStand
899+
object().movement().set_movement_type(eMovementTypeRun); //Alundaio: Changed from walk to run. (eMovementTypeStand)
891900
EObjectAction action = eObjectActionAimReady1;
892901
if (m_storage->property(eWorldPropertyKilledWounded))
893902
action = eObjectActionIdle;

0 commit comments

Comments
 (0)