Suggestion: Stalkers should gain points in their rank in offline combat

Issue #133 new
xQd
created an issue

This makes a lot of sense in my opinion. I mean, why do they gain rank when they kill stuff in online mode and they do not get any experience when they fight in offline?

I have already implemented this in my warfare files. So if you like my suggestion follow these instructions in order to have this implemented in your game as well:

Open up your combat_group.script file. Scroll down to the combat_group:simulate(squad) method.

Add this following code:

    if attacker and attacker.set_rank then
        --printf("increased %s's rank", attacker and attacker.character_name and attacker:character_name() or ".")
        attacker:set_rank(attacker:rank() + math.ceil(damage/1000)) -- increase attackers rank depending on their damage
    end
    local commander = sim:object(squad:commander_id())
    if commander and commander.set_rank then
        --printf("increased commander %s's rank", commander and commander.character_name and commander:character_name() or ".")
        commander:set_rank(commander:rank() + math.random(1,4)) -- increase rank of commander for each attack
    end

between the following lines:

        ...        

    local attacker = k1.object or k1.id and sim:object(k1.id)
    local victim = k2.object or k2.id and sim:object(k2.id)
    local damage = squad_power * (0.4 + math.random() * 0.2)
    local new_power = math.max(0, squad2_power - damage)
    local diff = squad2_power - new_power
    local kp = victim:rank()
    local mul = 1 / math.random(2, 3)

and

offline_combat_simulator.ocs_power_table[s2id] = new_power

The modified function should look like this after your modifications(copy and paste this over the unmodified function basically):

function combat_group:simulate(squad)
    printd(0)

    if not (self:is_valid()) then
        self:disband()
        return
    end

    local sim = alife()

    -- get the squads pwoer
    local squad_power = offline_combat_simulator.ocs_power_table[squad.id]

    -- if squads power is zero or less, remove it and return.
    if not (squad_power and squad_power > 0) or (squad:npc_count() == 0) then
        self:unregister(squad)
        printd(1)
        return
    end

    -- get the squads opponent id
    local s2id = squad.assigned_target_id

    -- check to see if the opponent squad is still in the combat group
    if not (self.squads[s2id]) then
        -- find a new opponent
        local new = self:find_enemy(squad)

        -- If new opponent found, set it as the new target for the squad. otherwise, unregister squad and return.
        if (new) then
            squad.assigned_target_id = new
            s2id = new

            --printf("--- " .. squad:name() .. " new target: " .. s2id .. " ---")
        else
            --printf("--- no enemies found for " .. squad:name() .. " - removing squad ---")
            self:unregister(squad)
            printd(2)
            return
        end
    end

    local squad2 = sim:object(s2id)

    if not (squad2) then
        printd(3)
        return
    end

    if squad.online or squad2.online then
        --printf("--- disbanding combat group (squad is online) ---")   
        self:disband()
        printd(4)
        return
    end

    local squad2_power = offline_combat_simulator.ocs_power_table[s2id]

    if not (squad2_power and squad2_power > 0) or (squad2:npc_count() == 0) then
        self:unregister(squad2)
        printd(5)
        return
    end

    local squad1mult = warfare_options.options.factions[squad:get_squad_community()].offline_power_multiplier or 1
    local squad2mult = warfare_options.options.factions[squad2:get_squad_community()].offline_power_multiplier or 1

    squad_power = squad_power * squad1mult
    squad2_power = squad2_power * squad2mult

    local totalCasualties = 0

    local squad_npcs = {}
    for k in squad:squad_members() do
        squad_npcs[#squad_npcs+1] = k
    end

    local squad2_npcs = {}
    for k in squad2:squad_members() do
        squad2_npcs[#squad2_npcs+1] = k
    end

    local k1 = squad_npcs[math.random(#squad_npcs)]
    local k2 = squad2_npcs[math.random(#squad2_npcs)]

    --printf("squad1 count: " .. squad:npc_count())
    --printf("squad2 count: " .. squad2:npc_count())

    local attacker = k1.object or k1.id and sim:object(k1.id)
    local victim = k2.object or k2.id and sim:object(k2.id)
    local damage = squad_power * (0.4 + math.random() * 0.2)
    local new_power = math.max(0, squad2_power - damage)
    local diff = squad2_power - new_power
    local kp = victim:rank()
    local mul = 1 / math.random(2, 3)

        -- MODIFICATION START
    if attacker and attacker.set_rank then
        --printf("increased %s's rank", attacker and attacker.character_name and attacker:character_name() or ".")
        attacker:set_rank(attacker:rank() + math.ceil(damage/1000)) -- increase attackers rank depending on their damage
    end
    local commander = sim:object(squad:commander_id())
    if commander and commander.set_rank then
        --printf("increased commander %s's rank", commander and commander.character_name and commander:character_name() or ".")
        commander:set_rank(commander:rank() + math.random(1,4)) -- increase rank of commander for each attack
    end
        -- MODIFICATION END

    --printf("power (victim): %s, power (attacker): %s, damage: %s, new: %s", squad2_power, squad_power, damage, new_power)

    offline_combat_simulator.ocs_power_table[s2id] = new_power

    if new_power <= 0 then      
        --printf("!!! %s killed %s !!!", squad:name(), squad2:name())

        for i,npc in pairs(squad2_npcs) do
            squad2:remove_npc(npc)
            squad_npc_killed_offline_combat(squad:get_squad_community(), squad2:get_squad_community())
        end

        sim_squad_warfare.remove_squad(squad2)
        self:unregister(squad2)     
    else
        if kp * mul <= diff then        
            squad2:remove_npc(k2.id)

            squad_npc_killed_offline_combat(squad:get_squad_community(), squad2:get_squad_community())

            if squad2:npc_count() <= 1 then
                sim_squad_warfare.remove_squad(squad2)
            end

            --printf("!!! %s NPC killed %s NPC !!!", squad:name(), squad2:name())
        end
    end

    printd(6)
end

The attacker will gain rank based on this formula: the damage they done in offline divided by 1000. The commander of the squad will also receive a small bonus for each attack done by one of their squadmates, a random number between 1 and 4.

Comments (2)

  1. Log in to comment