Page 1 of 1

Fog of war script

PostPosted: 04 Jul 2013, 11:57
by sado1
Hello. I just wanted to share my Fog of War script. Currently, it works for fight maps only (buildings probably don't reveal the map, and I'm unsure whether it would work fast enough). The code is quite... lame, I would say, but I believe there's no better way to implement FOW at the moment.
  Code:
procedure RevealFog(Units: array of Integer; P: Integer); var I, X, Y: Integer; begin for I := 0 to (Length(Units)-1) do begin X := States.UnitPositionX(Units[I]); Y := States.UnitPositionY(Units[I]); Actions.FogRevealCircle(P, X, Y, 9); end; end; procedure OnMissionStart; var P: Integer; begin for P := 0 to 7 do Actions.FogCoverAll(P); end; procedure OnTick; var P, R: Integer; var Units, Units2: array of Integer; begin for P := 0 to 7 do if ( (States.GameTime + P) mod 10 = 0) and (not(States.PlayerDefeated(P))) then begin Actions.FogCoverAll(P); Units := States.PlayerGetAllUnits(P); RevealFog(Units, P); for R := 0 to 7 do begin if States.PlayerAllianceCheck(P,R) then begin Units2 := States.PlayerGetAllUnits(R); RevealFog(Units2, P); end; end; end; end; procedure OnPlayerDefeated(P: Integer); var I: Integer; begin Actions.FogRevealAll(P); end;
Also, I uploaded an example of a map (I used Enter the Heat, with TDL's permission) that works with the mode. The only changes to the map were making it a special map and obviously adding the script - it should work on any fight map though.

Re: Fog of war script

PostPosted: 04 Jul 2013, 14:41
by Lewin
Nice work :)
The implementation looks fine to me (there's no better way to do it with the current script commands), the way it only processes 1 player per tick should avoid performance issues. I think it should work fine for battle maps, but if you tried it on 8P building maps you might have performance issues with all the serfs...

Re: Fog of war script

PostPosted: 04 Jul 2013, 15:10
by sado1
Who cares about serfs, I'd just assume they don't exist as they usually move within the roads (except when feeding troops) :) For now it was good enough for 6P Ambushed gameplay and 8P Enter the Heat, so it's fine enough on tactical maps.

Re: Fog of war script

PostPosted: 06 Jul 2013, 12:01
by Siegfried
Is this meant to be included into maps? Or just for testing?

Re: Fog of war script

PostPosted: 06 Jul 2013, 16:15
by sado1
Yeah, it can be included into fight maps. If someone wants to use the script, feel free to. I'll probably use this for something, maybe it would fit nicely into the Conquest mode.