Skip to content

Commit

Permalink
optimizations and rando changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Mar 4, 2021
1 parent e04556e commit 8982c59
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/door_randomizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ meta.description = "Random exit doors and boss order. Beat all the bosses and be
meta.author = "Dregu"

register_option_int("min_levels", "Min normal levels before boss", 3, 1, 100)
register_option_int("max_levels", "Max normal levels before boss", 8, 1, 100)
register_option_int("max_levels", "Max normal levels before boss", 6, 1, 100)
register_option_int("bosses", "Bosses to defeat to trigger ending", 5, 1, 5)
register_option_bool("xiit", "Spawn exit on entrance (for debugging)", false)

Expand Down
29 changes: 29 additions & 0 deletions examples/enemy_randomizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ big_to = {ENT_TYPE.MONS_CAVEMAN_BOSS, ENT_TYPE.MONS_LAVAMANDER, ENT_TYPE.MONS_MU
olmec_ammo = {ENT_TYPE.ACTIVEFLOOR_PUSHBLOCK, ENT_TYPE.ITEM_CHEST, ENT_TYPE.ITEM_POT, ENT_TYPE.ITEM_BOMB,
ENT_TYPE.ITEM_PASTEBOMB, ENT_TYPE.ITEM_EGGPLANT, ENT_TYPE.ITEM_TV, ENT_TYPE.ITEM_PUNISHBALL,
ENT_TYPE.ITEM_LANDMINE, ENT_TYPE.ITEM_SCRAP, ENT_TYPE.MONS_MAGMAMAN, ENT_TYPE.ACTIVEFLOOR_POWDERKEG}
kingu_ammo = {ENT_TYPE.MONS_JIANGSHI, ENT_TYPE.MONS_FEMALE_JIANGSHI, ENT_TYPE.MONS_OCTOPUS,
ENT_TYPE.ACTIVEFLOOR_POWDERKEG, ENT_TYPE.MONS_YETI, ENT_TYPE.MONS_VAMPIRE, ENT_TYPE.MONS_LEPRECHAUN,
ENT_TYPE.MONS_BEE, ENT_TYPE.MONS_OLMITE_BODYARMORED, ENT_TYPE.MONS_MONKEY, ENT_TYPE.MONS_PROTOSHOPKEEPER}
done = {}

function replaced(id)
Expand Down Expand Up @@ -97,6 +100,20 @@ function replace_projectile(id, from)
done[#done + 1] = newid
end

function replace_kingu(id, from)
x, y, l = get_position(id)
ent = get_entity(id):as_movable()
vx = ent.velocityx
vy = ent.velocityy
-- move_entity(id, 0, 0, 0, 0)
new = from[math.random(#from)]
newid = spawn(new, x + math.random() * 4 - 2, y, l, vx, vy)
newent = get_entity(newid):as_movable()
newent.velocityx = math.random() * 0.2 - 0.1
newent.velocityy = math.random() * 0.25
done[#done + 1] = newid
end

set_callback(function()
done = {}
set_timeout(function()
Expand Down Expand Up @@ -145,6 +162,18 @@ set_callback(function()
end, 1)
end

if state.theme == THEME.ABZU then
set_interval(function()
ufos = get_entities_by_type(ENT_TYPE.MONS_JIANGSHI, ENT_TYPE.MONS_FEMALE_JIANGSHI, ENT_TYPE.MONS_OCTOPUS)
for i, v in ipairs(ufos) do
if not replaced(v) then
replace_kingu(v, kingu_ammo)
end
done[#done + 1] = v
end
end, 1)
end

set_interval(function()
ufos = get_entities_by_type(ENT_TYPE.MONS_REDSKELETON)
for i, v in ipairs(ufos) do
Expand Down
2 changes: 1 addition & 1 deletion examples/trap_randomizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ meta.version = "WIP"
meta.description = "Add more traps, change default wall traps and put snap traps in unexpected places."
meta.author = "Dregu"

register_option_float("add_traps", "% of traps to add", 5, 0, 20)
register_option_float("add_traps", "% of traps to add", 4, 0, 20)

floor_to = {ENT_TYPE.FLOOR_JUNGLE_SPEAR_TRAP, ENT_TYPE.FLOOR_SPARK_TRAP, ENT_TYPE.FLOOR_TIMED_FORCEFIELD,
ENT_TYPE.ACTIVEFLOOR_CRUSH_TRAP, ENT_TYPE.ACTIVEFLOOR_ELEVATOR}
Expand Down
10 changes: 8 additions & 2 deletions src/game_api/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ using EntityMap = std::unordered_map<std::string, uint16_t>;

class Entity;

size_t cache_entities_ptr = 0;

size_t entities_offset()
{
ONCE(size_t)
Expand All @@ -22,8 +24,12 @@ size_t entities_offset()

size_t entities_ptr()
{
auto mem = Memory::get();
return mem.at_exe(decode_pc(mem.exe(), find_inst(mem.exe(), "\x48\xB8\x02\x55\xA7\x74\x52\x9D\x51\x43"s, mem.after_bundle) - 7));
if (cache_entities_ptr == 0)
{
auto mem = Memory::get();
cache_entities_ptr = mem.at_exe(decode_pc(mem.exe(), find_inst(mem.exe(), "\x48\xB8\x02\x55\xA7\x74\x52\x9D\x51\x43"s, mem.after_bundle) - 7));
}
return cache_entities_ptr;
}

std::vector<EntityItem> list_entities()
Expand Down

0 comments on commit 8982c59

Please sign in to comment.