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

Decouple Golems from Players and use SpawnMonster for Golem #7665

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

Conversation

obligaron
Copy link
Contributor

Contributes to #543 and supports #7663

In master and vanilla golems are tied to a specific monster id. This monster id corresponds 1:1 to the player id. This is how the relation player<->golem relationship is maintained and that's also why the game reserves the first 4 monster slots for golems (max player count in multiplayer).

This PR changes that by

  • using goalVar3 to maintain the golem<->player relationship (should be 0 in singleplayer saves)
  • introducing a helper to find golems for a player
  • using SpawnMonster logic to spawn golems (similar to how monsters are spawned dynamically, see Support dynamically spawned monsters in multiplayer #6890)
  • to maintain vanilla compatibility, the first 4 slots are still reserved for golems. In singleplayer, the first monster slot is always used.

Additional notes

  • Allows multiple golems to be spawned by removing the KillGolem call in AddGolem for existing golems (allows better mods).
  • This PR supports up to 55 players because we still store the enemy id in a uint8_t (could be changed later).
  • This PR can be tested with the current player count by changing ReservedMonsterSlotsForGolems to a lower number (I tested with 2 players and set it to 0 and 1).

@@ -2389,10 +2334,16 @@ size_t OnSpawnMonster(const TCmd *pCmd, const Player &player)

size_t typeIndex = static_cast<size_t>(SDL_SwapLE16(message.typeIndex));
size_t monsterId = static_cast<size_t>(SDL_SwapLE16(message.monsterId));
uint8_t golemOwnerPlayerId = message.golemOwnerPlayerId;
int16_t golemSpellLevel = SDL_SwapLE16(message.golemSpellLevel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should not trust whatever spell level the remote player sends us. #7485

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

Successfully merging this pull request may close these issues.

2 participants