From 88738bcc2f0a8a64cf037ccb83b519e6e901e1db Mon Sep 17 00:00:00 2001 From: AdamPlenty <58278560+AdamPlenty@users.noreply.github.com> Date: Mon, 7 Feb 2022 11:37:42 +0000 Subject: [PATCH] Player can see invisible units if possessed creature can (#1244) Also stops possessed units blocking view if using cheats to possess enemy. --- src/creature_graphics.c | 19 +++++++++++++++++-- src/creature_graphics.h | 1 + src/player_instances.c | 36 +++++++++++++++++++++++++++++++++++- src/player_instances.h | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/creature_graphics.c b/src/creature_graphics.c index 5f0e093917..6c3fcb2edd 100644 --- a/src/creature_graphics.c +++ b/src/creature_graphics.c @@ -32,6 +32,7 @@ #include "vidfade.h" #include "keeperfx.hpp" #include "engine_render.h" +#include "player_instances.h" #ifdef __cplusplus extern "C" { @@ -356,7 +357,7 @@ void update_creature_graphic_field_4F(struct Thing *thing) thing->field_4F &= ~TF4F_Transpar_Flags; thing->field_4F &= ~TF4F_Unknown40; // Now set only those that should be - if (((thing->alloc_flags & TAlF_IsControlled) != 0) && is_my_player_number(thing->owner)) + if ( (is_thing_directly_controlled_by_player(thing, my_player_number)) || (is_thing_passenger_controlled_by_player(thing, my_player_number)) ) { thing->field_4F |= TF4F_Unknown01; } @@ -372,7 +373,21 @@ void update_creature_graphic_field_4F(struct Thing *thing) thing->field_4F |= TF4F_Transpar_4; } else { - thing->field_4F |= TF4F_Unknown01; + thing->field_4F |= TF4F_Unknown01; + struct PlayerInfo* player = get_my_player(); + struct Thing* creatng = thing_get(player->influenced_thing_idx); + if (creatng != thing) + { + if ( (is_thing_directly_controlled_by_player(creatng, player->id_number)) || (is_thing_passenger_controlled_by_player(creatng, player->id_number)) ) + { + if (creature_can_see_invisible(creatng)) + { + thing->field_4F &= ~TF4F_Unknown01; + thing->field_4F &= ~TF4F_Transpar_Flags; + thing->field_4F |= TF4F_Transpar_4; + } + } + } } } } diff --git a/src/creature_graphics.h b/src/creature_graphics.h index 62ef26367d..e4c832718f 100644 --- a/src/creature_graphics.h +++ b/src/creature_graphics.h @@ -123,6 +123,7 @@ short get_creature_anim(struct Thing *thing, unsigned short frame); short get_creature_model_graphics(long crmodel, unsigned short frame); void set_creature_model_graphics(long crmodel, unsigned short frame, unsigned long val); void set_creature_graphic(struct Thing *thing); +void update_creature_graphic_field_4F(struct Thing *thing); /******************************************************************************/ #ifdef __cplusplus diff --git a/src/player_instances.c b/src/player_instances.c index a444982bac..d3c3e6f7ff 100644 --- a/src/player_instances.c +++ b/src/player_instances.c @@ -1285,7 +1285,7 @@ TbBool is_thing_directly_controlled_by_player(const struct Thing *thing, PlayerN } else { - if ((player->work_state != PSt_CtrlDirect) && (player->work_state != PSt_FreeCtrlDirect)) + if ((player->work_state != PSt_CtrlDirect) && (player->work_state != PSt_FreeCtrlDirect) && (player->work_state != PSt_CtrlDungeon)) { return false; } @@ -1319,4 +1319,38 @@ TbBool is_thing_directly_controlled_by_player(const struct Thing *thing, PlayerN } return false; } + +TbBool is_thing_passenger_controlled_by_player(const struct Thing *thing, PlayerNumber plyr_idx) +{ + if (!thing_exists(thing)) + return false; + struct PlayerInfo* player = get_player(plyr_idx); + if (player_invalid(player)) + { + ERRORLOG("Bad player: $d", plyr_idx); + return false; + } + else + { + if ((player->work_state != PSt_CtrlPassngr) && (player->work_state != PSt_FreeCtrlPassngr)) + return false; + switch (player->instance_num) + { + case PI_PsngrCtrl: + return ( (thing->index == player->influenced_thing_idx) && (player->view_type == PVT_CreaturePasngr) ); + case PI_CrCtrlFade: + return (thing->index == player->controlled_thing_idx); + case PI_PsngrCtLeave: + return (thing->index == player->influenced_thing_idx); + case PI_Unset: + case PI_Whip: // Whip can be used at any time by comp. assistant + case PI_WhipEnd: + return (thing->index == player->controlled_thing_idx); + default: + ERRORLOG("Bad player %d instance %d",plyr_idx,(int)player->instance_num); + break; + } + } + return false; +} /******************************************************************************/ diff --git a/src/player_instances.h b/src/player_instances.h index a5431d530d..796fb3a12d 100644 --- a/src/player_instances.h +++ b/src/player_instances.h @@ -101,6 +101,7 @@ TbBool is_thing_passenger_controlled(const struct Thing *thing); TbBool is_thing_query_controlled(const struct Thing *thing); TbBool is_thing_some_way_controlled(const struct Thing *thing); TbBool is_thing_directly_controlled_by_player(const struct Thing *thing, PlayerNumber plyr_idx); +TbBool is_thing_passenger_controlled_by_player(const struct Thing *thing, PlayerNumber plyr_idx); struct Room *player_build_room_at(MapSubtlCoord stl_x, MapSubtlCoord stl_y, PlayerNumber plyr_idx, RoomKind rkind); TbBool player_place_trap_at(MapSubtlCoord stl_x, MapSubtlCoord stl_y, PlayerNumber plyr_idx, ThingModel tngmodel);