From 3fbaaddd77b13d22e5b3244890200f659d6de8c2 Mon Sep 17 00:00:00 2001 From: walter253 <130906143+walt253@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:47:58 +0100 Subject: [PATCH 1/3] DrawSwipeCrashFix --- config/fxdata/creature.cfg | 6 ++---- src/creature_states_combt.c | 1 - src/room_entrance.c | 1 - src/thing_creature.c | 24 ++++++++++++++++-------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/config/fxdata/creature.cfg b/config/fxdata/creature.cfg index 5b04800cee..a29cebb90d 100644 --- a/config/fxdata/creature.cfg +++ b/config/fxdata/creature.cfg @@ -70,10 +70,8 @@ RangeMax = 0 ; 3,4 will only target other players, 5,6 only own player. ; 7 will target traps. PrimaryTarget = 0 -; Instance used by creature "going postal" while working in a room -; Creature will only use available instances with the highest priority, -; If multiple instances have the same PostalPriority, one is chosen randomly -; 0 disables the instance for beeing used while "going postal". +; Instance used when the creature is 'going postal' in a room. It will use the instance with the highest priority. +; If multiple have the same priority, one is chosen randomly. 0 disables the instance. PostalPriority = 0 ; Instance properties flags: ; REPEAT_TRIGGER allows player to hold down the mouse button to cast. diff --git a/src/creature_states_combt.c b/src/creature_states_combt.c index f2be3d7b79..307f4ed83f 100644 --- a/src/creature_states_combt.c +++ b/src/creature_states_combt.c @@ -1893,7 +1893,6 @@ CrInstance get_postal_instance_to_use(const struct Thing *thing, unsigned long d CrInstance av_postal_inst[INSTANCE_TYPES_MAX]; short av_postal_inst_num = 0; char highest_prio = 0; - short highest_prio_idx = CrInst_NULL; // Loop through the cached postal instances for (short j = 0; j < postal_inst_num; j++) { diff --git a/src/room_entrance.c b/src/room_entrance.c index 6a4c671a46..9dfe6f042f 100644 --- a/src/room_entrance.c +++ b/src/room_entrance.c @@ -435,7 +435,6 @@ TbBool update_creature_pool_state(void) void add_creature_to_pool(ThingModel kind, long amount) { - long prev_amount; kind %= game.conf.crtr_conf.model_count; if (amount > 0 && game.pool.crtr_kind[kind] > LONG_MAX - amount) diff --git a/src/thing_creature.c b/src/thing_creature.c index dfb5e49142..9ae4b034bb 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -393,7 +393,7 @@ void draw_swipe_graphic(void) if (thing_is_creature(thing)) { struct CreatureControl* cctrl = creature_control_get_from_thing(thing); - if (instance_draws_possession_swipe(cctrl->instance_id)) + if ((instance_draws_possession_swipe(cctrl->instance_id)) && (cctrl->inst_total_turns > 0)) { lbDisplay.DrawFlags = Lb_SPRITE_TRANSPAR4; long n = (int)cctrl->inst_turn * (5 << 8) / cctrl->inst_total_turns; @@ -404,23 +404,31 @@ void draw_swipe_graphic(void) struct TbSprite* sprlist = &swipe_sprites[SWIPE_SPRITES_X * SWIPE_SPRITES_Y * i]; struct TbSprite* startspr = &sprlist[1]; struct TbSprite* endspr = &sprlist[1]; - for (n=0; n < SWIPE_SPRITES_X; n++) + for (n = 0; n < SWIPE_SPRITES_X; n++) { allwidth += endspr->SWidth; endspr++; } - int units_per_px = (LbScreenWidth() * 59 / 64) * 16 / allwidth; + int units_per_px; + if (allwidth != 0) + { + units_per_px = (LbScreenWidth() * 59 / 64) * 16 / allwidth; + } + else + { + units_per_px = 0; + } int scrpos_y = (MyScreenHeight * 16 / units_per_px - (startspr->SHeight + endspr->SHeight)) / 2; struct TbSprite *spr; int scrpos_x; if (myplyr->swipe_sprite_drawLR) { int delta_y = sprlist[1].SHeight; - for (i=0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i+=SWIPE_SPRITES_X) + for (i = 0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i += SWIPE_SPRITES_X) { spr = &startspr[i]; scrpos_x = (MyScreenWidth * 16 / units_per_px - allwidth) / 2; - for (n=0; n < SWIPE_SPRITES_X; n++) + for (n = 0; n < SWIPE_SPRITES_X; n++) { LbSpriteDrawResized(scrpos_x * units_per_px / 16, scrpos_y * units_per_px / 16, units_per_px, spr); scrpos_x += spr->SWidth; @@ -431,12 +439,12 @@ void draw_swipe_graphic(void) } else { lbDisplay.DrawFlags = Lb_SPRITE_TRANSPAR4 | Lb_SPRITE_FLIP_HORIZ; - for (i=0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i+=SWIPE_SPRITES_X) + for (i = 0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i += SWIPE_SPRITES_X) { spr = &sprlist[SWIPE_SPRITES_X+i]; int delta_y = spr->SHeight; scrpos_x = (MyScreenWidth * 16 / units_per_px - allwidth) / 2; - for (n=0; n < SWIPE_SPRITES_X; n++) + for (n = 0; n < SWIPE_SPRITES_X; n++) { LbSpriteDrawResized(scrpos_x * units_per_px / 16, scrpos_y * units_per_px / 16, units_per_px, spr); scrpos_x += spr->SWidth; @@ -449,7 +457,7 @@ void draw_swipe_graphic(void) return; } } - // we get here many times a second when in possession mode and not attacking: to randomise the swipe direction + // We get here many times a second when in possession mode and not attacking: to randomise the swipe direction. randomise_swipe_graphic_direction(); } From 75ec8e3c2774f463bc9fa935b9b45000b035f2ec Mon Sep 17 00:00:00 2001 From: walter253 <130906143+walt253@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:59:33 +0100 Subject: [PATCH 2/3] maybe best to default it to 1 if it happens units_per_px shouldn't be 0 too --- src/thing_creature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thing_creature.c b/src/thing_creature.c index 9ae4b034bb..45faf99063 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -416,7 +416,7 @@ void draw_swipe_graphic(void) } else { - units_per_px = 0; + units_per_px = 1; } int scrpos_y = (MyScreenHeight * 16 / units_per_px - (startspr->SHeight + endspr->SHeight)) / 2; struct TbSprite *spr; From 4ba5e01865d1fc2a5b2ff4f28fa92a58091c1381 Mon Sep 17 00:00:00 2001 From: walter253 <130906143+walt253@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:53:02 +0100 Subject: [PATCH 3/3] Update thing_creature.c no point trying to draw a zero-width sprite --- src/thing_creature.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/thing_creature.c b/src/thing_creature.c index 45faf99063..cb2502b6ea 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -400,7 +400,9 @@ void draw_swipe_graphic(void) long allwidth = 0; long i = (abs(n) >> 8) -1; if (i >= SWIPE_SPRITE_FRAMES) + { i = SWIPE_SPRITE_FRAMES-1; + } struct TbSprite* sprlist = &swipe_sprites[SWIPE_SPRITES_X * SWIPE_SPRITES_Y * i]; struct TbSprite* startspr = &sprlist[1]; struct TbSprite* endspr = &sprlist[1]; @@ -409,14 +411,14 @@ void draw_swipe_graphic(void) allwidth += endspr->SWidth; endspr++; } - int units_per_px; - if (allwidth != 0) + if (allwidth == 0) { - units_per_px = (LbScreenWidth() * 59 / 64) * 16 / allwidth; + return; // No point trying to draw a zero-width sprite. } - else + int units_per_px = (LbScreenWidth() * 59 / 64) * 16 / allwidth; + if (units_per_px == 0) { - units_per_px = 1; + return; } int scrpos_y = (MyScreenHeight * 16 / units_per_px - (startspr->SHeight + endspr->SHeight)) / 2; struct TbSprite *spr; @@ -436,7 +438,8 @@ void draw_swipe_graphic(void) } scrpos_y += delta_y; } - } else + } + else { lbDisplay.DrawFlags = Lb_SPRITE_TRANSPAR4 | Lb_SPRITE_FLIP_HORIZ; for (i = 0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i += SWIPE_SPRITES_X)