-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KOTORBASE: Add SwitchPlayerCharacter nwscript method #546
base: master
Are you sure you want to change the base?
Conversation
Apparently not, since it invokes UB :P sanitizer log here: https://gist.github.com/DrMcCoy/94d189fb6136cf2f5e5316dde6fdaaa3 |
src/engines/kotorbase/module.cpp
Outdated
throw Common::Exception("%u is not an available npc id", index); | ||
|
||
Creature *newPC = createCreature(_partyController.getAvailableNPCTemplate(index)); | ||
ObjectMan.registerObject(newPC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object registration is handled automatically when the object is created and destroyed. See
xoreos/src/engines/kotorbase/object.cpp
Line 54 in 9000339
ObjectMan.registerObject(this); |
src/engines/kotorbase/module.cpp
Outdated
notifyPartyLeaderChanged(); | ||
|
||
_area->removeObject(oldPC); | ||
removeObject(*oldPC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module::removeObject
is called implicitly in Area::removeObject
. See
xoreos/src/engines/kotorbase/area.cpp
Line 872 in 9000339
_module->removeObject(*object); |
_partyController.addPartyMember(index, newPC); | ||
int oldLeaderID = _partyController.getPartyLeaderID(); | ||
|
||
Creature *oldPC = _partyController.getPartyLeader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Player character will not always be the party leader. Maybe we should modify Module::_pc
instead?
ac1c970
to
c89717b
Compare
The double free should now be fixed. About the use of _pc, I'm unsure. Can _pc be considered the player generated character or the currently controlled character and therefore being equal to the party leader? |
Currently, Player Character and Party Leader are two separate roles, which may or may not be represented by a single object. PC is instantiated once per module ( |
Yeah, I guess we have three separate concepts here, in the KotOR games.
Maybe we should call 1. something else, and keep that around permanently too. Especially because we need to remember the inventory and other things that might modify this entitiy during gameplay. Module::_pc would then be pointer or copy of this entity (again, maing sure to keep everything in sync). |
The crash is gone, btw. But skipping the prologue doesn't work now:
Also, maybe we should investigate how the original keeps track of the original PC first? |
Just to make sure, this is still currently blocked by us not really knowing how this should be implemented, right? Might be worth waiting to see what seedhartha will do in his reone project there :P |
Yes, I'm still not sure how to best realize this. |
This PR implements the SwitchPlayerCharacter nwscript method. It allows the switch in the kotor2 prologue from the main character to T3M4. I hope, i did everything right, concerning object creation and destruction.