Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: C++ | Size: 28.87 KB | Hits: 77 | Expires: Never
Copy text to clipboard
  1. /*
  2. **      Aetheria.h contains all of the structs common
  3. **      to the game Aetheria and its related editors.
  4. **     
  5. **      Structures include all of the various forms of
  6. **      equipment, items and systems since the editors
  7. **      will need those too. Game state is not in here
  8. **      since that is handled by the client.
  9. */
  10. #include <stdio.h>
  11. #include <string>
  12. #include <stdlib.h>
  13. #include "..\..\include\hge.h"
  14. #pragma comment(lib,"user32.lib")
  15. #include "..\..\include\hgegui.h"
  16. #include "..\..\include\hgefont.h"
  17. #include "..\..\include\hgevector.h"
  18. #include "..\..\include\hgesprite.h"
  19. #include "..\..\include\hgeparticle.h"
  20. #include "..\..\include\hgeresource.h"
  21.  
  22. int screenMode = 1;
  23. #define MODE_FULLSCREEN         0
  24. #define MODE_WINDOWED           1
  25.  
  26. #define TERRAN                          1
  27. #define VICTORIAN                       2
  28. #define ANCIENT                         3
  29. #define WILD                            4
  30.  
  31. struct pointf;
  32. struct pointi;
  33. struct item;
  34. struct thing;
  35. struct npc;
  36. struct celestial;
  37. struct engine;
  38. struct pwrplant;
  39. struct shield;
  40. struct weapon;
  41. struct ship;
  42. struct hive;
  43. struct world;
  44.  
  45. struct pointf
  46. {
  47.         float           x,
  48.                                 y;
  49. };
  50. struct pointi
  51. {
  52.         int                     x,
  53.                                 y;
  54. };
  55. struct item
  56. {
  57.         static const int TYPE_SHIP      = 1,
  58.                                          TYPE_POWER     = 2,
  59.                                          TYPE_ENGINE= 3,
  60.                                          TYPE_SHIELD= 4,
  61.                                          TYPE_WEAPON= 5;
  62.         string          name;
  63.         int                     cost,
  64.                                 type;
  65.         float           mass,
  66.                                 size;
  67. };
  68. struct npc
  69. {
  70.         char            *name;
  71. };
  72. struct celestial
  73. {
  74.         string          name,
  75.                                 sprite,
  76.                                 portalto;
  77.         int                     orbits,
  78.                                 star,
  79.                                 portal;
  80.         pointf          loc;
  81.         hgeVector       orb;
  82.         float           distance,
  83.                                 speed,
  84.                                 drot,
  85.                                 scale,
  86.                                 mass,
  87.                                 angle;
  88.         npc*            npcs;
  89.         item*           catalog;
  90.         hgeSprite*      spt;
  91. };
  92. struct engine
  93. {
  94.         static const int TYPE_ENERGY= 1,
  95.                                          TYPE_FUEL      = 2,
  96.                                          TYPE_ZERO_P= 3;
  97.         string          name,
  98.                                 sprite,
  99.                                 parsys;
  100.         int                     type,
  101.                                 stealth;
  102.         float           thr;
  103.         float           tur;
  104.         hgeParticleSystem*      par;
  105. };
  106. struct pwrplant
  107. {
  108.         string          name;
  109.         int                     type,
  110.                                 stealth,
  111.                                 commod;
  112.         float           max,
  113.                                 charge,
  114.                                 chgtime,
  115.                                 commoduse;
  116. };
  117. struct shield
  118. {
  119.         static const int TYPE_DIRECT    = 1, // Hits drain power (coeff)
  120.                                          TYPE_RESTORE   = 2, // Power used on replenishing banks
  121.                                          TYPE_CONSTANT  = 3, // Power always used, drain
  122.                                          TYPE_COMMOD    = 4, // Hits drain resources (coeff)
  123.                                          TYPE_STATIC    = 6; // Shield banks don't restore
  124.         string          name,
  125.                                 sprite;
  126.         int                     type;
  127.         float           max,
  128.                                 charge, // Charge per second
  129.                                 chgtime,
  130.                                 opacity, // Not all shields absorb 100% damage
  131.                                 drain,
  132.                                 coeff;
  133.         hgeSprite*      spt;
  134. };
  135. struct weapon
  136. {
  137.         static const int TYPE_PROJECTILE        = 1,
  138.                                          TYPE_BEAM                      = 2,
  139.                                          TYPE_PARTICLES         = 3;
  140.         string          name,
  141.                                 sprite;
  142.         int                     type;
  143.         float           dmg,
  144.                                 pwr,
  145.                                 cooldown,
  146.                                 range,
  147.                                 mass,
  148.                                 spread;
  149.         hgeSprite*      spt;
  150. };
  151. struct ship
  152. {
  153.         static const int TYPE_TERRAN    = 1,
  154.                                          TYPE_VICTORIAN = 2,
  155.                                          TYPE_ANCIENT   = 3,
  156.                                          TYPE_WILD              = 4;
  157.         string          name,
  158.                                 sprite;
  159.         float           size,
  160.                                 armor,
  161.                                 capacity,
  162.                                 speed,
  163.                                 mass;
  164.         hgeVector       *engines;
  165.         hgeVector       *guns;
  166.         hgeVector       center;
  167.         int                     type,
  168.                                 neng,
  169.                                 ngun;
  170.         hgeSprite*      spt;
  171. };
  172. struct hive
  173. {
  174.         ship            *shp;
  175.         weapon          *gun;
  176.         shield          *shd;
  177.         pwrplant        *pwr;
  178.         engine          *eng;
  179.        
  180.         celestial       cel;
  181.  
  182.         int                     number;
  183.         float           range,
  184.                                 adrenaline,
  185.                                 cowardice,
  186.                                 aggressiveness;
  187.         bool            feral;
  188. };
  189. struct world
  190. {
  191.         string  name;
  192.         celestial*      celestials;
  193.         celestial**     portals;
  194.         celestial**     stars;
  195.         hive*           hives;
  196.         int                     ncel,
  197.                                 nhiv,
  198.                                 nport,
  199.                                 nstars;
  200.         pointf          pstart,
  201.                                 shift;
  202.         HTEXTURE        bg1;
  203.         HTEXTURE        bg2;
  204.         HTEXTURE        bg3;
  205. };
  206.  
  207. // Pointer to the HGE interface (helper classes require this to work)
  208.  
  209. HGE                     *hge=0;
  210. //hgeResourceManager* shipres;
  211. hgeResourceManager* wildres;
  212. hgeResourceManager* shieldres;
  213. hgeResourceManager* wepres;
  214. hgeResourceManager* partres;
  215. hgeResourceManager* planetres;
  216. hgeResourceManager* bgres;
  217.  
  218. engine*         engines;
  219. pwrplant*       pwrplants;
  220. shield*         shields;
  221. weapon*         weapons;
  222. ship*           ships;
  223.  
  224. #pragma warning(disable:4244) // Shuts the compiler up about those int to float conversions in hgeSprite(tex,f,f,f,f)
  225.  
  226.  
  227. bool LoadEngineParticle(int i);
  228. void cmdSavePreset(int n, hgeParticleSystemInfo info);
  229. void cmdLoadPreset(int n, hgeParticleSystemInfo info);
  230.  
  231. ship LoadShip( int i )
  232. {
  233.         if(ships[i].type)
  234.                 return ships[i];
  235.  
  236.         hge->System_SetState(HGE_INIFILE,"ships.ini");
  237.  
  238.         char num [3];                   // Creates a string buffer for the item index
  239.         _itoa_s(i,num,3,10);    // And writes the index to the buffer
  240.        
  241.         // These are intuitive, they copy the value from init file to data structure,
  242.         // issuing appropriate defaults if no value is found
  243.         ships[i].name           = hge->Ini_GetString(   num, "name",    "Missing");
  244.         ships[i].sprite         = hge->Ini_GetString(   num, "sprite",  num);
  245.         ships[i].type           = hge->Ini_GetInt(              num, "type",    1);
  246.         ships[i].size           = hge->Ini_GetFloat(    num, "size",    45.0);
  247.         ships[i].armor          = hge->Ini_GetFloat(    num, "armor",   100.0);
  248.         ships[i].capacity       = hge->Ini_GetFloat(    num, "capacity",100.0);
  249.         ships[i].speed          = hge->Ini_GetFloat(    num, "speed",   200.0);
  250.         ships[i].mass           = hge->Ini_GetFloat(    num, "mass",    75.0);
  251.         ships[i].neng           = hge->Ini_GetInt(              num, "engines", 1);
  252.         ships[i].ngun           = hge->Ini_GetInt(              num, "guns",    0);
  253.         ships[i].center.x       = hge->Ini_GetFloat(    num, "center x",0);
  254.         ships[i].center.y       = hge->Ini_GetFloat(    num, "center y",0);
  255.  
  256.         ships[i].engines = new hgeVector[ships[i].neng];
  257.         for(int n = 0; n<ships[i].neng; n++)
  258.         {
  259.                 char eng [20]; eng[0]=0;
  260.                 sprintf_s(eng,20,"engine %d x",n+1);
  261.                 ships[i].engines[n].x = hge->Ini_GetFloat(      num, eng,0);
  262.                 sprintf_s(eng,20,"engine %d y",n+1);
  263.                 ships[i].engines[n].y = hge->Ini_GetFloat(      num, eng,0);
  264.         }
  265.         ships[i].guns = new hgeVector[ships[i].ngun];
  266.         for(int n = 0; n<ships[i].neng; n++)
  267.         {
  268.                 char gun [20]={0};
  269.                 sprintf_s(gun,20,"weapon %d x",n+1);
  270.                 ships[i].guns[n].x = hge->Ini_GetFloat( num, gun,0);
  271.                 sprintf_s(gun,20,"weapon %d y",n+1);
  272.                 ships[i].guns[n].y = hge->Ini_GetFloat( num, gun,0);
  273.         }
  274.        
  275.         // Maps the item's sprite to a sprite cached by the respective resource manager
  276.         ships[i].spt = wildres->GetSprite(ships[i].sprite.c_str());
  277.         ships[i].spt->SetHotSpot(ships[i].spt->GetWidth()/2,ships[i].spt->GetHeight()/2);
  278.         return ships[i];
  279. }
  280. /*bool SaveShip( int i )
  281. {
  282.         hge->System_SetState(HGE_INIFILE,"ships.ini");
  283.  
  284.         char num [3];
  285.         _itoa_s(i,num,3,10);
  286.  
  287.         hge->Ini_SetString(     num,    "name",         ships[i].name);
  288.         hge->Ini_SetString(     num,    "sprite",       ships[i].sprite);
  289.         hge->Ini_SetFloat(      num,    "size",         ships[i].size);
  290.         hge->Ini_SetFloat(      num,    "armor",        ships[i].armor);
  291.         hge->Ini_SetFloat(      num,    "capacity",     ships[i].capacity);
  292.         hge->Ini_SetFloat(      num,    "speed",        ships[i].speed);
  293.         hge->Ini_SetFloat(      num,    "mass",         ships[i].mass);
  294.         hge->Ini_SetInt(        num,    "type",         ships[i].type);
  295.  
  296.         return true;
  297. }*/
  298.  
  299. weapon LoadWeapon( int i )
  300. {
  301.         if(weapons[i].type)
  302.                 return weapons[i];
  303.         hge->System_SetState(HGE_INIFILE,"weapons.ini");
  304.  
  305.         char num [3];
  306.         _itoa_s(i,num,3,10);
  307.  
  308.         weapons[i].name         = hge->Ini_GetString(   num, "name",    "Missing");
  309.         weapons[i].sprite       = hge->Ini_GetString(   num, "sprite""Error.png");
  310.         weapons[i].type         = hge->Ini_GetInt(              num, "type",    1);
  311.         weapons[i].dmg          = hge->Ini_GetFloat(    num, "damage",  15.0);
  312.         weapons[i].mass         = hge->Ini_GetFloat(    num, "mass",    0);
  313.         weapons[i].pwr          = hge->Ini_GetFloat(    num, "power",   15.0);
  314.         weapons[i].cooldown     = hge->Ini_GetFloat(    num, "cooldown",0.5);
  315.         weapons[i].range        = hge->Ini_GetFloat(    num, "range",   500.0);
  316.         weapons[i].spread       = hge->Ini_GetFloat(    num, "spread",  5.0);
  317.  
  318.         weapons[i].spt = wepres->GetSprite(weapons[i].sprite.c_str());
  319.         weapons[i].spt->SetHotSpot(weapons[i].spt->GetWidth()/2,weapons[i].spt->GetHeight()/2);
  320.  
  321.         return weapons[i];
  322. }/*
  323. bool SaveWeapon( int i )
  324. {
  325.         hge->System_SetState(HGE_INIFILE,"weapons.ini");
  326.  
  327.         char num [3];
  328.         _itoa_s(i,num,3,10);
  329.  
  330.         hge->Ini_SetString(     num,    "name",         weapons[i].name);
  331.         hge->Ini_SetString(     num,    "sprite",       weapons[i].sprite);
  332.         hge->Ini_SetFloat(      num,    "damage",       weapons[i].dmg);
  333.         hge->Ini_SetFloat(      num,    "dmgtime",      weapons[i].dmgtime);
  334.         hge->Ini_SetFloat(      num,    "power",        weapons[i].pwr);
  335.         hge->Ini_SetFloat(      num,    "cooldown",     weapons[i].cooldown);
  336.         hge->Ini_SetFloat(      num,    "range",        weapons[i].range);
  337.         hge->Ini_SetFloat(      num,    "spread",       weapons[i].spread);
  338.  
  339.         return true;
  340. }*/
  341.  
  342. shield LoadShield( int i )
  343. {
  344.         if(shields[i].type)
  345.                 return shields[i];
  346.         hge->System_SetState(HGE_INIFILE,"shields.ini");
  347.  
  348.         char num [3];
  349.         _itoa_s(i,num,3,10);
  350.  
  351.         shields[i].name         = hge->Ini_GetString(   num, "name",    "Missing");
  352.         shields[i].sprite       = hge->Ini_GetString(   num, "sprite""Bubble");
  353.         shields[i].type         = hge->Ini_GetInt(              num, "type",    1);
  354.         shields[i].max          = hge->Ini_GetFloat(    num, "max_shd", 200.0);
  355.         shields[i].charge       = hge->Ini_GetFloat(    num, "charge",  20.0);
  356.         shields[i].chgtime      = hge->Ini_GetFloat(    num, "chg_time",1000);
  357.  
  358.         shields[i].spt = shieldres->GetSprite(shields[i].sprite.c_str());
  359.         shields[i].spt->SetHotSpot(shields[i].spt->GetWidth()/2,shields[i].spt->GetHeight()/2);
  360.  
  361.         return shields[i];
  362. }/*
  363. bool SaveShield( int i )
  364. {
  365.         hge->System_SetState(HGE_INIFILE,"shields.ini");
  366.  
  367.         char num [3];
  368.         _itoa_s(i,num,3,10);
  369.  
  370.         hge->Ini_SetString(     num,    "name",         shields[i].name);
  371.         hge->Ini_SetString(     num,    "sprite",       shields[i].sprite);
  372.         hge->Ini_SetFloat(      num,    "max_shd",      shields[i].max);
  373.         hge->Ini_SetFloat(      num,    "charge",       shields[i].charge);
  374.         hge->Ini_SetFloat(      num,    "chg_time",     shields[i].chgtime);
  375.  
  376.         return true;
  377. }*/
  378.  
  379. pwrplant LoadPower( int i )
  380. {
  381.         if(pwrplants[i].type)
  382.                 return pwrplants[i];
  383.  
  384.         hge->System_SetState(HGE_INIFILE,"pwrplants.ini");
  385.  
  386.         char num [3];
  387.         _itoa_s(i,num,3,10);
  388.  
  389.         pwrplants[i].name               = hge->Ini_GetString(   num, "name",    "Missing");
  390.         pwrplants[i].type               = hge->Ini_GetInt(              num, "type",    1);
  391.         pwrplants[i].max                = hge->Ini_GetFloat(    num, "max_pwr", 100.0);
  392.         pwrplants[i].charge             = hge->Ini_GetFloat(    num, "charge",  10.0);
  393.         pwrplants[i].chgtime    = hge->Ini_GetFloat(    num, "chg_time",1000);
  394.  
  395.         return pwrplants[i];
  396. }/*
  397. bool SavePower( int i )
  398. {
  399.         hge->System_SetState(HGE_INIFILE,"pwrplants.ini");
  400.  
  401.         char num [3];
  402.         _itoa_s(i,num,3,10);
  403.  
  404.         hge->Ini_SetString(     num,    "name",         pwrplants[i].name);
  405.         hge->Ini_SetFloat(      num,    "max_shd",      pwrplants[i].max);
  406.         hge->Ini_SetFloat(      num,    "charge",       pwrplants[i].charge);
  407.         hge->Ini_SetFloat(      num,    "chg_time",     pwrplants[i].chgtime);
  408.  
  409.         return true;
  410. }*/
  411.  
  412. engine LoadEngine( int i )
  413. {
  414.         if(engines[i].type)
  415.                 return engines[i];
  416.  
  417.         hge->System_SetState(HGE_INIFILE,"engines.ini");
  418.  
  419.         char num[3];
  420.         //sprintf_s(num,4,"%d",i);
  421.         _itoa_s(i,num,3,10);
  422.  
  423.         engines[i].name         = hge->Ini_GetString(   num, "name",    "Missing");
  424.         engines[i].parsys       = hge->Ini_GetString(   num, "particle","Missing");
  425.         engines[i].sprite       = hge->Ini_GetString(   num, "sprite""Error");
  426.         engines[i].type         = hge->Ini_GetInt(              num, "type",    1);
  427.         engines[i].thr          = hge->Ini_GetFloat(    num, "thrust",  100);
  428.         engines[i].tur          = hge->Ini_GetFloat(    num, "turning", 100);
  429.  
  430.         //engines[i].spt = partres->GetSprite(engines[i].sprite.c_str());
  431.         //engines[i].spt->SetHotSpot(engines[i].spt->GetWidth()/2,engines[i].spt->GetHeight()/2);
  432.         LoadEngineParticle(i);
  433.  
  434.         return engines[i];
  435. }
  436. bool SaveEngine( int i );
  437.  
  438. world LoadWorld(char *name)
  439. {
  440.         //      MessageBox(NULL, "World Components Configured", "Debug", MB_OK | MB_ICONERROR | MB_APPLMODAL);
  441.         hge->System_SetState(HGE_INIFILE,name);
  442.  
  443.         world output;
  444.         output.bg1 = bgres->GetTexture(hge->Ini_GetString( "System", "Background 1", "clouds"));
  445.         output.bg2 = bgres->GetTexture(hge->Ini_GetString( "System", "Background 2", "smallstars"));
  446.         output.bg3 = bgres->GetTexture(hge->Ini_GetString( "System", "Background 3", "bigstars"));
  447.         output.name = hge->Ini_GetString(       "System", "Name", "Missing");
  448.         output.ncel = hge->Ini_GetInt(          "System", "Number of Bodies",   1);
  449.                 output.celestials = new celestial[output.ncel];
  450.         output.nhiv = hge->Ini_GetInt(          "System", "Number of Hives",    1);
  451.                 output.hives = new hive[output.nhiv];
  452.         output.nstars = hge->Ini_GetInt(        "System", "Number of Stars",    1);
  453.                 output.stars = new celestial*[output.nstars];
  454.         output.nport = hge->Ini_GetInt(         "System", "Number of Portals",  1);
  455.                 output.portals = new celestial*[output.nport];
  456.         output.pstart.x = hge->Ini_GetFloat("System", "Origin X", 0.0);
  457.         output.pstart.y = hge->Ini_GetFloat("System", "Origin y", 0.0);
  458.         output.shift.x = hge->Ini_GetFloat( "System", "Background Shift X", 0.0);
  459.         output.shift.y = hge->Ini_GetFloat( "System", "Background Shift y", 0.0);
  460.  
  461.         int stars=0; int portals=0;
  462.         char num [3];
  463.         for(int n = 1; n<=output.ncel; n++)
  464.         {
  465.                 _itoa_s(n,num,3,10);
  466.                 int i = n-1;
  467.                 output.celestials[i].name               = hge->Ini_GetString(   num, "Name",                    "Noname");
  468.                 output.celestials[i].sprite             = hge->Ini_GetString(   num, "Sprite",                  "Error.png");
  469.                 output.celestials[i].orb.x              = hge->Ini_GetFloat(    num, "Location X",              0.0);
  470.                 output.celestials[i].orb.y              = hge->Ini_GetFloat(    num, "Location Y",              0.0);
  471.                 output.celestials[i].speed              = hge->Ini_GetFloat(    num, "Orbital Speed",   0);
  472.                 output.celestials[i].scale              = hge->Ini_GetFloat(    num, "Scale",                   1.0);
  473.                 output.celestials[i].mass               = hge->Ini_GetFloat(    num, "Mass",                    output.celestials[i].scale);
  474.                 output.celestials[i].drot               = hge->Ini_GetFloat(    num, "Rotation Speed",  0);
  475.                 output.celestials[i].star               = hge->Ini_GetInt(              num, "Star",                    0);
  476.                 output.celestials[i].portal             = hge->Ini_GetInt(              num, "Portal",                  0);
  477.                 if(output.celestials[i].star){
  478.                         output.stars[stars]=&output.celestials[i]; ++stars; }
  479.                 if(output.celestials[i].portal){
  480.                         output.portals[portals]=&output.celestials[i]; ++portals;
  481.                         output.celestials[i].portalto= hge->Ini_GetString(      num, "Portal To",               "Sol.ini");}
  482.                 output.celestials[i].orbits             = hge->Ini_GetInt(              num, "Orbits",                  0);
  483.  
  484.                 output.celestials[i].spt = planetres->GetSprite(output.celestials[i].sprite.c_str());
  485.                 output.celestials[i].spt->SetHotSpot(output.celestials[i].spt->GetWidth()/2,output.celestials[i].spt->GetHeight()/2);
  486.         }
  487.         for(int n = output.ncel+1; n<=output.ncel+output.nhiv; n++)
  488.         {
  489.                 _itoa_s(n,num,3,10);
  490.                 int i = n-output.ncel-1;
  491.                 output.hives[i].cel.name                = hge->Ini_GetString(   num, "Name",                                    "Error");
  492.                 output.hives[i].cel.sprite              = hge->Ini_GetString(   num, "Sprite",                                  "byroid");
  493.                 output.hives[i].cel.orb.x               = hge->Ini_GetFloat(    num, "Location X",                              0.0);
  494.                 output.hives[i].cel.orb.y               = hge->Ini_GetFloat(    num, "Location Y",                              0.0);
  495.                 output.hives[i].cel.orbits              = hge->Ini_GetInt(              num, "Orbits",                                  0);
  496.                 output.hives[i].cel.speed               = hge->Ini_GetFloat(    num, "Orbital Speed",                   0);
  497.                 output.hives[i].cel.scale               = hge->Ini_GetFloat(    num, "Scale",                                   1.0);
  498.                 output.hives[i].cel.drot                = hge->Ini_GetFloat(    num, "Rotation Speed",                  0);
  499.  
  500.                 output.hives[i].adrenaline              = hge->Ini_GetFloat(    num, "Offensive Feedback",              1.05f);
  501.                 output.hives[i].cowardice               = hge->Ini_GetFloat(    num, "Defensive Feedback",              1.1f);
  502.                 output.hives[i].aggressiveness  = hge->Ini_GetFloat(    num, "Offensive Coefficient",   1.0);
  503.                 output.hives[i].shp = &ships[     hge->Ini_GetInt(              num, "Ship",                                    1)];
  504.                 output.hives[i].gun = &weapons[   hge->Ini_GetInt(              num, "Weapon",                                  1)];
  505.                 output.hives[i].eng = &engines[   hge->Ini_GetInt(              num, "Engine",                                  1)];
  506.                 output.hives[i].pwr = &pwrplants[ hge->Ini_GetInt(              num, "Power",                                   1)];
  507.                 output.hives[i].shd = &shields[   hge->Ini_GetInt(              num, "Shield",                                  1)];
  508.                 output.hives[i].number =                  hge->Ini_GetInt(              num, "Number",                                  3);
  509.  
  510.                 output.hives[i].cel.spt = wildres->GetSprite(output.hives[i].cel.sprite.c_str());
  511.                 output.hives[i].cel.spt->SetHotSpot(output.hives[i].cel.spt->GetWidth()/2,output.hives[i].cel.spt->GetHeight()/2);
  512.         }
  513.  
  514.         return output;
  515. }
  516.  
  517.  
  518. struct shipeng
  519. {
  520.         hgeVector                       loc;
  521.         hgeParticleSystem*      par;
  522. };
  523. struct thing
  524. {
  525.         hgeSprite*      spt;
  526.         float           x,y,
  527.                                 scale;
  528.         hgeVector       v,f;
  529. };
  530. struct entity
  531. {
  532.         char            *name;
  533.         thing           loc;
  534.         entity          *target;
  535.         ship            shp;
  536.         weapon          gun;
  537.         shield          shd;
  538.         pwrplant        pwr;
  539.         engine          eng;
  540.         shipeng         *engines;
  541.         float           drot;
  542.         bool            cw,ccw,
  543.                                 thrusting,
  544.                                 firing;
  545.         float           cooldown;
  546. };
  547. struct missile
  548. {
  549.         thing           loc;
  550.         entity          *parent,
  551.                                 *target;
  552.         float           damage,
  553.                                 mass,
  554.                                 range;
  555. };
  556. struct roamai
  557. {                                                               // Fight-or-flight engages when AI becomes aware of player
  558.         entity          ent;                    //
  559.         pointf          target,                 //                        (hostility*aggressiveness*anger)
  560.                                 range;                  // Attacks if -------------------------- > 1.0, flees if < 1.0
  561.         hive*           parent;                 //                        (fear*(playerLvl/AILevel))
  562.         vector<float> angers,           //
  563.                                 fears;                  // Anger and fear both rise as the AI is attacked
  564.         float           hostility,                      // at rates proportional to adrenaline and cowardice;
  565.                                 adrenaline,             // both go down constantly, and AI enemies may attack
  566.                                 cowardice,              // differently depending on anger level
  567.                                 aggressiveness; //
  568. };
  569.  
  570. struct config
  571. {
  572.         int                     resolutionx,
  573.                                 resolutiony;
  574.         bool            fullscreen,
  575.                                 whackyrotation;
  576. };
  577.  
  578. world                   sys;
  579. config                  options;
  580. vector<entity>  players;
  581. vector<missile> missiles;
  582. vector<roamai>  roamers;
  583.  
  584. void newRoamer(hive* daddy, pointf range, float agg, float host, float adr, float cow)
  585. {
  586.         roamai ai;
  587.         ai.parent                       = daddy;
  588.         ai.range                        = range;
  589.         ai.hostility            = host;
  590.         ai.aggressiveness       = agg;
  591.         ai.adrenaline           = adr;
  592.         ai.cowardice            = cow;
  593.         roamers.push_back(ai);
  594. }
  595. void newMissile(entity* parent, hgeSprite* spt, float x, float y, float mass, float damage, float range)
  596. {
  597.         missile mis = *(new missile);
  598.         mis.damage      = damage;
  599.         mis.mass        = mass;
  600.         mis.range       = range;
  601.         mis.parent      = parent;
  602.         mis.target      = parent->target;
  603.         mis.loc         = parent->loc;
  604.         mis.loc.x       = x;
  605.         mis.loc.y       = y;
  606.         mis.loc.spt     = spt;
  607.         mis.loc.scale*=.5;
  608.         missiles.push_back(mis);
  609. }
  610. void newEntity(int shp, int eng, int shd, int pwr, int wep, float x, float y, float scale)
  611. {
  612.         entity ent = *(new entity);
  613.         ent.shp                 = LoadShip(shp);
  614.         ent.eng                 = LoadEngine(eng);
  615.         ent.shd                 = LoadShield(shd);
  616.         ent.pwr                 = LoadPower(pwr);
  617.         ent.gun                 = LoadWeapon(wep);
  618.         ent.cooldown    = 0;
  619.         ent.thrusting   = false;
  620.         ent.firing              = false;
  621.         ent.cw                  = false;
  622.         ent.ccw                 = false;
  623.         ent.loc.v               = hgeVector(0,0);
  624.         ent.loc.f               = hgeVector(ent.eng.thr*40/ent.shp.mass,0);
  625.         ent.loc.scale   = scale;
  626.         ent.loc.x               = x;
  627.         ent.loc.y               = y;
  628.         ent.engines             = new shipeng[ent.shp.neng];
  629.         for(int i = 0; i<ent.shp.neng; i++){
  630.                 ent.engines[i].loc = ent.shp.engines[i];
  631.                 ent.engines[i].par = new hgeParticleSystem(*ent.eng.par);
  632.                 ent.engines[i].par->SetScale(scale*2/sqrt((float)ent.shp.neng));
  633.         }
  634.         players.push_back(ent);
  635. }
  636. bool LoadEngineParticle(int i)
  637. {
  638.         engines[i].par = new hgeParticleSystem( engines[i].parsys.c_str(),partres->GetSprite(engines[i].sprite.c_str()) );
  639.  
  640.         return true;
  641. }
  642.  
  643.  
  644. #include <cstring>
  645. #include <float.h>
  646. #include <iostream>
  647. #include <vector>
  648. #include <math.h>
  649.  
  650. using namespace std;
  651.  
  652. #include "Aetheria.h"
  653. #include "AetheriaIO.h"
  654. #include "Client.h"
  655.  
  656.  
  657. hgeSprite               *bgspr1,*bgspr2,*bgspr3;
  658. //HTEXTURE              ptex;
  659. //HTARGET               target;
  660. //hgeSprite*            tar;
  661. hgeSprite*              pshd;
  662. hgeFont                 *fnt;
  663.  
  664. char                    loading[20];
  665.  
  666. /*bool GfxRestoreFunc()
  667. {
  668.         if(tar && target) tar->SetTexture(hge->Target_GetTexture(target));
  669.         return false;
  670. }*/
  671.  
  672. bool FrameFunc()
  673. {
  674.         float dt=hge->Timer_GetDelta();
  675.         if(*loading)
  676.         {
  677.                 //delete sys;
  678.                 sys = LoadWorld(loading);
  679.                 delete bgspr1; bgspr1 = new hgeSprite(sys.bg1,0,0,800,600);
  680.                 delete bgspr2; bgspr2 = new hgeSprite(sys.bg2,0,0,800,600);
  681.                 delete bgspr3; bgspr3 = new hgeSprite(sys.bg3,0,0,800,600);
  682.                 bgspr1->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE);
  683.                 bgspr2->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE);
  684.                 bgspr3->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE);
  685.  
  686.                 players.clear();
  687.                 newEntity(8,1,1,1,1,sys.pstart.x,sys.pstart.y,0.5f);
  688.                 //delete loading;
  689.                 *loading = 0;
  690.         }
  691.  
  692.         if(hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
  693.         if(players.size() == 0) return false;
  694.  
  695.         /*      Process Key Input
  696.         */
  697.         if(hge->Input_GetKeyState(HGEK_SPACE))  players[0].firing = true;
  698.                                         else    players[0].firing = false;
  699.         if(hge->Input_GetKeyState(HGEK_UP))     players[0].thrusting = true;
  700.                                         else    players[0].thrusting = false;
  701.         if(hge->Input_GetKeyState(HGEK_LEFT))   players[0].ccw = true;
  702.                                         else    players[0].ccw = false;
  703.         if(hge->Input_GetKeyState(HGEK_RIGHT))  players[0].cw = true;
  704.                                         else    players[0].cw = false;
  705.         if(hge->Input_GetKeyState(HGEK_R)){
  706.                 for(int i=0; i<sys.nport; i++){
  707.                         float xdist = abs(players[0].loc.x)-abs(sys.portals[i]->loc.x);
  708.                         float ydist = abs(players[0].loc.y)-abs(sys.portals[i]->loc.y);
  709.                         float dist = sqrt(xdist*xdist+ydist*ydist)*2;
  710.                         if(dist<100) strcpy(loading,sys.portals[i]->portalto.c_str());
  711.                 }
  712.         }
  713.  
  714.         /*      Process all registered entities, including AI ships
  715.         */
  716.         vector<entity>::iterator ent;
  717.         for( ent=players.begin(); ent<players.end(); ent++)
  718.         {
  719.                 /*      Rotate the ship and associated vectors
  720.                 */
  721.                 float drot = ent->eng.tur/ent->shp.mass;
  722.                 if(ent->cw && !ent->ccw){
  723.                         ent->loc.f.Rotate(drot*dt*100);
  724.                         for(int i=0; i<ent->shp.neng; i++)
  725.                                 ent->engines[i].loc.Rotate(drot*dt*100);
  726.                         for(int i=0; i<ent->shp.ngun; i++)
  727.                                 ent->shp.guns[i].Rotate(drot*dt*100);
  728.                 }
  729.                 if(!ent->cw && ent->ccw){
  730.                         ent->loc.f.Rotate(-drot*dt*100);
  731.                         for(int i=0; i<ent->shp.neng; i++)
  732.                                 ent->engines[i].loc.Rotate(-drot*dt*100);
  733.                         for(int i=0; i<ent->shp.ngun; i++)
  734.                                 ent->shp.guns[i].Rotate(-drot*dt*100);
  735.                 }
  736.  
  737.                 /*      Compute engine impulse and process associated particle systems
  738.                 */
  739.                 for(int i=0; i<ent->shp.neng; i++)
  740.                 {
  741.                         if(ent->thrusting)
  742.                         {
  743.                                 ent->loc.v+=ent->loc.f*dt*100;
  744.                                 ent->engines[i].par->Fire();
  745.                                 ent->loc.v.Clamp(ent->shp.speed);
  746.                         }
  747.                         else ent->engines[i].par->Stop();
  748.                         ent->engines[i].par->Update(dt);
  749.                         ent->engines[i].par->Transpose(ent->loc.x - players[0].loc.x + options.resolutionx/2,
  750.                                                         ent->loc.y - players[0].loc.y + options.resolutiony/2);
  751.                         ent->engines[i].par->MoveTo(ent->engines[i].loc.x, ent->engines[i].loc.y,true);
  752.                         ent->engines[i].par->info.fDirection=ent->loc.f.Angle()+M_PI;
  753.                 }
  754.  
  755.                 /*      Universal gravitation is processed for every celestial in-system
  756.                 */
  757.                 int j = 0;
  758.                 for( ; j < sys.ncel; j++ )
  759.                 {
  760.                         float dist = hgeVector(ent->loc.x-sys.celestials[j].loc.x,ent->loc.y-sys.celestials[j].loc.y).Length();
  761.                         dist+=sys.celestials[j].scale*200; // This cuts off the horrendous asymptote in the G formula at the body's outer bound
  762.                         ent->loc.v+=hgeVector(  sys.celestials[j].loc.x - ent->loc.x,
  763.                                                 sys.celestials[j].loc.y - ent->loc.y)*(10*sys.celestials[j].mass/(dist*dist));
  764.                 }
  765.  
  766.                 /*      Process weapon systems; spawning missiles, particles or beams
  767.                 */
  768.                 ent->cooldown -= dt;
  769.                 if((ent->cooldown <= 0) && ent->firing)
  770.                 {
  771.                         ent->cooldown = ent->gun.cooldown;
  772.                         for(int i=0; i<ent->shp.ngun; i++)
  773.                         {
  774.                                 float xloc = ent->loc.x+ent->shp.guns[i].x*ent->loc.scale;
  775.                                 float yloc = ent->loc.y+ent->shp.guns[i].y*ent->loc.scale;
  776.                                 newMissile(&*ent,ent->gun.spt,xloc,yloc,ent->gun.mass,ent->gun.dmg,ent->gun.range);
  777.                         }
  778.                 }
  779.  
  780.                 /*      Finally, move the entity
  781.                 */
  782.                 ent->loc.x += ent->loc.v.x*dt;
  783.                 ent->loc.y += ent->loc.v.y*dt;
  784.         }
  785.        
  786.         vector<missile>::iterator kill; bool dead=0;
  787.         vector<missile>::iterator mis;
  788.         for( mis=missiles.begin(); mis<missiles.end(); mis++)
  789.         {
  790.                 mis->loc.x += mis->loc.v.x*dt;
  791.                 mis->loc.y += mis->loc.v.y*dt;
  792.                 mis->range -= mis->loc.v.Length()*dt;
  793.                 if(mis->range <= 0){ kill=mis; dead=1;}
  794.         }
  795.         if(dead) missiles.erase(kill);
  796.         /*      Process all celestials in registered world structure
  797.         */
  798.         for( int i = 0; i < sys.ncel; i++ )
  799.         {
  800.                 celestial* cel = &sys.celestials[i];
  801.                 cel->angle+=cel->drot*dt;
  802.                 cel->orb.Rotate(cel->speed*dt);
  803.                 if(cel->orbits){
  804.                         cel->loc.x=cel->orb.x+sys.celestials[cel->orbits-1].loc.x;
  805.                         cel->loc.y=cel->orb.y+sys.celestials[cel->orbits-1].loc.y;
  806.                 }else{
  807.                         cel->loc.x=cel->orb.x;
  808.                         cel->loc.y=cel->orb.y;
  809.                 }
  810.         }
  811.         /*      Do the same for all hives, spawning new AI if necessary.
  812.         */
  813.         for( int i = 0; i < sys.nhiv; i++ )
  814.         {
  815.                 hive* hiv = &sys.hives[i];
  816.                 hiv->cel.orb.Rotate(hiv->cel.speed*dt);
  817.                 hiv->cel.loc.x=hiv->cel.orb.x+sys.celestials[hiv->cel.orbits-1].loc.x;
  818.                 hiv->cel.loc.y=hiv->cel.orb.y+sys.celestials[hiv->cel.orbits-1].loc.y;
  819. //MessageBox(NULL, "Updating Hive", hiv->cel.name, MB_OK | MB_ICONERROR | MB_APPLMODAL);
  820.         }
  821.         return false;
  822. }
  823. bool RenderFunc()
  824. {
  825.         // Render the scene
  826.  
  827.         hge->Gfx_BeginScene();
  828.         bgspr1->SetTextureRect( players[0].loc.x*.1f + sys.shift.x - options.resolutionx/2,
  829.                                                         players[0].loc.y*.1f + sys.shift.y - options.resolutiony/2,options.resolutionx,options.resolutiony);
  830.         bgspr1->Render(0,0);
  831.         bgspr2->SetTextureRect(players[0].loc.x*.3f,players[0].loc.y*.5f,options.resolutionx,options.resolutiony);
  832.         bgspr2->Render(0,0);
  833.         bgspr3->SetTextureRect(players[0].loc.x*.6f,players[0].loc.y*.8f,options.resolutionx,options.resolutiony);
  834.         bgspr3->Render(0,0);
  835.  
  836.         for( int i = 0; i < sys.ncel; i++ )
  837.         {
  838.                 celestial cel=sys.celestials[i];
  839.                 cel.spt->RenderEx(cel.loc.x-players[0].loc.x+options.resolutionx/2,
  840.                                                   cel.loc.y-players[0].loc.y+options.resolutiony/2,
  841.                                                   cel.angle,cel.scale);
  842.  
  843.                 hgeVector(sys.celestials[1].loc.x-cel.loc.x,sys.celestials[1].loc.y-cel.loc.y).Angle();
  844.                 if(!cel.star)
  845.                 pshd->RenderEx(cel.loc.x-players[0].loc.x+options.resolutionx/2,
  846.                                                   cel.loc.y-players[0].loc.y+options.resolutiony/2,
  847.                                                   hgeVector(-(sys.celestials[1].loc.x-cel.loc.x),-(sys.celestials[1].loc.y-cel.loc.y)).Angle(),cel.scale);
  848.         }
  849.         for( int i = 0; i < sys.nhiv; i++ )
  850.         {
  851.                 hive hiv=sys.hives[i];
  852.                 hiv.cel.spt->RenderEx(hiv.cel.loc.x-players[0].loc.x+options.resolutionx/2,
  853.                                                   hiv.cel.loc.y-players[0].loc.y+options.resolutiony/2,
  854.                                                   hiv.cel.angle,hiv.cel.scale);
  855.         }
  856.         vector<entity>::iterator ent;
  857.         for( ent=players.begin(); ent<players.end(); ent++)
  858.         {
  859.                 for(int i = 0; i < ent->shp.neng; i++){
  860.                         //ent->par->Transpose(ent->engines[i].x+ent->loc.x-players[0].loc.x+options.resolutionx/2,
  861.                         //                                      ent->engines[i].y+ent->loc.y-players[0].loc.y+options.resolutiony/2);
  862.                         ent->engines[i].par->Render();
  863.                 }
  864.                 ent->shp.spt->RenderEx(ent->loc.x-players[0].loc.x+options.resolutionx/2,
  865.                                                                 ent->loc.y-players[0].loc.y+options.resolutiony/2,
  866.                                                                 ent->loc.f.Angle(), ent->loc.scale);
  867.         }      
  868.         vector<missile>::iterator mis;
  869.         for( mis=missiles.begin(); mis<missiles.end(); mis++)
  870.         {
  871.                 mis->loc.spt->RenderEx(mis->loc.x-players[0].loc.x+options.resolutionx/2,
  872.                                                                 mis->loc.y-players[0].loc.y+options.resolutiony/2,
  873.                                                                 mis->loc.v.Angle(), mis->loc.scale);
  874.         }
  875.  
  876.        
  877.  
  878.         float dist = hgeVector(players[0].loc.x-sys.celestials[0].loc.x,players[0].loc.y-sys.celestials[0].loc.y).Length();
  879.  
  880.         fnt->printf(7,100,HGETEXT_LEFT, "Portal Location = %.1f,%.1f\nDistance From Portal = %.1f",sys.celestials[0].loc.x,sys.celestials[0].loc.y,dist);
  881.         fnt->printf(7, 7, HGETEXT_LEFT, "Current Position: %.1f,%.1f\nCurrent Direction: %.1f\nCurrent Speed: %.1f\nFPS: %d", players[0].loc.x, players[0].loc.y, players[0].loc.f.Angle()*180/M_PI, players[0].loc.v.Length(), hge->Timer_GetFPS());
  882.         hge->Gfx_EndScene();
  883.         return false;
  884. }
  885.  
  886. int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  887. {
  888.         //_control87(_MCW_RC, _RC_CHOP);
  889.         hge = hgeCreate(HGE_VERSION);
  890.  
  891.         // Set desired system states and initialize HGE
  892.         hge->Resource_AttachPack("Aetheria.pak");
  893.  
  894.         hge->System_SetState(HGE_INIFILE, "options.ini");
  895.         options.resolutionx = hge->Ini_GetInt("System","Resolution X",640);
  896.         options.resolutiony = hge->Ini_GetInt("System","Resolution Y",480);
  897.         options.fullscreen = hge->Ini_GetInt("System","Fullscreen",0);
  898.  
  899.         hge->System_SetState(HGE_LOGFILE, "Aetheria.log");
  900.         hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
  901.         hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
  902.         hge->System_SetState(HGE_FPS, HGEFPS_UNLIMITED );
  903.         hge->System_SetState(HGE_TITLE, "Aetheria");
  904.         hge->System_SetState(HGE_USESOUND, false);
  905.         hge->System_SetState(HGE_WINDOWED, !((bool)options.fullscreen));
  906.         hge->System_SetState(HGE_SCREENWIDTH, options.resolutionx);
  907.         hge->System_SetState(HGE_SCREENHEIGHT, options.resolutiony);
  908.         hge->System_SetState(HGE_SCREENBPP, 32);
  909.         //hge->System_SetState(HGE_SHOWSPLASH,false);
  910.  
  911.         if(hge->System_Initiate())
  912.         {
  913.                 //shipres =     new hgeResourceManager("ships.res");
  914.                 wildres =       new hgeResourceManager("wildships.res");
  915.                 shieldres =     new hgeResourceManager("shields.res");
  916.                 wepres =        new hgeResourceManager("weapons.res");
  917.                 partres =       new hgeResourceManager("particles.res");
  918.                 planetres =     new hgeResourceManager("planets.res");
  919.                 planetres->Precache();
  920.                 bgres =         new hgeResourceManager("backgrounds.res");
  921.  
  922.                 pshd = planetres->GetSprite("shader.png");
  923.                 pshd->SetHotSpot(200,200);
  924.                 ships = new ship[64];
  925.                 weapons = new weapon[64];
  926.                 shields = new shield[64];
  927.                 pwrplants = new pwrplant[64];
  928.                 engines = new engine[64];
  929.                 for(int i = 0;i<64;i++)
  930.                 {
  931.                         ships[i].type=0;
  932.                         weapons[i].type=0;
  933.                         shields[i].type=0;
  934.                         pwrplants[i].type=0;
  935.                         engines[i].type=0;
  936.                 }
  937.  
  938.                 strcpy(loading,"Sol.ini");
  939.  
  940.                 fnt=new hgeFont("font2.fnt");
  941.                 //ptex=hge->Texture_Load("particles.png");
  942.                 //missiles.resize(12);
  943.  
  944.                
  945.  
  946.                 hge->System_Start();
  947.  
  948.                 // Delete created objects and free loaded resources
  949.  
  950.                 wildres->Purge();
  951.                 shieldres->Purge();
  952.                 wepres->Purge();
  953.                 partres->Purge();
  954.                 planetres->Purge();
  955.                 bgres->Purge();
  956.                 delete [] engines;
  957.                 delete [] pwrplants;
  958.                 delete [] shields;
  959.                 delete [] weapons;
  960.                 delete [] ships;
  961.         }
  962.  
  963.         // Clean up and shutdown
  964.  
  965.         hge->System_Shutdown();
  966.         hge->Release();
  967.         return 0;
  968. }