Non Wave Defense

by Lunzir

This mod is derived from the official WaveDefense scenario mode. Get funding to upgrade technology by killing biters. 这是从官方场景模式“异星格勒保卫战”提取出来的功能,通过击杀虫子获得资金升级科技。如果你玩过那个模式,你就知道这个mod是干啥用的。在原基础上添加了一些可升级的科技。可以与当前科技叠加效果

4 years ago
0.17
12

b Techs don't apply on loading a save, bullet speed is unaffected, and stack inserters are broken

4 years ago

I noticed when I loaded a save my upgrades didn't apply. Easy to see on turret damage upgrades.

I added "lib.on_configuration_changed()" to refresh_player_gui_event and it seems to work.

In default_tech_data, there's no bullet speed entry under shooting speed. I added:

    {
        type = "gun-speed",
        cat = "bullet",
        mod = game.forces.player.get_gun_speed_modifier("bullet")
    },

And it works for UPGRADES, but it doesn't apply the current level, only the +10% from the upgrade. I think this is because it had no value before, so it only gets 10% for every new upgrade one gets. The bullet speed is already in non_wave_defense_upgrades, it just has no information in the default tech data, so never applies (again, one can look at turrets or the SMG to see there's no effect from the current level).

I need to get enough money to play around with the inserter upgrade in my current game, but it conflicts with technology upgrades. It keeps getting reset to 4 for stack inserters, and not to the current modifier. I've had inserters in my game world with different grab sizes because some I placed before upgrades and some after.

4 years ago

Nevermind, it doesn't load again on save? what the hell. I think the bonuses get reset to 0 somewhere.

4 years ago

I was able to make a command and function which recalculates bonuses, because the shooting speed for bullets wasn't updated. I can share it if you want. Technically I need to fix it a little bit, because it could conflict with other mods.

4 years ago

Please post your fixes here.
I'm struggling with that issue, too, and it would be nice to not need to dive in completely into factorio-modding just to fix this bug ;)

4 years ago
(updated 4 years ago)

I fixed it by reapplying all updates in the player-joined event:

lib.events = 
 ...
  [defines.events.on_player_joined_game] = player_join_meta_event,
 ...

local player_join_meta_event = function(event, player_index)
    -- reapply upgrades
    -- the names are weird around?
    local conversion_table = {
          ["physical-projectile-damage"] = "physical_projectile_damage",
          ["weapon-shooting-speed"] = "weapon_shooting_speed",
          ["stronger-explosives"] = "stronger_explosives",
          ["refined-flammables"] = "refined_flammables",
          ["energy-weapons-damage"] = "energy_weapons_damage",
          ["laser-turret-speed"] = "laser_turret_shooting_speed",
          ["follower-robot-count"] = "following_robot_count",
          ["artillery-shell-range"] = "artillery_shell_range",
          ["artillery-shell-speed"] = "artillery_shell_speed",
          ["mining-productivity"] = "mining_productivity",
          ["inserter-capacity-bonus"] = "inserter_stack_size",
          ["braking-force"] = "braking_force",
          ["worker-robots-speed"] = "worker_robot_speed",
          ["worker-robots-storage"] = "worker_robot_storage",
          ["research-speed"] = "research_speed",
          ["bounty_bonus"] = "bounty_bonus",
    }
    local list = get_upgrades()
    for name, upgrade_level in pairs (script_data.team_upgrades) do
        log(string.format("Increasing %s %d times...", name, upgrade_level))
            for i=1,upgrade_level do
                for k, effect in pairs (list[conversion_table[name]].effect) do
                  effect(event)
                end
            end
    end

    refresh_player_gui_event(event)
end

additionally, I needed to change global.non_wave_defense to global_wave_defense in the non_wave_defense_upgrades.lua:397. Idk why :/

Thanks for the gun-speed, I did not notice that before :)
Same with inserters, I did not check them yet to where they are broken, but I'll take fixes if you do ;)

4 years ago
(updated 4 years ago)

