Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Nostritius
Copy link
Contributor

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.

@DrMcCoy
Copy link
Member

DrMcCoy commented Oct 6, 2019

Apparently not, since it invokes UB :P

sanitizer log here: https://gist.github.com/DrMcCoy/94d189fb6136cf2f5e5316dde6fdaaa3

throw Common::Exception("%u is not an available npc id", index);

Creature *newPC = createCreature(_partyController.getAvailableNPCTemplate(index));
ObjectMan.registerObject(newPC);
Copy link
Contributor

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

ObjectMan.registerObject(this);

notifyPartyLeaderChanged();

_area->removeObject(oldPC);
removeObject(*oldPC);
Copy link
Contributor

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

_module->removeObject(*object);

_partyController.addPartyMember(index, newPC);
int oldLeaderID = _partyController.getPartyLeaderID();

Creature *oldPC = _partyController.getPartyLeader();
Copy link
Contributor

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?

@Nostritius
Copy link
Contributor Author

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?

@seedhartha
Copy link
Contributor

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 (Module::loadPC()), while the party leader a.k.a. currently controlled character, is a changing reference to either the PC or one of the party members. SwitchPlayerCharacter should probably recreate the PC object (Module::_pc), regardless of his status in the party, while persisting Module::_pcInfo and Module::_chargenInfo of the original PC.

@DrMcCoy
Copy link
Member

DrMcCoy commented Oct 13, 2019

Yeah, I guess we have three separate concepts here, in the KotOR games.

  1. The originally created player character
  2. The current player character, which can be different when the game switches to another POV (during the tutorial, for example)
  3. The party leader

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).

@DrMcCoy
Copy link
Member

DrMcCoy commented Oct 13, 2019

The crash is gone, btw. But skipping the prologue doesn't work now:

WARNING: Failed running dialog script "a_end_001"
    Because: Failed running engine function "SwitchPlayerCharacter" (11)
    Because: 4294967295 is not an available npc id

Also, maybe we should investigate how the original keeps track of the original PC first?

@DrMcCoy
Copy link
Member

DrMcCoy commented Aug 6, 2020

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

@Nostritius
Copy link
Contributor Author

Yes, I'm still not sure how to best realize this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants