Advertisement
Janne252

How to: Classic population cap system part #2

Feb 2nd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. function Monitor_TerritorySectors()
  2.     for key, point in ipairs(TerritoryPoints) do
  3.         local entity = Entity_FromWorldID(point.worldID)
  4.         local current_owner = Entity_GetPlayerOwnerSafe(entity)
  5.         local previous_owner = point.owner
  6.        
  7.         -- Is owned by world
  8.         if current_owner == "world" then
  9.             if point.granted then
  10.                 --remove bonus
  11.                 if point.owner ~= "world" then
  12.                     GrantPopulationBonus(point.owner, point.type, "-")
  13.                     point.owner = "world"
  14.                 end
  15.                 point.granted = false
  16.             end
  17.         else
  18.             -- IS owned by player
  19.             if not World_IsInSupply(current_owner, Entity_GetPosition(entity)) then
  20.                 if point.granted then
  21.                     --remove bonus         
  22.                     GrantPopulationBonus(point.owner, point.type, "-")
  23.                     point.owner = current_owner
  24.                     point.granted = false
  25.                 end
  26.             else
  27.                 if not point.granted then
  28.                     point.owner = current_owner
  29.                     GrantPopulationBonus(point.owner, point.type, "+")
  30.                     --give bonus
  31.                     point.granted = true
  32.                 end
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. function GrantPopulationBonus(player, _type, direction)
  39.     local current_population = Player_GetMaxPopulation(player, CT_Personnel)
  40.     local grant = _PopCapSystemConfig.grant_per_point[_type][Player_GetRace(player)]
  41.    
  42.     if direction == "-" then
  43.         -- turn it negative
  44.         grant = 0 - grant
  45.     end
  46.    
  47.     for i = 1, World_GetPlayerCount() do
  48.         local _player = World_GetPlayerAt(i)   
  49.         if Player_GetTeam(_player) == Player_GetTeam(player) then
  50.             Player_SetPopCapOverride(_player, current_population + grant)
  51.         end
  52.     end
  53. end
  54.  
  55. function Entity_GetPlayerOwnerSafe(entity)
  56.     if World_OwnsEntity(entity) then
  57.         return "world"
  58.     else
  59.         return Entity_GetPlayerOwner(entity)
  60.     end
  61. end
  62.  
  63. function Player_GetIDSafe(player)
  64.     if not player or player == "world" then
  65.         return "world"
  66.     else
  67.         return Player_GetID(player)
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement