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

player.colour console command #3728

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions src/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,21 @@ TbBool cmd_speech_test(PlayerNumber plyr_idx, char * args)
return true;
}

TbBool cmd_player_colour(PlayerNumber plyr_idx, char * args)
{
char * pr2str = strsep(&args, " ");
PlayerNumber id = get_player_number_for_command(pr2str);
char * pr3str = strsep(&args, " ");
char colour_idx = get_rid(cmpgn_human_player_options, pr3str);
if (colour_idx > -1)
{
struct PlayerInfo * player = get_player(plyr_idx);
set_players_packet_action(player, PckA_SetPlayerColour, id, colour_idx, 0, 0);
return true;
}
return false;
}

TbBool cmd_exec(PlayerNumber plyr_idx, char * args)
{
struct ConsoleCommand {
Expand Down Expand Up @@ -1951,6 +1966,8 @@ TbBool cmd_exec(PlayerNumber plyr_idx, char * args)
{ "herogate.zoomto", cmd_zoom_to_hero_gate },
{ "sound.test", cmd_sound_test },
{ "speech.test", cmd_speech_test },
{ "player.color", cmd_player_colour},
{ "player.colour", cmd_player_colour},
};
SYNCDBG(2, "Command %d: %s",(int)plyr_idx, args);
const char * command = strsep(&args, " ");
Expand Down
67 changes: 2 additions & 65 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6006,7 +6006,6 @@ static void set_power_configuration_process(struct ScriptContext *context)
static void set_player_color_check(const struct ScriptLine *scline)
{
ALLOCATE_SCRIPT_VALUE(scline->command, scline->np[0]);

long color_idx = get_rid(cmpgn_human_player_options, scline->tp[1]);
if (color_idx == -1)
{
Expand All @@ -6020,75 +6019,13 @@ static void set_player_color_check(const struct ScriptLine *scline)
return;
}
}
value->shorts[0] = color_idx;
value->bytes[0] = (unsigned char)color_idx;
PROCESS_SCRIPT_VALUE(scline->command);
}

static void set_player_color_process(struct ScriptContext *context)
{
long color_idx = context->value->shorts[0];
struct Dungeon* dungeon;

for (int plyr_idx = context->plr_start; plyr_idx < context->plr_end; plyr_idx++)
{
dungeon = get_dungeon(plyr_idx);

if(dungeon->color_idx == color_idx)
{
continue;
}

dungeon->color_idx = color_idx;

update_panel_color_player_color(plyr_idx,color_idx);

for (MapSlabCoord slb_y=0; slb_y < gameadd.map_tiles_y; slb_y++)
{
for (MapSlabCoord slb_x=0; slb_x < gameadd.map_tiles_x; slb_x++)
{
struct SlabMap* slb = get_slabmap_block(slb_x,slb_y);
if (slabmap_owner(slb) == plyr_idx)
{
redraw_slab_map_elements(slb_x,slb_y);
}

}
}

const struct StructureList *slist;
slist = get_list_for_thing_class(TCls_Object);
int k = 0;
unsigned long i = slist->index;
while (i > 0)
{
struct Thing *thing;
thing = thing_get(i);
TRACE_THING(thing);
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)
{
ThingModel base_model = get_coloured_object_base_model(thing->model);
if(base_model != 0)
{
create_coloured_object(&thing->mappos, plyr_idx, thing->parent_idx,base_model);
delete_thing_structure(thing, 0);
}
}
// Per-thing code ends
k++;
if (k > slist->count)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break;
}
}
}
set_player_colour(context->player_idx, context->value->bytes[0]);
}

static void set_game_rule_check(const struct ScriptLine* scline)
Expand Down
58 changes: 39 additions & 19 deletions src/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,23 @@ TbBool process_players_global_packet_action(PlayerNumber plyr_idx)
}
}

TbBool process_players_general_packet_action(PlayerNumber plyr_idx)
{
struct PlayerInfo* player = get_player(plyr_idx);
struct Packet* pckt = get_packet_direct(player->packet_num);
SYNCDBG(6,"Processing player %d action %d",(int)plyr_idx,(int)pckt->action);
switch (pckt->action)
{
case PckA_SetPlayerColour:
{
set_player_colour(pckt->actn_par1, pckt->actn_par2);
return true;
}
default:
return false;
}
}

