1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: debug.lua
-- brief: printing routines to debug Spring call-out results
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function PrintInCommand()
local cmdIndex, cmdId, cmdType, name = Spring.GetActiveCommand()
print("InCommand: ", cmdIndex, cmdId, cmdType, name)
end
function PrintBuildQueue(unitID)
local queue, count = Spring.GetRealBuildQueue(unitID)
print("BuildQueue(" .. unitID .."): " .. count)
for i,v in pairs(queue) do
for i2,v2 in pairs(v) do
print(' ' .. i .. ': ' .. i2 .. ' x' .. v2)
end
end
end
function PrintSelection()
local udTable = Spring.GetSelectedUnitsSorted()
local selectedGroup = Spring.GetSelectedGroup()
print("Selected Group = " .. selectedGroup)
print("Selected: " .. udTable.n .. " types")
udTable.n = nil
for udid,uTable in pairs(udTable) do
print(' ' .. udid .. '=' .. UnitDefs[udid].name .. ' count ' .. uTable.n)
uTable.n = nil
for _,uid in ipairs(uTable) do
local health, maxHealth, paralyze, capture, build = Spring.GetUnitHealth(uid)
print(' ', uid, health, maxHealth, paralyze, capture, build)
PrintCommandQueue(uid)
end
end
for udid,uTable in pairs(udTable) do
uTable.n = nil
for uid,udid2 in pairs(uTable) do
PrintBuildQueue(uid)
end
end
end
function PrintCommandQueue(uid)
local queue = Spring.GetCommandQueue(uid)
if (queue ~= nil) then
local msg = ''
local count = 0
for i,cmd in pairs(queue) do
if (cmd ~= CMD.SET_WANTED_MAX_SPEED) then
local name = CommandNames[cmd]
if (name ~= nil) then
count = count + 1
msg = msg .. ' ' .. CommandNames[cmd] .. ','
if (count >= 8) then
break
end
end
end
end
print('', 'commands: ' .. msg)
end
end
function PrintGroups()
local groupList, count = Spring.GetGroupList()
print("GetGroupList: " .. tostring(count))
for i, v in pairs(groupList) do
local groupName = Spring.GetGroupAIName(i)
if (groupName == nil) then groupName = "" end
print(' ' .. i .. '\t' .. v .. '\t' .. groupName)
end
for g, c in pairs(groupList) do
print("Units in Group " .. g)
local udTable = Spring.GetGroupUnitsSorted(g)
print(" MyTeamUnits: " .. udTable.n .. " types")
udTable.n = nil
for udid,uTable in pairs(udTable) do
print(' ' .. udid .. '=' .. UnitDefs[udid].name .. ' count ' .. uTable.n)
uTable.n = nil
for _,uid in ipairs(uTable) do
print(' ', uid)
end
end
end
end
function PrintTeamUnits(team)
udTable = Spring.GetTeamUnitsSorted(team)
-- print("TeamUnits(" .. team .. "): " .. udTable.n .. " types")
-- udTable.n = nil
if (udTable == nil) then
return
end
udTable.n = nil
for udid,uTable in pairs(udTable) do
print(' ' .. udid .. '=' .. UnitDefs[udid].name .. ' count ' .. uTable.n)
uTable.n = nil
for _,uid in ipairs(uTable) do
print(' ', uid)
end
end
end
function PrintTeamUnitsCounts(team)
print("Team Units Count:" .. team)
local countTable = Spring.GetTeamUnitsCounts(team)
if (countTable == nil) then
return
end
countTable.n = nil
for udid,count in pairs(countTable) do
print(' ' .. udid .. '=' .. UnitDefs[udid].name .. ': ' .. count)
end
end
function PrintAlliedUnits()
local teamTable = Spring.GetTeamList(Spring.GetMyAllyTeamID())
-- print("AlliedUnits: " .. teamTable.n .. " teams")
teamTable.n = nil
for n,tid in pairs(teamTable) do
PrintTeamUnits(tid);
end
end
function PrintAllyTeamList()
local allyTeamTable = Spring.GetAllyTeamList()
local msg = "AllyTeams(" .. allyTeamTable.n .. ")"
allyTeamTable.n = nil
for n,atid in pairs(allyTeamTable) do
msg = msg .. " " .. atid
end
print(msg)
end
function PrintTeamList(allyTeam)
local teamTable
if (allyTeam == nil) then
teamTable = Spring.GetTeamList()
else
teamTable = Spring.GetTeamList(allyTeam)
end
if (teamTable == nil) then
return
end
local msg = "Teams(" .. teamTable.n .. ")"
teamTable.n = nil
for n,tid in pairs(teamTable) do
msg = msg .. " " .. tid
end
print(msg)
end
function PrintPlayerList(team)
local playerTable
if (team == nil) then
playerTable = Spring.GetTeamList()
else
playerTable = Spring.GetTeamList(team)
end
if (playerTable == nil) then
return
end
local msg = "Players(" .. playerTable.n .. ")"
playerTable.n = nil
for n,pid in pairs(playerTable) do
msg = msg .. " " .. pid
end
print(msg)
end
function PrintPlayerTree()
local atTable = Spring.GetAllyTeamList()
for atn,atid in ipairs(atTable) do
print('Ally team: ' .. atid)
local tTable = Spring.GetTeamList(atid)
for tn,tid in ipairs(tTable) do
print(' Team: ' .. tid)
local pTable = Spring.GetPlayerList(tid)
for pn,pid in ipairs(pTable) do
local pname, active = Spring.GetPlayerInfo(pid)
if (active) then
print(' Player: ' .. pid .. " " .. pname)
end
end
end
end
end
function PrintTeamInfo(teamID)
local num, leader, dead, isAI, side, allyTeam = Spring.GetTeamInfo(teamID)
print('Team number: ' .. num)
print(' leader: ' .. leader)
print(' dead: ' .. tostring(dead))
print(' isAI: ' .. tostring(isAI))
print(' side: ' .. side)
print(' allyTeam: ' .. allyTeam)
end
function PrintTeamResources(teamID, type)
local current, storage, pull, income, expense,
share, sent, received = Spring.GetTeamResources(teamID, type)
if (current ~= nil) then
print('Team number: ' .. teamID)
print(' ' .. type .. ': ' .. current)
print(' ' .. type .. ' storage: ' .. storage)
print(' ' .. type .. ' pull: ' .. pull)
print(' ' .. type .. ' income: ' .. income)
print(' ' .. type .. ' expense: ' .. expense)
print(' ' .. type .. ' share: ' .. share)
print(' ' .. type .. ' sent: ' .. sent)
print(' ' .. type .. ' received: ' .. received)
end
end
function PrintTeamUnitStats(teamID)
local kills, deaths, caps, losses, recv, sent = Spring.GetTeamUnitStats(teamID)
if (kills ~= nil) then
print('Team number: ' .. teamID)
print(' kills: ' .. kills)
print(' deaths: ' .. deaths)
print(' caps: ' .. caps)
print(' losses: ' .. losses)
print(' recv: ' .. recv)
print(' sent: ' .. sent)
end
end
function PrintPlayerInfo(playerID)
local name, active, spectator, team, allyteam, ping, cpuUsage =
Spring.GetPlayerInfo(playerID)
print(' name: '..name)
print(' id: '..playerID)
print(' active: '..tostring(active))
print(' spectator '..tostring(spectator))
print(' team: '..team)
print(' allyteam: '..allyteam)
print(' ping: '..ping)
print(' cpu: '..(100*cpuUsage)..'%')
end
function PrintCommands(commands)
for i, v in pairs(commands) do
if (type(v) == "table") then
local txt = ""
for i2, v2 in pairs(v) do
txt = txt .. '"' .. i2 .. '"' .. ' = '
if (type(v2) ~= "table") then
txt = txt .. tostring(v2) .. ', '
else
txt = txt .. '{ '
for i3,v3 in pairs(v2) do
txt = txt .. '"' .. v3 .. '", '
end
txt = txt .. '}, '
end
end
print(txt)
else
print(i, v)
end
end
end
function Debug()
for i,v in pairs(UnitDefs) do
if (v ~= nil) then
print(i ..' '.. v.name)
end
end
for i,v in pairs(WeaponDefs) do
if (v ~= nil) then
print(i ..' '.. v.name)
end
end
print("Game.version = " .. Game.version)
print("Game.commEnds = " .. tostring(Game.commEnds))
print("Game.gravity = " .. Game.gravity)
print("Game.tidal = " .. Game.tidal)
print("Game.windMin = " .. Game.windMin)
print("Game.windMax = " .. Game.windMax)
print("Game.mapX = " .. Game.mapX)
print("Game.mapY = " .. Game.mapY)
print("Game.mapSizeX = " .. Game.mapSizeX)
print("Game.mapSizeZ = " .. Game.mapSizeZ)
print("Game.mapName = " .. Game.mapName)
print("Game.modName = " .. Game.modName)
print("Game.limitDGun = " .. tostring(Game.limitDGun))
print("Game.Game.diminishingMetal = " .. tostring(Game.diminishingMetal))
PrintAllyTeamList()
PrintTeamList()
PrintPlayerList()
PrintPlayerTree()
PrintAlliedUnits()
PrintSelection()
PrintGroups()
PrintInCommand()
print("UserName = " .. Spring.GetConfigString("name", ""))
print("Shadows = " .. Spring.GetConfigString("Shadows", 0))
print("ReflectiveWater = " .. Spring.GetConfigString("ReflectiveWater", 1))
PrintTeamUnits(Spring.GetMyTeamID())
print("My Player Info:")
local myPlayerID = Spring.GetMyPlayerID()
PrintPlayerInfo(myPlayerID)
PrintTeamUnitsCounts(Spring.GetMyTeamID())
end
|