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

Computer players joining later will have their creatures initialized too #3441

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,45 @@
*/
/******************************************************************************/
#include "pre_inc.h"
#include "lvl_script_commands.h"

#include "lvl_script_conditions.h"
#include "lvl_script_lib.h"

#include <math.h>
#include <string.h>

#include "dungeon_data.h"
#include "thing_data.h"
#include "player_instances.h"
#include "keeperfx.hpp"
#include "custom_sprites.h"
#include "gui_soundmsgs.h"
#include "bflib_memory.h"
#include "bflib_sound.h"
#include "config_effects.h"
#include "config_magic.h"
#include "config_players.h"
#include "config_powerhands.h"
#include "config_settings.h"
#include "config_effects.h"
#include "config_spritecolors.h"
#include "config_trapdoor.h"
#include "config_powerhands.h"
#include "config_players.h"
#include "frontmenu_ingame_map.h"
#include "thing_effects.h"
#include "thing_physics.h"
#include "thing_navigate.h"
#include "console_cmd.h"
#include "creature_states_pray.h"
#include "creature_states_mood.h"
#include "room_util.h"
#include "creature_instances.h"
#include "power_hand.h"
#include "power_specials.h"
#include "creature_states.h"
#include "creature_states_mood.h"
#include "creature_states_pray.h"
#include "custom_sprites.h"
#include "dungeon_data.h"
#include "frontmenu_ingame_map.h"
#include "gui_soundmsgs.h"
#include "keeperfx.hpp"
#include "lvl_script_commands.h"
#include "lvl_script_conditions.h"
#include "lvl_script_lib.h"
#include "map_blocks.h"
#include "bflib_memory.h"
#include "post_inc.h"
#include "music_player.h"
#include "bflib_sound.h"
#include "config_spritecolors.h"
#include "player_instances.h"
#include "player_utils.h"
#include "power_hand.h"
#include "power_specials.h"
#include "room_util.h"
#include "sounds.h"
#include "thing_data.h"
#include "thing_effects.h"
#include "thing_navigate.h"
#include "thing_physics.h"

#include "post_inc.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -6031,6 +6031,8 @@ static void computer_player_process(struct ScriptContext* context)
{
script_support_setup_player_as_computer_keeper(i, model);
get_dungeon(i)->turns_between_entrance_generation = game.generate_speed;
init_creature_states_for_player(i);
post_init_player(get_player(i));
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/player_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TbBool player_sell_door_at_subtile(PlayerNumber plyr_idx, MapSubtlCoord stl_x, M
void init_players(void);
void init_player(struct PlayerInfo *player, short no_explore);
void post_init_players(void);
void post_init_player(struct PlayerInfo* player);
void init_players_local_game(void);
void init_keeper_map_exploration_by_terrain(struct PlayerInfo *player);
void init_keeper_map_exploration_by_creatures(struct PlayerInfo *player);
Expand Down
29 changes: 29 additions & 0 deletions src/thing_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,35 @@ void init_all_creature_states(void)
}
}

void init_creature_states_for_player(PlayerNumber plyr_idx)
{
int k = 0;
const struct StructureList* slist = get_list_for_thing_class(TCls_Creature);
int i = slist->index;
while (i != 0)
{
struct Thing* thing = thing_get(i);
if (thing_is_invalid(thing))
{
ERRORLOG("Jump to invalid thing detected");
break;
}
i = thing->next_of_class;
// Per-thing code
if (thing->owner == plyr_idx)
{
init_creature_state(thing);
}
// Per-thing code ends
k++;
if (k > THINGS_COUNT)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break;
}
}
}

void remove_thing_from_mapwho(struct Thing *thing)
{
struct Thing *mwtng;
Expand Down
1 change: 1 addition & 0 deletions src/thing_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ void init_player_start(struct PlayerInfo *player, TbBool keep_prev);
void setup_computer_players(void);
void setup_zombie_players(void);
void init_all_creature_states(void);
void init_creature_states_for_player(PlayerNumber plyr_idx);
TbBool update_creature_speed(struct Thing *thing);

TbBool perform_action_on_all_creatures_in_group(struct Thing *thing, Thing_Bool_Modifier action);
Expand Down
Loading