Revealing Shroud for parts of the map

How to technically achieve conditional revealing?

Information and discussion for custom maps and mods.
Post Reply
HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Revealing Shroud for parts of the map

Post by HeimSpiel »

Hi guys,

I'm trying to build a map with an north-south-conflict. There are 4 positions in the north and 4 in the south. They are separated by a river that flows more or less in the middle from east to west.

The following is what I want to do:
I want to reveal the shroud (but not fow) in the northern hemisphere for the 4 northern locations. The equivalent for the south.

I'd thought of the following logical solution:
I create an array with the y-coordinates of the river. At the very beginning of the map I'd run an init function that does the following:

Code: Select all

for x=0..border {
 for y=0..border {
  if &#40;y < rivercoordinates&#40;x&#41; &#41;
   reveal1tilenorth&#40;x,y&#41;
  else
   reveal1tilesouth&#40;x,y&#41;
 &#125;
&#125;
- So the problem I have now is how do I achieve that? It seems to me that I need a lua script, is that correct?
- Is there a list for all available triggers?
- Is there an easier way to to this maybe with map.yaml settings only?
- How can I force an alliance of the northern/southern players?

User avatar
Graion Dilach
Posts: 277
Joined: Fri May 15, 2015 5:57 pm

Re: Revealing Shroud for parts of the map

Post by Graion Dilach »

HeimSpiel wrote: - So the problem I have now is how do I achieve that? It seems to me that I need a lua script, is that correct?
- Is there an easier way to to this maybe with map.yaml settings only?
You can either do a lua script, either add two nonplayable (NonCombatant: true) players (one allied with the north, one with the south) and place camera actors to the places you want revealed. I feel the latter option a bit hacky and unclean to be honest, though.
HeimSpiel wrote: - Is there a list for all available triggers?
https://github.com/OpenRA/OpenRA/wiki/Lua-API Ctrl-F Trigger there.
HeimSpiel wrote: - How can I force an alliance of the northern/southern players?
Set LockTeam to true and Team in the PlayerReference. See Fort Lonestar for an example.
Image
Image
Image
AS Discord server: https://discord.gg/7aM7Hm2

HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Re: Revealing Shroud for parts of the map

Post by HeimSpiel »

Graion Dilach wrote: You can either do a lua script
So I decided to go that way. What I have so far:

Code: Select all

River = &#123; 80, 80, 79, 78, etc. &#125;

RevealCoord = function&#40;pos, gamer&#41;
	for i=1,#gamer do
		??? what to do here ???
	end
end

WorldLoaded = function&#40;&#41;
	north = &#123; &#125;
	south = &#123; &#125;
	for i = 0,3 do
		north&#91;i+1&#93; = Player.GetPlayer&#40;"Multi" ..i&#41;
	end
	for i = 4,7 do
		south&#91;i+1&#93; = Player.GetPlayer&#40;"Multi" ..i&#41;
	end
	for x = 1,159 do
		for y = 1,159 do
			if &#40;y < River&#91;x&#93;&#41; then
				RevealCoord&#40;WPos.New&#40;x,y,0&#41;, north&#41;
			else
				RevealCoord&#40;WPos.New&#40;x,y,0&#41;, south&#41;
			end
		end
	end
end
The problem now is that I'm missing an API call to reveal the shroud. What can I do?
Graion Dilach wrote: Set LockTeam to true and Team in the PlayerReference. See Fort Lonestar for an example.
That worked, thanks!

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

Post by abcdefg30 »

You would need to create a camera actor at "??? what to do here ???".
This can be also done through map.yaml / the ingame map editor.
Just place cameras owned by each player you want to have sight there.
(Then you wouldn't need a lua script.)

HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Post by HeimSpiel »

Hi guys,

after some tries I decided to go with the solution abcdefg30 proposed.
But 2 more questions:

a) is it possible to have multiple locations as an owner of a map? It's quite dull to have the actors spawned 4 times.

b) is there an actor that reveals only fow but not the shroud? 'camera' seems to reveal fow, too.

HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Post by HeimSpiel »

My current situation is the following: I have a bunch of Actors in map.yaml

Code: Select all

...
	Actor1101&#58; camera
		Owner&#58; Multi0
		Location&#58; 189,216
...
What I try to do is to kill all those camera actors a second after map start with the following lua script

Code: Select all

DoFoW = function&#40;&#41;
	for i = 0,7 do
		CurPlayer = Player.GetPlayer&#40;"Multi"..i&#41;
		if CurPlayer ~= nil then
			ActCameras = CurPlayer.GetActorsByType&#40;"camera"&#41;
			for i=1,#ActCameras do
				Trigger.AfterDelay&#40;DateTime.Seconds&#40;10&#41;, function&#40;&#41;
					ActCameras&#91;i&#93;.Destroy&#40;&#41;
				end&#41;
			end
		end
	end
end
Nothing happens.
It seems I have access to dynamically assigned cameras. This works and reveals a part of the map around the specified coordinates:

Code: Select all

DoFoW = function&#40;&#41;
	loc = CPos.New&#40;28,112&#41;
	for i = 0,7 do
		CurPlayer = Player.GetPlayer&#40;"Multi"..i&#41;
		if CurPlayer ~= nil then
			SpyCamera = Actor.Create&#40;"camera", true, &#123; Owner = CurPlayer, Location = loc &#125;&#41;
			Trigger.AfterDelay&#40;DateTime.Seconds&#40;10&#41;, function&#40;&#41;
				SpyCamera.Destroy&#40;&#41;
			end&#41;
		end
	end
end
I wonder: why don't I get access to the camera actors defined in the map.yaml?

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

Post by abcdefg30 »

HeimSpiel wrote: a) is it possible to have multiple locations as an owner of a map? It's quite dull to have the actors spawned 4 times.
Sorry, I don't exactly get what you mean here...
Something like:

