package com.lloydm.javakogengine_chess; import java.io.File; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.os.Environment; import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; class Program { //game specific stuff here // //RTS Components // public static boolean quit = false; public static int rframe = 0;//22sep2021 public static Game game; public static long frametime = 0; ///////////////////Method Definition/////////////// static void Main(String[] args) { if(args!=null) { if(args.length>0) { if(args[0].equals("-editor")) { Game.EDITOR = true; } } } //init(); //13mar2021 //start--------------//13mar2021 Game.restart = true; Game.restartgamestate = -1;//26mar2021 while(Game.restart) { Game.restart = false; init(); } //end----------------//13mar2021 } ///////////////////Method Definition/////////////// //static void checkconfig() //28Feb2021 ///////////////////Method Definition/////////////// static boolean checkconfig() //28Feb2021 { //Game initialisation - check the config file //and setup initial parameters including the filenames and paths //to check for all the various game components //language also set here //start-------------//12mar2021 Game.BOARDY = 900/9; if(Game.RESOLUTIONY==1200 && Game.RESOLUTIONX==1600) { Game.LETTERBOX = true; Game.BOARDY = 1200 / 9; } Config.useUNICODE = false; //15mar2021 if(Config.KOG2) { Game.NETTITLE = "grumthorr2"; Game.TITLE = "Knights of Grumthorr 2"; } //end---------------//12mar2021 //25Feb2021 - altered order of try/catch statements...config file read first. //start-------------//28Feb2021 Config.configfile = "media/txt/config.txt"; //28Feb2021 try { String[] cdata = Resources.ReadAllLines("media/txt/init.txt"); for(int i=0;i1) { alpha = 1f; } if(sx>1) { sx = 1f; } if(sy>1) { sy = 1f; } RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(1,1,8),0); RenderList.drawimage(game,Game.images[Resources.LOGO].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,2,2,0,0,false,alpha,Resources.LOGO); //if(Game.frame>180)27mar2021 if(fr>180)//27mar2021 { Game.gamestate=Game.CAT_GAMESTATE_MENU; Game.chosenmissionindex = 0;//25sep2021 Config.loaded = false; Config.loadpct = 0; Unit.QuickGetColor(); Unit.NewColor0(null, -1, 0); } } ///////////////////Method Definition/////////////// public static void skirmishmission(Game game) { //setup the skirmish mission settings ///////////////////////////// //unit positions and types.. Game.fogoff = 0; //26Feb2021 Game.neutralfog = 0; //26Feb2021 Game.LOCKCORNER = 0;//1mar2021 Game.skirmish = true; Game.zoom = 0; Game.mwheel = 0; Game.playingtutorial = false; Game.victorymessage = true; cleardeaths(game); int id = 0; int tmpid = -1; int jjj = - 1; for(int i=0;i=0 && yy>=0 && xx0) { id++; } } } if(id>0) { id = 1 + (Functions.rand(1,1000) % id); for(int i=0;i0) { id--; if(id<=0) { tmpid = i; break; } } } } } if(tmpid>=0) { for(int x=40;x<60;x++) { Map.treeimage[x + y * Map.MAXX] = -1; Map.rockimage[x + y * Map.MAXX] = -1; Map.wallimage[x + y * Map.MAXX] = -1; if(Functions.rand(0,100)<20 && Map.passable(x * Map.GRIDW, y * Map.GRIDH)==true && maxj>0) { jjj++; if(jjj0) { id++; } } } if(id>0) { id = 1 + (Functions.rand(1,1000) % id); for(int i=0;i0) { id--; if(id<=0) { tmpid = i; break; } } } } } if(tmpid>=0) { int aa = Functions.rand(10,79); int bb = aa + 20; for(int x=aa;x0) { Game.units[jjj].createunitatxy(game,jjj,Game.templates[tmpid],x * Map.GRIDW,y * Map.GRIDH); Game.units[jjj].ai = Unit.AI_EXTRAASSAULT; Game.units[jjj].orderframe = 300; jjj++; maxj--; } } } } //copy the triggers..... for(int i=0;i0 && Game.templates[i].faction!=Unit.NULLFACTION) { String enemyunitname = Game.templates[i].name; found = false; for(int j=0;j0) { found = true; } } if(found) { Game.triggers[id] = new Trigger(game,Trigger.TYPE_OR_DEFEAT,0,0,enemyunitname,0 ,0,100, 100); id++; } } if(Game.templates[i].faction!=Game.PLAYERFACTION && Game.templates[i].walkspeed>0 && Game.templates[i].faction!=Unit.NULLFACTION) { String unitname = Game.templates[i].name; found = false; for(int j=0;j0) { found = true; } } if(found) { Game.triggers[id] = new Trigger(game,Trigger.TYPE_VICTORY,0,0,unitname,0 ,0,100, 100); id++; } } } Game.triggers[id] = new Trigger(game,Trigger.TYPE_CHATTER,((int)Functions.rand(0,1000)%20),1,Config.skirmishmessage,300,780,0,0); Game.GAMEENDSTATE = 0; Game.gameovertime = 0; Game.paused = false; } ///////////////////Method Definition/////////////// public static void testdebrief(Game game) { //debugging only for(int i=0;i0) { mission = i; break; } } setupmission(game,mission,1); Game.playingtutorial = false; } ///////////////////Method Definition/////////////// public static void setupmission(Game game,int mission,int tutorial) { Beacon.Init();//19oct2021 Beacon.enabled = 1;//20oct2021 //start---------//18oct2021 Game.LocalPlayerIndex = Game.FriendIndex; Game.LocalEnemyIndex = Game.EnemyIndex; Game.spellcast = 0; Map.overriderain = false; if(Game.vsai<=0) { if(NetworkUDP.Ready()) { if(NetworkUDP.isserver) { Game.LocalPlayerIndex = Game.FriendIndex; Game.LocalEnemyIndex = Game.EnemyIndex; } else { Game.LocalPlayerIndex = Game.EnemyIndex; Game.LocalEnemyIndex = Game.FriendIndex; } } } //end------------//18oct2021 Game.spellcast = 0;//18oct2021 Game.winloss = 0;//17oct2021 Game.battlespeed = 1;//16oct2021 Functions.saveseed(); //apply all mission settings prior to starting the mission //start--------//17sep2021 boolean minimap = false; if(tutorial==99) { minimap = true; tutorial = 2; } //end----------//17sep2021 Game.gamestartframe = Game.frame;//2apr2021 Tech.resetall(game);//2sep2021 if(mission==1)//24sep2021 { Tech.unpurchase(game); } Config.precalcused = 0; Config.seekpathfailed = 0; Config.seekpathsuccess = 0; Config.seekpathused = 0; Game.fogoff = 0; //26Feb2021 Game.neutralfog = 0; //26Feb2021 Game.LOCKCORNER = 0; //1mar2021 Game.zoom = 0; Game.mwheel = 0; Game.playerready = false; Game.playingtutorial = false; Game.skirmish = false; Game.victorymessage = false; cleardeaths(game); if(mission<0 && mission!=-999 && tutorial==0) { mission = 0; } if(mission>0 && mission!=-999 && tutorial==0 && tutorial!=2) { if(mission>Game.maxmission) { Game.maxmission = mission; } } if(Game.missions.length>0 && mission!=-999) { if(mission>=0 && mission0) { Game.playingtutorial = true; } Game.missionid = mission; Map.loadpath(mission); //try and get the precalced path..... Game.nextmissionid = Game.missions[mission].nextmissionid; Game.failedmissionid = Game.missions[mission].failedmissionid; //start--------------//1mar2021 if(!Game.missions[mission].nextmissionname.equals("")) { for(int mi=0;mi0 && Map.deserttilecat>0) { try { //final String weatherdate = DateFormat.format("yyyy-MM-dd", System.currentTimeMillis()).toString(); int dayofmonth = 15; //try //{ // dayofmonth = Integer.decode(weatherdate.substring(8, 10)); //} //catch(Exception f) //{ // //do nothing.... //} int randomweather = Functions.rand(0,1000) % 100; if(Game.chosenmissionindex==1)//FINAL VICTORY//17oct2021 { dayofmonth = 1; randomweather=50; } if(Game.chosenmissionindex==2)//FINAL Defeat//17oct2021 { dayofmonth = 1; randomweather = 5; } if(dayofmonth<10) { //winter (cold and dark) if(randomweather<30) { Map.tilecat = Map.snowtilecat; if(randomweather<15) { Map.treecat = Map.snowtreecat; } Map.weather = Map.WEATHERCOLD; } if(randomweather>90) { Map.tilecat = Map.deserttilecat; if(randomweather>95) { Map.treecat = Map.deserttreecat; } Map.weather = Map.WEATHERHOT; } } if(dayofmonth>20) { //summer (hot and dry) if(randomweather<10) { Map.tilecat = Map.snowtilecat; if(randomweather<5) { Map.treecat = Map.snowtreecat; } Map.weather = Map.WEATHERCOLD; } if(randomweather>70) { Map.tilecat = Map.deserttilecat; if(randomweather>85) { Map.treecat = Map.deserttreecat; } Map.weather = Map.WEATHERHOT; } } if(dayofmonth>=10 && dayofmonth<=20) { //temperate if(randomweather<15) { Map.tilecat = Map.snowtilecat; Map.treecat = Map.snowtreecat; Map.weather = Map.WEATHERCOLD; } if(randomweather>85) { Map.tilecat = Map.deserttilecat; Map.treecat = Map.deserttreecat; Map.weather = Map.WEATHERHOT; } } } catch(Exception e) { } } //end-----------------//7oct2021 //start---------------//14oct2021 if(Game.campaignmode>0) { if(Game.campaignattackprovince!=-1) { if(Functions.rand(0,100)<85) { int provinceweather = CampaignMap.provinceweather[Game.campaignattackprovince]; if(provinceweather==Map.WEATHERCOLD || provinceweather==Map.WEATHERHOT) { Map.weather = provinceweather; } if(Map.weather==Map.WEATHERCOLD) { Map.tilecat = Map.snowtilecat; Map.treecat = Map.snowtreecat; Map.weather = Map.WEATHERCOLD; } if(Map.weather==Map.WEATHERHOT) { Map.tilecat = Map.deserttilecat; Map.treecat = Map.deserttreecat; Map.weather = Map.WEATHERHOT; } } } } //end-----------------//14oct2021 Map.indoor = Game.missions[mission].indoor;//23sep2021 Game.CORNERX = Game.missions[mission].cornerx; Game.CORNERY = Game.missions[mission].cornery; Game.fogoff = 0;//Functions.sign(Game.missions[mission].fogoff); //26Feb2021//26sep2021 Game.neutralfog = Functions.sign(Game.missions[mission].neutralfog); //26Feb2021 Game.LOCKCORNER = Game.missions[mission].lockcorner; //1mar2021 //4apr2021 added //Network command in here // //if(Game.missions[mission].name!="demo") //5apr2021//17sep2021 if(!Game.missions[mission].name.equals("demo") && minimap==false) //5apr2021//17sep2021 { try { //Network.url = "https://www.mattiesgames.com/metrics/metric.php?game=kog2mission&event="+Game.missions[mission].name.Replace(" ","_")+"&value=1&uid="+Config.uid;//30mar2021 //Network.httpget(//Network.url); } catch(Exception e) { String message = e.getMessage(); } } // // //start-------------//28Feb2021 Game.PLAYERFACTION = Game.missions[mission].playerfaction; Game.SKIRMISHENEMYFACTION = Game.missions[mission].skirmishenemyfaction; //end---------------//28Feb2021 if(Game.missions[mission].skirmish==1) { Game.skirmish = true; } for(int i=0;i 0) //26oct2020 { Map.decorimage[Game.missions[mission].decorimage[i]] = Functions.rand(0,1000) % Game.missions[mission].decorframes;//8; } else { if(Map.decorframes>0)//19sep2021 bugfix { Map.decorimage[Game.missions[mission].decorimage[i]] = Functions.rand(0,1000) % Map.decorframes;//8; } } //Log.i(Config.TAG,"Index:"+Game.missions[mission].treeimage[i]+ " Value:"+Map.treeimage[Game.missions[mission].treeimage[i]]); } } //end----------------//2mar2021 Map.missiontreeframes = Map.treeframes;//28mar2021 if(Game.missions[mission].treeimage!=null) { for(int i=0;i 0) //26oct2020 { Map.treeimage[Game.missions[mission].treeimage[i]] = Functions.rand(0,1000) % Game.missions[mission].treeframes;//8; Map.missiontreeframes = Game.missions[mission].treeframes; } else { Map.treeimage[Game.missions[mission].treeimage[i]] = Functions.rand(0,1000) % Map.treeframes;//8; } //Log.i(Config.TAG,"Index:"+Game.missions[mission].treeimage[i]+ " Value:"+Map.treeimage[Game.missions[mission].treeimage[i]]); } } if(Game.missions[mission].rockimage!=null) { for(int i=0;i 0) //26oct2020 { Map.rockimage[Game.missions[mission].rockimage[i]] = Functions.rand(0,1000) % Game.missions[mission].rockframes;//4; } else { Map.rockimage[Game.missions[mission].rockimage[i]] = Functions.rand(0,1000) % Map.rockframes;//4; } } } if(Game.missions[mission].wallimage!=null) { for(int i=0;i 0) //26oct2020 { Map.wallimage[Game.missions[mission].wallimage[i]] = Functions.rand(0,1000) % Game.missions[mission].wallframes;//; } else { Map.wallimage[Game.missions[mission].wallimage[i]] = Functions.rand(0,1000) % Map.wallframes;//; } } } //start--------//16sep2021 //if(Game.missions[mission].floorpattern>0)//17sep2021 if(Game.missions[mission].floorpattern>0 && minimap==false)//17sep2021 { if(Game.missions[mission].floorpattern==1 && Map.tileframes>3) { int mainfloor = Functions.rand(0,1000) % 3; int secondaryfloor = Functions.rand(0,1000) % 3; if(mainfloor<0) { mainfloor = 0; } if(secondaryfloor<0) { secondaryfloor = 0; if(secondaryfloor == mainfloor) { secondaryfloor = 1; } } for(int a=0;a<10;a++) { if(secondaryfloor==mainfloor) { secondaryfloor = Functions.rand(0,1000) % 3; } else { break; } } int thirdfloor = 0; if(mainfloor==0 || secondaryfloor==0) { thirdfloor = 1; } if(mainfloor==1 || secondaryfloor==1) { thirdfloor = 2; } for(int x=1;x0) { Functions.saveseed(Game.missions[mission].seed); Map.generate(game); Functions.restoreseed(); } //15oct2021 added this block Functions.restoreseed(); //if(Game.campaignmode>0)//17oct2021 if(Game.campaignmode>0 && Game.chosenmissionindex<1)//17oct2021 { CampaignMap.CreateMap(Game.campaignattackprovince); } else { CampaignMap.CreateMap(-1); } Map.SetUpHills();//20oct2021 //unit positions and types.. for(int i=0;i=Unit.MAXUNITS) { continue; } for(int j=0;j0) { if(Game.units[i].faction!=Unit.HUMAN) { Game.units[i].hp=0; } } } break; } } } } //copy the triggers..... for(int i=0;i=Game.triggers.length) { continue; } Game.triggers[i] = new Trigger(game,Game.missions[mission].triggers[i].type,Game.missions[mission].triggers[i].comparator,Game.missions[mission].triggers[i].n,Game.missions[mission].triggers[i].unitname,Game.missions[mission].triggers[i].x , Game.missions[mission].triggers[i].y, Game.missions[mission].triggers[i].fx, Game.missions[mission].triggers[i].fy); if(Game.triggers[i].unitname!=null)//7oct2021 { int qq = Functions.rand(0,10); if(Game.triggers[i].unitname.equals("WEATHER")) { if(Map.weather==Map.WEATHERHOT) { Game.triggers[i].unitname = "It is a hot day sir.|The troops will tire more quickly."; if(qq==0) { Game.triggers[i].unitname = "The hot weather will weaken our armoured soldiers"; } if(qq==1) { Game.triggers[i].unitname = "The terrible heat makes it hard to fight in."; } } if(Map.weather==Map.WEATHERCOLD) { Game.triggers[i].unitname = "It is a cold and blustery day. The army will march slower.|Our arrows will not travel as far."; if(qq==0) { Game.triggers[i].unitname = "The Wintry weather will affect both their troops and ours."; } if(qq==1) { Game.triggers[i].unitname = "The cold weather will impact our fighting ability."; } if(qq==2) { Game.triggers[i].unitname = "The snow and ice will make it harder to fight in."; } } if(Map.weather==Map.WEATHERNORMAL) { Game.triggers[i].unitname = "It is a fine day for battle dear General."; if(qq==0) { Game.triggers[i].unitname = "The weather is good for fighting."; } if(qq==1) { Game.triggers[i].unitname = "A clear day."; } } } if(Game.triggers[i].unitname.equals("WON")) { Game.triggers[i].unitname = "We won the battle! The enemy is scattered|to the four winds."; if(qq==1) { Game.triggers[i].unitname = "The day is ours. Our enemies are crushed before us!"; } if(qq==2) { Game.triggers[i].unitname = "They flee from our army - we have won!"; } if(qq==3) { Game.triggers[i].unitname = "Victory is ours!"; } if(qq==4) { Game.triggers[i].unitname = "We stand victorious General!"; } if(qq==5) { Game.triggers[i].unitname = "Our army has defeated the enemy!"; } //Log.i(Config.TAG,"Trigger:"+Game.triggers[i].unitname); } if(Game.triggers[i].unitname.equals("LOST")) { Game.triggers[i].unitname = "All is lost! Our troops have routed|and been destroyed."; if(qq==0) { Game.triggers[i].unitname = "We have lost the battle General. Our armies flee in terror."; } if(qq==1) { Game.triggers[i].unitname = "The day is lost!|Our forces have been destroyed."; } if(qq==2) { Game.triggers[i].unitname = "A terrible loss for our forces General."; } if(qq==3) { Game.triggers[i].unitname = "The bitter taste of defeat is in our mouths.|We lost this one."; } //Log.i(Config.TAG,"Trigger:"+Game.triggers[i].unitname); } if(Game.LETTERBOX==true && (Game.triggers[i].type==3 || Game.triggers[i].type==4)) { Game.triggers[i].x = Game.triggers[i].fx; Game.triggers[i].y = Game.triggers[i].fy; } } } } if(Game.missions[mission].campfirex!=-1) { Map.setonfire(Game.missions[mission].campfirex,Game.missions[mission].campfirey,true); } Game.GAMEENDSTATE = 0; Game.gameovertime = 0; Game.paused = false; Map.adddecor();//2mar2021 Map.marktreepos(game); Gui.ResetSpells();//26sep2021 } } } ///////////////////Method Definition/////////////// public static void resetlevel(Game game) { //reset procedure //temporary Game.GAMEENDSTATE = 0; Game.gameovertime = 0; Game.zoom = 1; //start--------//2apr2021 Game.gibbet = new Gibbet[Gibbet.MAXGIBBET]; for(int i=0;i0) { //draw the target icon...... float ss = 0.2f*(float)Math.sin((float)Game.frame/20f); RenderList.drawanimimage(game,Game.images[Game.targeticon].texture,Game.mx,Game.my,0,0.4f+ss,0.4f+ss,0,0,false,1f,Game.targeticon); } } } } } ///////////////////Method Definition/////////////// static void basemenus(Game game) { //part of core update loop if(Game.gamestate==Game.CAT_GAMESTATE_MENU) { Game.skirmish = false; Config.loaded = true; if(Game.mlclick==true || Game.frame>5) { if(Config.loaded) { Game.gamestate=Game.CAT_GAMESTATE_NEWCONTINUE; } if(Config.TESTDEBRIEF) { Game.gamestate=Game.CAT_GAMESTATE_DEBRIEF2; testdebrief(game); } //Audios.playsound(Game.audios[Resources.CAT_AUDIO_CLICK],1f); //level = Game.LEVEL1; } return; } if(Game.gamestate==Game.CAT_GAMESTATE_NEWCONTINUE) { resetgame(game); //Audios.playsound(Game.audios[Resources.CAT_AUDIO_CLICK],1f); //level = Game.LEVEL1; //newlevelframe = 200; if(Game.EDITOR) { Game.gamestate = Game.CAT_GAMESTATE_GAME; Game.map = new Map(); Program.setupeditor(game); Game.PLAYERFACTION = Unit.HUMAN; } else { Game.gamestate = Game.CAT_GAMESTATE_GUIMENUS; Game.map = new Map(); Program.setupbackdrop(game); Game.demomode = true; Game.PLAYERFACTION = Unit.HUMAN; } return; } if(Game.gamestate==Game.CAT_GAMESTATE_STARTLEVEL) { //temporary Game.gamestate = Game.CAT_GAMESTATE_GAME; } } ///////////////////Method Definition/////////////// static void handlezoom(Game game) { //handle the zoom in the game map to scale things //correctly if(Game.EDITOR) { return; } if(Game.mwheel<0) { Game.zoom -= 0.25f; } if(Game.mwheel>0) { Game.zoom += 0.25f; } Game.mwheel = 0; if(Game.zoom>4) { Game.zoom = 4; } if(Game.zoom<1) { Game.zoom = 1; } Game.zoom = 1;//27mar2021 // no more zoom.....? Game.zoomcornerx = (int)(-1f * (float)(Game.RESOLUTIONX/2)*(Game.zoom - 1)); Game.zoomcornery = (int)(-1f * (float)(Game.RESOLUTIONY/2)*(Game.zoom - 1)); } ///////////////////Method Definition/////////////// static void handleedit(Game game) { //handle editing the map in the editor if(Game.frame % 200==0) { Map.marktreepos(game); } for(int i=0;i0) { //Game.editname = "HEIGHT";//22mar2021 Game.editname = Translation.TranslateWord("HEIGHT",false);//22mar2021 if(Game.mldown) { //Map.heightmap[Game.editgridx + Game.editgridy * Map.MAXX]--; Map.pushmap(Game.editgridx * Map.GRIDW,Game.editgridy * Map.GRIDH,-1); } if(Game.mrdown) { //Map.heightmap[Game.editgridx + Game.editgridy * Map.MAXX]++; Map.pushmap(Game.editgridx * Map.GRIDW,Game.editgridy * Map.GRIDH,+1); } } if(Game.EDITMODE==Game.EDITMODE_UNIT) { if(dirn>0) { Game.editindex++; } if(dirn<0) { Game.editindex--; } if(Game.editindex<0) { Game.editindex = Game.templates.length - 1; } if(Game.editindex>Game.templates.length - 1) { Game.editindex = 0; } //Game.editname = Game.templates[Game.editindex].name + " Faction:"+Game.templates[Game.editindex].faction;//22mar2021 Game.editname = Game.templates[Game.editindex].dname() + " " + Translation.TranslateWord("Faction:",false)+Game.templates[Game.editindex].faction; if(Game.mldown) { for(int k=0;k0 && Game.units[j].faction==Game.PLAYERFACTION && Game.leftcontrolkey>0 && Game.units[j].selected>Unit.SELECTIONNONE) { if(!found) { found = true; //for(int k=0;k0 && Game.units[j].faction==Game.PLAYERFACTION && Game.units[j].groupid==i && Game.leftcontrolkey==0) { if(!found) { //for(int k=0;k1) { Game.CORNERX = (sumx / count) - Game.RESOLUTIONX/2; Game.CORNERY = (sumy / count) - Game.RESOLUTIONY/2; 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; } for(int k=0;k<10;k++) { Game.numberkeys[k]=0; } } } } if(Game.frame > Game.numberkeysframe[i]+15) { Game.numberkeys[i] = 0; } } } } ///////////////////Method Definition/////////////// static void updatestats(Game game) { //update the display statistics at the debriefing for(int i=0;i0 || Game.templates[i].prevkills>0 || Game.templates[i].prevdeaths>0) { color = RenderList.getrgb(255,255,200); if(Game.templates[i].faction!=Game.PLAYERFACTION) { color = RenderList.getrgb(255,200,200); } if(Game.templates[i].faction==Unit.NULLFACTION) { color = RenderList.getrgb(200,200,200); } iiline++; if(Game.templates[i].faction!=ofaction) { ofaction = Game.templates[i].faction; iiline++; RenderList.drawtext(game,800,yb + iiline * (Game.fonts[Resources.FONT].ptsize + factor),"----------------------------------------------------------------------------",RenderList.getrgb(200,200,200),Game.fonts[Resources.FONT].font,true); iiline++; } RenderList.drawtext(game,400,yb + iiline * (factor + Game.fonts[Resources.FONT].ptsize),Game.templates[i].dname(),color,Game.fonts[Resources.FONT].font,false); //13mar2021 RenderList.drawtext(game,700,yb + iiline * (factor + Game.fonts[Resources.FONT].ptsize),""+Translation.TranslateNumber(Game.templates[i].dispcreates),color,Game.fonts[Resources.FONT].font,false);//13mar2021 RenderList.drawtext(game,900,yb + iiline * (factor + Game.fonts[Resources.FONT].ptsize),""+Translation.TranslateNumber(Game.templates[i].dispkills),color,Game.fonts[Resources.FONT].font,false);//13mar2021 RenderList.drawtext(game,1100,yb + iiline * (factor + Game.fonts[Resources.FONT].ptsize),""+Translation.TranslateNumber(Game.templates[i].dispdeaths),color,Game.fonts[Resources.FONT].font,false);//13mar2021 updatestats(game); } } } ///////////////////Method Definition/////////////// static void update(Game game) { //core game update routine //handles all updates ////////////////////////////////// //---------------------NetworkUDP if(!NetworkUDP.Ready())//9oct2021 { NetworkUDP.InitAsServer(); } else { NetworkUDP.HandleComms(); } //---------------------NetworkUDP ////////////////////////////////// if(Game.gamestate!=Game.CAT_GAMESTATE_GAME) { Unit.NewColor(null, -1, 0); } if(Game.newtrees==null)//20sep2021 { Game.newtrees = new int[0];//24apr2021 } //start---------------//26mar2021 if(Game.selectingtime>0) { Game.selectingtime--; } //end-----------------//26mar2021 if(Game.gamestate==Game.CAT_GAMESTATE_LOGO) { drawlogo(game); return; } //END RTS // basemenus(game); if(Game.gamestate!=Game.CAT_GAMESTATE_GAME)//9oct2021 { //NetworkUDP.Exit(); // if(!NetworkUDP.Ready())//9oct2021 //{ // if(Game.LETTERBOX) // { // NetworkUDP.InitAsClient(); //} // else // { // NetworkUDP.InitAsServer(); // } //} //else // { // NetworkUDP.HandleComms(); // } } if(Game.gamestate==Game.CAT_GAMESTATE_GAME) { //network //if(!NetworkUDP.Ready())//9oct2021 //{ // if(Game.LETTERBOX) // { // NetworkUDP.InitAsClient(); // } // else // { // NetworkUDP.InitAsServer(); // } //} //else //{ // NetworkUDP.HandleComms(); //} ///////// Game.demomode = false; Map.updatepos(game); Game.CORNERX = 0;//5oct2021 Game.CORNERY = 0;//5oct2021 Game.mouseoverunitid = -1;//5oct2021 //start--------//20sep2021 if(Game.winloss!=0)//17oct2021 { Game.battlespeed = 1; } Beacon.ClickBeacon();//19oct2021 //long utime = 0; //long atime = 0; if(Config.delta>0) { //around 60 milliseconds is in here...... int nf = Config.delta / 75; if(nf<1) { nf = 1; } //this takes about.....70-90 milliseconds //on my Samsung S4 to execute.... //drawing all the bitmaps takes about 50ms. //therefore...if I can work out what is causing this to be slow...then //I can optimise it.... for(int ff=0;ff0)//16oct2021 { Game.frame++; } Beacon.UpdateBeacons();//19oct2021 //utime = System.currentTimeMillis(); //atime = System.currentTimeMillis(); Unit.updateall(game); //this is where optimisation will make the most difference.... //it is about 70 milliseconds all up that this uses per renderframe..when it executes as many times as it can to get to a certain update frame rate.... //utime+= System.currentTimeMillis() - atime; //utime-=System.currentTimeMillis(); // Tech.updateall(game);//2sep2021//20sep2021 } } if(!Game.EDITOR) { if(!Game.togglepause)//22mar2021 { if(ff==0) { //rtime = System.currentTimeMillis(); Bullet.updateall(game); Blood.updateall(game); Gibbet.updateall(game);//2apr2021 //rtime-= System.currentTimeMillis(); } Game.frame++; if((Game.frame % 10)==0)//5oct2021 moved down here { Map.correct(game); } } handlezoom(game); } } } //utime-=System.currentTimeMillis(); //Program.debugstuff(utime,0); Game.CORNERX = 0; Game.CORNERY = 0; //end----------//20sep2021 RenderList.IGNOREZOOM = false; Game.mouseoverunitid = -1; //24mar2021 //clear the screen... RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(0,0,0),0); if(RenderList.renderframe % 75==0)//14oct2021 { if(Game.groundbitmap!=null) { Game.groundbitmap.recycle(); Game.groundbitmap = null; } } if(Resources.THREADRUNNING==0)//8oct2021 { Unit.drawall(game); } if(!Game.EDITOR) { Bullet.drawall(game); Blood.drawall(game); Gibbet.drawall(game);//2apr2021 Beacon.DrawBeacons();//19oct2021 Map.drawrain(game); } if(Game.middlecanvas==null)//14sep2021 (whole block) { if(RenderList.backbuffer!=null) { Game.middlecanvas = new Canvas(RenderList.backbuffer); } } else { Game.middlecanvas.setBitmap(RenderList.backbuffer); Program.rendertocanvas(Game.middlecanvas); } RenderList.IGNOREZOOM = true; //if(Game.mldown && !Game.paused)//22mar2021 Game.TMPCORNERX = Game.CORNERX;//21apr2021 Game.TMPCORNERY = Game.CORNERY;//21apr2021 //commented out all the selection stuff to try and sync on mobile....5oct2021 if(Game.mldown && !Game.paused && !Game.togglepause)//22mar2021 { //int x = Game.smx; //int y = Game.smy; //int w = (int)Functions.abs(Game.fmx - Game.smx); //int h = (int)Functions.abs(Game.fmy - Game.smy); //if(x > Game.fmx) //{ // x = Game.fmx; //} //if(y > Game.fmy) //{ // y = Game.fmy; //} // //start---------------//26mar2021 //if(Functions.abs(w)>10 || Functions.abs(h)>10) //{ // Game.selectingtime = Game.WAITSELECTINGTIME; //} // //end-----------------//26mar2021 ////21apr2021 added diffx stuff //int mmx = (int)((float)(x - Game.RESOLUTIONX/2)/Game.zoom) + Game.CORNERX + Game.RESOLUTIONX/2; //int mmy = (int)((float)(y - Game.RESOLUTIONY/2)/Game.zoom) + Game.CORNERY + Game.RESOLUTIONY/2; //int mmw = (int)((float)w / Game.zoom); //int mmh = (int)((float)h / Game.zoom); //Unit.select(game,mmx,mmy,mmw,mmh); } //if(Game.mlclick && !Game.paused)//22mar2021 if(Game.mlclick && !Game.paused && !Game.togglepause)//22mar2021 { } //if(Game.mrclick && !Game.paused)//22mar2021 if(Game.mlclick && !Game.paused && !Game.togglepause)//22mar2021//20sep2021 changed to mlclick { //Unit.issueorder(game); //Unit.deselect(game); } if(Unit.CRPG>0)//25sep2021 { if(Game.mlclick && !Game.paused && !Game.togglepause) { //Unit.issueorder(game); } } if(!Game.togglepause)//22mar2021 { //handlegroupselection(game); } Game.CORNERX = Game.TMPCORNERX;//21apr2021 Game.CORNERY = Game.TMPCORNERY;//21apr2021 //debugstuff(utime,rtime); } else { if(Game.demomode) { RenderList.IGNOREZOOM = true;//18sep2021 if(Config.NOUPDATEINDEMOMODE==0)//18sep2021 { Map.updatepos(game); if((Game.frame % 121)==0) { Map.correct(game); Map.setonfire(1940,2580,true); } Unit.updateall(game); Tech.updateall(game);//2sep2021 Bullet.updateall(game); Blood.updateall(game); Gibbet.updateall(game);//2apr2021 //RenderList.IGNOREZOOM = true;//18sep2021 Unit.drawall(game); Bullet.drawall(game); Blood.drawall(game); Gibbet.drawall(game);//2apr2021 } Game.editkeypressed = 0; //22mar2021 } } //RenderList.uisetstart();//21sep2021 ///22sep2021 draw the middle layer..... //14oct2021 testing commenting this out.... //if(Config.hires<=0)//22sep2021 if in low res mode..... //{ // Game.QUALITY = 2; //if(Game.middlebitmap==null) //{ // Game.middlebitmap = Bitmap.createBitmap(Game.RESOLUTIONX/Game.QUALITY,Game.RESOLUTIONY/Game.QUALITY,Bitmap.Config.ARGB_8888); //} //if(Game.middlecanvas==null) //{ // Game.middlecanvas = new Canvas(Game.middlebitmap); //} //Program.rendertobackbuffer(Game.middlecanvas, Game.middlebitmap, 0, 0); //RenderList.renderi = 0; //Game.QUALITY = 1; //} if(Unit.ColorChanging==1 || Unit.ColorChanging==2) { Game.mlclick = false; Game.mldown = false; Game.mrclick = false; Game.mrdown = false; } Unit.SPELL_EXTRA1 = 0; Unit.SPELL_EXTRA2 = 0; switch(Unit.HeroColor) { case 12: Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 1; Unit.SPELL_EXTRA1 = 0; Unit.SPELL_EXTRA2 = 0; break; case 13: Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 0; Unit.SPELL_EXTRA1 = 0; Unit.SPELL_EXTRA2 = 0; break; case 8://7 Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 1; Unit.SPELL_EXTRA1 = 1; Unit.SPELL_EXTRA2 = 1; break; case 9://4 Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 1; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 1; Unit.SPELL_EXTRA1 = 1; Unit.SPELL_EXTRA2 = 1; break; case 10://5 Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 1; Unit.SPELL_EXTRA1 = 1; Unit.SPELL_EXTRA2 = 1; break; case 11://6 Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 0; Unit.SPELL_EXTRA1 = 1; Unit.SPELL_EXTRA2 = 1; break; case 7: Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 1; break; case 4: Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 1; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 1; break; case 5: Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 1; break; case 6: Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 0; break; case 0: Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 1; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 0; break; case 1: Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 1; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 0; break; case 2: Unit.SPELL_LIGHTNING = 0; Unit.SPELL_ALTSHIELD = 1; Unit.SPELL_ALTAURA = 1; Unit.SPELL_AURA = 0; Unit.SPELL_SHIELD = 0; Unit.SPELL_ALTLIGHTNING = 1; break; case 3: Unit.SPELL_LIGHTNING = 1; Unit.SPELL_ALTSHIELD = 0; Unit.SPELL_ALTAURA = 0; Unit.SPELL_AURA = 1; Unit.SPELL_SHIELD = 1; Unit.SPELL_ALTLIGHTNING = 0; break; } handleboard(); //start----------//8oct2021 Game.campaignpcclick = false;//8oct2021 int omode = Game.campaignmode; if(Game.campaignmode>0 && Game.campaignmode0) { Game.campaignpcclick = true; Game.campaignpcx = Functions.rand(0,10000) % Game.RESOLUTIONX; Game.campaignpcy = Functions.rand(0,10000) % Game.RESOLUTIONY; } else { Game.campaignmode++; Game.campaignmode%=(Game.MaxArmies + 1); if(Game.campaignmode==Game.MaxArmies) { CampaignMap.EndTurn(); } if(Game.campaignmode==0){Game.campaignmode++;} } } if(System.currentTimeMillis()>Game.toolongthinking) { Game.campaignmode++; Game.campaignmode%=(Game.MaxArmies + 1); if(Game.campaignmode==Game.MaxArmies) { CampaignMap.EndTurn(); } if(Game.campaignmode==0){Game.campaignmode++;} } } else { Game.toolongthinking = System.currentTimeMillis() + 4000; Game.THINKING = 0; } } if(omode!=Game.campaignmode || Game.gamestate!=Game.CAMPAIGNSTATE) { Game.toolongthinking = System.currentTimeMillis() + 4000; } //end--------//8oct2021 guimenus(game); if(Game.gamestate==Game.CAT_GAMESTATE_GAME) { if(Game.RESOLVE<=0)//7oct2021 weather stuff..... { if(Map.weather==Map.WEATHERCOLD) { RenderList.drawtext(game,Game.RESOLUTIONX - 200,Game.RESOLUTIONY - 50,"Very Cold Weather",RenderList.getrgb(24,24,32),Game.fonts[Resources.FONT].font,true); } if(Map.weather==Map.WEATHERHOT) { RenderList.drawtext(game,Game.RESOLUTIONX - 200,Game.RESOLUTIONY - 50,"Very Hot Weather",RenderList.getrgb(24,24,32),Game.fonts[Resources.FONT].font,true); } } } if(Game.gamestate==Game.CAT_GAMESTATE_DEBRIEF || Game.gamestate==Game.CAT_GAMESTATE_DEBRIEF2) { //drawdebriefbk(game);//25sep2021 Game.gamestate = Game.CAT_GAMESTATE_MENU;//25sep2021 } //if(Game.gamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false)//18apr2021 if(Game.oldgamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false)//18apr2021 { if(!Game.togglepause)//22mar2021 { Trigger.updateall(game); } if(Game.onscreen==false && Game.GAMEENDSTATE==0) { // RenderList.drawtext(game,Game.RESOLUTIONX/2,3*Game.RESOLUTIONY/4,"Double Click To Find Units",RenderList.getrgb(200,200,180),Game.fonts[Resources.FONT].font,true); } float factor = 0f; if(Game.LETTERBOX) { factor = 0.5f; } if(Game.missions!=null) //&& Game.skirmish==false) { if(Game.missionid>=0 && Game.missionid0) { //RenderList.drawtext(game,40,40 + (j * Game.fonts[Resources.SMALLFONT].ptsize * 2),"Kills:"+Game.killcount,RenderList.getrgb(200,200,180),Game.fonts[Resources.SMALLFONT].font,false);//13mar2021 RenderList.drawtext(game,40,40 + (int)(j * Game.fonts[Resources.SMALLFONT].ptsize * (2+factor)),Translation.TranslateWord("Kills",false)+":"+Translation.TranslateNumber(Game.killcount),RenderList.getrgb(200,200,180),Game.fonts[Resources.SMALLFONT].font,false);//13mar2021 } } } } } if(Game.GAMEENDSTATE!=0 && Game.gamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false) { Game.gameovertime--; Game.togglepause=false;//22mar2021 if(Game.GAMEENDSTATE==Game.GAMEENDSTATE_VICTORY) { if(Game.victorymessage) { //RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,"Victory",RenderList.getrgb(200,200,180),Game.fonts[Resources.FONT].font,true); } else { Game.gameovertime=1; } } else { //RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,"Defeat",RenderList.getrgb(200,200,180),Game.fonts[Resources.FONT].font,true); } if(Game.gameovertime==1) { Blood.clearall(game);//29oct2020 Bullet.clearall(game);//29oct2020 Gibbet.clearall(game);//2apr2021 //Map.savepath(Game.missionid); //start-------------//12mar2021 //if(Game.missionid>=0 && Game.missionid < Game.missions.length && Game.missions!=null && Game.GAMEENDSTATE==Game.GAMEENDSTATE_VICTORY && Game.skirmish==false && Game.playingtutorial==false)//4apr2021 if(Game.missionid>=0 && Game.missionid < Game.missions.length && Game.missions!=null && Game.GAMEENDSTATE==Game.GAMEENDSTATE_VICTORY && Game.skirmish==false && Game.playingtutorial==false )//4apr2021 { LocalStorage.setitem("mission"+Game.missionid,"Complete"); Unit.SaveScore(game,Game.missionid);//17sep2021 } //end---------------//12mar2021 if(Game.GAMEENDSTATE==Game.GAMEENDSTATE_DEFEAT || Game.nextmissionid==-1 || Game.skirmish==true || Game.playingtutorial==true) { Game.gamestate = Game.CAT_GAMESTATE_MENU; Game.chosenmissionindex = 0;//25sep2021 Game.skirmish = false; if(Game.GAMEENDSTATE==Game.GAMEENDSTATE_DEFEAT && Game.failedmissionid!=-1) { Game.PLAYERFACTION = Unit.HUMAN; Game.SKIRMISHENEMYFACTION = Unit.UNDEAD; Game.gamestate = Game.CAT_GAMESTATE_GAME; if(Game.missionid>=0 && Game.missionid < Game.missions.length && Game.missions!=null && Config.DODEBRIEF==true) { if(Game.missions[Game.missionid].debrief==1) { //Game.gamestate = Game.CAT_GAMESTATE_DEBRIEF;//25sep2021 //start-------------//28Feb2021 Game.PLAYERFACTION = Game.missions[Game.missionid].playerfaction; Game.SKIRMISHENEMYFACTION = Game.missions[Game.missionid].skirmishenemyfaction; //end---------------//28Feb2021 } } Game.map = new Map(); Program.setupmission(game,Game.failedmissionid,0); } else { //Game.gamestate = Game.CAT_GAMESTATE_DEBRIEF2;//25sep2021 cleardeaths(game); } } else { Game.PLAYERFACTION = Unit.HUMAN; Game.SKIRMISHENEMYFACTION = Unit.UNDEAD; Game.gamestate = Game.CAT_GAMESTATE_GAME; if(Game.missionid>=0 && Game.missionid < Game.missions.length && Game.missions!=null && Config.DODEBRIEF==true) { if(Game.missions[Game.missionid].debrief==1) { //Game.gamestate = Game.CAT_GAMESTATE_DEBRIEF;//25sep2021 //start-------------//28Feb2021 Game.PLAYERFACTION = Game.missions[Game.missionid].playerfaction; Game.SKIRMISHENEMYFACTION = Game.missions[Game.missionid].skirmishenemyfaction; //end---------------//28Feb2021 } } Game.map = new Map(); Program.setupmission(game,Game.nextmissionid,0); } } } } ///////////////////Method Definition/////////////// static void updateaudio(Game game) { //manages the audio playing for(int i=0;i=x - 40 && Game.mx<=x + 40) { if(Game.my>=y - 25 && Game.my<=y + 25) { Game.mlclick = false; Game.mldown = false; Game.audioon = !Game.audioon; updateaudio(game); //Audios.playsound(Game.audios[Resources.CAT_AUDIO_CLICK],1f); } } } } ///////////////////Method Definition/////////////// static void getmaxmission(Game game) { //get the value of the max mission in terms of locked campaign maps //currently we ignore this mostly. if(Config.KOG2) //12mar2021 { Game.maxmission = 36; } if(Game.maxmission > Game.overridemaxmission)//13sep2021 { Game.maxmission = Game.overridemaxmission;//13sep2021 } } static void getsavedcampaign(Game game) { String playerarmy = LocalStorage.getitem("PlayerArmy"); int playerindex = 1; try { playerindex = Integer.decode(LocalStorage.getitem("PlayerIndex")); } catch(Exception e) { //do nothing..... } if(!playerarmy.equals(Game.PlayerArmy)) { if(playerindex!=Game.PlayerIndex) { //Resources.LoadNewArmy(Game.FriendArmy, playerarmy); Game.OldFriendArmy = Game.FriendArmy; Game.PlayerIndex = playerindex; Game.FriendIndex = playerindex; Game.PlayerArmy = playerarmy; Game.FriendArmy = playerarmy; for(int g=0;g=0) { Game.templates[t].faction = 6; } if(Game.templates[t].name.indexOf(Game.EnemyArmy)>=0) { Game.templates[t].faction = 5; } } for(int g=0;g0)//26apr2021 { Game.VERSIONSTR = "0001"; } Config.FASTFRAMECHECK++;//14sep2021 if(Config.FASTFRAMECHECK>1)//14sep2021 { Config.FASTFRAMECHECK = 2;//14sep2021 } if(Config.FASTFRAMECHECK<1)//14sep2021 { Config.FASTFRAMECHECK = 1;//14sep2021 } switch(Config.FASTFRAMECHECK)//14sep2021 { case 1: Unit.ORDERTIME = 300; break; case 2: Unit.ORDERTIME = 100; break; } resetgame(game); if(Game.restartgamestate!=-1) { Game.gamestate = Game.restartgamestate; if(Game.gamestate!=Game.CAT_GAMESTATE_GAME)//7apr2021 { Game.map = new Map();//7apr2021 Program.setupbackdrop(game);//7apr2021 Game.demomode = true;//7apr2021 } } //end-----------------//26mar2021 //start----------//5apr2021 //end-----------//5apr2021 Config.delta = 100;//18sep2021 } ///////////////////Method Definition/////////////// static void game(int window,int renderer) { //start--------//18sep2021 Game.CORNERX = 0; Game.CORNERY = 0;//locked corner.... long ftime = System.currentTimeMillis(); if(Config.UNLOCKFRAMERATE>0) { Config.FRAMETIME = 1000 / (int)Config.UNLOCKFRAMERATE; } if(Game.FRAMERATE>0)// && deltafps>0) { if(Config.UNLOCKFRAMERATE>0) { Config.delta = (100 * Config.UNLOCKFRAMERATE) / Game.FRAMERATE; if(Config.delta < 100) { Config.delta = 100; } //if(NetworkUDP.Ready() && Game.gamestate == Game.CAT_GAMESTATE_GAME)//12oct2021 //{ // if(NetworkUDP.otherpcspeed < Game.FRAMERATE && NetworkUDP.otherpcspeed>0) // { // //other PC is slower than our framerate..... // //and is slower than the target frame rate.... // //this is ALMOST NEVER going to be the case for the mobile devices compared to a pc.... // if(Config.delta == 100) // { // Config.delta = (100 * NetworkUDP.otherpcspeed) / Game.FRAMERATE; // } // if(Config.delta<10) // { // Config.delta = 10; // } // } // //} if(Config.delta > 500) { Config.delta = 500; } } else { Config.delta = 100; } } else { Config.delta = 100; } //end-----//18sep2021 if(!Game.togglepause)//12apr2021 { if(Game.gamestate!=Game.CAT_GAMESTATE_GAME && Game.oldgamestate!=Game.CAT_GAMESTATE_GAME)//5oct2021 { Game.frame++; } } Game.formation = 0;//2apr2021 if(Game.mldown) //14apr2021 { Game.HORIZONTALFORMATION = 0; Game.VERTICALFORMATION = 0; } Game.getmouse(); Game.oldgamestate = Game.gamestate; //long utime = System.currentTimeMillis(); if(RenderList.transitionmode0) { Research.Enhance();//21oct2021 } update(game); if(cmode>0) { Research.Revert();//21oct2021 Research.UpdateResearch();//21oct2021 outside of main update loop...... } } //utime-=System.currentTimeMillis(); Game.newgamestate = Game.gamestate; //start-------------//12mar2021 if(Game.gamestate!=Game.oldgamestate) { Game.togglepause = false;//19oct2021 //if(RenderList.transitionmode<0 && Game.FULLSCREEN>0){RenderList.transitionmode = RenderList.STARTTRANSITION;}//18apr2021//19apr2021 if(RenderList.transitionmode<0){RenderList.transitionmode = RenderList.STARTTRANSITION;}//18apr2021//19apr2021 if(Game.chosenmissionindex!=-1) { Game.previousmissionindex = Game.chosenmissionindex; } //Game.chosenmissionindex = -1;//25sep2021 Unit.MAXINDEX = 0;//26mar2021 Bullet.MAXINDEX = 0;//27mar2021 try { Audios.sndpool.setVolume(Game.snd_battle_channel, 0, 0);//7oct2021 } catch(Exception e) { } } //long rtime = System.currentTimeMillis(); render(game,window); //rtime-=System.currentTimeMillis(); //debugstuff(utime,rtime); if(Game.gamestate<0) { quit = true; } ftime = System.currentTimeMillis() - ftime; if(ftime > 0) { Game.FRAMERATE = (int)((long)1000 / ftime); } else { Game.FRAMERATE = Config.UNLOCKFRAMERATE; if(Game.FRAMERATE<=0) { Game.FRAMERATE = 75; } } Game.mlclick = false;//20sep2021 Game.mrclick = false; } public static void handleboard() { if(Gui.firstunit==1) { Gui.firstunit++; if(NetworkUDP.isserver && Game.vsai<=0) { if(Map.weather==Map.WEATHERNORMAL) { NetworkUDP.communicate(NetworkUDP.MAPNORMAL, null); Map.SetUpHills();//20oct2021 } if(Map.weather==Map.WEATHERCOLD) { NetworkUDP.communicate(NetworkUDP.MAPSNOW, null); Map.SetUpHills();//20oct2021 } if(Map.weather==Map.WEATHERHOT) { NetworkUDP.communicate(NetworkUDP.MAPDESERT, null); Map.SetUpHills();//20oct2021 } } } if(Game.RESOLVE<=0) { Game.battleover = false; Game.battleovertime = 0; Unit.battlejoined = 0;//14oct2021 } if(Game.RESOLVE>0) { //Every n seconds...send another SYNC update if we are the server..... int f5 = 0; int f6 = 0; for(int i=0;i0) { if(Game.units[i].faction==5) { f5++; } if(Game.units[i].faction==6) { f6++; } if(f5>0 && f6>0) { break; } } } if(f5==0 || f6==0) { Game.winloss = 1;//17oct2021 if(Game.battleovertime==0) { Game.battleovertime = System.currentTimeMillis() + 5000; int mm = 0; for(int i=0;i0) { mm++; Game.units[i].tx = Game.RESOLUTIONX/2 - 400 + (mm % 15) * Map.GRIDW * 2; Game.units[i].ty = Game.RESOLUTIONY/2 - 250 + ((mm - (mm % 15)) / 15) * Map.GRIDH * 2; Game.units[i].tmptx = Game.units[i].tx; Game.units[i].tmpty = Game.units[i].ty; Game.units[i].tmptattempts = 0; Game.units[i].firetargeti = -1; } } } else { if(Game.battleovertimeNetworkUDP.lastsync) { NetworkUDP.lastsync = System.currentTimeMillis() + Config.SYNCTIME; NetworkUDP.communicate(NetworkUDP.SYNC, null); } if(System.currentTimeMillis()>NetworkUDP.lastspeedcheck) { NetworkUDP.lastspeedcheck = System.currentTimeMillis() + Config.SPEEDCHECKTIME; NetworkUDP.communicate(NetworkUDP.UPDATESPEED,null); } } if(Game.RESOLVE==1) { //start---------13oct2021 //13oct2021 add heroes on to map at this point...... int its = 0; int count = 0; int index = 0; //start-----------//18oct2021 if(Game.vsai>0) { //ai should try and cast a spell..... if(Functions.rand(0,1000) < 800) { Spells.SpellAction(Game.EnemyIndex,(int)Functions.abs(Functions.rand(0,1000)) % 3); } } //end-------------//18oct2021 while(Game.numfhero>0) { Game.numfhero--; //Game.units[i].createunitatxy(game, i, Game.templates[Game.units[i].templateid], x, y)) count = 0; index = 0; for(int t=0;t0) { if(Game.templates[t].name.indexOf("hero")>=0 && Game.templates[t].name.indexOf(Game.FriendArmy)>=0) { count++; } } } if(count>0) { index = 1 + (Functions.rand(0,1000) % count); for(int t=0;t0) { if(Game.templates[t].name.indexOf("hero")>=0 && Game.templates[t].name.indexOf(Game.FriendArmy)>=0) { index--; if(index<=0) { for(int i=0;i16) { break; } } its = 0; while(Game.numehero>0) { Game.numehero--; count = 0; index = 0; for(int t=0;t0) { if(Game.templates[t].name.indexOf("hero")>=0 && Game.templates[t].name.indexOf(Game.EnemyArmy)>=0) { count++; } } } if(count>0) { index = 1 + (Functions.rand(0,1000) % count); for(int t=0;t0) { if(Game.templates[t].name.indexOf("hero")>=0 && Game.templates[t].name.indexOf(Game.EnemyArmy)>=0) { index--; if(index<=0) { for(int i=0;i16) { break; } } //////////////////////// //end----------//13oct2021 Gui.firstunit = 0; //start--------//7oct2021 for(int trig=0;trig0) { ucount++; break; } } if(ucount<=0) { for(int i=0;i0) { Game.frame = 10000; //reset the game frame Game.gamestartframe = Game.frame;//reset the game frame... Functions.seed = 7573823;//reset random number seed } for(int i=0;i0) { Game.units[i].faction = Game.templates[Game.units[i].templateid].faction; if(Game.units[i].faction!=5 && Game.units[i].faction!=6) { if(Game.units[i].y < Game.RESOLUTIONY/2) { Game.units[i].faction = 5;//Red } else { Game.units[i].faction = 6;//Blue } } Game.units[i].walkspeed = Game.templates[Game.units[i].templateid].walkspeed; if(Game.units[i].walkspeed<=0) { if(Game.templates[Game.units[i].templateid].origwalkspeed>0)//7oct2021 { Game.units[i].walkspeed = Game.templates[Game.units[i].templateid].origwalkspeed;//7oct2021 } else { Game.units[i].walkspeed=2;//bug fix//6oct2021 } } Game.units[i].ai = Unit.AI_ASSAULT; if(Config.SYNCON>0) { Game.units[i].animmode = Unit.ANIMMODE_IDLE; Game.units[i].dirn = i % 8; Game.units[i].animframe = Game.units[i].animmodeidleframestart + (i % 4); if(Game.units[i].animframe > Game.units[i].animmodeidleframeend) { Game.units[i].animframe = Game.units[i].animmodeidleframestart; } } } } Game.RESOLVE = 2; } return; } if(Game.movingtime>0) { Game.movingtime--; if(Game.movingtime<=0) { for(int i=0;i0) { //remove the unit... int oldhp = Game.units[i].hp; int oldfrenzy = Game.units[i].frenzy; int oldx = Game.units[i].x; int oldy = Game.units[i].y; Game.units[i].hp=0; Map.removeunit(i, Game.units[i].x,Game.units[i].y); //then recreate it.... //in the board area..... boolean placed = false; for(int x=Game.units[i].boardx * 160;x0) { okay = false; } } if(okay) { Game.gamemode = Game.MODE_ORDER; Game.firstcell = -1; Game.secondcell = -1; Game.CELLSIDE = -1; Game.movingtime=0; } } } if(Game.battletime>0) { Game.battletime--; if(Game.battletime<=0) { for(int i=0;i0) { for(int x=Game.units[i].boardx * 160;x0) { Game.units[i].walkspeed = Game.templates[Game.units[i].templateid].walkspeed; int boardi = Game.units[i].x/160 + (Game.units[i].y/Game.BOARDY)*10; if(Game.units[i].boardi!=boardi) { Game.units[i].hp = 0; Map.removeunit(i,Game.units[i].x,Game.units[i].y); Game.units[i].reset(null,i); } if(boardi>=0 && boardi<90) { if(Game.units[i].faction==5) { faction5count[boardi]++; } if(Game.units[i].faction==6) { faction6count[boardi]++; } } else { Game.units[i].hp = 0; Map.removeunit(i,Game.units[i].x,Game.units[i].y); } } } for(int b=0;b<90;b++) { if(faction5count[b]>0 && faction6count[b]>0) { //can't share the same square.... if(faction5count[b]0 && Game.units[i].faction==5) { int boardi = Game.units[i].x/160 + (Game.units[i].y/Game.BOARDY)*10; if(b==boardi) { Game.units[i].hp=0; Map.removeunit(i,Game.units[i].x,Game.units[i].y); Game.units[i].reset(null,i); } } } } else { if(faction5count[b]==faction6count[b]) { for(int i=0;i0 && Game.units[i].faction==6) { int boardi = Game.units[i].x/160 + (Game.units[i].y/Game.BOARDY)*10; if(b==boardi) { Game.units[i].hp=0; Map.removeunit(i,Game.units[i].x,Game.units[i].y); Game.units[i].reset(null,i); } } } } } } } } } else { int faction5 = 0; int faction6 = 0; for(int i=0;i0) { if(Game.units[i].faction==5) { faction5++; } if(Game.units[i].faction==6) { faction6++; } } } if(faction5==0 || faction6==0) { Game.gamemode = Game.MODE_ORDER; Game.firstcell = -1; Game.secondcell = -1; Game.CELLSIDE = -1; Game.battletime = 0; for(int i=0;i0) { for(int x=Game.units[i].boardx * 160;x