Skip to content

Commit

Permalink
Player can see invisible units if possessed creature can (#1244)
Browse files Browse the repository at this point in the history
Also stops possessed units blocking view if using cheats to possess enemy.
  • Loading branch information
AdamPlenty committed Feb 7, 2022
1 parent f3e7caa commit 88738bc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/creature_graphics.c
Expand Up @@ -32,6 +32,7 @@
#include "vidfade.h"
#include "keeperfx.hpp"
#include "engine_render.h"
#include "player_instances.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/creature_graphics.h
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion src/player_instances.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
/******************************************************************************/
1 change: 1 addition & 0 deletions src/player_instances.h
Expand Up @@ -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);
Expand Down

0 comments on commit 88738bc

Please sign in to comment.