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

Make all trap types slappable #3843

Merged
merged 2 commits into from
Jan 24, 2025
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
19 changes: 10 additions & 9 deletions src/player_instances.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ long pinstfe_hand_whip(struct PlayerInfo *player, long *n)
trapst = get_trap_model_stats(thing->model);
if ((trapst->slappable > 0) && trap_is_active(thing))
{
struct Thing* trgtng = INVALID_THING;
shotst = get_shot_model_stats(trapst->created_itm_model);
if (trapst->slappable == 1)
{
external_activate_trap_shot_at_angle(thing, player->acamera->orient_a, trgtng);
} else
if (trapst->slappable == 2)
activate_trap_by_slap(player, thing);

struct Dungeon* dungeon = get_dungeon(thing->owner);
if (!dungeon_invalid(dungeon))
{
trgtng = get_nearest_enemy_creature_in_sight_and_range_of_trap(thing);
external_activate_trap_shot_at_angle(thing, player->acamera->orient_a, trgtng);
dungeon->trap_info.activated[thing->trap.flag_number]++;
if (thing->trap.flag_number > 0)
{
memcpy(&dungeon->last_trap_event_location, &thing->mappos, sizeof(struct Coord3d));
}
}
process_trap_charge(thing);
}
break;
case TCls_Object:
Expand Down
10 changes: 10 additions & 0 deletions src/thing_shots.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,16 @@ static TbBool shot_hit_trap_at(struct Thing* shotng, struct Thing* target, struc
if (((trapst->unstable == 1) && !(shotst->model_flags & ShMF_Disarming)) || trapst->unstable == 2)
{
activate_trap(target, target);
struct Dungeon* dungeon = get_dungeon(target->owner);
if (!dungeon_invalid(dungeon))
{
dungeon->trap_info.activated[target->trap.flag_number]++;
if (target->trap.flag_number > 0)
{
memcpy(&dungeon->last_trap_event_location, &target->mappos, sizeof(struct Coord3d));
}
}
process_trap_charge(target);
}
}
if (shotst->destroy_on_first_hit) {
Expand Down
51 changes: 50 additions & 1 deletion src/thing_traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,56 @@ void activate_trap(struct Thing *traptng, struct Thing *creatng)
}
}

void activate_trap_by_slap(struct PlayerInfo *player, struct Thing* traptng)
{
struct Thing* trgtng = INVALID_THING;
struct TrapConfigStats* trapst = get_trap_model_stats(traptng->model);
TbBool special_case = false;

if (trapst->slappable == 2)
{
trgtng = get_nearest_enemy_creature_in_sight_and_range_of_trap(traptng);
activate_trap(traptng, trgtng);
}
if (trapst->slappable == 1)
{
switch (trapst->activation_type)
{
case TrpAcT_EffectonTrap:
case TrpAcT_ShotonTrap:
case TrpAcT_SlabChange:
case TrpAcT_CreatureSpawn:
case TrpAcT_Power:
activate_trap(traptng, trgtng);
Copy link
Contributor

Choose a reason for hiding this comment

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

get_nearest_enemy_creature_in_sight_and_range_of_trap how does it works for keeper power?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it would fail to find a target creature, so direct target spells would fail. But powers that would not need a target creature would cast.

break;
default:
special_case = true;
break;
}

if (special_case == true)
{
traptng->trap.revealed = 1;
if (trapst->notify == true)
{
event_create_event(traptng->mappos.x.val, traptng->mappos.y.val, EvKind_AlarmTriggered, traptng->owner, 0);
}
thing_play_sample(traptng, trapst->trigger_sound_idx, NORMAL_PITCH, 0, 3, 0, 2, FULL_LOUDNESS);

switch (trapst->activation_type)
{
case TrpAcT_HeadforTarget90:
case TrpAcT_CreatureShot:
external_activate_trap_shot_at_angle(traptng, player->acamera->orient_a, trgtng);
break;
default:
ERRORLOG("Illegal trap activation type %d (idx=%d)", (int)trapst->activation_type, traptng->index);
break;
}
}
}
}

TbBool find_pressure_trigger_trap_target_passing_by_subtile(const struct Thing *traptng, MapSubtlCoord stl_x, MapSubtlCoord stl_y, struct Thing **found_thing)
{
struct Map* mapblk = get_map_block_at(stl_x, stl_y);
Expand Down Expand Up @@ -1089,7 +1139,6 @@ void external_activate_trap_shot_at_angle(struct Thing *thing, short angle, stru
&& (trapst->activation_type != TrpAcT_HeadforTarget90))
{
activate_trap(thing, trgtng);
process_trap_charge(thing);
if (thing->trap.num_shots != INFINITE_CHARGES)
{
if (thing->trap.num_shots > 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/thing_traps.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ TbBool rearm_trap(struct Thing *traptng);
TngUpdateRet update_trap(struct Thing *thing);
void init_traps(void);
void activate_trap(struct Thing *traptng, struct Thing *creatng);
void activate_trap_by_slap(struct PlayerInfo* player, struct Thing* traptng);
void process_trap_charge(struct Thing* traptng);

unsigned long remove_trap(struct Thing *traptng, long *sell_value);
unsigned long remove_trap_on_subtile(MapSubtlCoord stl_x, MapSubtlCoord stl_y, long *sell_value);
Expand Down
Loading