void process_players_map_packet_control(long plyr_idx)
{
SYNCDBG(6,"Starting");
Expand Down Expand Up @@ -1102,26 +1119,29 @@ void process_players_packet(long plyr_idx)
// Different changes to the game are possible for different views.
// For each there can be a control change (which is view change or mouse event not translated to action),
// and action perform (which does specific action set in packet).
switch (player->view_type)
if (!process_players_general_packet_action(plyr_idx))
{
case PVT_DungeonTop:
process_players_dungeon_control_packet_control(plyr_idx);
process_players_dungeon_control_packet_action(plyr_idx);
break;
case PVT_CreatureContrl:
process_players_creature_control_packet_control(plyr_idx);
process_players_creature_control_packet_action(plyr_idx);
break;
case PVT_CreaturePasngr:
//process_players_creature_passenger_packet_control(plyr_idx); -- there are no control changes in passenger mode
process_players_creature_passenger_packet_action(plyr_idx);
break;
case PVT_MapScreen:
process_players_map_packet_control(plyr_idx);
//process_players_map_packet_action(plyr_idx); -- there are no actions to perform from map screen
break;
default:
break;
switch (player->view_type)
{
case PVT_DungeonTop:
process_players_dungeon_control_packet_control(plyr_idx);
process_players_dungeon_control_packet_action(plyr_idx);
break;
case PVT_CreatureContrl:
process_players_creature_control_packet_control(plyr_idx);
process_players_creature_control_packet_action(plyr_idx);
break;
case PVT_CreaturePasngr:
//process_players_creature_passenger_packet_control(plyr_idx); -- there are no control changes in passenger mode
process_players_creature_passenger_packet_action(plyr_idx);
break;
case PVT_MapScreen:
process_players_map_packet_control(plyr_idx);
//process_players_map_packet_action(plyr_idx); -- there are no actions to perform from map screen
break;
default:
break;
}
}
}
SYNCDBG(8,"Finished");
Expand Down
2 changes: 2 additions & 0 deletions src/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ enum TbPacketAction {
PckA_SetRoomspaceDragPaint,
PckA_PlyrQueryCreature,
PckA_CheatGiveDoorTrap,
PckA_SetPlayerColour,
};

/** Packet flags for non-action player operation. */
Expand Down Expand Up @@ -307,6 +308,7 @@ TbBool process_players_dungeon_control_packet_action(long idx);
void process_players_creature_control_packet_control(long idx);
void process_players_creature_passenger_packet_action(long idx);
void process_players_creature_control_packet_action(long idx);
TbBool process_players_general_packet_action(PlayerNumber plyr_idx);
void process_frontend_packets(void);
void process_map_packet_clicks(long idx);
void process_pause_packet(long a1, long a2);
Expand Down
54 changes: 54 additions & 0 deletions src/player_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "gui_soundmsgs.h"
#include "gui_frontmenu.h"
#include "config_settings.h"
#include "config_spritecolors.h"
#include "config_terrain.h"
#include "map_blocks.h"
#include "map_utils.h"
Expand Down Expand Up @@ -1221,11 +1222,64 @@ void compute_and_update_player_payday_total(PlayerNumber plyr_idx)
struct Dungeon* dungeon = get_players_num_dungeon(plyr_idx);
dungeon->creatures_total_pay = compute_player_payday_total(dungeon);
}

void compute_and_update_player_backpay_total(PlayerNumber plyr_idx)
{
SYNCDBG(15, "Starting for player %d", (int)plyr_idx);
struct Dungeon* dungeon = get_dungeon(plyr_idx);
dungeon->creatures_total_backpay = compute_player_payday_total(dungeon);
}

void set_player_colour(PlayerNumber plyr_idx, unsigned char colour_idx)
{
struct Dungeon* dungeon = get_dungeon(plyr_idx);
if (dungeon->color_idx != colour_idx)
{
dungeon->color_idx = colour_idx;
update_panel_color_player_color(plyr_idx,colour_idx);
for (MapSlabCoord slb_y=0; slb_y < gameadd.map_tiles_y; slb_y++)
{
for (MapSlabCoord slb_x=0; slb_x < gameadd.map_tiles_x; slb_x++)
{
struct SlabMap* slb = get_slabmap_block(slb_x,slb_y);
if (slabmap_owner(slb) == plyr_idx)
{
redraw_slab_map_elements(slb_x,slb_y);
}

}
}
const struct StructureList *slist = get_list_for_thing_class(TCls_Object);
int k = 0;
unsigned long i = slist->index;
while (i > 0)
{
struct Thing *thing = thing_get(i);
TRACE_THING(thing);
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)
{
ThingModel base_model = get_coloured_object_base_model(thing->model);
if(base_model != 0)
{
create_coloured_object(&thing->mappos, plyr_idx, thing->parent_idx,base_model);
delete_thing_structure(thing, 0);
}
}
// Per-thing code ends
k++;
if (k > slist->count)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break;
}
}
}
}

/******************************************************************************/
2 changes: 2 additions & 0 deletions src/player_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ 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);
void process_players(void);

void set_player_colour(PlayerNumber plyr_idx, unsigned char colour_idx);
/******************************************************************************/
#ifdef __cplusplus
}
Expand Down