require("helpers.gui_helpers") local config = config.civ ------------------------------------------------------------------------ -- Civ Class - container for all high level mod variables pertaining -- to the array of cities that make up the civilization. ------------------------------------------------------------------------ Civ = {} function Civ:init() self.state = { assist_mode = config.assist_mode, -- Turns daytime on and gives items to player on startup update_interval = config.update_interval, -- Time between city updates status_interval = config.status_interval, -- Time between status updates max_hh_per_city = config.max_hh_per_city, -- Max households per city entity (can build many cities) tiers = config.tiers, -- Array of status tiers and resultant status description needs = config.needs, -- Array of items needed to increase household count days = 0, -- Number of days that have passed in this game total_households = 0, -- Total number of households in your civ - sum of all households in all cities score = 0, -- Civilization score - used to determine status status_title = "Colony World", -- Status title from tiers array - based on score status_renown = "New Startup", -- Status renown from tiers array - based on score city_count = 0, -- Count of cities - corresponds to cities array exports = 0, -- Number of trade goods exported to the galaxy cities = {}, -- Array of instantiated city objects gui = {} } global.civ_state = self.state end function Civ:load() self.state = global.civ_state end function Civ:assist_player() game.surfaces[1].always_day=true for _, player in pairs(game.players) do player.print("CityPeeps - Daytime On") player.insert{name = "steel-axe",count = 10} player.insert{name = "power-armor-mk2",count = 1} player.insert{name = "fusion-reactor-equipment",count = 1} player.insert{name = "energy-shield-mk2-equipment",count = 2} player.insert{name = "battery-mk2-equipment",count = 4} player.insert{name = "personal-laser-defense-equipment",count = 2} player.insert{name = "exoskeleton-equipment",count = 2} player.insert{name = "personal-roboport-mk2-equipment",count = 1} player.insert{name = "firearm-magazine",count = 100} player.insert{name = "construction-robot",count = 25} if self.state.assist_mode then player.insert{name = "electric-furnace",count = 4} player.insert{name = "assembling-machine-2",count = 4} player.insert{name = "electric-mining-drill",count = 4} player.insert{name = "solar-panel",count = 4} player.insert{name = "accumulator",count = 2} player.insert{name = "pipe-to-ground",count = 5000} player.insert{name = "productivity-module-3",count = 5000} player.insert{name = "speed-module-3",count = 5000} player.insert{name = "iron-plate",count = 5000} player.insert{name = "steel-plate",count = 5000} player.insert{name = "copper-plate",count = 5000} player.insert{name = "stone",count = 5000} player.insert{name = "wood",count = 5000} player.insert{name = "k2cp-glass",count = 5000} player.insert{name = "k2cp-crate-meals",count = 5000} player.insert{name = "k2cp-crate-house",count = 5000} player.insert{name = "k2cp-crate-energy",count = 5000} player.insert{name = "k2cp-crate-medical",count = 5000} player.insert{name = "k2cp-crate-school",count = 5000} player.insert{name = "k2cp-crate-military",count = 5000} player.insert{name = "k2cp-crate-pleasure",count = 5000} player.insert{name = "k2cp-crate-const",count = 5000} player.insert{name = "k2cp-city",count = 2} player.print("CityPeeps - Extra Items Inserted") end end end function Civ:tick(event) if event.tick % self.state.update_interval == 0 then self.state.days = self.state.days + 1 local city_households = 0 for city_index = 1, self.state.city_count do local city = self.state.cities[city_index] city:update(self.state.needs) city_households = city_households + city.state.households end self.state.total_households = city_households if event.tick % self.state.status_interval == 0 then game.players[1].print("Status Interval Met") end for player_index, frame in pairs(self.state.gui) do self:update_gui(player_index) end end end function Civ:entity_built(event) local entity = event.created_entity if entity.name == "k2cp-city" then self.state.city_count = self.state.city_count + 1 new_city = City:new() new_city:init(self.state.city_count, entity) table.insert(self.state.cities, new_city) for player_index, frame in pairs(self.state.gui) do self:update_gui(player_index) end end end function Civ:entity_mined(entity) if entity.name == "k2cp-city" then for city_index = 1, self.state.city_count do local city = self.state.cities[city_index] if city.state.index == city_index then table.remove(self.state.cities, city_index) self.state.city_count = self.state.city_count - 1 self.state.total_households = self.state.total_households - city.state.households for player_index, frame in pairs(self.state.gui) do self:update_gui(player_index) end end end end end function Civ:show_gui(player_index) if self.state.gui[player_index] then return end GUI.push_left_section(player_index) self.state.gui[player_index] = GUI.push_parent(GUI.frame("civ", "City Peeps", GUI.VERTICAL)) GUI.label_data("title", "Status:", self.state.status_title) GUI.label_data("renown", "Renown:", self.state.status_renown) GUI.label_data("days", "Days:", self.state.days) GUI.label_data("cities", "Cities:", self.state.city_count) GUI.label_data("households", "Households:", self.state.total_households) GUI.label_data("exports", "Exports:", self.state.exports) end function Civ:update_gui(player_index) self.state.gui[player_index].title.data.caption = self.state.status_title self.state.gui[player_index].renown.data.caption = self.state.status_renown self.state.gui[player_index].days.data.caption = self.state.days self.state.gui[player_index].cities.data.caption = self.state.city_count self.state.gui[player_index].households.data.caption = self.state.total_households self.state.gui[player_index].exports.data.caption = self.state.exports end function Civ:hide_gui(player_index) if self.state.gui[player_index] == nil then return end self.state.gui[player_index].destroy() self.state.gui[player_index] = nil end