From 2810aa9c1cddfd09b161b52147eebeb88fbfc694 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Sun, 13 Oct 2024 19:52:47 -0400 Subject: [PATCH] fix angry ghost being visually weird, cull more dead entitiys from enemy sync --- .../data/scripts/perks/angry_ghost_shoot.lua | 36 +++++++++++++------ quant.ew/files/core/util.lua | 1 + quant.ew/files/system/enemy_sync.lua | 5 +++ .../files/system/world_sync/world_sync.lua | 4 +-- quant.ew/init.lua | 4 --- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/quant.ew/data/scripts/perks/angry_ghost_shoot.lua b/quant.ew/data/scripts/perks/angry_ghost_shoot.lua index 45821a15..8f9c689f 100644 --- a/quant.ew/data/scripts/perks/angry_ghost_shoot.lua +++ b/quant.ew/data/scripts/perks/angry_ghost_shoot.lua @@ -1,21 +1,37 @@ dofile_once("data/scripts/lib/utilities.lua") +local function get_herd_id( entity_id ) + local genome = EntityGetFirstComponentIncludingDisabled(entity_id, "GenomeDataComponent") + local herd = ComponentGetValue2(genome, "herd_id") + return herd +end + +local function shoot_projectile( who_shot, entity_file, x, y, vel_x, vel_y, send_message ) + local entity_id = EntityLoad( entity_file, x, y ) + local herd_id = get_herd_id( who_shot ) + if( send_message == nil ) then send_message = true end + + GameShootProjectile( who_shot, x, y, x+vel_x, y+vel_y, entity_id, send_message ) + + edit_component( entity_id, "ProjectileComponent", function(comp,vars) + vars.mWhoShot = who_shot + vars.mShooterHerdId = herd_id + end) + + edit_component( entity_id, "VelocityComponent", function(comp,vars) + ComponentSetValueVector2( comp, "mVelocity", vel_x, vel_y ) + end) + + return entity_id +end + function wand_fired( wand_id ) local projectile_velocity = 600 local entity_id = GetUpdatedEntityID() local children = EntityGetAllChildren( entity_id ) local ghost_ids = {} - local root = EntityGetRootEntity(entity_id) - local shooter - if EntityHasTag(root, "ew_peer") and not EntityHasTag(root, "ew_notplayer") then - shooter = EntityGetWithTag("player_unit")[1] - if EntityHasTag(shooter, "ew_notplayer") then - shooter = root - end - else - shooter = root - end + local shooter = EntityGetRootEntity(entity_id) if ( children ~= nil ) then for i,v in ipairs( children ) do diff --git a/quant.ew/files/core/util.lua b/quant.ew/files/core/util.lua index a03b4092..217f7dca 100644 --- a/quant.ew/files/core/util.lua +++ b/quant.ew/files/core/util.lua @@ -183,6 +183,7 @@ end) -- Load an entity that doesn't get saved. function util.load_ephemerial(path, x, y) local entity = EntityCreateNew() + EntityAddTag(entity, "ew_synced_entity") EntitySetTransform(entity, x, y) local ent_2 = EntityLoad(path, x, y) EntityAddChild(entity, ent_2) diff --git a/quant.ew/files/system/enemy_sync.lua b/quant.ew/files/system/enemy_sync.lua index aeeceb26..f7ab4c22 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -339,6 +339,11 @@ function enemy_sync.client_cleanup() ctx.entity_by_remote_id[remote_id] = nil end end + for _, ent in ipairs(EntityGetWithTag("ew_synced_entity") or {}) do + if #(EntityGetAllChildren(ent) or {}) == 0 then + EntityKill(ent) + end + end end function enemy_sync.on_world_update_host() diff --git a/quant.ew/files/system/world_sync/world_sync.lua b/quant.ew/files/system/world_sync/world_sync.lua index d1273970..99e4f817 100644 --- a/quant.ew/files/system/world_sync/world_sync.lua +++ b/quant.ew/files/system/world_sync/world_sync.lua @@ -24,7 +24,7 @@ local iter_slow = 0 local iter_slow_2 = 0 -local function do_benchmark() +--[[local function do_benchmark() local world_ffi = require("noitapatcher.nsew.world_ffi") local grid_world = world_ffi.get_grid_world() local chunk_map = grid_world.vtable.get_chunk_map(grid_world) @@ -37,7 +37,7 @@ local function do_benchmark() local end_time = GameGetRealWorldTimeSinceStarted() local elapsed = (end_time - start) * 1000 * 1000 * 1000 / (iters * 128 * 128) print("Benchmark:", elapsed, "ns/pixel") -end +end]] function world_sync.on_world_initialized() local c = 0 diff --git a/quant.ew/init.lua b/quant.ew/init.lua index 81301442..880c3d50 100755 --- a/quant.ew/init.lua +++ b/quant.ew/init.lua @@ -130,10 +130,6 @@ local function load_extra_modules() end end -local function is_suitable_target(entity) - return EntityGetIsAlive(entity) and not EntityHasTag(entity,"ew_notplayer") -end - function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message, unknown1, multicast_index, unknown3) ctx.hook.on_projectile_fired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message, unknown1, multicast_index, unknown3)