Skip to content

Commit

Permalink
Fix a non-working player check (#725)
Browse files Browse the repository at this point in the history
* set aiPolicy in npc constructor

fixes a non-working isPlayer check

* minor polish

---------

Co-authored-by: Try <[email protected]>
  • Loading branch information
thokkat and Try authored Jan 29, 2025
1 parent a972bfc commit 0fb0aa2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion game/game/gamescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ void GameScript::invokePickLock(Npc& npc, int bSuccess, int bBrokenOpen) {
}

void GameScript::invokeRefreshAtInsert(Npc& npc) {
if(B_RefreshAtInsert==nullptr)
if(B_RefreshAtInsert==nullptr || owner.version().game!=2)
return;
ScopeVar self(*vm.global_self(), npc.handlePtr());
vm.call_function<void>(B_RefreshAtInsert);
Expand Down
8 changes: 3 additions & 5 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ struct Npc::TransformBack {
};


Npc::Npc(World &owner, size_t instance, std::string_view waypoint)
:owner(owner),mvAlgo(*this) {
Npc::Npc(World &owner, size_t instance, std::string_view waypoint, ProcessPolicy aiPolicy)
:owner(owner),aiPolicy(aiPolicy),mvAlgo(*this) {
outputPipe = owner.script().openAiOuput();

hnpc = std::make_shared<zenkit::INpc>();
Expand Down Expand Up @@ -490,9 +490,7 @@ bool Npc::resetPositionToTA() {
invent.autoEquipWeapons(*this);
}

if(g2)
owner.script().invokeRefreshAtInsert(*this);

owner.script().invokeRefreshAtInsert(*this);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion game/world/objects/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Npc final {

using Anim = AnimationSolver::Anim;

Npc(World &owner, size_t instance, std::string_view waypoint);
Npc(World &owner, size_t instance, std::string_view waypoint, ProcessPolicy aiPolicy = AiNormal);
Npc(const Npc&)=delete;
~Npc();

Expand Down
5 changes: 2 additions & 3 deletions game/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ void World::createPlayer(std::string_view cls) {
if(id==size_t(-1))
return;
std::string_view waypoint = wmatrix->startPoint().name;
auto npc = std::make_unique<Npc>(*this,id,waypoint);
npcPlayer = wobj.insertPlayer(std::move(npc),waypoint);
npcPlayer->setProcessPolicy(Npc::ProcessPolicy::Player);
auto npc = std::make_unique<Npc>(*this, id, waypoint, Npc::ProcessPolicy::Player);
npcPlayer = wobj.insertPlayer(std::move(npc), waypoint);
game.script()->setInstanceNPC("HERO",*npcPlayer);
}

Expand Down
1 change: 1 addition & 0 deletions game/world/worldobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ Npc* WorldObjects::addNpc(size_t npcInstance, const Vec3& pos) {
Npc* npc = new Npc(owner,npcInstance,pstr);
npc->setPosition (pos.x,pos.y,pos.z);
npc->updateTransform();
owner.script().invokeRefreshAtInsert(*npc);

npcArr.emplace_back(npc);
return npc;
Expand Down

0 comments on commit 0fb0aa2

Please sign in to comment.