Lua win conditions

Reinforcements seem to be ignored when checking if a player has any units

Information and discussion for custom maps and mods.
Post Reply
jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Lua win conditions

Post by jeremy1337 »

Hi all, super grateful for any help from people knowledgable about the Lua API please.

Background

I'm setting up a mission where one human and one AI start on an empty map with one MCV each.

Their MCVs appear via the Reinforcements.Reinforce() command, which works correctly.

The winning condition for the human is to eliminate the AI side, so in my Tick() function I have:

Code: Select all

Tick = function()
	if soviets.HasNoRequiredUnits() then
		player.MarkCompletedObjective(destroyBaseObjective)
	end
end
As soon as the world loads, this objective evaluates as completed, and the human player receives "mission accomplished".

This indicates that the MCV given to the AI side at the start of the mission is not counted when soviets.HasNoRequiredUnits() evaluates.

The question

Assuming this behaviour is by design, how can I implement a "kill all opposition" objective, such that the AI's MCV has to be killed before the objective is completed?

(Yes, this happens to also be the winning criterion for skirmish games, so it must be doable somehow!)

abcdefg30
Posts: 562
Joined: Mon Aug 18, 2014 6:00 pm

Re: Lua win conditions

Post by abcdefg30 »

Try using

Code: Select all

Tick = function()
	if DateTime.GameTime  > DateTime.Seconds(1) and soviets.HasNoRequiredUnits() then
		player.MarkCompletedObjective(destroyBaseObjective)
	end
end
which will make the game only check for required units after one second into the match, at which point the reinforcements will have entered the map.

jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Re: Lua win conditions

Post by jeremy1337 »

Hello abcdefg30 that's done the trick, thanks ever so much :)

Just while I've got your attention

1) I'm a C++ dev with quite a lot of experience but haven't used Lua before. In the openra API, is there an equivalent of PHP's vardump where I can spit out arrays into the log file to see what they contain? It would make debugging a lot faster.

2) Also unrelated but something I just want to check, am I right in thinking that the AI in missions has to be totally scripted? There's no way we can drop in an AI player like in skirmish with an MCV and expect them to know what to do right?

Thanks in advance!

abcdefg30
Posts: 562
Joined: Mon Aug 18, 2014 6:00 pm

Re: Lua win conditions

Post by abcdefg30 »

Hi, glad that it worked. As for 1) you can use

Code: Select all

Media.DisplayMessage(tostring(variable))
to print something to the game chat for debugging. If you want to print out a table you'll have to iterate over the contents though and print them individually. To answer 2), you can go to the player definitions in "map.yaml" and add "Bot: bottype" to the "PlayerReference" to give the player a bot. For example:

Code: Select all

Players:
	PlayerReference@USSR:
		Name: USSR
		Bot: rush
		Faction: soviet
		Color: FE1100
		Enemies: Greece, England
(Intentionally no "Playable: True" so that it always gets a Rush AI assigned.)

jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Re: Lua win conditions

Post by jeremy1337 »

Hi, that solved both questions thank you, just some small followups please:

1) The following code prints correctly but all it spits back is "Actor (fact 12)", so I'm wondering how to get a bit more info on the objects without knowing what they are beforehand. I'm not sure if this an openra-specific question but is there a way, if I have a table of objects, to print more info about what they are? Ie runtime type identification

Code: Select all

		local sovietBuildings = Utils.Where(Map.ActorsInWorld, function(a)
			return a.Owner == soviets and a.HasProperty("StartBuildingRepairs")
		end)
		for idx, building in ipairs(sovietBuildings) do
			Media.DisplayMessage(tostring(building))
		end
2) I've swapped the bot over and it is behaving correctly thank you and I've now found ra/rules/ai.yaml which is presumably where the rush bot is defined. I can't seem to find any info in the API docs on what the "campaign" bot does, nor in fact does it appear in ai.yaml at all. Is there any documentation on what this bot does, or on the AI generally, please?

abcdefg30
Posts: 562
Joined: Mon Aug 18, 2014 6:00 pm

Re: Lua win conditions

Post by abcdefg30 »

Sadly there's not really a way to get more information other than manually calling properties from https://docs.openra.net/en/latest/relea ... s-commands. Most useful are probably "Location", "Owner", "Type" and "Health".

The "campaign" bot is just a dummy defined in "campaign-rules.yaml", see https://github.com/OpenRA/OpenRA/pull/16119.

jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Re: Lua win conditions

Post by jeremy1337 »

Thanks abcdefg30 that's very helpful. No further questions! :)

Post Reply