diff --git a/lib/random.lua b/lib/random.lua index a9c29a8..58d2887 100644 --- a/lib/random.lua +++ b/lib/random.lua @@ -41,12 +41,12 @@ end local R = math.random local RS = math.randomseed - local function random(n, m) RANDOM_CALLS_COUNT = RANDOM_CALLS_COUNT + 1 local r if n then + log('calling random with "n" %g', n) if m then r = math.floor(R() * (m - n) + n) else diff --git a/src/mob.lua b/src/mob.lua index 6ce6ff6..7c2c3d4 100644 --- a/src/mob.lua +++ b/src/mob.lua @@ -131,7 +131,7 @@ end local function get_spawn_hex() -- ensure we spawn on an random tile along the map's edges - local roll = math.random(HEX_GRID_WIDTH * 2 + HEX_GRID_HEIGHT * 2) - 1 + local roll = math.floor(math.random() * (HEX_GRID_WIDTH * 2 + HEX_GRID_HEIGHT * 2) - 1) local x, y if roll < HEX_GRID_HEIGHT then @@ -298,6 +298,11 @@ local function update_mob_beeper(mob, mob_index) if mob_can_pass_through(mob, mob.frame_target) then local from = hex_map_get(game_state.map, mob.hex) local to = hex_map_get(game_state.map, mob.frame_target) + + if not from or not to then + -- @TODO this happens rarely, why? when? + return + end local rate = (4 * mob.speed - math.abs(to.elevation - from.elevation)) * am.delta_time mob.position = mob.position + math.normalize(hex_to_pixel(mob.frame_target, vec2(HEX_SIZE)) - mob.position) * rate