Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OnInitID()
- -- [[ Markers ]]
- -- [[ Squad Groups ]]
- -- [[ Entity Groups ]]
- territoryPointType = {
- strategic = 1,
- fuel = 2,
- munition = 3,
- victory = 4,
- }
- _territory_point_blueprints = {
- {blueprint = BP_GetEntityBlueprint("territory_point_mp"), type = territoryPointType.strategic},
- {blueprint = BP_GetEntityBlueprint("territory_fuel_point_mp"), type = territoryPointType.fuel},
- {blueprint = BP_GetEntityBlueprint("territory_munitions_point_mp"), type = territoryPointType.munition},
- {blueprint = BP_GetEntityBlueprint("victory_point"), type = territoryPointType.victory},
- }
- TerritoryPoints = {}
- _PopCapSystemConfig = {
- default_basepop = {
- [0] = 35,
- [1] = 40,
- },
- grant_per_point = {
- -- strategic
- [1] = {
- [0] = 6,
- [1] = 7,
- },
- -- fuel
- [2] = {
- [0] = 12,
- [1] = 16,
- },
- -- muni
- [3] = {
- [0] = 12,
- [1] = 16,
- },
- -- victory
- [4] = {
- [0] = 4,
- [1] = 5,
- },
- },
- }
- for i = 1, World_GetPlayerCount() do
- local player = World_GetPlayerAt(i)
- Player_SetPopCapOverride(player, _PopCapSystemConfig.default_basepop[Player_GetRace(player)])
- end
- for index = 0, World_GetNumEntities() -1 do
- local entity = World_GetEntity(index)
- if Entity_IsOfType(entity, "strategic_node") then
- local _blueprint = Entity_GetBlueprint(entity)
- local _type
- for key, item in ipairs(_territory_point_blueprints) do
- if _blueprint == item.blueprint then
- _type = item.type
- end
- end
- local _territory_point = {
- worldID = Entity_GetGameID(entity),
- blueprint = _blueprint,
- type = _type,
- owner = "world",
- granted = false,
- }
- table.insert(TerritoryPoints, _territory_point)
- end
- end
- Rule_Add(Monitor_TerritorySectors)
- end
- function Monitor_TerritorySectors()
- for key, point in ipairs(TerritoryPoints) do
- local entity = Entity_FromWorldID(point.worldID)
- local current_owner = Entity_GetPlayerOwnerSafe(entity)
- local previous_owner = point.owner
- -- Is owned by world
- if current_owner == "world" then
- if point.granted then
- --remove bonus
- if point.owner ~= "world" then
- GrantPopulationBonus(point.owner, point.type, "-")
- point.owner = "world"
- end
- point.granted = false
- end
- else
- -- IS owned by player
- if not World_IsInSupply(current_owner, Entity_GetPosition(entity)) then
- if point.granted then
- --remove bonus
- GrantPopulationBonus(point.owner, point.type, "-")
- point.owner = current_owner
- point.granted = false
- end
- else
- if not point.granted then
- point.owner = current_owner
- GrantPopulationBonus(point.owner, point.type, "+")
- --give bonus
- point.granted = true
- end
- end
- end
- end
- end
- function GrantPopulationBonus(player, _type, direction)
- local current_population = Player_GetMaxPopulation(player, CT_Personnel)
- local grant = _PopCapSystemConfig.grant_per_point[_type][Player_GetRace(player)]
- if direction == "-" then
- -- turn it negative
- grant = 0 - grant
- end
- for i = 1, World_GetPlayerCount() do
- local _player = World_GetPlayerAt(i)
- if Player_GetTeam(_player) == Player_GetTeam(player) then
- Player_SetPopCapOverride(_player, current_population + grant)
- end
- end
- end
- function Entity_GetPlayerOwnerSafe(entity)
- if World_OwnsEntity(entity) then
- return "world"
- else
- return Entity_GetPlayerOwner(entity)
- end
- end
- function Player_GetIDSafe(player)
- if not player or player == "world" then
- return "world"
- else
- return Player_GetID(player)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement