00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include "WinMainSelector.h"
00024
00025 #ifdef COMPILE_DEMOMULTIPLAYBATTLE
00026
00027 #include "..\AEngine\AEngine.h"
00028 #include "globals.h"
00029
00030 #include "BattleEntry.h"
00031 #include "BattleUnitData.h"
00032
00033 using namespace Globals;
00034
00035 BattleEntry *pBattle;
00036 FLOAT screenSize;
00037 bool notInGame;
00038 int lastHeardTick;
00039
00040 string& stripComments(string& str)
00041 {
00042 size_t start;
00043 size_t end;
00044 while( (start = str.find("//")) != string::npos )
00045 {
00046 end = str.find("\n", start)+1;
00047 str.erase(start, end-start);
00048 }
00049 return str;
00050 }
00051
00052 void initData()
00053 {
00054 ifstream fileIn("data.txt");
00055 ostringstream fileDump;
00056
00057 fileDump << fileIn.rdbuf();
00058 string file = stripComments(fileDump.str());
00059
00060 size_t start = file.find(BattleUnitData::TOK_BEGIN_DATA)+BattleUnitData::TOK_BEGIN_DATA.size();
00061 size_t len = file.find(BattleUnitData::TOK_END_DATA) - start;
00062 BattleUnitData::getObj().initData(istringstream(file.substr(start, len)));
00063 }
00064
00065
00066 void init()
00067 {
00068 initData();
00069 sys_showConsole(false);
00070 Globals::artWork = new ArtWork();
00071 pBattle = NULL;
00072 screenSize = 1.0f;
00073 sys_setSkipRate(0);
00074 notInGame = true;
00075
00076 }
00077
00078 void update()
00079 {
00080
00081 if( notInGame && input_isKeyPressed(KeyCodes::key_H)) { net_runAsServer("155.101.73.116","UsitS",8); notInGame=false; }
00082 if( notInGame && input_isKeyPressed(KeyCodes::key_J)) { net_connectToServer("155.101.73.116","UsitC"); notInGame=false; }
00083 if( notInGame && input_isKeyPressed(KeyCodes::key_F)) { net_runAsFakeServer("UsitF",8); notInGame=false; }
00084
00085 if( net_amIServer() && input_isKeyPressed(KeyCodes::key_SPACE) && pBattle==NULL )
00086 {
00087 net_send("BeginBattle");
00088 }
00089
00090
00091 string msg;
00092 while( (msg=net_recv()) != "" )
00093 {
00094 sys_console() << "[" << msg << "]" << endl;
00095
00096 if( msg=="BeginBattle" )
00097 {
00098 sys_console() << "Starting Battle" << endl;
00099 pBattle = new BattleEntry( Colors::blue, Colors::black, Vec2D(0.0f,0.0f) );
00100
00101 pBattle->teamAGroups.push_back( Int2Tuple( UnitTypes::LIGHT_TANK, 30 ) );
00102 pBattle->teamAGroups.push_back( Int2Tuple( UnitTypes::HEAVY_TANK, 16 ) );
00103 pBattle->teamAGroups.push_back( Int2Tuple( UnitTypes::LAUNCHER, 24 ) );
00104 pBattle->teamAGroups.push_back( Int2Tuple( UnitTypes::ARTILLERY, 18 ) );
00105
00106 pBattle->teamBGroups.push_back( Int2Tuple( UnitTypes::LIGHT_TANK, 30 ) );
00107 pBattle->teamBGroups.push_back( Int2Tuple( UnitTypes::LIGHT_TANK, 30 ) );
00108 pBattle->teamBGroups.push_back( Int2Tuple( UnitTypes::LAUNCHER, 24 ) );
00109
00110 screenSize = 0.01f;
00111
00112
00113 gameTick = 0;
00114 sys_setRandSeed(0);
00115 lastHeardTick = 0;
00116 }
00117 else
00118 if(pBattle) pBattle->enQueueInput(msg);
00119 }
00120
00121 if(pBattle)
00122 {
00123 pBattle->input();
00124 pBattle->update();
00125 if(pBattle->isBattleFinished())
00126 {
00127 pBattle = NULL;
00128 sys_console() << "Battle Terminates at GameTick = " << gameTick << endl;
00129 }
00130 }
00131
00132 if(screenSize<1.0f) screenSize = (screenSize + 0.004f) * 1.025f;
00133 if(screenSize>1.0f) screenSize = 1.0f;
00134 camera_setScreenSize(screenSize);
00135 }
00136
00137 void render()
00138 {
00139 if(pBattle)
00140 {
00141 pBattle->render();
00142 }
00143 else
00144 {
00145 overlay_text() << "DemoBattleMode : Main" << endl;
00146 if(notInGame)
00147 {
00148 overlay_text() << "Press [H] to host a game" << endl;
00149 overlay_text() << "Press [J] to join a game" << endl;
00150 overlay_text() << "Press [F] to fake-host a game" << endl;
00151 }
00152 else if( net_amIServer() )
00153 overlay_text() << "Press [SPACE] to begin battle" << endl;
00154
00155 overlay_textOut( Vec2D(0.0f,0.0f) );
00156 }
00157 }
00158
00159 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, INT )
00160 {
00161 sys_init(hInst,800,600,32,true);
00162 sys_setInitFunc(init);
00163 sys_setUpdateFunc(update);
00164 sys_setRenderFunc(render);
00165 sys_go();
00166 return 0;
00167 }
00168
00169 #endif