Skip to content

feat: print with candidate name #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ All other information should be explored by reading the source code!
- [2023/3/28 09:11] fix: ban nonhero units for hero choosing.([#31](https://github.com/Escapingbug/dotaxctf/pull/31),reporter: 114@x1ct34m)
- [2023/3/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30))
- [2023/3/29 08:46] fix: place history.scores updates to correct loc.([#32](https://github.com/Escapingbug/dotaxctf/pull/32), reporter: AAA剑圣)
- [2023/3/29 11:18] feat: print with [Sandbox.candidate_name] banner to support checking specified hero's log.([#33](https://github.com/Escapingbug/dotaxctf/pull/33))
6 changes: 3 additions & 3 deletions rounds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function Rounds:ChooseHeros(chooser_scripts, attributes, bot_scripts)
local cur_team_id = AVAILABLE_TEAMS[i]

for _, candidate_id in ipairs(cur_candidates) do
local chooser = Sandbox:LoadChooseHeroScript(chooser_scripts[candidate_id])
local chooser = Sandbox:LoadChooseHeroScript(chooser_scripts[candidate_id], Candidates[candidate_id])
local hero_name = Sandbox:RunChooseHero(chooser)
local player_id = self.candidate_to_player[candidate_id]
local player_owner = PlayerResource:GetPlayer(player_id)
Expand Down Expand Up @@ -562,11 +562,11 @@ function Rounds:BeginRound(bot_scripts)
}
)

for candidate_num, _ in pairs(Candidates) do
for candidate_num, candidate_name in pairs(Candidates) do
local hero = self.heros[candidate_num]
if hero then
local script = bot_scripts[candidate_num]
BotScriptEnv:AttachScriptOnUnit(hero, script)
BotScriptEnv:AttachScriptOnUnit(hero, script, candidate_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function AttachScriptOnUnit prototype does not have an argument candidcate_name.

end
end
end
Expand Down
14 changes: 8 additions & 6 deletions sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ function Sandbox:SetupGameInfo(game_info)
self.game_info = game_info
end

function Sandbox:LoadScript(user_script, quota, env)
function Sandbox:LoadScript(user_script, quota, env, candidate_name)
for k, v in pairs(self.public_api) do
env[k] = v
end
env["print"] = function (...)
return print("[Sandbox.".. candidate_name .."]", ...)
end
for k, v in pairs(self.game_info) do
env[k] = v
end
Expand Down Expand Up @@ -53,12 +56,12 @@ function Sandbox:RunFunctionWrap(func, ...)
return results[2]
end

function Sandbox:LoadChooseHeroScript(user_script)
return self:LoadScript(user_script, 100000, {})
function Sandbox:LoadChooseHeroScript(user_script, candidate_name)
return self:LoadScript(user_script, 100000, {}, candidate_name)
end

function Sandbox:LoadActionScript(user_script)
return self:LoadScript(user_script, 500000, {})
function Sandbox:LoadActionScript(user_script, candidate_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadActionScript is called in bot_script_env.lua without candidate_name.

return self:LoadScript(user_script, 500000, {}, candidate_name)
end

function Sandbox:RunChooseHero(choose_func)
Expand All @@ -84,7 +87,6 @@ function Sandbox:SandboxPublicAPI()
Vector = Vector,
QAngle = QAngle,
GetGameTime = GetGameTime,
print = print, -- TODO: remove this
}
return api
end
Expand Down