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

Take control of and play as NPC followers #51450

Merged
merged 3 commits into from
Sep 11, 2021

Conversation

eltank
Copy link
Contributor

@eltank eltank commented Sep 7, 2021

Summary

Features "Take control of and play as NPC followers"

Purpose of change

Ever wanted to take control of a follower for a while in order to make use of their abilities? Or just continue playing as that NPC? Well now you can.
This PR adds infrastructure allowing the player to relinquish control of their current avatar character and permanently take control of a follower NPC.
This functionality could be used to give a new option on death (continue playing the character of a follower), or simply to change the way you play the game (switch to controlling a follower at any time no matter where they are).
But for now it's limited to the debug menu as a proof of concept.

Describe the solution

The key idea that enables all of this is the transfer of Character data between avatar and npc objects (both subclasses of Character) using the Character move-assignment operator.
Add a protected Character::swap_character(Character&, Character&) and a public avatar::control_npc(npc&) that uses it.
Add a shadow_npc field to avatar which stores the suppressed personality of the character being controlled by the avatar. A shadow npc is generated automatically for the "original character" the first time this feature is used. The default shadow NPC has a neutral personality (0 in every personality trait) and a high op_of_u (10 trust and 10 value).
Move the followers field from Character to avatar.
Add a debug menu entry to activate the feature (target any follower NPC including those outside the reality bubble).

Describe alternatives you've considered

Doing more with it, as described above. But I want to collect some feedback first.

Implementing a "possession" spell in Magiclysm. I still want to do that in another PR, but the way that will work will be fundamentally different. The avatar won't change, instead they'll be rooted in place while they "warg" a monster, similar to remote-controlling an RC car or vehicle but seeing through the target's eyes. The range will be limited (less than reality bubble radius). The player should be able to invoke the controlled monster's special attacks and cancel at any time, possibly with negative after-effects, especially if the target took damage. Of course, maintaining possession will also cost mana each turn. Possessing one's own familiar may be cheaper/free.

Testing

Start a new game as Debug. Debug all skills to 5. Using debug Mind Control and NPC spawning acquire 2 followers. Rename them A and B. Tell them to guard. Make note of the 2 NPCs personalities to make sure they remain unchanged.

image

image

Take over npc A. Save and quit. In the main menu see only 1 save for the test world, named "Debug" (the save name is unaffected by character change). Load.
Take over npc B, repeat above.
Inspect Debug's personality, check default shadow NPC personality.

image

Talk to Debug, order them to guard. Switch to Debug. Inspect the personalities of A and B, make sure they were not swapped:

image

image

Next, a Z-level test. Swap to A, send them to the basement, swap to B, send them to the roof, swap to Debug and order the npcs to follow.

control_npc3.mp4

Next, a long range test. Order the npcs to guard. Teleport far away, then take control of A.

control_npc4.mp4

Now let's inspect the faction menu. A, being the current leader, is not listed but Debug is.

image

Swap to Debug and teleport back. Inspect the faction menu again. The list shows A and B.

image

Finally switch to A and... murder Debug. Observe that the game is not over and you can simply carry on (you monster).

image

The faction roster is updated.

image

Additional context

Q: What happens if you switch to a passenger while driving?
A: Your previous character stops driving and the vehicle starts coasting. You can swap places with the former driver and continue driving, if the vehicle doesn't crash into something first.

Q: What happens if you switch while hauling items on the ground?
A: Your previous character pauses hauling, but will resume if you switch back and there are items below them.