Code: Select all

ActorXY&#58; type
   Owner&#58; Multi0
   Location&#58; 0,0 1,1 2,2 3,3 ...
?
If so, that is not possible.
HeimSpiel wrote: b) is there an actor that reveals only fow but not the shroud? 'camera' seems to reveal fow, too.
Sorry, I don't think that is possible.


Your latest problem is weird.. I couldn't find errors while looking over your code.
Are you running DoFoW from inside WorldLoaded?
Also: You can access the actors from map.yaml through their names.
E.g.

Code: Select all

Trigger.AfterDelay&#40;DateTime.Seconds&#40;10&#41;, function&#40;&#41;
   ...
   Actor1101.Destroy&#40;&#41;
   ...
end&#41;
PS: Sorry for the late answer.

HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Post by HeimSpiel »

I finally managed to achieve what I wanted. For those who may need a similar thing:

I removed all cameras from the yaml and into the lua. At the beginning of the match, the cameras are created dynamically with a trigger that kills them after a few seconds:

Code: Select all

CamPosNorth = &#123; CPos.New&#40;9,0&#41;, CPos.New&#40;9,18&#41;, CPos.New&#40;0,9&#41;, CPos.New&#40;18,9&#41; ..... &#125;
CamPlayerNorth = &#123; &#125;

RevealNorth = function&#40;&#41;
	for i = 0,3 do
		gamer = Player.GetPlayer&#40;"Multi"..i&#41;
		if gamer ~= nil then
			CamPlayerNorth&#91;i+1&#93; = &#123; &#125;
			for k = 1,#CamPosNorth do
				CamPlayerNorth&#91;i+1&#93;&#91;k&#93; = Actor.Create&#40;"camera", true, &#123; Owner = gamer, Location = CamPosNorth&#91;k&#93; &#125;&#41;
				Trigger.AfterDelay&#40;DateTime.Seconds&#40;3&#41;, function&#40;&#41;
					CamPlayerNorth&#91;i+1&#93;&#91;k&#93;.Destroy&#40;&#41;
				end&#41;
			end
		end
	end
end
To completely reveal a region you don't need to add a camera at each cell - it's sufficient to have them at the corners of a diamond with a diameter of 18 cells.

Thanks for all the input!

Post Reply