package com.lloydm.javakogengine_chess; class Map { public static int hillson = 0;//20oct2021 public static boolean overriderain = false;//18oct2021 public static boolean israining = false;//15oct2021 public static int raining = -4;//15oct2021 public static int MAXRAIN = 100; public static int[] rainx = new int[MAXRAIN];//15oct2021 public static int[] rainy = new int[MAXRAIN];//15oct2021 public static int[] rainh = new int[MAXRAIN];//15oct2021 public static void SetUpHills()//20oct2021 { for(int i=0;i0) { if(Map.weather==Map.WEATHERNORMAL) { if(Game.missions[0].ghill!=null) { for(int i=0;i 90) { raining = 0; } } else { raining = 0; if(Map.weather==Map.WEATHERNORMAL) { if(CampaignMap.seed % 100 > 50) { raining = -3; } } } } if(raining==0) { israining = false; return; } israining = true; for(int i=0;i100) { ff = 100; } rainh[i] += raining * (100 / (ff + 1)); rainx[i] = rainx[i] + (raining / 2) * (100 / (ff + 1)); rainy[i] = rainy[i] - ((raining * 3) / 2) * (100 / (ff + 1)); //RenderList.drawline(game,rainx[i],rainy[],rainx[i] + 2,rainy[i] + 3,RenderList.getrgb(36,36,36),0); RenderList.drawrect(game,rainx[i],rainy[i],4,5,RenderList.getrgb(124,124,144),0); } } } public static int WEATHERNORMAL = 0;//7oct2021 public static int WEATHERCOLD = 1;//7oct2021 public static int WEATHERHOT = 2;//7oct2021 public static int weather = WEATHERNORMAL; public static boolean MINIMAPMODE = false;//18sep2021 public static int DECOR = 9999;//18sep2021 public static int levelseed = 0; //2apr2021 public static int levelseed2 = 0;//2apr2021 public static boolean issnow = false; public static boolean isdesert = false; public static boolean isrgbbk = false; public static int isrgbbk_r = 0; public static int isrgbbk_g = 0; public static int isrgbbk_b = 0; public static int FADEOUT = 10; public static int MAXMUSIC=3; public static int[] musictrack; public static String[] musictrackfile;//25mar2021 public static int[] musicduration; public static int musicplaying; public static int musicstartframe; public static int menumusic; public static int menumusicplaying; public static String menumusicfile = ""; //25mar2021 public static boolean OPENMAP = false; public static int[] deadcell = new int[10]; public static int VACANT = -1; public static int PATHINIT = 99999; public static int NOTCHECKED = -2; public static int MAXX = 100; public static int MAXY = 100; public static int GRIDW = 32; public static int GRIDH = 32; public static int indoor = 0;//23sep2021 public static int DEFAULTGRIDW = 32;//10sep2021 public static int DEFAULTGRIDH = 32;//10sep2021 public static int[] unitmap; //id to unit in cell public static int[] tilefog; //15sep2021 public static int[] unitcollisionmap; public static int[] flightmap;//4may2021 //id to unit in cell...for flyers....MAXX*MAXY*10 (10 should be sufficient)(3 dimensional array as 1 dimensional array) public static int[] flightlist;//4may2021 public static int FLIGHTLEVELS = 2;//4may2021 public static int FLIGHTLAYER = 999;//4may2021 public static int[] pathmap; //public static int[][][][] precalcedpaths; //public static int[][][][] losmap;//15sep2021 public static int precalcframestart; public static int precalcframestart2; public static boolean ignoreunits; // public static int[] heightmap; public static int[] tileimage; public static int[] treeimage; public static int[] rockimage; public static int[] wallimage; public static int[] hillimage;//20oct2021 public static int hillgrass;//20oct2021 public static int hillsnow;//20oct2021 public static int hilldesert;//20oct2021 public static boolean dirtymap = true; public static int FIRETIME = 60 * 10; public static int[] firecell; public static int firecat; public static int fireframes; public static int tilecat; public static int treecat; public static int grasstilecat;//7oct2021 public static int grasstreecat;//7oct2021 public static int snowtilecat;//7oct2021 public static int snowtreecat;//7oct2021 public static int deserttilecat;//7oct2021 public static int deserttreecat;//7oct2021 public static int treeframes; public static int missiontreeframes;//28mar2021 public static int treeoffsety; public static int rockcat; public static int rockframes; public static int rockoffsety; public static int wallcat; public static int wallframes; public static int walloffsety; public static int tileframes; //start--------------//2mar2021 public static int[] decorimage; public static int decorcat; public static int decorframes; public static int odecorframes; //15mar2021 public static int decoroffsety; //end----------------//2mar2021 public static int[] treepositions; public static int FOGMAXX = 24; public static int FOGMAXY = 24; public static int FOGW = 160; public static int FOGH = 160; public static float FOGSCALE = 1f;//18sep2021 public static float FOGADD = -0.25f; public static boolean[] fog; public static float[] fogalpha; // public static String pathfile = ""; public static boolean threadrunning = false; public static int TILELIGHTRADIUS = 8;//15sep2021 public static int MAXTILEFOG = 300;//15sep2021 public static int tmptilecat; public static int tmptreecat; public static int tmprockcat; public static int tmpwallcat; public static int tmpdecorcat; public static int tmptreeoffsety; public static int tmprockoffsety; public static int tmpwalloffsety; public static int tmpdecoroffsety; ///////////////////Method Definition/////////////// public static boolean TileVisible(int x,int y) { if(Config.TILEFOG==0) { return true; } int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0 || gx>=MAXX || gy>=MAXY) { return true; } if(tilefog[gx + gy * MAXX]<=0) { return false; } return true; } ///////////////////Method Definition/////////////// public static int TileFog(Game game,int x,int y)//15sep2021 { if(Config.TILEFOG==0) { return 0; } if(x<0 || y<0 || x>=MAXX || y>=MAXY) { return 0; } //update tilefog..... if(tilefog[x + y * MAXX]>0) { tilefog[x + y * MAXX]--; int jx = x + (Game.frame % (TILELIGHTRADIUS*2)) - TILELIGHTRADIUS; int jy = y + ((Game.frame - (Game.frame % (TILELIGHTRADIUS*2)))/(TILELIGHTRADIUS*2)) - TILELIGHTRADIUS; if(Map.cellunit(jx,jy)!=-1) { int jid = Map.cellunit(jx,jy); if(Game.units[jid].hp>0 && Game.units[jid].faction==Game.PLAYERFACTION) { tilefog[x + y * MAXX] = MAXTILEFOG; } } return 0; } for(int ix=x-TILELIGHTRADIUS;ix<=x+TILELIGHTRADIUS;ix++) { if(ix<0 || ix>=MAXX) { continue; } for(int iy=y-TILELIGHTRADIUS;iy<=y+TILELIGHTRADIUS;iy++) { if(iy<0 || iy>=MAXY) { continue; } if(Map.cellunit(ix * GRIDW,iy * GRIDH)!=-1) { int id = Map.cellunit(ix * GRIDW,iy * GRIDH); if(Game.units[id].hp>0 && Game.units[id].faction==Game.PLAYERFACTION) { tilefog[x + y * MAXX]=MAXTILEFOG; return 0; } } } } return 1; } ///////////////////Method Definition/////////////// public static void init() //13mar2021 { //map initialisation used at startup and restartup musictrack = null; musicduration = null; musicplaying = 0; musicstartframe = 0; menumusic = 0; menumusicplaying = 0; OPENMAP = false; deadcell = new int[10]; unitmap = null; //id to unit in cell tilefog = null; //15sep2021 flightmap = null;//id to unit in cell //4may2021 flightlist = null;//4may2021 unitcollisionmap = null; pathmap = null; //precalcedpaths = null; //losmap = null;//15sep2021 heightmap = null; tileimage = null; treeimage = null; rockimage = null; wallimage = null; firecell = null; hillimage = null;//20oct2021 hilldesert = -1;//20oct2021 hillgrass = -1;//20oct2021 hillsnow = -1;//20oct2021 firecat = 0; fireframes = 0; tilecat = 0; treecat = 0; //7oct202 grass/desert/snow grasstilecat = 0; snowtilecat = 0; deserttilecat = 0; grasstreecat = 0; deserttreecat = 0; snowtreecat = 0; treeframes = 0; treeoffsety = 0; rockcat = 0; rockframes = 0; rockoffsety = 0; wallcat = 0; wallframes = 0; walloffsety = 0; tileframes = 0; GRIDW = 32;//10sep2021 GRIDH = 32;//10sep2021 //DEFAULTGRIDH = 32;//10sep2021 //DEFAULTGRIDW = 32;//10sep2021 //start--------------//2mar2021 decorimage = null; decorcat = 0; decorframes = 0; decoroffsety = 0; //end----------------//2mar2021 treepositions = null; fog = null; fogalpha = null; // pathfile = ""; } ///////////////////Method Definition/////////////// public static void loadpath(int mission) { //not used if(!Config.USEPATHFILE) { return; } try { String file = Config.custommapfolder + "\\path"+mission+".txt"; String[] data = Resources.ReadAllLines(file); for(int i=0;i=0 && nid0)//17sep2021 if(Game.units[i].hp>0 && Game.units[i].flightlevel==-1)//17sep2021 { int gx = Game.units[i].x / GRIDW; int gy = Game.units[i].y / GRIDH; if(gx>=0 && gx=0 && gyConfig.maxmaperrors) { Config.maxmaperrors = errors; } } ///////////////////Method Definition/////////////// public static void updatemusic(Game game) { //handle music control if(Game.gamestate==Game.CAT_GAMESTATE_GAME) { if(menumusicplaying!=-1) { //SDL_mixer.Mix_PauseMusic(); menumusicplaying = -1; } boolean startnewmusic = false; if(musicplaying==-1) { startnewmusic = true; } else { int v = 0; if(Game.frame > musicstartframe + 60 * musicduration[musicplaying]) { startnewmusic = true; } if(Game.frame/Map.FADEOUT < (musicstartframe/Map.FADEOUT) + Game.MUSICVOLUME) { v = (Game.frame - musicstartframe)/Map.FADEOUT; if(v<=0) { v = 1; } if(v>Game.MUSICVOLUME) { v = Game.MUSICVOLUME; } } if((Game.frame/Map.FADEOUT) > (musicstartframe + 60 * (musicduration[musicplaying] - 5))/Map.FADEOUT) { v = Game.MUSICVOLUME - (Game.frame - (musicstartframe + 60 * (musicduration[musicplaying] - 5)))/Map.FADEOUT; if(v<=0) { v = 1; } if(v>Game.MUSICVOLUME) { v = Game.MUSICVOLUME; } } //if(v!=0){SDL_mixer.Mix_VolumeMusic(v);} } if(startnewmusic) { int nmusic = (int)(Functions.rand(0,1000) % musictrack.length); if(nmusic==musicplaying) { nmusic++; nmusic%=musictrack.length; } if(musictrack[nmusic]!=-1) { if(musicplaying!=-1) { //SDL_mixer.Mix_PauseMusic(); } musicplaying = nmusic; Audios.playmusic(Game.audios[musictrack[musicplaying]],Game.MUSICVOLUME,true); musicstartframe = Game.frame; } } } else { if(musicplaying!=-1) { //SDL_mixer.Mix_PauseMusic(); Map.musicplaying = -1; Map.musicstartframe = -1; } if(menumusicplaying==-1) { if(menumusic!=-1) { menumusicplaying = 0; Audios.playmusic(Game.audios[menumusic],Game.MUSICVOLUME,true); } } else { } } } ///////////////////Method Definition/////////////// public Map() { //initialise the map object //for(int i=0;i0) { decorimage[i] = Functions.rand(0,1000) % decorframes; if(decorimage[i]<-1) //15mar2021 bugfix { decorimage[i] = -1; } } //} } if(Map.odecorframes>0) //15mar2021 { Map.decorframes = Map.odecorframes; } } //end----------------//2mar2021 ///////////////////Method Definition/////////////// public static void generate(Game game) { //not used int q = 0; flightmap = new int[MAXX*MAXY*FLIGHTLEVELS];//4may2021 for(int f=0;f0) { for(int wall=0;wall=0 && wy>=0 && wx80) { treeimage[i] = -1; } if(treeimage[i]!=-1) { q = Functions.rand(-150,30); for(int j=0;j=0 && k=0 && i0) { decorimage[i] = Functions.rand(0,1000) % decorframes; } } } //end----------------//2mar2021 int treex = -1; int treey = -1; for(int i=0;i=unitmap.length) { return false; } if(firecell[i]>0) { return true; } return false; } ///////////////////Method Definition/////////////// public static void spreadfire(int x,int y,int time) { //attempt to spread a fire around the map that is burning int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return ; } int i = gx + gy * MAXX; if(i<0 || i>=unitmap.length) { return; } if(firecell[i]<=0) { firecell[i] = time; } } ///////////////////Method Definition/////////////// public static void setonfire(int x, int y,boolean permanent) { //set the ground on fire here int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return; } int i = gx + gy * MAXX; if(i<0 || i>=unitmap.length) { return; } firecell[i] = Map.FIRETIME; if(permanent) { firecell[i] = Map.FIRETIME * 100000; } } ///////////////////Method Definition/////////////// public static void pushmap(int x,int y,int dirn) { //not used pushmapdepth(x / GRIDW,y / GRIDH,4 * dirn,0); int radius = 20; x/=GRIDW; y/=GRIDH; for(int gx = x - radius;gx<=x + radius;gx++) { for(int gy = y - radius;gy<= y + radius;gy++) { if((gx-x)*(gx-x)+(gy-y)*(gy-y)>radius*radius) { continue; } float hh = (float)dirn; float factor = (float)((gx-x)*(gx-x)+(gy-y)*(gy-y))/(float)(radius*radius); hh *= (1f-factor); if(Functions.sign(hh)!=Functions.sign(dirn)) { continue; } pushmapdepth(gx,gy,(int)hh,0); } } } ///////////////////Method Definition/////////////// public static void pushmapdepth(int gx, int gy,int dirn,int depth) { //not used if(depth > 2) { return; } if(gx<0 || gy<0 || gx>=MAXX || gy>=MAXY) { return; } heightmap[gx + gy * MAXX]+=dirn; } ///////////////////Method Definition/////////////// public static int heightdiff2(int curh,int nx,int ny) { //not used int gsx = nx / GRIDW; int gsy = ny / GRIDH; if(gsx<0 || gsy<0 || gsx>=MAXX || gsy>=MAXY) { return 0; } int si = gsx + gsy * MAXX; if(si<0 || si >= heightmap.length) { return 0; } return (int)Functions.abs(heightmap[si] - curh); } ///////////////////Method Definition/////////////// public static int getheight(int x,int y) { //not used int gsx = x / GRIDW; int gsy = y / GRIDH; if(gsx<0 || gsy<0 || gsx>=MAXX || gsy>=MAXY) { return 0; } int si = gsx + gsy * MAXX; if(si<0 || si >= heightmap.length) { return 0; } return heightmap[si]; } ///////////////////Method Definition/////////////// public static int heightdiff(int sx,int sy, int fx, int fy) { //not used //an absolute value..... int gsx = sx / GRIDW; int gsy = sy / GRIDH; int gfx = fx / GRIDW; int gfy = fy / GRIDH; if(gsx<0 || gsy<0 || gsx>=MAXX || gsy>=MAXY || gfx<0 || gfy<0 || gfx>=MAXX || gfy>=MAXY) { return 0; } int si = gsx + gsy * MAXX; int fi = gfx + gfy * MAXX; if(si<0 || fi<0 || si >= heightmap.length || fi>=heightmap.length) { return 0; } return (int)Functions.abs(heightmap[si] - heightmap[fi]); } ///////////////////Method Definition/////////////// public static boolean ishill(int x,int y)//20oct2021 { int gx = x / GRIDW;//21apr2021 int gy = y / GRIDH; //21apr2021 if(gx<0 || gy<0 || gx >= MAXX || gy>= MAXY) { return false; } int i = gx + gy * MAXX; if(i<0 || i>=unitmap.length) { return false; } if(hillimage[i]>0) { return true; } return false; } ///////////////////Method Definition/////////////// public static boolean passable(int x,int y) { //determine if the position on the map is walkable int gx = x / GRIDW;//21apr2021 int gy = y / GRIDH; //21apr2021 if(gx<0 || gy<0 || gx >= MAXX || gy>= MAXY) { return false; } int i = gx + gy * MAXX; if(i<0 || i>=unitmap.length) { return false; } if(treeimage[i]!=-1) { return false; } if(i>0) //21apr2021 { if(treeimage[i-1]!=-1) { return false; } } if((i % MAXX) < MAXX - 1) //21apr2021 { if(treeimage[i+1]!=-1) { return false; } } if(rockimage[i]!=-1) { return false; } if(wallimage[i]!=-1) { return false; } if(gx>0) { if(wallimage[i-1]!=-1) { return false; } } if(gx=unitmap.length) { return false; } for(int gxx=gx-2;gxx<=gx+2;gxx++) { for(int gyy=gy-2;gyy<=gy+2;gyy++) { if(gxx>=0 && gyy>=0 && gxx=unitmap.length) { return; } if(cellunit(x,y)!=-1) { return; } int tmptreeframes = treeframes; if(missiontreeframes!=treeframes && missiontreeframes>0) { tmptreeframes = missiontreeframes; } if(tmptreeframes<=0) { return; } treeimage[i] = (int)Functions.abs(Functions.rand(0,1000)) % tmptreeframes; Game.newtrees = (int[]) ArrayResize.Resize(Game.newtrees,Game.newtrees.length + 1); //11apr2021 Game.newtrees[Game.newtrees.length -1] = i + 1;//treeimage[i] + 1;//24apr2021 //1 based index not 0 based index } ///////////////////Method Definition/////////////// public static boolean isfogged(int x,int y) { //check if the region is covered in fog int fogx = (int)((float)x / (float)Map.FOGW); int fogy = (int)((float)y / (float)Map.FOGH); int f = fogx + fogy * Map.FOGMAXX; if(f>=0 && f0) { return false; } int fogx = (int)((float)(gx * Map.GRIDW) / (float)Map.FOGW); int fogy = (int)((float)(gy * Map.GRIDH) / (float)Map.FOGH); int f = fogx + fogy * Map.FOGMAXX; if(f>=0 && f=1) { return true; } } return false; } ///////////////////Method Definition/////////////// public static void fogclear(Game game,int id) { //clear fog from the map here //if(Game.units[id].faction==Game.PLAYERFACTION) //26Feb2021 if(Game.units[id].faction==Game.PLAYERFACTION || (Game.neutralfog==1 && Game.units[id].faction==Unit.NULLFACTION) || Game.neutralfog==-1) //26Feb2021 { int fogx = (int)((float)Game.units[id].x / (float)Map.FOGW); int fogy = (int)((float)Game.units[id].y / (float)Map.FOGH); for(int xx=fogx-1;xx<=fogx+2;xx++) { for(int yy=fogy-1;yy<=fogy+2;yy++) { int f = xx + yy * Map.FOGMAXX; if(f>=0 && f1) { Map.fogalpha[i] = 1; } float alpha = Map.fogalpha[i]; if(alpha<0) { alpha = 0; } if(alpha>1) { alpha = 1; } if(fogx>-150 && fogy>-150 && fogx0) { //RenderList.drawimage(game,Game.images[Resources.FOG].texture,fogx,fogy,0,1,1,0,0,false,alpha,Resources.FOG); //18sep2021 RenderList.drawimage(game,Game.images[Resources.FOG].texture,fogx,fogy,0,Map.FOGSCALE,Map.FOGSCALE,0,0,false,alpha,Resources.FOG); } } } } } ///////////////////Method Definition/////////////// public static void drawminimap(Game game,int sx,int sy, int fx,int fy) { //not used for(int y=0;y=0 && i=tileimage.length) { return; } //26oct2020 start if(Map.dirtymap) { Map.dirtymap = false; issnow = false; isdesert = false; isrgbbk = false; //1nov2020 tmptilecat = tilecat; tmptreecat = treecat; tmprockcat = rockcat; tmpwallcat = wallcat; tmpdecorcat = decorcat; //2mar2021 tmptreeoffsety = treeoffsety; tmprockoffsety = rockoffsety; tmpwalloffsety = walloffsety; tmpdecoroffsety = decoroffsety; //2mar2021 //if(Game.missions!=null) //&& Game.skirmish==false)//22mar2021 //if(Game.missions!=null && Game.EDITOR==false) //22mar2021 if(Game.missions!=null && (Game.EDITOR==false || (Game.EDITOR==true && Game.demomode==false))) //14apr2021 { if(Game.missionid>=0 && Game.missionid0)//24sep2021 { if(wallimage[i]==-1) { if(i0) { if(wallimage[i - 1]!=-1) { RenderList.drawimage(game,Game.images[Game.shadowleft].texture,offsetx + x-Game.CORNERX-Game.shadowoffx,heightmap[i] + y-Game.CORNERY,0,1f,1f,0,0,false,1f,Game.shadowleft); } } } } //end----------//15sep2021 if(firecell[i]>0) { Map.drawfires(game,offsetx + x-Game.CORNERX,heightmap[i] + y-Game.CORNERY,Map.GRIDW/2,Map.GRIDH/2); if(!Game.paused && !Game.demomode) { firecell[i]--; boolean spread = false; if((Game.frame % 60)==0 && firecell[i]>0 && Game.demomode==false && firecell[i]<=Map.FIRETIME && Map.israining==false) { for(int gxx=gx-1;gxx<=gx+1;gxx++) { for(int gyy=gy-1;gyy<=gy+1;gyy++) { if(gxx>=0 && gyy>=0 && gxx0)//24sep2021 { if(wallimage[i]!=-1) { if(i0) { if(Game.units[i].x>Game.CORNERX && Game.units[i].y>Game.CORNERY && Game.units[i].xmin) { min = count; corx = x; cory = y; } } } } } } } Game.CORNERX = corx; Game.CORNERY = cory; } } Game.mlclickframe = Game.frame; } //if(!Game.paused && !Game.demomode)//1mar2021 if(!Game.paused && !Game.demomode && Game.LOCKCORNER==0)//1mar2021 { //21apr2012 changed mx to rmx etc if(Game.rmxGame.RESOLUTIONX-Game.CORNEREDGEDIST) { Game.CORNERX+=(int)(Game.CORNERSPEED/Game.zoom); } if(Game.rmy>Game.RESOLUTIONY-Game.CORNEREDGEDIST) { Game.CORNERY+=(int)(Game.CORNERSPEED/Game.zoom); } } if(Game.CORNERX<0) { Game.CORNERX = 0; } if(Game.CORNERY<0) { Game.CORNERY = 0; } if(Game.CORNERX > Map.MAXX*Map.GRIDW - Game.RESOLUTIONX) { Game.CORNERX = Map.MAXX*Map.GRIDW - Game.RESOLUTIONX; } if(Game.CORNERY > Map.MAXY*Map.GRIDH - Game.RESOLUTIONY) { Game.CORNERY = Map.MAXY*Map.GRIDH - Game.RESOLUTIONY; } } ///////////////////Method Definition/////////////// public static void removeallbones() { for(int i=0;i=0 && gy>=0 && gx=0 && gy>=0 && gx=0 && gy>=0 && gx0) { count = 1 + ((int)Functions.rand(0,1000) % count); for(int j=0;j=unitmap.length) { return false; } if(unitmap[i]!=id) { return false; } unitmap[i] = -1; return true; } ///////////////////Method Definition/////////////// public static boolean insertunit(int id,int x, int y) { //insert a unit into the map array int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return false; } int i = gx + gy * MAXX; if(i<0 || i>=unitmap.length) { return false; } if(unitmap[i]!=-1) { return false; } unitmap[i] = id; return true; } //start-------------//7mar2021 ///////////////////Method Definition/////////////// public static boolean removeflyer(int id,int x,int y,int flightlevel)//4may2021 { //remove a unit from the map array int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return false; } if(flightlevel<0 || flightlevel>=FLIGHTLEVELS) { return false; } int i = (flightlevel * MAXX * MAXY) + (gy * MAXX) + (gx);//gx + gy * MAXX; if(i<0 || i>=flightmap.length) { return false; } if(flightmap[i]!=id) { return false; } flightmap[i] = -1; return true; } ///////////////////Method Definition/////////////// public static int insertflyer(int id,int x, int y)//4may2021 { //insert a unit into the map array int flightlevel = -1; int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return -1; } for(int f=0;f=flightmap.length) { return -1; } if(flightmap[i]!=-1) { continue; } flightmap[i] = id; flightlevel = f; break; } return flightlevel; } ///////////////////Method Definition/////////////// public static int cellflyer(int x,int y,int flightlevel)//4may2021 { //indicate the unit id at the xy position in question //return -1 if no unit there int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return -1; } if(flightlevel<0 || flightlevel>=FLIGHTLEVELS) { return -1; } int i = gx + gy * MAXX + flightlevel * MAXX * MAXY; if(i<0) { return -1; } if(i>=flightmap.length) { return -1; } return flightmap[i]; } ///////////////////Method Definition/////////////// public static int countfactionneighbours(Game game,int x,int y,int faction) { //return the number of units of a specific faction adjacent to this grid cell int gx = x / GRIDW; int gy = y / GRIDH; int count = 0; if(gx<0 || gy<0) { return -1; } int i = gx + gy * MAXX; if(i<0) { return -1; } if(i>=unitmap.length) { return -1; } for(int gxx=gx-1;gxx<=gx+1;gxx++) { for(int gyy=gy-1;gyy<=gy+1;gyy++) { int nid = cellunit(gxx * GRIDW,gyy * GRIDH); if(nid!=-1) { if(Game.units[nid].faction==faction) { count++; } } } } return count; } //end---------------//7mar2021 ///////////////////Method Definition/////////////// public static int cellunit(int x, int y) { //indicate the unit id at the xy position in question //return -1 if no unit there int gx = x / GRIDW; int gy = y / GRIDH; if(gx<0 || gy<0) { return -1; } int i = gx + gy * MAXX; if(i<0) { return -1; } if(i>=unitmap.length) { return -1; } return unitmap[i]; } ///////////////////Method Definition/////////////// public static void resetpathmap() { if(pathmap.length>0) { int len = pathmap.length; if(len>0) { pathmap[0] = 0; } for(int i=1;i