HAHA OH MY GOD:
<code>
local upgrade_list = {
["physical-projectile-damage"] = "physical_projectile_damage",
["weapon-shooting-speed"] = "weapon_shooting_speed",
["energy_weapons_damage"] = "energy_weapons_damage",
["laser-turret-speed"] = "laser_turret_shooting_speed",
["stronger-explosives"] = "stronger_explosives",
["refined-flammables"] = "refined_flammables",
["follower-robot-count"] = "following_robot_count",
["mining-productivity"] = "mining_productivity",
["artillery-shell-range"] = "artillery_shell_range",
["artillery-shell-speed"] = "artillery_shell_speed",
["inserter-capacity-bonus"] = "inserter_stack_size",
["worker-robots-speed"] = "worker_robot_speed",
["worker-robots-storage"] = "worker_robot_storage",
["research-speed"] = "research_speed",
}

function reset_upgrades()
-- this does not respect any bonuses that came from game events i.e. only research bonuses are applied
--log("Resetting technology bonuses")
game.print("Resetting technology bonuses")
--log(serpent.block(game.forces["player"].technologies))
game.player.force.reset_technology_effects()
local i = 0

--log(serpent.block(script_data))
for datakey, scriptkey in pairs(upgrade_list) do
--log("datakey = "..datakey.." scriptkey = "..scriptkey)
if script_data.team_upgrades[scriptkey] ~= nil then
i = script_data.team_upgrades[scriptkey]
while (i > 0) do
log("doing effect for "..scriptkey)
for _, effect in pairs(upgrades[scriptkey].effect) do
effect({player_index = game.player.index})
end
i = i - 1
end
else
log("reset_upgrades - "..datakey.." did not have a match in script_data")
end
end
end
</code>
https://drive.google.com/open?id=115JPFkNHAOE4TbQIwkd9Ox3lgfHHIuUl

There may be other things. I've been modifying this mod a little bit, and another one a lot more, and I got mixed up.

Under debug I added a /check command, so it prints out the current bonuses. Just woke up and need to remember what the hell I've done.

4 years ago

how do I tag it properly

4 years ago

A point to make, if you're playing single player, certain events like on_joined don't fire. It's a pain. There is literally nowhere in the game to run functions that affect the game table when a save is loaded in single player. on_load can only modify global.

4 years ago

was inactive, sadly my snippet doesn't really work.
On join does not fire in singleplayer and fires for every player joining, leading to multiplying bonusses.

In the end I made a button applying all bonusses, which I can press once after loading the game.
Hopefully, all those workarounds won't be necessary and this will get fixed someday :)

4 years ago

Yeah, I normally only play single player... everything's working fine except I think except the stack inserter bonuses, I haven't tried lately. Happy New Year, friend

4 years ago

Honktown, I tried your version of the mod, and the laser shooting speed does not persist.. Wish the author would fix the mod..

4 years ago
(updated 4 years ago)

I had some issues with mining productivity in the beginning. Not on laser turrets yet in my current game.

I'll re-upload my current version: there's an issue with resetting technology bonuses that unlocks technology and unhides it, which breaks warptorio2 expansion (what I'm playing atm).

https://drive.google.com/open?id=1AnHiSiRwpLVvMnFoKo-ZA5_7xk0KItAj

If you do the command /reset_upgrades it will reset bonuses from technology, and then re-apply non-wave-defense bonuses. If you have other mods or are running a scenario it would probably conflict. I'm sure the fix is just finding what the broken load is but I don't know and reset_upgrades works in my case. I added reset_upgrades. It will print in the log all the upgrade effects it applies.

Edit: I do have a patch for not breaking warptorio2 expansion. Another thing is I don't know if stack inserters are still messed up. I went looking but I'm not sure.

4 years ago

Thanks :) I'm not playing Warptorio so thats all good, will test out as soon as I can :)

4 years ago

Is there a command to completely reset points and bonuses, I forgot to turn down the kill multiplier after a test game, and had suddenly amassed millions of bonus points in my regular game lol

4 years ago

There is. In control.lua it's commented out: resetnwd . After enabling that command, you run it, then do a /reset_upgrades, otherwise the bonuses would still be in effect I think

4 years ago
(updated 4 years ago)

Wow that was a fast respond :), gonna try it out right now. Kinda made it work, ran the command and nothing happened, so loaded the game without the mod loaded, saved it, reloaded with mod, ran commands and kinda made it work.

New response