-
Notifications
You must be signed in to change notification settings - Fork 0
/
fog.cpp
executable file
·58 lines (52 loc) · 1.27 KB
/
fog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "main.hpp"
void Model::revealFog(playerID player, int radius, int x, int y)
{
if(player==0)
return;
int r2 = radius*radius;
int xi, yi;
int minx = x-radius,
maxx = x+radius,
miny = y-radius,
maxy = y+radius;
if(minx<0) minx=0;
if(miny<0) miny=0;
if(maxx>=(int)sizeX) maxx=sizeX-1;
if(maxy>=(int)sizeY) maxy=sizeY-1;
for(yi=miny; yi<=maxy; yi++)
for(xi=minx; xi<=maxx; xi++)
{
if( (xi-x)*(xi-x) + (yi-y)*(yi-y) <= r2 )
fogOfWar[player][yi][xi]++;
}
}
void Model::concealFog(playerID player, int radius, int x, int y)
{
if(player==0)
return;
int r2 = radius*radius;
int xi, yi;
int minx = x-radius,
maxx = x+radius,
miny = y-radius,
maxy = y+radius;
if(minx<0) minx=0;
if(miny<0) miny=0;
if(maxx>=(int)sizeX) maxx=sizeX-1;
if(maxy>=(int)sizeY) maxy=sizeY-1;
for(yi=miny; yi<=maxy; yi++)
for(xi=minx; xi<=maxx; xi++)
{
if( (xi-x)*(xi-x) + (yi-y)*(yi-y) <= r2 )
fogOfWar[player][yi][xi]--;
}
}
bool Model::playerCanSee(playerID player, unsigned x, unsigned y)
{
return fogOfWar[player][y][x]>0 || fogOfWar[player][y+1][x+1]>0;
}
void Model::revealFogAround(unitID unit)
{
Unit *u = getUnit(unit);
revealFog(u->owner, u->type->vision, u->nextX, u->nextY);
}