Map Database  •  FAQ  •  RSS  •  Register  •  Login

Fog of war script

<<

sado1

User avatar

Council Member

Posts: 1412

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 04 Jul 2013, 11:57

Fog of war script

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.
You do not have the required permissions to view the files attached to this post.
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3821

Joined: 16 Sep 2007, 22:00

Location: Australia

KaM Skill Level: Skilled

Post 04 Jul 2013, 14:41

Re: Fog of war script

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...
<<

sado1

User avatar

Council Member

Posts: 1412

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 04 Jul 2013, 15:10

Re: Fog of war script

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.
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 06 Jul 2013, 12:01

Re: Fog of war script

Is this meant to be included into maps? Or just for testing?
<<

sado1

User avatar

Council Member

Posts: 1412

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 06 Jul 2013, 16:15

Re: Fog of war script

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.

Return to Ideas / Suggestions

Who is online

Users browsing this forum: No registered users and 7 guests