Q: What happens if you switch while dragging a cart?
A: The dragging stops (doesn't resume even if you switch back immediately)

Q: What happens if you switch to an npc who is reading a book?
A: You find yourself reading! Press . to stop.

Q: What happens if you switch to an npc who is deconstructing a vehicle?
A: You find yourself removing vehicle parts. Press . to stop.

Q: What happens if you switch to an npc who is building something?
A: You find yourself doing construction work. If there are multiple blueprints, you'll do all of them. Press . to stop.

You can see the pattern here... Switch to an npc who is performing an activity and you'll find yourself doing it.

Note that controlled npcs will burn calories and will eat if they're hungry and they have food when you relinquish control.

@PatrikLundell
Copy link
Contributor

It's an interesting functionality with interesting potential applications.

However, I think it also has a potential for creating "interesting" bugs, so it probably would need a fair bit of testing by people who can think up more or less weird situations that can cause issues.
Some random cases:

  • Swapping while driving (how will a companion handle suddenly being in control of a vehicle, including a mech and a mount?).
  • Swapping while climbing (or just on a roof top).
  • Swapping while another companion is performing reality bubble dependent tasks (such as sorting, but a lot of different tasks are probably needed to be tested). I suspect it will work as if the PC just walked/drove away, but a potentially large jump of the bubble focus should be tested.
  • Swapping while hauling stuff.
  • ...

@linonetwo
Copy link
Contributor

linonetwo commented Sep 7, 2021

Seems this feature needs debug currently, and will disable achievement?

Can you consider making this a normal action, that can be placed in the player action menu? Consider the current NPC AI, I think this will not be too much harmful to game immersiveness, but will enrich the game play.

@eltank
Copy link
Contributor Author

eltank commented Sep 7, 2021

I think it also has a potential for creating "interesting" bugs, so it probably would need a fair bit of testing.

Yes.

Seems this feature needs debug currently, and will disable achievement?

Yes.

Can you consider making this a normal action.

I am certainly considering that, but I don't make the call about what's allowed in the game.

@eltank
Copy link
Contributor Author

eltank commented Sep 7, 2021

Currently this will create an extra character save file if you don't swap back to your original body before saving. This doesn't break the game, but it then shows both character names as load options when you start the game which is confusing.

I have an idea about how to fix that, but I need to do a bit more work.

@eltank eltank marked this pull request as draft September 7, 2021 10:52
@actual-nh actual-nh added <Enhancement / Feature> New features, or enhancements on existing [C++] Changes (can be) made in C++. Previously named `Code` Code: Debug Debugging and troubleshooting the game, also includes the debug menu Game: Mechanics Change Code that changes how major features work labels Sep 7, 2021
@eltank
Copy link
Contributor Author

eltank commented Sep 8, 2021

I wrote #51466 as a pre-requisite to fix the save duplication. I also thought some more about how to make controlling any follower work without accidentally swapping the followers' minds (i.e. if you swap with A, then with B then back with your original character then A and B remain swapped).

Instead of thinking of it as a mind-swap, think of it as you (the player) taking control of an NPC, suppressing their (simulated) consciousness. Which means that avatar needs to contain an instance of the npc object for the NPC you took over, let's call this instance "shadow npc". Your original character would also have a "shadow npc" instance. When you switch characters, the "shadow npc" associated with your current character becomes active, while the "npc" instance of the target becomes a "shadow npc" and that character is taken over by the avatar instance.

I'll implement this idea tomorrow.

@Entity-y
Copy link
Contributor

Entity-y commented Sep 8, 2021

To balance this out and not have this amazing feature locked behind a debug menu, this could be added to the faction interface. Swapping characters could be tied to the NPC's opinion of the player and if the NPC decides to mutiny then they would no longer be accessible to swap to.

image
image

It might also be good to change the current save structure to a party instead of individual characters.

@eltank eltank changed the title Add avatar-npc mind swap to Debug menu Take control of and play as NPC followers Sep 8, 2021
@PatrikLundell
Copy link
Contributor

I believe the debug menu access should be as broad as reasonable, i.e. if possible, it should allow you to control NPCs (and, again if possible, monsters), while a "regular" party feature should be restricted to companions. Introduction of the party application ought to be delayed until the functionality has been tested out via the debug menu.

Thus, both avenues ought to use the same functionality, but the party one would be restricted further up in the call chain.

The suggestion to tie the structure to your factions (which is what I interpret @Entity-y to mean, rather than a new group level) ought to work well for regular use, but will it work for debug mode without introducing weird side effects or requirements for controlled NPCs to be included into and then kicked out of your faction?

@eltank
Copy link
Contributor Author

eltank commented Sep 8, 2021

To balance this out and not have this amazing feature locked behind a debug menu, this could be added to the faction interface. Swapping characters could be tied to the NPC's opinion of the player and if the NPC decides to mutiny then they would no longer be accessible to swap to.

That's precisely where I want to put it, if it's allowed.
With a few changes I think I can make it work long-distance, so you can take control of far-away NPCs.

That's a good suggestion about handling disgruntled NPCs, I can make it require non-negative reputation. There's a slight issue with that. The npc that takes over when you leave the original character has 0 trust. If you do anything to annoy them you can't change back. [Edit: I bumped that up to 10]

That also brings up some other issues with this feature. All NPCs have an "opinion of you", which at the moment doesn't change when you switch bodies. For non-follower NPCs that might make sense, you could say it's their opinion of your faction. But why would your followers accept orders from another member of your faction who isn't the leader? And shouldn't their opinion reset to 0 when you're not in the leader's body? Should I make it so that only the leader can give orders? Or maybe when you switch characters you're also transferring leadership?

Until all these issues can be resolved it's probably best to keep it as a debug feature.

@PatrikLundell
Copy link
Contributor

I believe you should always be allowed to switch back to the PC, but companion opinions of each other probably would need further work (probably in a separate PR) before usage of this feature as a party mode is free of that kind of gotchas.
This issue with leadership is essentially the nebulous player party overlordship vs the roles of the individual characters. Party based games typically hand waves that away by having all the party members being puppets of the overlord when it comes to control (although some allow members to have different agendas that can lead to them breaking with the party, but unless it's a betrayal plot twist it typically doesn't happen mid control). My approach would be to allow the currently appointed leader (i.e. the character currently possessed by the player) to order the other party members around as usual. Once a companion decides to break with the party the companion reverts to becoming an NPC, and thus won't be a party member or subject to party control. There's probably a need for some kind of check to avoid the PC breaking with the player's faction, though.

Some terminology, to avoid confusion:

  • Here I use party as a synonym for faction, but there may be a need to make a distinction (akin to how some party RPGs may let you switch companions in and out of the active party).
  • "Companion" is used to denote a faction member who's not the PC (although the status of the PC character when the player is controlling a companion may be that of a companion in some circumstances, and set apart in others).
  • NPC any non PC, but I use the term "companion" instead if only faction members are indicated. If there's a need to specify non companion NPCs that would have to be done explicitly.

@eltank
Copy link
Contributor Author

eltank commented Sep 9, 2021

Instead of thinking of it as a mind-swap, think of it as you (the player) taking control of an NPC, suppressing their (simulated) consciousness. Which means that avatar needs to contain an instance of the npc object for the NPC you took over, let's call this instance "shadow npc". Your original character would also have a "shadow npc" instance. When you switch characters, the "shadow npc" associated with your current character becomes active, while the "npc" instance of the target becomes a "shadow npc" and that character is taken over by the avatar instance.

I'll implement this idea tomorrow.

This is done. I also added book-keeping code to keep faction membership references updated, fixed some post-transfer UI issues and made the feature work beyond the reality bubble.
There's a new video in the OP demonstrating long-range control.

@eltank eltank force-pushed the swap_player branch 3 times, most recently from b86af51 to 8878407 Compare September 10, 2021 08:44
@eltank eltank marked this pull request as ready for review September 10, 2021 08:44
@eltank
Copy link
Contributor Author

eltank commented Sep 10, 2021

Finished testing, found and fixed another bug and now it's ready for review.

@kevingranade kevingranade merged commit 85661df into CleverRaven:master Sep 11, 2021
@linonetwo
Copy link
Contributor

so this finally being a debug feature?

@eltank eltank deleted the swap_player branch September 11, 2021 06:24
@eltank
Copy link
Contributor Author

eltank commented Sep 11, 2021

so this finally being a debug feature?

Yes, you'll be able to use this via the debug menu in the next Experimental release. I've got some plans for making the feature available without debug, but first I want to see if anyone finds bugs that I missed.

@Theawesomeboophis
Copy link
Contributor

so this finally being a debug feature?

Yes, you'll be able to use this via the debug menu in the next Experimental release. I've got some plans for making the feature available without debug, but first I want to see if anyone finds bugs that I missed.

Maybe a mind control mutation or something, or a spell ( Not sure if there's spells in vanilla), so that it can be done immersively?
I think this is a really cool idea in any situation, and am excited to see where this goes.

@linonetwo
Copy link
Contributor

I think this is also a way of role-playing, that you are playing a group of survivors. Some games recommend players to play this way, like genshin-impact, Pokémon Mystery Dungeon, and Rimworld.

I think even this feature is easily accessible (just like gender change...), we can still enhance the immersive, players can feel this game is telling stories about survivors working together in the world, not just a lonely man walking in the world. This can make the world warmer, and make players feel accompanied.

@eltank eltank mentioned this pull request Sep 15, 2021
@eltank
Copy link
Contributor Author

eltank commented Sep 15, 2021

Future development (i.e. the plan for taking this out of debug and making it a game feature) is described in #51632

@linonetwo
Copy link
Contributor

When using this feature, it always saying "disable achievement", which is somehow annoying... Can you move it out of the debug menu to make it easier for players to test this feature? @eltank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Debug Debugging and troubleshooting the game, also includes the debug menu <Enhancement / Feature> New features, or enhancements on existing Game: Mechanics Change Code that changes how major features work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants