Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add kill count sensor.
Browse files Browse the repository at this point in the history
Closes #29
  • Loading branch information
narc0tiq committed Sep 30, 2015
1 parent 0de6ed4 commit 9ec9a2a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions evoGUI.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "defines"
require "value_sensors.day_time"
require "value_sensors.evolution_factor"
require "value_sensors.kill_count"
require "value_sensors.play_time"
require "value_sensors.player_locations"
require "value_sensors.pollution_around_player"
Expand Down
10 changes: 10 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ sensor.player_locations.settings.show_direction=Show direction to walk to reach
sensor.pollution_around_player.name=Nearby pollution level
sensor.pollution_around_player.format=Pollution: __1__ PU.

sensor.kill_count.name=Kill count (for your team)
sensor.kill_count.format=Kills: __1__, __2__, __3__.
sensor.kill_count.biter_fragment_single=1 biter
sensor.kill_count.biter_fragment_multiple=__1__ biters
sensor.kill_count.spawner_fragment_single=1 spawner
sensor.kill_count.spawner_fragment_multiple=__1__ spawners
sensor.kill_count.other_fragment_single=1 other
sensor.kill_count.other_fragment_multiple=__1__ others


settings_title=EvoGUI settings

settings.core_settings.title=Core settings (shared)
Expand Down
87 changes: 87 additions & 0 deletions value_sensors/kill_count.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require "template"

-- Preload known vanilla types
local entity_types = {
["unit"] = {
["small-biter"] = true,
["medium-biter"] = true,
["big-biter"] = true,
["behemoth-biter"] = true,
["small-spitter"] = true,
["medium-spitter"] = true,
["big-spitter"] = true,
["behemoth-spitter"] = true,
},
["unit-spawner"] = {
["biter-spawner"] = true,
["spitter-spawner"] = true,
},
}

local function is_entity_type(what_type, entity_name)
if not entity_types[what_type] then entity_types[what_type] = {} end
local type_cache = entity_types[what_type]

if type_cache[entity_name] ~= nil then
return type_cache[entity_name]
end

local prototype = game.entity_prototypes[entity_name]
if prototype and prototype.type == what_type then
type_cache[entity_name] = true
else
type_cache[entity_name] = false
end

return type_cache[entity_name]
end


local function is_biter(entity_name)
return is_entity_type("unit", entity_name)
end


local function is_spawner(entity_name)
return is_entity_type("unit-spawner", entity_name)
end


local sensor = ValueSensor.new("kill_count")

function sensor:update_ui(owner)
local player = game.get_player(owner.player_index)

local biter_count = 0
local spawner_count = 0
local other_count = 0
for entity_name, kill_count in pairs(player.force.kill_counts) do
if is_biter(entity_name) then
biter_count = biter_count + kill_count
elseif is_spawner(entity_name) then
spawner_count = spawner_count + kill_count
else
other_count = other_count + kill_count
end
end

local biter_kills = {"sensor.kill_count.biter_fragment_single"}
if biter_count ~= 1 then
biter_kills = {"sensor.kill_count.biter_fragment_multiple", biter_count}
end

local spawner_kills = {"sensor.kill_count.spawner_fragment_single"}
if spawner_count ~= 1 then
spawner_kills = {"sensor.kill_count.spawner_fragment_multiple", spawner_count}
end

local other_kills = {"sensor.kill_count.other_fragment_single"}
if other_count ~= 1 then
other_kills = {"sensor.kill_count.other_fragment_multiple", other_count}
end

owner[self.name].caption = {self.format_key, biter_kills, spawner_kills, other_kills}
end

ValueSensor.register(sensor)

0 comments on commit 9ec9a2a

Please sign in to comment.