The3vilM0nk3y

ColonyInfo

Sep 15th, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.74 KB | None | 0 0
  1. function clearScreen()
  2.   term.clear()
  3.   term.setCursorPos(1,1)
  4. end
  5.  
  6. function scanChild(res)
  7.     if res ~= nil then
  8.         if res.children ~= nil then
  9.             for key,val in pairs(res.children) do
  10.                 if val.status == "IN_PROGRESS" then
  11.                     rtext = rtext .. (val.name) .. "\n"
  12.                     researchCount = researchCount + 1
  13.                 end
  14.                 scanChild(val)
  15.             end
  16.         end
  17.     end
  18. end
  19. function inBed(cit,bed)
  20.     d = distance(cit,bed)
  21.     if d == "P" or d == "T" then
  22.         return false, d
  23.     elseif d <=3 then
  24.         return true, d
  25.     else
  26.         return false, d
  27.     end
  28. end
  29. function showColonyInfo(showResourceInfo)
  30.   citizens = colony.getCitizens()
  31.   buildings = colony.getBuildings()
  32.     text = "^d\n"..colony.getColonyName() .. " Info  ID: " .. colony.getColonyID().. "\n^d\n" ..
  33.     "Population: ".. #citizens .. " / ".. colony.maxOfCitizens() .." Happiness:" ..  round(colony.getHappiness(),2) .. "/10\n"
  34.     --if (info.mourning)  then
  35.     --  text = text .. " In Mourning\n"
  36.         --ardata.mourning = false
  37.     --else
  38.     --  text = text .. "\n"
  39.     --end
  40.  
  41.     if colony.isUnderAttack() then
  42.       text = text .. "RAID IN PROGRESS\n"
  43.         ardata.raid = true
  44.     end
  45.  
  46.     idleCount = 0
  47.     childCount = 0
  48.     adultCount = #citizens
  49.     housingMax = 0
  50.     guardHousingMax = 0
  51.     guardHousingUsed = 0
  52.     guardCount = 0
  53.     maxResearch = 0
  54.     builderCount = 0
  55.   studentCount = 0
  56.     sleeping = 0
  57.     sleepingMax = 0
  58.     guardJobs = {"guardtower", "barrackstower", "combatacademy", "archery"}
  59.     ardata.health = {}
  60.     ardata.sleep = {}
  61.     jobList = {}
  62.     for _,citizen in pairs(citizens) do
  63.     --get adult and child count
  64.         if citizen.age == "child" then
  65.             childCount = childCount + 1
  66.             adultCount = adultCount - 1
  67.       --Get jobless
  68.         elseif citizen.work == nil then
  69.             idleCount = idleCount + 1
  70.       --get guard counts
  71.         elseif hasValue(guardJobs, citizen.work.type) then
  72.             guardHousingUsed = guardHousingUsed + 1
  73.             guardCount = guardCount + 1
  74.       --get Builder counts
  75.         elseif citizen.work.type == "builder" then
  76.             builderCount = builderCount + 1
  77.     elseif citizen.work.type == "library" then
  78.       studentCount = studentCount + 1
  79.         end
  80.     if citizen.work ~= nil then
  81.       --Get a list of jobs
  82.       if citizen.work.type ~= nil then
  83.         if jobList[citizen.work.type] ~= nil then
  84.                 jobList[citizen.work.type] = jobList[citizen.work.type] + 1
  85.             else
  86.                 jobList[citizen.work.type] = 1
  87.             end
  88.       end
  89.       --This \/ may be erroneous.. only accounts for sleeping that have a job.
  90.       --Get sleep count
  91.         if citizen.work.type ~= "guardtower" and citizen.work.type ~= "barrackstower" then
  92.             --debugText(citizen.status)
  93.             asleep,d = inBed(citizen.location,citizen.bedPos)
  94.             if citizen.isAsleep then
  95.                 sleeping = sleeping + 1
  96.         --add directional marker to those that are not sleeping after 11oclock
  97.             elseif (os.time() > 21 or os.time() < 6) then
  98.                 if d == "P" or d == "T" or d > 3 then
  99.                     table.insert(ardata.sleep,{name = citizen.name, distance = d, location = citizen.location})
  100.                 end
  101.             end
  102.             sleepingMax = sleepingMax + 1
  103.         end
  104.     end
  105.     --get damaged citizens
  106.     if citizen.health then
  107.             if citizen.health < citizen.maxHealth then
  108.                 table.insert(ardata.health,{name = citizen.name, health = citizen.health, maxHealth = citizen.maxHealth, location = citizen.location})
  109.             end
  110.     end
  111.     end
  112.     --Building Data
  113.     guardHouseLocations = {"barrackstower","combatacademy","archery"}
  114.     for _,v in pairs(buildings) do
  115.         if v.type == "citizen" then
  116.             housingMax = housingMax + v.level
  117.         elseif v.type == "tavern" then
  118.             housingMax = housingMax + 4
  119.         elseif hasValue(guardHouseLocations, v.type) then
  120.             guardHousingMax = guardHousingMax + v.level
  121.         elseif v.type == "guardtower" then
  122.             guardHousingMax = guardHousingMax + 1
  123.         elseif v.type == "university" then
  124.             maxResearch = maxResearch + v.level
  125.         end
  126.     end
  127.     ardata.idle = idleCount
  128.     ardata.popCount = #citizens
  129.     ardata.totalHousing = housingMax + guardHousingMax
  130.     ardata.children = childCount
  131.     ardata.builderCount = builderCount
  132.   ardata.studentCount = studentCount
  133.     ardata.sleeping = sleeping
  134.     ardata.sleepingMax = sleepingMax
  135.     text = text ..  "Idle Citizens: " .. idleCount .. " Students: ".. studentCount ..
  136.           "\nHousing: " .. #citizens-guardHousingUsed .. "/" .. housingMax ..
  137.           "\nGuards: " .. guardHousingUsed .. "/" .. guardHousingMax ..
  138.                     "\nAdults: ".. adultCount .. " Children: " .. childCount
  139.   --Building Queues
  140.     qText = ""
  141.     ardata.buildQueue = {}
  142.     ardata.buildCount = 0
  143.     ardata.totalQueueCount = 0
  144.     ardata.activeBuildCount = 0
  145.     queue = colony.getWorkOrders()
  146.  
  147.  
  148.     for k,v in pairs(buildings) do
  149.         --debugText(v.type)
  150.         if v.isWorkingOn then
  151.             ardata.buildCount = ardata.buildCount + 1
  152.             qText = qText .. v.type .. v.level .. " to lvl " .. (v.level + 1) .. "\n"
  153.             --if v.isClaimed == false then
  154.                 --text = text .. " (Queued)\n"
  155.                 --table.insert(ardata.buildQueue, {name = "building", toLevel = 0, queued = true})
  156.                 ardata.totalQueueCount = ardata.totalQueueCount + 1
  157.             --else
  158.                 table.insert(ardata.buildQueue, {name = v.type, toLevel = (v.level + 1), queued = false})
  159.                 --ardata.activeBuildCount = ardata.activeBuildCount + 1
  160.             --end
  161.         end
  162.         --if v.type == "WorkOrderDecoration" then
  163.             --text = text .. "Decoration"
  164.             --if v.claimedByBuilding == nil then
  165.                 --text = text .. " (Queued)\n"
  166.                 --table.insert(ardata.buildQueue, {name = "Decoration", toLevel = "N/A", queued = true})
  167.                 --ardata.totalQueueCount = ardata.totalQueueCount + 1
  168.             --else
  169.                 --text = text .. "\n"
  170.                 --table.insert(ardata.buildQueue, {name = "Decoration", toLevel = "N/A", queued = false})
  171.                 --ardata.activeBuildCount = ardata.activeBuildCount + 1
  172.             --end
  173.         --end
  174.     end
  175.   for k,v in pairs(queue) do
  176.     if v.isClaimed then
  177.       ardata.activeBuildCount = ardata.activeBuildCount + 1
  178.     end
  179.   end
  180.   qText = "^d\nConstructing: " .. ardata.activeBuildCount .. " / " .. ardata.builderCount .. "\n^d\n" .. qText .. "Total Queued - " .. ardata.buildCount
  181. --Resource Info
  182.     if showBuilderResourceInfo then
  183.         missingResources = {}
  184.         for i=1, #buildings do
  185.             if buildings[i].type == "builder" then
  186.                 buildResources = colony.getBuilderResources(buildings[i].location)
  187.  
  188.                 for j = 1, #buildResources do
  189.                     resource = buildResources[j].item
  190.                     if missingResources[resource.displayName] ~= nil then
  191.                         missingResources[resource.displayName].needed = missingResources[resource.displayName].needed + resource.count
  192.                         missingResources[resource.displayName].onHand = missingResources[resource.displayName].onHand + buildResources[j].available
  193.                         missingResources[resource.displayName].inRoute = missingResources[resource.displayName].inRoute + buildResources[j].delivering
  194.                     else
  195.                         missingResources[resource.displayName] = {}
  196.                         missingResources[resource.displayName].needed = resource.count
  197.                         missingResources[resource.displayName].onHand = buildResources[j].available
  198.                         missingResources[resource.displayName].inRoute = buildResources[j].delivering
  199.                     end
  200.                 end
  201.             end
  202.         end
  203.         mtext = "Needed Resources:\n"
  204.         for k,v in pairs(missingResources) do
  205.             if v.needed - v.onHand - v.inRoute > 0 then
  206.                 mtext = mtext .. k .." : " .. v.needed - (v.onHand + v.inRoute) .. "\n"
  207.             end
  208.         end
  209.     end
  210. --Research
  211.     research = colony.getResearch()
  212.     rtext = ""
  213.     researchCount = 0
  214.     for _, y in pairs(research) do
  215.         for _,v in pairs(y) do
  216.             if v.status == "IN_PROGRESS" then
  217.                 researchCount = researchCount + 1
  218.                 rtext = rtext .. v.name .. "\n"
  219.             end
  220.             scanChild(v)
  221.         end
  222.     end
  223.     rtext = "^d\nResearching: " .. researchCount .. " / " .. maxResearch .. "\n^d\n" .. rtext
  224.     ardata.research = {}
  225.     ardata.research.max = maxResearch
  226.     ardata.research.currentAmount = researchCount
  227.     return text, jobList, qText, rtext
  228. end
  229.  
  230. return { showColonyInfo = showColonyInfo }
  231.  
Advertisement
Add Comment
Please, Sign In to add comment