00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include "stratagus.h"
00036 #include "player.h"
00037 #include "unittype.h"
00038 #include "unit.h"
00039 #include "map.h"
00040
00041
00042
00043
00044
00053 bool UnitVisibleOnRadar(const CPlayer *pradar, const CUnit *punit)
00054 {
00055 for (int i = punit->X; i < punit->X + punit->Type->TileWidth; ++i) {
00056 for (int j = punit->Y; j < punit->Y + punit->Type->TileHeight; ++j) {
00057 if (IsTileRadarVisible(pradar, punit->Player, i, j) != 0) {
00058 return true;
00059 }
00060 }
00061 }
00062
00063
00064 return false;
00065 }
00066
00077 unsigned char IsTileRadarVisible(const CPlayer *pradar, const CPlayer *punit, int x, int y)
00078 {
00079 unsigned char radarvision;
00080 unsigned char *radar;
00081 unsigned char *jamming;
00082
00083 jamming = Map.Field(x, y)->RadarJammer;
00084 if (jamming[punit->Index]) {
00085 return 0;
00086 }
00087
00088 radar = Map.Field(x, y)->Radar;
00089 radarvision = radar[pradar->Index];
00090
00091 if (!pradar->SharedVision) {
00092 return radarvision;
00093 }
00094
00095
00096 for (int i = 0; i < PlayerMax; ++i) {
00097 if (jamming[i] > 0 && (punit->SharedVision & (1 << i)) &&
00098 (Players[i].SharedVision & (1 << punit->Index))) {
00099
00100 return 0;
00101 }
00102 if (pradar->SharedVision & (1 << i) &&
00103 (Players[i].SharedVision & (1 << pradar->Index))) {
00104 radarvision |= radar[i];
00105 }
00106 }
00107
00108
00109 return radarvision;
00110 }
00111
00119 void MapMarkTileRadar(const CPlayer *player, int x, int y)
00120 {
00121 Assert(0 <= x && x < Map.Info.MapWidth);
00122 Assert(0 <= y && y < Map.Info.MapHeight);
00123 Assert(Map.Field(x, y)->Radar[player->Index] != 255);
00124
00125 Map.Field(x, y)->Radar[player->Index]++;
00126 }
00127
00135 void MapUnmarkTileRadar(const CPlayer *player, int x, int y)
00136 {
00137 unsigned char *v;
00138
00139 Assert(0 <= x && x < Map.Info.MapWidth);
00140 Assert(0 <= y && y < Map.Info.MapHeight);
00141
00142
00143 v = &Map.Field(x, y)->Radar[player->Index];
00144 if (*v) {
00145 --*v;
00146 }
00147 }
00148
00156 void MapMarkTileRadarJammer(const CPlayer *player, int x, int y)
00157 {
00158 Assert(0 <= x && x < Map.Info.MapWidth);
00159 Assert(0 <= y && y < Map.Info.MapHeight);
00160 Assert(Map.Field(x, y)->RadarJammer[player->Index] != 255);
00161
00162 Map.Field(x, y)->RadarJammer[player->Index]++;
00163 }
00164
00172 void MapUnmarkTileRadarJammer(const CPlayer *player, int x, int y)
00173 {
00174 unsigned char *v;
00175
00176 Assert(0 <= x && x < Map.Info.MapWidth);
00177 Assert(0 <= y && y < Map.Info.MapHeight);
00178
00179
00180 v = &Map.Field(x, y)->RadarJammer[player->Index];
00181 if (*v) {
00182 --*v;
00183 }
00184 }