Greetings, Here is the source code for Knights of Grumthorr(2) along with required dependency information. First of all you will need to purchase and download the game to have access to the media. Second you will need to create a folder on your pc called 'fantasyrts' Put the contents of the media folder into a folder fantasyrts/media. Create a folder called fantasyrts/sdl Copy the .cs files for the c# version of sdl2 into this folder. Download the sdl dlls as well. The sdl components you will require include sdl2, sdl2_image, sdl2_ttf and sdl2_mixer. Finally copy the two source files as found below this text into fantasyrts/ The first is fantasyrts.csproj This is a small file that contains some parameters that determine how the program compiles. The second is Program.cs. You will need a recent version of .NET (c#) to run and test and compile the program. Go to your command prompt (run->cmd) and navigate to the fantasyrts folder "cd\fantasyrts" for example. Then you can use the following: dotnet run to run the program. Or you can use dotnet publish -r win-x64 to compile the program into a release version. Before I attach the two files I will give a basic licence for you to use my code with: Licence: "You may use this Program.cs and associated source code and files as you see fit. This licence is supplied on a 'common sense' basis - in other words - use it as you would hope someone might use your own code and treat it with respect. Beyond that - go nuts with it. As a small time one man developer if I put a law-speak licence in do you really think I'm going to have the ability to enforce it?" Here are the two files: fantasyrts.csproj Exe netcoreapp3.1 true And Program.cs You can edit both of them with a simple text editor such as notepad++ or notepad.exe Have fun!/////////////////////////////////////////////////// //fantasyrts - Knights of Grumthorr 2 - Version 2.00 //Version 18-Mar-2021 - Matt Lloyd /////////////////////////////////////////////////// // //////////////////////////////// //Fantasy RTS Engine - KOG2 //Matt Lloyd 2020/2021 //'Knights of Grumthorr - 2' // //1-Oct-2020 - Bug Fix - data/data2 with 'description=' //26-Oct-2020 - Bug Fix - Count Varna 700+ times on skirmish mode in report //26-Oct-2020 - Enhancements - snow/desert mode, overrides for scenery, multiple factions possible now. //1-Nov-2020 - Enhancements - override for rgbbk //1-Nov-2020 - Enhancements - gui.txt file modified for simpler gui arrangement..less cluttered. //1-Nov-2020 - Release Version 1.0 //24-Feb-2021 - Enhancements - greater modding capability and adjustments to gui things //25-Feb-2021 - Enhancements - death animation support added, high rate of fire support added. //25-Feb-2021 - Enhancements - better mod support. //26-Feb-2021 - Enhancements relating to fog //28-Feb-2021 - Enhancements - gui link better to missions //28-Feb-2021 - Enhancements - playable faction specific to missions.... //28-Feb-2021 - Enhancements - added second idle animation //28-Feb-2021 - Enhancements - more flexible image loading //28-Feb-2021 - Enhancements - better mod support. //28-Feb-2021 - Bug Fix/Enhancements - better resource loading error handling. //1-Mar-2021 - Enhancements - allow mission choice by name rather than index as well. //2-Mar-2021 - Enhancements - map details (decor) //5-Mar-2021 - Release Version 1.1 //7-Mar-2021 - Enhancements - "extraunits=" - to add more units without changing units.txt file //7-Mar-2021 - Enhancements - new unit characteristics coded in, mob, animosity, hatred, craftsman, planar, slow, woodsman, stupidity, frenzy //7-Mar-2021 - Bug Fix with decor //9-Mar-2021 - Enhancements - formations, in-battle ui, //10-Mar-2021 - Enhancements - controllable spawners (choose what to build). //11-Mar-2021 - Enhancements to gui and AI spawners... ////////////////////////////////////////////////////////// //12-Mar-2021 - Enhancements Officially changed to Version 2.0, KoG2 - grumthorr2 as well. //12-Mar-2021 - KOG2 maxmission defaults to 36 at the beginning. //12-Mar-2021 - Planar Bug Fix - Shouldn't be able to build planar units at a builder (design decision) //12-Mar-2021 - LocalStorage.getitem, LocalStorage.setitem //12-Mar-2021 - Marked missions as complete or incomplete. //13-Mar-2021 - Enhancements - Language Localisation Features //15-Mar-2021 - Enhancements to handle Chinese text. Also shield added for defend units. And a bug fix for missing check on a -1 value for an array index (would never occur though). //15-Mar-2021 - Bug Fix - Chinese Text was being truncated - this has now been fixed with a user defined variable 'fontwmultiplier' which should be 1 or greater or left unassigned. //15-Mar-2021 - Bug Fix / Other - Removed Network commands and Bug fix for record=1 flag when quitting and thread running causing a crash.. //16-Mar-2021 - Fix for wmultiplier on Fonts. for ascii only strings. //16-Mar-2021 - Released to Steam for build verification by Valve. //17-Mar-2021 - Bug Fix for chinese Text - additional fix for wmultiplier for unicode fonts. //17-Mar-2021 - Bug fix in TranslateWord returning "" instead of the word at times. //18-Mar-2021 - Culture Info added ? //19-Mar-2021 - Enhancement - spellcasters buff friendly units now. //19-Mar-2021 - Re-Enabled Network Command //20-Mar-2021 - Enhancement - armour/attack modifier (percentage multiplier) enabled via config file. //20-Mar-2021 - Graphical Glitch fixed with Unit drawing... //21-Mar-2021 - Added +/- and unit circles //21-Mar-2021 - Enhancement - added custom scenarios via level editor to game. //21-Mar-2021 - Language Enhancement/Translation //22-Mar-2021 - Bug Fix - scaling of sprites in Gui due to comma/period difference in region settings. //22-Mar-2021 - Editor language allowed for, Selection indicator added. Pause with pause key on keyboard. //23-Mar-2021 - Minor graphical glitch fixed. Trigger enhancements. //24-Mar-2021 - Updated ALTMODE in Gui.ALTMODE to change more often. Improved Targeting. //25-Mar-2021 - Threaded music loading....Trigger *ANY, *FRIEND, *ENEMY and CREATE and REMOVE //26-Mar-2021 - Optimisation added (MAXINDEX)...to units and a few others. //27-Mar-2021 - Bug Fix.... //Important note about the Bug fix on 27-Mar-2021 //The bug was introduced on 26-Mar-2021 when 'selectingtime' was added to the code //This has now been altered so that the bug does not occur. //That means the versions of the game released prior to 26-Mar-2021 were fine //And now those released after are fine again too. //27-Mar-2021 - Disabled Zoom. Adjusted WAITSELECTINGTIME from 30 to 6. Added Bullet.MAXINDEX = 0 on change gamestate. tmpbrave added... //28-Mar-2021 - Translation Class optimised search by sorting based on length of string....(NOT IMPLEMENTED) //28-Mar-2021 - Building spells in...minimap gui enhanced/bug fix, language reporting... //30-Mar-2021 - added uid //1-apr-2021 - tidied up web request. //2-apr-2021 - enhanced some graphical features....And After Action 10 minute Replay //2-apr-2021 - Action Replay added at end of battle. (actually 3-apr, but code changes recorded as 2-Apr) /////////////////////////////////////////// //7apr2021 - fixed Editor restart //9apr2021 - new spells... //11apr2021 - fixed some minor frame+id glitches, added extra altimage handling, some saving of seeds as an attempt to fix replay (didn't work) //12-16apr2021 - various minor enhancements //17apr2021 - moved clicker and targeticon into gui section without hardcoding their presence. //17apr2021 - altered AI//hmultiplier //18apr2021 - gamestate transitions implemented....fadeout/fadein added. //19apr2021 - fixed glitch with editor trees... //20apr2021 - toggle gui panels, auto calculate offy/offx //24apr2021 - addressed spawner selection bug //25apr2021 - addressed replay bug with onscreen feature, Translation binary search (in case list gets long) //26apr2021 - enabled demo mode //28apr2021 - pathfinding quick pathing added. //2may2021 - note Matt - eventually ADD the following: Transforming Units, Flying Units including dual ground/air units and Transports. All are possible with simple changes/additions. //3may2021 Transforming units added but not tested.....Transported units added but not tested also.... //4may2021 - adding flying units.... //6may2021 - added replay MAXLENGTH back in.... //22may2021 resizable window in windowed mode..... //29may2021 - sprite rotations through directions takes time rather than instant //29may2021 - multithreaded pathfinding //2jun2021 - sprite batching in part..... //12jul2021 - bound demon code added but not tested or used yet. //28jul2021 - added deathfx code for sound effects.... //2sep2021 - minor addition - allowed shock to be specified in file instead of shocktrooper. Also allowed TITLE set in text file. //2sep2021 - tech addition (large update) (seems complete sort of).... //2sep2021 - bug fix - canflyandwalk units fixed...somewhat. transform bug fix also. transporting also works now. //4sep2021 - bug fix with transporting units. /////////////////////////////////////////// //9sep2021 - spawners can be constrained. //10sep2021 - defaultgridw/h, and mission based gridw/h, trigger for chatter image....and audio, //10sep2021 - adding individual character names to units in the armies. //12sep2021 - allow 'exit to mission name' via a trigger //13sep2021 - bug fix with dead units (if dead animation present) //14sep2021 - a few changes... //15sep2021 - need los added ////////////////////////////////// //Space Squad Began Here //16sep2021 - NOSHOWABILITY added //17sep2021 - added menu mini map feature. //18sep2021 - various additions. //19sep2021 - bug fix. ////////////////////////////////// //Everything After 20 Sep Can be Ignored If Desired. ////////////////////////////////// //27dec2021 - Added VARIABLE trigger for complex trigger arrangements. //31dec2021 - Added ability from gui to affect VARIABLE trigger data. //12feb2021 - coding test - evaluating the number of lines written on average in a 10 minute window or thereabouts. Need to therefore write some code...described below. //12feb2021 11:31am code update - "displayunitname" to allow for text as well as a number, where if it is neither 0, nor 1, then it assigns it as the name to the unit.....11:40 finished...10 minutes to write:12 lines of code. //Therefore approximately 1 minute per line of code added. Total 26,000 lines of code is equivalent to 26,000 minutes OR approximately 400+ hours of work in this file. If I were billing $150 per Hour like at work I'd be charging $60,000AUD to write this. //But that is merely the code, there's also the data files, the debugging and testing, the graphics and sound...and more. Let's take a guess and say development cost would therefore be equivalent to $100,000 to develop for a company. ////////////////////////////////// //21feb2022 and 22feb2022 various changes for conflict3048 with some bug fixes that never mattered to grumthorr. //23feb2022 and 24feb2022 various changes for conflict3048. //6mar2022 allowed EDITOR to be switched OUT OF with the TAB key //22apr2022 added Particles and Emitters using System; using System.Diagnostics; using System.Threading; using System.Net; //15mar2021 using System.IO; using System.Text;//13Mar2021//1apr2021 using System.Runtime.InteropServices; using SDL2; using System.Globalization; namespace fantasyrts { /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Config { public static int dointro = 0;//1mar2022 public static bool NonEnglishAllowed = false;//1mar2022 //start-----//28feb2022 public static int options_fog = 1; public static int options_overlay = 1; //end-------//28feb2022 public static int highseas = 0;//28feb2022 public static int CurrentMonth;//23feb2022 public static int Season;//23feb2022 public static int WINTER = 2;//24feb2022 public static int SUMMER = 1;//24feb2022 public static int useseasons;//23feb2022 public static int Night;//24feb2022 public static int DEFAULTRESX = 1600;//23sep2021 public static int DEFAULTRESY = 900;//23sep2021 public static int NOUPDATEINDEMOMODE = 0;//18sep2021 public static int USEDELTATIME = 0;//18sep2021 public static int delta;//18sep2021 public static int UNLOCKFRAMERATE = 0;//18sep2021 public static int AUTOPLAY = 0;//18sep2021 public static int NOSHOWABILITY = 0;//16sep2021 public static int OPTIMISEFIRES = 0;//15sep2021 public static int TILEFOG = 0;//15sep2021 public static int CLUMP = 0;//15sep2021 public static int NOREPLAY = 0;//15sep2021 public static int FASTFRAMECHECK = 0;//14sep2021 public static bool USETECH = true;//false;//2sep2021 public static bool THREADEDPATHING = false;//29may2021 public static bool SLOWROTATE = true;//29may2021 public static int WINDOWRESIZE = 0;//22may2021 public static bool ALLOWFLYING = true;//4may2021 //flag while debugging...will set to true later.... public static bool FREEDEMO = false; public static int freedemo = 60 * 60 * 10;//26apr2021 public static bool AUTOCALCOFFSETS = false;//20apr2021 public static uint FRAMETIME = 15;//18apr2021 public static bool BLOCKPRECALC = true;//11apr2021 public static bool ALLOWREPLAY = true;//2apr2021 public static bool GETDATA = false;//1apr2021 public static string autodetectlang = "";//30mar2021 public static string uid = "1234";//30mar2021 public static bool DEBUG = false; //23mar2021 moved up here from below... public static bool NOMETRICS = false;//remember to change this appropriately... public static bool TRANSLATEGUI = true;//21mar2021 public static bool USEICONCIRCLES = false;//21mar2021 public static bool USECOVERFLAG = false;//21mar2021 public static bool USEFEETCIRCLES = false;//21mar2021 public static int ARMOURPCT = 100;//20mar2021 public static int ATTACKPCT = 100;//20mar2021 public static int HEALTHPCT = 100;//20mar2021 public static bool useUNICODE = false; //ml15mar2021 public static bool bestiarychk = false; //5apr2021 public static bool KOG2 = true; public static bool RECORD = false; public static bool STREAMLOAD = true; //28Feb2021 public static bool STREAMLOADAUDIO = false;//25mar2021 public static int USEHEIGHTS = 0; public static bool DODEBRIEF = true; public static bool TESTDEBRIEF = false; public static bool USEPATHFILE = false; public static int FACTOR = 10; //determines size of armies and so on.....10 seems to be about sufficient for the game to run very well still with lots of units on the map. public static int NORMALSPEED = 10;//23mar2021 (not used yet...) public static int LOWSPECSPEED = 6;//23mar2021 (not used yet...) public static string configfile; //28Feb2021 public static string guifile; public static string campaignfile; public static string customcampaignfile; public static string unitsfile; public static string wordsfile = ""; //13mar2021 public static string techfile = "";//2sep2021 public static string defaultfontfile; public static int largefontsize; public static int smallfontsize; public static int normalfontsize; public static string audioclickfile; public static string offsetfile = "";//20apr2021 public static bool FINISHEDOFFSETS = false;//20apr2021 public static string logofile; public static string fogfile; public static int logowidth; public static int logoheight; public static int fogwidth; public static int fogheight; public static int hires = 0; public static string custommapfolder; public static string usercampaignfolder = ""; public static string usercampaignfile = ""; public static string custommapprefix = "custom_"; public static string skirmishmessage = "Take control of the portals to spawn units.|Eliminate the enemy."; public static int FONTALIAS = 4; public static long precalcused = 0; public static long seekpathused = 0; public static long seekpathfailed = 0; public static long seekpathsuccess = 0 ; public static long maxbmenutime = 0; public static long maxumusictime = 0; public static long maxmapupdatepostime = 0; public static long maxmapcorrecttime = 0; public static long maxmaperrors = 0; public static long maxunitupdatetime = 0; public static long maxbullettime = 0; public static long maxbloodtime = 0; public static long maxselecttime = 0; public static long maxtriggertime = 0; public static long maxdrawtime = 0; public static long maxanimate = 0; public static long maxwalk = 0; public static long maxupdate = 0; public static long maxatt = 0; public static long[] totrtime = new long[600]; public static long[] totutime = new long[600]; public static long sumr = 0; public static long sumu = 0; public static long UTIMELOW = 800; public static long RUNNINGSPEED = 0; public static long runningspeed = 0; public static bool loaded = false; public static int loadpct = 0; } /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Game { public static int LoadingPct = 0; public static string NETTITLE = "grumthorr"; public static string TITLE = "Knights of Grumthorr"; public static string AUTHOR = "Matt Lloyd"; public static string MUSIC = "Eric Matyas, soundimage.org"; public static string YEAR = "2021"; public static string VERSION = "2.00"; public static int VERSIONINT = 200; public static string VERSIONSTR = "20210603"; //14apr2021(and subsequent) // public static bool restart = false;//13mar2021 public IntPtr renderer; public IntPtr window; public IntPtr screen; public bool takepicture; //public int recordframe; public static bool running = true; //for screenshots..... //unsafe takepicture Pointer // public static bool EDITOR = false; public static int EDITED = -1; //7apr2021 public RenderList[] renderlist; public static Replay[] replay;//2apr2021 public Images[] images; public Fonts[] fonts; public Audios[] audios; //public static long killcount; //13mar2021 public static int killcount; //13mar2021 // public Map map; public Unit[] units; public Unit[] templates; public Mission[] missions; public Tech[] techs;//2sep2021 //public Mission tutorial; public int missionid; public int nextmissionid; public int failedmissionid; public Gui[] gui; public Bullet[] bullets; public Trigger[] triggers; public Blood[] blood; public Gibbet[] gibbet; //2apr2021 // // public static int neutralfog = 0; //26Feb2021 public static int fogoff = 0; //26Feb2021 // public static int topmissionindex = 0; public static int previousmissionindex = -1;//2apr2021 public static int chosenmissionindex = -1; public static int ochosenmissionindex = -1;//17sep2021 public static int maxmission = 1; public static int overridemaxmission = 0;//13sep2021 public static int countcustoms = 0; // public int SW; public int SH; //public static int SSW; //public static int SSH; public int frame; public int gamestartframe;//2apr2021 // public int mx; public int my; public int rmx;//21apr2021 public int rmy;//21apr2021 public int wmx;//21apr2021 public int wmy;//21apr2021 public static int RCORNERX;//21apr2021 public static int RCORNERY;//21apr2021 public static int TMPCORNERX;//21apr2021 public static int TMPCORNERY;//21apr2021 //public int exitmx;//2apr2021 //public int exitmy;//2apr2021 public int omx; public int omy; public int smx; public int smy; public int fmx; public int fmy; public bool mlclick; public bool mldown; //public bool exitclick;//2apr2021 //public bool exitdown;//2apr2021 public bool mrclick; public int mlclickframe; public bool mrdown; public int mwheel; public float zoom; public int zoomcornerx; public int zoomcornery; public bool paused; public int minimapframe; public bool demomode; public static int checksum;//2apr2021 public static int ordergivenframe; public static int EXTRAPATHINGTIME = 60 * 4; public static int leftcontrolkey = 0; public static int[] numberkeys = new int[10]; public static int[] numberkeysframe = new int[10]; public static bool SPAWNERSELECTED = false; //10mar2021 public static bool NONSPAWNERSELECTED = false;//11mar2021 public static int SPELLCASTERSELECTED = -1;//28mar2021 public static int SPELLCASTERLEVEL = 0;//28mar2021 public static bool SPELLSACTIVE = true;//false;//28mar2021 public static int EDITMODE_TREE = 1; public static int EDITMODE_ROCK = 2; public static int EDITMODE_WALL = 3; public static int EDITMODE_UNIT = 0; public static int EDITMODE_TRIGGER = 4; public static int EDITMODE_ENTERTEXT = 5; //from triggers.... public static int EDITMODE_HEIGHT = 6; public static int EDITMODE; public static int editgridx; public static int editgridy; public static int editindex; public static string editname; public static int editkeypressed = 0; public static int recordkeypressed = 0; public static int backupkeypressed = 0; public static string edittriggerstring = ""; public static bool editshiftheld = false; // public static int FULLSCREEN = 0; public static int FXVOLUME = 100; public static int MUSICVOLUME = 100; public static int oFXVOLUME = 100; public static int oMUSICVOLUME = 100; // public static int RESOLUTIONX; public static int RESOLUTIONY; public static int FRAMERATE; public static bool NODELAY = true; // public static int CORNERX = 0; public static int CORNERY = 0; public static int CORNERSPEED = 5; public static int CORNEREDGEDIST = 50; public static int LOCKCORNER = 0; public static int HORIZONTALFORMATION = 0; //14apr2021 public static int VERTICALFORMATION = 0; //14apr2021 // // public int gamestate; public int oldgamestate; public int newgamestate; public static int restartgamestate; //26mar2021 public static int selectingtime;//26mar2021 public static int WAITSELECTINGTIME = 6;//26mar2021 //public static int transitionframe; //public static int TRANSITIONTIME = 30; public bool playerready; public bool skirmish; public bool onscreen; public bool victorymessage; public bool playingtutorial; public static int CAT_GAMESTATE_INTRO = 4;//28feb2022 public static int CAT_GAMESTATE_LOGO = 0; public static int CAT_GAMESTATE_OUTRO = 5;//28feb2022 public static int CAT_GAMESTATE_OUTROBAD = 6;//28feb2022 public static int CAT_GAMESTATE_CREDITS2 = 7;//28feb2022 public static int CAT_GAMESTATE_MENU = 10; public static int CAT_GAMESTATE_NEWCONTINUE = 20; public static int CAT_GAMESTATE_GAME = 1000; public static int CAT_GAMESTATE_DEBRIEF = 999; public static int CAT_GAMESTATE_DEBRIEF2 = 998; public static int CAT_GAMESTATE_REPLAY = 997; //2apr2021 public static int CAT_GAMESTATE_MATCH_PLAY = 1000; public static int CAT_GAMESTATE_STARTLEVEL = 1050; public static int CAT_GAMESTATE_GAMEOVER = 1100; public static int CAT_GAMESTATE_NEWLEVEL = 1200; public static int CAT_GAMESTATE_ENDLEVEL = 1300; public static int CAT_GAMESTATE_GUIMENUS = 10000; // public static int PLAYERFACTION = 0; public static int SKIRMISHENEMYFACTION = 0; public static int EDITORPFACTION = 0; //22mar2021 public static int EDITOREFACTION = 0; //22mar2021 public static int GAMEENDSTATE = 0; public static int GAMEENDSTATE_VICTORY = 1; public static int GAMEENDSTATE_DEFEAT = 2; public static int EXITPRESSED = 0;//1mar2022 public static int MAXFACTIONS = 16; // public int gameovertime; //public int nextleveltime; // public static int MissionScore = 0;//1mar2022 public static int TopScore = 0;//1mar2022 public static int quoteindex = 0;//1mar2022 public static int outroframe = 0;//28feb2022 public static int outrodelay = 0;//28feb2022 public static int healthbar = -1; public static int whiteflag = -1; public static int highseas_hi = -1;//28feb2022 public static int highseas_lo = -1;//28feb2022 public static int shadowup = -1;//15sep2021 public static int shadowleft = -1;//15sep2021 public static int shadowright = -1;//15sep2021 public static int shadowoffy = -1;//15sep2021 public static int shadowoffx = -1;//15sep2021 public static int shield = -1; //15mar2021 public static int lightning = -1;//28mar2021 public static int whirlwind = -1;//28mar2021 public static int targeticon = -1;//16apr2021 public static int spellball = -1;//12apr2021 public static int clicker = -1;//15apr2021 public static int clickerframe = -1;//15apr2021 public static int clickerrow = 0;//15apr2021 public static int clickerx = 0;//15apr2021 public static int clickery = 0;//15apr2021 public static int BLUEBALL = 0; public static int GREENBALL = 1; public static int PURPLEBALL = 2; public static int ORANGEBALL = 3; public static int REDBALL = 4; public static bool audioon; public static int iconplus = -1;//21mar2021 public static int iconminus = -1;//21mar2021 public static int iconcircles = -1;//21mar2021 public static int groupselected = -1;//21mar2021 public static bool showingselectedicons = false; //22mar2021 public static bool togglepause = false;//22mar2021 public static int mouseoverunitid = -1; public static bool anyselected = false;//16apr2021 public static int formation = 0;//2apr2021 public static int ai_direction = 0;//17apr2021 public static int[] newtrees;//24apr2021 public static int totalscore = 0;//18sep2021 public static int maxtotalscore = 0;//18sep2021 public static bool scoredirty = true;//18sep2021 // ///////////////////Method Definition/////////////// public static void DisplayQuote(Game game)//1mar2022 { string txt = ""; string[] quotes = new string[10]; for(int i=0;i999) { LoadingPct = 999; } if(LoadingPct<0) { LoadingPct = 0; } SDL.SDL_Event e; SDL.SDL_Delay(1); while(SDL.SDL_PollEvent(out e) != 0) { SDL.SDL_Delay(1);// } RenderList.transitionmode = -1; //RenderList.drawanimimage(game,game.images[Resources.LoadingBack].texture,800,450,0,1,1,0,0,false,1,Resources.LoadingBack); RenderList.drawrect(game,10,880,(1580 * LoadingPct) / 1000,16,RenderList.getrgb(40,255,255),0); RenderList.drawunfilledrect(game,10,880,1580,16,RenderList.getrgb(120,120,120),0); if(game.fonts.Length>0) { if(Resources.FONT>=0 && Resources.FONT0)//17sep2021 if(units[i].animmodedeadframeend>0 && gb <= (Gibbet.GIBMOD + 1)/2)//17sep2021 { units[i].animmode = Unit.ANIMMODE_DEAD; return; } else//2apr2021 { Gibbet.GIBCOUNTER++; if((Gibbet.GIBCOUNTER % Gibbet.GIBMOD)==0) { Gibbet.makegibbets(game,i); gibbets = true; } } } else { if(units[i].animframe < units[i].animmodedeadframeend) { return; } } //end-------------//25Feb2021 units[i].playdeathsound(game,i); //28jul2021 Map.addbones(units[i].x,units[i].y); game.templates[units[i].templateid].deaths++; Map.removeunit(i,units[i].x,units[i].y); if(units[i].faction!=6)//1mar2022 { Game.MissionScore+=units[i].basehp + units[i].damage + units[i].armour;//1mar2022 } if(units[i].deathanim!=null && units[i].infected<=0)//22apr2022 added infected { if(units[i].deathanim!="") { for(int t=0;t0) { for(int j=0;j<4;j++) { Blood.makeblood(game,units[i].x+(int)Functions.rand(-Map.GRIDW/2,Map.GRIDW/2),units[i].y+units[i].offy+(int)Functions.rand(-Map.GRIDH/2,Map.GRIDH/2),0); } } } Game.killcount++; } private void initgame() { } ///////////////////Method Definition/////////////// public void quit() { //////////////////////// //finalisation of the game upon exiting the main loop //handles removing all textures and sounds Game.running = false; Emitter.pimages = null;//12apr2022/bug fix try//13mar2021 added try catch { for(int i=0;i0 && SW>0) { float gxscale = (float)Game.RESOLUTIONX/ (float)SW; float gyscale = (float)Game.RESOLUTIONY/ (float)SH; mx = (int)((float)mx*gxscale); my = (int)((float)my*gyscale); //exitmx = mx; //2apr2021 //exitmy = my; //2apr2021 rmx = mx; //21apr2021 rmy = my; //21apr2021 wmx = mx; //21apr2021 wmy = my; //21apr2021 } if(mldown==false) { smx = mx; smy = my; } else { fmx = mx; fmy = my; } //if(!Replay.PLAYBACK) //{ // exitclick = false; // exitdown = false; //} } } // //start-------------//28Feb2021 /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class StreamResources { public static int TOLERANCE = 60 * 5; public static int SHORTTOLERANCE = 60 * 5; public static int LONGTOLERANCE = 60 * 60; public static int STARTTOLERANCE = 60 * 15; //public static bool threadrunning = false;//25mar2021//24feb2022 //public static Audios audio = null;//24feb2022 ///////////////////Method Definition/////////////// public static void streamloadhelper(Game game) { //////////////////////// //handles loading of resources during the game //and also freeing the resources //manages them so that we do not hog memory with //graphics that are unecessarily being kept when not in use for long periods if(!Config.STREAMLOAD) { return; } //start------------//25mar2021 //24feb2022 commented out this audio part //if(threadrunning==false && Config.STREAMLOADAUDIO==true) //{ // for(int i=0;i TOLERANCE)// && game.frame > STARTTOLERANCE) { //if(game.gamestate!=Game.CAT_GAMESTATE_GAME)//2apr2021 if(game.gamestate!=Game.CAT_GAMESTATE_GAME && game.gamestate!=Game.CAT_GAMESTATE_REPLAY)//2apr2021 { Resources.FreeImage(game,i); } } else { if(game.images[i].loaded == false && game.images[i].texture==IntPtr.Zero && (game.images[i].okloaded==true || game.images[i].neverloaded==true)) { if(Config.useseasons>0 && Config.Night>0) { /////start---------//24feb2022 //check if the nighttime file version exists.... //if it does - use it..... string sfile = game.images[i].file; int index = sfile.Length - 1; while(index>=0) { if(sfile.Substring(index,1) == "/") { break; } index--; } if(index>=0) { string prefix = sfile.Substring(0,index + 1); string suffix = sfile.Substring(index + 1,sfile.Length - (index + 1)); string nightfile = prefix + "night_" + suffix; if(File.Exists(nightfile)) { //file = nightfile; game.images[i].texture = SDL_image.IMG_LoadTexture(game.renderer,nightfile); if(game.images[i].texture!=IntPtr.Zero) { game.images[i].loaded = true; game.images[i].okloaded = true; game.images[i].neverloaded = false; LocalStorage.setitem("FILE LOAD:"+nightfile,"LOADED");//24mar2021 imgloaded = true;//25apr2022 } else //24mar2021 { LocalStorage.setitem("FILE LOAD:"+nightfile,"FAILED TO LOAD");//24mar2021 } } else { game.images[i].texture = SDL_image.IMG_LoadTexture(game.renderer,game.images[i].file); if(game.images[i].texture!=IntPtr.Zero) { game.images[i].loaded = true; game.images[i].okloaded = true; game.images[i].neverloaded = false; LocalStorage.setitem("FILE LOAD:"+game.images[i].file,"LOADED");//24mar2021 imgloaded = true;//25apr2022 } else //24mar2021 { LocalStorage.setitem("FILE LOAD:"+game.images[i].file,"FAILED TO LOAD");//24mar2021 } } } ////end------------//24feb2022 } else//24feb2022 { game.images[i].texture = SDL_image.IMG_LoadTexture(game.renderer,game.images[i].file); if(game.images[i].texture!=IntPtr.Zero) { game.images[i].loaded = true; game.images[i].okloaded = true; game.images[i].neverloaded = false; LocalStorage.setitem("FILE LOAD:"+game.images[i].file,"LOADED");//24mar2021 imgloaded = true;//25apr2022 } else //24mar2021 { LocalStorage.setitem("FILE LOAD:"+game.images[i].file,"FAILED TO LOAD");//24mar2021 } } } } } } //24feb2022 commented out //private static void ThreadFunction() //{ // if(audio.file!="" && audio.file!=null)//28Feb2021 //{ // audio.audio = SDL_mixer.Mix_LoadMUS(audio.file); //} //if(audio.audio==IntPtr.Zero) //{ // Console.WriteLine("Could Not Load Music:"+audio.file+". Error:"+SDL.SDL_GetError()); //Network.reporterror("MusicLoadFailure:"+audio.file,false);//15mar2021 //LocalStorage.setitem("FILE LOAD:"+audio.file,"FAILED TO LOAD"); //24mar2021 //} //else //24mar2021 //{ // LocalStorage.setitem("FILE LOAD:"+audio.file,"LOADED"); //24mar2021 //} //threadrunning = false; //} } //end---------------//28Feb2021 /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Resources { // //put all resource names in here..... public static int LOGO = 0; public static int FONT = 0; public static int SMALLFONT = 0; public static int LARGEFONT = 0; public static int FOG = 0; public static int CLICK = 0; public static int blackcat = -1; public static int outro = -1;//28feb2022 public static int intro = -1;//1mar2022 public static int outrobad = -1;//28feb2022 public static int credits = -1;//28feb2022 public static int page01 = -1;//28feb2022 //public static int loadingbk = -1; //27mar2021 //public static int loadingbar = -1;//27mar2021 //temporarily do this //start-------------//28Feb2021 ///////////////////Method Definition/////////////// public static bool readbool(string data) { //////////////////////// //takes a string that contains 'true' or 'false' and returns a bool value //string is form left identifier=right value //swapped if statements around 12sep2021 if(data.Substring(data.IndexOf("=") + 1)=="false")//this was below the other if block earlier//12sep2021 { return false; } else { if(data.Substring(data.IndexOf("=") + 1)=="true") { return true; } } int i; Int32.TryParse(data.Substring(data.IndexOf("=") + 1),out i); if(i<=0) { return false; } else { if(i>0) { return true; } } return false; //have to return something by default...so make it false by default.... } //end---------------//28Feb2021 ///////////////////Method Definition/////////////// public static uint readuint(string data)//2apr2021 { uint i; UInt32.TryParse(data.Substring(data.IndexOf("=")+1),out i); return i; } ///////////////////Method Definition/////////////// public static int readint(string data) { //takes a string that contains an int, with no commas or period symbols //and converts to an integer. //string is of form left identifier=right value int i; Int32.TryParse(data.Substring(data.IndexOf("=") + 1),out i); return i; } ///////////////////Method Definition/////////////// public static float readfloat(string data) { //takes a string in 100.01 format (ie one hundred point oh-one) //and returns the float value //string is of form left identifier=right value float i; try { System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint; //22mar2021 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); //22mar2021 if(!Single.TryParse(data.Substring(data.IndexOf("=") + 1),style,culture,out i)) //22mar2021 { if(data.IndexOf("-")>=0) { if(!Single.TryParse(data.Substring(data.IndexOf("=") + 2),style,culture,out i)) //22mar2021 { Console.WriteLine("Error reading float:"+data); i = 1.0f; LocalStorage.setitem("READ FLOAT:"+readstring(data),"FAILED 1");//24mar2021 } else { i*=-1f; LocalStorage.setitem("READ FLOAT:"+readstring(data),"SUCCESS");//24mar2021 } } else { Console.WriteLine("Error reading float:"+data); i = 1.0f; LocalStorage.setitem("READ FLOAT:"+readstring(data),"FAILED 1");//24mar2021 } } else { LocalStorage.setitem("READ FLOAT:"+readstring(data),"SUCCESS");//24mar2021 } } catch(Exception e) { i = 1f; Console.WriteLine("Error reading float:"+e.Message); LocalStorage.setitem("READ FLOAT:"+readstring(data),"FAILED 2");//24mar2021 } return i; } ///////////////////Method Definition/////////////// public static string readstring(string data) { //simply returns a string from a line that looks like x=abc //ie left identifier=right value return data.Substring(data.IndexOf("=") + 1); } ///////////////////Method Definition/////////////// public static void AssignOffsets(Game game,string file)//20apr2021 { if(file=="") { return; } try { string[] data = System.IO.File.ReadAllLines(file); for(int i=0;i0) { game.gui = new Gui[count]; int id = -1; int cw = 0; int ch = 0; int nw = 0; int nh = 0; int fontsize = 0; string fontfile = ""; for(int i=0;i4) { continue; } game.gui[id].altimagefile[alti] = readstring(data[i]); bool found = false; for(int j=0;j0) { game.gui[id].font = Resources.LoadFont(game,fontfile,fontsize); } } fontfile = ""; fontsize = 0; break; } } } } LocalStorage.setitem("FILE LOAD:"+file,"SUCCESS");//24mar2021 } catch(Exception e) { Console.WriteLine("403:"+e.Message); LocalStorage.setitem("FILE LOAD:"+file,"FAILED");//24mar2021 } } ///////////////////Method Definition/////////////// public static string[] processextraunits() //7mar2021 { //////////////////////// //in the config files we can have multiple lines indicating //multiple files for creatures and so forth //this method handles getting this data before we create all our //templates in LoadTemplates string[] data = new string[0]; try { string[] config = System.IO.File.ReadAllLines(Config.configfile); for(int i=0;i0) { int ii = data.Length; Array.Resize(ref data,data.Length + data2.Length); for(int j=0;j0) { game.techs = new Tech[count]; int id = -1; for(int i=0;i0) { int ii = data.Length; Array.Resize(ref data,data.Length + data2.Length); for(int i=0;i0) { game.templates = new Unit[count]; int id = -1; int cw = 0; int ch = 0; int nw = 0; int nh = 0; for(int i=0;i0) { game.templates[id].transportarray = new int[game.templates[id].transportcapacity]; } break; case "transportsize": game.templates[id].transportsize = readint(data[i]); break; //end----------------//3may2021 //start--------------//9apr2021 case "magicsummoner": game.templates[id].magiczombiemaster = readint(data[i]); if(game.templates[id].magiczombiemaster>0) { game.templates[id].magiczombiemaster = Unit.MAGICZOMBIEMASTER; } break; case "magiczombiemaster"://redundant version alias game.templates[id].magiczombiemaster = readint(data[i]); if(game.templates[id].magiczombiemaster>0) { game.templates[id].magiczombiemaster = Unit.MAGICZOMBIEMASTER; } break; case "magicleader": game.templates[id].magicleader = readint(data[i]); if(game.templates[id].magicleader>0) { game.templates[id].magicleader = Unit.MAGICLEADER; } break; //end----------------//9apr2021 case "magicfrenzy": game.templates[id].magicfrenzy = readint(data[i]); if(game.templates[id].magicfrenzy>0) { game.templates[id].magicfrenzy = Unit.MAGICFRENZY; } break; case "magicdoom": game.templates[id].magicdoom = readint(data[i]); if(game.templates[id].magicdoom>0) { game.templates[id].magicdoom = Unit.MAGICDOOM; } break; case "magicdefense": game.templates[id].magicdef = readint(data[i]); if(game.templates[id].magicdef>0) { game.templates[id].magicdef = Unit.MAGICDEF; } break; case "magicdef": //redundancy game.templates[id].magicdef = readint(data[i]); if(game.templates[id].magicdef>0) { game.templates[id].magicdef = Unit.MAGICDEF; } break; //end-------------//01apr2021 //start---------------//28mar2021 case "magicweb": game.templates[id].magicweb = readint(data[i]); if(game.templates[id].magicweb>0) { game.templates[id].magicweb = Unit.MAGICWEB; } break; case "magicgas": game.templates[id].magicgas = readint(data[i]); if(game.templates[id].magicgas>0) { game.templates[id].magicgas = Unit.MAGICGAS; } break; case "magichaste": game.templates[id].magichaste = readint(data[i]); if(game.templates[id].magichaste>0) { game.templates[id].magichaste = Unit.MAGICHASTE; } break; case "magicfear": game.templates[id].magicfear = readint(data[i]); if(game.templates[id].magicfear>0) { game.templates[id].magicfear = Unit.MAGICFEAR; } break; case "magicshield": game.templates[id].magicshield = readint(data[i]); if(game.templates[id].magicshield>0) { game.templates[id].magicshield = Unit.MAGICSHIELD; } break; case "magicstorm": game.templates[id].magicstorm = readint(data[i]); if(game.templates[id].magicstorm>0) { game.templates[id].magicstorm = Unit.MAGICSTORM; } break; case "magicsword": game.templates[id].magicsword = readint(data[i]); if(game.templates[id].magicsword>0) { game.templates[id].magicsword = Unit.MAGICSWORD; } break; case "magicstealth": game.templates[id].magicstealth = readint(data[i]); if(game.templates[id].magicstealth>0) { game.templates[id].magicstealth = Unit.MAGICSTEALTH; } break; case "magicplant": game.templates[id].magicplant = readint(data[i]); if(game.templates[id].magicplant>0) { game.templates[id].magicplant = Unit.MAGICPLANT; } break; case "magicwind": game.templates[id].magicwind = readint(data[i]); if(game.templates[id].magicwind>0) { game.templates[id].magicwind = Unit.MAGICWIND; } break; //end-----------------//28mar2021 case "highfirerate": //25Feb2021 game.templates[id].highfirerate = readint(data[i]); break; //start-------------//7mar2021 case "mob": game.templates[id].mob = readint(data[i]); break; case "hatred": game.templates[id].hatred = readint(data[i]); break; case "craftsman": game.templates[id].craftsman = readint(data[i]); break; case "dieonplace"://21feb2022 game.templates[id].dieonplace = readint(data[i]); break; case "deathanim"://21feb2022 game.templates[id].deathanim = readstring(data[i]); break; case "planar": game.templates[id].planar = readint(data[i]); break; case "slow": game.templates[id].slow = readint(data[i]); break; case "woodsman": game.templates[id].woodsman = readint(data[i]); break; case "stupid": game.templates[id].stupid = readint(data[i]); break; case "frenzy": game.templates[id].frenzy = readint(data[i]); break; //end---------------//7mar2021 case "shocktroops": game.templates[id].shock = readint(data[i]); break; case "shock": //2sep2021 game.templates[id].shock = readint(data[i]);//2sep2021 break;//2sep2021 case "stealth": game.templates[id].stealth = readint(data[i]); break; case "accuracy"://28feb2022 game.templates[id].accuracy = readint(data[i]); break; case "damagex": game.templates[id].damagex = readint(data[i]); break; case "fearsome": game.templates[id].fearsome = readint(data[i]); break; case "leader": game.templates[id].leader = readint(data[i]); break; case "scale"://25sep2021 game.templates[id].scale = readfloat(data[i]); break; case "bounddemon"://12jul2021 game.templates[id].bounddemon = readint(data[i]); break; case "spawner": game.templates[id].spawner = readstring(data[i]); game.templates[id].spawnerconstraint = "*"; break; case "spawnerconstraint": //9sep2021 game.templates[id].spawnerconstraint = readstring(data[i]); break; case "spawnercount": game.templates[id].spawnercount = readint(data[i]); break; case "spawnertime": game.templates[id].spawnertime = readint(data[i]); break; case "bossmonster": game.templates[id].bossmonster = readint(data[i]); break; case "flammable": game.templates[id].flammable = readint(data[i]); break; case "regeneration": game.templates[id].regeneration = readint(data[i]); break; case "zombie": game.templates[id].zombie = readint(data[i]); break; case "evilfire": game.templates[id].firespell = - readint(data[i]); break; case "sacrificial": game.templates[id].sacrificial = readint(data[i]); break; case "cansacrifice": game.templates[id].cansacrifice = readint(data[i]); break; case "animosity": game.templates[id].animosity = readint(data[i]); break; //start-----------//25Feb2021 case "deadframestart": game.templates[id].animmodedeadframestart = readint(data[i]); break; case "deadframeend": game.templates[id].animmodedeadframeend = readint(data[i]); break; //end-------------//25Feb2021 //start-------------//28Feb2021 case "idle2framestart": game.templates[id].animmodeidle2framestart = readint(data[i]); break; case "idle2frameend": game.templates[id].animmodeidle2frameend = readint(data[i]); break; //end---------------//28Feb2021 case "idleframestart": game.templates[id].animmodeidleframestart = readint(data[i]); break; case "idleframeend": game.templates[id].animmodeidleframeend = readint(data[i]); break; case "walkframestart": game.templates[id].animmodewalkframestart = readint(data[i]); break; case "walkframeend": game.templates[id].animmodewalkframeend = readint(data[i]); break; //2sep2021 bug fix case "flyframestart": game.templates[id].animmodeflyframestart = readint(data[i]); break; case "flyframeend": game.templates[id].animmodeflyframeend = readint(data[i]); break; //end 2sep2021 case "att1framestart": game.templates[id].animmodeattframestart = readint(data[i]); break; case "att1frameend": game.templates[id].animmodeattframeend = readint(data[i]); break; case "att2framestart": game.templates[id].animmodeatt2framestart = readint(data[i]); break; case "att2frameend": game.templates[id].animmodeatt2frameend = readint(data[i]); break; case "walkspeed": game.templates[id].walkspeed = readint(data[i]); break; case "animspeed": game.templates[id].animspeed = (5 * readint(data[i])) / 4;//29sep2021 break; case "targetfx": for(int a=0;a0)//23feb2022 { //hardcoded crap... if(Config.Season==Config.SUMMER) { //seasonalground = readstring(data[i].Substring(0,readstring(data[i]).IndexOf(".") )) + "desert" + readstring(data[i].Substring(readstring(data[i]).IndexOf("."),4)); seasonalground = "media/environment/grounddesert.png"; } if(Config.Season==Config.WINTER) { //seasonalground = readstring(data[i].Substring(0,readstring(data[i]).IndexOf(".") )) + "snow" + readstring(data[i].Substring(readstring(data[i]).IndexOf(".") ,4)); seasonalground = "media/environment/groundsnow.png"; } } Map.tilecat = Resources.LoadAnimImage(game,seasonalground,game.renderer,cw,ch,nw,nh);//23feb2022 Map.tileframes = nw * nh; break; case "environment_trees": Map.treecat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); Map.treeframes = nw * nh; Map.treeoffsety = offy; break; //start--------------//2mar2021 case "environment_decor": Map.decorcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); Map.decorframes = nw * nh; Map.decoroffsety = offy; break; //end----------------//2mar2021 case "environment_rocks": Map.rockcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); Map.rockframes = nw * nh; Map.rockoffsety = offy; break; case "environment_walls": Map.wallcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); Map.wallframes = nw * nh; Map.walloffsety = offy; break; case "environment_fire": Map.firecat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); Map.fireframes = nw * nh; break; case "mission": countmissions++; break; } } } if(countmissions>0 || countcustoms>0) { game.missions = new Mission[countmissions+countcustoms]; Game.overridemaxmission = countmissions;//13sep2021 int countobjectives = 0; int objective = -1; for(int i=0;i0) { game.missions[id].units = new Unit[countunits]; unitid = -1; } if(countobjectives>0) { game.missions[id].objectives = new string[countobjectives]; } Game.LoadingProgress(game); break; //26oct2020 start case "cw": cw = readint(data[i]); break; case "ch": ch = readint(data[i]); break; case "nw": nw = readint(data[i]); break; case "nh": nh = readint(data[i]); break; case "offy": offy = readint(data[i]); break; //start-----------------//10sep2021 case "gridw": game.missions[id].gridw = readint(data[i]); break; case "gridh": game.missions[id].gridh = readint(data[i]); break; //end-------------------//10sep2021 //start-----------------//21feb2022 case "overlayimage": cw = game.missions[id].gridw * Map.MAXX; ch = game.missions[id].gridh * Map.MAXY; game.missions[id].overlayimage = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,1,1); break; case "overlaysnow"://4mar2022 cw = game.missions[id].gridw * Map.MAXX; ch = game.missions[id].gridh * Map.MAXY; game.missions[id].overlaysnow = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,1,1); break; //end-------------------//21feb2022 //1nov2020 start case "override_bk_red": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_r = readint(data[i]); break; case "override_bk_green": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_g = readint(data[i]); break; case "override_bk_blue": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_b = readint(data[i]); break; //1nov2020 end case "override_ground": game.missions[id].tilecat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); game.missions[id].tileframes = nw * nh; if(readstring(data[i]).IndexOf("snow")>0) { game.missions[id].issnow = true; } if(readstring(data[i]).IndexOf("desert")>0) { game.missions[id].isdesert = true; } break; //start--------------//2mar2021 case "override_decor": game.missions[id].decorcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); game.missions[id].decorframes = nw * nh; game.missions[id].decoroffsety = offy; break; //end----------------//2mar2021 case "override_trees": game.missions[id].treecat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); game.missions[id].treeframes = nw * nh; game.missions[id].treeoffsety = offy; break; case "override_rocks": game.missions[id].rockcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); game.missions[id].rockframes = nw * nh; game.missions[id].rockoffsety = offy; break; case "override_walls": game.missions[id].wallcat = Resources.LoadAnimImage(game,readstring(data[i]),game.renderer,cw,ch,nw,nh); game.missions[id].wallframes = nw * nh; game.missions[id].walloffsety = offy; break; //26oct2020 end case "nextmissionid": game.missions[id].nextmissionid = readint(data[i]); break; case "debrief": game.missions[id].debrief = readint(data[i]); break; case "failedmissionid": game.missions[id].failedmissionid = readint(data[i]); break; case "floorpattern"://16sep2021 game.missions[id].floorpattern = readint(data[i]); break; //start--------------//1mar2021 case "nextmissionname": game.missions[id].nextmissionname = readstring(data[i]); break; case "failedmissionname": game.missions[id].failedmissionname = readstring(data[i]); break; case "indoor"://23sep2021 game.missions[id].indoor = readint(data[i]); break; //end----------------//1mar2021 case "demo": game.missions[id].demo = readint(data[i]); break; case "flavourtext"://18sep2021 game.missions[id].flavourtext = readstring(data[i]); break; //start-----------//26Feb2021 case "fogoff": game.missions[id].fogoff = readint(data[i]); break; case "neutralfog": game.missions[id].neutralfog = readint(data[i]); break; //end-------------//26Feb2021 //start-------------//28Feb2021 case "playerfaction": game.missions[id].playerfaction = readint(data[i]); break; case "enemyfaction": game.missions[id].skirmishenemyfaction = readint(data[i]); break; case "unlocked": game.missions[id].alwaysunlocked = readint(data[i]); break; //end---------------//28Feb2021 //start--------------//1mar2021 case "lockcorner": game.missions[id].lockcorner = readint(data[i]); break; //end----------------//1mar2021 case "corner": string[] tmpcorner = readstring(data[i]).Split(","); if(tmpcorner.Length==2) { Int32.TryParse(tmpcorner[0],out game.missions[id].cornerx); Int32.TryParse(tmpcorner[1],out game.missions[id].cornery); } break; case "seed": game.missions[id].seed = readint(data[i]); break; case "skirmish": game.missions[id].skirmish = readint(data[i]); break; case "description": if(game.missions[id].description[0] == "") { game.missions[id].description[0] = readstring(data[i]); } else { if(game.missions[id].description[1] == "") { game.missions[id].description[1] = readstring(data[i]); } else { game.missions[id].description[2] = readstring(data[i]); } } break; case "mapgen": game.missions[id].mapgen = 1; break; case "ai": game.missions[id].ai = readint(data[i]); break; case "istutorial": game.missions[id].istutorial = readint(data[i]); break; case "toomanytrees": toomanytrees=1; break; case "toomanyrocks": toomanyrocks=1; break; case "toomanywalls": toomanywalls = 1; break; //start--------------//2mar2021 case "decor": if(id>=0) { string[] tmpdecor = readstring(data[i]).Split(","); game.missions[id].decorimage = new int[tmpdecor.Length]; for(int j=0;j=0) { string[] tmptrees = readstring(data[i]).Split(","); game.missions[id].treeimage = new int[tmptrees.Length]; for(int j=0;j0) { if(j % 3<2) { continue; } } game.missions[id].treeimage[j] = tt; } } break; case "walls": if(id>=0) { string[] tmpwalls = readstring(data[i]).Split(","); game.missions[id].wallimage = new int[tmpwalls.Length]; for(int j=0;j0) { continue; } } game.missions[id].wallimage[j] = tt; } } break; case "rocks": if(id>=0) { string[] tmprocks = readstring(data[i]).Split(","); game.missions[id].rockimage = new int[tmprocks.Length]; for(int j=0;j0) { if(j % 3<2) { continue; } } game.missions[id].rockimage[j] = tt; } } break; case "setfire": if(id>=0) { string[] tmpfire = readstring(data[i]).Split(","); if(tmpfire.Length==2) { game.missions[id].campfirex = -1; game.missions[id].campfirey = -1; Int32.TryParse(tmpfire[0],out game.missions[id].campfirex); Int32.TryParse(tmpfire[1],out game.missions[id].campfirey); } } break; case "objective": objective++; game.missions[id].objectives[objective] = readstring(data[i]); break; case "showkills": game.missions[id].showkills = readint(data[i]); break; case "unit": string[] unitlist = readstring(data[i]).Split(","); if(unitlist.Length==3) { bool success1 = true; bool success2 = true; string name = unitlist[0]; int x = 0; int y = 0; if(unitlist[1]=="random") { x = Functions.rand(Map.GRIDW * 35,Map.GRIDW*65); success1 = true; } else { success1 = Int32.TryParse(unitlist[1],out x); } if(unitlist[2]=="random") { y = Functions.rand(Map.GRIDH * 35,Map.GRIDH*65); success2 = true; } else { success2 = Int32.TryParse(unitlist[2],out y); } if(success1 && success2) { unitid++; game.missions[id].units[unitid] = new Unit(game); game.missions[id].units[unitid].x = x; game.missions[id].units[unitid].y = y; game.missions[id].units[unitid].name = name; } } break; //start--------------//10sep2021 case "unitname"://unit name must immediately follow the unit that was just created.... if(game.missions[id].units!=null) { if(unitid=0) { game.missions[id].units[unitid].charactername = readstring(data[i]); } } break; case "displayunitname"://unit name must immediately follow the unit that was just created.... if(game.missions[id].units!=null) { if(unitid=0) { game.missions[id].units[unitid].displaycharactername = readint(data[i]); //start--------------------//12feb2021 if(readint(data[i])!=1) { //potentially mixed up data game.missions[id].units[unitid].charactername = readstring(data[i]); game.missions[id].units[unitid].displaycharactername = 1; } //end----------------------//12feb2021 } } break; //end----------------//10sep2021 case "trigger": //type,num,comparator,name,xx,yy,ww,hh //type == 1 Victory //type == 2 Defeat //comparator == 0 equal //comparator == -1 less than //comparator == 1 greater than if(id>=0) { string[] trigger = readstring(data[i]).Split(","); if(trigger.Length==8) { int typ = 0; int num = 0; int comp = 0; Int32.TryParse(trigger[0],out typ); Int32.TryParse(trigger[1],out num); Int32.TryParse(trigger[2],out comp); int xx = 0; int yy = 0; int ww = 0; int hh = 0; Int32.TryParse(trigger[4],out xx); Int32.TryParse(trigger[5],out yy); Int32.TryParse(trigger[6],out ww); Int32.TryParse(trigger[7],out hh); game.missions[id].createtrigger(typ,num,comp,trigger[3].Replace("^",","),xx,yy,ww,hh); } } break; } } } // //customs bool validblock = true; //24Feb2021 for(int i=0;i0) { game.missions[id].units = new Unit[countunits]; unitid = -1; } if(countobjectives>0) { game.missions[id].objectives = new string[countobjectives]; } Game.LoadingProgress(game); break; //26oct2020 start case "cw": cw = readint(data2[i]); break; case "ch": ch = readint(data2[i]); break; case "nw": nw = readint(data2[i]); break; case "nh": nh = readint(data2[i]); break; case "offy": offy = readint(data2[i]); break; //start-----------------//10sep2021 case "gridw": game.missions[id].gridw = readint(data2[i]); break; case "gridh": game.missions[id].gridh = readint(data2[i]); break; //end-------------------//10sep2021 //start-----------------//21feb2022 case "overlayimage": cw = game.missions[id].gridw * Map.MAXX; ch = game.missions[id].gridh * Map.MAXY; game.missions[id].overlayimage = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,1,1); break; case "overlaysnow"://4mar2022 cw = game.missions[id].gridw * Map.MAXX; ch = game.missions[id].gridh * Map.MAXY; game.missions[id].overlaysnow = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,1,1); break; //end-------------------//21feb2022 //1nov2020 start case "override_bk_red": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_r = readint(data2[i]); break; case "override_bk_green": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_g = readint(data2[i]); break; case "override_bk_blue": game.missions[id].overridergbbk = true; game.missions[id].overridergbbk_b = readint(data2[i]); break; //1nov2020 end case "override_ground": game.missions[id].tilecat = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,nw,nh); game.missions[id].tileframes = nw * nh; if(readstring(data2[i]).IndexOf("snow")>0) { game.missions[id].issnow = true; } if(readstring(data2[i]).IndexOf("desert")>0) { game.missions[id].isdesert = true; } break; case "override_trees": game.missions[id].treecat = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,nw,nh); game.missions[id].treeframes = nw * nh; game.missions[id].treeoffsety = offy; break; //start--------------//2mar2021 case "override_decor": game.missions[id].decorcat = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,nw,nh); game.missions[id].decorframes = nw * nh; game.missions[id].decoroffsety = offy; break; //end----------------//2mar2021 case "override_rocks": game.missions[id].rockcat = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,nw,nh); game.missions[id].rockframes = nw * nh; game.missions[id].rockoffsety = offy; break; case "override_walls": game.missions[id].wallcat = Resources.LoadAnimImage(game,readstring(data2[i]),game.renderer,cw,ch,nw,nh); game.missions[id].wallframes = nw * nh; game.missions[id].walloffsety = offy; break; //26oct2020 end case "nextmissionid": game.missions[id].nextmissionid = readint(data2[i]); break; case "debrief": game.missions[id].debrief = readint(data2[i]); break; case "failedmissionid": game.missions[id].failedmissionid = readint(data2[i]); break; //start--------------//1mar2021 case "nextmissionname": game.missions[id].nextmissionname = readstring(data2[i]); break; case "failedmissionname": game.missions[id].failedmissionname = readstring(data2[i]); break; //end----------------//1mar2021 case "demo": game.missions[id].demo = 0;//readint(data2[i]); break; //start-----------//26Feb2021 case "fogoff": game.missions[id].fogoff = readint(data2[i]); break; case "neutralfog": game.missions[id].neutralfog = readint(data2[i]); break; //end-------------//26Feb2021 //start-------------//28Feb2021 case "playerfaction": game.missions[id].playerfaction = readint(data2[i]); break; case "enemyfaction": game.missions[id].skirmishenemyfaction = readint(data2[i]); break; case "flavourtext"://18sep2021 game.missions[id].flavourtext = readstring(data2[i]); break; case "floorpattern"://16sep2021 game.missions[id].floorpattern = readint(data2[i]); break; case "unlocked": game.missions[id].alwaysunlocked = readint(data2[i]); break; //end---------------//28Feb2021 //start--------------//1mar2021 case "lockcorner": game.missions[id].lockcorner = readint(data2[i]); break; //end----------------//1mar2021 case "corner": string[] tmpcorner = readstring(data2[i]).Split(","); if(tmpcorner.Length==2) { Int32.TryParse(tmpcorner[0],out game.missions[id].cornerx); Int32.TryParse(tmpcorner[1],out game.missions[id].cornery); } break; case "seed": game.missions[id].seed = readint(data2[i]); break; case "skirmish": game.missions[id].skirmish = readint(data2[i]); break; case "indoor"://23sep2021 game.missions[id].indoor = readint(data2[i]); break; case "mapgen": game.missions[id].mapgen = 1; break; case "ai": game.missions[id].ai = readint(data2[i]); break; case "description": if(game.missions[id].description[0] == "") { //game.missions[id].description[0] = readstring(data2[i]);//21mar2021 game.missions[id].description[0] = Translation.TranslateWord(readstring(data2[i]),false);//21mar2021 } else { if(game.missions[id].description[1] == "") { //game.missions[id].description[1] = readstring(data2[i]);//22mar2021 game.missions[id].description[1] = Translation.TranslateWord(readstring(data2[i]),false);//22mar2021 } else { //game.missions[id].description[2] = readstring(data2[i]);//22mar2021 game.missions[id].description[2] = Translation.TranslateWord(readstring(data2[i]),false);//22mar2021 } } break; case "istutorial": game.missions[id].istutorial = 0;//readint(data[i]); break; //start--------------//2mar2021 case "decor": if(id>=0) { string[] tmpdecor = readstring(data2[i]).Split(","); game.missions[id].decorimage = new int[tmpdecor.Length]; for(int j=0;j=0) { string[] tmptrees = readstring(data2[i]).Split(","); game.missions[id].treeimage = new int[tmptrees.Length]; for(int j=0;j=0) { string[] tmpwalls = readstring(data2[i]).Split(","); game.missions[id].wallimage = new int[tmpwalls.Length]; for(int j=0;j=0) { string[] tmprocks = readstring(data2[i]).Split(","); game.missions[id].rockimage = new int[tmprocks.Length]; for(int j=0;j=0) { string[] tmpfire = readstring(data2[i]).Split(","); if(tmpfire.Length==2) { game.missions[id].campfirex = -1; game.missions[id].campfirey = -1; Int32.TryParse(tmpfire[0],out game.missions[id].campfirex); Int32.TryParse(tmpfire[1],out game.missions[id].campfirey); } } break; case "objective": objective++; //game.missions[id].objectives[objective] = readstring(data2[i]);//22mar2021 game.missions[id].objectives[objective] = Translation.TranslateWord(readstring(data2[i]),false);//22mar2021 break; case "showkills": game.missions[id].showkills = readint(data2[i]); break; case "unit": string[] unitlist = readstring(data2[i]).Split(","); if(unitlist.Length==3) { bool success1 = true; bool success2 = true; string name = unitlist[0]; int x = 0; int y = 0; if(unitlist[1]=="random") { x = Functions.rand(Map.GRIDW * 35,Map.GRIDW*65); success1 = true; } else { success1 = Int32.TryParse(unitlist[1],out x); } if(unitlist[2]=="random") { y = Functions.rand(Map.GRIDH * 35,Map.GRIDH*65); success2 = true; } else { success2 = Int32.TryParse(unitlist[2],out y); } if(success1 && success2) { unitid++; game.missions[id].units[unitid] = new Unit(game); game.missions[id].units[unitid].x = x; game.missions[id].units[unitid].y = y; game.missions[id].units[unitid].name = name; } } break; //start--------------//10sep2021 case "unitname"://unit name must immediately follow the unit that was just created.... if(game.missions[id].units!=null) { if(unitid=0) { game.missions[id].units[unitid].charactername = readstring(data2[i]); } } break; case "displayunitname": if(game.missions[id].units!=null) { if(unitid=0) { game.missions[id].units[unitid].displaycharactername = readint(data2[i]); //start--------------------//12feb2021 if(readint(data2[i])!=1) { //potentially mixed up data game.missions[id].units[unitid].charactername = readstring(data2[i]); game.missions[id].units[unitid].displaycharactername = 1; } //end----------------------//12feb2021 } } break; //end----------------//10sep2021 case "trigger": //type,num,comparator,name,xx,yy,ww,hh //type == 1 Victory //type == 2 Defeat //comparator == 0 equal //comparator == -1 less than //comparator == 1 greater than if(id>=0) { string[] trigger = readstring(data2[i]).Split(","); if(trigger.Length==8) { int typ = 0; int num = 0; int comp = 0; Int32.TryParse(trigger[0],out typ); Int32.TryParse(trigger[1],out num); Int32.TryParse(trigger[2],out comp); int xx = 0; int yy = 0; int ww = 0; int hh = 0; Int32.TryParse(trigger[4],out xx); Int32.TryParse(trigger[5],out yy); Int32.TryParse(trigger[6],out ww); Int32.TryParse(trigger[7],out hh); game.missions[id].createtrigger(typ,num,comp,trigger[3].Replace("^",","),xx,yy,ww,hh); } } break; } } } } LocalStorage.setitem("FILE LOAD:"+file,"SUCCESS");//24mar2021 } catch(Exception e) { Console.WriteLine("766:"+"Error in file on line containing:"+errline+" "+e.Message); //LocalStorage.WriteLog("766:"+"Error in file on line containing:"+errline+" "+e.Message); LocalStorage.setitem("FILE LOAD:"+file,"FAILED");//24mar2021 } } ///////////////////Method Definition/////////////// public static int LoadFont(Game game,string file,int ptsize) { //////////////////////// //Load a font in the game for use Fonts f = new Fonts(); //ptsize*=Config.FONTALIAS; if(file!="" && file!=null)//28Feb2021 { if(ptsize>=20) { f.font = SDL_ttf.TTF_OpenFont(file,ptsize*Config.FONTALIAS); } else { f.font = SDL_ttf.TTF_OpenFont(file,ptsize); } } if(f.font==IntPtr.Zero) { Console.WriteLine("Could Not Open Font:"+file+". Error:"+SDL.SDL_GetError()); Network.reporterror("FontLoadFailure:"+file,false);//15mar2021 LocalStorage.setitem("FILE LOAD:"+file,"FAILED TO LOAD"); } else { LocalStorage.setitem("FILE LOAD:"+file,"LOADED"); } int i = game.fonts.Length; Array.Resize(ref game.fonts,i+1); f.file = file;//24mar2021 game.fonts[i] = f; game.fonts[i].font = f.font; game.fonts[i].ptsize = ptsize; i++; return i - 1; } // ///////////////////Method Definition/////////////// public static int LoadAudio(Game game,string file,bool music) { //////////////////////// //Load an Audio file of .wav type for(int j=0;j(ref game.audios,i+1); game.audios[i] = a; game.audios[i].index = i; game.audios[i].loop = music; game.audios[i].volume = 1; game.audios[i].file = file; i++; return i - 1; } // //start-------------//28Feb2021 ///////////////////Method Definition/////////////// public static void StreamImage(Game game,int i) { //////////////////////// //not used //used after an image is released...and we want to reload it in game....in a separate thread. if(i>=0 && i=0 && i0 && Config.Night>0) //{ // //check if the nighttime file version exists.... ////if it does - use it..... //string sfile = file; //int index = sfile.Length - 1; //while(index>=0) //{ // if(sfile.Substring(index,1) == "/") //{ // break; //} //index--; //} //if(index>=0) //{ // string prefix = sfile.Substring(0,index + 1); //string suffix = sfile.Substring(index + 1,sfile.Length - (index + 1)); //string nightfile = prefix + "night_" + suffix; //if(File.Exists(nightfile)) //{ // file = nightfile; //} //} //} ////end------------//24feb2022 //Load an image of the form .png or .jpg into memory bool loaded = false;//28Feb2021 for(int j=0;j(ref game.images,i+1); game.images[i] = img; game.images[i].file = file;//26oct2020 game.images[i].texture = img.texture; game.images[i].anim = false; game.images[i].index = i; game.images[i].cwx = w;//?? game.images[i].chy = h;//?? game.images[i].chn = 1; game.images[i].cwn = 1; game.images[i].stream = Config.STREAMLOAD;//28Feb2021 game.images[i].loaded = loaded; ///28Feb2021 game.images[i].okloaded = loaded; //28Feb2021 game.images[i].neverloaded = !loaded; //28Feb2021 i++; return i - 1; } // ///////////////////Method Definition/////////////// public static int LoadAnimImage(Game game,string file,IntPtr renderer,int cellwidth, int cellheight, int cellswide, int cellshigh) { /////start---------//24feb2022 // if(Config.useseasons>0 && Config.Night>0) //{ // //check if the nighttime file version exists.... ////if it does - use it..... //string sfile = file; //int index = sfile.Length - 1; //while(index>=0) //{ // if(sfile.Substring(index,1) == "/") //{ // break; //} //index--; //} //if(index>=0) //{ // string prefix = sfile.Substring(0,index + 1); //string suffix = sfile.Substring(index + 1,sfile.Length - (index + 1)); //string nightfile = prefix + "night_" + suffix; //if(File.Exists(nightfile)) //{ // file = nightfile; //} //} //} ////end------------//24feb2022 //////////////////////// //Load an animated image of the form .png or .jpg into memory bool loaded = false; //28Feb2021 for(int j=0;j(ref game.images,i+1); game.images[i] = img; game.images[i].file = file;//26oct2020 game.images[i].texture = img.texture; game.images[i].anim = true; game.images[i].index = i; game.images[i].cwx = cellwidth; game.images[i].chy = cellheight; game.images[i].chn = cellshigh; game.images[i].cwn = cellswide; game.images[i].stream = Config.STREAMLOAD;//28Feb2021 game.images[i].loaded = loaded;//28Feb2021 game.images[i].okloaded = loaded; //28Feb2021 game.images[i].neverloaded = !loaded; //28Feb2021 i++; return i - 1; } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Fonts { public IntPtr font; public int ptsize; public static int WMULTIPLIER = 1; //15mar2021 public static int HMULTIPLIER = 1; //17apr2021 public string file; ///////////////////Method Definition/////////////// public Fonts() { file = ""; } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Audios { public int index; public bool loop; public int volume; // public IntPtr audio; public bool ismusic; public bool ispaused; public int[] channel; public static int maxchannels = 8; public string file; public int previousmusicchannel; public int currentmusicchannel; // // ///////////////////Method Definition/////////////// public Audios() { loop = false; volume = 1; index = 0; ismusic = false; channel = new int[Audios.maxchannels]; ispaused = false; file = "";//25mar2021 } // ///////////////////Method Definition/////////////// public static int playsound(Audios a,int vol) { //////////////////////// //play an audio clip at a specified volume from 0 to 100 if(!Game.audioon) { return -1; } if(!a.ismusic) { //start-------------//10sep2021 //in case we freed at a certain point..... //in the game.... if(a.audio==IntPtr.Zero) { if(a.file!=null) { if(a.file!="") { a.audio = SDL_mixer.Mix_LoadWAV(a.file); } } } //end---------------//10sep2021 int i = SDL_mixer.Mix_PlayChannel(-1,a.audio,0); SDL_mixer.Mix_Volume(i,vol); return i; } return -1; } ///////////////////Method Definition/////////////// public static void playmusic(Audios a,int vol,bool loop) { //play a music clip at a specified volume from 0 to 100, and perhaps loop it if(!Game.audioon) { return; } if(a.ismusic) { if(a.ispaused) { SDL_mixer.Mix_ResumeMusic(); a.ispaused = false; } else { int i = SDL_mixer.Mix_PlayMusic(a.audio,-1); SDL_mixer.Mix_VolumeMusic(vol); a.previousmusicchannel = a.currentmusicchannel; a.currentmusicchannel = i; a.ispaused = false; } } } ///////////////////Method Definition/////////////// public static void FreeAudio(Audios a)//10sep2021 { //alias for freeaudio(Audios a) freeaudio(a); } ///////////////////Method Definition/////////////// public static void freeaudio(Audios a)//10sep2021 { if(a.ismusic) { return; } try { SDL_mixer.Mix_FreeChunk(a.audio); LocalStorage.setitem("FREE AUDIO:"+a.file,"SUCCESS"); //24mar2021 a.audio = IntPtr.Zero; } catch(Exception e) { string txt = e.Message; } } ///////////////////Method Definition/////////////// public static void stopchannel(int i)//10sep2021 { try { SDL_mixer.Mix_HaltChannel(i); } catch(Exception e) { string txt = e.Message; } } ///////////////////Method Definition/////////////// public static void pauseaudio(Audios a) { //pause an audio music track that is playing //and stop all other audio at the same time. if(a.ismusic) { SDL_mixer.Mix_PauseMusic(); a.ispaused = true; } else { } SDL_mixer.Mix_HaltChannel(-1); } ///////////////////Method Definition/////////////// public static void resumemusic(Audios a) { //resume a music track that is paused. if(!Game.audioon) { return; } if(a.ismusic) { SDL_mixer.Mix_ResumeMusic(); a.ispaused = false; } } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Images { public IntPtr texture; public int index; public bool anim; public int cwx; public int chy; public int chn; public int cwn; public string file; //26oct2020 public bool loaded;//28Feb2021 public bool stream; //28Feb2021 public int drawframe; //28Feb2021 public bool okloaded; //28Feb2021 public bool neverloaded; //28Feb2021 ///////////////////Method Definition/////////////// public Images() { } ///////////////////Method Definition/////////////// public Images(int i,bool a,int cw, int ch, int xn, int yn) { index = i; anim = a; cwx = cw; chy = ch; cwn = xn; chn = yn; loaded = false;//28Feb2021 okloaded = false; //28Feb2021 stream = Config.STREAMLOAD; //28Feb2021 neverloaded = true;//28Feb2021 } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class RenderList { // public static int transitionmode = -1; //18apr2021 public static int HALFTRANSIT = 30;//18apr2021 public static int TRANSITIONRATE = 1;//18apr2021 public static int STARTTRANSITION = 60;//18apr2021 public static int screenshake = 0; public static bool IGNOREZOOM; public static int RENDERMODE = 0; public static int RENDERMODE_POOL = 0; public static int RENDERMODE_NONPOOL = 1; public IntPtr texture; public bool istext; public bool isrect; public bool isline; public bool filled; public int x; public int y; public int w; public int h; public int blend; public int index; public int frame; public uint color; public float sx; public float sy; public bool flipx; public bool flipy; public float alpha; public float angle; public string text; public IntPtr font; public int fontindex;//2apr2021//7apr2021 public bool drawn; public bool centre; public bool ignorezoom; public bool ignorefontalias; // public static int renderi = 0; public static int maxrenderi = 0; // public static int offsetx = 0; public static int offsety = 0; // public static bool threadrunning = false; public static int recordframe = 0; public static IntPtr screenshotsurface; //start--------------//2apr2021 public bool subimage; public int subx; public int suby; public int subw; public int subh; //end----------------//2apr2021 ///////////////////Method Definition/////////////// public static void init() { //RenderList has an init function that is called once before drawing renderi = 0; maxrenderi = 0; } ///////////////////Method Definition/////////////// public static bool CaptureThread(IntPtr screenshotsurface) { //Separate thread used for capturing screenshots //screenshot is captured in the main thread //but the file is saved in a secondary thread to //prevent performance hits //if we had a faster hard drive we could capture movies this way..! if(threadrunning) { return false; } threadrunning = true; RenderList.screenshotsurface = screenshotsurface; Thread thread = new Thread(new ThreadStart(ThreadFunction)); thread.Start(); return true; } ///////////////////Method Definition/////////////// private static void ThreadFunction() { //screenshot saving thread recordframe++; //SDL.SDL_SaveBMP(screenshotsurface,"media/screenshots/img_"+Functions.zstr(recordframe,6)+".bmp"); try //13mar2021 - try catch block added.... { SDL_image.IMG_SavePNG(screenshotsurface,"media/screenshots/img_"+Functions.zstr(recordframe,6)+".png"); } catch(Exception e) { Console.WriteLine("Thread Error Taking Screenshot:"+e.Message); } try { SDL.SDL_FreeSurface(screenshotsurface); } catch(Exception e) { string msg = e.Message; } threadrunning = false; } ///////////////////Method Definition/////////////// public RenderList() { drawn = false; text = ""; font = IntPtr.Zero; texture = IntPtr.Zero; centre = false; ignorezoom = true; ignorefontalias = false; subimage = false;//2apr2021 subx = 0; suby = 0; subw = 0; subh = 0; } ///////////////////Method Definition/////////////// public static void render(Game game) { //////////////////////// //Core Render function that is called in the game //Takes all the drawimage/drawrect/drawtext calls that were stored //in an array and draws them one after the other //start------//15mar2021 bool chinese = false; Functions.saveseed(Functions.seed); if(Translation.GetLanguage()=="chinesesimplified") { chinese = true; } if(Config.useUNICODE) { chinese = true; } //end--------//15mar2021 SDL.SDL_Rect src; SDL.SDL_Rect dst; int SW = 0; int SH = 0; SDL.SDL_GetRendererOutputSize(game.renderer,out SW,out SH); game.SW = SW; game.SH = SH; float gxscale = 1f; float gyscale = 1f; gxscale = (float)SW / (float)Game.RESOLUTIONX; gyscale = (float)SH / (float)Game.RESOLUTIONY; int offsetx = 0;//23feb2022 int offsety = 0; if(screenshake>0)//23feb2022 { screenshake--; offsetx=(int)(gxscale*(float)(Functions.rand(0,screenshake+1)-screenshake/2)); offsety=(int)(gyscale*(float)(Functions.rand(0,screenshake+1)-screenshake/2)); } for(int i=0;i0)//23feb2022 //{ // screenshake--; //int offsetx=(int)(gxscale*(float)(Functions.rand(0,screenshake+1)-screenshake/2)); //int offsety=(int)(gyscale*(float)(Functions.rand(0,screenshake+1)-screenshake/2)); //game.renderlist[i].x+=offsetx; //game.renderlist[i].y+=offsety; //} game.renderlist[i].x+=offsetx;//23feb2022 game.renderlist[i].y+=offsety; // if(game.renderlist[i].sx<0) { game.renderlist[i].sx*=-1; game.renderlist[i].flipx = true; } else { game.renderlist[i].flipx = false; } if(game.renderlist[i].sy<0) { game.renderlist[i].sy*=-1; game.renderlist[i].flipy = true; } else { game.renderlist[i].flipy = false; } SDL.SDL_SetRenderDrawColor(game.renderer,RenderList.getcomponents(game.renderlist[i].color)[1],RenderList.getcomponents(game.renderlist[i].color)[2],RenderList.getcomponents(game.renderlist[i].color)[3],RenderList.getcomponents(game.renderlist[i].color)[0]); if(game.renderlist[i].isrect) { dst.x = game.renderlist[i].x; dst.y = game.renderlist[i].y; dst.w = game.renderlist[i].w; dst.h = game.renderlist[i].h; if(game.renderlist[i].filled) { SDL.SDL_RenderFillRect(game.renderer,ref dst); } else { SDL.SDL_RenderDrawRect(game.renderer,ref dst); } } if(game.renderlist[i].isline) { SDL.SDL_RenderDrawLine(game.renderer,game.renderlist[i].x,game.renderlist[i].y,game.renderlist[i].x+game.renderlist[i].w,game.renderlist[i].y+game.renderlist[i].h); } if(game.renderlist[i].istext) { SDL.SDL_Color color; color.r = RenderList.getcomponents(game.renderlist[i].color)[1]; color.g = RenderList.getcomponents(game.renderlist[i].color)[2]; color.b = RenderList.getcomponents(game.renderlist[i].color)[3]; color.a = (byte)Convert.ToInt32(255f * game.renderlist[i].alpha); IntPtr text_surface; if(!chinese) //15mar2021 { text_surface = SDL_ttf.TTF_RenderText_Solid(game.renderlist[i].font,game.renderlist[i].text,color); } else { text_surface = SDL_ttf.TTF_RenderUNICODE_Solid(game.renderlist[i].font,game.renderlist[i].text,color); //15mar2021 } dst.x = game.renderlist[i].x; dst.y = game.renderlist[i].y; if(!chinese) //15mar2021 { SDL_ttf.TTF_SizeText(game.renderlist[i].font,game.renderlist[i].text,out dst.w,out dst.h); } else { SDL_ttf.TTF_SizeText(game.renderlist[i].font,game.renderlist[i].text,out dst.w,out dst.h); if(!Translation.AllAscii(game.renderlist[i].text)) //16mar2021 { //dst.w*=Fonts.WMULTIPLIER;//17mar2021 if(game.renderlist[i].text!=null)//17mar2021 { if(game.renderlist[i].text.Length>0) { dst.w*=(int)System.Math.Ceiling((double)((float)Fonts.WMULTIPLIER * (float)Translation.CountNonAscii(game.renderlist[i].text)) / (float)game.renderlist[i].text.Length); //Huh!?//17mar2021 dst.h*=(int)System.Math.Ceiling((double)((float)Fonts.HMULTIPLIER * (float)Translation.CountNonAscii(game.renderlist[i].text)) / (float)game.renderlist[i].text.Length);//17apr2021 } } } } src.x = 0; src.y = 0; src.w = dst.w; src.h = dst.h; if(game.renderlist[i].ignorefontalias) { dst.w = Convert.ToInt32((float)dst.w*game.renderlist[i].sx); dst.h = Convert.ToInt32((float)dst.h*game.renderlist[i].sy); } else { dst.w = Convert.ToInt32((float)dst.w*game.renderlist[i].sx)/Config.FONTALIAS; dst.h = Convert.ToInt32((float)dst.h*game.renderlist[i].sy)/Config.FONTALIAS; } if(game.renderlist[i].centre) { dst.x-=dst.w/2; dst.y-=dst.h/2; } IntPtr tex = SDL.SDL_CreateTextureFromSurface(game.renderer,text_surface); //SDL.SDL_SetTextureScaleMode(tex,SDL.SDL_ScaleMode.SDL_ScaleModeNearest); //already commented out a while ago SDL.SDL_FreeSurface(text_surface); SDL.SDL_RenderCopyEx(game.renderer,tex,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); SDL.SDL_DestroyTexture(tex); } SDL.SDL_SetRenderDrawColor(game.renderer,0,0,0,0); if(game.renderlist[i].texture!=IntPtr.Zero) { SDL.SDL_SetTextureAlphaMod(game.renderlist[i].texture,Convert.ToByte(255.0f*game.renderlist[i].alpha)); switch(game.renderlist[i].blend) { case 0: SDL.SDL_SetTextureBlendMode(game.renderlist[i].texture,SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); break; case 1: SDL.SDL_SetTextureBlendMode(game.renderlist[i].texture,SDL.SDL_BlendMode.SDL_BLENDMODE_ADD); break; } //start--------------//2apr2021 if(game.renderlist[i].subimage) { src.x = game.renderlist[i].subx; src.y = game.renderlist[i].suby; src.w = game.renderlist[i].subw; src.h = game.renderlist[i].subh; dst.x = game.renderlist[i].x; dst.y = game.renderlist[i].y; dst.w = Convert.ToInt32(game.renderlist[i].subw * game.renderlist[i].sx); dst.h = Convert.ToInt32(game.renderlist[i].subh * game.renderlist[i].sy); dst.x -= dst.w/2; dst.y -= dst.h/2; //SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); if(game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL); } if(!game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(!game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); } continue; } //end----------------//2apr2021 if(game.images[game.renderlist[i].index].anim) { src.x = game.images[game.renderlist[i].index].cwx * (game.renderlist[i].frame % game.images[game.renderlist[i].index].cwn); src.y = game.images[game.renderlist[i].index].chy * ((game.renderlist[i].frame - (game.renderlist[i].frame % game.images[game.renderlist[i].index].cwn))/game.images[game.renderlist[i].index].cwn); src.w = game.images[game.renderlist[i].index].cwx; src.h = game.images[game.renderlist[i].index].chy; dst.x = game.renderlist[i].x; dst.y = game.renderlist[i].y; dst.w = Convert.ToInt32(src.w * game.renderlist[i].sx); dst.h = Convert.ToInt32(src.h * game.renderlist[i].sy); dst.x -= dst.w/2; dst.y -= dst.h/2; if(game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL); } if(!game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(!game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); } } else { src.x = 0; src.y = 0; src.w = game.images[game.renderlist[i].index].cwx; src.h = game.images[game.renderlist[i].index].chy; dst.x = game.renderlist[i].x; dst.y = game.renderlist[i].y; dst.w = Convert.ToInt32(game.images[game.renderlist[i].index].cwx * game.renderlist[i].sx); dst.h = Convert.ToInt32(game.images[game.renderlist[i].index].chy * game.renderlist[i].sy); dst.x -= dst.w/2; dst.y -= dst.h/2; //SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); if(game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL); } if(!game.renderlist[i].flipx && game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL); } if(!game.renderlist[i].flipx && !game.renderlist[i].flipy) { SDL.SDL_RenderCopyEx(game.renderer,game.renderlist[i].texture,ref src,ref dst,Convert.ToDouble(game.renderlist[i].angle),IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); } } } //start----//19apr2021 game.renderlist[i].x = origx; game.renderlist[i].y = origy; game.renderlist[i].sx = origsx; game.renderlist[i].sy = origsy; game.renderlist[i].w = origw; game.renderlist[i].h = origh; //end------//19apr2021 } if(RenderList.renderi>RenderList.maxrenderi) { RenderList.maxrenderi = RenderList.renderi; } //start-----//18apr2021 if(transitionmode>=0) { //byte alpha = 255; int alpha = 255; if(transitionmode < HALFTRANSIT) { RenderList.renderi = 0; //alpha = (byte)(transitionmode * 8); alpha = transitionmode * 8; } else { //alpha = (byte)((60 - transitionmode) * 8); alpha = (60 - transitionmode) * 8; } src.x = 0; src.y = 0; src.w = 1; src.h = 1; dst.x = 0; dst.y = 0; dst.w = SW; dst.h = SH; //if(Resources.blackcat!=-1) //{ //SDL.SDL_SetRenderDrawColor(game.renderer,(byte)(255-alpha),(byte)(255-alpha),(byte)(255-alpha),(byte)255); SDL.SDL_SetRenderDrawBlendMode(game.renderer,SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); SDL.SDL_SetRenderDrawColor(game.renderer,0,0,0,(byte)alpha); //SDL.SDL_SetRenderDrawBlendMode(game.renderer,SDL.SDL_BlendMode.SDL_BLENDMODE_MUL); //SDL.SDL_SetTextureAlphaMod(game.images[Resources.blackcat].texture,alpha); //SDL.SDL_SetTextureBlendMode(game.images[Resources.blackcat].texture,SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); //SDL.SDL_RenderCopyEx(game.renderer,game.images[Resources.blackcat].texture,ref src,ref dst,0,IntPtr.Zero,SDL.SDL_RendererFlip.SDL_FLIP_NONE); SDL.SDL_RenderFillRect(game.renderer,ref dst); SDL.SDL_SetRenderDrawBlendMode(game.renderer,SDL.SDL_BlendMode.SDL_BLENDMODE_NONE); SDL.SDL_SetRenderDrawColor(game.renderer,0,0,0,0); //} transitionmode-=TRANSITIONRATE; Functions.restoreseed(); return; //in other words don't clear the drawing list //so that we can draw over the top of it in some way //such as a black fade out screen...... } //end-------//18apr2021 RenderList.renderi = 0; Functions.restoreseed(); } //draw an image ///////////////////Method Definition/////////////// public static void drawimage(Game game,IntPtr img,int x,int y,float angle,float scalex,float scaley,int framenumber,int blend,bool istext,float alpha,int celltype) { //draw an image on the screen RenderList r; if(RenderList.renderi= 0 && celltype < game.images.Length) { game.images[celltype].drawframe = game.frame; } //end---------------//28Feb2021 if(RenderList.renderi>=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } // ///////////////////Method Definition/////////////// public static void drawanimimage(Game game,IntPtr img,int x,int y,float angle,float scalex,float scaley,int framenumber,int blend,bool istext,float alpha,int index) { //draw an animated image on the screen //can be used as an alternative to drawimage, but they are mostly identical now. //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi= 0 && index < game.images.Length) { game.images[index].drawframe = game.frame; } //end---------------//28Feb2021 if(RenderList.renderi>=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } ///////////////////Method Definition/////////////// public static void drawsubimage(Game game,IntPtr img,int x,int y,float angle,float scalex,float scaley,int framenumber,int blend,bool istext,float alpha,int celltype,int ssx,int ssy,int ssw,int ssh)//2apr2021 { //draw an image on the screen RenderList r; if(RenderList.renderi= 0 && celltype < game.images.Length) { game.images[celltype].drawframe = game.frame; } //end---------------//28Feb2021 if(RenderList.renderi>=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } // //draw primitives ///////////////////Method Definition/////////////// public static void drawrect(Game game,int x,int y,int w,int h,uint color,int blend) { //draw a filled rect on the screen //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } ///////////////////Method Definition/////////////// public static void drawunfilledrect(Game game,int x,int y,int w,int h,uint color,int blend) { //draw an unfilled rect on the screen //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } ///////////////////Method Definition/////////////// public static void drawline(Game game,int sx,int sy,int fx,int fy,uint color,int blend) { //draw a solid line on the screen //can also draw points. //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } //draw text ///////////////////Method Definition/////////////// public static void drawtext(Game game,int x,int y,string text,uint color,IntPtr font,bool centre) { //draw text with a certain font on the screen //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } ///////////////////Method Definition/////////////// public static void drawtext(Game game,IntPtr font,int x,int y,float angle,float scalex,float scaley,bool centre,int blend,string text,float alpha,uint color) { //alternative drawtext command //RenderList r = new RenderList(); RenderList r; if(RenderList.renderi=RenderList.maxrenderi) { Array.Resize(ref game.renderlist,game.renderlist.Length + 1); } game.renderlist[RenderList.renderi] = r; game.renderlist[RenderList.renderi].ignorezoom = IGNOREZOOM; RenderList.renderi++; } //rgb helper functions. ///////////////////Method Definition/////////////// public static uint getrgb(int r, int g, int b) { //return the rgb value by its components return (uint)(255 << 24 | (byte)r << 16 | (byte)g << 8 | (byte)b); } ///////////////////Method Definition/////////////// public static uint getrgb(byte r,byte g, byte b) { //return the rgb value by its components return (uint)(255 << 24 | r << 16 | g << 8 | b); } ///////////////////Method Definition/////////////// public static byte[] getcomponents(uint argb) { //get the components of an argb colour and return an array of alpha, red, green, blue as a bunch of byte values byte[] rgbarray = {0,0,0,0}; rgbarray[0] = (byte)((argb >> 24) & (255)); rgbarray[1] = (byte)((argb >> 16) & (255)); rgbarray[2] = (byte)((argb >> 8) & 255); rgbarray[3] = (byte)((argb & 255)); return rgbarray; } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Network { //Network.url = "https://www.mattiesgames.com/metrics/metric.php?game="+Game.NETTITLE+"&event=[your event here]&value="[your value here]; //Network.httpget(Network.url); public static string url = ""; public static string errorreport = ""; public static string ERRORURL = "https://www.mattiesgames.com/metrics/metric.php?game=grumthorr&event=errorlog&value=error:"; ///////////////////Method Definition/////////////// private static void ThreadFunction() { //send a network message to a website //typically used for sending metrics //or such. return values are ignored if(Network.url=="") { return; } try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Network.url); request.Timeout = 10000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //start---//1apr2021 Stream stream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader read = new StreamReader(stream,encode); Char[] chararray = new Char[256]; if(Config.GETDATA) { int count = read.Read(chararray,0,256); while(count>0) { String str = new String(chararray,0,count); //Console.WriteLine(str); count = read.Read(chararray,0,256); } } response.Close();//1apr2021 read.Close(); //end---//1apr2021 } catch(Exception e) { string message = (e.Message); } } ///////////////////Method Definition/////////////// private static void ErrorFunction() { //send error information to a location //should the game have an error on intialisation Network.url = Network.ERRORURL+Network.errorreport; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Network.url); request.Timeout = 10000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //start---//1apr2021 Stream stream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader read = new StreamReader(stream,encode); Char[] chararray = new Char[256]; int count = read.Read(chararray,0,256); if(Config.GETDATA) { while(count>0) { String str = new String(chararray,0,count); //Console.WriteLine(str); count = read.Read(chararray,0,256); } } response.Close();//1apr2021 read.Close(); //end---//1apr2021 } catch(Exception e) { Console.WriteLine(e.Message); } Network.url = ""; } ///////////////////Method Definition/////////////// public static void httpget(string u) { //basic function for performing a http get operation //runs in a separate thread if(Config.NOMETRICS) { return; } Network.url = u; try { Thread thread = new Thread(new ThreadStart(ThreadFunction)); thread.Start(); } catch(Exception e) { string message = e.Message; } } ///////////////////Method Definition/////////////// public static void reporterror(bool send) { //report an error in intialisation of the game if(Network.errorreport=="") { return; } if(send) { Network.errorreport+="endoferrors"; Thread thread = new Thread(new ThreadStart(ErrorFunction)); thread.Start(); } } ///////////////////Method Definition/////////////// public static void reporterror(string report,bool send) { //alternative reporting of an error method Network.errorreport+=report+":"; if(send) { Network.errorreport+="endoferrors"; Thread thread = new Thread(new ThreadStart(ErrorFunction)); thread.Start(); } } } /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Functions { public static int oseed = 12345678; public static int seed = 12345678; public static int[] seeds = new int[0]; // ///////////////////Method Definition/////////////// public static string ClockTime(int seconds) { int mins = (seconds - (seconds % 60)) / 60; int secs = seconds % 60; return zstr(mins,2) + ":" + zstr(secs,2); } ///////////////////Method Definition/////////////// public static string zstr(int i,int n) { //return an integer number such as 123 as 00123, //i = the number //n = the number of digits to use string s = "" + i; while(s.Length0)//11apr2021 { seed = seeds[seeds.Length - 1];//11apr2021 Array.Resize(ref seeds,seeds.Length -1);//11apr2021 } else//11apr2021 { seed = oseed;//11apr2021 Console.WriteLine("Warning:Seeds Out of Sync");//11apr2021 } } ///////////////////Method Definition/////////////// public static float abs(float value) { //absolute value if(value<0) { return -1* value; } return value; } ///////////////////Method Definition/////////////// public static int Rand(int min,int max) { //random number generator return min + Convert.ToInt32(random()*(double)(max-min)); } // ///////////////////Method Definition/////////////// public static int Sign(float value) { //return the sign positive or negative of the number, or zero if(value>0){return 1;} if(value<0){return -1;} return 0; } // ///////////////////Method Definition/////////////// public static int rand(int min,int max) { //random number generator return Rand(min,max); } // ///////////////////Method Definition/////////////// public static int sign(float value) { //alias of Sign return Sign(value); } // ///////////////////Method Definition/////////////// public static double random() { //pseudo random number generator Functions.seed = ((89723453 * Functions.seed + 42854321) % 1000000); double r = ((double)Functions.seed / 1000000.0); if(r<0) { r*=-1.0; } return r; } /* ///////////////////Method Definition/////////////// public static float calcangle(float x, float y) { // return Math.atan2(y, x) ; } // */ ///////////////////Method Definition/////////////// public static int isox(int x,int y,int w) { //isometric calculation //pass in the grid square and return a location in screen coordinates return (w/2) * (1 + x - y); } // ///////////////////Method Definition/////////////// public static int isoy(int x,int y,int w) { //isometric calculation //pass in the grid square and return a location in screen coordinates return (w/4) * (1 + y + x); } // ///////////////////Method Definition/////////////// public static int screentoisox(int sx,int sy,int w,int offsetx,int offsety) { //isometric calculation //pass in screen coordinates and convert to iso x grid sx-=offsetx; sy-=offsety; return Convert.ToInt32((((float)sx + 2f * (float)sy)/(float)w) - 1f); } // ///////////////////Method Definition/////////////// public static int screentoisoy(int sx,int sy,int w,int offsetx,int offsety) { //isometric calculation //pass in screen coordinates and convert to iso y grid sx-=offsetx; sy-=offsety; return Convert.ToInt32((2f*(float)sy - (float)sx)/(float)w); } } // /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Program { //game specific stuff here // //RTS Components // ///////////////////Method Definition/////////////// static void Main(string[] args) { if(args!=null) { if(args.Length>0) { if(args[0] == "-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 bool 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-------------//23feb2022 //remember it is an alien planet so perhaps the seasons are different? Int32.TryParse(DateTime.Now.ToString("HH"),out Config.CurrentMonth); Config.Season = Config.CurrentMonth % 3; //Config.Season = Config.WINTER;//debugging 4mar2022 //Config.Season = Config.SUMMER; //Config.Season = 0; //int timeofday = 12; //Int32.TryParse(DateTime.Now.ToString("HH"),out timeofday); //Config.Night = 0; //if(timeofday<6 || timeofday>18) //{ // Config.Night = 1; //} //end---------------//23feb2022 //start-------------//12mar2021 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. string folder = ""; string folderu = ""; string folderd = ""; //start-------------//28Feb2021 Config.configfile = "media/txt/config.txt"; //28Feb2021 try { string[] cdata = System.IO.File.ReadAllLines("media/txt/init.txt"); for(int i=0;i10000) { Config.FACTOR = 10000; } break; case "tilefog"://15sep2021 Config.TILEFOG = Resources.readint(data[i]);//15sep2021 break; case "noreplay"://15sep2021 Config.NOREPLAY = Resources.readint(data[i]);//15sep2021 break; case "gridw"://10sep2021 Map.DEFAULTGRIDW = Resources.readint(data[i]);//10sep2021 break;//10sep2021 case "gridh"://10sep2021 Map.DEFAULTGRIDH = Resources.readint(data[i]);//10sep2021 break;//10sep2021 case "VER"://16apr2021 Game.VERSIONSTR = Resources.readstring(data[i]);//16apr2021 break; case "NETTITLE": //25Feb2021 Game.NETTITLE = Resources.readstring(data[i]);//25Feb2021; break;//25Feb2021 case "TITLE"://2sep2021 Game.TITLE = Resources.readstring(data[i]);//2sep2021 break;//2sep2021 case "PATHTHREADING"://29may2021 if(Resources.readint(data[i])>0 && Environment.ProcessorCount>=4) { Config.THREADEDPATHING = true; } else { Config.THREADEDPATHING = false; } break; case "KEYFRAME": //21apr2021 Replay.KEYFRAME = Resources.readint(data[i]); if(Replay.KEYFRAME<1) { Replay.KEYFRAME = 1; } break; //start-----------------//21mar2021 case "usecoverflag": if(Resources.readstring(data[i])=="1") { Config.USECOVERFLAG = true; } if(Resources.readstring(data[i])=="0") { Config.USECOVERFLAG = false; } break; case "usefeetcircles": if(Resources.readstring(data[i])=="1") { Config.USEFEETCIRCLES = true; } if(Resources.readstring(data[i])=="0") { Config.USEFEETCIRCLES = false; } break; case "translategui": if(Resources.readstring(data[i])=="1") { Config.TRANSLATEGUI = true; } if(Resources.readstring(data[i])=="0") { Config.TRANSLATEGUI = false; } break; case "useiconcircles": if(Resources.readstring(data[i])=="1") { Config.USEICONCIRCLES = true; } if(Resources.readstring(data[i])=="0") { Config.USEICONCIRCLES = false; } break; //end-------------------//21mar2021 case "fullscreen": Game.FULLSCREEN = Resources.readint(data[i]); break; case "resize"://22may2021 Config.WINDOWRESIZE = Resources.readint(data[i]);//22may2021 break;//22may2021 case "hires"://10apr2021 Config.hires = Resources.readint(data[i]);//10apr202 break;//10apr2021 case "musicvolume": Game.MUSICVOLUME = Resources.readint(data[i]); Game.oMUSICVOLUME = Game.MUSICVOLUME; if(Game.EDITOR) { Game.MUSICVOLUME = 0; } break; //start--------------//13mar2021 case "words": Config.wordsfile = Resources.readstring(data[i]); break; //end----------------//13mar2021 case "fxvolume": Game.FXVOLUME = Resources.readint(data[i]); Game.oFXVOLUME = Game.FXVOLUME; break; case "guifile": Config.guifile = Resources.readstring(data[i]); break; case "fontalias": Config.FONTALIAS = Resources.readint(data[i]); if(Config.FONTALIAS<1) { Config.FONTALIAS = 1; } break; //start-----------------//20mar2021 case "healthmod": Config.HEALTHPCT = Resources.readint(data[i]); break; case "armourmod": Config.ARMOURPCT = Resources.readint(data[i]); break; case "attackmod": Config.ATTACKPCT = Resources.readint(data[i]); break; //end-------------------//20mar2021 case "campaignfile": Config.campaignfile = Resources.readstring(data[i]); break; case "skirmishmessage": Config.skirmishmessage = Resources.readstring(data[i]); break; case "customcampaignfile": Config.customcampaignfile = Resources.readstring(data[i]); break; case "unitsfile": Config.unitsfile = Resources.readstring(data[i]); break; case "techfile": //2sep2021 Config.techfile = Resources.readstring(data[i]);//2sep2021 break;//2sep2021 case "defaultfontfile": Config.defaultfontfile = Resources.readstring(data[i]); break; case "normalfontsize": Config.normalfontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "dointro"://1mar2022 Config.dointro = Resources.readint(data[i]);//1mar2022 break; case "smallfontsize": Config.smallfontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "largefontsize": Config.largefontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "audioclickfile": Config.audioclickfile = Resources.readstring(data[i]); break; case "offsetfile"://20apr2021 Config.offsetfile = Resources.readstring(data[i]);//20apr2021 break; case "DOCALCOFFSETS"://20apr2021 if(Resources.readint(data[i])==1) { Config.AUTOCALCOFFSETS = true; } else { Config.AUTOCALCOFFSETS = false; } break; case "logofile": Config.logofile = Resources.readstring(data[i]); break; case "fogfile": Config.fogfile = Resources.readstring(data[i]); break; case "logowidth": Config.logowidth = Resources.readint(data[i]); break; case "logoheight": Config.logoheight = Resources.readint(data[i]); break; case "fogwidth": Config.fogwidth = Resources.readint(data[i]); break; case "fogheight": Config.fogheight = Resources.readint(data[i]); break; case "record": //13mar2021 if(Resources.readint(data[i])==1) { Config.RECORD = true; } break; case "useunicode": //15mar2021 if(Resources.readint(data[i])==1) { Config.useUNICODE = true; } if(Resources.readint(data[i])==0) { Config.useUNICODE = false; } break; } } } } catch(Exception e) { Console.WriteLine("Error reading config.txt:"+e.Message); return false; //28Feb2021 } try { folderd = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"\\"+Game.NETTITLE; if(!Directory.Exists(folderd)) { Directory.CreateDirectory(folderd); } } catch(Exception e) { string message = e.Message; } try { string[] datad = System.IO.File.ReadAllLines(folderd+"\\nometrics.txt"); if(datad.Length>0) { Config.NOMETRICS = true; } } catch(Exception e) { string mm = e.Message; } try { folderu = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"\\"+Game.NETTITLE+"\\usercampaign"; if(!Directory.Exists(folderu)) { Directory.CreateDirectory(folderu); } if(Directory.Exists(folderu)) { Config.usercampaignfolder = folderu; Config.usercampaignfile = folderu + "\\usercampaign.txt"; } } catch(Exception e) { string message = e.Message; } try { folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"\\"+Game.NETTITLE+"\\custommaps"; if(!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if(Directory.Exists(folder)) { Config.custommapfolder = folder; } } catch(Exception e) { string message = e.Message; } if(Game.EDITOR) { Game.FULLSCREEN = 0; } LocalStorage.init();//12mar2021 //LocalStorage.WriteLog("Begin"); LocalStorage.finalise();//13mar2021 applyprefs(); return true; //28Feb2021 } ///////////////////Method Definition/////////////// static void applyprefs() //12mar2021 { //start---------------//30mar2021 if(LocalStorage.getitem("uid")!="") { Config.uid = LocalStorage.getitem("uid"); } else { long milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds(); Config.uid = ""+milliseconds; LocalStorage.setitem("uid",Config.uid); } //end-----------------//30mar2021 //apply preferences and language settings Fonts.WMULTIPLIER = 1;//15mar2021 Fonts.HMULTIPLIER = 1;//17apr2021 //start-------//28feb2022 if(LocalStorage.getitem("options_fog")=="off") { Config.options_fog = 0; } if(LocalStorage.getitem("options_fog")=="on") { Config.options_fog = 1; } if(LocalStorage.getitem("options_overlay")=="off") { Config.options_overlay = 0; } if(LocalStorage.getitem("options_overlay")=="on") { Config.options_overlay = 1; } //end---------//28feb2022 if(LocalStorage.getitem("sfx")=="off") { Game.oFXVOLUME = Game.FXVOLUME; Game.FXVOLUME = 0; } if(LocalStorage.getitem("music")=="off") { Game.oMUSICVOLUME = Game.MUSICVOLUME; Game.MUSICVOLUME = 0; } //start------------//17apr2021 if(LocalStorage.getitem("hires")=="0") { Config.hires = 0; } if(LocalStorage.getitem("hires")=="1") { Config.hires = 1; } if(LocalStorage.getitem("fullscreen")=="0") { Game.FULLSCREEN = 0; } if(LocalStorage.getitem("fullscreen")=="1") { Game.FULLSCREEN = 1; } //end--------------//17apr2021 //start--------------//13mar2021 string language = Translation.GetLanguage(); //start------------------//18mar2021 if(Config.NonEnglishAllowed)//1mar2022 { if(language=="") { try { string langcode = CultureInfo.CurrentUICulture.Name; switch(langcode.Substring(0,2)) { case "en": //English language = "english"; break; case "de": //German language = "german"; break; case "fr": //French language = "french"; break; case "es": //Spanish language = "spanish"; break; case "zh": //Chinese if(langcode=="zh-CN") { language = "chinesesimplified"; } break; case "tr": //Turkish//22mar2021 language = "turkish"; break; case "ru": //Russian language = "russian"; break; case "ro": //Romanian //21mar2021 language = "romanian"; break; } if(language!="") { Console.WriteLine("Language Found and Chosen:"+language); //LocalStorage.WriteLog("Language Found and Chosen:"+language); Config.autodetectlang = language;//30mar2021 } else { Console.WriteLine("Possible language not supported"); //LocalStorage.WriteLog("Possible language not supported"); } } catch(Exception e) { Console.WriteLine("Error getting UI Language:"+e.Message); //LocalStorage.WriteLog("Error getting UI Language:"+e.Message); } } } else//1mar2022 { language = "english"; } //end--------------------//18mar2021 if(language!="") { string altconfigfile = Config.configfile + language; try { string[] data = System.IO.File.ReadAllLines(altconfigfile); //28Feb2021 for(int i=0;i10000) { Config.FACTOR = 10000; } break; case "clump"://15sep2021 Config.CLUMP = Resources.readint(data[i]);//15sep2021 break; case "tilefog"://15sep2021 Config.TILEFOG = Resources.readint(data[i]);//15sep2021 break; case "campaignfile": Config.campaignfile = Resources.readstring(data[i]); break; case "skirmishmessage": Config.skirmishmessage = Resources.readstring(data[i]); break; case "customcampaignfile": Config.customcampaignfile = Resources.readstring(data[i]); break; case "unitsfile": Config.unitsfile = Resources.readstring(data[i]); break; case "gridw"://10sep2021 Map.DEFAULTGRIDW = Resources.readint(data[i]);//10sep2021 break;//10sep2021 case "gridh"://10sep2021 Map.DEFAULTGRIDH = Resources.readint(data[i]);//10sep2021 break;//10sep2021 case "techfile"://2sep2021 Config.techfile = Resources.readstring(data[i]);//2sep2021 break;//2sep2021 case "defaultfontfile": Config.defaultfontfile = Resources.readstring(data[i]); break; case "normalfontsize": Config.normalfontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "dointro"://1mar2022 Config.dointro = Resources.readint(data[i]);//1mar2022 break; case "smallfontsize": Config.smallfontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "largefontsize": Config.largefontsize = Resources.readint(data[i]);// * Config.FONTALIAS; break; case "fonthmultiplier"://17apr2021 Fonts.HMULTIPLIER = Resources.readint(data[i]); if(Fonts.HMULTIPLIER<1) { Fonts.HMULTIPLIER = 1; } break; case "fontwmultiplier": //15mar2021 Fonts.WMULTIPLIER = Resources.readint(data[i]); if(Fonts.WMULTIPLIER<1) { Fonts.WMULTIPLIER = 1; } break; case "offsetfile"://20apr2021 Config.offsetfile = Resources.readstring(data[i]);//20apr2021 break; case "audioclickfile": Config.audioclickfile = Resources.readstring(data[i]); break; // case "logofile": // Config.logofile = Resources.readstring(data[i]); // break; // case "fogfile": // Config.fogfile = Resources.readstring(data[i]); // break; // case "logowidth": // Config.logowidth = Resources.readint(data[i]); // break; // case "logoheight": // Config.logoheight = Resources.readint(data[i]); // break; // case "fogwidth": // Config.fogwidth = Resources.readint(data[i]); // break; // case "fogheight": // Config.fogheight = Resources.readint(data[i]); // break; // case "record": //13mar2021 // if(Resources.readint(data[i])==1) // { // Config.RECORD = true; // } // break; case "translategui": //21mar2021 if(Resources.readstring(data[i])=="1") { Config.TRANSLATEGUI = true; } if(Resources.readstring(data[i])=="0") { Config.TRANSLATEGUI = false; } break; case "useunicode": //15mar2021 if(Resources.readint(data[i])==1) { Config.useUNICODE = true; } if(Resources.readint(data[i])==0) { Config.useUNICODE = false; } break; } } } Config.configfile = altconfigfile; } catch(Exception e) { Console.WriteLine("Error reading language config.txt:"+e.Message); //LocalStorage.WriteLog("Error reading language config.txt:"+e.Message); return; } } if(Config.wordsfile!="") { Translation.CollectWords(); } //end----------------//13mar2021 } ///////////////////Method Definition/////////////// static void init() { //core window initialisation routine RenderList.init(); //13mar2021 Game.RESOLUTIONX = 1600; Game.RESOLUTIONY = 900; //start-------------//28Feb2021 //checkconfig(); if(!checkconfig()) { return; } Game.ExtremelySimplePiracyCheck();//27feb2022 Game.RESOLUTIONX = Config.DEFAULTRESX;//25sep2021 Game.RESOLUTIONY = Config.DEFAULTRESY;//25sep2021 //end---------------//28Feb2021 SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1"); if(SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_AUDIO)<0) { Console.WriteLine("Could Not Initialise Window. Error:"+SDL.SDL_GetError()); Network.reporterror("WindowOpenFailure",true);//15mar2021 return; } var window = IntPtr.Zero; switch(Game.FULLSCREEN) { case 0: //window = SDL.SDL_CreateWindow(Game.TITLE,SDL.SDL_WINDOWPOS_CENTERED,SDL.SDL_WINDOWPOS_CENTERED,Game.RESOLUTIONX,Game.RESOLUTIONY,SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED); //22may2021 //window = SDL.SDL_CreateWindow(Game.TITLE,SDL.SDL_WINDOWPOS_CENTERED,SDL.SDL_WINDOWPOS_CENTERED,Game.RESOLUTIONX,Game.RESOLUTIONY,SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE); //22may2021 //start---------//22may2021 if(Config.WINDOWRESIZE==0) { window = SDL.SDL_CreateWindow(Game.TITLE,SDL.SDL_WINDOWPOS_CENTERED,SDL.SDL_WINDOWPOS_CENTERED,Game.RESOLUTIONX,Game.RESOLUTIONY,SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED); //22may2021 } else { window = SDL.SDL_CreateWindow(Game.TITLE,SDL.SDL_WINDOWPOS_CENTERED,SDL.SDL_WINDOWPOS_CENTERED,Game.RESOLUTIONX,Game.RESOLUTIONY,SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE); //22may2021 } //end----------//22may2021 break; case 1: window = SDL.SDL_CreateWindow(Game.TITLE,SDL.SDL_WINDOWPOS_CENTERED,SDL.SDL_WINDOWPOS_CENTERED,Game.RESOLUTIONX,Game.RESOLUTIONY,SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); break; } if(window == IntPtr.Zero) { Console.WriteLine("Could Not Create Window. Error:"+SDL.SDL_GetError()); Network.reporterror("WindowOpenFailure",true);//15mar2021 SDL.SDL_Quit(); return; } SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_JPG | SDL_image.IMG_InitFlags.IMG_INIT_PNG); SDL_ttf.TTF_Init(); // var renderer = IntPtr.Zero; renderer = SDL.SDL_CreateRenderer(window,-1,SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED); // if(SDL_mixer.Mix_Init(SDL_mixer.MIX_InitFlags.MIX_INIT_MP3)<0) { Console.WriteLine("Could Not Initialise Audio Mixer. Error:"+SDL.SDL_GetError()); Network.reporterror("MixerOpenFailure",false);//15mar2021 } if(SDL_mixer.Mix_OpenAudio(SDL_mixer.MIX_DEFAULT_FREQUENCY,SDL_mixer.MIX_DEFAULT_FORMAT,8,1024)<0) { Console.WriteLine("Could Not Open Audio Mixer. Error:"+SDL.SDL_GetError()); Network.reporterror("MixerOpenFailure",false);//15mar2021 } game(window,renderer); LocalStorage.finalise();//12mar2021 // SDL_mixer.Mix_CloseAudio(); SDL_mixer.Mix_Quit(); // SDL_ttf.TTF_Quit(); SDL_image.IMG_Quit(); SDL.SDL_DestroyRenderer(renderer); SDL.SDL_DestroyWindow(window); SDL.SDL_Quit(); } ///////////////////Method Definition/////////////// static void loadprogress(Game game, string txt) { //not used RenderList.drawtext(game,800,400,txt,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); } ///////////////////Method Definition/////////////// static void resourceload(Game game) { //load all resources for the game here //call this prior to entering the main game loop //Resources.loadingbk = Resources.LoadAnimImage(game,"media/gui/loading.png",game.renderer,648,100,1,1);//27mar2021 //Resources.loadingbar = Resources.LoadAnimImage(game,"media/gui/loadinglight.png",game.renderer,8,100,81,1);//27mar2021 Resources.blackcat = Resources.LoadAnimImage(game,"media/gui/black.png",game.renderer,64,64,1,1); Resources.LOGO = Resources.LoadAnimImage(game,Config.logofile,game.renderer,Config.logowidth,Config.logoheight,1,1); Resources.FOG = Resources.LoadAnimImage(game,Config.fogfile,game.renderer,Config.fogwidth,Config.fogheight,1,1); Resources.FONT = Resources.LoadFont(game,Config.defaultfontfile,Config.normalfontsize); Game.LoadingPct = 0; Resources.SMALLFONT = Resources.LoadFont(game,Config.defaultfontfile,Config.smallfontsize); Resources.LARGEFONT = Resources.LoadFont(game,Config.defaultfontfile,Config.largefontsize); Game.LoadingProgress(game); Resources.LoadGui(game,Config.guifile); Game.LoadingProgress(game); Resources.LoadTemplates(game,Config.unitsfile); Game.LoadingProgress(game); Resources.LoadCampaign(game,Config.campaignfile); Game.LoadingProgress(game); Resources.LoadTech(game,Config.techfile);//2sep2021 Game.LoadingProgress(game); Gui.matchcampaign(game); //28Feb2021 Resources.CLICK = Resources.LoadAudio(game,Config.audioclickfile,false); Resources.AssignOffsets(game,Config.offsetfile);//20apr2021 Game.LoadingProgress(game); Resources.intro = Resources.LoadAnimImage(game,"media/gui/intro.jpg",game.renderer,400,225,10,10);//28feb2022 Game.LoadingProgress(game); Resources.outro = Resources.LoadAnimImage(game,"media/gui/outro.jpg",game.renderer,400,225,7,7);//28feb2022 Game.LoadingProgress(game); Resources.outrobad = Resources.LoadAnimImage(game,"media/gui/outrobad.jpg",game.renderer,3911,900,1,1);//28feb2022 Game.LoadingProgress(game); Resources.page01 = Resources.LoadAnimImage(game,"media/gui/01.jpg",game.renderer,1600,900,1,1);//28feb2022 Game.LoadingProgress(game); Resources.credits = Resources.LoadAnimImage(game,"media/gui/credits.png",game.renderer,1600,900,1,1);//28feb2022 Game.LoadingProgress(game); //Game.clicker = Resources.LoadAnimImage(game,"media/gui/clicker.png",game.renderer,32,32,8,2);//15apr2021 //Game.targeticon = Resources.LoadAnimImage(game,"media/gui/targeticon.png",game.renderer,64,64,1,1);//16apr2021 Emitter.pimages = null;//22apr2022 Game.LoadingProgress(game); Emitter.Reset(game);//22apr2022 Particle.Reset();//22apr2022 Game.LoadingProgress(game); } //static void drawloadingbar(Game game,int w,int pct,int offy) //27mar2021 //{ // if(Resources.loadingbk!=-1 && Resources.loadingbar!=-1) // { // int f = (pct * game.images[Resources.loadingbar].cwn) / 100; // for(int i=0;i1) { alpha = 1f; } if(sx>1) { sx = 1f; } if(sy>1) { sy = 1f; } RenderList.drawimage(game,game.images[Resources.LOGO].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,1,1,0,0,false,alpha,Resources.LOGO); //if(game.frame>180)27mar2021 if(fr>180)//27mar2021 { game.gamestate=Game.CAT_GAMESTATE_MENU; Config.loaded = false; Config.loadpct = 0; //debugging //game.gamestate=Game.CAT_GAMESTATE_INTRO; //Game.outroframe = 0; //Game.outrodelay = 10; } } ///////////////////Method Definition/////////////// public static void drawintro(Game game)//28feb2022 { float alpha = 1f; if(Game.outroframe > 86) { alpha = (float)(96 - Game.outroframe)/10f; } string txt = Translation.TranslateWord("Transport en-route to Warzone.....",false); int l = 1 + ((Game.outroframe * txt.Length) / 70); if(l>txt.Length) { l = txt.Length; } txt = txt.Substring(0,l); RenderList.drawanimimage(game,game.images[Resources.intro].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,4,4,Game.outroframe,0,false,alpha,Resources.intro); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 330,txt,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 410,Translation.TranslateWord("The End",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); Game.outrodelay--; if(Game.outrodelay<=0) { Game.outrodelay = 5; Game.outroframe++; if(Game.outroframe>96) { game.gamestate=Game.CAT_GAMESTATE_GAME; Game.outroframe = 0; } } if(game.mlclick) { game.gamestate=Game.CAT_GAMESTATE_GAME; Game.outroframe = 0; } } ///////////////////Method Definition/////////////// public static void drawoutro(Game game)//28feb2022 { float alpha = 1f; if(Game.outroframe > 33) { alpha = (float)(43 - Game.outroframe)/10f; } RenderList.drawanimimage(game,game.images[Resources.outro].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,4,4,Game.outroframe,0,false,alpha,Resources.outro); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 380,Translation.TranslateWord("You Return Home A Hero From Your Tour Of Duty",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 410,Translation.TranslateWord("The End",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); Game.outrodelay--; if(Game.outrodelay<=0) { Game.outrodelay = 15; Game.outroframe++; if(Game.outroframe>43) { game.gamestate=Game.CAT_GAMESTATE_CREDITS2; Game.outroframe = 0; } } if(game.mlclick) { game.gamestate=Game.CAT_GAMESTATE_MENU; Game.outroframe = 0; } } ///////////////////Method Definition/////////////// public static void drawoutrobad(Game game)//28feb2022 { int x = - Game.outroframe; if(Game.outroframe > 3911 - 1600) { x = - (3911 - 1600); } RenderList.drawanimimage(game,game.images[Resources.outrobad].texture,x + (3911/2),Game.RESOLUTIONY/2,0,1,1,0,0,false,1,Resources.outrobad); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 380,Translation.TranslateWord("You were killed in the line of duty. There was a small but loving funeral.",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2 + 410,Translation.TranslateWord("The End",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); { Game.outroframe++; if(Game.outroframe>3911 - 1600 + 60*5) { game.gamestate=Game.CAT_GAMESTATE_CREDITS2; Game.outroframe = 0; } } if(game.mlclick) { game.gamestate=Game.CAT_GAMESTATE_MENU; Game.outroframe = 0; } } ///////////////////Method Definition/////////////// public static void drawcredits(Game game)//28feb2022 { RenderList.drawanimimage(game,game.images[Resources.page01].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,1,1,0,0,false,1,Resources.page01); RenderList.drawanimimage(game,game.images[Resources.credits].texture,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,0,1,1,0,0,false,1,Resources.credits); { Game.outroframe++; if(Game.outroframe>60*10) { game.gamestate=Game.CAT_GAMESTATE_MENU; Game.outroframe = 0; } } if(game.mlclick) { game.gamestate=Game.CAT_GAMESTATE_MENU; Game.outroframe = 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) { //apply all mission settings prior to starting the mission //start--------//17sep2021 Game.EXITPRESSED = 0;//1mar2022 //start------//4mar2022 Config.Season = Functions.rand(1,100) % 3; if(Config.Season<0) { Config.Season*=-1; Config.Season%=3; } //end-------//4mar2022 bool minimap = false; if(tutorial==99) { minimap = true; tutorial = 2; } //end----------//17sep2021 MapThread.complete = false;//29may2021 if(!Replay.PLAYBACK)//2apr2021 { 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); string folder = ""; try { folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"/"+Game.NETTITLE; if(!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } catch(Exception e) { string message = e.Message; } if(mission<0 && mission!=-999 && tutorial==0) { try { string[] savegame = System.IO.File.ReadAllLines(folder+"/"+"savegame.txt"); if(savegame.Length>0) { Int32.TryParse(savegame[0],out mission); } } catch(Exception e) { Console.WriteLine(e.Message); } } 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; try { System.IO.File.WriteAllText(folder+"/"+"savegame.txt",""+mission); } catch(Exception e) { Console.WriteLine(e.Message); } } } 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!="") { for(int mi=0;mi 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; } } //Console.WriteLine("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; } //Console.WriteLine("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 { int mainfloor = 0;//25sep2021 int secondaryfloor = 0;//25sep2021 int thirdfloor = 0;//25sep2021 bool other = false;//25sep2021 int its = 0; int row1 = 0; int row2 = 0; int row3 = 0; int[] assigned = new int[Map.MAXX * Map.MAXY]; if(game.missions[mission].floorpattern==2 && Map.tileframes>4)//25sep2021 { for(int x=1;x100) { break; } } its = 0; while(thirdfloor == mainfloor || thirdfloor<0 || thirdfloor == secondaryfloor) { its++; thirdfloor = Functions.rand(0,1000) % Map.tileframes;//25sep2021 if(its>100) { break; } } } Map.tileimage[x + y * Map.MAXX] = mainfloor; if(Map.wallimage[x + y * Map.MAXX] != -1) { for(int ix=x-1;ix=0 && iy>=0 && ix4 && y>4 && x3) { mainfloor = Functions.rand(0,1000) % 3;//25sep2021 secondaryfloor = Functions.rand(0,1000) % 3;//25sep2021 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; } } thirdfloor = 0;//25sep2021 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(); } //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.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); } } } ///////////////////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 && Config.Night>0)// && (game.gamestate==Game.CAT_GAMESTATE_GAME || game.gamestate==Game.CAT_GAMESTATE_REPLAY)) { RenderList.drawtext(game,1380,Game.RESOLUTIONY - 20,Translation.TranslateWord("Night Battles Currently",false),RenderList.getrgb(255,255,200),game.fonts[Resources.SMALLFONT].font,false);//3jun2021 } //end--------//24feb2022 if(Game.targeticon!=-1)//16apr2021 { if(Game.mouseoverunitid!=-1) { if(Game.anyselected) { int i = Game.mouseoverunitid; if(game.units[i].faction==Game.SKIRMISHENEMYFACTION && game.units[i].hp>0) { //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; } /* if(!Config.loaded) { if((game.frame % 20)==0) { Config.loadpct+=(int)Functions.rand(5,25); } if(Config.loadpct>100) { Config.loaded = true; Config.loadpct = 100; } RenderList.drawtext(game,800,800,"Loading..."+Config.loadpct+"%",RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); } */ 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 drawcreditsinfo(Game game) { string[] consoletext = new string[3]; consoletext[0] = "Art, Design, Development, Programming"; consoletext[1] = Game.AUTHOR + " " + Game.YEAR; consoletext[2] = "Music by Eric Matyas, soundimage.org"; int a = 3; for(int i=0;i0) { 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,"----------------------------------------------------------------------------",RenderList.getrgb(200,200,200),game.fonts[Resources.FONT].font,true); iiline++; } //RenderList.drawtext(game,500,yb + iiline * game.fonts[Resources.FONT].ptsize,game.templates[i].name,color,game.fonts[Resources.FONT].font,false); //13mar2021 //RenderList.drawtext(game,700,yb + iiline * game.fonts[Resources.FONT].ptsize,""+game.templates[i].dispcreates,color,game.fonts[Resources.FONT].font,false);//13mar2021 //RenderList.drawtext(game,900,yb + iiline * game.fonts[Resources.FONT].ptsize,""+game.templates[i].dispkills,color,game.fonts[Resources.FONT].font,false);//13mar2021 //RenderList.drawtext(game,1100,yb + iiline * game.fonts[Resources.FONT].ptsize,""+game.templates[i].dispdeaths,color,game.fonts[Resources.FONT].font,false);//13mar2021 RenderList.drawtext(game,400,yb + iiline * game.fonts[Resources.FONT].ptsize,game.templates[i].dname(),color,game.fonts[Resources.FONT].font,false); //13mar2021 RenderList.drawtext(game,700,yb + iiline * 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 * 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 * game.fonts[Resources.FONT].ptsize,""+Translation.TranslateNumber(game.templates[i].dispdeaths),color,game.fonts[Resources.FONT].font,false);//13mar2021 updatestats(game); } } //1mar2022 added the mission score... iiline++; RenderList.drawtext(game,800,yb + iiline * game.fonts[Resources.FONT].ptsize,"----------------------------------------------------------------------------",RenderList.getrgb(200,200,200),game.fonts[Resources.FONT].font,true); iiline++; RenderList.drawtext(game,400,yb + iiline * game.fonts[Resources.FONT].ptsize,Translation.TranslateWord("Mission Score:",false)+Game.MissionScore + " " + Translation.TranslateWord("Top Score:",false) + Game.TopScore,color,game.fonts[Resources.FONT].font,false); iiline++; } ///////////////////Method Definition/////////////// static void update(Game game) { //core game update routine //handles all updates Stopwatch utimer = new Stopwatch(); utimer.Start(); long bmenutime = 0; long umusictime = 0; long mapupdatepostime = 0; long mapcorrecttime = 0; long unitupdatetime = 0; long bullettime = 0; long bloodtime = 0; long selecttime = 0; long triggertime = 0; long drawtime = 0; Game.newtrees = new int[0];//24apr2021 //int dieroll = Functions.rand(0,100);//2apr2021 //start---------------------//20apr2021 if(Config.AUTOCALCOFFSETS==true && Config.FINISHEDOFFSETS==false) { for(int i=0;i0) { Game.selectingtime--; } //end-----------------//26mar2021 if(game.gamestate==Game.CAT_GAMESTATE_LOGO) { //if(game.frame<100) //27mar2021 //{ //drawloadingbar(game,648,game.frame,300); //return; //} drawlogo(game); return; } if(game.gamestate==Game.CAT_GAMESTATE_OUTRO) { drawoutro(game); return; } if(game.gamestate==Game.CAT_GAMESTATE_INTRO) { drawintro(game); return; } if(game.gamestate==Game.CAT_GAMESTATE_OUTROBAD) { drawoutrobad(game); return; } if(game.gamestate==Game.CAT_GAMESTATE_CREDITS2) { drawcredits(game); return; } //END RTS // bmenutime = utimer.ElapsedMilliseconds; basemenus(game); bmenutime = Math.Abs(utimer.ElapsedMilliseconds - bmenutime); umusictime = utimer.ElapsedMilliseconds; Map.updatemusic(game); umusictime = Math.Abs(utimer.ElapsedMilliseconds - umusictime); if(game.gamestate==Game.CAT_GAMESTATE_GAME) { if(Game.editkeypressed==10) { Game.editkeypressed=11; Game.EDITOR = true; //start----------//5apr2021 try { Network.url = "https://www.mattiesgames.com/metrics/metric.php?game=kog2mission&event=editor&value=1&uid="+Config.uid;//30mar2021 Network.httpget(Network.url); } catch(Exception e) { string message = e.Message; } //end-----------//5apr2021 Game.EDITORPFACTION = Game.PLAYERFACTION; //22mar2021 Game.EDITOREFACTION = Game.SKIRMISHENEMYFACTION; //22mar2021 Functions.saveseed(Functions.seed); game.zoom = 0; game.mwheel = 0; game.playerready = false; game.playingtutorial = false; game.skirmish = false; game.victorymessage = false; cleardeaths(game); game.playingtutorial = false; Game.GAMEENDSTATE = 0; game.gameovertime = 0; game.paused = false; Map.adddecor();//2mar2021 Map.marktreepos(game); return; } if(Game.EDITOR) { if(Game.backupkeypressed>=10) { Game.backupkeypressed = 0; try { System.Diagnostics.Process.Start(@"restoreall.bat"); Console.WriteLine("Original Settings Restored"); } catch(Exception eee) { Console.WriteLine(eee.Message); } } } else { Game.backupkeypressed = 0; } game.demomode = false; mapupdatepostime = Math.Abs(utimer.ElapsedMilliseconds); Map.updatepos(ref game); mapupdatepostime = Math.Abs(utimer.ElapsedMilliseconds - mapupdatepostime); if((game.frame % 121)==0 && Config.RUNNINGSPEED<90) { mapcorrecttime = utimer.ElapsedMilliseconds; Map.correct(game); mapcorrecttime = Math.Abs(utimer.ElapsedMilliseconds - mapcorrecttime); } unitupdatetime = utimer.ElapsedMilliseconds; if(!Game.togglepause)//22mar2021 { Unit.updateall(game); //this is where optimisation will make the most difference.... Tech.updateall(game);//2sep2021 } unitupdatetime = Math.Abs(utimer.ElapsedMilliseconds - unitupdatetime); if(!Game.EDITOR) { if(!Game.togglepause)//22mar2021 { bullettime = utimer.ElapsedMilliseconds; Bullet.updateall(game); bullettime = Math.Abs(utimer.ElapsedMilliseconds - bullettime); bloodtime = utimer.ElapsedMilliseconds; Blood.updateall(game); bloodtime = Math.Abs(utimer.ElapsedMilliseconds - bloodtime); Gibbet.updateall(game);//2apr2021 Emitter.UpdateAll(game);//22apr2022 Particle.UpdateAll(game);//22apr2022 } handlezoom(game); } else { handleedit(game); Game.recordkeypressed = 0; } RenderList.IGNOREZOOM = false; drawtime = utimer.ElapsedMilliseconds; Game.mouseoverunitid = -1; //24mar2021 Unit.drawall(game); if(!Game.EDITOR) { Bullet.drawall(game); Blood.drawall(game); Gibbet.drawall(game);//2apr2021 Particle.DrawAll(game);//22apr2022 } else { //13mar2021 editor not translated yet..... if(Game.editname!="") { RenderList.drawtext(game,game.mx,game.my,Game.editname+","+Game.editgridx+","+Game.editgridy,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true); } //RenderList.drawtext(game,0,800,"w-Wall Mode,r-Rock Mode,t-Tree Mode,u-Unit Mode,x-Triggers,o-Map File,c-Campaign File,Left Mouse Place, Right Mouse Remove",RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//22mar2021 RenderList.drawtext(game,0,800,Translation.TranslateWord("w-Wall Mode,r-Rock Mode,t-Tree Mode,u-Unit Mode,x-Triggers,o-Map File,c-Campaign File,Left Mouse Place, Right Mouse Remove",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//22mar2021 RenderList.drawtext(game,0,830,Translation.TranslateWord("TAB - Test Map",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//6mar2022 if(Config.USEHEIGHTS>0) { //RenderList.drawtext(game,0,830,"h-Height Mode",RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);/22mar2021 RenderList.drawtext(game,0,830,Translation.TranslateWord("h-Height Mode",false),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//22mar2021 } //RenderList.drawtext(game,0,860,"Map Saved In:"+Config.custommapfolder,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//22mar2021 RenderList.drawtext(game,0,860,Translation.TranslateWord("Map Saved In:",false)+Config.custommapfolder,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,false);//22mar2021 if(Game.EDITMODE==Game.EDITMODE_TRIGGER || Game.EDITMODE==Game.EDITMODE_ENTERTEXT) { RenderList.drawtext(game,0,700,TriggerHelper.constructorstring(game,false,false,0),RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false); //RenderList.drawtext(game,0,750,"INFO: You will have to edit the triggers in a text file for some features.",RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 RenderList.drawtext(game,0,750,Translation.TranslateWord("INFO: You will have to edit the triggers in a text file for some features.",false),RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 if(Game.EDITMODE==Game.EDITMODE_ENTERTEXT) { if(Game.edittriggerstring.Length>0) { if(game.frame % 60 < 30) { RenderList.drawtext(game,0,725,Game.edittriggerstring+"__",RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false); } else { RenderList.drawtext(game,0,725,Game.edittriggerstring,RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false); } } else { if(game.frame % 60 < 30) { //RenderList.drawtext(game,0,725,"[CHATTER]__",RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 RenderList.drawtext(game,0,725,Translation.TranslateWord("[CHATTER]__",false),RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 } else { //RenderList.drawtext(game,0,725,"[CHATTER]",RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 RenderList.drawtext(game,0,725,Translation.TranslateWord("[CHATTER]",false),RenderList.getrgb(32,32,32),game.fonts[Resources.SMALLFONT].font,false);//22mar2021 } } } for(int i=0;i 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 diffx = Game.CORNERX - Game.TMPCORNERX; int diffy = Game.CORNERY - Game.TMPCORNERY; RenderList.drawunfilledrect(game,diffx + x - 1,diffy + y - 1,w,h,RenderList.getrgb(24,170,24),0); RenderList.drawunfilledrect(game,diffx + x + 1,diffy + y + 1,w,h,RenderList.getrgb(24,170,24),0); RenderList.drawunfilledrect(game,diffx + x,diffy + y,w,h,RenderList.getrgb(32,255,32),0); 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 { //freeze selection until a command is chosen.... if(Unit.noneselected(game)) { //Unit.selectone(game); int mmx = (int)((float)(game.mx - Game.RESOLUTIONX/2)/game.zoom) + Game.CORNERX + Game.RESOLUTIONX/2; int mmy = (int)((float)(game.my - Game.RESOLUTIONY/2)/game.zoom) + Game.CORNERY + Game.RESOLUTIONY/2; Unit.select(game,mmx,mmy,-1,-1); } Unit.freezeselect(game); } //if(game.mrclick && !game.paused)//22mar2021 if(game.mrclick && !game.paused && !Game.togglepause)//22mar2021 { 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); } selecttime = Math.Abs(utimer.ElapsedMilliseconds - selecttime); Game.CORNERX = Game.TMPCORNERX;//21apr2021 Game.CORNERY = Game.TMPCORNERY;//21apr2021 } else { if(game.demomode) { RenderList.IGNOREZOOM = true;//18sep2021 if(Config.NOUPDATEINDEMOMODE==0)//18sep2021 { Map.updatepos(ref 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 Emitter.UpdateAll(game);//22apr2022 Particle.UpdateAll(game);//22apr2022 //RenderList.IGNOREZOOM = true;//18sep2021 Unit.drawall(game); Bullet.drawall(game); Blood.drawall(game); Gibbet.drawall(game);//2apr2021 Particle.DrawAll(game);//22apr2022 } Game.editkeypressed = 0; //22mar2021 //RenderList.drawtext(game,1400,845,"Version"+Game.VERSION,RenderList.getrgb(255,255,200),game.fonts[Resources.SMALLFONT].font,false); //RenderList.drawtext(game,1400,860,Game.AUTHOR+" "+Game.YEAR,RenderList.getrgb(255,255,200),game.fonts[Resources.SMALLFONT].font,false); //RenderList.drawtext(game,1400,875,Game.MUSIC,RenderList.getrgb(255,255,200),game.fonts[Resources.SMALLFONT].font,false); } } guimenus(game); if(game.gamestate==10000 || game.gamestate==10088)//bestiary or main menu//1mar2022 { Game.DisplayQuote(game); } if(Replay.PLAYBACK)//2apr2021 { if(Replay.CHECKSUMBROKEN!=-1) { RenderList.drawtext(game,30,870,"err:"+Replay.CHECKSUMBROKEN,RenderList.getrgb(255,255,200),game.fonts[Resources.SMALLFONT].font,false); } } if(game.gamestate==Game.CAT_GAMESTATE_DEBRIEF || game.gamestate==Game.CAT_GAMESTATE_DEBRIEF2) { drawdebriefbk(game); } //if(game.gamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false)//18apr2021 if(game.oldgamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false)//18apr2021 { triggertime = utimer.ElapsedMilliseconds; 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); } if(game.missions!=null) //&& game.skirmish==false) { if(game.missionid>=0 && game.missionid0)//1mar2022 { //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 + (j * game.fonts[Resources.SMALLFONT].ptsize * 2),Translation.TranslateWord("Mission Score:",false)+":"+Translation.TranslateNumber(Game.MissionScore),RenderList.getrgb(200,200,180),game.fonts[Resources.SMALLFONT].font,false);//13mar2021 } } } } triggertime = Math.Abs(utimer.ElapsedMilliseconds - triggertime); } 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 && Replay.PLAYBACK==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.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; Game.MissionScore+=Trigger.VARIABLE[Trigger.TYPE_POINTS];//1mar2022 Game.TopScore = 0;//1mar2022 try//1mar2022 { Int32.TryParse(LocalStorage.getitem("topscore_"+game.missionid),out Game.TopScore); } catch(Exception e) { Console.WriteLine(e.Message); } if(Game.MissionScore>Game.TopScore)//1mar2022 { Game.TopScore = Game.MissionScore;//1mar2022 LocalStorage.setitem("topscore_"+game.missionid,""+Game.TopScore); } //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; Game.MissionScore+=Trigger.VARIABLE[Trigger.TYPE_POINTS];//1mar2022 try//1mar2022 { Int32.TryParse(LocalStorage.getitem("topscore_"+game.missionid),out Game.TopScore); } catch(Exception e) { Console.WriteLine(e.Message); } if(Game.MissionScore>Game.TopScore)//1mar2022 { Game.TopScore = Game.MissionScore;//1mar2022 LocalStorage.setitem("topscore_"+game.missionid,""+Game.TopScore); } cleardeaths(game); //this next bit is for the final mission - if we win it....then we should go to the outro..... if(game.nextmissionid==-1 && game.skirmish==false && game.playingtutorial==false && Game.GAMEENDSTATE!=Game.GAMEENDSTATE_DEFEAT)//28feb2022 { game.gamestate = Game.CAT_GAMESTATE_OUTRO; Game.outroframe = 0; Game.outrodelay = 10; } if(game.nextmissionid==-1 && game.skirmish==false && game.playingtutorial==false && Game.GAMEENDSTATE==Game.GAMEENDSTATE_DEFEAT && Game.EXITPRESSED==0)//28feb2022 { game.gamestate = Game.CAT_GAMESTATE_OUTROBAD; Game.outroframe = 0; Game.outrodelay = 10; } } } 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; Game.MissionScore+=Trigger.VARIABLE[Trigger.TYPE_POINTS];//1mar2022 try//1mar2022 { Int32.TryParse(LocalStorage.getitem("topscore_"+game.missionid),out Game.TopScore); } catch(Exception e) { Console.WriteLine(e.Message); } if(Game.MissionScore>Game.TopScore)//1mar2022 { Game.TopScore = Game.MissionScore;//1mar2022 LocalStorage.setitem("topscore_"+game.missionid,""+Game.TopScore); } //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); } } } utimer.Reset(); if(bmenutime > Config.maxbmenutime || game.frame % 300 == 0) { Config.maxbmenutime = bmenutime; } if(umusictime > Config.maxumusictime || game.frame % 300 == 0) { Config.maxumusictime = umusictime; } if(mapupdatepostime > Config.maxmapupdatepostime || game.frame % 300 == 0) { Config.maxmapupdatepostime = mapupdatepostime; } if(mapcorrecttime > Config.maxmapcorrecttime || game.frame % 300 == 0) { Config.maxmapcorrecttime = mapcorrecttime; } if(unitupdatetime > Config.maxunitupdatetime || game.frame % 300 == 0) { Config.maxunitupdatetime = unitupdatetime; } if(bullettime > Config.maxbullettime || game.frame % 300 == 0) { Config.maxbullettime = bullettime; } if(bloodtime > Config.maxbloodtime || game.frame % 300 == 0) { Config.maxbloodtime = bloodtime; } if(selecttime > Config.maxselecttime || game.frame % 300 == 0) { Config.maxselecttime = selecttime; } if(triggertime > Config.maxtriggertime || game.frame % 300 == 0) { Config.maxtriggertime = triggertime; } if(drawtime > Config.maxdrawtime || game.frame % 300 == 0) { Config.maxdrawtime = drawtime; } } ///////////////////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. string folder = ""; try { folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"/"+Game.NETTITLE; if(!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string[] savegame = System.IO.File.ReadAllLines(folder+"/"+"savegame.txt"); if(savegame.Length>0) { Int32.TryParse(savegame[0],out Game.maxmission); } } catch(Exception e) { Console.WriteLine(e.Message); } if(Config.KOG2) //12mar2021 { Game.maxmission = 36; } if(Game.maxmission > Game.overridemaxmission)//13sep2021 { Game.maxmission = Game.overridemaxmission;//13sep2021 } } ///////////////////Method Definition/////////////// static void game(IntPtr window,IntPtr renderer) { //contains core game loop //perform initialisation of loading resource calls //and then enters core game loop Game game = new Game(renderer); game.takepicture = false; game.window = window; game.screen = SDL.SDL_GetWindowSurface(window); Stopwatch gametimer = new Stopwatch(); SDL.SDL_Event e; SDL.SDL_MouseMotionEvent m; m.x = 0; m.y = 0; bool quit = false; Map.menumusic = -1; Map.menumusicplaying = -1; resourceload(game); getmaxmission(game); Network.reporterror(true);//15mar2021 updateaudio(game); gametimer.Start(); if(!Config.FREEDEMO)//26apr2021 { Config.freedemo = 0; } if(Config.freedemo>0)//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; } //26mar2021 commented out the if statement and surrounds//calling network command each time now.... //string playedonce = LocalStorage.getitem("start"); //19mar2021 //if(playedonce!="1") //19mar2021 (and inside) //{ //Network.url = "https://www.mattiesgames.com/metrics/launch.php?game=grumthorr";//15mar2021//30mar2021 Network.url = "https://www.mattiesgames.com/metrics/launch.php?game=grumthorr&uid="+Config.uid+"&version="+Game.VERSIONSTR;//30mar2021//14apr2021 added version string.... Network.httpget(Network.url);//15mar2021 // LocalStorage.setitem("start","1"); // LocalStorage.finalise(); //} resetgame(game); long maxutime = 0; long maxrtime = 0; //while(!quit)//15mar2021 //start---------------//26mar2021 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 if(Game.EDITOR) { try { Network.url = "https://www.mattiesgames.com/metrics/metric.php?game=kog2mission&event=editor&value=1&uid="+Config.uid;//30mar2021 Network.httpget(Network.url); } catch(Exception ffe) { string message = ffe.Message; } } //end-----------//5apr2021 bool usedelta = false;//18sep2021 if(Config.USEDELTATIME>0)//18sep2021 { usedelta = true;//18sep2021 } Config.delta = 100;//18sep2021 Stopwatch pausetimer = new Stopwatch();//28feb2022 bool opause = Game.togglepause;//28feb2022 while(quit==false || RenderList.threadrunning==true)//15mar2021 { //start-------//28feb2022 if(opause!=Game.togglepause) { if(Game.togglepause) { pausetimer.Reset(); pausetimer.Start(); Trigger.VARIABLE[Trigger.TYPE_PAUSETIMER] = 0; } else { if(game.gamestate==Game.CAT_GAMESTATE_GAME || game.gamestate==Game.CAT_GAMESTATE_REPLAY) { Trigger.VARIABLE[Trigger.TYPE_PAUSETIMER] = Convert.ToInt32(pausetimer.ElapsedMilliseconds); } pausetimer.Stop(); } } opause = Game.togglepause; //end--------//28feb2022 //start--------//18sep2021 if(Config.UNLOCKFRAMERATE>0) { Config.FRAMETIME = 1000 / (uint)Config.UNLOCKFRAMERATE; } if(usedelta && Game.FRAMERATE>0)// && deltafps>0) { if(Config.UNLOCKFRAMERATE>0) { Config.delta = (100 * Config.UNLOCKFRAMERATE) / Game.FRAMERATE; if(Config.delta < 100) { Config.delta = 100; } if(Config.delta > 500) { Config.delta = 500; } } else { Config.delta = 100; } } else { Config.delta = 100; } //end-----//18sep2021 if(Game.EDITOR)//22mar2021 { Game.togglepause = false; } //start-------------//28Feb2021 StreamResources.streamloadhelper(game); //if(game.gamestate==Game.CAT_GAMESTATE_GAME) //2apr2021 if(game.gamestate==Game.CAT_GAMESTATE_GAME || game.gamestate==Game.CAT_GAMESTATE_REPLAY)//2apr2021 { StreamResources.TOLERANCE = StreamResources.LONGTOLERANCE; } else { StreamResources.TOLERANCE = StreamResources.SHORTTOLERANCE; Game.togglepause = false;//22mar2021 } //end---------------//28Feb2021 //start------------//29may2021 if(game.oldgamestate==Game.CAT_GAMESTATE_GAME || game.oldgamestate==Game.CAT_GAMESTATE_REPLAY)//29may2021 { if(Config.THREADEDPATHING)//29may2021 { MapThread.init();//29may2021 } } //end--------------//29may2021 if(!Game.togglepause)//12apr2021 { game.frame++; } game.getmouse(); Game.formation = 0;//2apr2021 if(game.mldown) //14apr2021 { Game.HORIZONTALFORMATION = 0; Game.VERTICALFORMATION = 0; } int k = -1; while(SDL.SDL_PollEvent(out e) != 0) { switch(e.type) { case SDL.SDL_EventType.SDL_QUIT: quit = true; break; case SDL.SDL_EventType.SDL_KEYDOWN: switch(e.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_BACKSPACE: if(Game.EDITMODE==Game.EDITMODE_ENTERTEXT && Game.EDITOR==true) { if(Game.edittriggerstring.Length>0 && (game.frame % 20 < 10)) { Game.edittriggerstring = Game.edittriggerstring.Substring(0,Game.edittriggerstring.Length-1); } } break; //start--------------------//2apr2021 case SDL.SDL_Keycode.SDLK_ESCAPE: if(Replay.PLAYBACK && Replay.FRAME>0) { Replay.FRAME = Game.replay[0].mx.Length + 100; //cheap and nasty way of getting out of it..... } break; //end----------------------//2apr2021 case SDL.SDL_Keycode.SDLK_LSHIFT: Game.editshiftheld = true; break; case SDL.SDL_Keycode.SDLK_RSHIFT: Game.editshiftheld = true; break; case SDL.SDL_Keycode.SDLK_LCTRL: Game.leftcontrolkey = 1; break; case SDL.SDL_Keycode.SDLK_0: k = 0; break; case SDL.SDL_Keycode.SDLK_1: k = 1; break; case SDL.SDL_Keycode.SDLK_2: k = 2; break; case SDL.SDL_Keycode.SDLK_3: k = 3; break; case SDL.SDL_Keycode.SDLK_4: k = 4; break; case SDL.SDL_Keycode.SDLK_5: k = 5; break; case SDL.SDL_Keycode.SDLK_6: k = 6; break; case SDL.SDL_Keycode.SDLK_7: k = 7; break; case SDL.SDL_Keycode.SDLK_8: k = 8; break; case SDL.SDL_Keycode.SDLK_9: k = 9; break; } if(k!=-1 && Game.leftcontrolkey>0) { Game.numberkeys[k]=1; } break; case SDL.SDL_EventType.SDL_KEYUP: if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_PRINTSCREEN) { game.takepicture = true; } if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_F5)//22apr2022 { Emitter.pimages = null; Emitter.Reset(game); Particle.Reset(); } if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_TAB) { //6mar2022 if(Game.EDITOR) { Game.EDITOR = false;//6mar2022 Game.editkeypressed = 0;//6mar2022 //22apr2022 altered this....whole section.... //Game.PLAYERFACTION = 6; //Game.SKIRMISHENEMYFACTION = 5; bool first = false; bool second = false; for(int u=0;u0 && game.units[u].faction!=Unit.NULLFACTION) { if(!first) { first = true; Game.PLAYERFACTION = game.units[u].faction; } if(!second && first) { if(game.units[u].faction!=Game.PLAYERFACTION) { Game.SKIRMISHENEMYFACTION = game.units[u].faction; second = true; } } } } } // //if(RenderList.RENDERMODE==RenderList.RENDERMODE_POOL) //{ // RenderList.RENDERMODE=RenderList.RENDERMODE_NONPOOL; //} //else //{ // RenderList.RENDERMODE=RenderList.RENDERMODE_POOL; //} } if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_LSHIFT) { Game.editshiftheld = false; } if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_RSHIFT) { Game.editshiftheld = false; } if(e.key.keysym.sym==SDL.SDL_Keycode.SDLK_BACKQUOTE) { //Config.DEBUG = !Config.DEBUG; } if(Game.EDITOR) { if(Game.EDITMODE!=Game.EDITMODE_ENTERTEXT) { switch(e.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_b: Game.backupkeypressed++; break; case SDL.SDL_Keycode.SDLK_h: if(Config.USEHEIGHTS>0) { Game.EDITMODE = Game.EDITMODE_HEIGHT; } break; case SDL.SDL_Keycode.SDLK_w: Game.EDITMODE = Game.EDITMODE_WALL; break; case SDL.SDL_Keycode.SDLK_r: Game.EDITMODE = Game.EDITMODE_ROCK; break; case SDL.SDL_Keycode.SDLK_t: Game.EDITMODE = Game.EDITMODE_TREE; break; case SDL.SDL_Keycode.SDLK_u: Game.EDITMODE = Game.EDITMODE_UNIT; break; case SDL.SDL_Keycode.SDLK_x: Game.EDITMODE = Game.EDITMODE_TRIGGER; break; case SDL.SDL_Keycode.SDLK_o: Map.OPENMAP = true; Map.savemap(game); Map.OPENMAP = false; break; case SDL.SDL_Keycode.SDLK_c: Map.opencampaign(game); break; } } else { switch(e.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_RETURN: Game.edittriggerstring+="|"; break; case SDL.SDL_Keycode.SDLK_ESCAPE: Game.EDITMODE = Game.EDITMODE_TRIGGER; break; case SDL.SDL_Keycode.SDLK_BACKSPACE: if(Game.edittriggerstring.Length>0) { Game.edittriggerstring = Game.edittriggerstring.Substring(0,Game.edittriggerstring.Length-1); } break; } if(e.key.keysym.sym!= SDL.SDL_Keycode.SDLK_RETURN && e.key.keysym.sym!= SDL.SDL_Keycode.SDLK_BACKSPACE) { try { string mychar = (string)SDL.SDL_GetKeyName(e.key.keysym.sym); if(mychar.Length==1) { mychar = mychar.ToLower(); if(Game.editshiftheld) { mychar = mychar.ToUpper(); if(mychar=="1") { mychar = "!"; } if(mychar=="2") { mychar = "@"; } if(mychar=="3") { mychar = "#"; } if(mychar=="4") { mychar = "$"; } if(mychar=="5") { mychar = "%"; } if(mychar=="6") { mychar = "^"; } if(mychar=="7") { mychar = "&"; } if(mychar=="8") { mychar = "*"; } if(mychar=="9") { mychar = "("; } if(mychar=="0") { mychar = ")"; } if(mychar=="-") { mychar = "_"; } if(mychar=="=") { mychar = "+"; } if(mychar=="\\") { mychar = "|"; } if(mychar=="/") { mychar = "?"; } if(mychar==";") { mychar = ":"; } if(mychar=="[") { mychar = "{"; } if(mychar=="]") { mychar = "}"; } if(mychar==",") { mychar = "<"; } if(mychar==".") { mychar = ">"; } } Game.edittriggerstring+=mychar; } if(mychar.ToUpper()=="SPACE") { Game.edittriggerstring+=" "; } } catch(Exception f) { string message = f.Message; } } } } else { if(!Replay.PLAYBACK)//2apr2021 { switch(e.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_LCTRL: Game.leftcontrolkey = 0; break; //start-----------------//22mar2021 case SDL.SDL_Keycode.SDLK_PAUSE: if(game.gamestate==Game.CAT_GAMESTATE_GAME && Game.EDITOR==false) { Game.togglepause = !Game.togglepause; } break; //end-------------------//22mar2021 case SDL.SDL_Keycode.SDLK_e: Game.editkeypressed++; break; /* //9mar2021 case SDL.SDL_Keycode.SDLK_r: Game.recordkeypressed++; if(Game.recordkeypressed>9) { //Config.RECORD = !Config.RECORD; Game.recordkeypressed = 0; } break; */ //9mar2021 //start-------------//9mar2021 case SDL.SDL_Keycode.SDLK_o: //OPEN FORMATION Unit.Formation(game,Gui.ACTION_OPEN); Game.formation = Gui.ACTION_OPEN;//2apr2021 break; case SDL.SDL_Keycode.SDLK_c: //CLOSE FORMATION Unit.Formation(game,Gui.ACTION_CLOSE); Game.formation = Gui.ACTION_CLOSE;//2apr2021 break; case SDL.SDL_Keycode.SDLK_r: // RALLY FORMATION Unit.Formation(game,Gui.ACTION_RALLY); Game.formation = Gui.ACTION_RALLY;//2apr2021 break; case SDL.SDL_Keycode.SDLK_v: // VERTICAL LINE FORMATION Unit.Formation(game,Gui.ACTION_LINEV); Game.formation = Gui.ACTION_LINEV;//2apr2021 break; case SDL.SDL_Keycode.SDLK_h: // HORIZONTAL LINE FORMATION Unit.Formation(game,Gui.ACTION_LINEH); Game.formation = Gui.ACTION_LINEH;//2apr2021 break; case SDL.SDL_Keycode.SDLK_d: // DEFEND FORMATION Unit.Formation(game,Gui.ACTION_DEFEND); Game.formation = Gui.ACTION_DEFEND;//2apr2021 break; case SDL.SDL_Keycode.SDLK_a: // ENGAGE FORMATION Unit.Formation(game,Gui.ACTION_ENGAGE); Game.formation = Gui.ACTION_ENGAGE;//2apr2021 break; //end---------------//9mar2021 case SDL.SDL_Keycode.SDLK_0: k = 0; break; case SDL.SDL_Keycode.SDLK_1: k = 1; break; case SDL.SDL_Keycode.SDLK_2: k = 2; break; case SDL.SDL_Keycode.SDLK_3: k = 3; break; case SDL.SDL_Keycode.SDLK_4: k = 4; break; case SDL.SDL_Keycode.SDLK_5: k = 5; break; case SDL.SDL_Keycode.SDLK_6: k = 6; break; case SDL.SDL_Keycode.SDLK_7: k = 7; break; case SDL.SDL_Keycode.SDLK_8: k = 8; break; case SDL.SDL_Keycode.SDLK_9: k = 9; break; } if(k!=-1 && Game.leftcontrolkey==0) { Game.numberkeys[k]++; if(game.frame - Game.numberkeysframe[k]<=15) { Game.numberkeys[k]++; } Game.numberkeysframe[k] = game.frame; } }//2apr2021 } break; case SDL.SDL_EventType.SDL_MOUSEWHEEL: game.mwheel = e.wheel.y; break; } } long utime = gametimer.ElapsedMilliseconds; game.oldgamestate = game.gamestate; if(Config.ALLOWREPLAY )//2apr2021 { if(Replay.PLAYBACK) { //playback begins on frame 2 Replay.PlayReplay(game,Replay.FRAME); //sets mouse and other values.... Replay.FRAME++; } if(Replay.RECORD) { //recording begins on frame 2 Replay.RecordReplay(game); //mouse and running speeds etc will be set by now....as well as seeds.... } } if(RenderList.transitionmode0)//26apr2021 { Config.freedemo--; if(Config.freedemo==60*10) { game.gamestate = 10000 + 888; } if(Config.freedemo<=1) { quit = true; Game.restart = false; } RenderList.drawtext(game,800,850,"Demo Time Remaining:"+Functions.ClockTime(Config.freedemo / 60),RenderList.getrgb(220,220,180),game.fonts[Resources.FONT].font,true); } game.newgamestate = game.gamestate; //start-------------//12mar2021 if(game.gamestate!=game.oldgamestate) { if(game.gamestate==Game.CAT_GAMESTATE_GAME)//1mar2022 { Game.MissionScore = 0;//1mar2022 } Game.quoteindex = Functions.rand(0,100);//1mar2022 if(Game.quoteindex<0)//1mar2022 { Game.quoteindex*=-1;//1mar2022 } //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.EDITED>0) //7apr2021 {//7apr2021 Game.restart = true;//7apr2021 Game.EDITED = -1; }//7apr2021 if(Game.chosenmissionindex!=-1) { Game.previousmissionindex = Game.chosenmissionindex; } Game.chosenmissionindex = -1; Unit.MAXINDEX = 0;//26mar2021 Bullet.MAXINDEX = 0;//27mar2021 //moved elsewhere....//18apr2021//maybenot? //Functions.saveseed(Functions.seed);//2apr2021 //if((Functions.Rand(0,100) % 10)<7) //24mar2021 //{ // Gui.ALTMODE = !Gui.ALTMODE; //24mar2021 //} //Functions.restoreseed();//2apr2021 //start--------------//2apr2021 if(Config.ALLOWREPLAY) { if(game.gamestate==Game.CAT_GAMESTATE_GAME && Replay.PLAYBACK==false) { //this occurs on frame 1 Replay.Init(game); Replay.StartRecordReplay(game,0); } if(game.oldgamestate==Game.CAT_GAMESTATE_GAME) { Replay.EndRecord(game); } if(game.gamestate==Game.CAT_GAMESTATE_REPLAY) { //this occurs on frame 1 Replay.PrepareToPlay(game); //Trigger.updateall(game); //to keep in line with the standard path taken through the game code.//18apr2021 commented out.... } } else { Replay.RECORD = false; Replay.PLAYBACK = false; } //end----------------//2apr2021 } utime-=gametimer.ElapsedMilliseconds; long rtime = gametimer.ElapsedMilliseconds; long sumr = 0; long sumu = 0; for(int i=0;i 9000) { RenderList.drawtext(game,800,100,"WARNING:"+((sumu+sumr)*100/10000)+"%",RenderList.getrgb(255,32,32),game.fonts[Resources.FONT].font,true); } else { RenderList.drawtext(game,800,100,((sumu+sumr)*100/10000)+"%",RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); } if(RenderList.RENDERMODE==RenderList.RENDERMODE_POOL) { RenderList.drawtext(game,800,75,"POOL Tot U:"+Math.Abs(sumu)+" Tot R:"+Math.Abs(sumr),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); } else { RenderList.drawtext(game,800,75,"NON POOL Tot U:"+Math.Abs(sumu)+" Tot R:"+Math.Abs(sumr),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); } //RenderList.drawtext(game,800,100,"bmenutime:"+Math.Abs(Config.maxbmenutime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,125,"bullettime:"+Math.Abs(Config.maxbullettime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); RenderList.drawtext(game,800,150,"drawtime:"+Math.Abs(Config.maxdrawtime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,175,"correcttime:"+Math.Abs(Config.maxmapcorrecttime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,200,"mappostime:"+Math.Abs(Config.maxmapupdatepostime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,225,"selecttime:"+Math.Abs(Config.maxselecttime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,250,"triggertime:"+Math.Abs(Config.maxtriggertime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,275,"unitupdatetime:"+Math.Abs(Config.maxunitupdatetime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,300,"musictime:"+Math.Abs(Config.maxumusictime),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,75,"animatetime:"+Math.Abs(Config.maxanimate),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,100,"updatetime:"+Math.Abs(Config.maxupdate),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,125,"attacktime:"+Math.Abs(Config.maxatt),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //this is where the optimisation can be found.... //RenderList.drawtext(game,800,325,"walktime:"+Math.Abs(Config.maxwalk),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); RenderList.drawtext(game,800,350,"MAXINDEX:"+Unit.MAXINDEX,RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,400,"precalcused:"+Math.Abs(Config.precalcused),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,425,"seekpathused:"+Math.Abs(Config.seekpathused),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,450,"seekpathsuccess:"+Math.Abs(Config.seekpathsuccess),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,475,"seekpathfailed:"+Math.Abs(Config.seekpathfailed),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); //RenderList.drawtext(game,800,500,"maperrors:"+Math.Abs(Config.maxmaperrors),RenderList.getrgb(180,180,180),game.fonts[Resources.FONT].font,true); } //if(Game.transitionframe!=Game.TRANSITIONTIME) //{ if(Game.restart)//13apr2021 { RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(1,1,1),0); RenderList.drawtext(game,Game.RESOLUTIONX/2,Game.RESOLUTIONY/2,Translation.TranslateWord("Please Wait",false),RenderList.getrgb(180,180,180),game.fonts[Resources.LARGEFONT].font,true); } render(game,window); //} if(game.takepicture || (game.frame >1 && (game.frame % 120)==0 && Config.RECORD==true && Config.totrtime[(game.frame - 1) % 600]<20)) { if(Config.RECORD) { if(RenderList.recordframe>60*60) { Config.RECORD = false; Game.recordkeypressed = 0; } } bool taken = false; SDL.SDL_Rect rect = new SDL.SDL_Rect(); rect.x = 0; rect.y = 0; rect.w = game.SW; rect.h = game.SH; IntPtr surface = SDL.SDL_CreateRGBSurfaceWithFormat(SDL.SDL_RLEACCEL,game.SW,game.SH,32,SDL.SDL_PIXELFORMAT_ARGB8888); try { //WARNING - NOT SURE IF I'M DOING THIS QUITE CORRECTLY. FOR MEMORY SAFETY. unsafe { SDL.SDL_Surface * sur = (SDL.SDL_Surface *)surface; SDL.SDL_RenderReadPixels(game.renderer,ref rect,SDL.SDL_PIXELFORMAT_ARGB8888,sur->pixels,sur->pitch); //free the * sur reference } taken = RenderList.CaptureThread(surface); } catch(Exception ggg) { string msg = ggg.Message; } if(!taken) { try { SDL.SDL_FreeSurface(surface); } catch(Exception ggg) { string msg = ggg.Message; } } game.takepicture = false; } rtime-=gametimer.ElapsedMilliseconds; utime = Math.Abs(utime); rtime = Math.Abs(rtime); Config.totrtime[game.frame % 600]=rtime; Config.totutime[game.frame % 600]=utime; if(utime>maxutime || game.frame % 300== 0) { maxutime = utime; } if(rtime > maxrtime || game.frame % 300 == 0) { maxrtime = rtime; } if(game.gamestate<0) { quit = true; } //while(gametimer.ElapsedMilliseconds<14)//26mar2021 while(gametimer.ElapsedMilliseconds=0)//26mar2021 { //if(Game.NODELAY){SDL.SDL_Delay(1);}//26mar2021 SDL.SDL_Delay(Config.FRAMETIME - Convert.ToUInt32(gametimer.ElapsedMilliseconds));//26mar2021 } Game.FRAMERATE = Convert.ToInt32(1000.0 / gametimer.ElapsedMilliseconds); gametimer.Reset(); gametimer.Start(); //26mar2021 uncommented this block out //if(game.frame % (60*60)==0 && game.frame > 0)//15mar2021//15sep2021 if(game.frame % (60*60)==0 && game.frame > 0 && Game.togglepause==false)//15mar2021//15sep2021 {//15mar2021 //Network.url = "https://www.mattiesgames.com/metrics/timespent.php?game=grumthorr";//15mar2021//30mar2021 Network.url = "https://www.mattiesgames.com/metrics/timespent.php?game=grumthorr&uid="+Config.uid;//30mar2021 Network.httpget(Network.url);//15mar2021 }//15mar2021 //start--------------//13mar2021 //if(Game.restart)//15mar2021 if(Game.restart==true && RenderList.threadrunning==false)//15mar2021 { //if(game.gamestate!=Game.CAT_GAMESTATE_GAME)//7apr2021 //{ quit = true; //} //Game.restart = false; //13mar2021 - bugger. } //end----------------//13mar2021 } MapThread.quit = true;//29may2021 gametimer.Stop(); game.quit(); //Network.url = "https://www.mattiesgames.com/metrics/metric.php?game="+Game.NETTITLE+"&event=maxmission&value="+Game.maxmission;//15mar2021 //Network.httpget(Network.url);//15mar2021 Game.restartgamestate = game.gamestate; //26mar2021 //start---------------//28mar2021 if(Game.restart==false) { string langlang = LocalStorage.getitem("language"); if(langlang=="") { langlang = "english"; if(Config.autodetectlang!="")//30mar2021 { langlang = Config.autodetectlang; } } int gtime = (game.frame / (60*60)); //Network.url = "https://www.mattiesgames.com/metrics/metric.php?game=grumthorr&event="+langlang+"&value="+gtime;//15mar2021//30mar2021 Network.url = "https://www.mattiesgames.com/metrics/metric.php?game=grumthorr&event="+langlang+"&value="+gtime+"&uid="+Config.uid;//30mar2021 Network.httpget(Network.url); } //end-----------------//28mar2021 } } /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Tech //2sep2021 { public static bool TECHUNITSELECTED = false; public static int TECHUNITIDSELECTED = -1; public static int COMPLETEDTIME = 60 * 5; //time to show on screen the 'completed' message for.... public static int COMPLETEDID = -1; // public static int ADDSUBTRACT = 0; public static int TARGETUID = -1; // public string name; public string techclass;//23sep2021 public string displayname; public string[] description; public string tooltip; public int guilinkid; public int id; public int faction; // public int researchtime; //number of seconds to count down from public int timeleft; //initialised to -1 public int researched; //reset at beginning of mission. public int completedtime;// public int researching; public int unlimited;//23sep2021 // public int goldcost;//23sep2021 public int purchased;//23sep2021 public int purchaseguilink;//23sep2021 public int temporary;//23sep2021 public int temporarytime;//23sep2021 public int TEMPORARYTIME = 90;//23sep2021 public int attackaction;//23sep2021 public int guiactionid;//23sep2021 public int selectedtopurchase;//23sep2021 public int manacost;//23sep2021 public int img; //icon image public int imgframe; //frame in image if multiple cells... public string imgfile; //image file public int saleimg;//saleimage//23sep2021 public string saleimgfile;//image file//23sep2021 public int saleimgframe;//23sep2021 public int scw; //cell width//23sep2021 public int sch; //cell height//23sep2021 public int snw; //number wide//23sep2021 public int snh; //number high//23sep2021 public int cw; //cell width public int ch; //cell height public int nw; //number wide public int nh; //number high // public string effectname; //pipe separated list of items.... public int effectint;// if value is a buff of sorts.... // public static string ENABLEUNIT = "EU_"; public static string BUFFMOVE = "BM_"; public static string BUFFATT = "BA_"; public static string BUFFDEF = "BD_"; public static string BUFFHP = "BH_"; public static string BUFFABILITY = "BZ_"; // public int[] unittemplatesenabled; public int[] unittemplatesmove; public int[] unittemplatesatt; public int[] unittemplatesdef; public int[] unittemplateshp; public string[] unittemplatesability; // //example effect name string: //effectname = EU_Hero Skeleton //would enable the Hero Skeleton to be built. //effectname = BA_Hero Skeleton|BD_Hero Skeleton //effectint = 1 //would buff Hero Skeletons' Att and Def by +1 point permanently. public static string MV = "MV"; public static string BA = "BA"; public static string BD = "BD"; public static string BH = "BH"; public static string BZ = "BZ"; ///////////////////Method Definition/////////////// public static int PercentComplete(Game game,int id) { if(!Config.USETECH) { return 100; } if(game.techs[id].timeleft<0) { return 0; } if(game.techs[id].timeleft==0) { return 100; } if(game.techs[id].researchtime<=0) { return 100; } return ((game.techs[id].researchtime - game.techs[id].timeleft) * 100) / game.techs[id].researchtime; } ///////////////////Method Definition/////////////// public static void StartResearch(Game game,int techid,int faction) { if(!Config.USETECH) { return; } for(int i=0;i0) { if(game.techs[i].unittemplatesmove!=null && type==Tech.MV) { for(int j=0;j0) { game.units[id].magicrelease = Unit.MAGICRELEASE; } else { game.units[id].magicrelease = 0; } break; case "magictransform": //for transforming into a different unit redomagic = true; game.units[id].magictransform +=value; if(game.units[id].magictransform>0) { game.units[id].magictransform = Unit.MAGICTRANSFORM; } else { game.units[id].magictransform = 0; } break; case "magicsummoner": redomagic = true; game.units[id].magiczombiemaster+=value; if(game.units[id].magiczombiemaster>0) { game.units[id].magiczombiemaster = Unit.MAGICZOMBIEMASTER; } else { game.units[id].magiczombiemaster = 0; } break; case "magiczombiemaster"://redundant version alias redomagic = true; game.units[id].magiczombiemaster+=value; if(game.units[id].magiczombiemaster>0) { game.units[id].magiczombiemaster = Unit.MAGICZOMBIEMASTER; } else { game.units[id].magiczombiemaster = 0; } break; case "magicleader": game.units[id].magicleader+=value; redomagic = true; if(game.units[id].magicleader>0) { game.units[id].magicleader = Unit.MAGICLEADER; } else { game.units[id].magicleader = 0; } break; //end----------------//9apr2021 case "magicfrenzy": game.units[id].magicfrenzy+=value; redomagic = true; if(game.units[id].magicfrenzy>0) { game.units[id].magicfrenzy = Unit.MAGICFRENZY; } else { game.units[id].magicfrenzy = 0; } break; case "magicdoom": game.units[id].magicdoom+=value; redomagic = true; if(game.units[id].magicdoom>0) { game.units[id].magicdoom = Unit.MAGICDOOM; } else { game.units[id].magicdoom = 0; } break; case "magicdefense": game.units[id].magicdef+=value; redomagic = true; if(game.units[id].magicdef>0) { game.units[id].magicdef = Unit.MAGICDEF; } else { game.units[id].magicdef = 0; } break; case "magicdef": //redundancy game.units[id].magicdef+=value; redomagic = true; if(game.units[id].magicdef>0) { game.units[id].magicdef = Unit.MAGICDEF; } else { game.units[id].magicdef = 0; } break; //end-------------//01apr2021 //start---------------//28mar2021 case "magicweb": game.units[id].magicweb+=value; redomagic = true; if(game.units[id].magicweb>0) { game.units[id].magicweb = Unit.MAGICWEB; } else { game.units[id].magicweb = 0; } break; case "magicgas": redomagic = true; game.units[id].magicgas+=value; if(game.units[id].magicgas>0) { game.units[id].magicgas = Unit.MAGICGAS; } else { game.units[id].magicgas = 0; } break; case "magichaste": redomagic = true; game.units[id].magichaste+=value; if(game.units[id].magichaste>0) { game.units[id].magichaste = Unit.MAGICHASTE; } else { game.units[id].magichaste = 0; } break; case "magicfear": redomagic = true; game.units[id].magicfear+=value; if(game.units[id].magicfear>0) { game.units[id].magicfear = Unit.MAGICFEAR; } else { game.units[id].magicfear = 0; } break; case "magicshield": redomagic = true; game.units[id].magicshield+=value; if(game.units[id].magicshield>0) { game.units[id].magicshield = Unit.MAGICSHIELD; } else { game.units[id].magicshield = 0; } break; case "magicstorm": redomagic = true; game.units[id].magicstorm+=value; if(game.units[id].magicstorm>0) { game.units[id].magicstorm = Unit.MAGICSTORM; } else { game.units[id].magicstorm = 0; } break; case "magicsword": redomagic = true; game.units[id].magicsword += value; if(game.units[id].magicsword>0) { game.units[id].magicsword = Unit.MAGICSWORD; } else { game.units[id].magicsword = 0; } break; case "magicstealth": redomagic = true; game.units[id].magicstealth += value; if(game.units[id].magicstealth>0) { game.units[id].magicstealth = Unit.MAGICSTEALTH; } else { game.units[id].magicstealth = 0; } break; case "magicplant": redomagic = true; game.units[id].magicplant += value; if(game.units[id].magicplant>0) { game.units[id].magicplant = Unit.MAGICPLANT; } else { game.units[id].magicplant = 0; } break; case "magicwind": redomagic = true; game.units[id].magicwind += value; if(game.units[id].magicwind>0) { game.units[id].magicwind = Unit.MAGICWIND; } else { game.units[id].magicwind = 0; } break; //end-----------------//28mar2021 case "highfirerate": //25Feb2021 game.units[id].highfirerate += value; break; //start-------------//7mar2021 case "mob": game.units[id].mob += value; break; case "hatred": game.units[id].hatred += value; break; case "craftsman": game.units[id].craftsman += value; break; case "planar": game.units[id].planar += value; break; case "slow": game.units[id].slow += value; break; case "woodsman": game.units[id].woodsman += value; break; case "stupid": game.units[id].stupid += value; break; case "frenzy": game.units[id].frenzy += value; break; //end---------------//7mar2021 case "shocktroops": game.units[id].shock += value; break; case "shock": //2sep2021 game.units[id].shock += value; break;//2sep2021 case "stealth": game.units[id].stealth += value; break; case "damagex": game.units[id].damagex += value; break; case "fearsome": game.units[id].fearsome += value; break; case "leader": game.units[id].leader += value; break; case "bounddemon"://12jul2021 game.units[id].bounddemon += value; break; case "bossmonster": game.units[id].bossmonster += value; break; case "flammable": game.units[id].flammable += value; break; case "regeneration": game.units[id].regeneration += value; break; case "zombie": game.units[id].zombie += value; break; case "evilfire": game.units[id].firespell -= value; break; case "sacrificial": game.units[id].sacrificial += value; break; case "cansacrifice": game.units[id].cansacrifice += value; break; case "animosity": game.units[id].animosity += value; break; } if(redomagic) { game.units[id].magicarray = new int[17]; int m = 0; if(game.units[id].magicrelease>0)//3may2021 { game.units[id].magicarray[m] = game.units[id].magicrelease; m++; } if(game.units[id].magictransform>0)//3may2021 { game.units[id].magicarray[m] = game.units[id].magictransform; m++; } //start--------------//9apr2021 if(game.units[id].magicleader>0)//01apr2021 { game.units[id].magicarray[m] = game.units[id].magicleader; m++; } if(game.units[id].magiczombiemaster>0)//01apr2021 { game.units[id].magicarray[m] = game.units[id].magiczombiemaster; m++; } //end----------------//9apr2021 if(game.units[id].magicdoom>0)//01apr2021 { game.units[id].magicarray[m] = game.units[id].magicdoom; m++; } if(game.units[id].magicdef>0)//01apr2021 { game.units[id].magicarray[m] = game.units[id].magicdef; m++; } if(game.units[id].magicfrenzy>0)//01apr2021 { game.units[id].magicarray[m] = game.units[id].magicfrenzy; m++; } if(game.units[id].magicweb>0) { game.units[id].magicarray[m] = game.units[id].magicweb; m++; } if(game.units[id].magicfear>0) { game.units[id].magicarray[m] = game.units[id].magicfear; m++; } if(game.units[id].magicgas>0) { game.units[id].magicarray[m] = game.units[id].magicgas; m++; } if(game.units[id].magichaste>0) { game.units[id].magicarray[m] = game.units[id].magichaste; m++; } if(game.units[id].magicplant>0) { game.units[id].magicarray[m] = game.units[id].magicplant; m++; } if(game.units[id].magicshield>0) { game.units[id].magicarray[m] = game.units[id].magicshield; m++; } if(game.units[id].magicstealth>0) { game.units[id].magicarray[m] = game.units[id].magicstealth; m++; } if(game.units[id].magicstorm>0) { game.units[id].magicarray[m] = game.units[id].magicstorm; m++; } if(game.units[id].magicsword>0) { game.units[id].magicarray[m] = game.units[id].magicsword; m++; } if(game.units[id].magicwind>0) { game.units[id].magicarray[m] = game.units[id].magicwind; m++; } } } ///////////////////Method Definition/////////////// public static bool IsUnitEnabled(Game game,int templateid) { if(!Config.USETECH) { return true; } for(int i=0;i0) { if(game.techs[i].unittemplatesenabled!=null) { for(int j=0;j0 && game.units[u].faction==game.techs[i].faction && game.units[u].techguilinkid==game.techs[i].guilinkid)//26feb2022 for(int tt=0;tt0 && game.units[u].faction==game.techs[i].faction && game.units[u].techguilinkid[tt]==game.techs[i].guilinkid)//26feb2022 { Tech.StartResearch(game,i,game.techs[i].faction); break; } } } } } } } } public static void unpurchase(Game game)//24sep2021 { if(!Config.USETECH) { return; } for(int i=0;i=0) { game.gui[i].action = Gui.ACTION_NONE; } } } public static void resetall(Game game) { if(!Config.USETECH) { return; } for(int i=0;i0 && purchased<=0) { timeleft = -1; completedtime = -1; researched = -1; researching = 0; return; } if(temporary>0 && attackaction>0) { //player is using this tech to perform an attack..... //therefore if(temporarytime>0) { temporarytime--; researched = 1; completedtime = COMPLETEDTIME; timeleft = 0; researching = 0; //pick a firetargeti value...... Unit.SelectNearestTarget(game,Unit.GetPlayer(game));//24sep2021 } else { timeleft = -1; completedtime = -1; researched = -1; researching = 0; } return; } //end-------------//23sep2021 if(timeleft==0) { researched = 1; completedtime = COMPLETEDTIME; } if(timeleft>0 && researching>0) { timeleft--; } if(completedtime>0) { completedtime--; COMPLETEDID = id; } else { COMPLETEDID = -1; } } //start----------23sep2021 public static int GetTechIdFromAction(Game game,int guiactionid) { if(!Config.USETECH) { return -1; } if(game.techs==null) { return -1; } for(int i=0;i0 && game.techs[i].attackaction>0) { bool found = false; for(int g=0;g=0) { //don't overwrite existing if filling an empty slot.... found = true; break; } } if(found) { continue; } return game.techs[i].guiactionid; } } return Gui.ACTION_NONE; } // public static int GoldCost(Game game,int id) { if(!Config.USETECH) { return -1; } return game.techs[id].goldcost; } public static int GoldCostGui(Game game,int action) { if(!Config.USETECH) { return 0; } for(int i=0;i=game.techs.Length) { return 0; } if(game.techs[id].purchased>0) { return 0; } if(game.techs[id].goldcost<=0) { return 0; } for(int i=0;i0) { game.techs[i].selectedtopurchase = 0; } } game.techs[id].selectedtopurchase = 1; if(game.techs[id].unlimited>0) { game.techs[id].selectedtopurchase = -1; } return game.techs[id].selectedtopurchase; } public static int PurchaseGuiSelected(Game game) { int limit = 0; for(int i=0;i0) { return; } for(int j=0;j0 && game.units[j].gold>=game.techs[id].goldcost) { game.units[j].gold-=game.techs[id].goldcost; if(game.techs[id].name=="healthpotion") { game.units[j].healthpotions++; break; } if(game.techs[id].name=="manapotion") { game.units[j].manapotions++; break; } if(game.techs[id].name=="bothpotion") { game.units[j].bothpotions++; break; } game.techs[id].purchased=1; game.techs[id].researched = -1; game.techs[id].completedtime = -1; game.techs[id].timeleft = -1; game.techs[id].researching = 0; break; } } } public static void DrinkPotion(Game game,int pid,string type) { if(type=="health") { if(game.units[pid].healthpotions>0) { game.units[pid].healthpotions--; game.units[pid].hp+=PotionStrength(game,"healthpotion"); if(game.units[pid].hp>game.units[pid].basehp) { game.units[pid].hp = game.units[pid].basehp; } } } if(type=="mana") { if(game.units[pid].manapotions>0) { game.units[pid].manapotions--; game.units[pid].mana+=PotionStrength(game,"manapotion"); if(game.units[pid].mana>game.units[pid].basemana) { game.units[pid].mana = game.units[pid].basemana; } } } if(type=="both") { if(game.units[pid].bothpotions>0) { game.units[pid].bothpotions--; game.units[pid].hp+=PotionStrength(game,"bothpotion"); if(game.units[pid].hp>game.units[pid].basehp) { game.units[pid].hp = game.units[pid].basehp; } game.units[pid].mana+=PotionStrength(game,"bothpotion"); if(game.units[pid].mana>game.units[pid].basemana) { game.units[pid].mana = game.units[pid].basemana; } } } } public static int PotionStrength(Game game,string type) { if(!Config.USETECH) { return 0; } if(game.techs==null) { return 0; } for(int i=0;i0) { return true; } } } return false; } public static void ActivateAttack(Game game,int id) { if(!Config.USETECH) { return; } if(game.techs==null) { return; } int pid = Unit.GetPlayer(game); if(pid==-1) { return; } //Console.WriteLine("Attack Button Pressed"); for(int i=0;i0) { if(game.units[pid].mana>=game.techs[i].manacost) { game.units[pid].mana-=game.techs[i].manacost; } else { return; } if(game.techs[i].temporary>0) { game.techs[i].temporarytime = game.techs[i].TEMPORARYTIME; } //the player will activate this option..... if(game.units[pid].animmode!=Unit.ANIMMODE_ATTACK && game.units[pid].animmode!=Unit.ANIMMODE_ATTACK2 && game.units[pid].animmode!=Unit.ANIMMODE_ATTACK3) { game.units[pid].firetargeti = -1; //reset the player's attack choice.... game.units[pid].orderframe = 0; game.techs[i].update(game); } } } } } public static void RemoveItemFromStore(Game game,int g) { if(!Config.USETECH) { return; } if(game.techs==null) { return; } if(game.gui==null) { return; } if(g<0 || g>game.gui.Length) { return; } game.gui[g].action = Gui.ACTION_NONE; } public static void ChooseItemForStore(Game game,int g,string name,int mincost,int maxcost) { if(!Config.USETECH) { return; } if(game.techs==null) { return; } if(game.gui==null) { return; } if(g<0 || g>=game.gui.Length) { return; } if(game.gui[g].command.IndexOf("buydescription")>=0) { return; } int count = 0; int index = 0; //Console.WriteLine("Choose Item For Store:"+name); for(int i=0;imaxcost) { continue; } } if(game.techs[i].name==name) { game.gui[g].action = game.techs[i].guiactionid; break; } if(game.techs[i].techclass==name) { count++; } } //Console.WriteLine("Item Count:"+count); if(count>0) { index = Functions.rand(0,1000); if(index<0) { index*=-1; } index%=count; index++; //Console.WriteLine("Item Index:"+index); for(int i=0;imaxcost) { continue; } } if(game.techs[i].techclass==name) { index--; if(index<=0) { game.gui[g].action = game.techs[i].guiactionid; break; } } } } //Console.WriteLine("Gui Item Action Buy ID:"+game.gui[g].action); } //end----23sep2021 } /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class Units //21apr2021 { public Unit[] unit; public Units(Game game) { unit = new Unit[Unit.MAXUNITS]; for(int i=0;i=game.units.Length)//25sep2021 { return; } int target = -1; int mindist = 9999; int dist = 0; int[] searched = new int[Map.MAXX * Map.MAXY]; //Console.WriteLine("Selecting Nearest"); for(int c=1;c<10;c++) { if(c > 1 + (game.units[id].firerange / Map.GRIDW)) { continue; } for(int cx=game.units[id].x / Map.GRIDW - c;cx<=game.units[id].x / Map.GRIDW + c;cx++) { for(int cy=game.units[id].y / Map.GRIDH - c;cy<=game.units[id].y / Map.GRIDH + c ;cy++) { if(cx>=0 && cx=0 && cy0 && game.units[target].faction!=game.units[id].faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cx - game.units[id].x / Map.MAXX) + Functions.abs(cy - game.units[id].y / Map.MAXY)); if(dist < mindist ) { if(game.units[id].needlos>0)//15sep2021 { if(los(game,id,target)) { mindist = dist; game.units[id].firetargeti = target; //Console.WriteLine("Selecting Nearest:"+game.units[target].dname()); } } else//15sep2021 { mindist = dist; game.units[id].firetargeti = target; //Console.WriteLine("Selecting Nearest:"+game.units[target].dname()); } } } } } } if(game.units[id].firetargeti!=-1) { break; } } } ///////////////////Method Definition/////////////// public static int PlayerGold(Game game)//23sep2021 { if(game.units==null) { return 0; } int gold = 0; for(int i=0;i0) { if(game.units[i].gold>0) { gold+=game.units[i].gold; } } } return gold; } ///////////////////Method Definition/////////////// public static int GetPlayer(Game game)//23sep2021 { if(game==null) { return -1; } if(game.units==null) { return -1; } for(int i=0;i0) { return i; } } return -1; } ///////////////////Method Definition/////////////// public static void SaveScore(Game game,int mid)//17sep2021 { int count = 0; for(int i=0;i0 && game.units[i].hp>0 && game.units[i].faction==Game.PLAYERFACTION) { count+=game.units[i].points; } } LocalStorage.setitem("missionscore"+mid,""+count); Game.scoredirty = true;//18sep2021 } ///////////////////Method Definition/////////////// public static bool SpawnerCanBuild(Game game,string constraint,int tid)//9sep2021 { if(Trigger.VARIABLE[Trigger.TYPE_POINTS]0) { for(int k=0;k0)//4may2021 { return; } if(game.units[j].flightlevel!=-1)//4may2021 { return; } //if our distance is further than 2 grid squares then disallow as well //if(Functions.abs(game.units[i].x - game.units[j].x)>Map.GRIDW * 2 || Functions.abs(game.units[i].y - game.units[j].y)>Map.GRIDH *2)//3mar2022 if(Functions.abs(game.units[i].x - game.units[j].x)>Map.GRIDW * 3 || Functions.abs(game.units[i].y - game.units[j].y)>Map.GRIDH *3)//3mar2022//additional grid distances... { return; } int numinside = 0; for(int k=0;k=game.units[i].transportcapacity) { return; } for(int k=0;k0) { for(int k=0;k0) { if(game.units[nid].transportedbyid==i) { //try and drop us out of the transport...... bool foundspot = false; for(int x=game.units[i].x - Map.GRIDW * 2;x<=game.units[i].x + Map.GRIDW * 2;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * 2;y<=game.units[i].y + Map.GRIDH * 2;y+=Map.GRIDH) { if(Map.cellunit(x,y)==Map.VACANT) { foundspot = true; if(Map.insertunit(nid,x,y)) { game.units[nid].x = x; game.units[nid].y = y; game.units[nid].tx = x; game.units[nid].ty = y; game.units[nid].tmptx = x; game.units[nid].tmpty = y; game.units[nid].firetargeti = -1; game.units[nid].transportedbyid = -1; game.units[i].transportarray[k] = -1; } break; } } if(foundspot) { break; } } } } } } } } ///////////////////Method Definition/////////////// public static void CorrectTransport(Game game,int i)//3may2021 { if(game.units[i].transportcapacity>0) { //go through any units inside.....and check they're alive..... if(game.units[i].transportarray==null) { return; } for(int k=0;k=0 && i0 && game.templates[i].walkspeed>0) { if(game.images[game.templates[i].cat].texture!=IntPtr.Zero) { try { int w = game.images[game.templates[i].cat].cwx; int h = game.images[game.templates[i].cat].chy; IntPtr surface = SDL_image.IMG_Load(game.images[game.templates[i].cat].file); game.templates[i].autocalcedoffsets=true; SDL.SDL_Surface * sur = (SDL.SDL_Surface *)surface; int frame = 0; while(frame < game.images[game.templates[i].cat].cwn * game.images[game.templates[i].cat].chn) { int pointer = 0; int cellx = frame % game.images[game.templates[i].cat].cwn; int celly = (frame - cellx) / game.images[game.templates[i].cat].cwn; int sx = cellx * game.images[game.templates[i].cat].cwx; int sy = celly * game.images[game.templates[i].cat].chy; pointer = 4 * (sy*sur->pitch + sx); for(int y=0;ypixels,pointer + x * 4); byte lastpixel = Marshal.ReadByte(sur->pixels,pointer + x * 4 + 3); if(alphapixel>0 && lastpixel>0) { pixelcount++; sumx+=x; sumy+=y; fully=y; } } pointer+=sur->pitch; } if(pixelcount>0) { offx = (w/2) - (sumx/pixelcount); offy = - (h / 2) + 3 * (h - fully) / 2 + (h - fully) / 2 + (fully - sumy/pixelcount)/2; game.templates[i].offxa[frame] = offx; game.templates[i].offya[frame] = offy; game.templates[i].offx+=offx; game.templates[i].offy+=offy; //game.templates[i].autocalcedoffsets = true; //Console.WriteLine("Offx:"+offx+" offy:"+offy+" file:"+game.templates[i].catfile+" frame:"+frame); sumx = 0; sumy = 0; pixelcount = 0; offx = 0; offy = 0; fully = 0; } frame++; } if(frame>0) { game.templates[i].offx/=frame; game.templates[i].offy/=frame; } SDL.SDL_FreeSurface(surface); } catch(Exception e) { string msg = e.Message; Console.WriteLine(e.Message); } } } } } ///////////////////Method Definition/////////////// public int percentagespawn(Game game) { //used for showing the build progress at construction buildings //(game.frame+id)%(framecheck*spawnertime)==0) int framecheck = 60; if(Config.RUNNINGSPEED>90) { framecheck = 80; } if(Config.RUNNINGSPEED>110) { framecheck = 90; } framecheck/=Config.FASTFRAMECHECK;//14sep2021 int curframe = game.frame + id; int fulltime = framecheck * spawnertime; if(fulltime==0) { return 0; } int startframe = (curframe - (curframe % fulltime)); //int framesleft = fulltime - (curframe % fulltime);//9sep2021 int pct = (100 * (fulltime - framesleft)) / fulltime; if(pct>100) { pct = 100; } if(pct<0) { pct = 0; } return pct; } ///////////////////Method Definition/////////////// public static int CalculateSpawnerTime(Game game,int tid) { //calculate the time to spawn this unit //kind of like a points cost for units in time int minvalue = 3; int maxvalue = 45; int value = minvalue; int firerate = game.templates[tid].highfirerate+1; if(firerate>2) { firerate = 2; } if(firerate<2) { firerate = 1; } int tmpvalue = minvalue + game.templates[tid].basehp * (1 + game.templates[tid].armour / 2 + (game.templates[tid].damage / 3 + game.templates[tid].damage2 / 3) * (firerate)) / 60; //start-----------------//20mar2021 tmpvalue += game.templates[tid].firebullet * 3; //20mar2021 - add 3 seconds to missile troops.... tmpvalue += game.templates[tid].brave * 2; //20mar2021 - add 2 seconds to brave troops... tmpvalue -= Functions.sign(game.templates[tid].stupid) * 2; //deduct 2 seconds from stupid troops tmpvalue -= Functions.sign(game.templates[tid].timid) * 3; //deduct 3 seconds from timid troops tmpvalue += Functions.sign(game.templates[tid].shock) * 2; //add 2 seconds to shock troops tmpvalue += Functions.sign(game.templates[tid].damagex) * 2; //add 2 seconds to damagex troops tmpvalue -= Functions.sign(game.templates[tid].hitandrun) * 2; //deduct 2 seconds from skirmishers tmpvalue += Functions.sign(game.templates[tid].craftsman) * 2; //add 3 seconds to craftsman tmpvalue += Functions.sign(game.templates[tid].frenzy) * 2;//add 2 seconds to frenzy tmpvalue += Functions.sign(game.templates[tid].regeneration) * 3; //add 3 seconds for regeneration tmpvalue += Functions.sign(game.templates[tid].fearsome) * 2; //add 2 seconds to fearsome tmpvalue += Functions.sign(game.templates[tid].woodsman) * 2; //add 2 seconds for woodsman tmpvalue += Functions.sign(game.templates[tid].banish) * 4; //add 4 seconds for banishment.... tmpvalue += Functions.sign(game.templates[tid].splash) * 6; //add 6 seconds for splash damage//2sep2021 tmpvalue += game.templates[tid].buildpenalty;//special factor to adjust for some troops..... // if(tmpvalue < minvalue) { tmpvalue = minvalue; } //end-------------------//20mar2021 if(tmpvalue > value) { value = tmpvalue; } if(value > maxvalue) { value = maxvalue; } return value; } //end---------------//10mar2021 //start-------------//9mar2021 ///////////////////Method Definition/////////////// public static void SpellCast(Game game,int spellid,int sfaction)//28mar2021 { //find our spellcasters...... bool soundplayed = false; Functions.saveseed(Functions.seed); for(int i=0;i<=Unit.MAXINDEX;i++) { if(game.units[i].hp>0 && game.units[i].faction==sfaction && game.units[i].spellcaster>0 && ((game.units[i].selected!=Unit.SELECTIONNONE && sfaction==Game.PLAYERFACTION && Game.SPELLCASTERSELECTED==i) || (sfaction!=Game.PLAYERFACTION && game.units[i].casting==true))) { //this is one of our casters. game.units[i].casting = false; if(!soundplayed) { game.units[i].playmagicsound(game,i); soundplayed = true; } int spell = spellid;// - Gui.ACTION_SPELL_START; //a value from 0 to 8 //as there are 9 different spells in the game (maximum) //of varying level.... /* spells are: (in no particular order) magicfear magicgas magichaste magicplant magicshield magicstealth magicstorm magicsword magicwind */ for(int m=0;m100) { oldhpfrac = 100; } int oldx = game.units[i].x; int oldy = game.units[i].y; int ztmp = -1; for(int tid=0;tid0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0) { game.units[nid].spelldefense++; Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[i].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } //start--------------//9apr2021 if(spell==Unit.MAGICLEADER) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(game.units[i].notabuffer>0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0) { game.units[nid].leader+=2; Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[i].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } if(spell==Unit.MAGICZOMBIEMASTER) { int nid = Map.cellunit(game.units[i].x,game.units[i].y); //ie ourselves.... if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0 && game.units[nid].zombiemaster>0) { game.units[nid].zombiemaster+=5; if(game.units[nid].zombiemaster>10) { game.units[nid].zombiemaster=10; } } } } //end----------------//9apr2021 if(spell==Unit.MAGICDOOM) { //hmm....what is this spell? some kind of 'inverse healing maybe?' for the undead? and chaos? for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].spelldefense>0)//01apr2021 { continue; } if(game.units[nid].hp>0 && game.units[nid].walkspeed>0) { if(Functions.rand(0,1000)<750) { game.units[nid].hp-=game.units[i].spellcaster; if(game.units[nid].onscreen) { Functions.saveseed();//25apr2021 if(Functions.rand(0,100)<25) { game.units[nid].playvictimhitsound(game,nid); } Functions.restoreseed();//25apr2021 } Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[i].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.REDSPELL); if(game.units[nid].hp<=0)//20mar2021 { game.killed(game,nid); game.templates[game.units[i].templateid].kills++; } game.units[i].hp+=game.units[i].spellcaster; if(game.units[i].hp>game.units[i].basehp) { game.units[i].hp = game.units[i].basehp; } } } } } } } if(spell==Unit.MAGICFRENZY) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(game.units[i].notabuffer>0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0 && game.units[nid].damage>0) { game.units[nid].frenzy+=3; Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[i].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } //end--------//01apr2021 if(spell==Unit.MAGICFEAR) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].faction!=game.units[i].faction && game.units[nid].hp>0 && game.units[nid].walkspeed>0) { if(game.units[nid].spelldefense>0)//01apr2021 { continue; } if(Functions.rand(0,1000)<500) { game.units[nid].timid = 1; game.units[nid].retreat = true; game.units[nid].retreatframe = game.frame + Unit.RETREATDEATH; game.units[nid].orderframe = Unit.ORDERTIME; game.units[nid].firetargeti = -1; Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.REDSPELL); } } } } } } if(spell==Unit.MAGICGAS) { int fires = 0; for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 5;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 5;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 5;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 5;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].spelldefense>0)//01apr2021 { continue; } if(game.units[nid].faction!=game.units[i].faction && game.units[nid].hp>0) { Map.setonfire(x,y,false); Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[i].offy,x,y,Bullet.FIRESPELL); fires++; } } if(fires>game.units[i].spellcaster*3) { break; } } if(fires>game.units[i].spellcaster*3) { break; } } } if(spell==Unit.MAGICWEB) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].spelldefense>0) { continue; } if(game.units[nid].faction!=game.units[i].faction && game.units[nid].hp>0 && game.units[nid].walkspeed>0) { game.units[nid].walkspeed--; //maximum walk speed.... //if(game.units[nid].walkspeed<1) //{ // game.units[nid].walkspeed=1; //} Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.REDSPELL); } } } } } if(spell==Unit.MAGICHASTE) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(game.units[i].notabuffer>0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0 && game.units[nid].walkspeed>0) { game.units[nid].walkspeed++; //maximum walk speed.... if(game.units[nid].walkspeed>3) { game.units[nid].walkspeed=3; } Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } if(spell==Unit.MAGICPLANT)//24apr2021 //if(spell==Unit.MAGICPLANT && Replay.IsPlaying()==false)//24apr2021 { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 4;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 4;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 4;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 4;y+=Map.GRIDH) { //plant trees...... if(Map.cellunit(x,y)!=Map.VACANT)//24apr2021 { continue;//24apr2021 } if(((x-game.units[i].x)*(x-game.units[i].x)+(y-game.units[i].y)*(y-game.units[i].y))<(Map.GRIDW*Map.GRIDW*8*8)) { if(Functions.rand(0,1000)<200) { Map.planttree(x,y); } } else { if(((x-game.units[i].x)*(x-game.units[i].x)+(y-game.units[i].y)*(y-game.units[i].y))<(Map.GRIDW*Map.GRIDW*10*10)) { if(Functions.rand(0,1000)<100) { Map.planttree(x,y); } } } } } } if(spell==Unit.MAGICSHIELD) { //add +2 to all friendly units within spellcaster * 3 grid squares to their DEF values.... for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(game.units[i].notabuffer>0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0) { if(game.units[nid].armour<4) { game.units[nid].armour++; } Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } if(spell==Unit.MAGICSTEALTH) { //set ourselves to stealthy..... if(Trigger.VARIABLE[Trigger.TYPE_AIRSTRIKE]<=0) { Trigger.VARIABLE[Trigger.TYPE_AIRSTRIKE] = game.units[i].spellcaster; //Console.WriteLine("Artillery called in:"+game.units[i].spellcaster); } } if(spell==Unit.MAGICSTORM)//23feb2022 altered for sci fi game... { //simply decimates the enemy...eg 1/10th of all enemy units are destroyed...... //and does so after a countdown..... if(Trigger.VARIABLE[Trigger.TYPE_ARTILLERY]<=0) { Trigger.VARIABLE[Trigger.TYPE_ARTILLERY] = game.units[i].spellcaster; //Console.WriteLine("Artillery called in:"+game.units[i].spellcaster); } //int storms = game.units[i].spellcaster * 5; /* for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 5;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 5;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 5;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 5;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].spelldefense>0)//01apr2021 { continue; } if(game.units[nid].faction!=game.units[i].faction && game.units[nid].hp>0 && game.units[nid].walkspeed>0) { if(Functions.rand(0,1000)<250) { //do damage..... storms--; game.units[nid].hp-=game.units[i].spellcaster * 5; if(game.units[nid].onscreen) { Functions.saveseed();//25apr2021 if(Functions.rand(0,100)<25) { game.units[nid].playvictimhitsound(game,nid); } Functions.restoreseed();//25apr2021 } //if(game.units[firetargeti].hp<=0) //20mar2021 Functions.saveseed();//11apr2021 int qqq = Functions.rand(0,1000); if(storms==game.units[i].spellcaster*5 - 1 || qqq<200)//11apr2021 qqq { Functions.restoreseed();//11apr2021 Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.LIGHTNINGSPELL); } else { Functions.restoreseed();//11apr2021 } Map.setonfire(x,y,false); if(game.units[nid].hp<=0)//20mar2021 { game.killed(game,nid); game.templates[game.units[i].templateid].kills++; } } } } if(storms<=0) { break; } } if(storms<=0) { break; } } */ } if(spell==Unit.MAGICSWORD) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(game.units[i].notabuffer>0 && nid!=i)//15apr2021 { continue; } if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction && game.units[nid].hp>0 && game.units[nid].damage>0) { if(game.units[nid].damage<10) { game.units[nid].damage++; } Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GREENSPELL); } } } } } if(spell==Unit.MAGICWIND) { for(int x=game.units[i].x - Map.GRIDW * game.units[i].spellcaster * 3;x<=game.units[i].x + Map.GRIDW * game.units[i].spellcaster * 3;x+=Map.GRIDW) { for(int y=game.units[i].y - Map.GRIDH * game.units[i].spellcaster * 3;y<=game.units[i].y + Map.GRIDH * game.units[i].spellcaster * 3;y+=Map.GRIDH) { int nid = Map.cellunit(x,y); if(nid!=-1) { if(game.units[nid].spelldefense>0)//01apr2021 { continue; } if(game.units[nid].faction!=game.units[i].faction && game.units[nid].hp>0 && game.units[nid].walkspeed>0 && game.units[nid].firebullet>0) { game.units[nid].misfire++; Bullet.createbullet(game,game.units[i].x,game.units[i].y+game.units[nid].offy,game.units[nid].x,game.units[nid].y+game.units[nid].offy,Bullet.GOODSPELL); } } } } } } } } } Functions.restoreseed(); } ///////////////////Method Definition/////////////// public static void Formation(Game game,int formation) { //apply a formation to the selected units //formation comes from Gui.... int centrex = -1; int centrey = -1; int count = 0; int sumx = 0; int sumy = 0; int diffx = 0; int diffy = 0; int index = 0; int leadercount = 0; int paniccount = 0; int timidcount = 0; //for(int i=0;i0 && game.units[i].walkspeed>0 && ((game.units[i].faction==Game.PLAYERFACTION && game.units[i].selected!=Unit.SELECTIONNONE) || (game.units[i].faction!=Game.PLAYERFACTION && isai==true && game.units[i].aiselectframe==game.frame))) { count++; sumx+=game.units[i].x; sumy+=game.units[i].y; centrex=sumx/count; centrey=sumy/count; if(game.units[i].retreat) { paniccount++; } if(game.units[i].leader>0) { leadercount++; } if(game.units[i].timid>0) { timidcount++; } } } if(centrex==-1) { return; } //for(int i=0;i0 && game.units[i].walkspeed>0 && game.units[i].faction==Game.PLAYERFACTION && game.units[i].selected!=Unit.SELECTIONNONE) { index++; diffx = game.units[i].x - centrex; diffy = game.units[i].y - centrey; if(formation!=Gui.ACTION_RALLY) { game.units[i].defendx = -1; game.units[i].defendy = -1; game.units[i].orderframe = Unit.ORDERTIME; game.units[i].firetargeti = -1; game.units[i].tmptattempts = 0; Game.ordergivenframe = game.frame; } if(formation==Gui.ACTION_CLOSE) { game.units[i].tx = game.units[i].x - diffx / 2; game.units[i].ty = game.units[i].y - diffy / 2; } if(formation==Gui.ACTION_DEFEND) { game.units[i].defendx = game.units[i].x; game.units[i].defendy = game.units[i].y; } if(formation==Gui.ACTION_ENGAGE) { game.units[i].defendx = -1; game.units[i].defendy = -1; } if(formation==Gui.ACTION_LINEH) { game.units[i].tx = centrex + (index - count/2) * Map.GRIDW; game.units[i].ty = centrey; Game.HORIZONTALFORMATION++; //14apr2021 game.units[i].formationx = game.units[i].tx - centrex;//14apr2021 game.units[i].formationy = game.units[i].ty - centrey;//14apr2021 } if(formation==Gui.ACTION_LINEV) { Game.VERTICALFORMATION++; //14apr2021 game.units[i].tx = centrex; game.units[i].ty = centrey + (index - count/2) * Map.GRIDH; game.units[i].formationx = game.units[i].tx - centrex;//14apr2021 game.units[i].formationy = game.units[i].ty - centrey;//14apr2021 } if(formation==Gui.ACTION_RALLY) { int dieroll = Functions.rand(0,100) - paniccount * 3 - timidcount + leadercount * 25; if(dieroll > RALLYORDERCHANCE) { game.units[i].retreat = false; game.units[i].retreatframe = 0; game.units[i].timid = 0; } } if(formation==Gui.ACTION_OPEN) { game.units[i].tx = game.units[i].x + diffx; game.units[i].ty = game.units[i].y + diffy; } } } Functions.restoreseed(); } //end---------------//9mar2021 ///////////////////Method Definition/////////////// public static int gettemplate(Game game,int index,int step,int depth) { //used for the bestiary going forwards and backwards through the list depth++; int its = 0; if(depth>game.templates.Length + 2) { return 0; } index+=step; if(index>=game.templates.Length) { index = 0; } if(index<0) { index = game.templates.Length - 1; } if(step>0) { while(game.templates[index].faction==Unit.NULLFACTION) { index++; index%=game.templates.Length; its++; if(its>10000) { break; } } } if(step<0) { while(game.templates[index].faction==Unit.NULLFACTION) { index--; if(index<0) { index = game.templates.Length - 1; } index%=game.templates.Length; its++; if(its>10000) { break; } } } return index; } ///////////////////Method Definition/////////////// public static int findtemplatebyname(Game game,string name) //2sep2021 { for(int i=0;i0) { uline[j] = Translation.TranslateWord("stealth",false);//"Stealth"; } if(game.templates[uid].infectchanceonhit>0 || game.templates[uid].infectchanceonkill>0)//22apr2022 { uline[j]+=" "+Translation.TranslateWord("infector",false); } if(game.templates[uid].healer>0) { uline[j]+= " "+Translation.TranslateWord("heal",false);//" Heal"; } if(game.templates[uid].regeneration>0) { uline[j]+=" "+ Translation.TranslateWord("regeneration",false);//Regeneration"; } if(game.templates[uid].firespell>0) { uline[j]+=" "+ Translation.TranslateWord("firespell",false);//Flames"; } if(game.templates[uid].zombiemaster>0) { uline[j]+=" "+ Translation.TranslateWord("zombiemaster",false);// } if(game.templates[uid].banish>0) //12mar2021 { uline[j]+=" "+ Translation.TranslateWord("banishment",false);// } if(game.templates[uid].damagex>0) { uline[j]+=" "+ Translation.TranslateWord("damagex",false);// } if(game.templates[uid].retreat) { uline[j]+=" "+Translation.TranslateWord("panic",false);//" PANIC!"; } if(game.templates[uid].timid>0) { uline[j]+=" "+ Translation.TranslateWord("timid",false);// } if(game.templates[uid].hitandrun>0) { uline[j]+=" "+ Translation.TranslateWord("hitandrun",false);// } //if(game.templates[uid].brave>0)//7mar2021 if(game.templates[uid].brave>0 && game.templates[uid].mob<=0 && game.templates[uid].hatred<=0)//7mar2021 { uline[j]+=" "+ Translation.TranslateWord("brave",false);// } //start-------------//7mar2021 if(game.templates[uid].mob>0) { uline[j]+=" "+ Translation.TranslateWord("mob",false);// } if(game.templates[uid].hatred>0) { uline[j]+=" "+ Translation.TranslateWord("hatred",false);// } if(game.templates[uid].craftsman>0) { uline[j]+=" "+ Translation.TranslateWord("craftsman",false);// } if(game.templates[uid].planar>0) { uline[j]+=" "+ Translation.TranslateWord("planar",false);// } if(game.templates[uid].animosity>0) { uline[j]+=" "+ Translation.TranslateWord("animosity",false);// } if(game.templates[uid].slow>0) { uline[j]+=" "+ Translation.TranslateWord("slow",false);// } if(game.templates[uid].woodsman>0) { uline[j]+=" "+ Translation.TranslateWord("woodsman",false);// } if(game.templates[uid].stupid>0) { uline[j]+=" "+ Translation.TranslateWord("stupid",false);// } if(game.templates[uid].frenzy>0) { uline[j]+=" "+ Translation.TranslateWord("frenzy",false);// } //end---------------//7mar2021 //start-----------//25Feb2021 if(game.templates[uid].highfirerate>0) { uline[j]+=" "+ Translation.TranslateWord("highfirerate",false);// } //end-------------//25Feb2021 if(game.templates[uid].shock>0) { uline[j]+=" "+ Translation.TranslateWord("shocktroops",false);// } if(game.templates[uid].fearsome>0) { uline[j]+=" "+ Translation.TranslateWord("fearsome",false);// } if(game.templates[uid].leader>0) { uline[j]+=" "+ Translation.TranslateWord("leader",false);// } //start---------------//12jul2021 if(game.templates[uid].bounddemon>0) { uline[j]+=" "+ Translation.TranslateWord("bounddemon",false);// } //end-----------------//12jul2021 if(game.templates[uid].firerange2>0) { uline[j]+=" "+ Translation.TranslateWord("damage2",false);// j++; uline[j]+=" "+ Translation.TranslateWord("secondary damage",false)+" "+game.templates[uid].damage2; } if(game.templates[uid].splash>0) //2sep2021 { uline[j]+=" "+ Translation.TranslateWord("splash",false); } for(int i=0;i<4;i++) { uline[i] = uline[i].Trim(); } return uline; } ///////////////////Method Definition/////////////// public static string[] getunittext(Game game,int uid) { //used for displaying informational text about a game unit or creature string[] uline = new string[4]; for(int i=0;i<4;i++) { uline[i] = ""; } uline[0] = game.units[uid].dname();//13mar2021 //13mar2021 lots of translation stuff going on here... int j = 1; string bhp = ""+game.units[uid].basehp; if(game.units[uid].basehp>5000) { bhp = " "+ Translation.TranslateWord("NA",true);//; } uline[j] = Translation.TranslateWord("basehp",true)+":"+bhp+" "+Translation.TranslateWord("walkspeed",true)+":"+game.units[uid].walkspeed; j++; //uline[j] = Translation.TranslateWord("damage",true)+":"+game.units[uid].damage + " " + Translation.TranslateWord("armour",true)+":"+game.units[uid].armour;//28feb2022 uline[j] = Translation.TranslateWord("damage",true)+":"+game.units[uid].damage + " " + Translation.TranslateWord("armour",true)+":"+game.units[uid].armour + " " + Translation.TranslateWord("accuracy",true)+":"+game.units[uid].accuracy;//28feb2022 if(game.units[uid].armour>10000) { uline[j] = "";//"Att:(NA) Def:(NA)"; } j++; if(game.units[uid].stealth>0) { uline[j] = Translation.TranslateWord("stealth",true);//"Stealth"; } if(game.units[uid].infectchanceonhit>0 || game.units[uid].infectchanceonkill>0)//22apr2022 { uline[j]+=" "+Translation.TranslateWord("infector",true);//zombieficator } if(game.units[uid].healer>0) { uline[j]+=" "+Translation.TranslateWord("heal",true);//Heal"; } if(game.units[uid].regeneration>0) { uline[j]+=" "+Translation.TranslateWord("regeneration",true);//" Regen."; } if(game.units[uid].firespell>0) { uline[j]+=" "+Translation.TranslateWord("firespell",true);//" Flames"; } if(game.units[uid].zombiemaster>0) { uline[j]+=" "+Translation.TranslateWord("zombiemaster",true);//" Summoner"; } if(game.units[uid].banish>0) //12mar2021 { uline[j]+=" "+Translation.TranslateWord("banishment",true);//" Banishment"; } if(game.units[uid].damagex>0) { uline[j]+=" "+Translation.TranslateWord("damagex",true);//" Ignore Def"; } if(game.units[uid].retreat) { uline[j]+=" "+Translation.TranslateWord("panic",true);//" PANIC!"; } if(game.units[uid].timid>0) { uline[j]+=" "+Translation.TranslateWord("timid",true);//" Timid"; } if(game.units[uid].hitandrun>0) { uline[j]+=" "+Translation.TranslateWord("hitandrun",true);//; } //if(game.units[uid].brave>0)//7mar2021 if(game.units[uid].brave>0 && game.units[uid].mob<=0 && game.units[uid].hatred<=0)//7mar2021 { uline[j]+=" "+Translation.TranslateWord("brave",true);//" Brave"; } //start-------------//7mar2021 if(game.units[uid].mob>0) { uline[j]+=" "+Translation.TranslateWord("mob",true);//" Mob"; } if(game.units[uid].hatred>0) { uline[j]+=" "+Translation.TranslateWord("hatred",true);//" Hatred"; } if(game.units[uid].craftsman>0) { uline[j]+=" "+Translation.TranslateWord("craftsman",true);//" Craftsman"; } if(game.units[uid].planar>0) { uline[j]+=" "+Translation.TranslateWord("planar",true);//" Planar"; } if(game.units[uid].animosity>0) { uline[j]+=" "+Translation.TranslateWord("animosity",true);//" Animosity"; } if(game.units[uid].slow>0) { uline[j]+=" "+Translation.TranslateWord("slow",true);//" Shambling"; } if(game.units[uid].woodsman>0) { uline[j]+=" "+Translation.TranslateWord("woodsman",true);//" Woodsman"; } if(game.units[uid].stupid>0) { uline[j]+=" "+Translation.TranslateWord("stupid",true);//" Stupid"; } if(game.units[uid].frenzy>0) { uline[j]+=" "+Translation.TranslateWord("frenzy",true);//" Frenzy"; } //end---------------//7mar2021 //start-----------//25Feb2021 if(game.units[uid].highfirerate>1) //NOTE special > 1....it changes from 0 to 1 and 1 to 2 in the actionattack method. { uline[j]+=" "+Translation.TranslateWord("highfirerate",true);//" Fast Shot"; } //end-------------//25Feb2021 if(game.units[uid].shock>0) { uline[j]+=" "+Translation.TranslateWord("shocktroops",true);//" Shock"; } if(game.units[uid].fearsome>0) { uline[j]+=" "+Translation.TranslateWord("fearsome",true);//" Fearsome"; } if(game.units[uid].leader>0) { uline[j]+=" "+Translation.TranslateWord("leader",true);//" Leader"; } //start---------------//12jul2021 if(game.units[uid].bounddemon>0) { uline[j]+=" "+Translation.TranslateWord("bounddemon",true);//Bound Demon } //end-----------------//12jul2021 if(game.units[uid].firerange2>0) { uline[j]+=" "+Translation.TranslateWord("damage2",true);//" Multi Att"; } if(game.units[uid].splash>0)//2sep2021 { uline[j]+= " " + Translation.TranslateWord("splash",true);//Splash Damage } for(int i=0;i<4;i++) { uline[i] = uline[i].Trim(); } return uline; } ///////////////////Method Definition/////////////// public void checkxp(Game game) { //not used //if(xp>=levelxp && levelxp>0) //{ // //level up...... //xp = 0; //} } ///////////////////Method Definition/////////////// public void playattacksound(Game game, int i) { if(game.demomode)//17sep2021 { return; } //play the sound when a unit makes an attack, melee or ranged int count = 0; for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a0) { count = 1 + (Functions.rand(0,1000)%count); for(int a=0;a=3) { //in other words if we have at least two buddies next to us....we're a little braver.... //it also lessens the ability of single shock troops from terrorising whole armies.... //yep this next line is the one you want for the Steam giveaway.....'tmpbrave = 1;' tmpbrave = 1; } //end-----------------//27mar2021 //if(game.units[tid].brave>0)//27mar2021 if(game.units[tid].brave>0 || tmpbrave>0)//27mar2021 { if(Functions.rand(0,1000)<850) { return; } } game.units[tid].shocked = true; if(Functions.rand(0,1000)<500) { game.units[tid].timid=1; } if(Functions.rand(0,1000)<500) { game.units[tid].firetargeti = -1; } if(Functions.rand(0,1000)<100) { game.units[tid].retreat = true; game.units[tid].retreatframe = game.frame + (60 * 20); //game.units[tid].tx = game.units[tid].x + (int)(Functions.rand(-500,500)); //game.units[tid].ty = game.units[tid].y + (int)(Functions.rand(-500,500)); //game.units[tid].tmptx = game.units[tid].tx; //game.units[tid].tmpty = game.units[tid].ty; //game.units[tid].orderframe = Unit.ORDERTIME; } } ///////////////////Method Definition/////////////// public void actionattack(Game game) { //base attack method that handles the whole process of //attacking other units //basic attack // // // int framecheck = 60; if(Config.RUNNINGSPEED>90) { framecheck = 80; } if(Config.RUNNINGSPEED>110) { framecheck = 90; } framecheck/=Config.FASTFRAMECHECK;//14sep2021 if(hp <= 0) { return; } //start-----------//25Feb2021 if(highfirerate>0) { if(highfirerate>2) { highfirerate = 2; } } else { highfirerate = 1; } //end-------------//25Feb2021 if(faction==Unit.NULLFACTION && walkspeed>0) { } if(faction==Unit.NULLFACTION && spawnercount<=0) { return; } bool closerange = false; int griddist = firerange / Map.GRIDW; int griddist2 = firerange2 / Map.GRIDW; if(griddist2==0) { griddist2 = griddist; } if(firerange2>firerange) { griddist = firerange2 / Map.GRIDW; } int myx = x / Map.GRIDW; int myy = y / Map.GRIDH; int enemyx = 0; int enemyy = 0; int ztmp = -1; //if(spawnercount>0 && (game.frame+id)%(framecheck*spawnertime)==0)//9sep2021 if(framesleft>0)//9sep2021 { framesleft--; } if(spawnercount>0 && framesleft==0)//9sep2021 { //if(orderframe>0) //{ //return; //} framesleft = spawnertime * framecheck;//9sep2021 for(int j=0;j=game.templates[ztmp].points) { Trigger.VARIABLE[Trigger.TYPE_POINTS]-=game.templates[ztmp].points; } else { return; } } for(int k=0;kUnit.MAXINDEX) { Unit.MAXINDEX = k;//11apr2021 } return; } } } } } } } return; } //start-------------//12mar2021 if(banish>0 && (game.frame + id)%(framecheck * 10)==1 && firetargeti!=-1) { if(orderframe>0) { return; } int rr1 = 4; bool banished = false; //Functions.saveseed();//11apr2021 for(int ex=myx - rr1;ex<=myx+rr1;ex++) { for(int ey=myy - rr1;ey<=myy + rr1;ey++) { int eid1 = Map.cellunit(ex*Map.GRIDW,ey*Map.GRIDH); if(eid1!=-1) { if(game.units[eid1].zombie>0 && game.units[eid1].hp>0 && game.units[eid1].faction!=faction) { //this unit killed it..... //d100 check to see if we banish it..... if(Functions.rand(0,100+game.units[eid1].zombie*10)0) { // xp+=game.units[eid1].xpvalue; // checkxp(game); } //do death effect..... game.killed(game,eid1); game.templates[templateid].kills++; banished = true; if(animmode != ANIMMODE_ATTACK) { animmode = ANIMMODE_ATTACK; animframe = animmodeattframestart; } } } } } } //Functions.restoreseed();//11apr2021 //Functions.saveseed();//11apr2021 Functions.saveseed();//25apr2021 if(Functions.rand(0,100)<30 && onscreen==true && banished==true) { playmagicsound(game,id); } //Functions.restoreseed();//11apr2021 Functions.restoreseed();//25apr2021 } //end---------------//12mar2021 // /*Explaining framecheck and game.frame + id mod.... ///in a second there are 60 frames. //if we take the game.frame and divide it by 60 at any point it will return a remainder of between 0 and 59. //if...if we take the game.frame and add the index or the id of the array element to it, and then do so we will also get a value between 0 and 59. //Basically - the size of our framecheck determines the value is being between 0 and framecheck-1 //By putting the id into 'game.frame + id' into our mod check...then we ensure that //we only check certain units every nth frame... */ if(zombiemaster>0 && ((game.frame + id)%(framecheck*10)==0) && firetargeti!=-1) { if(orderframe>0) { return; } int maxzombie = 0; for(int j=0;j0 && game.templates[j].faction==faction) { //game.units[i].createunitatxy(game,i,game.templates[j],game.missions[mission].units[i].x,game.missions[mission].units[i].y); if(game.templates[j].zombie > maxzombie) { ztmp = j; maxzombie = game.templates[j].zombie; //break; } } } if(ztmp!=-1) { int rr = 1; //if(game.skirmish) //{ rr = 4; //} int mzombiemaster = zombiemaster;//9apr2021 if(mzombiemaster>4)//9apr2021 { mzombiemaster = 4;//9apr2021 } for(int ex=myx - rr*mzombiemaster*2/maxzombie;ex<=myx+rr*mzombiemaster*2/maxzombie;ex++) { for(int ey=myy - rr*mzombiemaster*2/maxzombie;ey<=myy + rr*mzombiemaster*2/maxzombie;ey++) { int eid = Map.cellunit(ex*Map.GRIDW,ey*Map.GRIDH); if(eid==-1) { //nothing in the cell...... //must have bones in skirmish mode..... //if(game.skirmish==true) //{ if(!Map.dobonesexist(ex * Map.GRIDW, ey*Map.GRIDH)) { continue; } //} for(int k=0;kUnit.MAXINDEX) //11apr2021 { Unit.MAXINDEX = k; } break; } } } } } //Functions.saveseed();//11apr2021 Functions.saveseed();//25apr2021 if(Functions.rand(0,100)<30 && onscreen==true) { playmagicsound(game,id); } Functions.restoreseed();//25apr2021 //Functions.restoreseed();//11apr2021 } return; } //start------------//19mar2021 if(spellcaster>0) { if(orderframe>0) { return; } //start---------------//28mar2021 if((game.frame + id + 30)%framecheck*SPELLCHECK==0 && Game.SPELLSACTIVE==true) { if(faction!=Game.PLAYERFACTION) { //if(onscreen) //replace with ronscreen from replay......25apr2021 if((onscreen==true && Replay.IsPlaying()==false) || (ronscreen==true && Replay.IsPlaying()==true)) //replace with ronscreen from replay......25apr2021 { //we're an ai unit on screen......about to cast a magic spell..... if(firetargeti!=-1) { //and we have a target.... //Functions.saveseed();//11apr2021 int magicspell = (int)Functions.abs(Functions.rand(0,1000)) % 9; if(magicarray[magicspell]>0) { //yep we've got a spell ready.... if(casting==false) { ////// orderframe = Unit.ORDERTIME; casting = true; Unit.SpellCast(game,magicarray[magicspell],faction); casting = false; } } //Functions.restoreseed();//11apr2021 } } } } //end-----------------//28mar2021 if((game.frame + id)%framecheck*SPELLCHECK==0 && notabuffer==0) //once per six seconds.... { //pick a random location within firerange units..... //Functions.saveseed();//11apr2021 int rndx = (int)Functions.rand(x - firerange,x + firerange); int rndy = (int)Functions.rand(y - firerange,y + firerange); int rndid = Map.cellunit(rndx,rndy); bool rbuffed = false; if(rndid!=-1) { int ddx = 0; int ddy = 0; if(game.units[rndid].faction!=faction && rndid!=id && game.units[rndid].hp>0 && game.units[rndid].armour>0 && game.units[rndid].walkspeed>0) //curse an enemy { //we should buff it....if it is performing animmode==ANIMMODE_ATTACK if(game.units[rndid].animmode==ANIMMODE_ATTACK && game.units[rndid].armour>0) { game.units[rndid].armour-=spellcaster; game.units[rndid].cursed = true; //21mar2021 if(game.units[rndid].armour<0) { game.units[rndid].armour=0; } rbuffed = true; //fire a green ball of flame at the friendly unit..... Bullet.createbullet(game,x,y+offy,game.units[rndid].x,game.units[rndid].y+game.units[rndid].offy,Bullet.REDSPELL); if(animmode != ANIMMODE_ATTACK) { animmode = ANIMMODE_ATTACK; animframe = animmodeattframestart; } } ddx = Functions.sign(rndx - x); ddy = Functions.sign(rndy - y); odirn = dirn; if(dirntime>0) { dirntime--; } if(dirntime<=0) { dirntime = Unit.DIRNDELAY; if(ddx==0) { if(ddy>0) { dirn = DIRN_DOWN; } else { dirn = DIRN_UP; } } if(ddy==0) { if(ddx>0) { dirn = DIRN_RIGHT; } else { dirn = DIRN_LEFT; } } if(ddx!=0 && ddy!=0) { if(ddx==-1 && ddy==-1) { dirn = DIRN_UPLEFT; } if(ddx==-1 && ddy==1) { dirn = DIRN_DOWNLEFT; } if(ddx==1 && ddy==-1) { dirn = DIRN_UPRIGHT; } if(ddx==1 && ddy==1) { dirn = DIRN_DOWNRIGHT; } } } } if(game.units[rndid].faction==faction && rndid!=id && game.units[rndid].hp>0 && game.units[rndid].damage>0 && game.units[rndid].walkspeed>0) //buff a friend..... { //unit is alive and part of our faction..... //therefore..... //we should buff it....if it is performing animmode==ANIMMODE_ATTACK if(game.units[rndid].animmode==ANIMMODE_ATTACK && game.units[rndid].damage0) { dirntime--; } if(dirntime<=0) { dirntime = Unit.DIRNDELAY; if(ddx==0) { if(ddy>0) { dirn = DIRN_DOWN; } else { dirn = DIRN_UP; } } if(ddy==0) { if(ddx>0) { dirn = DIRN_RIGHT; } else { dirn = DIRN_LEFT; } } if(ddx!=0 && ddy!=0) { if(ddx==-1 && ddy==-1) { dirn = DIRN_UPLEFT; } if(ddx==-1 && ddy==1) { dirn = DIRN_DOWNLEFT; } if(ddx==1 && ddy==-1) { dirn = DIRN_UPRIGHT; } if(ddx==1 && ddy==1) { dirn = DIRN_DOWNRIGHT; } } } } } //Functions.restoreseed();//11apr2021 if(rbuffed) { return; } } } //end--------------//19mar2021 if(healer>0) { if(orderframe>0) { return; } bool bounddemonhelped = false; //12jul2021 if((game.frame + id)%framecheck==0) { //bool madeeffect = false; for(int ex=myx - healer*2;ex<=myx+healer*2;ex++) { for(int ey=myy - healer*2;ey<=myy + healer*2;ey++) { int eid = Map.cellunit(ex*Map.GRIDW,ey*Map.GRIDH); if(eid!=-1) { //start-------------------------//12jul2021 if(game.units[eid].faction==faction && eid!=id && game.units[eid].bounddemon1 && game.units[eid].hp>0 && bounddemonhelped == false) { game.units[eid].bounddemon+=1; //magic users with healing can prevent bound demons from turning against everyone.....the more you have the better..... bounddemonhelped = true; } //end---------------------------//12jul2021 if(game.units[eid].faction==faction && eid!=id && game.units[eid].hp0) { //ie friend in adjacent or near adjacent square //with less than full health..... game.units[eid].hp+=healer; if(game.units[eid].infected>0)//22apr2022 { game.units[eid].infected = 0; } //Blood.makeblood(game,game.units[eid].x,game.units[eid].y,1); //if(!madeeffect) //{ //Blood.makeblood(game,x,y,1); // madeeffect = true; //} if(game.units[eid].hp>game.units[eid].basehp) { game.units[eid].hp=game.units[eid].basehp; } if(animmode != ANIMMODE_ATTACK) { animmode = ANIMMODE_ATTACK; animframe = animmodeattframestart; } int ddx = Functions.sign(ex - myx); int ddy = Functions.sign(ey - myy); odirn = dirn; if(dirntime>0) { dirntime--; } if(dirntime<=0) { dirntime = Unit.DIRNDELAY; if(ddx==0) { if(ddy>0) { dirn = DIRN_DOWN; } else { dirn = DIRN_UP; } } if(ddy==0) { if(ddx>0) { dirn = DIRN_RIGHT; } else { dirn = DIRN_LEFT; } } if(ddx!=0 && ddy!=0) { if(ddx==-1 && ddy==-1) { dirn = DIRN_UPLEFT; } if(ddx==-1 && ddy==1) { dirn = DIRN_DOWNLEFT; } if(ddx==1 && ddy==-1) { dirn = DIRN_UPRIGHT; } if(ddx==1 && ddy==1) { dirn = DIRN_DOWNRIGHT; } } } } } } } } if(firebullet==0){return;} } if(firetargeti!=-1) { //current target if(game.units[firetargeti].hp > 0) { //check if we are in range....... enemyx = game.units[firetargeti].x / Map.GRIDW; enemyy = game.units[firetargeti].y / Map.GRIDH; if(Functions.abs(myx - enemyx)<= griddist && Functions.abs(myy - enemyy)<= griddist) { //we can attack if(Functions.abs(myx - enemyx)<= griddist && Functions.abs(myy - enemyy)<= griddist2) { closerange = true; } if(closerange) { if(animmode != ANIMMODE_ATTACK) { animmode = ANIMMODE_ATTACK; animframe = animmodeattframestart; } } else { if(animmode != ANIMMODE_ATTACK2) { animmode = ANIMMODE_ATTACK2; animframe = animmodeatt2framestart; } } int ddx = Functions.sign(enemyx - myx); int ddy = Functions.sign(enemyy - myy); odirn = dirn; if(dirntime>0) { dirntime--; } if(dirntime<=0) { dirntime = Unit.DIRNDELAY; if(ddx==0) { if(ddy>0) { dirn = DIRN_DOWN; } else { dirn = DIRN_UP; } } if(ddy==0) { if(ddx>0) { dirn = DIRN_RIGHT; } else { dirn = DIRN_LEFT; } } if(ddx!=0 && ddy!=0) { if(ddx==-1 && ddy==-1) { dirn = DIRN_UPLEFT; } if(ddx==-1 && ddy==1) { dirn = DIRN_DOWNLEFT; } if(ddx==1 && ddy==-1) { dirn = DIRN_UPRIGHT; } if(ddx==1 && ddy==1) { dirn = DIRN_DOWNRIGHT; } } } //if((game.frame + id) % framecheck==0) //25Feb2021 if((game.frame + id) % (framecheck/highfirerate)==0)//25Feb2021 { //once per second attack..... //Console.WriteLine("attacking -have at you!"); int actualdamage = damage - game.units[firetargeti].armour; int infectroll = -1; //start----------//5apr2021 //Functions.saveseed();//11apr2021 if(banish>0 && game.units[firetargeti].zombie>0) { if(Functions.rand(0,100+game.units[firetargeti].zombie*10)0 && game.units[firetargeti].planar>0) { if(Functions.rand(0,100)0) { frenzy--; actualdamage+=damage; } //end---------------//7mar2021 if(!closerange && damage2>0) { actualdamage = damage2 - game.units[firetargeti].armour; } //if(damagex>0)//7mar2021 if(damagex>0 && game.units[firetargeti].craftsman<=0)//7mar2021 { actualdamage+=game.units[firetargeti].armour; //ignores enemy armour..... } if(firespell>0 || game.units[firetargeti].flammable>0) { Map.setonfire(game.units[firetargeti].x,game.units[firetargeti].y,false); } int extradamage = 0; if(powerspell>0) { if((game.frame + id) % (framecheck*powerspell)==0) { extradamage = powerspell; actualdamage += extradamage; } } if(shock>0) { //Functions.saveseed();//11apr2021 shocktarget(game,firetargeti); //Functions.restoreseed();//11apr2021 } //start-------------//7mar2021 if(game.units[firetargeti].woodsman>0) { if(Map.nearobstacle(game.units[firetargeti].x,game.units[firetargeti].y)) { actualdamage/=2; } } //end---------------//7mar2021 //start-------------//24feb2022 if(Config.useseasons>0 && Config.Season==Config.WINTER && firebullet>0)//missile weapons are less effective in Winter... { if(Functions.rand(0,100)<25) { actualdamage/=2; } } //end---------------//24feb2022 if(firebullet==1 || closerange==false) { if(extradamage!=0) { Bullet.createbullet(game,x,y+offy,game.units[firetargeti].x,game.units[firetargeti].y+game.units[firetargeti].offy,powerspell); } else { Bullet.createbullet(game,x,y+offy,game.units[firetargeti].x,game.units[firetargeti].y+game.units[firetargeti].offy,firespell); } //if the target is near woods or other obstacles....then.... if(Map.nearobstacle(game.units[firetargeti].x,game.units[firetargeti].y) || misfire>0) { actualdamage/=2; } } //Functions.saveseed();//11apr2021 if(actualdamage<1) { if(Functions.rand(0,100)<50) //20mar2021 { actualdamage = 0; //20mar2021 } else { actualdamage = 1; } } if(splash>0 && actualdamage>0)//2sep2021 { int splashdamage = actualdamage / 2; if(splashdamage<=0) { splashdamage = 1; } for(int splashx = game.units[firetargeti].x - Map.GRIDW*splash;splashx<=game.units[firetargeti].x + Map.GRIDW*splash;splashx+=Map.GRIDW) { for(int splashy = game.units[firetargeti].y - Map.GRIDH*splash;splashy<=game.units[firetargeti].y + Map.GRIDH*splash;splashy+=Map.GRIDH) { if(Map.cellunit(splashx,splashy)!=Map.VACANT) { int splashi = Map.cellunit(splashx,splashy); if(splashi!=firetargeti) { game.units[splashi].hp-=splashdamage; infectroll = Functions.rand(0,100);//22apr2022 if(infectroll0)//18sep2021 { Gibbet.makegibbets(game,splashi);//18sep2021 } if(infectrollaccuracy)//28feb2022 { actualdamage = 0;//28feb2022 if(accuracy!=0){accuracy++;xp++;}//1mar2022//do better over time....experience growth of units....every miss is a learning experience.... } else { Game.MissionScore+=actualdamage;//1mar2022 } } if(actualdamage!=0)//28feb2022 { game.units[firetargeti].hp-=actualdamage; infectroll = Functions.rand(0,100);//22apr2022 if(infectroll0)//20mar2021 { //this unit killed it..... if(levelxp>0) { //xp+=game.units[firetargeti].xpvalue; //checkxp(game); } //do death effect..... game.killed(game,firetargeti); game.templates[templateid].kills++; if(extragibbet>0)//18sep2021 { Gibbet.makegibbets(game,firetargeti);//18sep2021 } if(infectroll0) { //Functions.saveseed();//11apr2021 if(Functions.rand(0,1000)<150) { //start-------//15mar2021 if(firetargeti!=-1) { tmptattempts = 0; tx = x + (Game.RESOLUTIONX / 3) * (int)Functions.sign(x - game.units[firetargeti].x); ty = y + (Game.RESOLUTIONY / 3) * (int)Functions.sign(y - game.units[firetargeti].y); tmptx = tx; tmpty = ty; } //end---------//15mar2021 firetargeti = -1; orderframe = 180;//15mar2021 //retreat = true;//15mar2021 //retreatframe = game.frame + Unit.RETREATDEATH;//15mar2021 } //Functions.restoreseed();//11apr2021 } } } else { //we should move towards the target tx = game.units[firetargeti].x; ty = game.units[firetargeti].y; tmptattempts = 0; if(retreat) { tx = x + Game.RESOLUTIONX * (int)Functions.sign(x - game.units[firetargeti].x); ty = y + Game.RESOLUTIONY * (int)Functions.sign(y - game.units[firetargeti].y); } if(faction!=Game.PLAYERFACTION && orderframe<=0) { firetargeti = -1; } } } else { firetargeti = -1; } } else { //no current target //find one..... if(orderframe>0) { return; } if(faction!=Game.PLAYERFACTION && game.playingtutorial==true) { return; } if(controlmode=="crpg")//24sep2021 { return; } //start-----------------------//4may2021 if(flightlevel!=-1) { //flying units cannot attack unless they have an anim mode for flying attacks.... //unless they have an animmodeflyattackframestart!=0 if(animmodeflyattackframestart==0 && animmodeflyattackframeend==0) { return; } } //end-------------------------//4may2021 //start-------------//7mar2021 if(stupid>0) { //Functions.saveseed();//11apr2021 if(stupid>=100) { stupid=99; } //if(Functions.rand(0,100)=AI_ASSAULT && faction!=Game.PLAYERFACTION && game.playerready==true)//18sep2021 if(ai>=AI_ASSAULT && (faction!=Game.PLAYERFACTION || Config.AUTOPLAY>0) && game.playerready==true)//18sep2021 { aidist = 45 * ai; } //if(game.skirmish==true && ai>0 && faction!=Game.PLAYERFACTION)//27mar2021//18sep2021 if(game.skirmish==true && ai>0 && (faction!=Game.PLAYERFACTION || Config.AUTOPLAY>0))//27mar2021//18sep2021 { aidist = Map.MAXX + Map.MAXY + 10; //27mar2021 } int rangeblock = 1 + ((game.frame + id) % aidist); if(rangeblock>aidist) { rangeblock = aidist; } //start-------------//7mar2021 if(slow>0) { rangeblock/=2; } //end---------------//7mar2021 if(rangeblock<1) { rangeblock = 1; } //up to 12 squares away...... if(stealth>0) { if (rangeblock>4) { rangeblock = 1 + (rangeblock % 4); } } int target = -1; int mindist = 9999; int dist = 0; int fl = (game.frame + id) % Map.FLIGHTLEVELS;//4may2021 for(int cx=myx - rangeblock;cx<=myx + rangeblock;cx++) { int cyy = myy - rangeblock; target = Map.cellunit(cx * Map.GRIDW,cyy * Map.GRIDH); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cx && game.units[target].y / Map.GRIDH == cyy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cx - myx) + Functions.abs(cyy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { if(needlos>0)//15sep2021 { if(los(game,id,target)) { mindist = dist; firetargeti = target; } } else//15sep2021 { mindist = dist; firetargeti = target; } } } } target = -1; } //start---------------------//4may2021 if(canattackair>0) { cyy = myy - rangeblock; target = Map.cellflyer(cx * Map.GRIDW,cyy * Map.GRIDH,fl); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cx && game.units[target].y / Map.GRIDH == cyy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cx - myx) + Functions.abs(cyy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { mindist = dist; firetargeti = target; } } } target = -1; } cyy = myy + rangeblock; target = Map.cellflyer(cx * Map.GRIDW,cyy * Map.GRIDH,fl); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cx && game.units[target].y / Map.GRIDH == cyy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cx - myx) + Functions.abs(cyy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { mindist = dist; firetargeti = target; } } } target = -1; } } //end-----------------------//4may2021 cyy = myy + rangeblock; target = Map.cellunit(cx * Map.GRIDW,cyy * Map.GRIDH); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cx && game.units[target].y / Map.GRIDH == cyy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cx - myx) + Functions.abs(cyy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { if(needlos>0)//15sep2021 { if(los(game,id,target)) { mindist = dist; firetargeti = target; } } else//15sep2021 { mindist = dist; firetargeti = target; } } } } } target = -1; } for(int cy=myy - rangeblock;cy<=myy + rangeblock;cy++) { int cxx = myx - rangeblock; target = Map.cellunit(cxx * Map.GRIDW,cy * Map.GRIDH); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cxx && game.units[target].y / Map.GRIDH == cy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cxx - myx) + Functions.abs(cy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { if(needlos>0)//15sep2021 { if(los(game,id,target)) { mindist = dist; firetargeti = target; } } else//15sep2021 { mindist = dist; firetargeti = target; } } } } target = -1; } //start-----------------------//4may2021 if(canattackair>0) { cxx = myx - rangeblock; target = Map.cellflyer(cxx * Map.GRIDW,cy * Map.GRIDH,fl); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cxx && game.units[target].y / Map.GRIDH == cy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cxx - myx) + Functions.abs(cy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { mindist = dist; firetargeti = target; } } } } target = -1; cxx = myx + rangeblock; target = Map.cellflyer(cxx * Map.GRIDW,cy * Map.GRIDH,fl); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cxx && game.units[target].y / Map.GRIDH == cy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cxx - myx) + Functions.abs(cy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { mindist = dist; firetargeti = target; } } } } target = -1; } //end-------------------------//4may2021 cxx = myx + rangeblock; target = Map.cellunit(cxx * Map.GRIDW,cy * Map.GRIDH); if(target!=-1) { if(game.units[target].x / Map.GRIDW == cxx && game.units[target].y / Map.GRIDH == cy) { if(game.units[target].hp>0 && game.units[target].faction!=faction && game.units[target].faction!=Unit.NULLFACTION) { dist = (int)(Functions.abs(cxx - myx) + Functions.abs(cy - myy)); if(game.units[target].walkspeed>0 && prefermobiletargets>0)//18sep2021 { //75% more likely to choose a mobile target.... dist*=3; dist/=4; //and they get a 10% higher rating for every point of 'extra speed' they have..... //noting that walkspeed is only between 1 and 3 and never as high as 10. dist*=(10 - game.units[target].walkspeed); dist/=10; } if(dist < mindist && dist < (rangeblock + 2) * Map.GRIDW) { if(needlos>0)//15sep2021 { if(los(game,id,target)) { mindist = dist; firetargeti = target; } } else//15sep2021 { mindist = dist; firetargeti = target; } } } } } target = -1; } if(firetargeti!=-1) { if(game.units[firetargeti].stealth>0) { //stealthy units are harder to target...unless they are themselves attacking...... if(game.units[firetargeti].animmode<=ANIMMODE_WALK) { //cannot be targeted..... //unless they are within 2 grid squares.... if(Functions.abs(x-game.units[firetargeti].x)>=Map.GRIDW*3 || Functions.abs(y - game.units[firetargeti].y)>=Map.GRIDH*3) { firetargeti = -1; orderframe = 1; tx = x; ty = y; tmptx = x; tmpty = y; } } } if(transportcapacity>0 && faction!=Game.PLAYERFACTION && (game.frame + id) % 60==6)//24apr2022 { if(Functions.abs(tx-x)<300 && Functions.abs(ty-y)<300) { //Unit.DeployUnits(game,id); } } } else//24apr2022 { if(faction!=Game.PLAYERFACTION && (game.frame + id) % 60==5) { if(transportsize>0 && transportsize<99) { //look around us for an APC for(int xx=x-Map.GRIDW*3;xx<=x+Map.GRIDW*3;xx+=Map.GRIDW) { for(int yy=y-Map.GRIDH*3;yy<=y+Map.GRIDH*3;yy+=Map.GRIDH) { int nid = Map.cellunit(xx,yy); if(nid!=Map.VACANT) { if(game.units[nid].faction==faction) { if(game.units[nid].hp>0 && game.units[nid].transportcapacity>0 && transportsize=4 && onscreen==true) { //Functions.saveseed();//11apr2021 Functions.saveseed();//25apr2021 if(Functions.rand(0,100)<20 && faction==Game.PLAYERFACTION) { playtargetchosensound(game,id); } if(Functions.rand(0,100)<5 && faction!=Game.PLAYERFACTION) { playtargetchosensound(game,id); } Functions.restoreseed();//25apr2021 //Functions.restoreseed();//11apr2021 } } } ///////////////////Method Definition/////////////// public static bool los(Game game,int id,int target) { int sx = game.units[id].x / Map.GRIDW; int sy = game.units[id].y / Map.GRIDH; int fx = game.units[target].x / Map.GRIDW; int fy = game.units[target].y / Map.GRIDH; if(sx>=0 && sx=0 && sy=0 && fx=0 && fy0) { if(game.units[i].selected==Unit.SELECTIONFROZEN) { count++; } } } return count; } ///////////////////Method Definition/////////////// public static void issueorder(Game game,int gx, int gy) { //issue a move or attack order bool ordered = false; int j = -1; int scount = countselected(game); //for(int i=0;i0) { if(game.units[i].selected==Unit.SELECTIONFROZEN) { game.units[i].tx = gx; game.units[i].ty = gy; if(Game.HORIZONTALFORMATION>0 || Game.VERTICALFORMATION>0)//14apr2021 { game.units[i].tx+=game.units[i].formationx; game.units[i].ty+=game.units[i].formationy; } else { game.units[i].formationx = 0; game.units[i].formationy = 0; } game.units[i].orderframe = Unit.ORDERTIME; game.units[i].firetargeti = -1; game.units[i].tmptattempts = 0; game.units[i].defendx = -1; //12mar2021 game.units[i].defendy = -1; //12mar2021 Game.ordergivenframe = game.frame; ordered = true; j = i; //12mar2021 - added a radius of 1 grid square around it.... int nid = Map.cellunit(game.units[i].tx,game.units[i].ty); if(nid==-1) { nid = Map.cellunit(game.units[i].tx - Map.GRIDW,game.units[i].ty); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty - Map.GRIDH); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty + Map.GRIDH); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } //start--------//24mar2021 //if(Game.mouseoverunitid!=-1)//4sep2021 //start--------//22feb2022 bool donot = false; for(int fl=0;fl0 && game.units[fid].transportcapacity>0 && game.units[i].transportsize0 && game.units[nid].transportcapacity>0 && game.units[i].transportsize0 && game.units[nid].faction!=Unit.NULLFACTION) { game.units[i].firetargeti = nid; game.units[i].orderframe = 0; Game.clickerrow = 1;//15apr2021 } } //if(scount > 1 && Game.VERTICALFORMATION==0 && Game.HORIZONTALFORMATION==0)//14apr2021//15sep2021 if(scount > 1 && Game.VERTICALFORMATION==0 && Game.HORIZONTALFORMATION==0 && Config.CLUMP==0)//14apr2021//15sep2021 { game.units[i].tx = gx + (int)Functions.rand(-Map.GRIDW*4,Map.GRIDW*4); game.units[i].ty = gy + (int)Functions.rand(-Map.GRIDH*4,Map.GRIDH*4); } } } } if(ordered) { game.units[j].playacknowledgesound(game,j); } } ///////////////////Method Definition/////////////// public static void issueorder(Game game) { //issue a move or attack order bool ordered = false; int j = -1; int scount = countselected(game); //for(int i=0;i0) { if(game.units[i].selected==Unit.SELECTIONFROZEN) { //zoom stuff game.units[i].tx = Game.CORNERX + (Game.RESOLUTIONX/2) + (int)(((float)(game.mx) - (float)Game.RESOLUTIONX/2)/game.zoom); game.units[i].ty = Game.CORNERY + (Game.RESOLUTIONY/2) + (int)(((float)(game.my) - (float)Game.RESOLUTIONY/2)/game.zoom); game.units[i].orderframe = Unit.ORDERTIME; game.units[i].firetargeti = -1; game.units[i].tmptattempts = 0; game.units[i].defendx = -1; //12mar2021 game.units[i].defendy = -1; //12mar2021 if(Game.HORIZONTALFORMATION>0 || Game.VERTICALFORMATION>0)//14apr2021 { game.units[i].tx+=game.units[i].formationx; game.units[i].ty+=game.units[i].formationy; } else { game.units[i].formationx = 0; game.units[i].formationy = 0; } ordered = true; Game.ordergivenframe = game.frame; j = i; int nid = Map.cellunit(game.units[i].tx,game.units[i].ty); //12mar2021 added these 1 grid cell checker... if(nid==-1) { nid = Map.cellunit(game.units[i].tx - Map.GRIDW,game.units[i].ty); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty - Map.GRIDH); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } if(nid==-1) { nid = Map.cellunit(game.units[i].tx + Map.GRIDW,game.units[i].ty + Map.GRIDH); if(nid!=-1) { if(game.units[nid].faction==game.units[i].faction) { nid = -1; } } } //start--------//22feb2022 bool donot = false; for(int fl=0;fl0 && game.units[fid].transportcapacity>0 && game.units[i].transportsize0 && game.units[nid].transportcapacity>0 && game.units[i].transportsize0 && game.units[nid].faction!=Unit.NULLFACTION) { game.units[i].firetargeti = nid; game.units[i].orderframe = 0; Game.clickerrow = 1;//15apr2021 } } //if(scount > 1) //if(scount > 1 && Game.VERTICALFORMATION==0 && Game.HORIZONTALFORMATION==0)//14apr2021//15sep2021 if(scount > 1 && Game.VERTICALFORMATION==0 && Game.HORIZONTALFORMATION==0 && Config.CLUMP==0)//14apr2021//15sep2021 { game.units[i].tx+= (int)Functions.rand(-Map.GRIDW*4,Map.GRIDW*4); game.units[i].ty+= (int)Functions.rand(-Map.GRIDH*4,Map.GRIDH*4); } } } } if(ordered) { game.units[j].playacknowledgesound(game,j); } } ///////////////////Method Definition/////////////// public static void deselect(Game game) { //deselect all units if(game.frame - game.minimapframe>5) { //for(int i=0;i0 && (game.units[i].faction==Game.PLAYERFACTION || Game.EDITOR==true)) { //if(game.units[i].faction==PLAYERFACTION) //{ //zoom stuff int mmx = (int)((float)(game.mx - Game.RESOLUTIONX/2)/game.zoom) + Game.CORNERX + Game.RESOLUTIONX/2; int mmy = (int)((float)(game.my - Game.RESOLUTIONY/2)/game.zoom) + Game.CORNERY + Game.RESOLUTIONY/2; if(mmx < game.units[i].x + (game.units[i].cw/2)/game.zoom && mmx > game.units[i].x - (game.units[i].cw/2)/game.zoom) { if(mmy < game.units[i].y + (game.units[i].ch/2)/game.zoom + (game.units[i].offy)/game.zoom && mmy > game.units[i].y - (game.units[i].ch/2 + game.units[i].offy)/game.zoom) { if(game.frame - game.units[i].selectedframe < 15) { //select all of the same type..... //for(int j=0;j0 && game.units[j].name==game.units[i].name) { game.units[j].selected = Unit.SELECTIONSTART; } } } game.units[i].selected = Unit.SELECTIONSTART; game.units[i].selectedframe = game.frame; //Game.selectingtime = Game.WAITSELECTINGTIME;//26mar2021 return; } } //} } } } ///////////////////Method Definition/////////////// public static bool noneselected(Game game) { //check if no units are selected //for(int i=0;i0) { if(game.units[i].selected!=Unit.SELECTIONNONE) { return false; } } } return true; } ///////////////////Method Definition/////////////// public static void freezeselect(Game game) { //take units that have been drag selected and //mark them as properly selected bool selected = false; //for(int i=0;i0) { if(game.units[i].selected==Unit.SELECTIONSTART) { game.units[i].selected=Unit.SELECTIONFROZEN; if(!selected) { selected = true; game.units[i].playselectsound(game,i); } } } } } ///////////////////Method Definition/////////////// public static void select(Game game,int x, int y, int w, int h) { //select the units at this location //zoom stuff bool anyselected = false; bool selectsingle = false; int ww = 0; int hh = 0; if(w==-1 && h==-1) { w = 40 ;//* (int)game.zoom; h = 40 ;//* (int)game.zoom; selectsingle = true; ww = w; hh = h; } //for(int i=0;i0 && (game.units[i].faction==Game.PLAYERFACTION || Game.EDITOR==true)) { //if(game.units[i].faction==PLAYERFACTION) //{ //if(x + Game.CORNERX game.units[i].x) //if(x - ww game.units[i].x)//26mar2021 if((x - ww game.units[i].x) || (i == Game.mouseoverunitid && selectsingle==true))//26mar2021 { //if(y + Game.CORNERY < game.units[i].y + game.units[i].offy && y + Game.CORNERY + h > game.units[i].y + game.units[i].offy) //if(y - hh < game.units[i].y + game.units[i].offy/game.zoom && y + h > game.units[i].y + game.units[i].offy/game.zoom)//26mar2021 if((y - hh < game.units[i].y + game.units[i].offy/game.zoom && y + h > game.units[i].y + game.units[i].offy/game.zoom) || (i == Game.mouseoverunitid && selectsingle==true))//26mar2021 { anyselected = true; if(selectsingle) { if(game.frame - game.units[i].selectedframe < 15) { //select all of the same type..... //for(int j=0;j0 && game.units[j].name==game.units[i].name) { game.units[j].selected = Unit.SELECTIONSTART; } } } else { //28mar2021 check for(int j=0;j<=Unit.MAXINDEX;j++)//26mar2021 { game.units[j].selected = Unit.SELECTIONNONE; } } } game.units[i].selected = Unit.SELECTIONSTART; game.units[i].selectedframe = game.frame; //Game.selectingtime = Game.WAITSELECTINGTIME;//26mar2021 if(selectsingle) { break; } } } //} } } //start-------------//9mar2021 //this block prevents units from being deselected when an icon in the gui is clicked upon //eg - if you are clicking the selection icons you don't want everything to become unselected //because you've left clicked somewhere on the screen! for(int i=0;i=Gui.ACTION_FORMATIONSTART && game.gui[i].action<=Gui.ACTION_FORMATIONEND && game.gui[i].mouseover==true) { return; //looks okay } //start-------------//10mar2021 if(game.gui[i].triggerlink==Gui.LINK_SPAWNER_ICON && game.gui[i].mouseover==true && (Game.SPAWNERSELECTED==true || Game.NONSPAWNERSELECTED==true))//11mar2021 { return; //looks okay } //end---------------//10mar2021 //start-------------//2sep2021 if(game.gui[i].triggerlink==Gui.LINK_TECH_ICON && game.gui[i].mouseover==true && (Game.SPAWNERSELECTED==true || Game.NONSPAWNERSELECTED==true || Tech.TECHUNITSELECTED == true))//11mar2021 { return; //looks okay } //end---------------//2sep2021 //start-----------------//22mar2021 if(Game.showingselectedicons==true && game.gui[i].triggerlink==Gui.LINK_SELECTED_ICONS && game.gui[i].mouseover==true) { return;//looks okay } //end-------------------//22mar2021 //start---------------//28mar2021 if(Game.SPELLCASTERSELECTED!=-1 && game.gui[i].action>=Gui.ACTION_SPELL_START && game.gui[i].action<=Gui.ACTION_SPELL_END && game.gui[i].mouseover==true) { return;//looks okay } //end-----------------//28mar2021 } //end---------------//9mar2021 if(!anyselected) { Unit.deselect(game); //and check if any enemy are selected...... //for(int i=0;i0 && (game.units[i].faction!=Game.PLAYERFACTION)) { if(x - ww game.units[i].x) { if(y - hh < game.units[i].y + game.units[i].offy/game.zoom && y + h > game.units[i].y + game.units[i].offy/game.zoom) { game.units[i].selected = Unit.SELECTIONENEMY; break; } } //} } } } } ///////////////////Method Definition/////////////// public static void deselectall(Game game) { //as title if(game.frame - game.minimapframe > 5) { //for(int i=0;i0) { alpha = 0.7f + 0.25f * (float)Math.Sin((float)game.frame/20); } int tmpanimframe = animframe; onscreen = true; if(faction==NULLFACTION || nodirn==1) //scenery...special scenery... { if(walkspeed<=0) { dirn = 0; animmode = ANIMMODE_IDLE; } } if(hp <= 0) { if(animmode!=ANIMMODE_DEAD)//13sep2021 { return; } } //start-----------------//21mar2021 //circles are offset too wrongly..... //if(Config.USEICONCIRCLES==true && Config.USEFEETCIRCLES==true)//20apr2021 //2jun2021 removed whole next section and moved it elsewhere...where circlesmax is used.... /* if(Config.USEFEETCIRCLES && game.templates[templateid].walkspeed>0)//20apr2021 { //offx added 20apr2021 if(selected!=Unit.SELECTIONNONE) { if(Game.iconcircles!=-1) { float cc = 0.8f; int cw0 = cw; int ch0 = ch; if(cw0<70) { cw0 = 70; } if(ch0<85) { ch0 = 85; } if(faction==Game.PLAYERFACTION) { //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,0,0,false,1f,Game.iconcircles); //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,0,1,false,0.25f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX,height + y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,0,0,false,1f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX,height + y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,0,1,false,0.25f,Game.iconcircles); } else { //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,1,0,false,1f,Game.iconcircles); //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,1,1,false,0.25f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX,height + y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,1,0,false,1f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX,height + y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,1,1,false,0.25f,Game.iconcircles); } } } } */ //start-------------//24mar2021 //if(game.mx > x-Game.CORNERX - cw/2 && game.mx < x - Game.CORNERX + cw/2 && game.my > y - Game.CORNERX + offy - ch/2 && game.my < y - Game.CORNERY + offy + ch/2)//26mar2021 if(game.mx > x-Game.CORNERX - cw/4 && game.mx < x - Game.CORNERX + cw/4 && game.my > y - Game.CORNERY + offy - ch/4 && game.my < y - Game.CORNERY + offy + ch/4 && game.zoom==1)//26mar2021 { //24apr2021 addressed potential mouseoverunitid being corrupt if(hp>0)//24apr2021 { Game.mouseoverunitid = id; } } //end---------------//24mar2021 //end-------------------//21mar2021 if(cat==-1) //show coloured rectangles if there are no graphics yet... { byte tr = 32; byte tg = 200; byte tb = 32; if(faction!=Game.PLAYERFACTION) { tr = 200; tg = 32; } RenderList.drawrect(game,x - Game.CORNERX - cw/2,height + y - Game.CORNERY - ch/2+offy,cw,ch,RenderList.getrgb(tr,tg,tb),0); //RenderList.drawtext(game,x - Game.CORNERX - cw/2,height + y - Game.CORNERY - ch+offy,name,RenderList.getrgb(200,200,180),game.fonts[Resources.SMALLFONT].font,true);//13mar2021 RenderList.drawtext(game,x - Game.CORNERX - cw/2,height + y - Game.CORNERY - ch+offy,dname(),RenderList.getrgb(200,200,180),game.fonts[Resources.SMALLFONT].font,true);//13mar2021 } else { if(mirrorleftright && (dirn==DIRN_DOWNRIGHT || dirn==DIRN_RIGHT || dirn==DIRN_UPRIGHT)) { int tmpdirn = dirn; if(dirn==DIRN_DOWNRIGHT) { tmpdirn = DIRN_DOWNLEFT; } if(dirn==DIRN_RIGHT) { tmpdirn = DIRN_LEFT; } if(dirn==DIRN_UPRIGHT) { tmpdirn = DIRN_UPLEFT; } //2apr2021 added alpha //9apr2021 cathires //20apr2021 added offx if(dropshadow>0)//25sep2021 { RenderList.drawrect(game,offx + x - Game.CORNERX + (int)(scale * cw/2) - cw/14,height + y - Game.CORNERY + offy + (int)(scale * ch * 8) / 10,(int)(scale * cw/7),(int)(scale * ch/10),RenderList.getrgb(10,10,10),0); } if(cathires!=-1) { //25sep2021 added scale RenderList.drawimage(game,game.images[cathires].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.5f * scale,0.5f * scale,tmpdirn * framesperdirn + tmpanimframe,0,false,alpha,cathires); //start----------//28feb2022 if(faction==6 && basehp<20 && Config.highseas!=0) { //if(Game.highseas_lo!=-1) //{ //RenderList.drawimage(game,game.images[Game.highseas_lo].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.5f * scale,0.5f * scale,tmpdirn,0,false,alpha,Game.highseas_lo); //} if(Game.highseas_hi!=-1 && tmpdirn==0) { RenderList.drawimage(game,game.images[Game.highseas_hi].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.75f * scale,0.75f * scale,tmpdirn,0,false,alpha,Game.highseas_hi); } } //end------------//28feb2022 } else { //25sep2021 added scale RenderList.drawimage(game,game.images[cat].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-1f * scale,1f * scale,tmpdirn * framesperdirn + tmpanimframe,0,false,alpha,cat); //start----------//28feb2022 if(faction==6 && basehp<20 && Config.highseas!=0) { if(Game.highseas_lo!=-1 && tmpdirn==0) { RenderList.drawimage(game,game.images[Game.highseas_lo].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.75f * scale,0.75f * scale,tmpdirn,0,false,alpha,Game.highseas_lo); } //if(Game.highseas_hi!=-1) //{ // RenderList.drawimage(game,game.images[Game.highseas_hi].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.5f * scale,0.5f * scale,tmpdirn,0,false,alpha,Game.highseas_hi); //} } //end------------//28feb2022 } } else { if(controlpoint==1) { //20apr2021 added offx if(controller==Game.PLAYERFACTION) { //25sep2012 added scale RenderList.drawimage(game,game.images[fcat].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f * scale,1f * scale,dirn * framesperdirn + tmpanimframe,0,false,1f,fcat); } if(controller==Game.SKIRMISHENEMYFACTION) { //25sep2012 added scale RenderList.drawimage(game,game.images[ecat].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f * scale,1f * scale,dirn * framesperdirn + tmpanimframe,0,false,1f,ecat); } if(controller!=Game.PLAYERFACTION && controller!=Game.SKIRMISHENEMYFACTION) { //9apr2021 hires stuff //20apr2021 added offx if(cathires!=-1) { //25sep2012 added scale RenderList.drawimage(game,game.images[cathires].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,0.5f * scale,0.5f * scale,dirn * framesperdirn + tmpanimframe,0,false,1f,cathires); } else { //25sep2012 added scale RenderList.drawimage(game,game.images[cat].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY+offy,0,1f * scale,1f * scale,dirn * framesperdirn + tmpanimframe,0,false,1f,cat); } } } else { //2apr2021 added alpha //9apr2021 added hires //20apr2021 added offx if(nodirn>0) { dirn = 0; } if(cathires!=-1) { //25sep2012 added scale RenderList.drawimage(game,game.images[cathires].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY+offy,0,0.5f * scale,0.5f * scale,dirn * framesperdirn + tmpanimframe,0,false,alpha,cathires); //start----------//28feb2022 if(faction==6 && basehp<20 && Config.highseas!=0) { //if(Game.highseas_lo!=-1) //{ //RenderList.drawimage(game,game.images[Game.highseas_lo].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.5f * scale,0.5f * scale,dirn,0,false,alpha,Game.highseas_lo); //} if(Game.highseas_hi!=-1 && dirn==0) { RenderList.drawimage(game,game.images[Game.highseas_hi].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.75f * scale,0.75f * scale,dirn,0,false,alpha,Game.highseas_hi); } } //end------------//28feb2022 } else { //25sep2012 added scale RenderList.drawimage(game,game.images[cat].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY+offy,0,1f * scale,1f * scale,dirn * framesperdirn + tmpanimframe,0,false,alpha,cat); //start----------//28feb2022 if(faction==6 && basehp<20 && Config.highseas!=0) { if(Game.highseas_lo!=-1 && dirn==0) { RenderList.drawimage(game,game.images[Game.highseas_lo].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.75f * scale,0.75f * scale,dirn,0,false,alpha,Game.highseas_lo); } //if(Game.highseas_hi!=-1) //{ // RenderList.drawimage(game,game.images[Game.highseas_hi].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,-0.5f * scale,0.5f * scale,dirn,0,false,alpha,Game.highseas_hi); //} } //end------------//28feb2022 } } } } if(Unit.CRPG>0)//25sep2021 { if(faction==Game.SKIRMISHENEMYFACTION && hp>0) { drawhealthbar(game); } } //25sep2021 removed this again.... //2jun2021 altered this section and moved it elsewhere.... //if(selected!=Unit.SELECTIONNONE || (bossmonster>0 && game.skirmish==false)) //{ //if(game.templates[templateid].walkspeed<=0 || selected==Unit.SELECTIONNONE) //2jun2021 - this is to account for the fact that SOME of these won't be drawn in the other section.... //{ // drawhealthbar(game); //} //} //if(retreat)//15mar2021 //20apr2021 added offx if(retreat==true && Game.whiteflag!=-1)//15mar2021 { RenderList.drawimage(game,game.images[Game.whiteflag].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f,1f,tmpanimframe % 3,0,false,1f,Game.whiteflag); } if((defendx!=-1 || defendy!=-1) && Game.shield!=-1)//15mar2021 { RenderList.drawimage(game,game.images[Game.shield].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f,1f,0,0,false,1f,Game.shield); } if(buffed && Game.iconplus!=-1) //21mar2021 { RenderList.drawimage(game,game.images[Game.iconplus].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f,1f,0,0,false,1f,Game.iconplus); } if((cursed==true || misfire!=0) && Game.iconminus!=-1) { RenderList.drawimage(game,game.images[Game.iconminus].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY+offy,0,1f,1f,0,0,false,1f,Game.iconminus); } //start-----------------//21mar2021 //20apr2021 added offx if(Config.USEICONCIRCLES) { if(Game.iconcircles!=-1 && Game.groupselected==groupid) { if(groupid>=0 && groupid<=9) { //25sep2012 added scale RenderList.drawimage(game,game.images[Game.iconcircles].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY + offy,0,0.5f * scale,0.5f * scale,2 + groupid,0,false,1f,Game.iconcircles); } } if(Config.USECOVERFLAG) { if(Game.iconcircles!=-1 && game.gamestate==Game.CAT_GAMESTATE_GAME) { if(Map.nearobstacle(x,y)) { //coverindicator RenderList.drawimage(game,game.images[Game.iconcircles].texture,offx + x-Game.CORNERX,height + y-Game.CORNERY + offy,0,0.5f,0.5f,12,0,false,1f,Game.iconcircles); } } } } //end-------------------//21mar2021 //20apr2021 added offx if(Game.EDITOR) { //RenderList.drawtext(game,x - Game.CORNERX,height + y - Game.CORNERY + offy,name+","+(x/Map.GRIDW)+","+(y/Map.GRIDH),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//13mar2021 RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy,dname()+","+Translation.TranslateNumber(x/Map.GRIDW)+","+Translation.TranslateNumber(y/Map.GRIDH),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//13mar2021 } else//10sep2021 { if(displaycharactername>0) { RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy - ch/2,dname(),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//13mar2021 } } //if(spawner!="" && spawnercount>0) //11mar2021//13mar2021 //start--------------//13mar2021 if(displayspawner=="") { displayspawner = spawner; } //end----------------//13mar2021 if(spawnertemplateid!=-1 && faction==Game.PLAYERFACTION)//26feb2022//25apr2022 added playerfaction { if(Trigger.VARIABLE[Trigger.TYPE_POINTS]0) //11mar2021//13mar2021 { //todo 13mar2021 //RenderList.drawtext(game,x - Game.CORNERX,height + y - Game.CORNERY + offy,spawner,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//13mar2021 //RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy,displayspawner,RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//13mar2021//24apr2021 RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy,displayspawner + " " +Translation.TranslateNumber(spawnercount),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//24apr2021 RenderList.drawunfilledrect(game,offx + x - Game.CORNERX - 1 - 50,height + y - Game.CORNERY + offy - game.fonts[Resources.FONT].ptsize * 2 - 1,100,4,RenderList.getrgb(180,180,200),0); RenderList.drawrect(game,offx + x - Game.CORNERX - 50,height + y - Game.CORNERY + offy - game.fonts[Resources.FONT].ptsize * 2,percentagespawn(game),2,RenderList.getrgb(32,255,255),0); } //start-----------//12jul2021 if(bounddemon>1) { RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy," " +Translation.TranslateNumber(bounddemon),RenderList.getrgb(255,255,200),game.fonts[Resources.FONT].font,true);//24apr2021 } if(bounddemon==1) { RenderList.drawtext(game,x - Game.CORNERX + offx,height + y - Game.CORNERY + offy,Translation.TranslateWord("!",false) ,RenderList.getrgb(255,155,100),game.fonts[Resources.FONT].font,true);//24apr2021 } //end-------------//12jul2021 drawn = true; } ///////////////////Method Definition/////////////// public void drawhealthbar(Game game) { //draw the unit's health bar int pct = ((10 * hp) / basehp) - 1; if (pct<0) { pct = 0; } if(pct>5) { pct = 5; } //20apr2021 added offx RenderList.drawanimimage(game,game.images[Game.healthbar].texture,offx + x - Game.CORNERX,height + y - Game.CORNERY - ch/2 + offy,0,1f,1f,pct,0,false,1f,Game.healthbar); //also show xp //1mar2022 if(faction==6) { if(xp>5) { RenderList.drawrect(game,-5 + offx + x - Game.CORNERX,height + y - Game.CORNERY - ch/2 + offy + 3,2,2,RenderList.getrgb(255,225,64),0); } if(xp>10) { RenderList.drawrect(game,- 5 + offx + x - Game.CORNERX + 5,height + y - Game.CORNERY - ch/2 + offy + 3,2,2,RenderList.getrgb(255,225,64),0); } if(xp>15) { RenderList.drawrect(game,- 5 + offx + x - Game.CORNERX + 10,height + y - Game.CORNERY - ch/2 + offy + 3,2,2,RenderList.getrgb(255,225,64),0); } } if(infected>0)//24apr2022 { RenderList.drawrect(game,- 5 + offx + x - Game.CORNERX + 15,height + y - Game.CORNERY - ch/2 + offy + 3,2,2,RenderList.getrgb(64,235,64),0); } //int pct = (cw * hp) / basehp; /* RenderList.drawrect(game,x - Game.CORNERX - cw/2,y - Game.CORNERY - ch/2+offy,cw,3,RenderList.getrgb(255,32,32),0); if(bossmonster>0 && game.skirmish==false) { RenderList.drawrect(game,x - Game.CORNERX - cw/2,y - Game.CORNERY - ch/2+offy,pct,3,RenderList.getrgb(255,255,32),0); } else { RenderList.drawrect(game,x - Game.CORNERX - cw/2,y - Game.CORNERY - ch/2+offy,pct,3,RenderList.getrgb(32,255,32),0); } */ /* for(int i=pct;i0 && game.skirmish==false) { RenderList.drawrect(game,x - Game.CORNERX - cw/2+i,y - Game.CORNERY - ch/2+offy,3,3,RenderList.getrgb(255,255,32),0); } else { RenderList.drawrect(game,x - Game.CORNERX - cw/2+i,y - Game.CORNERY - ch/2+offy,3,3,RenderList.getrgb(32,255,32),0); } } */ } ///////////////////Method Definition/////////////// public void managecontrolpoint(Game game) { //manage a control point - a type of infinite spawner //that is controlled by whoever is closest if(Game.EDITOR) { return; } int framecheck = 60; if(Config.RUNNINGSPEED > 90) { framecheck = 80; } if(Config.RUNNINGSPEED > 110) { framecheck = 90; } framecheck/=Config.FASTFRAMECHECK;//14sep2021 int gx = x / Map.GRIDW; int gy = y / Map.GRIDH; int gdist = firerange / Map.GRIDW; int countfriends = 0; int countenemies = 0; bool emptyslot = false; int[] countfaction = new int[Game.MAXFACTIONS]; //26oct2020 int highest = 0; int highestfaction = 0; if((game.frame + id) % framecheck==11) { //every second update the control points...... for(int xx=gx-gdist;xx<=gx+gdist;xx++) { for(int yy=gy-gdist;yy<=gy+gdist;yy++) { if(xx>=0 && yy>=0 && xx=0 && game.units[nid].factionhighest) { highest = countfaction[game.units[nid].faction]; highestfaction = game.units[nid].faction; } } } } } } if(countfriends>countenemies) { controller = Game.PLAYERFACTION; } if(countfriends0) //26oct2020 { controller = highestfaction; } } if((game.frame + id)%(framecheck * Unit.CONTROLRATE)==29 && (controller==Game.PLAYERFACTION || controller==Game.SKIRMISHENEMYFACTION || highest>0)) { //spawn a new unit....chosen how? for(int gdist2=1;gdist2<=gdist;gdist2++) { for(int xx=gx-gdist2;xx<=gx+gdist2;xx++) { for(int yy=gy-gdist2;yy<=gy+gdist2;yy++) { if(xx>=0 && yy>=0 && xx0 && game.templates[j].bossmonster==0) { count++; } } if(count>0) { index = 1 + ((int)Functions.rand(0,10000) % count); for(int j=0;j0 && game.templates[j].bossmonster==0) { index--; if(index<=0) { for(int k=0;kUnit.MAXINDEX)//11apr2021 { Unit.MAXINDEX = k; } break; } } break; } } } } } ///////////////////Method Definition/////////////// public void fademagic(Game game)//28mar2021 { //if armour, damage, misfire, etc are in play.... //then gradually reduce them back to their standard levels.... int framecheck = 60; if(Config.RUNNINGSPEED>90) { framecheck = 80; } if(Config.RUNNINGSPEED>110) { framecheck = 90; } framecheck/=Config.FASTFRAMECHECK;//14sep2021 int plusorminus = 0; if(Config.USETECH) //2sep2021 { walkspeed-=Tech.AddUnitUpgradeBuff(game,templateid,Tech.MV); damage-=Tech.AddUnitUpgradeBuff(game,templateid,Tech.BA); armour-=Tech.AddUnitUpgradeBuff(game,templateid,Tech.BD); Tech.TARGETUID = id; Tech.ADDSUBTRACT = -1; Tech.AddUnitUpgradeBuff(game,templateid,Tech.BZ); } plusorminus-=Functions.sign(game.templates[templateid].walkspeed-walkspeed); plusorminus-=Functions.sign(game.templates[templateid].damage-damage); plusorminus-=Functions.sign(game.templates[templateid].armour-armour); plusorminus-=Functions.sign(game.templates[templateid].spelldefense-spelldefense);//01apr2021 plusorminus-=Functions.sign(game.templates[templateid].frenzy-frenzy);//01apr2021 plusorminus-=Functions.sign(game.templates[templateid].leader-leader);//09apr2021 plusorminus-=Functions.sign(game.templates[templateid].zombiemaster-zombiemaster);//09apr2021 if(misfire>0) { plusorminus--; } if(plusorminus>0) { buffed = true; cursed = false; } if(plusorminus<0) { cursed = true; buffed = false; } if(plusorminus==0) { cursed = false; buffed = false; } if(((game.frame + id)%(framecheck*20))==0) { //every 6 seconds...... bool anydiff = false; if(misfire>0) { //plusorminus--; misfire--; anydiff = true; cursed = true; } if(game.templates[templateid].frenzy!=frenzy)//01apr2021 { anydiff = true; frenzy+=Functions.sign(game.templates[templateid].frenzy-frenzy); } if(game.templates[templateid].spelldefense!=spelldefense)//01apr2021 { anydiff = true; spelldefense+=Functions.sign(game.templates[templateid].spelldefense-spelldefense); } if(game.templates[templateid].walkspeed!=walkspeed) { anydiff = true; walkspeed+=Functions.sign(game.templates[templateid].walkspeed-walkspeed); } if(game.templates[templateid].damage!=damage) { anydiff = true; damage+=Functions.sign(game.templates[templateid].damage-damage); } if(game.templates[templateid].armour!=armour) { anydiff = true; armour+=Functions.sign(game.templates[templateid].armour-armour); } //start--------------//9apr2021 if(game.templates[templateid].leader!=leader) { anydiff = true; leader+=Functions.sign(game.templates[templateid].leader-leader); } if(game.templates[templateid].zombiemaster!=zombiemaster) { anydiff = true; zombiemaster+=Functions.sign(game.templates[templateid].zombiemaster-zombiemaster); } //end----------------//9apr2021 if(!anydiff) { cursed = false; buffed = false; } } if(Config.USETECH) //2sep2021 { walkspeed+=Tech.AddUnitUpgradeBuff(game,templateid,Tech.MV); damage+=Tech.AddUnitUpgradeBuff(game,templateid,Tech.BA); armour+=Tech.AddUnitUpgradeBuff(game,templateid,Tech.BD); Tech.TARGETUID = id; Tech.ADDSUBTRACT = 1; Tech.AddUnitUpgradeBuff(game,templateid,Tech.BZ); } } ///////////////////Method Definition/////////////// public void update(Game game) { //core unit update method //correction for offx/offy if(game.templates[templateid].autocalcedoffsets==true && autocalcedoffsets==false)//20apr2021 { offx = game.templates[templateid].offx; offy = game.templates[templateid].offy; autocalcedoffsets = true; } if(game.frame - game.gamestartframe<10)//2apr2021 { return; } int framecheck = 60; if(hp>0) { timedead = 0;//25mar2021 height = Map.getheight(x,y); game.templates[templateid].livecount++;//9mar2021 if(faction==Game.PLAYERFACTION && selected!=SELECTIONNONE && walkspeed>0)//22mar2021 { game.templates[templateid].selectioncount++; } } else { timedead++; //25mar2021 if(faction==Game.PLAYERFACTION)//17sep2021 { if(points>0) //space squad uses this.... { if(redping<0) { redping=120; } } } } fademagic(game); if(firetargeti!=-1)//22mar2021 { //this fixes a bug where because units replace so fast, sometimes //a creature dies, then the pool reuses it but the other creatures //still have it as their firetargeti which causes them to //chase after their own guys.....occasionally. if(game.units[firetargeti].faction==faction) { firetargeti = -1; } } if(faction==Game.PLAYERFACTION)//24sep2021 { if(controlmode=="crpg")//24sep2021 { Unit.CRPG = 1;//25sep2021 Game.CORNERX = x - Game.RESOLUTIONX/2; Game.CORNERY = y - 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; } if(selected==Unit.SELECTIONNONE){selected = Unit.SELECTIONSTART;selectedframe = game.frame;} } } if(groupid>=0 && groupid<=9 && selected!=SELECTIONNONE)//21mar2021 { Game.groupselected = groupid; } if(Config.RUNNINGSPEED>90) { framecheck = 80; } if(Config.RUNNINGSPEED>110) { framecheck = 90; } framecheck/=Config.FASTFRAMECHECK;//14sep2021 if(controlpoint==1) { managecontrolpoint(game); return; } //start-------------//7mar2021 int enemyfaction = Game.PLAYERFACTION; if(faction==Game.PLAYERFACTION) { enemyfaction = Game.SKIRMISHENEMYFACTION; } if(mob>0) { int countfriend = Map.countfactionneighbours(game,x,y,faction); int countenemy = Map.countfactionneighbours(game,x,y,enemyfaction); if(countfriend>countenemy) { brave = 1; } else { brave = 0; } } if(basemana>0)//23sep2021 { if(mana0) { if(game.frame % framecheck == 0) { mana++; } } } } if(hatred>0) { if(hatred==enemyfaction) { brave = 1; } } if(planar>0 && Game.EDITOR==false && hp>0) { //if(animmode==ANIMMODE_IDLE) //{ if((game.frame+id) % 60==0)//11apr2021 added +id { //Functions.saveseed();//11apr2021 if(Functions.rand(0,100)0 && Game.whirlwind!=-1)//28mar2021 { int ggxx = x / Map.GRIDW; int ggyy = y / Map.GRIDH; if((ggxx + ggyy)%Blood.WHIRLWINDGRID==0) { Blood.makeblood(game,x,y,Blood.WHIRLWINDSPELL); } } if(animosity>0 && Game.EDITOR==false && hp>0) { if(animmode==ANIMMODE_IDLE) { if((game.frame + id) % 60==0)//11apr2021 added +id { if(id%animosity==0) { //not sure about this one yet.... //Functions.saveseed();//11apr2021 if(Functions.rand(0,100)<10) { animosity = 0; faction = Unit.ANIMOSITY; } //Functions.restoreseed();//11apr2021 } } } } //end---------------//7mar2021 //if(fearsome > 0 || leader > 0)//12jul2021 if(fearsome > 0 || leader > 0 || bounddemon > 0) //12jul2021 { retreat = false; retreatframe = game.frame + Unit.RETREATDEATH; timid = 0; } //start---------------//12jul2021 if(bounddemon > 1) { if((game.frame + id) % framecheck==0) //28jul21 - brought into line from being '60'. { bounddemon--; } if(bounddemon==1) { //alter the faction to a faction not in the game, but not neutral.... faction = (Game.PLAYERFACTION + Game.SKIRMISHENEMYFACTION); //should be good enough....to do the job... selected = Unit.SELECTIONNONE; //13jul2021 bug fix potentially. } } //end-----------------//12jul2021 if(brave > 0 && retreat==true) { if((game.frame + id) % 60 == 0)//11apr2021 { //Functions.saveseed();//11apr2021 if(Functions.rand(0,1000) 0 && retreat==true) { if((game.frame+id) % framecheck == 0) { int qqq1 = Functions.rand(0,1000); int qqq2 = Functions.rand(0,1000); int qqq3 = Functions.rand(0,1000); if(qqq10)//26feb2022 if(selected!=SELECTIONNONE && faction==Game.PLAYERFACTION && techguilinkid.Length>0)//26feb2022 { Tech.TECHUNITSELECTED = true; Tech.TECHUNITIDSELECTED = id; } //end-----------------//2sep2021 //start-------------//10mar2021 if(selected!=SELECTIONNONE && faction==Game.PLAYERFACTION && spawner!="") { Game.SPAWNERSELECTED = true; } if(selected!=SELECTIONNONE && spawner=="") //11mar2021 { Game.NONSPAWNERSELECTED = true; //11mar2021 } //start-------------//11mar2021 if(spawner!="" && faction!=Game.PLAYERFACTION) { if(((game.frame + id) % (framecheck*10))==2)//9sep2021 if(((game.frame + id) % (framecheck*10))==2 && framesleft<=0)//9sep2021 { //AI spawners randomly choose a new thing to spawn..... int randomspawncount = 0; int randomspawnindex = 0; int ttid = -1; int maxkill = 0; int maxkill2 = 0; int ktid = -1; Game.ai_direction++;//17apr2021 if((Game.ai_direction % 10)<5)//17apr2021 - altered AI to make it a bit more weird.......unpredictable but still following a logical course of action. { maxkill = 999999; maxkill2 = 0; for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { randomspawncount++; if(game.templates[tid].kills < maxkill) { maxkill = game.templates[tid].kills; ktid = tid; } } } //get the second highest value....not the first highest value... //Functions.saveseed();//11apr2021 if(Functions.rand(0,100)<25) { for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { if(game.templates[tid].kills > maxkill2)// && game.templates[tid].kills < maxkill) { maxkill2 = game.templates[tid].kills; ktid = tid; } } } } //Functions.restoreseed();//11apr2021 if(randomspawncount>0) { Functions.saveseed();//11apr2021 int qqq4 = Functions.rand(0,100);//11apr2021 if(ktid==-1 || (qqq4 < 10 && ktid!=-1)) { Functions.restoreseed();//11apr2021 randomspawnindex = 1 + (Functions.rand(0,1000) % randomspawncount); for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { randomspawnindex--; if(randomspawnindex<=0) { ttid = tid; break; } } } } else { ttid = ktid; Functions.restoreseed();//11apr2021 } if(ttid!=-1) { spawner = game.templates[ttid].name; spawnertemplateid = ttid; //26feb2022 displayspawner = game.templates[ttid].dname(); //13mar2021 spawnertime = Unit.CalculateSpawnerTime(game,ttid); framesleft = framecheck * spawnertime;//9sep2021 if(spawnercount<10) { //spawnercount++;//12mar2021 spawnercount+=3;//12mar2021 //to guarantee it keeps on producing and doesn't slow down with time..... } if(spawnercount<=0) { spawnercount=1; } } //Functions.restoreseed();//11apr2021 } } else { for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { randomspawncount++; if(game.templates[tid].kills > maxkill) { maxkill = game.templates[tid].kills; ktid = tid; } } } //get the second highest value....not the first highest value... //Functions.saveseed();//11apr2021 if(Functions.rand(0,100)<25) { for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { if(game.templates[tid].kills > maxkill2 && game.templates[tid].kills < maxkill) { maxkill2 = game.templates[tid].kills; ktid = tid; } } } } //Functions.restoreseed();//11apr2021 if(randomspawncount>0) { Functions.saveseed();//11apr2021 int qqq4 = Functions.rand(0,100);//11apr2021 if(ktid==-1 || (qqq4 < 10 && ktid!=-1)) { Functions.restoreseed();//11apr2021 randomspawnindex = 1 + (Functions.rand(0,1000) % randomspawncount); for(int tid=0;tid0 && game.templates[tid].bossmonster<=0 && game.templates[tid].leader<=0 && game.templates[tid].planar<=0) { randomspawnindex--; if(randomspawnindex<=0) { ttid = tid; break; } } } } else { ttid = ktid; Functions.restoreseed();//11apr2021 } if(ttid!=-1) { spawner = game.templates[ttid].name; spawnertemplateid = ttid;//26feb2022 displayspawner = game.templates[ttid].dname(); //13mar2021 spawnertime = Unit.CalculateSpawnerTime(game,ttid); framesleft = framecheck * spawnertime;//9sep2021 if(spawnercount<10) { //spawnercount++;//12mar2021 spawnercount+=3;//12mar2021 //to guarantee it keeps on producing and doesn't slow down with time..... } if(spawnercount<=0) { spawnercount=1; } } //Functions.restoreseed();//11apr2021 } } } } //end---------------//11mar2021 //end---------------//10mar2021 if(selected!=SELECTIONNONE && faction!=Game.PLAYERFACTION && (game.frame + id) % 15==3) { //correct this if necessary //for(int i=0;i retreatframe && ronscreen==false) { if(hp>0) { game.killed(game,id); } hp=0; } } else//25apr2021 { if(retreat==true && game.frame > retreatframe && onscreen==false) { if(hp>0) { game.killed(game,id); } hp=0; } } if(Replay.IsPlaying())//25apr2021 { if(retreat==true && game.frame <= retreatframe && ronscreen==false) { //rallying chance? if((game.frame + id) % framecheck == 0) { //Functions.saveseed();//11apr2021 Functions.saveseed();//25apr2021 if(Functions.rand(0,1000)0 && ronscreen==true) { retreatframe++; } } else { if(retreatframe>0 && onscreen==true) { retreatframe++; } } //start-------------//4may2021 if(hp<=0 && flightlevel!=-1) { int nid = Map.cellflyer(x,y,flightlevel); if(nid==id) { Map.removeflyer(id,x,y,flightlevel); } return; } //end---------------//4may2021 if(hp <= 0) { int nid = Map.cellunit(x,y); if(nid==id) { if(animmode!=ANIMMODE_DEAD)//13sep2021 (just the if block) { Map.removeunit(id,x,y); } } return; } //flying 4may2021 // if(flightlevel!=-1)//4may2021 { if(x > Game.CORNERX - Map.GRIDW*2 && x < Game.CORNERX + Game.RESOLUTIONX + Map.GRIDW*2 && y > Game.CORNERY - Map.GRIDH * 2 && y < Game.CORNERY + Game.RESOLUTIONY + Map.GRIDH * 2) { Array.Resize(ref Map.flightlist,Map.flightlist.Length + 1); Map.flightlist[Map.flightlist.Length - 1] = id; } } //end flying if(timid>0) { if((game.frame + id) % (2 * framecheck)==0) { //Functions.saveseed();//11apr2021 int dieroll = Functions.rand(0,100); int pcthp = hp * 100 / basehp; if(dieroll>pcthp) { retreat = true; retreatframe = game.frame + Unit.RETREATDEATH; } //Functions.restoreseed();//11apr2021 } } if(faction==Game.PLAYERFACTION) { infog = false; } else { if(Game.EDITOR) { infog = false; } } //start-------------//9mar2021 if(defendx!=-1 && defendy!=-1) { if(((game.frame+id) % 180)==11) { tx = defendx; ty = defendy; tmptx = tx;//12mar2021 tmpty = ty;//12mar2021 if(Functions.abs(x - tx)>Unit.GUARDRANGE && Functions.abs(y - ty)>Unit.GUARDRANGE)//12mar2021 { firetargeti = -1;//12mar2021 orderframe = Unit.ORDERTIME; //12mar2021 tmptattempts = 0; //12mar2021 } } } //end---------------//9mar2021 if(tmptframe>0) { tmptframe--; } else { tmptx = tx; tmpty = ty; if(game.gamestate==Game.CAT_GAMESTATE_GAME && ((game.frame + id)%30)==19){quickpathfind(x,y,tx,ty);}//28apr2021 } //26oct2020 //if(faction==Game.SKIRMISHENEMYFACTION && game.skirmish==true) if(faction!=Game.PLAYERFACTION && game.skirmish==true && faction!=Unit.NULLFACTION) { //Functions.saveseed();//11apr2021 int cpoint = ((int)Functions.rand(0,10000) % 1000); if(firetargeti==-1) { if(orderframe<=0) { if((game.frame + id)%framecheck==13) { //for(int i=0;i0) { orderframe--; } if(hp0 && ((game.frame+id) % framecheck)==0) { hp+=regeneration; if(hp>basehp) { hp = basehp; } } //if(Map.isonfire(x,y))//4may2021 if(Map.isonfire(x,y) && flightlevel==-1)//4may2021 { if((game.frame + id) % framecheck==0 && firespell==0) { //take damage.... if(hp>0)//25Feb2021 { hp--; if(hp<=0) { game.killed(game,id); } }//25Feb2021 } } drawn = false; if(game.demomode) { if((game.frame + id) % (framecheck*20)==0) { tx = x + 500 * (int)Functions.sign(1600 - x); ty = y; orderframe = Unit.ORDERTIME; firetargeti = -1; tmptattempts = 0; } } } ///////////////////Method Definition/////////////// public static void updateall(Game game) { //method that handles updating all units in game during gameplay Game.groupselected = -1;//21mar2021 Game.anyselected = false;//16apr2021 bool friendlyselected = false;//20apr2021 int enemyselected = -1;//20apr2021 Stopwatch utimer = new Stopwatch(); utimer.Start(); long atime = 0; long utime = 0; long atttime = 0; long wtime = 0; long ttime = 0; Game.SPAWNERSELECTED = false; //10mar2021 Game.NONSPAWNERSELECTED = false;//11mar2021 Tech.TECHUNITSELECTED = false;//2sep2021 Tech.TECHUNITIDSELECTED = -1;//2sep2021 //start-------------//9mar2021 Map.flightlist = new int[0];//4may2021 Unit.circlesmax = 0;//2jun2021 for(int i=0;i0) { game.templates[i].livecountframe--; } } game.templates[i].olivecount = game.templates[i].livecount; game.templates[i].livecount = 0; game.templates[i].selectioncount = 0;//22mar2021 } //end---------------//9mar2021 //start---------------//26mar2021 if(game.units[MAXINDEX].hp<=0 && game.units[MAXINDEX].timedead>MAXDEADTIME && MAXINDEX>0) { MAXINDEX--; } //end-----------------//26mar2021 Game.checksum = 0;//2apr2021 for(int i=0;i0 || game.units[i].timedeadMAXINDEX) { MAXINDEX = i; } if(game.units[i].selected!=Unit.SELECTIONNONE && game.units[i].hp>0 && game.units[i].walkspeed>0 && game.units[i].faction==Game.PLAYERFACTION)//16apr2021 { Game.anyselected = true; friendlyselected = true;//20apr2021 } if(game.units[i].selected!=Unit.SELECTIONNONE && game.units[i].faction!=Game.PLAYERFACTION) { enemyselected = i; } Game.checksum+=game.units[i].hp+game.units[i].x+game.units[i].y;//2apr2021 if(game.units[i].hp<=0) //24apr2021 { game.units[i].selected = Unit.SELECTIONNONE; } //end-----------------//26mar2021 Unit.CorrectTransport(game,i);//3may2021///in case stuff goes wrong..it shouldn't though...... if(game.units[i].transportedbyid!=-1)//3may2021 { game.units[i].onscreen = false; game.units[i].ronscreen = false; continue; //we don't want to update units that are inside transports...they should do nothing..... //until they are out of the transport..... } //start-------------//2jun2021 //if(game.templates[game.units[i].templateid].walkspeed>0 && game.units[i].selected!=Unit.SELECTIONNONE && game.units[i].hp>0)//3mar2022 if(game.units[i].selected!=Unit.SELECTIONNONE && game.units[i].hp>0)//3mar2022 { Unit.circles[Unit.circlesmax] = i; Unit.circlesmax++; if(Unit.circlesmax>=MAXUNITS) //should never be needed { Unit.circlesmax=MAXUNITS - 1; } } //end---------------//2jun2021 //start-------------//2sep2021 if(Config.USETECH) { game.units[i].walkspeed+=Tech.AddUnitUpgradeBuff(game,game.units[i].templateid,Tech.MV); game.units[i].damage+=Tech.AddUnitUpgradeBuff(game,game.units[i].templateid,Tech.BA); game.units[i].armour+=Tech.AddUnitUpgradeBuff(game,game.units[i].templateid,Tech.BD); Tech.TARGETUID = i; Tech.ADDSUBTRACT = 1; Tech.AddUnitUpgradeBuff(game,game.units[i].templateid,Tech.BZ); } //end---------------//2sep2021 ttime = utimer.ElapsedMilliseconds; game.units[i].animate(game);//includes flying as of 4may2021 atime+= Math.Abs(utimer.ElapsedMilliseconds - ttime); ttime = utimer.ElapsedMilliseconds; game.units[i].update(game); utime+= Math.Abs(utimer.ElapsedMilliseconds - ttime); if(!Game.EDITOR) { ttime = utimer.ElapsedMilliseconds; game.units[i].actionattack(game); atttime+= Math.Abs(utimer.ElapsedMilliseconds - ttime); } ttime = utimer.ElapsedMilliseconds; int tmpwalkspeed = game.units[i].walkspeed; //24feb2022 if(Config.useseasons>0 && Config.Season==Config.WINTER)//Winter//24feb2022 { if(game.units[i].canfly<=0 && game.units[i].canflyandwalk<=0) { if(game.units[i].walkspeed>2)//there's a maximum speed you can move at in the Winter... { game.units[i].walkspeed = 2; } } } game.units[i].walk(game,game.units[i].tmptx - game.units[i].x,game.units[i].tmpty - game.units[i].y); if(Config.USEDELTATIME>0)//18sep2021 { if(Config.delta > 150) { int ndelta = (Config.delta - (Config.delta % 100)) / 100; for(int nd=0;nd0) { game.units[i].isdead=2; game.units[i].hp=0; game.killed(game, i); if(game.units[i].infectinto!="" && game.units[i].infected>0)//22apr2022 { Unit.Infect(game,i,game.units[i].infectinto); } } } if(enemyselected!=-1 && friendlyselected==true)//20apr2021 { game.units[enemyselected].selected=Unit.SELECTIONNONE; } utimer.Reset(); if(atime > Config.maxanimate || game.frame % 300==0) { Config.maxanimate = atime; } if(utime > Config.maxupdate || game.frame % 300 == 0) { Config.maxupdate = utime; } if(atttime > Config.maxatt || game.frame % 300 == 0) { Config.maxatt = atttime; } if(wtime > Config.maxwalk || game.frame % 300 == 0) { Config.maxwalk = wtime; } } ///////////////////Method Definition/////////////// public static void drawall(Game game) { //draw all units on the screen currently //draw in sorted order......down the screen from low y to high y //4mar2022 - using overlayimage if it exists instead of these..... if(game.missions[game.missionid].overlayimage!=-1 && Config.options_overlay!=0)//4mar2022 { if(Config.Season==Config.WINTER && Config.useseasons>0 && game.missions[game.missionid].overlaysnow!=-1) { RenderList.drawimage(game,game.images[game.missions[game.missionid].overlaysnow].texture,-Game.CORNERX+Map.MAXX*Map.GRIDW/2,-Game.CORNERY+Map.MAXY*Map.GRIDH/2,0,(float)Map.MAXX*(float)Map.GRIDW/(float)game.images[game.missions[game.missionid].overlaysnow].cwx,(float)Map.MAXY*(float)Map.GRIDH/(float)game.images[game.missions[game.missionid].overlaysnow].chy,0,0,false,1,game.missions[game.missionid].overlaysnow); } else { RenderList.drawimage(game,game.images[game.missions[game.missionid].overlayimage].texture,-Game.CORNERX+Map.MAXX*Map.GRIDW/2,-Game.CORNERY+Map.MAXY*Map.GRIDH/2,0,(float)Map.MAXX*(float)Map.GRIDW/(float)game.images[game.missions[game.missionid].overlayimage].cwx,(float)Map.MAXY*(float)Map.GRIDH/(float)game.images[game.missions[game.missionid].overlayimage].chy,0,0,false,1,game.missions[game.missionid].overlayimage); } } else { if(Map.issnow) { RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(182,191,180),0); } if(Map.isdesert) { RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(109,96,37),0); } if(Map.isrgbbk) //1nov2020 { RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(Map.isrgbbk_r,Map.isrgbbk_g,Map.isrgbbk_b),0); } if(Map.isdesert==false && Map.issnow==false && Map.isrgbbk==false) { RenderList.drawrect(game,0,0,Game.RESOLUTIONX,Game.RESOLUTIONY,RenderList.getrgb(103,105,63),0); } for(int y=Game.CORNERY/Map.GRIDH - 2;y<(Game.CORNERY+Game.RESOLUTIONY)/Map.GRIDH + 2;y++) { for(int x=Game.CORNERX/Map.GRIDW - 2;x<(Game.CORNERX+Game.RESOLUTIONX)/Map.GRIDW + 2;x++) { if(Map.TileFog(game,x,y)==0)//15sep2021 { Map.draw(game,x*Map.GRIDW,y*Map.GRIDH,0); //the ground contents...if any..... } } } //start---------------//21feb2022 //if(game.missions[game.missionid].overlayimage!=-1)//28feb2022 //4mar2022 commented out //if(game.missions[game.missionid].overlayimage!=-1 && Config.options_overlay!=0)//28feb2022 //{ // RenderList.drawimage(game,game.images[game.missions[game.missionid].overlayimage].texture,-Game.CORNERX+Map.MAXX*Map.GRIDW/2,-Game.CORNERY+Map.MAXY*Map.GRIDH/2,0,1,1,0,0,false,1,game.missions[game.missionid].overlayimage); //} //end-----------------//21feb2022 //start---------------------------//18sep2021 for(int y=Game.CORNERY/Map.GRIDH - 2;y<(Game.CORNERY+Game.RESOLUTIONY)/Map.GRIDH + 2;y++) { for(int x=Game.CORNERX/Map.GRIDW - 2;x<(Game.CORNERX+Game.RESOLUTIONX)/Map.GRIDW + 2;x++) { if(Map.TileFog(game,x,y)==0)//15sep2021 { Map.draw(game,x*Map.GRIDW,y*Map.GRIDH,Map.DECOR); //the ground contents...if any..... } } } }//4mar2022 //end-----------------------------//18sep2021 //start------------//25apr2021 if(Replay.IsPlaying()) { Game.TMPCORNERX = Game.CORNERX; Game.TMPCORNERY = Game.CORNERY; Game.CORNERX = Game.RCORNERX; Game.CORNERY = Game.RCORNERY; for(int y=Game.CORNERY/Map.GRIDH - 2;y<(Game.CORNERY+Game.RESOLUTIONY)/Map.GRIDH + 4;y++) { for(int x=Game.CORNERX/Map.GRIDW - 2;x<(Game.CORNERX+Game.RESOLUTIONX)/Map.GRIDW + 2;x++) { int id = Map.cellunit(x*Map.GRIDW,y*Map.GRIDH); if(id!=-1) { //if the unit is drawn then onscreen would have been true.... //so we need to set ronscreen to true as well..... game.units[id].ronscreen = true; } } } Game.CORNERX = Game.TMPCORNERX; Game.CORNERY = Game.TMPCORNERY; } //end--------------//25apr2021 //start------------------------//2jun2021 for(int i=0;i Game.CORNERX + Game.RESOLUTIONX + Map.GRIDW * 2 || game.units[id].y < Game.CORNERY - Map.GRIDH * 2 || game.units[id].y > Game.CORNERY + Game.RESOLUTIONY + Map.GRIDH * 2) { continue; } if(game.units[id].walkspeed<=0) { continue; } if(Config.USEFEETCIRCLES) { { if(Game.iconcircles!=-1) { float cc = 0.8f; int cw0 = game.units[id].cw; int ch0 = game.units[id].ch; if(cw0<70) { cw0 = 70; } if(ch0<85) { ch0 = 85; } if(game.units[id].faction==Game.PLAYERFACTION) { //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,0,0,false,1f,Game.iconcircles); //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,0,1,false,0.25f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,game.units[id].x-Game.CORNERX,game.units[id].height + game.units[id].y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,0,0,false,1f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,game.units[id].x-Game.CORNERX,game.units[id].height + game.units[id].y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,0,1,false,0.25f,Game.iconcircles); } else { //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,1,0,false,1f,Game.iconcircles); //RenderList.drawimage(game,game.images[Game.iconcircles].texture,x-Game.CORNERX + offx,height + y-Game.CORNERY + offy,0,cc * cw / game.images[Game.iconcircles].cwx,cc * ch / game.images[Game.iconcircles].chy,1,1,false,0.25f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,game.units[id].x-Game.CORNERX,game.units[id].height + game.units[id].y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,1,0,false,1f,Game.iconcircles); RenderList.drawimage(game,game.images[Game.iconcircles].texture,game.units[id].x-Game.CORNERX,game.units[id].height + game.units[id].y-Game.CORNERY,0,cc * cw0 / game.images[Game.iconcircles].cwx,cc * ch0 / game.images[Game.iconcircles].chy,1,1,false,0.25f,Game.iconcircles); } } } } } } //end--------------------------//2jun2021 for(int y=Game.CORNERY/Map.GRIDH - 2;y<(Game.CORNERY+Game.RESOLUTIONY)/Map.GRIDH + 4;y++) { for(int x=Game.CORNERX/Map.GRIDW - 2;x<(Game.CORNERX+Game.RESOLUTIONX)/Map.GRIDW + 2;x++) { if(Map.TileFog(game,x,y)==0)//15sep2021 { Map.draw(game,x*Map.GRIDW,y*Map.GRIDH,1); //the ground contents...if any..... } else//15sep2021 { continue; } int id = Map.cellunit(x*Map.GRIDW,y*Map.GRIDH); if(id!=-1) { //start-----------------//20mar2021 //game.units[id].draw(game); //some overdraw but that is fine..... int savedirn = game.units[id].dirn; //29may2021 if(Config.SLOWROTATE)//29may2021 { game.units[id].dirn = game.units[id].displaydirn;//29may2021 } int lid = Map.cellunit((x-1)*Map.GRIDW,y*Map.GRIDH); int rid = Map.cellunit((x+1)*Map.GRIDW,y*Map.GRIDH); if(lid!=-1)// && rid==-1) { //left of us is occupied and right of us is not.... if(game.units[lid].y > game.units[id].y) { game.units[id].draw(game); game.units[lid].draw(game); } else { game.units[id].draw(game); } } else { game.units[id].draw(game); } game.units[id].dirn = savedirn; //29may2021 /* if(lid==-1 && rid!=-1) { //left of us is empty and right of us is not if(game.units[rid].y <= game.units[id].y) { //draw nothing.... } else { game.units[id].draw(game); } } if(lid!=-1 && rid!=-1) { //neither left nor right are empty.... if(game.units[lid].y > game.units[id].y) { game.units[id].draw(game); game.units[lid].draw(game); } else { //this will be slightly incorrect..... //if(game.units[rid].y <= game.units[id].y) //{ //} //else //{ game.units[id].draw(game); //some overdraw will occur..... //} } } */ //end-------------------//20mar2021 } } } if(Config.ALLOWFLYING)//4may2021 { for(int f=0;f0)//15sep2021 { if(!Map.TileVisible(game.units[nid].x,game.units[nid].y)) { continue; } } int savedirn = game.units[nid].dirn;//29may2021 if(Config.SLOWROTATE)//29may2021 { game.units[nid].dirn = game.units[nid].displaydirn;//29may2021 } game.units[nid].draw(game);// game.units[nid].dirn = savedirn; //29may2021 } } } //start------------------------//2jun2021 for(int i=0;i Game.CORNERX + Game.RESOLUTIONX + Map.GRIDW * 2 || game.units[id].y < Game.CORNERY - Map.GRIDH * 2 || game.units[id].y > Game.CORNERY + Game.RESOLUTIONY + Map.GRIDH * 2) { continue; } game.units[id].drawhealthbar(game); } Unit.circles[i] = -1; //reset afterwards..... } //end--------------------------//2jun2021 if(!Game.EDITOR) { Map.fogdraw(game); } } ///////////////////Method Definition/////////////// public void reset(Game game,int i) { //initialisation if(circles==null)//2jun2021 { circles = new int[MAXUNITS];//2jun2021 for(int j=0;j0) { //Console.WriteLine("zombieficator!!!"); //Console.WriteLine("infectinto:"+infectinto); //unit has died, and was infected..... //therefore transform them into a zombie.... //check that their position on the map is empty... if(Map.cellunit(game.units[i].x,game.units[i].y)==Map.VACANT) { //Console.WriteLine("cell is empty"); for(int tid=0;tid<=game.templates.Length;tid++) { if(game.templates[tid].name==infectinto) { game.units[i].createunitatxy(game,i,game.templates[tid],game.units[i].x,game.units[i].y); if(game.units[i].name=="zombie") { //Console.WriteLine("ZOMBIES!!!"); } break; } } } } game.units[i].infected = 1; game.units[i].infectinto = infectinto; } ///////////////////Method Definition/////////////// public bool createunitatxy(Game game,int id,Unit template,int x, int y) { //create a unit at this position from a specific template if(Map.cellunit(x,y)==Map.VACANT && Map.passable(x,y)==true) { reset(game,id); Unit.copyunitstats(template,ref game.units[id]); game.units[id].x = x; game.units[id].y = y; game.units[id].tx = x; game.units[id].ty = y; game.units[id].tmptx = x; game.units[id].tmpty = y; game.units[id].infected = 0; game.units[id].dieonce = -1;//13sep2021 game.units[id].animmode = Unit.ANIMMODE_IDLE; if(game.units[id].dieonplace>0)//22feb2022 { game.units[id].animframe = game.units[id].animmodeidleframestart; game.units[id].animtime = game.units[id].animspeed; } if(Map.insertunit(id,x,y)) { game.templates[template.id].creates++; } if(id>Unit.MAXINDEX)//11apr2021 { Unit.MAXINDEX = id; } //start---------------//2sep2021 if(Config.USETECH) { game.units[id].hp+=Tech.AddUnitUpgradeBuff(game,template.id,Tech.BH); game.units[id].basehp+=Tech.AddUnitUpgradeBuff(game,template.id,Tech.BH); } //end-----------------//2sep2021 //start---------------//14sep2021 if(game.units[id].canfly>0) { if(Map.cellflyer(game.units[id].x,game.units[id].y,Map.FLIGHTLEVELS - 1)==-1) { Map.removeunit(id,game.units[id].x,game.units[id].y); game.units[id].flightlevel = Map.insertflyer(id,game.units[id].x,game.units[id].y); game.units[id].animmode = ANIMMODE_FLY; game.units[id].retreat = false; game.units[id].retreatframe = 0; game.units[id].tmptattempts = 0; game.units[id].tmptframe = 0; if(game.units[id].flightlevel==-1) { game.units[id].hp = 0; //bugger - we don't really want this to happen though....so we will prevent it through other means.... } } } //end-----------------//14sep2021 return true; } return false; } ///////////////////Method Definition/////////////// public void walk(Game game,int dx,int dy) { //walk or move the unit about the map handling collisions if(hp <= 0) { return; } if(Functions.abs(tmptx-x)<=walkspeed+2) { tmptx = x; dx = 0; } if(Functions.abs(tmpty-y)<=walkspeed+2) { tmpty = y; dy = 0; } if(dx==0 && dy==0) { if(animmode==ANIMMODE_WALK) { animmode = ANIMMODE_IDLE; } //tmptattempts = 0; return; } int ddx = Functions.sign(dx); int ddy = Functions.sign(dy); odirn = dirn; if(dirntime>0) { dirntime--; } if(dirntime<=0) { dirntime = Unit.DIRNDELAY; if(ddx==0 && ddy==-1) { //up dirn = DIRN_UP; } if(ddx==1 && ddy==-1) { //upright dirn = DIRN_UPRIGHT; } if(ddx==1 && ddy==0) { //right dirn = DIRN_RIGHT; } if(ddx==1 && ddy==1) { //downright dirn = DIRN_DOWNRIGHT; } if(ddx==0 && ddy==1) { //down dirn = DIRN_DOWN; } if(ddx==-1 && ddy==1) { //downleft dirn = DIRN_DOWNLEFT; } if(ddx==-1 && ddy==0) { //left dirn = DIRN_LEFT; } if(ddx==-1 && ddy==-1) { //upleft dirn = DIRN_UPLEFT; } } if(animrest>0) { animrest--; } if(animrest>0 || animmode>ANIMMODE_WALK) { if(animmode!=ANIMMODE_FLY) //2sep2021 { return; } } if(faction==Unit.UNDEAD) //?huh?26oct2020 { if(game.frame % Unit.UNDEADWALKRATE!=0) { return; } } //check if there is another unit here...... //we really should do this with a maparray rather than cycling through everything..... int nx = x + ddx*walkspeed; int ny = y + ddy*walkspeed; //int nnx = x + ddx * (walkspeed + Map.GRIDW);//21apr2021 //int nny = y + ddy * (walkspeed + Map.GRIDH);//21apr2021 int nid = Map.cellunit(nx,ny); //start-----------------------//4may2021 //flying if(Config.ALLOWFLYING) { if(flightlevel!=-1) { animmode = ANIMMODE_FLY; if(Map.cellflyer(nx,ny,Map.FLIGHTLEVELS - 1)==-1) { bool movedgrid = false;//2sep2021 if(nx/Map.GRIDW!=x/Map.GRIDW || ny/Map.GRIDH!=y/Map.GRIDH)//2sep2021 { movedgrid = true; Map.removeflyer(id,x,y,flightlevel); } x+=ddx*walkspeed; y+=ddy*walkspeed; if(movedgrid)//2sep2021 { flightlevel = Map.insertflyer(id,x,y); } if(flightlevel==-1) { hp = 0; //bugger - we don't really want this to happen though....so we will prevent it through other means.... return; } } if(canflyandwalk>0) { //should we return to ground? if(Map.passable(nx,ny) && nid==Map.VACANT) { Map.removeflyer(id,x,y,flightlevel); flightlevel = -1; //good! we've returned to Earth... animmode = ANIMMODE_WALK; //will insert into map cell in a moment.... } } if(flightlevel!=-1)//3mar2022 { return ;//3mar2022 } } else { //we are not flying currently..... //but....should we try to? if(canflyandwalk>0) { if(!Map.passable(nx,ny)) { if(Map.cellflyer(nx,ny,Map.FLIGHTLEVELS - 1)==-1) { Map.removeunit(id,x,y); x+=ddx*walkspeed; y+=ddy*walkspeed; flightlevel = Map.insertflyer(id,x,y); animmode = ANIMMODE_FLY; retreat = false; //retreatframe = 0;//2sep2021 tmptattempts = 0; tmptframe = 0; if(flightlevel==-1) { hp = 0; //bugger - we don't really want this to happen though....so we will prevent it through other means.... } } if(flightlevel!=-1) { return; //we are off the ground.... } } } else { if(canfly>0) //in case we are a flying unit at the beginning of our game...and we for some reason have started on the ground...... { if(Map.cellflyer(nx,ny,Map.FLIGHTLEVELS - 1)==-1) { Map.removeunit(id,x,y); x+=ddx*walkspeed; y+=ddy*walkspeed; flightlevel = Map.insertflyer(id,x,y); animmode = ANIMMODE_FLY; retreat = false; retreatframe = 0; tmptattempts = 0; tmptframe = 0; if(flightlevel==-1) { hp = 0; //bugger - we don't really want this to happen though....so we will prevent it through other means.... } } if(flightlevel!=-1) { return; //we are off the ground.... } } } } } //end-------------------------//4may2021 if((nid==id || nid==Map.VACANT) && Map.passable(nx,ny) && Map.heightdiff2(height,x,y)0) { //Blood.makeblood(game,x,y,Blood.DUSTCLOUD); } } else { //try and walk around the obstacle...... //tx = x + Functions.rand(-100,100); //ty = y + Functions.rand(-100,100); //animmode = ANIMMODE_IDLE; //tmptframe = 120; //tmptx = x + Functions.rand(-100,100); //tmpty = y + Functions.rand(-100,100); //NEED TO OPTIMISE PATH FINDING. animmode = ANIMMODE_WALK; if((game.frame + id) % 10==0) { bool freesquare = checkfreeadjacent(game,id); //if we are surrounded - eg such as when all enemies are around us, then no point checking to path find..... if(freesquare) { Functions.saveseed();//11apr2021 pathfind(game,x,y,tx,ty,id); // only path find a short way to where we are going.... Functions.restoreseed();//11apr2021 //animmode = ANIMMODE_WALK; if(tmptattempts > MAXPATHFIND) { tx = x; ty = y; tmptx = x; tmpty = y; tmptattempts = 0; } if(tmptattempts>4 && Functions.abs(tx-x)<4 && Functions.abs(ty-y)<4) { tx = x; ty = y; tmptx = x; tmpty = y; tmptattempts = 0; } } } if(nid!=id && nid!=Map.VACANT) { //start---------//23sep2021 //currently only gold can be picked up... if(game.units[nid].canpickup>0) { if(faction==Game.PLAYERFACTION) { gold+=game.units[nid].gold; game.units[nid].gold = 0; game.units[nid].hp=0; Map.removeunit(nid, game.units[nid].x, game.units[nid].y); //play sound? return; } } //end-----------//23sep2021 if(game.units[nid].faction!=faction && game.units[nid].faction!=Unit.NULLFACTION) { //we've bumped into an enemy...... if(orderframe<=0) { firetargeti = nid; } //if we are a shock unit if(shock>0 || fearsome>0) { //Functions.saveseed();//11apr2021 shocktarget(game,nid); //Functions.restoreseed();//11apr2021 } } if(game.units[nid].faction==faction) { if(leader > 0) { game.units[nid].timid = 0; game.units[nid].retreat = false; game.units[nid].retreatframe = game.frame + Unit.RETREATDEATH; } } if(timid==1 && game.units[nid].timid==0 && game.units[nid].faction==faction) { //Functions.saveseed();//11apr2021 if(Functions.rand(0,1000)<200) { game.units[nid].timid = 1; } //Functions.restoreseed();//11apr2021 } if(game.units[nid].faction==faction && retreat==true) { if(game.units[nid].timid==0) { game.units[nid].timid=1; } if(game.units[nid].retreat==false) { //Functions.saveseed();//11apr2021 if(Functions.rand(0,1000)<200) { game.units[nid].retreat = true; game.units[nid].retreatframe = game.frame + Unit.RETREATDEATH; } //Functions.restoreseed();//11apr2021 //start---------------//27mar2021 //there should be a chance for us ourselves to rally if we collide with a friend who is not //panicking.... //commented out currently until ready to test happily as I need a break from this... //if(game.units[nid].retreat==false) //{ // //so if we didn't spread panic ourselves.... // //then there's a chance we might rally... // if(Functions.rand(0,1000)<200) // { // retreat = false; // retreatframe = 0; // } // //and if we're not fleeing now...there's a chance we might no longer be timid too.. // if(game.templates[templateid].timid<=0 && retreat==false) // { // timid = 0; // } //} //end-----------------//27mar2021 } } } } } ///////////////////Method Definition/////////////// public bool checkfreeadjacent(Game game, int id) { //check that the position moving to is empty int gx = game.units[id].x / Map.GRIDW; int gy = game.units[id].y / Map.GRIDH; if(gx>=0 && gy>=0 && gx MAXDEPTH) { return -1; } if(sx==fx && sy==fy) { //Console.WriteLine("sx:"+sx+" sy:"+sy+" fx:"+fx+" fy:"+fy+" depth:"+depth+" met target."); return depth; } if(!Map.ignoreunits) { int nid = Map.cellunit(sx * Map.GRIDW,sy * Map.GRIDH); if(nid!=Map.VACANT && nid!=id) { //Console.WriteLine("Cell Not VACANT:"+nid); return -1; } } //okay..... if(!Map.passable(sx * Map.GRIDW,sy * Map.GRIDH)) { //Console.WriteLine("Not Passable"); return -1; } int pi = sx + sy * Map.MAXX; if(pi<0 || pi>=Map.pathmap.Length) { //Console.WriteLine("OUTSIDE BOUNDS"); return -1; } if(depth==0) { Map.pathmap[pi] = Map.PATHINIT; } if(Map.pathmap[pi]==0) { //we haven't tested this square yet Map.pathmap[pi] = depth; } else { //we've already tested this square.... if(depth < Map.pathmap[pi] || depth==0 || Map.pathmap[pi]==0) { Map.pathmap[pi] = depth; } else { return -1; } } int leftdir = -1; int rightdir = -1; int updir = -1; int downdir = -1; int mindepth = Map.PATHINIT; int direction = -1; if(Map.heightdiff(sx * Map.GRIDW,sy * Map.GRIDH,(sx - 1) * Map.GRIDW,(sy) * Map.GRIDH) MAXDEPTH) { return -1; } if(sx==fx && sy==fy) { //Console.WriteLine("sx:"+sx+" sy:"+sy+" fx:"+fx+" fy:"+fy+" depth:"+depth+" met target."); return depth; } if(!Map.ignoreunits) { int nid = Map.cellunit(sx * Map.GRIDW,sy * Map.GRIDH); if(nid!=Map.VACANT && nid!=id) { //Console.WriteLine("Cell Not VACANT:"+nid); return -1; } } //okay..... if(!Map.passable(sx * Map.GRIDW,sy * Map.GRIDH)) { //Console.WriteLine("Not Passable"); return -1; } int pi = sx + sy * Map.MAXX; if(pi<0 || pi>=Map.pathmap.Length) { //Console.WriteLine("OUTSIDE BOUNDS"); return -1; } if(depth==0) { Map.pathmap[pi] = 0; } if(Map.pathmap[pi]==Map.PATHINIT) { //we haven't tested this square yet Map.pathmap[pi] = depth; } else { //we've already tested this square.... if(depth < Map.pathmap[pi] || depth==0) { Map.pathmap[pi] = depth; } else { return -1; } } int leftdir = -1; int rightdir = -1; int updir = -1; int downdir = -1; int mindepth = Map.PATHINIT; int direction = -1; leftdir = seekpath(sx - 1,sy,fx,fy,0,depth + 1,id); rightdir = seekpath(sx + 1,sy,fx,fy,0,depth + 1,id); updir = seekpath(sx,sy - 1,fx,fy,0,depth + 1,id); downdir = seekpath(sx,sy + 1,fx,fy,0,depth + 1,id); if(leftdir!=-1 && leftdir=Map.MAXX || sy>=Map.MAXY || fx>=Map.MAXX || fy>=Map.MAXY) { return false; } int godirn = Map.precalcedpaths[sx,sy,fx,fy]; if(godirn!=Map.NOTCHECKED && godirn!=-1) { switch(godirn) { case 0: tmptx = x; tmpty = y + Unit.PATHSTEP * Map.GRIDH; break; case 2: tmptx = x - Unit.PATHSTEP * Map.GRIDW; tmpty = y; break; case 6: tmptx = x + Unit.PATHSTEP * Map.GRIDW; tmpty = y; break; case 4: tmptx = x; tmpty = y - Unit.PATHSTEP * Map.GRIDH; break; } return true; } return false; } ///////////////////Method Definition/////////////// public void pathfind(Game game, int x, int y, int tx, int ty,int id) { //more path finding //uses a modified Djikstra algorithm. //NEED TO OPTIMISE int ttx = tx; int tty = ty; int oMAXDEPTH = Unit.MAXDEPTH; if(selected==Unit.SELECTIONFROZEN && game.frame < Game.ordergivenframe + Game.EXTRAPATHINGTIME && game.frame < timesincelastpath + Game.EXTRAPATHINGTIME) { // Unit.MAXDEPTH*=2;//attempt to improve efficiency when lots of units are selected....24apr2022(hence commented this out) } timesincelastpath = game.frame; if(Functions.abs(tx-x)>Unit.MAXDEPTH) { ttx = x + Functions.sign(tx - x) * (Unit.MAXDEPTH/2) * Map.GRIDW; } else { ttx = x + Functions.rand(-4,4) * Map.GRIDW; } if(Functions.abs(ty-y)>Unit.MAXDEPTH) { tty = y + Functions.sign(ty - y) * (Unit.MAXDEPTH/2) * Map.GRIDH; } else { tty = y + Functions.rand(-4,4) * Map.GRIDH; } if(Functions.abs(tx-x)+Functions.abs(ty-y)=0 && fx>=0 && sy>=0 && fy>=0 && sx=0 && fx>=0 && sy>=0 && fy>=0 && sx=0 && fx>=0 && sy>=0 && fy>=0 && sxanimmodeattframeend) { //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 //change back to idle.... animmode = ANIMMODE_IDLE; animframe = animmodeidleframestart; animrest = 30; // half a second.... } } if(animmode==ANIMMODE_ATTACK2) { if(animframe>animmodeatt2frameend) { //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 //change back to idle.... animmode = ANIMMODE_IDLE; animframe = animmodeidleframestart; animrest = 30; // half a second.... } } if(animmode==ANIMMODE_ATTACK3) { if(animframe>animmodeatt3frameend) { //change back to idle.... animmode = ANIMMODE_IDLE; animframe = animmodeidleframestart; animrest = 30; // half a second.... //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } } } } //start-----------//4may2021 if(animmode==ANIMMODE_FLYATTACK) { if(animmode!=oanimmode) { if(animmode==ANIMMODE_FLYATTACK) { animframe = animmodeflyattackframestart; } } else { if(animmode==ANIMMODE_FLYATTACK) { if(animframe>animmodeflyattackframeend) { //change back to idle.... animmode = ANIMMODE_FLY; animframe = animmodeflyframestart; animrest = 30; // half a second.... //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } } } } //end------------//4may2021 //start-------------//28Feb2021 if(animmode==ANIMMODE_IDLE2) { if(animframe>animmodeidle2frameend) { animframe = animmodeidleframestart; animmode = ANIMMODE_IDLE; //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } if(animframeanimmodeidleframeend) { animframe = animmodeidleframestart; //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } if(animframeanimmodeflyframeend) { animframe = animmodeflyframestart; //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } if(animframeanimmodewalkframeend) { animframe = animmodewalkframestart; //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } } //Functions.restoreseed();//11apr2021 //start-----------//25Feb2021 if(animmode==ANIMMODE_DEAD) { if(animmode!=oanimmode) { animframe = animmodedeadframestart; } if(animframe>animmodedeadframeend) { animframe = animmodedeadframeend; if(hp<=0 && dieonce<=(animmodedeadframeend - animmodedeadframestart))//13sep2021 added dieonce { if(dieonce==animmodedeadframeend - animmodedeadframestart){game.killed(game,id);}//13sep2021 around die once block. dieonce++;//13sep2021 } //start----------//21feb2022 if(dieonplace>0 && Game.EDITOR == false) { hp = 0; } //end------------//21feb2022 } } //end-------------//25Feb2021 if(animmode!=oanimmode) { oanimmode = animmode; } } ///////////////////Method Definition/////////////// public static void copyunitstats(Unit input,ref Unit output) { //copy a unit template from the base template //to the in game unit //typically used when creating new units //start-----------------//21mar2021 if(Unit.COPYUNIT) { output.x = input.x; output.y = input.y; output.tx = input.tx; output.ty = input.ty; output.tmptx = input.tmptx; output.tmpty = input.tmpty; output.dirn = input.dirn; output.odirn = input.odirn; output.dirntime = input.dirntime; output.retreat = input.retreat; output.retreatframe = input.retreatframe; output.infog = input.infog; output.buffed = input.buffed; output.cursed = input.cursed; output.defendx = input.defendx; output.defendy = input.defendy; output.formationx = input.formationx; output.formationy = input.formationy; output.height = input.height; output.orderframe = input.orderframe; output.tmptframe = input.tmptframe; output.tmptattempts = input.tmptattempts; output.angle = input.angle; output.oanimmode = input.oanimmode; output.animmode = input.animmode; output.animrest = input.animrest; output.animframe = input.animframe; output.animspeed = input.animspeed; output.drawn = input.drawn; output.selected = input.selected; output.selectedframe = input.selectedframe; output.onscreen = input.onscreen; output.ronscreen = input.ronscreen;//25apr2021 output.transportedbyid = input.transportedbyid; //4may2021 output.bounddemon = input.bounddemon; //12jul2021 } output.scale = input.scale;//25sep2021 //end---------------------//21apr2021 output.transportsize = input.transportsize;//3may2021 output.transportcapacity = input.transportcapacity;//3may2021 if(output.transportcapacity>0)//3may2021 { output.transportarray = new int[output.transportcapacity];//3may2021 for(int t=0;t0 && input.transportarray.Length>0) { for(int k=0;k0)//3may2021 { output.magicarray[m] = output.magicrelease; m++; } if(output.magictransform>0)//3may2021 { output.magicarray[m] = output.magictransform; m++; } //start--------------//9apr2021 if(output.magicleader>0)//01apr2021 { output.magicarray[m] = output.magicleader; m++; } if(output.magiczombiemaster>0)//01apr2021 { output.magicarray[m] = output.magiczombiemaster; m++; } //end----------------//9apr2021 if(output.magicdoom>0)//01apr2021 { output.magicarray[m] = output.magicdoom; m++; } if(output.magicdef>0)//01apr2021 { output.magicarray[m] = output.magicdef; m++; } if(output.magicfrenzy>0)//01apr2021 { output.magicarray[m] = output.magicfrenzy; m++; } if(output.magicweb>0) { output.magicarray[m] = output.magicweb; m++; } if(output.magicfear>0) { output.magicarray[m] = output.magicfear; m++; } if(output.magicgas>0) { output.magicarray[m] = output.magicgas; m++; } if(output.magichaste>0) { output.magicarray[m] = output.magichaste; m++; } if(output.magicplant>0) { output.magicarray[m] = output.magicplant; m++; } if(output.magicshield>0) { output.magicarray[m] = output.magicshield; m++; } if(output.magicstealth>0) { output.magicarray[m] = output.magicstealth; m++; } if(output.magicstorm>0) { output.magicarray[m] = output.magicstorm; m++; } if(output.magicsword>0) { output.magicarray[m] = output.magicsword; m++; } if(output.magicwind>0) { output.magicarray[m] = output.magicwind; m++; } //start-----//21apr2021 if(Unit.COPYUNIT) { for(int m2=0;m20 & Config.useseasons>0 && COPYUNIT==false) { if(output.firerange>100) { output.firerange = (output.firerange * 4) / 5; } if(output.firerange2>100) { output.firerange2 = (output.firerange2 * 4) / 5; } } //end-----------//24feb2022 } } /////////////////////////////////////////////////// ///////////////////Class Definition//////////////// class MapThread //29may2021 { public static bool running = false; public static bool quit = false; public static int MAXDEPTH = 500; public static int sx = 0; public static int sy = 0; public static int fx = 0; public static int fy = 0; public static int osx = 0; public static int osy = 0; public static int ofx = 0; public static int ofy = 0; public static int[] pathmap = new int[Map.MAXX*Map.MAXY]; public static int[] checks = new int[Map.MAXX*Map.MAXY]; public static int[] checkf = new int[Map.MAXX*Map.MAXY]; public static int i = 0; public static int s = 0; public static int f = 0; public static bool complete = false; ///////////////////Method Definition/////////////// public static void resetpathmap() { //not used //for(int i=0;i=0;j--) { if(Map.unitmap[j]!=Map.VACANT && checkf[j]==0) { fx = j % Map.MAXX; fy = (j - sx) / Map.MAXX; f++; f%=Unit.MAXUNITS; break; } } checks[sx + sy * Map.MAXX] = 1; checkf[fx + fy * Map.MAXX] = 1; if(s==0) { Array.Clear(checks,0,checks.Length); } if(f==0) { Array.Clear(checkf,0,checkf.Length); } } if(Map.precalcedpaths!=null) { //do our pathfinding calculation.... if(Map.precalcedpaths[sx,sy,fx,fy]==Map.NOTCHECKED) { Map.precalcedpaths[sx,sy,fx,fy] = seekpath2(sx,sy,fx,fy,0,0,0); } } if(sx>=Map.MAXX && sy>=Map.MAXY && fx>=Map.MAXX && fy>=Map.MAXY) { quit = true; complete = true; //also quit IF the game is exited...... } if(Game.EDITOR) { quit = true; } sx = osx; sy = osy; fx = ofx; fy = ofy; fx++; fx%=Map.MAXX; if(fx==0) { fy++; fy%=Map.MAXY; if(fy==0) { sx++; sx%=Map.MAXX; if(sx==0) { sy++; sy%=Map.MAXY; if(sy==0) { quit=true; } } } } } running = false; } ///////////////////Method Definition/////////////// public static int seekpath2(int sx,int sy,int fx,int fy,int dirn,int depth,int id) { //path finding //optimise if(depth==0) { MapThread.resetpathmap(); } if(depth > MAXDEPTH) { return -1; } if(sx==fx && sy==fy) { return depth; } if(!Map.passable(sx * Map.GRIDW,sy * Map.GRIDH)) { return -1; } int pi = sx + sy * Map.MAXX; if(pi<0 || pi>=MapThread.pathmap.Length) { return -1; } if(depth==0) { MapThread.pathmap[pi] = Map.PATHINIT; } if(MapThread.pathmap[pi]==0) { //we haven't tested this square yet MapThread.pathmap[pi] = depth; } else { //we've already tested this square.... if(depth < MapThread.pathmap[pi] || depth==0 || MapThread.pathmap[pi]==0) { MapThread.pathmap[pi] = depth; } else { return -1; } } int leftdir = -1; int rightdir = -1; int updir = -1; int downdir = -1; int mindepth = Map.PATHINIT; int direction = -1; if(Map.heightdiff(sx * Map.GRIDW,sy * Map.GRIDH,(sx - 1) * Map.GRIDW,(sy) * Map.GRIDH)=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; firecat = 0; fireframes = 0; tilecat = 0; treecat = 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 = System.IO.File.ReadAllLines(file); for(int i=0;i0) { txt+="trees="; for(int i=0;i0) { txt+="rocks="; for(int i=0;i0) { txt+="walls="; for(int i=0;i0) { txt+="decor="; for(int i=0;i0 && game.units[i].faction0) { txt+="unit="+game.units[i].name+","+game.units[i].x+","+game.units[i].y+Environment.NewLine; } } txt+="///////////////////////////////////////////////"+Environment.NewLine; txt+="End of Mission"+Environment.NewLine; txt+="///////////////////////////////////////////////"+Environment.NewLine; try { System.IO.File.WriteAllText(file,txt); Console.WriteLine("Map Saved To:"+file); } catch(Exception e) { Console.WriteLine(e.Message); } if(OPENMAP) { try { System.Diagnostics.Process.Start(@Environment.GetFolderPath(Environment.SpecialFolder.Windows)+"\\notepad.exe",file); } catch(Exception e) { Console.WriteLine(e.Message); } } OPENMAP = false; } ///////////////////Method Definition/////////////// public static void marktreepos(Game game) { //mark trees on the minimap int count = 0; for(int i=0;i=0 && nid0)//17sep2021 if(game.units[i].hp>0 && game.units[i].flightlevel==-1)//17sep2021//22feb2022 if(game.units[i].hp>0 && game.units[i].flightlevel==-1 && game.units[i].transportedbyid==-1)//17sep2021//22feb2022 { int gx = game.units[i].x / GRIDW; int gy = game.units[i].y / GRIDH; if(gx>=0 && gx=0 && gy0 && game.units[i].flightlevel!=-1) { 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; } bool 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,bool 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 bool 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; Array.Resize(ref Game.newtrees,Game.newtrees.Length + 1);//24apr2021 Game.newtrees[Game.newtrees.Length -1] = i + 1;//treeimage[i] + 1;//24apr2021 //1 based index not 0 based index } ///////////////////Method Definition/////////////// public static bool 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 && 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 && fogx-150 && fogy>-150 && fogx0)//28feb2022 { if(alpha==1) { //RenderList.drawimage(game,game.images[Resources.FOG].texture,fogx,fogy,0,1.1f,1.1f,0,0,false,alpha,Resources.FOG); //18sep2021 RenderList.drawimage(game,game.images[Resources.FOG].texture,fogx,fogy,0,Map.FOGSCALE*1.1f,Map.FOGSCALE*1.1f,0,0,false,alpha,Resources.FOG); } else { if(alpha>0) { //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 int tmptilecat = tilecat; int tmptreecat = treecat; int tmprockcat = rockcat; int tmpwallcat = wallcat; int tmpdecorcat = decorcat; //2mar2021 int tmptreeoffsety = treeoffsety; int tmprockoffsety = rockoffsety; int tmpwalloffsety = walloffsety; int tmpdecoroffsety = decoroffsety; //2mar2021 issnow = false; isdesert = false; isrgbbk = false; //1nov2020 //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.missionid=TriggerHelper.iflocation[0] && gy>=TriggerHelper.iflocation[1] && gx<=TriggerHelper.iflocation[2] && gy<=TriggerHelper.iflocation[3]) { RenderList.drawunfilledrect(game,gx * Map.GRIDW - Game.CORNERX,heightmap[i] + gy * Map.GRIDH - Game.CORNERY,Map.GRIDW,Map.GRIDH,RenderList.getrgb(32,255,255),0); } } if(TriggerHelper.atlocation[3]!=-1) { if(gx>=TriggerHelper.atlocation[0] && gy>=TriggerHelper.atlocation[1] && gx<=TriggerHelper.atlocation[2] && gy<=TriggerHelper.atlocation[3]) { RenderList.drawunfilledrect(game,gx * Map.GRIDW - Game.CORNERX,heightmap[i] + gy * Map.GRIDH - Game.CORNERY,Map.GRIDW,Map.GRIDH,RenderList.getrgb(32,255,32),0); } } if(TriggerHelper.constructorindex>=8) { if(TriggerHelper.field8index==9) { if(TriggerHelper.atlocation[0]!=-1 && TriggerHelper.atlocation[1]!=-1) { if(gx==TriggerHelper.atlocation[0] && gy==TriggerHelper.atlocation[1]) { RenderList.drawrect(game,gx * Map.GRIDW - Game.CORNERX,heightmap[i] + gy * Map.GRIDH - Game.CORNERY,Map.GRIDW,Map.GRIDH,RenderList.getrgb(32,255,32),0); } } } } } if(rockimage[i]!=-1) { //26oct2020 //RenderList.drawimage(game,game.images[rockcat].texture,x-Game.CORNERX,heightmap[i] + y-Game.CORNERY+Map.rockoffsety,0,1f,1f,rockimage[i],0,false,1f,rockcat); RenderList.drawimage(game,game.images[tmprockcat].texture,x-Game.CORNERX,heightmap[i] + y-Game.CORNERY+tmprockoffsety,0,1f,1f,rockimage[i],0,false,1f,tmprockcat); } //start-----------//15sep2021 if(Game.shadowleft!=-1 && Game.shadowright!=-1 && Map.indoor>0)//24sep2021 { if(wallimage[i]==-1) { if(i0) { if(wallimage[i - 1]!=-1) { RenderList.drawimage(game,game.images[Game.shadowleft].texture,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) { //RenderList.drawimage(game,game.images[firecat].texture,x-Game.CORNERX,y-Game.CORNERY,0,1.5f,1.5f,((game.frame + i) / 4) % fireframes,0,false,1f,firecat); if(Config.OPTIMISEFIRES>0 && wallimage[i]!=-1)//15sep2021 { //do nothing } else//15sep2021 { Map.drawfires(game,x-Game.CORNERX,heightmap[i] + y-Game.CORNERY,Map.GRIDW/2,Map.GRIDH/2); } if(!game.paused && !game.demomode) { firecell[i]--; bool spread = false; if((game.frame % 60)==0 && firecell[i]>0 && game.demomode==false && firecell[i]<=Map.FIRETIME) { 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(wallimage[i - 1]==-1) //{ // RenderList.drawimage(game,game.images[Game.shadowleft].texture,x-Game.CORNERX-Game.shadowoffx,heightmap[i] + y-Game.CORNERY+Game.shadowoffy,0,1f,1f,0,0,false,1f,Game.shadowleft); //} //} } } //end--------------------//15sep2021 } } ///////////////////Method Definition/////////////// public static void precalc(Game game) { if(Config.BLOCKPRECALC)//11apr2021 { return; } Map.precalcframestart++; //there are 100 cells by 100 cells.... //and we need to check for each one 100 cells by 100 cells..... //that will take a long time...... //it is in fact....10,000 x 10,000 //however we can reduce this considerably..... //what we can do is look only around regions that //are "near" our player units as a starting point... //that reduces to approximately 100-200 checks....versus how any positions? //well...we can only check positions that are near opposing units //so a lot of the map will go unchecked...which is fine... //do it for one unit at a time..... //against one other unit at a time..... //so in reality...it is perhaps 200 checks versus 200 checks... //now if we do 1 check per frame then that will surely take a long time.... //at worst it will take 40,000 frames which at 60pfs is about 700 seconds...or 10 minutes //but if we change it to do like this: //1 unit per frame versus the first unit in position more than MAXDEPTH away from us //which has not already had a checked position..... //then it might work..... int i = ((Map.precalcframestart - Map.precalcframestart % Unit.MAXUNITS) / Unit.MAXUNITS) % Unit.MAXUNITS; if(Map.precalcframestart % Unit.MAXUNITS!=0) { if(Config.sumu>1000) { return; } } Game.TMPCORNERX = Game.CORNERX;//2may2021 Game.TMPCORNERY = Game.CORNERY;//2may2021' if(Replay.IsPlaying())//2may2021 { Game.CORNERX = Game.RCORNERX;//2may2021 Game.CORNERY = Game.RCORNERY;//2may2021 } if(game.units[i].hp>0) { int sx = 0; int sy = 0; int fx = 0; int fy = 0; if(Config.sumu=0 && sy>=0 && fx>=0 && fy>=0 && sx0) { int dist = (int)(Functions.abs(game.units[i].x-game.units[j].x)+Functions.abs(game.units[i].y - game.units[j].y)); if(dist > Unit.MAXDEPTH*Map.GRIDW) { sx = game.units[i].x / Map.GRIDW; sy = game.units[i].y / Map.GRIDH; fx = game.units[j].x / Map.GRIDW; fy = game.units[j].y / Map.GRIDH; if(sx>=0 && sy>=0 && fx>=0 && fy>=0 && sx Config.maxmapupdatepostime) //{ // Config.maxmapupdatepostime = time; //} //utimer.Reset(); for(int i=0;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 bool dobonesexist(int x,int y) { //check if dead men's bones exist on the map to be raised as skeletons or other summoned creatures int gx = x / GRIDW; int gy = y / GRIDH; int i = -1; if(gx>=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 bool 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 bool 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() { //not used //for(int i=0;i