fftrader-cvs Mailing List for Final Frontier Trader
Status: Alpha
Brought to you by:
tomt64
You can subscribe to this list here.
2005 |
Jan
(8) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(23) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: TomT64 <to...@us...> - 2005-08-24 09:52:40
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20526/src Modified Files: engine.cpp engine.h main.cpp py_baselib.cpp py_baselib.h Added Files: py_classes.h py_ship.cpp Log Message: Added "Ship" class to Python capability, and more scripting additions Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** main.cpp 23 Aug 2005 21:18:06 -0000 1.6 --- main.cpp 24 Aug 2005 09:52:27 -0000 1.7 *************** *** 60,64 **** static bool LoadScenario(); - static bool ShipSelect(float zoom, std::string scenselect); #define PI 3.1415926535897932384626433832795 --- 60,63 ---- *************** *** 319,378 **** } - static bool ShipSelect(float zoom, std::string scenselect) - { - Log::WriteVerbose("Entering ship selection"); - SDL_Surface *screen=SDL_GetVideoSurface(); - SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; - ship->SetZoom(zoom); - ship->SetCredits(mainScen->GetStartCredits()); - ship->SetPriceBought(0); - FPKShip **fpkships; - fpkships=LoadShipsFromScen(mainScen); - int quit=NewShipOptions(SCREEN_WIDTH, SCREEN_HEIGHT, fpkships); - if (quit==-1) engine->Quit(); - if (quit==1) return false; - Uint32 ticks=SDL_GetTicks(); - Log::WriteVerbose("Loading Game..."); - SDL_FillRect(screen,0,0); - centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); - SDL_Flip(screen); - delete map; - map = new Map; - map->Init(zoom); - engine->SetMap(map); - Log::WriteVerbose("Setting map to scenario"); - mainScen->SetMap(map); - Log::WriteVerbose("Loading map file"); - LoadMap(map, mainScen->GetMapFn(), zoom); - //delete gui2; - Log::WriteVerbose("Creating opening message"); - //std::string message=mainScen->GetOpenMessage(); - //gui2=MakeCenterOKWindow(message); - Log::WriteVerbose("Placing ship"); - ship->SetAngle(mainScen->GetStartAngle()); - Log::WriteVerbosen("Ship: Angle: %d",mainScen->GetStartAngle()); - ship->SetSpeed(mainScen->GetStartSpeed()); - Log::WriteVerbosen(" Speed: %d",mainScen->GetStartSpeed()); - ship->SetWarp(false); - ship->SetX(mainScen->GetStartX()); - Log::WriteVerbosen(" X: %d",mainScen->GetStartX()); - ship->SetY(mainScen->GetStartY()); - Log::WriteVerbosen(" Y: %d",mainScen->GetStartY()); - Log::WriteVerbose(" Remaining credits: %d",ship->GetCredits()); - //ship->SetZoom(zoom); - //Log::WriteVerbose("Loading images"); - //ship->ReloadImages(); - Log::WriteVerbose("Adjusting shoot point"); - ship->AdjustShootPoint(); - Log::WriteVerbose("Adding main ship to map"); - map->AddMainShip(ship); - Log::WriteVerbose("Starting up Scenario"); - mainScen->Startup(); - Uint32 timepassed=SDL_GetTicks()-ticks; - Uint32 ms=timepassed%1000; - Uint32 secs=(unsigned int)((double)timepassed/1000.0); - Uint32 mins=(unsigned int)((double)secs/60.0); - Log::WriteVerbose("Scenario loaded in %d minutes, %d seconds, and %d milliseconds",mins,secs,ms); - return true; - } - --- 318,319 ---- Index: engine.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** engine.cpp 23 Aug 2005 21:18:06 -0000 1.5 --- engine.cpp 24 Aug 2005 09:52:27 -0000 1.6 *************** *** 1,3 **** --- 1,4 ---- #include "engine.h" + #include "py_classes.h" extern int SCREEN_WIDTH; *************** *** 7,10 **** --- 8,13 ---- extern PyMethodDef catchMethods[]; + extern PyTypeObject pyship_type; + PyObject *module; PyObject *mainModule; *************** *** 41,44 **** --- 44,51 ---- PyObject_SetAttrString(sysModule, "stdout", catchmodule); PyObject_SetAttrString(sysModule, "stderr", catchmodule); + + Init_ShipType(); + Py_INCREF(&pyship_type); + PyModule_AddObject(module, "Ship", (PyObject*)&pyship_type); } Engine::~Engine() *************** *** 221,232 **** int targety=0; bool engage, disengage; ! angle=ship->GetAngle(); ! x=ship->GetX(); ! y=ship->GetY(); ! double dx=ship->GetDX(); ! double dy=ship->GetDY(); ! int maxspeed=ship->GetMaxSpeed(); ! speed=ship->GetSpeed(); ! bool atwarp=ship->AtWarp(); starx=0; stary=0; --- 228,239 ---- int targety=0; bool engage, disengage; ! angle=mainship->GetAngle(); ! x=mainship->GetX(); ! y=mainship->GetY(); ! double dx=mainship->GetDX(); ! double dy=mainship->GetDY(); ! int maxspeed=mainship->GetMaxSpeed(); ! speed=mainship->GetSpeed(); ! bool atwarp=mainship->AtWarp(); starx=0; stary=0; *************** *** 239,255 **** range=3; savespeed=0; ! __ship_slot curslot=ship->GetCurWeaponSlot(); engage=false; disengage=false; bool paused=false; //setup for GUI stuff ! shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); ! shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); starx=(int)(-dx/10); stary=(int)(-dy/10); starx2=(int)(-dx/20); stary2=(int)(-dy/20); ! sx=ship->GetSectorX(); ! sy=ship->GetSectorY(); mainmap->SetTarget(aiunit); mainmap->CheckSectors(sx, sy); --- 246,262 ---- range=3; savespeed=0; ! __ship_slot curslot=mainship->GetCurWeaponSlot(); engage=false; disengage=false; bool paused=false; //setup for GUI stuff ! shipx=(SCREEN_WIDTH/2)-(mainship->GetImageWidth()/2); ! shipy=(SCREEN_HEIGHT/2)-(mainship->GetImageHeight()/2); starx=(int)(-dx/10); stary=(int)(-dy/10); starx2=(int)(-dx/20); stary2=(int)(-dy/20); ! sx=mainship->GetSectorX(); ! sy=mainship->GetSectorY(); mainmap->SetTarget(aiunit); mainmap->CheckSectors(sx, sy); *************** *** 267,276 **** stars2->Display(starx2, stary2); mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! ship->Display(shipx,shipy); mainmap->DisplayMinimap(4,10,x,y,range); sprintf(disp, "%d sectors", range); centerString(font, 34, 80, "Sensor radius:", white); centerString(font, 34, 90, disp, white); ! ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); while (SDL_PollEvent(&event)) --- 274,283 ---- stars2->Display(starx2, stary2); mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! mainship->Display(shipx,shipy); mainmap->DisplayMinimap(4,10,x,y,range); sprintf(disp, "%d sectors", range); centerString(font, 34, 80, "Sensor radius:", white); centerString(font, 34, 90, disp, white); ! mainship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); while (SDL_PollEvent(&event)) *************** *** 371,387 **** else if((event.key.keysym.sym == maininput->GetWarp1() || event.key.keysym.sym == maininput->GetWarp2()) && !paused && incontrol) { ! if (ship->AtWarp() && ship->WarpEnabled()) { engage=false; disengage=true; } ! else if (!ship->AtWarp() && ship->WarpEnabled()) { disengage=false; engage=true; ship->SetWarp(true); } } else if((event.key.keysym.sym == maininput->GetFire1() || event.key.keysym.sym == maininput->GetFire2()) && !paused && incontrol) { ! if (!ship->AtWarp()) { int tempspeed=speed+maxspeed; if (speed<0) tempspeed=maxspeed; ! //mainmap->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, aiunit, curslot.id); if (curslot.image) { ! mainmap->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, curslot.image, aiunit, curslot.id); Mix_PlayChannel(0,shot,0); } --- 378,394 ---- else if((event.key.keysym.sym == maininput->GetWarp1() || event.key.keysym.sym == maininput->GetWarp2()) && !paused && incontrol) { ! if (mainship->AtWarp() && mainship->WarpEnabled()) { engage=false; disengage=true; } ! else if (!mainship->AtWarp() && mainship->WarpEnabled()) { disengage=false; engage=true; mainship->SetWarp(true); } } else if((event.key.keysym.sym == maininput->GetFire1() || event.key.keysym.sym == maininput->GetFire2()) && !paused && incontrol) { ! if (!mainship->AtWarp()) { int tempspeed=speed+maxspeed; if (speed<0) tempspeed=maxspeed; ! //mainmap->SpawnBullet(mainship->GetShootX(), mainship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, aiunit, curslot.id); if (curslot.image) { ! mainmap->SpawnBullet(mainship->GetShootX(), mainship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, curslot.image, aiunit, curslot.id); Mix_PlayChannel(0,shot,0); } *************** *** 402,408 **** zoom+=0.25; Log::WriteVerbose("Zooming ship"); ! ship->SetZoom(zoom); Log::WriteVerbose("Loading Ship images"); ! ship->ReloadImages(); Log::WriteVerbose("Zooming map"); mainmap->SetZoom(zoom); --- 409,415 ---- zoom+=0.25; Log::WriteVerbose("Zooming ship"); ! mainship->SetZoom(zoom); Log::WriteVerbose("Loading Ship images"); ! mainship->ReloadImages(); Log::WriteVerbose("Zooming map"); mainmap->SetZoom(zoom); *************** *** 415,421 **** zoom-=0.25; Log::WriteVerbose("Zooming ship"); ! ship->SetZoom(zoom); Log::WriteVerbose("Loading Ship images"); ! ship->ReloadImages(); Log::WriteVerbose("Zooming map"); mainmap->SetZoom(zoom); --- 422,428 ---- zoom-=0.25; Log::WriteVerbose("Zooming ship"); ! mainship->SetZoom(zoom); Log::WriteVerbose("Loading Ship images"); ! mainship->ReloadImages(); Log::WriteVerbose("Zooming map"); mainmap->SetZoom(zoom); *************** *** 424,429 **** else if(event.key.keysym.sym == maininput->GetPrevWeapon() && !paused && incontrol) { ! ship->PrevWeapon(); ! if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; else aiunit=0; mainmap->SetTarget(aiunit); --- 431,436 ---- else if(event.key.keysym.sym == maininput->GetPrevWeapon() && !paused && incontrol) { ! mainship->PrevWeapon(); ! if (strcmp(mainship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; else aiunit=0; mainmap->SetTarget(aiunit); *************** *** 431,436 **** else if(event.key.keysym.sym == maininput->GetNextWeapon() && !paused && incontrol) { ! ship->NextWeapon(); ! if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; else aiunit=0; mainmap->SetTarget(aiunit); --- 438,443 ---- else if(event.key.keysym.sym == maininput->GetNextWeapon() && !paused && incontrol) { ! mainship->NextWeapon(); ! if (strcmp(mainship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; else aiunit=0; mainmap->SetTarget(aiunit); *************** *** 439,443 **** { mainmap->Dock(x,y); ! if(aiunit==-1 && !strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) { aiunit=0; --- 446,450 ---- { mainmap->Dock(x,y); ! if(aiunit==-1 && !strcmp(mainship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) { aiunit=0; *************** *** 479,497 **** } fpscount+=1; ! bool overheated=ship->IsOverHeated(); ! int hullhits=ship->GetHullHits(); ! int maxhullhits=ship->GetMaxHullHits(); ! shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); ! shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); ! ship->Move(0,0); ! x=ship->GetX(); ! y=ship->GetY(); ! dx=ship->GetDX(); ! dy=ship->GetDY(); ! angle=ship->GetAngle(); ! speed=ship->GetSpeed(); ! sx=ship->GetSectorX(); ! sy=ship->GetSectorY(); ! curslot=ship->GetCurWeaponSlot(); aiunits=mainmap->GetUnitCount(); if (curslot.image) --- 486,504 ---- } fpscount+=1; ! bool overheated=mainship->IsOverHeated(); ! int hullhits=mainship->GetHullHits(); ! int maxhullhits=mainship->GetMaxHullHits(); ! shipx=(SCREEN_WIDTH/2)-(mainship->GetImageWidth()/2); ! shipy=(SCREEN_HEIGHT/2)-(mainship->GetImageHeight()/2); ! mainship->Move(0,0); ! x=mainship->GetX(); ! y=mainship->GetY(); ! dx=mainship->GetDX(); ! dy=mainship->GetDY(); ! angle=mainship->GetAngle(); ! speed=mainship->GetSpeed(); ! sx=mainship->GetSectorX(); ! sy=mainship->GetSectorY(); ! curslot=mainship->GetCurWeaponSlot(); aiunits=mainmap->GetUnitCount(); if (curslot.image) *************** *** 515,519 **** if (engage && speed<50) { ! ship->SetSpeed(speed+1); } if (engage && speed>=50) --- 522,526 ---- if (engage && speed<50) { ! mainship->SetSpeed(speed+1); } if (engage && speed>=50) *************** *** 523,538 **** if (disengage && speed>savespeed) { ! ship->SetSpeed(speed-1); } if (disengage && speed<=savespeed) { disengage=false; ! ship->SetWarp(false); } ! speed=ship->GetSpeed(); mainmap->MoveBullets(); mainmap->MoveAI(x,y); mainmap->CheckSectors(sx, sy); ! atwarp=ship->AtWarp(); if (!atwarp) { --- 530,545 ---- if (disengage && speed>savespeed) { ! mainship->SetSpeed(speed-1); } if (disengage && speed<=savespeed) { disengage=false; ! mainship->SetWarp(false); } ! speed=mainship->GetSpeed(); mainmap->MoveBullets(); mainmap->MoveAI(x,y); mainmap->CheckSectors(sx, sy); ! atwarp=mainship->AtWarp(); if (!atwarp) { *************** *** 545,549 **** } mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); savespeed=speed; if (savespeed<0) { savespeed=0; } --- 552,556 ---- } mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! if (hullhits<maxhullhits && !overheated) mainship->Display(shipx,shipy); savespeed=speed; if (savespeed<0) { savespeed=0; } *************** *** 562,566 **** } mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); for(i=0; i<(int)starfields.size(); i++) { --- 569,573 ---- } mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); ! if (hullhits<maxhullhits && !overheated) mainship->Display(shipx,shipy); for(i=0; i<(int)starfields.size(); i++) { *************** *** 584,588 **** centerString(font10, 34, 80, "Sensor radius:", white); centerString(font10, 34, 90, disp, white); ! ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); } --- 591,595 ---- centerString(font10, 34, 80, "Sensor radius:", white); centerString(font10, 34, 90, disp, white); ! mainship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); } *************** *** 601,614 **** if (fpscount%2==0 && !atwarp && !engage && !disengage) { ! if (speed<ship->GetMaxSpeed()) { ! ship->SetSpeed(speed+1); } } if (fpscount%2==0 && atwarp && !engage && !disengage) { ! if (speed<ship->GetMaxWarp()) { ! ship->SetSpeed(speed+1); } } --- 608,621 ---- if (fpscount%2==0 && !atwarp && !engage && !disengage) { ! if (speed<mainship->GetMaxSpeed()) { ! mainship->SetSpeed(speed+1); } } if (fpscount%2==0 && atwarp && !engage && !disengage) { ! if (speed<mainship->GetMaxWarp()) { ! mainship->SetSpeed(speed+1); } } *************** *** 618,624 **** if (fpscount%2==0 && !atwarp && !engage && !disengage) { ! if (speed>-ship->GetMaxSpeed()) { ! ship->SetSpeed(speed-1); } } --- 625,631 ---- if (fpscount%2==0 && !atwarp && !engage && !disengage) { ! if (speed>-mainship->GetMaxSpeed()) { ! mainship->SetSpeed(speed-1); } } *************** *** 627,631 **** if (speed>50) { ! ship->SetSpeed(speed-1); } } --- 634,638 ---- if (speed>50) { ! mainship->SetSpeed(speed-1); } } *************** *** 637,645 **** if (speed>0) { ! ship->SetSpeed(speed-1); } if (speed<0) { ! ship->SetSpeed(speed+1); } } --- 644,652 ---- if (speed>0) { ! mainship->SetSpeed(speed-1); } if (speed<0) { ! mainship->SetSpeed(speed+1); } } *************** *** 647,660 **** if(keys[maininput->GetLeft()] && incontrol) { ! if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) { ! ship->Rotate(0); turntime=SDL_GetTicks(); } else { ! if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) { ! ship->Rotate(0); turntime=SDL_GetTicks(); } --- 654,667 ---- if(keys[maininput->GetLeft()] && incontrol) { ! if (!atwarp && SDL_GetTicks()>=turntime+mainship->GetTurnDelay()) { ! mainship->Rotate(0); turntime=SDL_GetTicks(); } else { ! if (SDL_GetTicks()>=turntime+mainship->GetWarpTurnDelay()) { ! mainship->Rotate(0); turntime=SDL_GetTicks(); } *************** *** 663,675 **** if(keys[maininput->GetRight()] && incontrol) { ! if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) { ! ship->Rotate(1); turntime=SDL_GetTicks(); } else { ! if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) { ! ship->Rotate(1); turntime=SDL_GetTicks(); } --- 670,682 ---- if(keys[maininput->GetRight()] && incontrol) { ! if (!atwarp && SDL_GetTicks()>=turntime+mainship->GetTurnDelay()) { ! mainship->Rotate(1); turntime=SDL_GetTicks(); } else { ! if (SDL_GetTicks()>=turntime+mainship->GetWarpTurnDelay()) { ! mainship->Rotate(1); turntime=SDL_GetTicks(); } *************** *** 745,748 **** --- 752,850 ---- } } + bool Engine::ShipSelect() + { + Log::WriteVerbose("Entering ship selection"); + //SDL_Surface *screen=SDL_GetVideoSurface(); + //SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; + mainship->SetZoom((float)0.5); + //mainship->SetCredits(mainscen->GetStartCredits()); + mainship->SetPriceBought(0); + FPKShip **fpkships; + fpkships=this->LoadAllFPKShips(); + int quit=NewShipOptions(SCREEN_WIDTH, SCREEN_HEIGHT, fpkships); + mainship=ship; + if (quit==-1) this->Quit(); + if (quit==1) return false; + Uint32 ticks=SDL_GetTicks(); + //Log::WriteVerbose("Loading Game..."); + //SDL_FillRect(screen,0,0); + //centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); + //SDL_Flip(screen); + delete mainmap; + mainmap = new Map(); + mainmap->Init((float)0.5); + Log::WriteVerbose("Setting map to scenario"); + mainscen->SetMap(mainmap); + //Log::WriteVerbose("Loading map file"); + //LoadMap(map, mainscen->GetMapFn(), zoom); + //delete gui2; + //Log::WriteVerbose("Creating opening message"); + //std::string message=mainscen->GetOpenMessage(); + //gui2=MakeCenterOKWindow(message); + //Log::WriteVerbose("Placing ship"); + //mainship->SetAngle(mainscen->GetStartAngle()); + //Log::WriteVerbosen("Ship: Angle: %d",mainscen->GetStartAngle()); + //mainship->SetSpeed(mainscen->GetStartSpeed()); + //Log::WriteVerbosen(" Speed: %d",mainscen->GetStartSpeed()); + //mainship->SetWarp(false); + //mainship->SetX(mainscen->GetStartX()); + //Log::WriteVerbosen(" X: %d",mainscen->GetStartX()); + //mainship->SetY(mainscen->GetStartY()); + //Log::WriteVerbosen(" Y: %d",mainscen->GetStartY()); + //Log::WriteVerbose(" Remaining credits: %d",mainship->GetCredits()); + mainship->SetZoom((float)0.5); + //Log::WriteVerbose("Loading images"); + //mainship->ReloadImages(); + Log::WriteVerbose("Adjusting shoot point"); + mainship->AdjustShootPoint(); + Log::WriteVerbose("Adding main ship to map"); + mainmap->AddMainShip(mainship); + //Log::WriteVerbose("Starting up Scenario"); + //mainscen->Startup(); + Uint32 timepassed=SDL_GetTicks()-ticks; + Uint32 ms=timepassed%1000; + Uint32 secs=(unsigned int)((double)timepassed/1000.0); + Uint32 mins=(unsigned int)((double)secs/60.0); + Log::WriteVerbose("Scenario loaded in %d minutes, %d seconds, and %d milliseconds",mins,secs,ms); + return true; + } + FPKShip **Engine::LoadAllFPKShips() + { + Log::WriteVerbose("Inside LoadAllFPKShips"); + char **fpklist; + char **k; + int i, j, temp, fpks, max; + int total[60]; + static FPKShip *fpkships[100]; + for(i=0; i<100; i++) + { + fpkships[i]=0; + } + fpklist=PHYSFS_enumerateFiles("fpk"); + fpks=FPK_count(); + i=0; + max=0; + for (k = fpklist; *k != NULL; k++) + { + if(IsFPK(*k)) + { + total[i]=FPK_countPlayerShips(*k); + max+=total[i]; + i++; + } + } + PHYSFS_freeList(fpklist); + temp=0; + for(i=0; i<fpks; i++) + { + for(j=temp; j<total[i]+temp; j++) + { + FPKShip *tempship=new FPKShip(i, j-temp); + fpkships[j]=tempship; + } + temp=j; + } + return fpkships; + } void Engine::SetMainModule(std::string modulename) { *************** *** 757,760 **** --- 859,863 ---- { mainship=ship; + if (mainmap) mainmap->AddMainShip(ship); } void Engine::InControl(bool control) --- NEW FILE: py_ship.cpp --- #include "py_classes.h" #include "engine.h" extern Engine *engine; PyObject* ship_init(ShipObject* self, PyObject* args) { int x=0; int y=0; char* img = NULL; char* fpk = NULL; float zoom=(float)0.0; if (!PyArg_ParseTuple(args, "iissf", &x, &y, &img, &fpk, &zoom)) return NULL; self->unit->Init(x, y, img, fpk, zoom); Py_INCREF(Py_None); return Py_None; } PyObject* ship_display(ShipObject* self, PyObject* args) { int x=0; int y=0; if (!PyArg_ParseTuple(args, "ii", &x, &y)) return NULL; self->unit->Display(x,y); Py_INCREF(Py_None); return Py_None; } PyObject* ship_setlocation(ShipObject* self, PyObject* args, PyObject* kw) { static char* keywords[] = { "x", "y", 0 }; int x=0; int y=0; if (!PyArg_ParseTupleAndKeywords(args, kw, "ii:ShipSetLocation", keywords, &x, &y)) return 0; self->unit->SetX(x); self->unit->SetY(y); Py_INCREF(Py_None); return Py_None; } PyObject* ship_colorize(ShipObject* self, PyObject* args, PyObject* kw) { static char* keywords[] = { "r", "g", "b", 0 }; Uint8 r=0; Uint8 g=0; Uint8 b=0; if (!PyArg_ParseTupleAndKeywords(args, kw, "iii:ShipColorize", keywords, &r, &g, &b)) return 0; self->unit->Colorize(r, g, b); Py_INCREF(Py_None); return Py_None; } PyObject* ship_ai(ShipObject* self, PyObject* args, PyObject* kw) { static char* keywords[] = { "aistate", 0 }; char* saistate = NULL; int aistate=AI_STATE_STOP; if (!PyArg_ParseTupleAndKeywords(args, kw, "s:ShipAI", keywords, &saistate)) return 0; self->unit->SetAI("SIMPLE"); if (!strcmp(saistate,"AI_STATE_STOP")) aistate=AI_STATE_STOP; else if (!strcmp(saistate,"AI_STATE_RUN")) aistate=AI_STATE_RUN; else if (!strcmp(saistate,"AI_STATE_ATTACK")) aistate=AI_STATE_ATTACK; else if (!strcmp(saistate,"AI_STATE_LOOK")) aistate=AI_STATE_LOOK; else if (!strcmp(saistate,"AI_STATE_IGNORE")) aistate=AI_STATE_IGNORE; else if (!strcmp(saistate,"AI_STATE_WAITLOOK")) aistate=AI_STATE_WAITLOOK; self->unit->SetAIState(aistate); Py_INCREF(Py_None); return Py_None; } PyMethodDef shipMethods[] = { {"Init", (PyCFunction)ship_init, METH_VARARGS, "Inits ship"}, {"Display", (PyCFunction)ship_display, METH_VARARGS, "Displays the ship"}, {"SetLocation", (PyCFunction)ship_setlocation, METH_KEYWORDS, "SetLocation(x, y)\nSets the location of a ship"}, {"Colorize", (PyCFunction)ship_colorize, METH_KEYWORDS, "Colorize(r, g, b)\nApplies a color to a ship"}, {"AI", (PyCFunction)ship_ai, METH_KEYWORDS, "AI(aistate)\nGive the Ship an AI"}, {NULL, NULL, 0, NULL} }; //PyGetSetDef properties[] = { // { 0 } //}; PyTypeObject pyship_type; void Init_ShipType() { memset(&pyship_type, 0, sizeof pyship_type); pyship_type.ob_refcnt = 1; pyship_type.ob_type = &PyType_Type; pyship_type.tp_name = "Ship"; pyship_type.tp_basicsize = sizeof pyship_type; pyship_type.tp_dealloc = (destructor)Destroy_Ship; pyship_type.tp_methods = shipMethods; //pyship_type.tp_getset = properties; pyship_type.tp_doc = "Ship object"; pyship_type.tp_new = New_Ship; PyType_Ready(&pyship_type); } PyObject* New_Ship(PyTypeObject* type, PyObject* args, PyObject* kw) { ShipObject* unit1 = PyObject_New(ShipObject, &pyship_type); if (!unit1) return 0; unit1->unit=new Unit(); Map *map=engine->GetMap(); map->AddToUnits(unit1->unit); return (PyObject*)unit1; } void Destroy_Ship(ShipObject* self) { PyObject_Del(self); } Index: py_baselib.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** py_baselib.h 23 Aug 2005 09:56:44 -0000 1.4 --- py_baselib.h 24 Aug 2005 09:52:27 -0000 1.5 *************** *** 5,8 **** --- 5,9 ---- #include "engine.h" #include "guiapply.h" + #include "py_classes.h" PyObject* fft_log(PyObject* self, PyObject* args); *************** *** 13,16 **** --- 14,18 ---- PyObject* fft_yesnobox(PyObject* self, PyObject* args); PyObject* fft_render(PyObject* self); + PyObject* fft_setmainship(PyObject* self, PyObject* args); #endif /* __PY_BASELIB_H__ */ Index: engine.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** engine.h 23 Aug 2005 21:18:06 -0000 1.5 --- engine.h 24 Aug 2005 09:52:27 -0000 1.6 *************** *** 13,16 **** --- 13,17 ---- #include "log.h" #include "scenario.h" + #include "shop.h" #include "units.h" *************** *** 53,56 **** --- 54,59 ---- void CleanUpGame(); void Render(); + bool ShipSelect(); + FPKShip **LoadAllFPKShips(); void SetMainModule(std::string modulename); Unit *GetMainShip(); --- NEW FILE: py_classes.h --- #ifndef __PY_CLASSES_H__ #define __PY_CLASSES_H__ #include "Python.h" #include "map.h" #include "units.h" struct ShipObject { PyObject_HEAD Unit* unit; }; PyObject* ship_init(ShipObject* self, PyObject* pArgs); PyObject* ship_display(ShipObject* self, PyObject* pArgs); PyObject* ship_setlocation(ShipObject* self, PyObject* args, PyObject* kw); PyObject* ship_colorize(ShipObject* self, PyObject* args, PyObject* kw); void Init_ShipType(); PyObject* New_Ship(PyTypeObject* type, PyObject* args, PyObject* kw); void Destroy_Ship(ShipObject* self); #endif /* __PY_CLASSES_H__ */ Index: py_baselib.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** py_baselib.cpp 23 Aug 2005 21:18:06 -0000 1.5 --- py_baselib.cpp 24 Aug 2005 09:52:27 -0000 1.6 *************** *** 4,7 **** --- 4,9 ---- extern int SCREEN_HEIGHT; + extern PyTypeObject pyship_type; + extern Engine *engine; *************** *** 9,13 **** { {"Exit", (PyCFunction)fft_exit, METH_VARARGS, "Exit(message)\nExits the current game displaying \"message\", then returns to the main menu\n"}, ! {"Render", (PyCFunction)fft_render, METH_NOARGS, "Probably not goign to exist\n"}, {"MessageBox", (PyCFunction)fft_messagebox, METH_VARARGS, "MessageBox(message)\nDisplays \"message\" in a message box\n"}, {"YesNoBox", (PyCFunction)fft_yesnobox, METH_VARARGS, "YesNoBox(message)\nDisplays \"message\" in a message box that has a yes or no option. Returns a nonzero value if yes is pressed, zero if no is pressed.\n"}, --- 11,16 ---- { {"Exit", (PyCFunction)fft_exit, METH_VARARGS, "Exit(message)\nExits the current game displaying \"message\", then returns to the main menu\n"}, ! {"SetMainShip", (PyCFunction)fft_setmainship, METH_VARARGS, "SetMainShip(ship)\nSets the Main ship of the program to this ship, and gives it control\n"}, ! {"Render", (PyCFunction)fft_render, METH_NOARGS, "Probably not going to exist\n"}, {"MessageBox", (PyCFunction)fft_messagebox, METH_VARARGS, "MessageBox(message)\nDisplays \"message\" in a message box\n"}, {"YesNoBox", (PyCFunction)fft_yesnobox, METH_VARARGS, "YesNoBox(message)\nDisplays \"message\" in a message box that has a yes or no option. Returns a nonzero value if yes is pressed, zero if no is pressed.\n"}, *************** *** 106,107 **** --- 109,134 ---- return Py_None; } + PyObject* fft_setmainship(PyObject* self, PyObject* args) + { + ShipObject *ship; + if (!PyArg_ParseTuple(args, "O:SetMainShip", &ship)) return NULL; + + if ((PyObject*)ship == Py_None) + { + engine->InControl(false); + } + else + { + if (ship->ob_type != &pyship_type) + { + PyErr_SetString(PyExc_TypeError, "SetMainShip not called with Ship object or None."); + return 0; + } + engine->InControl(true); + engine->SetMainShip(ship->unit); + } + + Py_INCREF(Py_None); + return Py_None; + } + |
From: TomT64 <to...@us...> - 2005-08-24 09:52:40
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20526 Modified Files: fftrader.dev fftrader.dsp Log Message: Added "Ship" class to Python capability, and more scripting additions Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** fftrader.dev 23 Aug 2005 09:56:43 -0000 1.13 --- fftrader.dev 24 Aug 2005 09:52:26 -0000 1.14 *************** *** 2,6 **** FileName=fftrader.dev Name=fftrader ! UnitCount=35 Type=0 Ver=1 --- 2,6 ---- FileName=fftrader.dev Name=fftrader ! UnitCount=37 Type=0 Ver=1 *************** *** 209,213 **** [Unit36] ! FileName=src\engine.h CompileCpp=1 Folder=fftrader --- 209,213 ---- [Unit36] ! FileName=src\py_classes.h CompileCpp=1 Folder=fftrader *************** *** 427,428 **** --- 427,438 ---- BuildCmd= + [Unit37] + FileName=src\py_ship.cpp + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + Index: fftrader.dsp =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dsp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** fftrader.dsp 21 Aug 2005 11:29:49 -0000 1.13 --- fftrader.dsp 24 Aug 2005 09:52:26 -0000 1.14 *************** *** 150,153 **** --- 150,157 ---- # Begin Source File + SOURCE=.\src\py_ship.cpp + # End Source File + # Begin Source File + SOURCE=.\src\scenario.cpp # End Source File *************** *** 218,221 **** --- 222,229 ---- # Begin Source File + SOURCE=.\src\py_classes.h + # End Source File + # Begin Source File + SOURCE=.\src\scenario.h # End Source File |
From: TomT64 <to...@us...> - 2005-08-23 21:18:15
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24395/src Modified Files: engine.cpp engine.h graphics.cpp guiapply.cpp guiapply.h main.cpp py_baselib.cpp Log Message: Main loop now runs without a ship Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.cpp 23 Aug 2005 09:56:44 -0000 1.5 --- main.cpp 23 Aug 2005 21:18:06 -0000 1.6 *************** *** 28,33 **** #include "SDL_mixer.h" #include "SDL_ttf.h" - #include "SDL_framerate.h" #include "fftfile.h" #include "input.h" --- 28,33 ---- #include "SDL_mixer.h" #include "SDL_ttf.h" + #include "engine.h" #include "fftfile.h" #include "input.h" *************** *** 40,44 **** #include "units.h" - Uint8* keys; int SCREEN_WIDTH; int SCREEN_HEIGHT; --- 40,43 ---- *************** *** 54,68 **** Engine *engine; Map *map; - GUI *gui2; Mix_Chunk *shot; Mix_Chunk *explode; int SMOOTH=1; - bool FPSSHOW=false; std::string VERSION="0.70 alpha"; - static int mainLoop(); - static int AskToQuitGame(); - static int InGameMenu(); static bool LoadScenario(); static bool ShipSelect(float zoom, std::string scenselect); --- 53,62 ---- *************** *** 70,81 **** #define PI 3.1415926535897932384626433832795 - SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; - SDL_Color yellow = { 0xFF, 0xFF, 0x00, 0 }; - SDL_Color black = { 0x00, 0x00, 0x00, 0 }; - int main ( int argc, char *argv[] ) { bool fullscreen=false; bool software=false; if (argc>1) { --- 64,72 ---- #define PI 3.1415926535897932384626433832795 int main ( int argc, char *argv[] ) { bool fullscreen=false; bool software=false; + bool showfps=false; if (argc>1) { *************** *** 97,101 **** if (!strcmp(argv[i],"-showfps")) { ! FPSSHOW=true; } if (!strcmp(argv[i],"-log")) --- 88,92 ---- if (!strcmp(argv[i],"-showfps")) { ! showfps=true; } if (!strcmp(argv[i],"-log")) *************** *** 113,116 **** --- 104,108 ---- srand(time(NULL)); engine=new Engine(); + if (showfps) engine->ShowFPS(); SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 237,244 **** Log::WriteVerbose("Audio initialized and sounds loaded"); - gui2=new GUI; - gui2->Init(); - engine->AddGUI("openmessage",gui2); - SDL_Delay(1000); --- 229,232 ---- *************** *** 292,296 **** Log::WriteVerbose("Proceeding to main game play"); bool init=engine->StartGame(); ! if (init) maintemp=mainLoop(); engine->CleanUpGame(); Log::WriteVerbose("Main gameplay exited"); --- 280,284 ---- Log::WriteVerbose("Proceeding to main game play"); bool init=engine->StartGame(); ! if (init) maintemp=engine->MainLoop(); engine->CleanUpGame(); Log::WriteVerbose("Main gameplay exited"); *************** *** 306,498 **** } - static int AskToQuitGame() - { - Log::WriteVerbose("AskToQuitGame()"); - SDL_Event event; - SDL_Surface *screen=SDL_GetVideoSurface(); - SDL_Surface *bg = SDL_CreateRGBSurface(0, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); - SDL_Rect dest; - dest.x = 0; - dest.y = 0; - SDL_BlitSurface(screen, NULL, bg, &dest); - GUI *gui3=new GUI; - gui3->Init(); - gui3->MakeWindow(120,200,SCREEN_WIDTH-240,110); - gui3->MakeStatic(30,206,SCREEN_WIDTH-60,20,"Are you sure you want to quit this game?"); - gui3->MakeButton(150,270,40,"Yes"); - gui3->MakeButton(SCREEN_WIDTH-190,270,40,"No"); - int yesButton=gui3->GetButtonID(150,270,40,"Yes"); - int noButton=gui3->GetButtonID(SCREEN_WIDTH-190,270,40,"No"); - int done=0; - int getx, gety; - int click=-1; - while(!done) - { - Slock(); - while (SDL_PollEvent(&event)) - { - // an event was found - switch (event.type) { - // close button clicked - case SDL_QUIT: - delete gui3; - engine->Quit(); - break; - - // handle the keyboard - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_RETURN: - done = 1; - break; - default: - break; - } - break; - case SDL_MOUSEMOTION: - SDL_GetMouseState(&getx, &gety); - gui3->SendMouseMotion(getx,gety); - break; - case SDL_MOUSEBUTTONDOWN: - SDL_GetMouseState(&getx, &gety); - click = gui3->SendMouseClick(getx, gety); - break; - case SDL_MOUSEBUTTONUP: - SDL_GetMouseState(&getx, &gety); - if (click!=-1 && click==gui3->SendMouseClick(getx, gety)) - { - if (click==yesButton) - { - SDL_FillRect(screen,0,0); - DrawIMG(bg,0,0); - gui3->Draw(); - Sulock(); - SDL_Flip(screen); - SDL_Delay(100); - done=1; - } - if (click==noButton) - { - SDL_FillRect(screen,0,0); - DrawIMG(bg,0,0); - gui3->Draw(); - Sulock(); - SDL_Flip(screen); - SDL_Delay(100); - done=-1; - } - } - gui3->UpdateButtons(); - break; - default: - break; - } - } - SDL_FillRect(screen,0,0); - DrawIMG(bg,0,0); - gui3->Draw(); - Sulock(); - SDL_Flip(screen); - } - delete gui3; - SDL_FreeSurface(bg); - if (done!=1) done=0; - return done; - } - - static int InGameMenu() - { - Log::WriteVerbose("InGameMenu()"); - SDL_Event event; - SDL_Surface *screen=SDL_GetVideoSurface(); - int w=screen->w; - int h=screen->h; - SDL_Surface *bg = SDL_CreateRGBSurface(0, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); - SDL_Rect dest; - dest.x = 0; - dest.y = 0; - SDL_BlitSurface(screen, NULL, bg, &dest); - GUI *optionsGUI=new GUI; - optionsGUI->Init(); - optionsGUI->MakeWindow(60, 120, w-120, 220); - optionsGUI->MakeStatic(60,126,w-120,20,"Menu"); - int sControls=optionsGUI->MakeButton(100,160,w-200, "Controls"); - int sCancel=optionsGUI->MakeButton(100,280,200, "Back to Game"); - int sExit=optionsGUI->MakeButton(w-300,280,200, "Exit Game"); - - int done=0; - int getx, gety; - int click=-1; - while(!done) - { - Slock(); - while (SDL_PollEvent(&event)) - { - // an event was found - switch (event.type) { - // close button clicked - case SDL_QUIT: - done=-1; - break; - - // handle the keyboard - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_ESCAPE: - done=AskToQuitGame(); - break; - default: - break; - } - break; - case SDL_MOUSEMOTION: - SDL_GetMouseState(&getx, &gety); - optionsGUI->SendMouseMotion(getx,gety); - break; - case SDL_MOUSEBUTTONDOWN: - SDL_GetMouseState(&getx, &gety); - click = optionsGUI->SendMouseClick(getx, gety); - break; - case SDL_MOUSEBUTTONUP: - SDL_GetMouseState(&getx, &gety); - if (click!=-1 && click==optionsGUI->SendMouseClick(getx, gety)) - { - SDL_FillRect(screen,0,0); - DrawIMG(bg,0,0); - optionsGUI->Draw(); - Sulock(); - SDL_Flip(screen); - if (click==sControls) - { - done=ControlChanging(w,h,bg,false); - if (done==1) done=0; - } - if (click==sCancel) - { - done=2; - } - if (click==sExit) - { - done=AskToQuitGame(); - } - } - optionsGUI->UpdateButtons(); - break; - default: - break; - } - } - SDL_FillRect(screen,0,0); - DrawIMG(bg,0,0); - optionsGUI->Draw(); - Sulock(); - SDL_Flip(screen); - } - delete optionsGUI; - SDL_FreeSurface(bg); - if (done!=1 && done!=-1) done=0; - return done; - } - static bool LoadScenario() { --- 294,297 ---- *************** *** 524,527 **** --- 323,327 ---- Log::WriteVerbose("Entering ship selection"); SDL_Surface *screen=SDL_GetVideoSurface(); + SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; ship->SetZoom(zoom); ship->SetCredits(mainScen->GetStartCredits()); *************** *** 545,552 **** Log::WriteVerbose("Loading map file"); LoadMap(map, mainScen->GetMapFn(), zoom); ! delete gui2; Log::WriteVerbose("Creating opening message"); ! std::string message=mainScen->GetOpenMessage(); ! gui2=MakeCenterOKWindow(message); Log::WriteVerbose("Placing ship"); ship->SetAngle(mainScen->GetStartAngle()); --- 345,352 ---- Log::WriteVerbose("Loading map file"); LoadMap(map, mainScen->GetMapFn(), zoom); ! //delete gui2; Log::WriteVerbose("Creating opening message"); ! //std::string message=mainScen->GetOpenMessage(); ! //gui2=MakeCenterOKWindow(message); Log::WriteVerbose("Placing ship"); ship->SetAngle(mainScen->GetStartAngle()); *************** *** 577,1054 **** } - static int mainLoop() - { - Log::WriteVerbose("Main Loop begin"); - SDL_Event event; - SDL_Surface *screen=SDL_GetVideoSurface(); - int done=0; - char disp[100]; - int getx, gety; - int click=-1; - int ingameok=gui2->GetButtonID(150,300,SCREEN_WIDTH-300,"Go!"); - int x, y, angle, speed, starx, stary, starx2, stary2, shipx, shipy, sx, sy, savespeed, range; - int fps, fpscount; - int targetx=0; - int targety=0; - bool engage, disengage; - angle=ship->GetAngle(); - x=ship->GetX(); - y=ship->GetY(); - double dx=ship->GetDX(); - double dy=ship->GetDY(); - int maxspeed=ship->GetMaxSpeed(); - speed=ship->GetSpeed(); - bool atwarp=ship->AtWarp(); - starx=0; - stary=0; - starx2=0; - stary2=0; - fpscount=0; - int aiunit=-1; - int aiunits=map->GetUnitCount(); - fps=0; - range=3; - savespeed=0; - __ship_slot curslot=ship->GetCurWeaponSlot(); - engage=false; - disengage=false; - bool paused=false; - //setup for GUI stuff - shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); - shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); - starx=(int)(-dx/10); - stary=(int)(-dy/10); - starx2=(int)(-dx/20); - stary2=(int)(-dy/20); - sx=ship->GetSectorX(); - sy=ship->GetSectorY(); - map->SetTarget(aiunit); - map->CheckSectors(sx, sy); - float zoom=0.5; - Log::WriteVerbose("Variables set, displaying opening message"); - TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); - engine->AddFont("font9",font9); - while(!done) - { - Slock(); - SDL_FillRect(screen,0,0); - stars->Display(starx, stary); - stars2->Display(starx2, stary2); - map->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); - ship->Display(shipx,shipy); - map->DisplayMinimap(4,10,x,y,range); - sprintf(disp, "%d sectors", range); - centerString(font, 34, 80, "Sensor radius:", white); - centerString(font, 34, 90, disp, white); - ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); - map->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); - while (SDL_PollEvent(&event)) - { - switch (event.type) { - // close button clicked - case SDL_QUIT: - return -1; - break; - - // handle the keyboard - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_RETURN: - done = 1; - break; - case SDLK_ESCAPE: - done = 1; - break; - default: - break; - } - break; - case SDL_MOUSEMOTION: - SDL_GetMouseState(&getx, &gety); - gui2->SendMouseMotion(getx,gety); - break; - case SDL_MOUSEBUTTONDOWN: - SDL_GetMouseState(&getx, &gety); - click = gui2->SendMouseClick(getx, gety); - break; - case SDL_MOUSEBUTTONUP: - SDL_GetMouseState(&getx, &gety); - if (click!=-1 && click==gui2->SendMouseClick(getx, gety)) - { - if (click==ingameok) - { - gui2->Draw(); - gui2->UpdateButtons(); - Sulock(); - SDL_Flip(screen); - done=1; - } - } - gui2->UpdateButtons(); - break; - default: - break; - } - } - gui2->Draw(); - Sulock(); - SDL_Flip(screen); - } - done=0; - FPSmanager *FPS = new FPSmanager; - SDL_initFramerate(FPS); - SDL_setFramerate(FPS, 60); - Uint32 time=SDL_GetTicks(); - Uint32 pausetime=0; - Uint32 lastpausetime=SDL_GetTicks(); - Uint32 turntime=SDL_GetTicks(); - Uint32 checktime=SDL_GetTicks(); - char disppause[100]; - sprintf(disppause, "Press '%s' to unpause", fftinput->GetPauseStr().c_str()); - Log::WriteVerbose("Entering gameplay loop"); - while(!done) - { - while (SDL_PollEvent(&event)) - { - if(event.type == SDL_QUIT) { done=-1; } - else if(event.type == SDL_ACTIVEEVENT) - { - if(event.active.state==SDL_APPACTIVE || event.active.state==SDL_APPINPUTFOCUS) - { - if(event.active.gain==0) - { - paused=true; - Log::WriteVerbose("Game was paused because the window lost focus"); - if (paused) - { - centerString(font2, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2-8-1, "Game Paused", black); - centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-8, "Game Paused", yellow); - centerString(font2, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2+8-1, disppause, black); - centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2+8, disppause, yellow); - SDL_Flip(screen); - } - } - } - } - else if(event.type == SDL_KEYDOWN) - { - if(event.key.keysym.sym == fftinput->GetCancel()) - { - done = InGameMenu(); - } - else if((event.key.keysym.sym == fftinput->GetWarp1() || event.key.keysym.sym == fftinput->GetWarp2()) && !paused) - { - if (ship->AtWarp() && ship->WarpEnabled()) { engage=false; disengage=true; } - else if (!ship->AtWarp() && ship->WarpEnabled()) { disengage=false; engage=true; ship->SetWarp(true); } - } - else if((event.key.keysym.sym == fftinput->GetFire1() || event.key.keysym.sym == fftinput->GetFire2()) && !paused) - { - if (!ship->AtWarp()) - { - int tempspeed=speed+maxspeed; - if (speed<0) tempspeed=maxspeed; - //map->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, aiunit, curslot.id); - if (curslot.image) - { - map->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, curslot.image, aiunit, curslot.id); - Mix_PlayChannel(0,shot,0); - } - } - } - else if(event.key.keysym.sym == fftinput->GetMiniMapZoomIn() && !paused) - { - if (range*2 < 20) { range=range*2; } - } - else if(event.key.keysym.sym == fftinput->GetMiniMapZoomOut() && !paused) - { - if (range/2 > 1) { range=range/2; } - } - else if(event.key.keysym.sym == fftinput->GetZoomIn() && !paused) - { - if (zoom+0.25 <= 1) - { - zoom+=0.25; - Log::WriteVerbose("Zooming ship"); - ship->SetZoom(zoom); - Log::WriteVerbose("Loading Ship images"); - ship->ReloadImages(); - Log::WriteVerbose("Zooming map"); - map->SetZoom(zoom); - } - } - else if(event.key.keysym.sym == fftinput->GetZoomOut() && !paused) - { - if (zoom-0.25 >=0.5) - { - zoom-=0.25; - Log::WriteVerbose("Zooming ship"); - ship->SetZoom(zoom); - Log::WriteVerbose("Loading Ship images"); - ship->ReloadImages(); - Log::WriteVerbose("Zooming map"); - map->SetZoom(zoom); - } - } - else if(event.key.keysym.sym == fftinput->GetPrevWeapon() && !paused) - { - ship->PrevWeapon(); - if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; - else aiunit=0; - map->SetTarget(aiunit); - } - else if(event.key.keysym.sym == fftinput->GetNextWeapon() && !paused) - { - ship->NextWeapon(); - if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; - else aiunit=0; - map->SetTarget(aiunit); - } - else if(event.key.keysym.sym == fftinput->GetDock() && !paused) - { - map->Dock(x,y); - if(aiunit==-1 && !strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) - { - aiunit=0; - map->SetTarget(aiunit); - } - } - else if(event.key.keysym.sym == fftinput->GetPrevTarget() && !paused && aiunit!=-1) - { - if (aiunit+1<aiunits) aiunit++; - else aiunit=0; - map->SetTarget(aiunit); - } - else if(event.key.keysym.sym == fftinput->GetNextTarget() && !paused && aiunit!=-1) - { - if (aiunit-1>=0) aiunit--; - else aiunit=aiunits-1; - map->SetTarget(aiunit); - } - else if(event.key.keysym.sym == fftinput->GetPause()) - { - paused=!paused; - if (paused) - { - centerString(font2, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2-8-1, "Game Paused", black); - centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-8, "Game Paused", yellow); - centerString(font2, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2+8-1, disppause, black); - centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2+8, disppause, yellow); - SDL_Flip(screen); - } - } - } - } - if (!paused) - { - if(pausetime) - { - map->SendPauseTime(pausetime); - pausetime=0; - } - fpscount+=1; - bool overheated=ship->IsOverHeated(); - int hullhits=ship->GetHullHits(); - int maxhullhits=ship->GetMaxHullHits(); - shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); - shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); - ship->Move(0,0); - x=ship->GetX(); - y=ship->GetY(); - dx=ship->GetDX(); - dy=ship->GetDY(); - angle=ship->GetAngle(); - speed=ship->GetSpeed(); - sx=ship->GetSectorX(); - sy=ship->GetSectorY(); - curslot=ship->GetCurWeaponSlot(); - aiunits=map->GetUnitCount(); - if (curslot.image) - { - if (strcmp(curslot.holdweapon.c_str(),"heatseeking")) aiunit=-1; - } - if (aiunit<aiunits && aiunit!=-1) - { - targetx=map->GetUnitX(aiunit); - targety=map->GetUnitY(aiunit); - } - else - { - targetx=0; - targety=0; - aiunit=-1; - map->SetTarget(aiunit); - } - Slock(); - SDL_FillRect(screen,0,0); - if (engage && speed<50) - { - ship->SetSpeed(speed+1); - } - if (engage && speed>=50) - { - engage=false; - } - if (disengage && speed>savespeed) - { - ship->SetSpeed(speed-1); - } - if (disengage && speed<=savespeed) - { - disengage=false; - ship->SetWarp(false); - } - speed=ship->GetSpeed(); - map->MoveBullets(); - map->MoveAI(x,y); - map->CheckSectors(sx, sy); - starx=(int)(-dx/10); - stary=(int)(-dy/10); - starx2=(int)(-dx/20); - stary2=(int)(-dy/20); - atwarp=ship->AtWarp(); - if (!atwarp) - { - stars->Display(starx, stary); - stars2->Display(starx2, stary2); - map->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); - if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); - savespeed=speed; - if (savespeed<0) { savespeed=0; } - } - else if (atwarp) - { - stars2->DisplayWarp(starx2, stary2, angle, (int)((float)speed/2.5)); - map->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); - if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); - stars->DisplayWarp(starx, stary, angle, (int)((float)speed/2.5)); - } - if (FPSSHOW) - { - sprintf(disp, "FPS: %d", fps); - drawString(font2, SCREEN_WIDTH-80, 10, disp, white); - } - map->DisplayMinimap(4,10,x,y,range); - sprintf(disp, "%d sectors", range); - centerString(font, 34, 80, "Sensor radius:", white); - centerString(font, 34, 90, disp, white); - ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); - map->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); - if (SDL_GetTicks()>=time+1000) - { - fps=fpscount; - fpscount=0; - time=SDL_GetTicks(); - } - Sulock(); - SDL_Flip(screen); - keys = SDL_GetKeyState(NULL); - // If the keys UP, DOWN, LEFT and RIGHT have been pressed - if(keys[fftinput->GetUp()]) - { - if (fpscount%2==0 && !atwarp && !engage && !disengage) - { - if (speed<ship->GetMaxSpeed()) - { - ship->SetSpeed(speed+1); - } - } - if (fpscount%2==0 && atwarp && !engage && !disengage) - { - if (speed<ship->GetMaxWarp()) - { - ship->SetSpeed(speed+1); - } - } - } - if(keys[fftinput->GetDown()]) - { - if (fpscount%2==0 && !atwarp && !engage && !disengage) - { - if (speed>-ship->GetMaxSpeed()) - { - ship->SetSpeed(speed-1); - } - } - if (fpscount%2==0 && atwarp && !engage && !disengage) - { - if (speed>50) - { - ship->SetSpeed(speed-1); - } - } - } - if(keys[fftinput->GetAllStop()]) - { - if (fpscount%2==0 && !atwarp) - { - if (speed>0) - { - ship->SetSpeed(speed-1); - } - if (speed<0) - { - ship->SetSpeed(speed+1); - } - } - } - if(keys[fftinput->GetLeft()]) - { - if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) - { - ship->Rotate(0); - turntime=SDL_GetTicks(); - } - else - { - if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) - { - ship->Rotate(0); - turntime=SDL_GetTicks(); - } - } - } - if(keys[fftinput->GetRight()]) - { - if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) - { - ship->Rotate(1); - turntime=SDL_GetTicks(); - } - else { - if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) - { - ship->Rotate(1); - turntime=SDL_GetTicks(); - } - } - } - if (SDL_GetTicks()>=checktime+2000) - { - //Check for victory and loss only once per 2 seconds - checktime=SDL_GetTicks(); - if (hullhits>=maxhullhits) done=GameOverBox(SCREEN_WIDTH,SCREEN_HEIGHT); - if (overheated) done=GameOverBox(SCREEN_WIDTH,SCREEN_HEIGHT); - if (mainScen->CheckVictory()) - { - std::string message="Congratulations! You finished Scenario "; - message+=mainScen->GetName(); - done=ExitToMenuBox(SCREEN_WIDTH,SCREEN_HEIGHT,message); - } - if (mainScen->CheckLoss()) - { - std::string message="Game Over. You failed to complete your objectives."; - done=ExitToMenuBox(SCREEN_WIDTH,SCREEN_HEIGHT,message); - } - } - SDL_framerateDelay(FPS); - lastpausetime=SDL_GetTicks(); - } - if (paused) - { - pausetime=SDL_GetTicks()-lastpausetime; - } - } - delete FPS; - return done; - } - --- 377,378 ---- Index: engine.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** engine.cpp 23 Aug 2005 09:56:44 -0000 1.4 --- engine.cpp 23 Aug 2005 21:18:06 -0000 1.5 *************** *** 15,19 **** --- 15,21 ---- { Log::WriteVerbose("Initializing Engine"); + showfps=false; running=false; + incontrol=false; mainship=0; mainscen=0; *************** *** 39,58 **** PyObject_SetAttrString(sysModule, "stdout", catchmodule); PyObject_SetAttrString(sysModule, "stderr", catchmodule); - - /* - PyRun_SimpleString( - "import fft\n" - "def MyFunc():\n" - "\treturn 1\n" - "fft.Victory=MyFunc\n" - ); - PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), - PyObject *pFunc = PyDict_GetItemString(pDict, "Victory"); - Log::WriteVerbose("ok so far"); - PyObject *test=PyObject_CallFunction(pFunc, 0); - if(PyObject_IsTrue(test)) Log::WriteVerbose("method is true"); - else Log::WriteVerbose("method is false"); - Log::WriteVerbose("got through!"); - */ } Engine::~Engine() --- 41,44 ---- *************** *** 122,132 **** return running; } void Engine::CleanUpGame() { running=false; char c[2048]; ! sprintf(c,"del sys.modules['%s']",mainmodule.c_str()); PyRun_SimpleString(c); - Py_XDECREF(mainModule); } void Engine::Render() --- 108,715 ---- return running; } + int Engine::InGameMenu() + { + Log::WriteVerbose("InGameMenu()"); + SDL_Event event; + SDL_Surface *screen=SDL_GetVideoSurface(); + int w=screen->w; + int h=screen->h; + SDL_Surface *bg = SDL_CreateRGBSurface(0, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); + SDL_Rect dest; + dest.x = 0; + dest.y = 0; + SDL_BlitSurface(screen, NULL, bg, &dest); + GUI *optionsGUI=new GUI; + optionsGUI->Init(); + optionsGUI->MakeWindow(60, 120, w-120, 220); + optionsGUI->MakeStatic(60,126,w-120,20,"Menu"); + int sControls=optionsGUI->MakeButton(100,160,w-200, "Controls"); + int sCancel=optionsGUI->MakeButton(100,280,200, "Back to Game"); + int sExit=optionsGUI->MakeButton(w-300,280,200, "Exit Game"); + + int done=0; + int getx, gety; + int click=-1; + while(!done) + { + Slock(); + while (SDL_PollEvent(&event)) + { + // an event was found + switch (event.type) { + // close button clicked + case SDL_QUIT: + done=-1; + break; + + // handle the keyboard + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_ESCAPE: + done=AskToQuitGame(w,h); + if (done==-1) done=1; + break; + default: + break; + } + break; + case SDL_MOUSEMOTION: + SDL_GetMouseState(&getx, &gety); + optionsGUI->SendMouseMotion(getx,gety); + break; + case SDL_MOUSEBUTTONDOWN: + SDL_GetMouseState(&getx, &gety); + click = optionsGUI->SendMouseClick(getx, gety); + break; + case SDL_MOUSEBUTTONUP: + SDL_GetMouseState(&getx, &gety); + if (click!=-1 && click==optionsGUI->SendMouseClick(getx, gety)) + { + SDL_FillRect(screen,0,0); + DrawIMG(bg,0,0); + optionsGUI->Draw(); + Sulock(); + SDL_Flip(screen); + if (click==sControls) + { + done=ControlChanging(w,h,bg,false); + if (done==1) done=0; + } + if (click==sCancel) + { + done=2; + } + if (click==sExit) + { + done=AskToQuitGame(w, h); + if (done==-1) done=1; + } + } + optionsGUI->UpdateButtons(); + break; + default: + break; + } + } + SDL_FillRect(screen,0,0); + DrawIMG(bg,0,0); + optionsGUI->Draw(); + Sulock(); + SDL_Flip(screen); + } + delete optionsGUI; + SDL_FreeSurface(bg); + if (done!=1 && done!=-1) done=0; + return done; + } + int Engine::MainLoop() + { + Log::WriteVerbose("Main Loop begin"); + SDL_Event event; + SDL_Surface *screen=SDL_GetVideoSurface(); + SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; + SDL_Color yellow = { 0xFF, 0xFF, 0x00, 0 }; + SDL_Color black = { 0x00, 0x00, 0x00, 0 }; + int done=0; + char disp[100]; + //int getx, gety; + //int click=-1; + //int ingameok=gui2->GetButtonID(150,300,SCREEN_WIDTH-300,"Go!"); + int x, y, angle, speed, starx, stary, starx2, stary2, shipx, shipy, sx, sy, savespeed, range; + int fps, fpscount; + int targetx=0; + int targety=0; + bool engage, disengage; + angle=ship->GetAngle(); + x=ship->GetX(); + y=ship->GetY(); + double dx=ship->GetDX(); + double dy=ship->GetDY(); + int maxspeed=ship->GetMaxSpeed(); + speed=ship->GetSpeed(); + bool atwarp=ship->AtWarp(); + starx=0; + stary=0; + starx2=0; + stary2=0; + fpscount=0; + int aiunit=-1; + int aiunits=mainmap->GetUnitCount(); + fps=0; + range=3; + savespeed=0; + __ship_slot curslot=ship->GetCurWeaponSlot(); + engage=false; + disengage=false; + bool paused=false; + //setup for GUI stuff + shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); + shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); + starx=(int)(-dx/10); + stary=(int)(-dy/10); + starx2=(int)(-dx/20); + stary2=(int)(-dy/20); + sx=ship->GetSectorX(); + sy=ship->GetSectorY(); + mainmap->SetTarget(aiunit); + mainmap->CheckSectors(sx, sy); + float zoom=0.5; + //Log::WriteVerbose("Variables set, displaying opening message"); + TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); + TTF_Font *font14=this->GetFont("font14"); + TTF_Font *font10=this->GetFont("font10"); + /* + while(!done) + { + Slock(); + SDL_FillRect(screen,0,0); + stars->Display(starx, stary); + stars2->Display(starx2, stary2); + mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); + ship->Display(shipx,shipy); + mainmap->DisplayMinimap(4,10,x,y,range); + sprintf(disp, "%d sectors", range); + centerString(font, 34, 80, "Sensor radius:", white); + centerString(font, 34, 90, disp, white); + ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); + mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); + while (SDL_PollEvent(&event)) + { + switch (event.type) { + // close button clicked + case SDL_QUIT: + return -1; + break; + + // handle the keyboard + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_RETURN: + done = 1; + break; + case SDLK_ESCAPE: + done = 1; + break; + default: + break; + } + break; + case SDL_MOUSEMOTION: + SDL_GetMouseState(&getx, &gety); + gui2->SendMouseMotion(getx,gety); + break; + case SDL_MOUSEBUTTONDOWN: + SDL_GetMouseState(&getx, &gety); + click = gui2->SendMouseClick(getx, gety); + break; + case SDL_MOUSEBUTTONUP: + SDL_GetMouseState(&getx, &gety); + if (click!=-1 && click==gui2->SendMouseClick(getx, gety)) + { + if (click==ingameok) + { + gui2->Draw(); + gui2->UpdateButtons(); + Sulock(); + SDL_Flip(screen); + done=1; + } + } + gui2->UpdateButtons(); + break; + default: + break; + } + } + gui2->Draw(); + Sulock(); + SDL_Flip(screen); + } + done=0; + */ + FPSmanager *FPS = new FPSmanager; + SDL_initFramerate(FPS); + SDL_setFramerate(FPS, 60); + Uint32 time=SDL_GetTicks(); + Uint32 pausetime=0; + Uint32 lastpausetime=SDL_GetTicks(); + Uint32 turntime=SDL_GetTicks(); + Uint32 checktime=SDL_GetTicks(); + char disppause[100]; + sprintf(disppause, "Press '%s' to unpause", maininput->GetPauseStr().c_str()); + Log::WriteVerbose("Entering gameplay loop"); + while(!done) + { + while (SDL_PollEvent(&event)) + { + if(event.type == SDL_QUIT) { done=-1; } + else if(event.type == SDL_ACTIVEEVENT) + { + if(event.active.state==SDL_APPACTIVE || event.active.state==SDL_APPINPUTFOCUS) + { + if(event.active.gain==0) + { + paused=true; + Log::WriteVerbose("Game was paused because the window lost focus"); + if (paused) + { + centerString(font14, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2-8-1, "Game Paused", black); + centerString(font14, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-8, "Game Paused", yellow); + centerString(font14, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2+8-1, disppause, black); + centerString(font14, SCREEN_WIDTH/2, SCREEN_HEIGHT/2+8, disppause, yellow); + SDL_Flip(screen); + } + } + } + } + else if(event.type == SDL_KEYDOWN) + { + if(event.key.keysym.sym == maininput->GetCancel()) + { + done = this->InGameMenu(); + } + else if((event.key.keysym.sym == maininput->GetWarp1() || event.key.keysym.sym == maininput->GetWarp2()) && !paused && incontrol) + { + if (ship->AtWarp() && ship->WarpEnabled()) { engage=false; disengage=true; } + else if (!ship->AtWarp() && ship->WarpEnabled()) { disengage=false; engage=true; ship->SetWarp(true); } + } + else if((event.key.keysym.sym == maininput->GetFire1() || event.key.keysym.sym == maininput->GetFire2()) && !paused && incontrol) + { + if (!ship->AtWarp()) + { + int tempspeed=speed+maxspeed; + if (speed<0) tempspeed=maxspeed; + //mainmap->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, aiunit, curslot.id); + if (curslot.image) + { + mainmap->SpawnBullet(ship->GetShootX(), ship->GetShootY(), tempspeed, angle, curslot.fn, curslot.fpk, curslot.image, aiunit, curslot.id); + Mix_PlayChannel(0,shot,0); + } + } + } + else if(event.key.keysym.sym == maininput->GetMiniMapZoomIn() && !paused && incontrol) + { + if (range*2 < 20) { range=range*2; } + } + else if(event.key.keysym.sym == maininput->GetMiniMapZoomOut() && !paused && incontrol) + { + if (range/2 > 1) { range=range/2; } + } + else if(event.key.keysym.sym == maininput->GetZoomIn() && !paused && incontrol) + { + if (zoom+0.25 <= 1) + { + zoom+=0.25; + Log::WriteVerbose("Zooming ship"); + ship->SetZoom(zoom); + Log::WriteVerbose("Loading Ship images"); + ship->ReloadImages(); + Log::WriteVerbose("Zooming map"); + mainmap->SetZoom(zoom); + } + } + else if(event.key.keysym.sym == maininput->GetZoomOut() && !paused && incontrol) + { + if (zoom-0.25 >=0.5) + { + zoom-=0.25; + Log::WriteVerbose("Zooming ship"); + ship->SetZoom(zoom); + Log::WriteVerbose("Loading Ship images"); + ship->ReloadImages(); + Log::WriteVerbose("Zooming map"); + mainmap->SetZoom(zoom); + } + } + else if(event.key.keysym.sym == maininput->GetPrevWeapon() && !paused && incontrol) + { + ship->PrevWeapon(); + if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; + else aiunit=0; + mainmap->SetTarget(aiunit); + } + else if(event.key.keysym.sym == maininput->GetNextWeapon() && !paused && incontrol) + { + ship->NextWeapon(); + if (strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) aiunit=-1; + else aiunit=0; + mainmap->SetTarget(aiunit); + } + else if(event.key.keysym.sym == maininput->GetDock() && !paused && incontrol) + { + mainmap->Dock(x,y); + if(aiunit==-1 && !strcmp(ship->GetCurWeaponSlot().holdweapon.c_str(),"heatseeking")) + { + aiunit=0; + mainmap->SetTarget(aiunit); + } + } + else if(event.key.keysym.sym == maininput->GetPrevTarget() && !paused && aiunit!=-1 && incontrol) + { + if (aiunit+1<aiunits) aiunit++; + else aiunit=0; + mainmap->SetTarget(aiunit); + } + else if(event.key.keysym.sym == maininput->GetNextTarget() && !paused && aiunit!=-1 && incontrol) + { + if (aiunit-1>=0) aiunit--; + else aiunit=aiunits-1; + mainmap->SetTarget(aiunit); + } + else if(event.key.keysym.sym == maininput->GetPause()) + { + paused=!paused; + if (paused) + { + centerString(font14, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2-8-1, "Game Paused", black); + centerString(font14, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-8, "Game Paused", yellow); + centerString(font14, SCREEN_WIDTH/2-1, SCREEN_HEIGHT/2+8-1, disppause, black); + centerString(font14, SCREEN_WIDTH/2, SCREEN_HEIGHT/2+8, disppause, yellow); + SDL_Flip(screen); + } + } + } + } + if (!paused) + { + if(pausetime) + { + mainmap->SendPauseTime(pausetime); + pausetime=0; + } + fpscount+=1; + bool overheated=ship->IsOverHeated(); + int hullhits=ship->GetHullHits(); + int maxhullhits=ship->GetMaxHullHits(); + shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); + shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); + ship->Move(0,0); + x=ship->GetX(); + y=ship->GetY(); + dx=ship->GetDX(); + dy=ship->GetDY(); + angle=ship->GetAngle(); + speed=ship->GetSpeed(); + sx=ship->GetSectorX(); + sy=ship->GetSectorY(); + curslot=ship->GetCurWeaponSlot(); + aiunits=mainmap->GetUnitCount(); + if (curslot.image) + { + if (strcmp(curslot.holdweapon.c_str(),"heatseeking")) aiunit=-1; + } + if (aiunit<aiunits && aiunit!=-1) + { + targetx=mainmap->GetUnitX(aiunit); + targety=mainmap->GetUnitY(aiunit); + } + else + { + targetx=0; + targety=0; + aiunit=-1; + mainmap->SetTarget(aiunit); + } + Slock(); + SDL_FillRect(screen,0,0); + if (engage && speed<50) + { + ship->SetSpeed(speed+1); + } + if (engage && speed>=50) + { + engage=false; + } + if (disengage && speed>savespeed) + { + ship->SetSpeed(speed-1); + } + if (disengage && speed<=savespeed) + { + disengage=false; + ship->SetWarp(false); + } + speed=ship->GetSpeed(); + mainmap->MoveBullets(); + mainmap->MoveAI(x,y); + mainmap->CheckSectors(sx, sy); + atwarp=ship->AtWarp(); + if (!atwarp) + { + int i; + for(i=0; i<(int)starfields.size(); i++) + { + starx=(int)(-dx/starfields[i].factor); + stary=(int)(-dy/starfields[i].factor); + starfields[i].stars->Display(starx, stary); + } + mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); + if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); + savespeed=speed; + if (savespeed<0) { savespeed=0; } + } + else if (atwarp) + { + int i; + for(i=0; i<(int)starfields.size(); i++) + { + if (!starfields[i].above) + { + starx=(int)(-dx/starfields[i].factor); + stary=(int)(-dy/starfields[i].factor); + starfields[i].stars->DisplayWarp(starx, stary, angle, (int)((float)speed/2.5)); + } + } + mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); + if (hullhits<maxhullhits && !overheated) ship->Display(shipx,shipy); + for(i=0; i<(int)starfields.size(); i++) + { + if (starfields[i].above) + { + starx=(int)(-dx/starfields[i].factor); + stary=(int)(-dy/starfields[i].factor); + starfields[i].stars->DisplayWarp(starx, stary, angle, (int)((float)speed/2.5)); + } + } + } + if (showfps) + { + sprintf(disp, "FPS: %d", fps); + drawString(font14, SCREEN_WIDTH-80, 10, disp, white); + } + if (incontrol) + { + mainmap->DisplayMinimap(4,10,x,y,range); + sprintf(disp, "%d sectors", range); + centerString(font10, 34, 80, "Sensor radius:", white); + centerString(font10, 34, 90, disp, white); + ship->StatusDisplay(SCREEN_WIDTH-125, SCREEN_HEIGHT-195, 120, 190, font9); + mainmap->DisplayAITarget(5, SCREEN_HEIGHT-125,120,120,font9,targetx,targety); + } + if (SDL_GetTicks()>=time+1000) + { + fps=fpscount; + fpscount=0; + time=SDL_GetTicks(); + } + Sulock(); + SDL_Flip(screen); + Uint8* keys = SDL_GetKeyState(NULL); + // If the keys UP, DOWN, LEFT and RIGHT have been pressed + if(keys[maininput->GetUp()] && incontrol) + { + if (fpscount%2==0 && !atwarp && !engage && !disengage) + { + if (speed<ship->GetMaxSpeed()) + { + ship->SetSpeed(speed+1); + } + } + if (fpscount%2==0 && atwarp && !engage && !disengage) + { + if (speed<ship->GetMaxWarp()) + { + ship->SetSpeed(speed+1); + } + } + } + if(keys[maininput->GetDown()] && incontrol) + { + if (fpscount%2==0 && !atwarp && !engage && !disengage) + { + if (speed>-ship->GetMaxSpeed()) + { + ship->SetSpeed(speed-1); + } + } + if (fpscount%2==0 && atwarp && !engage && !disengage) + { + if (speed>50) + { + ship->SetSpeed(speed-1); + } + } + } + if(keys[maininput->GetAllStop()] && incontrol) + { + if (fpscount%2==0 && !atwarp) + { + if (speed>0) + { + ship->SetSpeed(speed-1); + } + if (speed<0) + { + ship->SetSpeed(speed+1); + } + } + } + if(keys[maininput->GetLeft()] && incontrol) + { + if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) + { + ship->Rotate(0); + turntime=SDL_GetTicks(); + } + else + { + if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) + { + ship->Rotate(0); + turntime=SDL_GetTicks(); + } + } + } + if(keys[maininput->GetRight()] && incontrol) + { + if (!atwarp && SDL_GetTicks()>=turntime+ship->GetTurnDelay()) + { + ship->Rotate(1); + turntime=SDL_GetTicks(); + } + else { + if (SDL_GetTicks()>=turntime+ship->GetWarpTurnDelay()) + { + ship->Rotate(1); + turntime=SDL_GetTicks(); + } + } + } + if (SDL_GetTicks()>=checktime+2000) + { + //Check for victory and loss only once per 2 seconds + checktime=SDL_GetTicks(); + if (hullhits>=maxhullhits) done=GameOverBox(SCREEN_WIDTH,SCREEN_HEIGHT); + if (overheated) done=GameOverBox(SCREEN_WIDTH,SCREEN_HEIGHT); + if (mainscen->CheckVictory()) + { + std::string message="Congratulations! You finished Scenario "; + message+=mainscen->GetName(); + done=ExitToMenuBox(SCREEN_WIDTH,SCREEN_HEIGHT,message); + } + if (mainscen->CheckLoss()) + { + std::string message="Game Over. You failed to complete your objectives."; + done=ExitToMenuBox(SCREEN_WIDTH,SCREEN_HEIGHT,message); + } + } + SDL_framerateDelay(FPS); + lastpausetime=SDL_GetTicks(); + } + if (paused) + { + pausetime=SDL_GetTicks()-lastpausetime; + } + } + delete FPS; + TTF_CloseFont(font9); + return done; + } void Engine::CleanUpGame() { running=false; char c[2048]; ! sprintf(c,"if '%s' in sys.modules:\n\tdel sys.modules['%s']",mainmodule.c_str(),mainmodule.c_str()); PyRun_SimpleString(c); } void Engine::Render() *************** *** 175,178 **** --- 758,765 ---- mainship=ship; } + void Engine::InControl(bool control) + { + incontrol=control; + } Scenario *Engine::GetMainScenario() { *************** *** 210,214 **** void Engine::AddFont(std::string name, TTF_Font *font) { ! if(this->GetFont(name)) { FFTFont fftfont; --- 797,801 ---- void Engine::AddFont(std::string name, TTF_Font *font) { ! if(!this->GetFont(name)) { FFTFont fftfont; *************** *** 331,333 **** --- 918,924 ---- starfields.push_back(fftstars); } + void Engine::ShowFPS() + { + showfps=true; + } Index: graphics.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/graphics.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** graphics.cpp 23 Aug 2005 09:56:44 -0000 1.2 --- graphics.cpp 23 Aug 2005 21:18:06 -0000 1.3 *************** *** 4,8 **** void CenterWindow() { - SDL_Surface *screen=SDL_GetVideoSurface(); SDL_SysWMinfo info; --- 4,7 ---- *************** *** 10,13 **** --- 9,13 ---- if ( SDL_GetWMInfo(&info) > 0 ) { #ifdef __unix + SDL_Surface *screen=SDL_GetVideoSurface(); if ( info.subsystem == SDL_SYSWM_X11 ) { info.info.x11.lock_func(); Index: guiapply.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/guiapply.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** guiapply.h 23 Aug 2005 09:56:44 -0000 1.3 --- guiapply.h 23 Aug 2005 21:18:06 -0000 1.4 *************** *** 2,14 **** #define __GUIAPPLY_H__ - #include "engine.h" #include "gui.h" - #include "graphics.h" - #include "input.h" - #include "fftfile.h" - - extern Engine *engine; - extern FFTInput *fftinput; - extern Preferences *prefs; int RunStartingGUI(int w, int h); --- 2,6 ---- *************** *** 17,20 **** --- 9,13 ---- int ChangeControl(int w, int h, SDL_Surface *bg=0, bool fill=true); int AskToQuit(int SCREEN_WIDTH, int SCREEN_HEIGHT); + int AskToQuitGame(int SCREEN_WIDTH, int SCREEN_HEIGHT); int MsgBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message); int YesNoBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message); Index: engine.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** engine.h 23 Aug 2005 09:56:44 -0000 1.4 --- engine.h 23 Aug 2005 21:18:06 -0000 1.5 *************** *** 7,11 **** #include "SDL_mixer.h" #include "SDL_ttf.h" ! #include "gui.h" #include "log.h" #include "scenario.h" --- 7,14 ---- #include "SDL_mixer.h" #include "SDL_ttf.h" ! #include "SDL_framerate.h" ! ! #include "guiapply.h" ! #include "graphics.h" #include "log.h" #include "scenario.h" *************** *** 46,49 **** --- 49,54 ---- void Quit(); bool StartGame(); + int InGameMenu(); + int MainLoop(); void CleanUpGame(); void Render(); *************** *** 51,54 **** --- 56,60 ---- Unit *GetMainShip(); void SetMainShip(Unit *ship); + void InControl(bool control); Scenario *GetMainScenario(); void SetMainScenario(Scenario *scen); *************** *** 66,71 **** --- 72,80 ---- void AddSurface(std::string name, SDL_Surface *surface); void AddStarfield(StarField *stars, bool above, int factor); + void ShowFPS(); private: + bool showfps; bool running; + bool incontrol; std::string mainmodule; Unit *mainship; Index: guiapply.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/guiapply.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** guiapply.cpp 23 Aug 2005 09:56:44 -0000 1.3 --- guiapply.cpp 23 Aug 2005 21:18:06 -0000 1.4 *************** *** 1,6 **** - #include "guiapply.h" #include <string.h> #include <sstream> #include <iostream> int RunStartingGUI(int w, int h) --- 1,14 ---- #include <string.h> #include <sstream> #include <iostream> + #include "engine.h" + #include "guiapply.h" + #include "graphics.h" + #include "input.h" + #include "fftfile.h" + + extern Engine *engine; + extern FFTInput *fftinput; + extern Preferences *prefs; int RunStartingGUI(int w, int h) *************** *** 774,777 **** --- 782,879 ---- return done; } + int AskToQuitGame(int SCREEN_WIDTH, int SCREEN_HEIGHT) + { + SDL_Event event; + SDL_Surface *screen=SDL_GetVideoSurface(); + SDL_Surface *bg = SDL_CreateRGBSurface(0, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); + SDL_Rect dest; + dest.x = 0; + dest.y = 0; + SDL_BlitSurface(screen, NULL, bg, &dest); + GUI *gui3=new GUI; + gui3->Init(); + gui3->MakeWindow(120,200,SCREEN_WIDTH-240,110); + gui3->MakeStatic(30,206,SCREEN_WIDTH-60,20,"Are you sure you want to quit this game?"); + gui3->MakeButton(150,270,40,"Yes"); + gui3->MakeButton(SCREEN_WIDTH-190,270,40,"No"); + int yesButton=gui3->GetButtonID(150,270,40,"Yes"); + int noButton=gui3->GetButtonID(SCREEN_WIDTH-190,270,40,"No"); + int done=0; + int getx, gety; + int click=-1; + while(!done) + { + Slock(); + while (SDL_PollEvent(&event)) + { + // an event was found + switch (event.type) { + // close button clicked + case SDL_QUIT: + delete gui3; + SDL_FreeSurface(bg); + engine->Quit(); + break; + + // handle the keyboard + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_RETURN: + done = 1; + break; + default: + break; + } + break; + case SDL_MOUSEMOTION: + SDL_GetMouseState(&getx, &gety); + gui3->SendMouseMotion(getx,gety); + break; + case SDL_MOUSEBUTTONDOWN: + SDL_GetMouseState(&getx, &gety); + click = gui3->SendMouseClick(getx, gety); + break; + case SDL_MOUSEBUTTONUP: + SDL_GetMouseState(&getx, &gety); + if (click!=-1 && click==gui3->SendMouseClick(getx, gety)) + { + if (click==yesButton) + { + SDL_FillRect(screen,0,0); + DrawIMG(bg,0,0); + gui3->Draw(); + Sulock(); + SDL_Flip(screen); + SDL_Delay(100); + done=-1; + } + if (click==noButton) + { + SDL_FillRect(screen,0,0); + DrawIMG(bg,0,0); + gui3->Draw(); + Sulock(); + SDL_Flip(screen); + SDL_Delay(100); + done=1; + } + } + gui3->UpdateButtons(); + break; + default: + break; + } + } + SDL_FillRect(screen,0,0); + DrawIMG(bg,0,0); + gui3->Draw(); + Sulock(); + SDL_Flip(screen); + } + delete gui3; + SDL_FreeSurface(bg); + if (done!=-1) done=0; + return done; + } int MsgBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message) { Index: py_baselib.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** py_baselib.cpp 23 Aug 2005 09:56:44 -0000 1.4 --- py_baselib.cpp 23 Aug 2005 21:18:06 -0000 1.5 *************** *** 4,7 **** --- 4,9 ---- extern int SCREEN_HEIGHT; + extern Engine *engine; + PyMethodDef fftMethods[] = { |
From: TomT64 <to...@us...> - 2005-08-23 09:56:56
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15827/src Modified Files: engine.cpp engine.h fftfile.cpp graphics.cpp graphics.h guiapply.cpp guiapply.h log.cpp log.h main.cpp map.cpp map.h mapobject.cpp py_baselib.cpp py_baselib.h scenario.cpp shop.cpp units.cpp Log Message: More scripting code, and added verbose option to Log and commandline options Index: engine.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** engine.h 23 Aug 2005 03:40:09 -0000 1.3 --- engine.h 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 26,29 **** --- 26,30 ---- StarField *stars; bool above; + int factor; }; struct FFTSound *************** *** 44,49 **** ~Engine(); void Quit(); ! void StartGame(); void CleanUpGame(); void SetMainModule(std::string modulename); Unit *GetMainShip(); --- 45,51 ---- ~Engine(); void Quit(); ! bool StartGame(); void CleanUpGame(); + void Render(); void SetMainModule(std::string modulename); Unit *GetMainShip(); *************** *** 63,67 **** SDL_Surface *GetSurface(std::string name); void AddSurface(std::string name, SDL_Surface *surface); ! void AddStarfield(StarField *stars, bool above); private: bool running; --- 65,69 ---- SDL_Surface *GetSurface(std::string name); void AddSurface(std::string name, SDL_Surface *surface); ! void AddStarfield(StarField *stars, bool above, int factor); private: bool running; Index: units.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/units.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** units.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- units.cpp 23 Aug 2005 09:56:44 -0000 1.3 *************** *** 685,689 **** this->RemoveWeaponFromSlot(slotid); this->NextWeapon(); ! Log::Write("Removed and changed weapon"); } } --- 685,689 ---- this->RemoveWeaponFromSlot(slotid); this->NextWeapon(); ! Log::WriteVerbose("Removed and changed weapon"); } } *************** *** 1089,1096 **** void Unit::FPK_NewImages(std::string fpk, std::string imagename) { ! Log::Write("FPK_NewImages: Loading new image (%s) from fpk %s",imagename.c_str(),fpk.c_str()); usingfpk=fpk; imgload=imagename; ! Log::Write("FPK_NewImages: Freeing existing images"); FreeImages(); if(hasShield) --- 1089,1096 ---- void Unit::FPK_NewImages(std::string fpk, std::string imagename) { ! Log::WriteVerbose("FPK_NewImages: Loading new image (%s) from fpk %s",imagename.c_str(),fpk.c_str()); usingfpk=fpk; imgload=imagename; ! Log::WriteVerbose("FPK_NewImages: Freeing existing images"); FreeImages(); if(hasShield) *************** *** 1104,1111 **** hasShield=false; } ! Log::Write("FPK_NewImages: Loading new images"); LoadImages(0, 71); int i; ! Log::Write("FPK_NewImages: Making new bitmasks"); for (i=0; i<UNITS_NUM_FRAMES; i++) { --- 1104,1111 ---- hasShield=false; } ! Log::WriteVerbose("FPK_NewImages: Loading new images"); LoadImages(0, 71); int i; ! Log::WriteVerbose("FPK_NewImages: Making new bitmasks"); for (i=0; i<UNITS_NUM_FRAMES; i++) { *************** *** 1127,1131 **** if (end<0) { end=0; } if (start<0) { start=0; } ! Log::Write("Unit::LoadImages: Loading base image (%s) from fpk %s",imgload.c_str(),usingfpk.c_str()); temp=FPK_LoadIMG(usingfpk, imgload); if (dispimg) --- 1127,1131 ---- if (end<0) { end=0; } if (start<0) { start=0; } ! Log::WriteVerbose("Unit::LoadImages: Loading base image (%s) from fpk %s",imgload.c_str(),usingfpk.c_str()); temp=FPK_LoadIMG(usingfpk, imgload); if (dispimg) *************** *** 1134,1149 **** dispimg=0; } ! Log::Write("Unit::LoadImages: Setting display image"); dispimg=rotozoomSurface(temp, 0, 0.5, SMOOTH); if (cr>0 || cg>0 || cb>0) { ! Log::Write("Unit::LoadImages: Colorizing images"); ColorizeSurface(temp, cr, cg, cb); ColorizeSurface(dispimg, cr, cg, cb); } ! Log::Writen("Unit::LoadImages: Freeing images and reloading: "); for (i=start; i<=end; i++) { ! Log::Writen("%d, ",i); if (image[i]) { --- 1134,1149 ---- dispimg=0; } ! Log::WriteVerbose("Unit::LoadImages: Setting display image"); dispimg=rotozoomSurface(temp, 0, 0.5, SMOOTH); if (cr>0 || cg>0 || cb>0) { ! Log::WriteVerbose("Unit::LoadImages: Colorizing images"); ColorizeSurface(temp, cr, cg, cb); ColorizeSurface(dispimg, cr, cg, cb); } ! Log::WriteVerbosen("Unit::LoadImages: Freeing images and reloading: "); for (i=start; i<=end; i++) { ! Log::WriteVerbosen("%d, ",i); if (image[i]) { *************** *** 1153,1160 **** image[i]=rotozoomSurface(temp, 360-i*angleinc, zoom, SMOOTH); } ! Log::Writen("\n"); if (hasShield) { ! Log::Write("Loading shield"); SDL_FreeSurface(temp); temp=0; --- 1153,1160 ---- image[i]=rotozoomSurface(temp, 360-i*angleinc, zoom, SMOOTH); } ! Log::WriteVerbosen("\n"); if (hasShield) { ! Log::WriteVerbose("Loading shield"); SDL_FreeSurface(temp); temp=0; Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.cpp 23 Aug 2005 03:40:09 -0000 1.4 --- main.cpp 23 Aug 2005 09:56:44 -0000 1.5 *************** *** 103,106 **** --- 103,110 ---- Log::Init("fft.log"); } + if (!strcmp(argv[i],"-verbose")) + { + Log::EnableVerbose(); + } } } *************** *** 115,129 **** if (!init) { ! Log::Write("Failed to initialize PHYSFS. Reason: %s",PHYSFS_getLastError()); exit(1); } ! Log::Write("PHYSFS initialized successfully"); char **i; for (i = PHYSFS_getSearchPath(); *i != NULL; i++) ! Log::Write("[%s] is in the search path.at the beginning of execution", *i); PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 0); //fpk dir PHYSFS_setWriteDir(PHYSFS_getBaseDir()); ! Log::Write("Loading Preferences"); prefs=new Preferences("prefs"); delete fftinput; --- 119,133 ---- if (!init) { ! Log::WriteVerbose("Failed to initialize PHYSFS. Reason: %s",PHYSFS_getLastError()); exit(1); } ! Log::WriteVerbose("PHYSFS initialized successfully"); char **i; for (i = PHYSFS_getSearchPath(); *i != NULL; i++) ! Log::WriteVerbose("[%s] is in the search path.at the beginning of execution", *i); PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 0); //fpk dir PHYSFS_setWriteDir(PHYSFS_getBaseDir()); ! Log::WriteVerbose("Loading Preferences"); prefs=new Preferences("prefs"); delete fftinput; *************** *** 135,147 **** if(TTF_Init()==-1) { ! Log::Write("TTF_Init: %s", TTF_GetError()); exit(2); } ! Log::Write("SDL_ttf initialized successfully"); // load font font=LoadTTF("fonts/arial.ttf", 10); if(!font) { ! Log::Write("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } --- 139,151 ---- if(TTF_Init()==-1) { ! Log::WriteVerbose("TTF_Init: %s", TTF_GetError()); exit(2); } ! Log::WriteVerbose("SDL_ttf initialized successfully"); // load font font=LoadTTF("fonts/arial.ttf", 10); if(!font) { ! Log::WriteVerbose("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } *************** *** 149,172 **** font2=LoadTTF("fonts/arial.ttf", 14); if(!font2) { ! Log::Write("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } engine->AddFont("font14",font2); ! Log::Write("Main Fonts loaded"); /* initialize SDL */ #ifdef DEBUG if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) { ! Log::Write("Could not initialize SDL: %s",SDL_GetError()); return -1; } #else if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0 ) { ! Log::Write("Could not initialize SDL: %s",SDL_GetError()); return -1; } #endif ! Log::Write("SDL initialized successfully"); //atexit(SDL_Quit); --- 153,176 ---- font2=LoadTTF("fonts/arial.ttf", 14); if(!font2) { ! Log::WriteVerbose("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } engine->AddFont("font14",font2); ! Log::WriteVerbose("Main Fonts loaded"); /* initialize SDL */ #ifdef DEBUG if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) { ! Log::WriteVerbose("Could not initialize SDL: %s",SDL_GetError()); return -1; } #else if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0 ) { ! Log::WriteVerbose("Could not initialize SDL: %s",SDL_GetError()); return -1; } #endif ! Log::WriteVerbose("SDL initialized successfully"); //atexit(SDL_Quit); *************** *** 177,186 **** engine->AddSurface("main icon",icon); SDL_WM_SetIcon(icon, NULL); ! Log::Write("Icon and caption in place"); /* create window */ screen = SDL_SetVideoMode(400, 300, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); //CenterWindow(); ! Log::Write("Video mode set and centered"); SDL_Surface *bg = LoadIMG("gfx/startupbg.png"); --- 181,190 ---- engine->AddSurface("main icon",icon); SDL_WM_SetIcon(icon, NULL); ! Log::WriteVerbose("Icon and caption in place"); /* create window */ screen = SDL_SetVideoMode(400, 300, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); //CenterWindow(); ! Log::WriteVerbose("Video mode set and centered"); SDL_Surface *bg = LoadIMG("gfx/startupbg.png"); *************** *** 188,192 **** DrawIMG(bg,0,0); SDL_Flip(screen); ! Log::Write("Splash screen displayed"); stars = new StarField; --- 192,196 ---- DrawIMG(bg,0,0); SDL_Flip(screen); ! Log::WriteVerbose("Splash screen displayed"); stars = new StarField; *************** *** 194,200 **** stars->Init(SCREEN_WIDTH, SCREEN_HEIGHT); stars2->Init(SCREEN_WIDTH, SCREEN_HEIGHT); ! engine->AddStarfield(stars, false); ! engine->AddStarfield(stars2, true); ! Log::Write("Beginning warp stars initialized"); char **k; --- 198,204 ---- stars->Init(SCREEN_WIDTH, SCREEN_HEIGHT); stars2->Init(SCREEN_WIDTH, SCREEN_HEIGHT); ! engine->AddStarfield(stars, false, 10); ! engine->AddStarfield(stars2, true, 20); ! Log::WriteVerbose("Beginning warp stars initialized"); char **k; *************** *** 211,229 **** } PHYSFS_freeList(fpklist); ! Log::Write("All FPKs placed in search path"); ship = new Unit; ! ship->Init(0, 0, "gfx/ship/ship.png","base.fpk",(float)0.1); engine->SetMainShip(ship); ! Log::Write("Main ship initialized"); map = new Map; map->Init(1); engine->SetMap(map); ! Log::Write("Map initialized"); if(Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 2048) < 0) { ! Log::Write("Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s", SDL_GetError()); } shot = LoadSound("sound/shoot.wav"); --- 215,233 ---- } PHYSFS_freeList(fpklist); ! Log::WriteVerbose("All FPKs placed in search path"); ship = new Unit; ! ship->Init(0, 0, "gfx/ship/ship.png","base.fpk",(float)0.01); engine->SetMainShip(ship); ! Log::WriteVerbose("Main ship initialized"); map = new Map; map->Init(1); engine->SetMap(map); ! Log::WriteVerbose("Map initialized"); if(Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 2048) < 0) { ! Log::WriteVerbose("Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s", SDL_GetError()); } shot = LoadSound("sound/shoot.wav"); *************** *** 231,235 **** engine->AddSound("shot", shot); engine->AddSound("explode", explode); ! Log::Write("Audio initialized and sounds loaded"); gui2=new GUI; --- 235,239 ---- engine->AddSound("shot", shot); engine->AddSound("explode", explode); ! Log::WriteVerbose("Audio initialized and sounds loaded"); gui2=new GUI; *************** *** 259,294 **** else screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); CenterWindow(); ! Log::Writen("Main window set to 640x480 "); ! if (fullscreen) Log::Writen("at fullscreen "); ! else Log::Writen("at windowed "); ! if (software) Log::Writen("software mode"); ! else Log::Writen("hardware mode"); ! Log::Write(" and centered"); int done=0; int maintemp=0; int GUIresult; ! Log::Write("Proceeding to main loop"); while(!done) { GUIresult=RunStartingGUI(SCREEN_WIDTH, SCREEN_HEIGHT); ! Log::Write("Option from Starting GUI selected"); if (GUIresult==-1) { done=1; ! Log::Write("Exiting game"); } if (GUIresult==2) { bool goahead=false; ! Log::Write("Entering New Game"); goahead=LoadScenario(); if (goahead) { ! Log::Write("Proceeding to main game play"); ! engine->StartGame(); engine->CleanUpGame(); ! //maintemp=mainLoop(); ! Log::Write("Main gameplay exited"); if (maintemp==-1) done=1; } --- 263,298 ---- else screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); CenterWindow(); ! Log::WriteVerbosen("Main window set to 640x480 "); ! if (fullscreen) Log::WriteVerbosen("at fullscreen "); ! else Log::WriteVerbosen("at windowed "); ! if (software) Log::WriteVerbosen("software mode"); ! else Log::WriteVerbosen("hardware mode"); ! Log::WriteVerbose(" and centered"); int done=0; int maintemp=0; int GUIresult; ! Log::WriteVerbose("Proceeding to main loop"); while(!done) { GUIresult=RunStartingGUI(SCREEN_WIDTH, SCREEN_HEIGHT); ! Log::WriteVerbose("Option from Starting GUI selected"); if (GUIresult==-1) { done=1; ! Log::WriteVerbose("Exiting game"); } if (GUIresult==2) { bool goahead=false; ! Log::WriteVerbose("Entering New Game"); goahead=LoadScenario(); if (goahead) { ! Log::WriteVerbose("Proceeding to main game play"); ! bool init=engine->StartGame(); ! if (init) maintemp=mainLoop(); engine->CleanUpGame(); ! Log::WriteVerbose("Main gameplay exited"); if (maintemp==-1) done=1; } *************** *** 304,308 **** static int AskToQuitGame() { ! Log::Write("AskToQuitGame()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 308,312 ---- static int AskToQuitGame() { ! Log::WriteVerbose("AskToQuitGame()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 399,403 **** static int InGameMenu() { ! Log::Write("InGameMenu()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 403,407 ---- static int InGameMenu() { ! Log::WriteVerbose("InGameMenu()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 499,510 **** { //bool goahead=false; ! Log::Write("LoadScenario()"); ! Log::Write("Entering Scenario selection"); std::string scenselect=ChooseScenario(); if (!strcmp(scenselect.c_str(),"")) return false; ! Log::Write("Scenario Selection is %s",scenselect.c_str()); delete mainScen; mainScen = new Scenario(); ! Log::Write("Reading Scenario information"); engine->SetMainModule(scenselect); done=1; --- 503,514 ---- { //bool goahead=false; ! Log::WriteVerbose("LoadScenario()"); ! Log::WriteVerbose("Entering Scenario selection"); std::string scenselect=ChooseScenario(); if (!strcmp(scenselect.c_str(),"")) return false; ! Log::WriteVerbose("Scenario Selection is %s",scenselect.c_str()); delete mainScen; mainScen = new Scenario(); ! Log::WriteVerbose("Reading Scenario information"); engine->SetMainModule(scenselect); done=1; *************** *** 518,522 **** static bool ShipSelect(float zoom, std::string scenselect) { ! Log::Write("Entering ship selection"); SDL_Surface *screen=SDL_GetVideoSurface(); ship->SetZoom(zoom); --- 522,526 ---- static bool ShipSelect(float zoom, std::string scenselect) { ! Log::WriteVerbose("Entering ship selection"); SDL_Surface *screen=SDL_GetVideoSurface(); ship->SetZoom(zoom); *************** *** 529,533 **** if (quit==1) return false; Uint32 ticks=SDL_GetTicks(); ! Log::Write("Loading Game..."); SDL_FillRect(screen,0,0); centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); --- 533,537 ---- if (quit==1) return false; Uint32 ticks=SDL_GetTicks(); ! Log::WriteVerbose("Loading Game..."); SDL_FillRect(screen,0,0); centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); *************** *** 537,567 **** map->Init(zoom); engine->SetMap(map); ! Log::Write("Setting map to scenario"); mainScen->SetMap(map); ! Log::Write("Loading map file"); LoadMap(map, mainScen->GetMapFn(), zoom); delete gui2; ! Log::Write("Creating opening message"); std::string message=mainScen->GetOpenMessage(); gui2=MakeCenterOKWindow(message); ! Log::Write("Placing ship"); ship->SetAngle(mainScen->GetStartAngle()); ! Log::Writen("Ship: Angle: %d",mainScen->GetStartAngle()); ship->SetSpeed(mainScen->GetStartSpeed()); ! Log::Writen(" Speed: %d",mainScen->GetStartSpeed()); ship->SetWarp(false); ship->SetX(mainScen->GetStartX()); ! Log::Writen(" X: %d",mainScen->GetStartX()); ship->SetY(mainScen->GetStartY()); ! Log::Writen(" Y: %d",mainScen->GetStartY()); ! Log::Write(" Remaining credits: %d",ship->GetCredits()); //ship->SetZoom(zoom); ! //Log::Write("Loading images"); //ship->ReloadImages(); ! Log::Write("Adjusting shoot point"); ship->AdjustShootPoint(); ! Log::Write("Adding main ship to map"); map->AddMainShip(ship); ! Log::Write("Starting up Scenario"); mainScen->Startup(); Uint32 timepassed=SDL_GetTicks()-ticks; --- 541,571 ---- map->Init(zoom); engine->SetMap(map); ! Log::WriteVerbose("Setting map to scenario"); mainScen->SetMap(map); ! Log::WriteVerbose("Loading map file"); LoadMap(map, mainScen->GetMapFn(), zoom); delete gui2; ! Log::WriteVerbose("Creating opening message"); std::string message=mainScen->GetOpenMessage(); gui2=MakeCenterOKWindow(message); ! Log::WriteVerbose("Placing ship"); ship->SetAngle(mainScen->GetStartAngle()); ! Log::WriteVerbosen("Ship: Angle: %d",mainScen->GetStartAngle()); ship->SetSpeed(mainScen->GetStartSpeed()); ! Log::WriteVerbosen(" Speed: %d",mainScen->GetStartSpeed()); ship->SetWarp(false); ship->SetX(mainScen->GetStartX()); ! Log::WriteVerbosen(" X: %d",mainScen->GetStartX()); ship->SetY(mainScen->GetStartY()); ! Log::WriteVerbosen(" Y: %d",mainScen->GetStartY()); ! Log::WriteVerbose(" Remaining credits: %d",ship->GetCredits()); //ship->SetZoom(zoom); ! //Log::WriteVerbose("Loading images"); //ship->ReloadImages(); ! Log::WriteVerbose("Adjusting shoot point"); ship->AdjustShootPoint(); ! Log::WriteVerbose("Adding main ship to map"); map->AddMainShip(ship); ! Log::WriteVerbose("Starting up Scenario"); mainScen->Startup(); Uint32 timepassed=SDL_GetTicks()-ticks; *************** *** 569,573 **** Uint32 secs=(unsigned int)((double)timepassed/1000.0); Uint32 mins=(unsigned int)((double)secs/60.0); ! Log::Write("Scenario loaded in %d minutes, %d seconds, and %d milliseconds",mins,secs,ms); return true; } --- 573,577 ---- Uint32 secs=(unsigned int)((double)timepassed/1000.0); Uint32 mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Scenario loaded in %d minutes, %d seconds, and %d milliseconds",mins,secs,ms); return true; } *************** *** 575,579 **** static int mainLoop() { ! Log::Write("Main Loop begin"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 579,583 ---- static int mainLoop() { ! Log::WriteVerbose("Main Loop begin"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 602,606 **** fpscount=0; int aiunit=-1; ! int aiunits=map->GetAICount(); fps=0; range=3; --- 606,610 ---- fpscount=0; int aiunit=-1; ! int aiunits=map->GetUnitCount(); fps=0; range=3; *************** *** 622,626 **** map->CheckSectors(sx, sy); float zoom=0.5; ! Log::Write("Variables set, displaying opening message"); TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); engine->AddFont("font9",font9); --- 626,630 ---- map->CheckSectors(sx, sy); float zoom=0.5; ! Log::WriteVerbose("Variables set, displaying opening message"); TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); engine->AddFont("font9",font9); *************** *** 702,706 **** char disppause[100]; sprintf(disppause, "Press '%s' to unpause", fftinput->GetPauseStr().c_str()); ! Log::Write("Entering gameplay loop"); while(!done) { --- 706,710 ---- char disppause[100]; sprintf(disppause, "Press '%s' to unpause", fftinput->GetPauseStr().c_str()); ! Log::WriteVerbose("Entering gameplay loop"); while(!done) { *************** *** 715,719 **** { paused=true; ! Log::Write("Game was paused because the window lost focus"); if (paused) { --- 719,723 ---- { paused=true; ! Log::WriteVerbose("Game was paused because the window lost focus"); if (paused) { *************** *** 765,773 **** { zoom+=0.25; ! Log::Write("Zooming ship"); ship->SetZoom(zoom); ! Log::Write("Loading Ship images"); ship->ReloadImages(); ! Log::Write("Zooming map"); map->SetZoom(zoom); } --- 769,777 ---- { zoom+=0.25; ! Log::WriteVerbose("Zooming ship"); ship->SetZoom(zoom); ! Log::WriteVerbose("Loading Ship images"); ship->ReloadImages(); ! Log::WriteVerbose("Zooming map"); map->SetZoom(zoom); } *************** *** 778,786 **** { zoom-=0.25; ! Log::Write("Zooming ship"); ship->SetZoom(zoom); ! Log::Write("Loading Ship images"); ship->ReloadImages(); ! Log::Write("Zooming map"); map->SetZoom(zoom); } --- 782,790 ---- { zoom-=0.25; ! Log::WriteVerbose("Zooming ship"); ship->SetZoom(zoom); ! Log::WriteVerbose("Loading Ship images"); ship->ReloadImages(); ! Log::WriteVerbose("Zooming map"); map->SetZoom(zoom); } *************** *** 858,862 **** sy=ship->GetSectorY(); curslot=ship->GetCurWeaponSlot(); ! aiunits=map->GetAICount(); if (curslot.image) { --- 862,866 ---- sy=ship->GetSectorY(); curslot=ship->GetCurWeaponSlot(); ! aiunits=map->GetUnitCount(); if (curslot.image) { *************** *** 865,870 **** if (aiunit<aiunits && aiunit!=-1) { ! targetx=map->GetAIUnitX(aiunit); ! targety=map->GetAIUnitY(aiunit); } else --- 869,874 ---- if (aiunit<aiunits && aiunit!=-1) { ! targetx=map->GetUnitX(aiunit); ! targety=map->GetUnitY(aiunit); } else Index: guiapply.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/guiapply.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** guiapply.h 19 Aug 2005 22:39:52 -0000 1.2 --- guiapply.h 23 Aug 2005 09:56:44 -0000 1.3 *************** *** 17,20 **** --- 17,21 ---- int ChangeControl(int w, int h, SDL_Surface *bg=0, bool fill=true); int AskToQuit(int SCREEN_WIDTH, int SCREEN_HEIGHT); + int MsgBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message); int YesNoBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message); int ExitToMenuBox(int SCREEN_WIDTH, int SCREEN_HEIGHT, std::string message); Index: shop.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/shop.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** shop.cpp 23 Aug 2005 03:40:09 -0000 1.3 --- shop.cpp 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 20,24 **** ShipyardShop::ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting) { ! Log::Write("New ShipyardShop"); int i; x=sx; --- 20,24 ---- ShipyardShop::ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting) { ! Log::WriteVerbose("New ShipyardShop"); int i; x=sx; *************** *** 66,70 **** } } ! Log::Write("Max FPKShips=%d",shipmax); cur=0; curcolor=0; --- 66,70 ---- } } ! Log::WriteVerbose("Max FPKShips=%d",shipmax); cur=0; curcolor=0; *************** *** 154,188 **** if ((int)ship->GetCredits()>=(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75))) { ! Log::Write("Giving New Ship"); ! Log::Write("Colorizing ship"); ship->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); ! Log::Write("Getting New ship images"); ship->FPK_NewImages(ships[cur]->GetFPK(), ships[cur]->GetImageFN()); ! Log::Write("Setting max speed"); ship->SetMaxSpeed(engine->GetMaxSpeed()); ! Log::Write("Setting max warp speed"); ship->SetMaxWarp(engine->GetMaxWarpSpeed()); ! Log::Write("Setting max safe warp speed"); ship->SetMaxSafeWarp(engine->GetMaxSafeWarpSpeed()); ! Log::Write("Setting turn delay"); ship->SetTurnDelay(engine->GetTurnDelay()); ! Log::Write("Setting warp turn delay"); ship->SetWarpTurnDelay(engine->GetWarpTurnDelay()); ! Log::Write("Filling slots"); ship->FillSlots(ships[cur]->GetSlots(),ships[cur]->GetSlotCount()); ! Log::Write("Setting shoot point"); ship->SetShootPoint(ships[cur]->GetShootX(),ships[cur]->GetShootY()); ! Log::Write("Setting overheat"); ship->SetOverHeatMax(engine->GetOverHeatMax()); ! Log::Write("Adding weapons"); ship->AddWeaponToSlot(101,"base.fpk","gfx/object/bullet.png"); //ship->AddWeaponToSlot(102,"base.fpk","gfx/object/bullet2.png"); ! if (ships[cur]->HasShield()) Log::Write("Adding shield"); if (ships[cur]->HasShield()) ship->AddShield(ships[cur]->GetShieldFN()); ! Log::Write("Setting battle hits"); ship->SetHullHitMax(ships[cur]->GetHullHitMax()); ship->SetShieldHitMax(10); ship->ResetHits(); ! Log::Write("Ship loaded"); ship->SetCredits((int)(ship->GetCredits()-(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)))); ship->SetPriceBought(ships[cur]->GetPrice()); --- 154,188 ---- if ((int)ship->GetCredits()>=(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75))) { ! Log::WriteVerbose("Giving New Ship"); ! Log::WriteVerbose("Colorizing ship"); ship->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); ! Log::WriteVerbose("Getting New ship images"); ship->FPK_NewImages(ships[cur]->GetFPK(), ships[cur]->GetImageFN()); ! Log::WriteVerbose("Setting max speed"); ship->SetMaxSpeed(engine->GetMaxSpeed()); ! Log::WriteVerbose("Setting max warp speed"); ship->SetMaxWarp(engine->GetMaxWarpSpeed()); ! Log::WriteVerbose("Setting max safe warp speed"); ship->SetMaxSafeWarp(engine->GetMaxSafeWarpSpeed()); ! Log::WriteVerbose("Setting turn delay"); ship->SetTurnDelay(engine->GetTurnDelay()); ! Log::WriteVerbose("Setting warp turn delay"); ship->SetWarpTurnDelay(engine->GetWarpTurnDelay()); ! Log::WriteVerbose("Filling slots"); ship->FillSlots(ships[cur]->GetSlots(),ships[cur]->GetSlotCount()); ! Log::WriteVerbose("Setting shoot point"); ship->SetShootPoint(ships[cur]->GetShootX(),ships[cur]->GetShootY()); ! Log::WriteVerbose("Setting overheat"); ship->SetOverHeatMax(engine->GetOverHeatMax()); ! Log::WriteVerbose("Adding weapons"); ship->AddWeaponToSlot(101,"base.fpk","gfx/object/bullet.png"); //ship->AddWeaponToSlot(102,"base.fpk","gfx/object/bullet2.png"); ! if (ships[cur]->HasShield()) Log::WriteVerbose("Adding shield"); if (ships[cur]->HasShield()) ship->AddShield(ships[cur]->GetShieldFN()); ! Log::WriteVerbose("Setting battle hits"); ship->SetHullHitMax(ships[cur]->GetHullHitMax()); ship->SetShieldHitMax(10); ship->ResetHits(); ! Log::WriteVerbose("Ship loaded"); ship->SetCredits((int)(ship->GetCredits()-(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)))); ship->SetPriceBought(ships[cur]->GetPrice()); *************** *** 325,332 **** cury+=80; } ! Log::Write("column=%d, cury=%d",column,cury); curx=x+(column*100)+80; slotshow->MakeWindow(curx, cury, 80, 66); ! Log::Write("Window %d, %d, %d, %d",curx, cury, 80, 66); sprintf(c, "ID: %d", slots[i].id); std::string slotid=c; --- 325,332 ---- cury+=80; } ! Log::WriteVerbose("column=%d, cury=%d",column,cury); curx=x+(column*100)+80; slotshow->MakeWindow(curx, cury, 80, 66); ! Log::WriteVerbose("Window %d, %d, %d, %d",curx, cury, 80, 66); sprintf(c, "ID: %d", slots[i].id); std::string slotid=c; *************** *** 354,358 **** int NewShipOptions(int w, int h, FPKShip **fpkships) { ! Log::Write("Inside Ship options"); SDL_Event event; ShipyardShop *shipyard=new ShipyardShop(0,0,w,h,fpkships,true); --- 354,358 ---- int NewShipOptions(int w, int h, FPKShip **fpkships) { ! Log::WriteVerbose("Inside Ship options"); SDL_Event event; ShipyardShop *shipyard=new ShipyardShop(0,0,w,h,fpkships,true); *************** *** 373,377 **** } delete shipyard; ! Log::Write("End Ship options"); return done; } --- 373,377 ---- } delete shipyard; ! Log::WriteVerbose("End Ship options"); return done; } Index: graphics.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/graphics.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** graphics.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- graphics.cpp 23 Aug 2005 09:56:44 -0000 1.2 *************** *** 383,386 **** --- 383,401 ---- } } + StaticAnim::StaticAnim(const StaticAnim &oldanim) + { + animbase=oldanim.animbase; + int i; + for (i=0; i<12; i++) + { + anim[i]=rotozoomSurface(oldanim.anim[i], 0, 1, 0); + } + nextframe=oldanim.nextframe; + x=oldanim.x; + y=oldanim.y; + w=oldanim.w; + h=oldanim.h; + zoom=oldanim.zoom; + } void StaticAnim::SetX(int sx) { Index: log.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/log.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** log.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- log.cpp 23 Aug 2005 09:56:44 -0000 1.3 *************** *** 4,7 **** --- 4,8 ---- { bool isLogging = false; + bool verbose = false; std::string logName; std::ofstream logFile; *************** *** 16,19 **** --- 17,24 ---- logFile.open(fname); }; + void Log::EnableVerbose() + { + verbose = true; + } void Log::Write(const std::string& s) { *************** *** 45,47 **** --- 50,81 ---- logFile << buffer; }; + void Log::WriteVerbose(const std::string& s) + { + if (!isLogging || !verbose) return; + logFile << s << std::endl; + }; + void Log::WriteVerbose(const char* s, ...) + { + if (!isLogging || !verbose) return; + va_list lst; + va_start(lst, s); + char buffer[2048]; + vsprintf(buffer, s, lst); + logFile << buffer; + logFile << std::endl; + }; + void Log::WriteVerbosen(const std::string& s) + { + if (!isLogging || !verbose) return; + logFile << s; + }; + void Log::WriteVerbosen(const char* s, ...) + { + if (!isLogging || !verbose) return; + va_list lst; + va_start(lst, s); + char buffer[2048]; + vsprintf(buffer, s, lst); + logFile << buffer; + }; Index: scenario.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** scenario.cpp 23 Aug 2005 03:40:09 -0000 1.3 --- scenario.cpp 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 12,16 **** Uint32 secs=0; Uint32 mins=0; ! Log::Write("LoadMap() at ticks=%d",ticks); struct Local { --- 12,16 ---- Uint32 secs=0; Uint32 mins=0; ! Log::WriteVerbose("LoadMap() at ticks=%d",ticks); struct Local { *************** *** 43,47 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = mapobjects.begin(); iter != mapobjects.end(); iter++) { --- 43,47 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = mapobjects.begin(); iter != mapobjects.end(); iter++) { *************** *** 79,83 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList bullets = objectsNode->getChildren("bullet"); --- 79,83 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList bullets = objectsNode->getChildren("bullet"); *************** *** 88,92 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = bullets.begin(); iter != bullets.end(); iter++) { --- 88,92 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = bullets.begin(); iter != bullets.end(); iter++) { *************** *** 115,119 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList actobjects = objectsNode->getChildren("actobject"); --- 115,119 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList actobjects = objectsNode->getChildren("actobject"); *************** *** 124,128 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); std::string imagefn; SDL_Surface *image=0; --- 124,128 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); std::string imagefn; SDL_Surface *image=0; *************** *** 219,223 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList aiships = objectsNode->getChildren("aiship"); --- 219,223 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList aiships = objectsNode->getChildren("aiship"); *************** *** 228,232 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = aiships.begin(); iter != aiships.end(); iter++) { --- 228,232 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = aiships.begin(); iter != aiships.end(); iter++) { *************** *** 341,345 **** if (cr||cg||cb) object->Colorize(cr,cg,cb); object->FreeImages(); ! map->AddToAIUnits(object); } timepassed=SDL_GetTicks()-ticks; --- 341,345 ---- if (cr||cg||cb) object->Colorize(cr,cg,cb); object->FreeImages(); ! map->AddToUnits(object); } timepassed=SDL_GetTicks()-ticks; *************** *** 347,351 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList stations = objectsNode->getChildren("station"); --- 347,351 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList stations = objectsNode->getChildren("station"); *************** *** 356,360 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = stations.begin(); iter != stations.end(); iter++) { --- 356,360 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = stations.begin(); iter != stations.end(); iter++) { *************** *** 522,528 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } ! Log::Write("Loading Animations"); StaticAnim *anim=new StaticAnim; anim->LoadFrames("gfx/anim/explosion"); --- 522,528 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } ! Log::WriteVerbose("Loading Animations"); StaticAnim *anim=new StaticAnim; anim->LoadFrames("gfx/anim/explosion"); *************** *** 532,536 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Map, %d minutes, %d seconds, %d ms total", mins, secs, ms); delete rootNode; } --- 532,536 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::WriteVerbose("Done Loading Map, %d minutes, %d seconds, %d ms total", mins, secs, ms); delete rootNode; } *************** *** 1155,1163 **** SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::Write(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::Write(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); --- 1155,1163 ---- SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::WriteVerbose(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::WriteVerbose(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); *************** *** 1169,1173 **** FPKShip **LoadShipsFromScen(Scenario *Scen) { ! Log::Write("Inside LoadShipsFromScen"); char **fpklist; char **k; --- 1169,1173 ---- FPKShip **LoadShipsFromScen(Scenario *Scen) { ! Log::WriteVerbose("Inside LoadShipsFromScen"); char **fpklist; char **k; Index: py_baselib.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** py_baselib.h 23 Aug 2005 03:40:09 -0000 1.3 --- py_baselib.h 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 10,13 **** --- 10,16 ---- PyObject* fft_loss(PyObject* self); PyObject* fft_exit(PyObject* self, PyObject* args); + PyObject* fft_messagebox(PyObject* self, PyObject* args); + PyObject* fft_yesnobox(PyObject* self, PyObject* args); + PyObject* fft_render(PyObject* self); #endif /* __PY_BASELIB_H__ */ Index: mapobject.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/mapobject.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mapobject.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- mapobject.cpp 23 Aug 2005 09:56:44 -0000 1.3 *************** *** 501,505 **** ship->SetCredits(ship->GetCredits()-shop.buyitems[buycur].price); ship->AddWeaponToSlot(bayid,shop.buyitems[buycur].fpk,shop.buyitems[buycur].imagefn,shop.buyitems[buycur].amount); ! Log::Write("Inserted %d of ammo into bay id %d\n",shop.buyitems[buycur].amount,bayid); } } --- 501,505 ---- ship->SetCredits(ship->GetCredits()-shop.buyitems[buycur].price); ship->AddWeaponToSlot(bayid,shop.buyitems[buycur].fpk,shop.buyitems[buycur].imagefn,shop.buyitems[buycur].amount); ! Log::WriteVerbose("Inserted %d of ammo into bay id %d\n",shop.buyitems[buycur].amount,bayid); } } Index: fftfile.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/fftfile.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** fftfile.cpp 23 Aug 2005 03:40:09 -0000 1.3 --- fftfile.cpp 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 8,12 **** return buffer; } ! else Log::Write(PHYSFS_getLastError()); return 0; } --- 8,12 ---- return buffer; } ! else Log::WriteVerbose(PHYSFS_getLastError()); return 0; } *************** *** 558,566 **** SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::Write(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::Write(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); --- 558,566 ---- SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::WriteVerbose(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::WriteVerbose(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); *************** *** 643,647 **** FPKShip::FPKShip(int listindex, int num) { ! Log::Write("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) --- 643,647 ---- FPKShip::FPKShip(int listindex, int num) { ! Log::WriteVerbose("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) *************** *** 653,669 **** shootx=0; shooty=0; ! //Log::Write("FPKShip CP"); this->ZeroSlots(); ! //Log::Write("FPKShip CP"); this->GetFileInfo(listindex, num); ! //Log::Write("FPKShip CP"); image=LoadIMG(imagefn); ! //Log::Write("FPKShip CP"); if (hasShield) shield=LoadIMG(shieldfn); ! //Log::Write("FPKShip CP"); } FPKShip::FPKShip(std::string sfpk, std::string shipname) { ! Log::Write("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) --- 653,669 ---- shootx=0; shooty=0; ! //Log::WriteVerbose("FPKShip CP"); this->ZeroSlots(); ! //Log::WriteVerbose("FPKShip CP"); this->GetFileInfo(listindex, num); ! //Log::WriteVerbose("FPKShip CP"); image=LoadIMG(imagefn); ! //Log::WriteVerbose("FPKShip CP"); if (hasShield) shield=LoadIMG(shieldfn); ! //Log::WriteVerbose("FPKShip CP"); } FPKShip::FPKShip(std::string sfpk, std::string shipname) { ! Log::WriteVerbose("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) *************** *** 689,693 **** void FPKShip::GetFileInfo(int listindex, int num) { ! Log::Write("FPKShip::GetFileInfo Begin"); char **spath = PHYSFS_getSearchPath(); --- 689,693 ---- void FPKShip::GetFileInfo(int listindex, int num) { ! Log::WriteVerbose("FPKShip::GetFileInfo Begin"); char **spath = PHYSFS_getSearchPath(); *************** *** 737,741 **** void FPKShip::GetFileInfo(std::string sfpk, std::string shipname) { ! Log::Write("FPKShip::GetFileInfo Begin"); fpk = sfpk; --- 737,741 ---- void FPKShip::GetFileInfo(std::string sfpk, std::string shipname) { ! Log::WriteVerbose("FPKShip::GetFileInfo Begin"); fpk = sfpk; *************** *** 786,794 **** if (ships[num]->hasChild("displayname")) name=ships[num]->getChild("displayname")->getString(); else FPK_Invalid(temp, "displayname command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("image")) imagefn=ships[num]->getChild("image")->getString(); else FPK_Invalid(temp, "image command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shield")) --- 786,794 ---- if (ships[num]->hasChild("displayname")) name=ships[num]->getChild("displayname")->getString(); else FPK_Invalid(temp, "displayname command not found in a playership in FPK"); ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("image")) imagefn=ships[num]->getChild("image")->getString(); else FPK_Invalid(temp, "image command not found in a playership in FPK"); ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shield")) *************** *** 798,802 **** } else hasShield=false; ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("price")) --- 798,802 ---- } else hasShield=false; ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("price")) *************** *** 831,835 **** } else FPK_Invalid(temp, "dimensions command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shootpoint")) --- 831,835 ---- } else FPK_Invalid(temp, "dimensions command not found in a playership in FPK"); ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shootpoint")) *************** *** 849,856 **** shooty=image->h/2; } ! //Log::Write("FPKShip::GetFileInfo CP shootpoint"); DataNodeList shipslots = ships[num]->getChildren("slot"); ! //Log::Write("FPKShip::GetFileInfo CP"); slotcount=shipslots.size(); int j=0; --- 849,856 ---- shooty=image->h/2; } ! //Log::WriteVerbose("FPKShip::GetFileInfo CP shootpoint"); DataNodeList shipslots = ships[num]->getChildren("slot"); ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); slotcount=shipslots.size(); int j=0; *************** *** 1017,1021 **** FPKEngine::FPKEngine(std::string sfpk, std::string sengine) { ! Log::Write("New FPKShip"); image=0; price=0; --- 1017,1021 ---- FPKEngine::FPKEngine(std::string sfpk, std::string sengine) { ! Log::WriteVerbose("New FPKShip"); image=0; price=0; *************** *** 1029,1033 **** void FPKEngine::GetFileInfo(std::string sfpk, std::string sengine) { ! Log::Write("FPKEngine::GetFileInfo Begin"); fpk = sfpk; --- 1029,1033 ---- void FPKEngine::GetFileInfo(std::string sfpk, std::string sengine) { ! Log::WriteVerbose("FPKEngine::GetFileInfo Begin"); fpk = sfpk; *************** *** 1128,1132 **** if (engines[num]->hasChild("turndelay")) turndelay=atoi(engines[num]->getChild("turndelay")->getString().c_str()); else FPK_Invalid(temp, "turndelay command not found in an engine in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (engines[num]->hasChild("turndelaywarp")) warpturndelay=atoi(engines[num]->getChild("turndelaywarp")->getString().c_str()); --- 1128,1132 ---- if (engines[num]->hasChild("turndelay")) turndelay=atoi(engines[num]->getChild("turndelay")->getString().c_str()); else FPK_Invalid(temp, "turndelay command not found in an engine in FPK"); ! //Log::WriteVerbose("FPKShip::GetFileInfo CP"); if (engines[num]->hasChild("turndelaywarp")) warpturndelay=atoi(engines[num]->getChild("turndelaywarp")->getString().c_str()); Index: engine.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** engine.cpp 23 Aug 2005 03:40:09 -0000 1.3 --- engine.cpp 23 Aug 2005 09:56:44 -0000 1.4 *************** *** 1,4 **** --- 1,7 ---- #include "engine.h" + extern int SCREEN_WIDTH; + extern int SCREEN_HEIGHT; + extern PyMethodDef fftMethods[]; extern PyMethodDef catchMethods[]; *************** *** 11,15 **** Engine::Engine() { ! Log::Write("Initializing Engine"); running=false; mainship=0; --- 14,18 ---- Engine::Engine() { ! Log::WriteVerbose("Initializing Engine"); running=false; mainship=0; *************** *** 24,28 **** starfields.clear(); Py_Initialize(); ! Log::Write("Loading FFTrader Python Library"); PyImport_AddModule("fft"); module = Py_InitModule3("fft", fftMethods, "fft standard module.\n"); --- 27,31 ---- starfields.clear(); Py_Initialize(); ! Log::WriteVerbose("Loading FFTrader Python Library"); PyImport_AddModule("fft"); module = Py_InitModule3("fft", fftMethods, "fft standard module.\n"); *************** *** 33,42 **** PyRun_SimpleString("import sys; sys.path.insert(0, './scenario')"); ! PyObject* sysModule = PyImport_ImportModule("sys"); PyObject_SetAttrString(sysModule, "stdout", catchmodule); PyObject_SetAttrString(sysModule, "stderr", catchmodule); /* - PyRun_SimpleString( "import fft\n" --- 36,44 ---- PyRun_SimpleString("import sys; sys.path.insert(0, './scenario')"); ! PyObject *sysModule = PyImport_ImportModule("sys"); PyObject_SetAttrString(sysModule, "stdout", catchmodule); PyObject_SetAttrString(sysModule, "stderr", catchmodule); /* PyRun_SimpleString( "import fft\n" *************** *** 47,55 **** PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), PyObject *pFunc = PyDict_GetItemString(pDict, "Victory"); ! Log::Write("ok so far"); PyObject *test=PyObject_CallFunction(pFunc, 0); ! if(PyObject_IsTrue(test)) Log::Write("method is true"); ! else Log::Write("method is false"); ! Log::Write("got through!"); */ } --- 49,57 ---- PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), PyObject *pFunc = PyDict_GetItemString(pDict, "Victory"); ! Log::WriteVerbose("ok so far"); PyObject *test=PyObject_CallFunction(pFunc, 0); ! if(PyObject_IsTrue(test)) Log::WriteVerbose("method is true"); ! else Log::WriteVerbose("method is false"); ! Log::WriteVerbose("got through!"); */ } *************** *** 85,98 **** Mix_CloseAudio(); this->CleanUpGame(); ! Py_XDECREF(module); ! Py_XDECREF(catchmodule); //Py_XDECREF(objectiveModule); PHYSFS_deinit(); TTF_Quit(); SDL_Quit(); - Py_Finalize(); Log::Write("Thank you for playing!"); } ! void Engine::StartGame() { PyObject* sysModule = PyImport_ImportModule("sys"); --- 87,100 ---- Mix_CloseAudio(); this->CleanUpGame(); ! //Py_XDECREF(module); ! //Py_XDECREF(catchmodule); //Py_XDECREF(objectiveModule); + Py_Finalize(); PHYSFS_deinit(); TTF_Quit(); SDL_Quit(); Log::Write("Thank you for playing!"); } ! bool Engine::StartGame() { PyObject* sysModule = PyImport_ImportModule("sys"); *************** *** 102,106 **** { Log::Write("The main module hasn't been set yet"); ! return; } PyObject *pModuleName = PyString_FromString(mainmodule.c_str()); --- 104,108 ---- { Log::Write("The main module hasn't been set yet"); ! return false; } PyObject *pModuleName = PyString_FromString(mainmodule.c_str()); *************** *** 109,134 **** Log::Write("Could not create Python string from %s",mainmodule.c_str()); PyErr_Print(); ! return; } ! mainModule = PyImport_Import(pModuleName); ! if (mainModule == NULL) { ! //Log::Write("Could not import file %s",mainmodule.c_str()); ! return; } ! else running=true; } void Engine::CleanUpGame() { running=false; - Py_XDECREF(mainModule); char c[2048]; sprintf(c,"del sys.modules['%s']",mainmodule.c_str()); PyRun_SimpleString(c); } void Engine::SetMainModule(std::string modulename) { if (!running) mainmodule=modulename; ! else Log::Write("\nWARNING:\nAttempted to set a new module while the game is already running\n"); } Unit *Engine::GetMainShip() --- 111,169 ---- Log::Write("Could not create Python string from %s",mainmodule.c_str()); PyErr_Print(); ! return false; } ! else { ! Log::Write("**********************\nLoading module: %s\n",mainmodule.c_str()); ! running=true; } ! mainModule = PyImport_Import(pModuleName); ! if (mainModule == NULL) running=false; ! return running; } void Engine::CleanUpGame() { running=false; char c[2048]; sprintf(c,"del sys.modules['%s']",mainmodule.c_str()); PyRun_SimpleString(c); + Py_XDECREF(mainModule); + } + void Engine::Render() + { + SDL_Surface *screen=SDL_GetVideoSurface(); + SDL_FillRect(screen,0,0); + int x=0; + int y=0; + double dx=0.0; + double dy=0.0; + if(mainship) + { + x=mainship->GetX(); + y=mainship->GetY(); + dx=mainship->GetDX(); + dy=mainship->GetDY(); + } + if(mainmap) + { + int i; + for (i=0; i<(int)starfields.size(); i++) + { + starfields[i].stars->Display((int)(-dx/starfields[i].factor),(int)(-dy/starfields[i].factor)); + } + mainmap->DisplayOnScreenObjects(x,y,SCREEN_WIDTH,SCREEN_HEIGHT); + } + if(mainship) + { + int shipx=(SCREEN_WIDTH/2)-(ship->GetImageWidth()/2); + int shipy=(SCREEN_HEIGHT/2)-(ship->GetImageHeight()/2); + mainship->Display(shipx,shipy); + //mainmap->DisplayMinimap(4,10,x,y,range); + } } void Engine::SetMainModule(std::string modulename) { if (!running) mainmodule=modulename; ! else Log::WriteVerbose("\nWARNING:\nAttempted to set a new module while the game is already running\n"); } Unit *Engine::GetMainShip() *************** *** 288,296 **** } } ! void Engine::AddStarfield(StarField *stars, bool above) { FFTStars fftstars; fftstars.stars=stars; fftstars.above=above; starfields.push_back(fftstars); } --- 323,332 ---- } } ! void Engine::AddStarfield(StarField *stars, bool above, int factor) { FFTStars fftstars; fftstars.stars=stars; fftstars.above=above; + fftstars.factor=factor; starfields.push_back(fftstars); } Index: map.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/map.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** map.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- map.cpp 23 Aug 2005 09:56:44 -0000 1.3 *************** *** 1,52 **** #include "map.h" Map::~Map() { ! int i; ! for (i=0; i<next; i++) ! { ! delete objects[i]; ! } ! for (i=0; i<stationnext; i++) [...1092 lines suppressed...] ! return (int)objects.size(); } ! int Map::GetUnitCount() { ! int retval=(int)units.size(); ! if (mainship) retval--; ! return retval; } void Map::SendPauseTime(Uint32 time) { int i; ! for (i=0; i<(int)stations.size(); i++) { stations[i]->AddToWaitTime(time); } ! for (i=0; i<(int)sobjects.size(); i++) { ! sobjects[i]->ticks+=time; } } Index: map.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/map.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** map.h 19 Aug 2005 07:32:29 -0000 1.1 --- map.h 23 Aug 2005 09:56:44 -0000 1.2 *************** *** 2,12 **** #define __MAP_H__ #include "units.h" #include "mapobject.h" class Map { public: ! Map() {} ~Map(); void Init(float zzoom); --- 2,22 ---- #define __MAP_H__ + #include <deque> + #include <algorithm> #include "units.h" #include "mapobject.h" + struct MapBullet + { + Unit* bullet; + bool enemyfire; + Uint32 ticks; + int target; + }; + class Map { public: ! Map(); ~Map(); void Init(float zzoom); *************** *** 15,23 **** void AddToStations(Station *object); void AddToActiveObjects(Unit *object); ! void RemoveFromActiveObjects(int start); void AddToShootingObjects(Unit *object, int aishipindex); - void RemoveFromShootingObjects(int j); void AddToAIShootingObjects(Unit *object); ! void RemoveFromAIShootingObjects(int j); void DestroyObjects(); void DisplayMinimap(int x, int y, int shipx, int shipy, int range); --- 25,32 ---- void AddToStations(Station *object); void AddToActiveObjects(Unit *object); ! void RemoveFromActiveObjects(int index); void AddToShootingObjects(Unit *object, int aishipindex); void AddToAIShootingObjects(Unit *object); ! void RemoveFromShootingObjects(int index); void DestroyObjects(); void DisplayMinimap(int x, int y, int shipx, int shipy, int range); *************** *** 25,29 **** void CheckSectors(int sectorx, int sectory); int CheckCollisions(Unit *a); ! int CheckAIUnitCollisions(Unit *a); int CheckShipCollisions(Unit *a); void SpawnBullet(int x, int y, int speed, int angle, std::string img, std::string fpk, SDL_Surface *image, int aishipindex=-1, int slotid=0); --- 34,38 ---- void CheckSectors(int sectorx, int sectory); int CheckCollisions(Unit *a); ! int CheckUnitCollisions(Unit *a); int CheckShipCollisions(Unit *a); void SpawnBullet(int x, int y, int speed, int angle, std::string img, std::string fpk, SDL_Surface *image, int aishipindex=-1, int slotid=0); *************** *** 33,74 **** void SetZoom(float szoom); void AddToAnimations(StaticAnim *anim); ! void RemoveFromActiveAnims(int start); ! void AddToAIUnits(Unit *unit); ! void RemoveFromAIUnits(int start); void SpawnAnim(int index, int x, int y); void Dock(int x, int y); ! int GetAIUnitX(int index); ! int GetAIUnitY(int index); void SetTarget(int index); void DisplayAITarget(int sx, int sy, int sw, int sh, TTF_Font *font, int targetx, int targety); ! int Map::GetAIUnitImageW(int index); ! int Map::GetAIUnitImageH(int index); int GetObjCount(); ! int GetAICount(); void SendPauseTime(Uint32 time); Unit *mainship; private: ! MapObject *objects[5000]; ! Station *stations[500]; ! Unit *actobjects[1000]; ! Unit *sobjects[100]; ! Unit *aisobjects[100]; ! StaticAnim *anims[20]; ! Unit *aiunits[100]; ! int next; ! int stationnext; ! int actnext; ! int snext; ! int aisnext; ! int animnext; ! int activeanimnext; ! int aiunitnext; int target; - int shootindex[100]; - Uint32 s_ticks[100]; - Uint32 ais_ticks[100]; float zoom; - StaticAnim *activeanims[20]; - bool activeanim[20]; }; --- 42,70 ---- void SetZoom(float szoom); void AddToAnimations(StaticAnim *anim); ! void RemoveFromActiveAnims(int index); ! void AddToUnits(Unit *unit); ! void RemoveFromUnits(int index); void SpawnAnim(int index, int x, int y); void Dock(int x, int y); ! int GetUnitX(int index); ! int GetUnitY(int index); void SetTarget(int index); void DisplayAITarget(int sx, int sy, int sw, int sh, TTF_Font *font, int targetx, int targety); ! int GetUnitImageW(int index); ! int GetUnitImageH(int index); int GetObjCount(); ! int GetUnitCount(); void SendPauseTime(Uint32 time); U... [truncated message content] |
From: TomT64 <to...@us...> - 2005-08-23 09:56:53
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15827 Modified Files: fftrader.dev Log Message: More scripting code, and added verbose option to Log and commandline options Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** fftrader.dev 21 Aug 2005 11:29:49 -0000 1.12 --- fftrader.dev 23 Aug 2005 09:56:43 -0000 1.13 *************** *** 12,16 **** MakeIncludes= Compiler= ! CppCompiler=_@@_ Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lpython24_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 --- 12,16 ---- MakeIncludes= Compiler= ! CppCompiler=-Wall_@@_ Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lpython24_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 *************** *** 22,26 **** HostApplication= Folders= ! CommandLine=-showfps -log IncludeVersionInfo=0 SupportXPThemes=0 --- 22,26 ---- HostApplication= Folders= ! CommandLine=-showfps -log -verbose IncludeVersionInfo=0 SupportXPThemes=0 |
From: TomT64 <to...@us...> - 2005-08-23 03:40:18
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10816 Modified Files: Makefile Log Message: Update to Python Engine, some scripting (test files not included yet) Index: Makefile =================================================================== RCS file: /cvsroot/fftrader/fftrader/Makefile,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile 19 Aug 2005 07:32:29 -0000 1.13 --- Makefile 23 Aug 2005 03:40:09 -0000 1.14 *************** *** 1,6 **** sdl_CPPFLAGS := $(shell sdl-config --cflags) sdl_LIBS := $(shell sdl-config --libs) fft_CPPFLAGS = -Wall -ansi -O2 ! fft_LIBS = -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_gfx -lz DEBUG=1 --- 1,8 ---- + python_LIBS := -lpython2.3 + python_CPPFLAGS := -I/usr/include/python2.3 sdl_CPPFLAGS := $(shell sdl-config --cflags) sdl_LIBS := $(shell sdl-config --libs) fft_CPPFLAGS = -Wall -ansi -O2 ! fft_LIBS = -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_gfx -lphysfs DEBUG=1 *************** *** 24,38 **** %.o: %.c ! $(CC) -c $(sdl_CPPFLAGS) $(fft_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ %.o: %.cpp ! $(CXX) -c $(sdl_CPPFLAGS) $(fft_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< -o $@ %.o: %.m ! $(CC) -c $(sdl_CPPFLAGS) $(filter-out -ansi,$(fft_CPPFLAGS)) \ -I/System/Library/Frameworks/Cocoa/Headers $< -o $@ fft: $(OBJS) ! $(LD) $(sdl_LIBS) $(fft_LIBS) $(LDFLAGS) $^ -o $@ new: clean fft --- 26,40 ---- %.o: %.c ! $(CC) -c $(sdl_CPPFLAGS) $(python_CPPFLAGS) $(fft_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ %.o: %.cpp ! $(CXX) -c $(sdl_CPPFLAGS) $(python_CPPFLAGS) $(fft_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< -o $@ %.o: %.m ! $(CC) -c $(sdl_CPPFLAGS) $(python_CPPFLAGS) $(filter-out -ansi,$(fft_CPPFLAGS)) \ -I/System/Library/Frameworks/Cocoa/Headers $< -o $@ fft: $(OBJS) ! $(LD) $(sdl_LIBS) $(python_LIBS) $(fft_LIBS) $(LDFLAGS) $^ -o $@ new: clean fft |
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10816/src Modified Files: engine.cpp engine.h fftfile.cpp main.cpp py_baselib.cpp py_baselib.h scenario.cpp scenario.h shop.cpp Log Message: Update to Python Engine, some scripting (test files not included yet) Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 19 Aug 2005 22:39:52 -0000 1.3 --- main.cpp 23 Aug 2005 03:40:09 -0000 1.4 *************** *** 267,271 **** int done=0; ! int maintemp; int GUIresult; Log::Write("Proceeding to main loop"); --- 267,271 ---- int done=0; ! int maintemp=0; int GUIresult; Log::Write("Proceeding to main loop"); *************** *** 287,291 **** { Log::Write("Proceeding to main game play"); ! maintemp=mainLoop(); Log::Write("Main gameplay exited"); if (maintemp==-1) done=1; --- 287,293 ---- { Log::Write("Proceeding to main game play"); ! engine->StartGame(); ! engine->CleanUpGame(); ! //maintemp=mainLoop(); Log::Write("Main gameplay exited"); if (maintemp==-1) done=1; *************** *** 491,500 **** static bool LoadScenario() { ! float zoom=0.5; int done; done=0; while (!done) { ! bool goahead; Log::Write("LoadScenario()"); Log::Write("Entering Scenario selection"); --- 493,502 ---- static bool LoadScenario() { ! //float zoom=0.5; int done; done=0; while (!done) { ! //bool goahead=false; Log::Write("LoadScenario()"); Log::Write("Entering Scenario selection"); *************** *** 505,511 **** mainScen = new Scenario(); Log::Write("Reading Scenario information"); ! mainScen->ReadOnly(scenselect); ! goahead=ShipSelect(zoom, scenselect); ! if (goahead) done=1; } return true; --- 507,515 ---- mainScen = new Scenario(); Log::Write("Reading Scenario information"); ! engine->SetMainModule(scenselect); ! done=1; ! //mainScen->ReadOnly(scenselect); ! //goahead=ShipSelect(zoom, scenselect); ! //if (goahead) done=1; } return true; Index: shop.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/shop.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** shop.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- shop.cpp 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 282,286 **** void ShipyardShop::DisplayShipSlots(FPKShip *curship) { ! SDL_Surface *screen=SDL_GetVideoSurface(); SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; if (starting) centerString(font14, x+(w/2), y+20, "Ship Slots", white); --- 282,286 ---- void ShipyardShop::DisplayShipSlots(FPKShip *curship) { ! //SDL_Surface *screen=SDL_GetVideoSurface(); SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; if (starting) centerString(font14, x+(w/2), y+20, "Ship Slots", white); Index: scenario.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scenario.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- scenario.cpp 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 1,4 **** --- 1,6 ---- #include "scenario.h" + extern PyObject* module; + void LoadMap(Map *map, const std::string& filename, float zoom) { *************** *** 541,548 **** void Scenario::ReadOnly(std::string fn) { - victnext=0; - condnext=0; - lossnext=0; - lcondnext=0; startx=0; starty=0; --- 543,546 ---- *************** *** 551,555 **** credits=0; startingshipnext=0; ! int i; for (i=0; i<50; i++) { --- 549,554 ---- credits=0; startingshipnext=0; ! //int i; ! /* for (i=0; i<50; i++) { *************** *** 557,560 **** --- 556,560 ---- got[i]=false; } + */ struct Local { *************** *** 586,592 **** if (!realRoot->hasChild("openmessage")) SCN_Invalid(name, "openmessage command not found in Scenario file"); openmessage=Local::getStringNode(realRoot, "openmessage"); ! if (!realRoot->hasChild("victory")) SCN_Invalid(name, "victory command not found in Scenario file"); ! DataNode *victoryNode = realRoot->getChild("victory"); DataNodeList::iterator iter; DataNodeList conditionsets = victoryNode->getChildren("conditionset"); if (!conditionsets.empty()) --- 586,594 ---- if (!realRoot->hasChild("openmessage")) SCN_Invalid(name, "openmessage command not found in Scenario file"); openmessage=Local::getStringNode(realRoot, "openmessage"); ! if (realRoot->hasChild("module")) modulename=Local::getStringNode(realRoot, "module"); DataNodeList::iterator iter; + //if (!realRoot->hasChild("victory")) SCN_Invalid(name, "victory command not found in Scenario file"); + /* + DataNode *victoryNode = realRoot->getChild("victory"); DataNodeList conditionsets = victoryNode->getChildren("conditionset"); if (!conditionsets.empty()) *************** *** 718,728 **** } else SCN_Invalid(name, "actobjects loss condition has no 'meet' command"); - /* - if ((*iter)->getChild("actobjects")->hasChild("whenmet")) - { - get[lossnext]=true; - getwhat[lossnext]=Local::getStringNode((*iter)->getChild("actobjects"), "whenmet"); - } - */ valloss[lossnext] = "actobjects"; if ((*iter)->getChild("actobjects")->hasChild("equals")) --- 720,723 ---- *************** *** 772,782 **** } else SCN_Invalid(name, "aiships loss condition has no 'meet' command"); - /* - if ((*iter)->getChild("aiships")->hasChild("whenmet")) - { - get[lossnext]=true; - getwhat[lossnext]=Local::getStringNode((*iter)->getChild("aiships"), "whenmet"); - } - */ valloss[lossnext] = "aiships"; if ((*iter)->getChild("aiships")->hasChild("equals")) --- 767,770 ---- *************** *** 823,826 **** --- 811,815 ---- else SCN_Invalid(name, "No 'conditionset's found under loss command"); } + */ if (!realRoot->hasChild("start")) SCN_Invalid(name, "start command not found in Scenario file"); if (!realRoot->getChild("start")->hasChild("x")) SCN_Invalid(name, "start command does not have x command"); *************** *** 863,1053 **** bool Scenario::CheckVictory() { ! bool retval=false; ! int met[50]; ! int i; ! for (i=0; i<50; i++) ! { ! met[i]=0; ! } ! int bigmet=0; ! int savemet=0; ! if (!victnext && !lossnext) ! { ! Log::Write("There are no victory conditions or loss conditions! This should never happen!"); ! exit(1); ! } ! else ! { ! for (i=0; i<victnext; i++) ! { ! savemet=met[conditionset[i]]; ! if (!strcmp(valvictory[i].c_str(),"actobjects")) ! { ! if (!strcmp(compvictory[i].c_str(),"equals")) ! { ! if(scnmap->GetObjCount()==victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"notequal")) ! { ! if(scnmap->GetObjCount()!=victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"lessthan")) ! { ! if(scnmap->GetObjCount()<victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"greaterthan")) ! { ! if(scnmap->GetObjCount()>victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"lessthanorequal")) ! { ! if(scnmap->GetObjCount()<=victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"greaterthanorequal")) ! { ! if(scnmap->GetObjCount()>=victory[i]) met[conditionset[i]]++; ! } ! } ! if (!strcmp(valvictory[i].c_str(),"aiships")) ! { ! if (!strcmp(compvictory[i].c_str(),"equals")) ! { ! if(scnmap->GetAICount()==victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"notequal")) ! { ! if(scnmap->GetAICount()!=victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"lessthan")) ! { ! if(scnmap->GetAICount()<victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"greaterthan")) ! { ! if(scnmap->GetAICount()>victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"lessthanorequal")) ! { ! if(scnmap->GetAICount()<=victory[i]) met[conditionset[i]]++; ! } ! else if (!strcmp(compvictory[i].c_str(),"greaterthanorequal")) ! { ! if(scnmap->GetAICount()>=victory[i]) met[conditionset[i]]++; ! } ! } ! if (savemet<met[conditionset[i]] && get[i] && !got[i]) ! { ! if (!strcmp(getwhat[i].c_str(),"enablewarp")) scnmap->mainship->EnableWarp(); ! got[i]=true; ! } ! } ! } ! int j; ! for(i=0; i<condnext; i++) ! { ! for(j=0; j<victnext; j++) ! { ! if (i==conditionset[j]) ! { ! if (met[i]>=meet[j]) bigmet++; ! } ! } ! } ! if (bigmet>=condnext) retval=true; ! else retval=false; ! return retval; } bool Scenario::CheckLoss() { ! bool retval=false; ! int lmet[50]; ! int i; ! for (i=0; i<50; i++) ! { ! lmet[i]=0; ! } ! int lbigmet=0; ! if (!victnext && !lossnext) ! { ! Log::Write("There are no victory conditions AND no loss conditions! This should never happen!"); ! exit(1); ! } ! else ! { ! if (lossnext) ! { ! for (i=0; i<lossnext; i++) ! { ! if (!strcmp(valloss[i].c_str(),"actobjects")) ! { ! if (!strcmp(comploss[i].c_str(),"equals")) ! { ! if(scnmap->GetObjCount()==loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"notequal")) ! { ! if(scnmap->GetObjCount()!=loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"lessthan")) ! { ! if(scnmap->GetObjCount()<loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"greaterthan")) ! { ! if(scnmap->GetObjCount()>loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"lessthanorequal")) ! { ! if(scnmap->GetObjCount()<=loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"greaterthanorequal")) ! { ! if(scnmap->GetObjCount()>=loss[i]) lmet[lconditionset[i]]++; ! } ! } ! if (!strcmp(valloss[i].c_str(),"aiships")) ! { ! if (!strcmp(comploss[i].c_str(),"equals")) ! { ! if(scnmap->GetAICount()==loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"notequal")) ! { ! if(scnmap->GetAICount()!=loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"lessthan")) ! { ! if(scnmap->GetAICount()<loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"greaterthan")) ! { ! if(scnmap->GetAICount()>loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"lessthanorequal")) ! { ! if(scnmap->GetAICount()<=loss[i]) lmet[lconditionset[i]]++; ! } ! else if (!strcmp(comploss[i].c_str(),"greaterthanorequal")) ! { ! if(scnmap->GetAICount()>=loss[i]) lmet[lconditionset[i]]++; ! } ! } ! } ! int j; ! for(i=0; i<lcondnext; i++) ! { ! for(j=0; j<lossnext; j++) ! { ! if (i==lconditionset[j]) ! { ! if (lmet[i]>=lmeet[j]) lbigmet++; ! } ! } ! } ! if (lbigmet>=lcondnext) retval=true; ! else retval=false; ! } ! } ! return retval; } std::string Scenario::GetMapFn() --- 852,868 ---- bool Scenario::CheckVictory() { ! PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), ! PyObject *pFunc = PyDict_GetItemString(pDict, "Victory"); ! PyObject *test=PyObject_CallFunction(pFunc, 0); ! if(PyObject_IsTrue(test)) return true; ! else return false; } bool Scenario::CheckLoss() { ! PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), ! PyObject *pFunc = PyDict_GetItemString(pDict, "Loss"); ! PyObject *test=PyObject_CallFunction(pFunc, 0); ! if(PyObject_IsTrue(test)) return true; ! else return false; } std::string Scenario::GetMapFn() *************** *** 1067,1070 **** --- 882,889 ---- return openmessage; } + std::string Scenario::GetModuleName() + { + return modulename; + } int Scenario::GetStartX() { *************** *** 1146,1149 **** --- 965,969 ---- std::string name[total]; std::string desc[total]; + std::string module[total]; DataNode *rootNode=0; DataNodeList orderedScenarios; *************** *** 1166,1169 **** --- 986,990 ---- name[scencount]=Scen->GetName(); desc[scencount]=Scen->GetDesc(); + module[scencount]=Scen->GetModuleName(); scencount++; delete Scen; *************** *** 1198,1201 **** --- 1019,1023 ---- name[scencount]=Scen->GetName(); desc[scencount]=Scen->GetDesc(); + module[scencount]=Scen->GetModuleName(); scencount++; delete Scen; *************** *** 1257,1261 **** if (click==select) { ! retval=scen[cur]; done=1; } --- 1079,1083 ---- if (click==select) { ! retval=module[cur]; done=1; } Index: py_baselib.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** py_baselib.h 21 Aug 2005 11:29:49 -0000 1.2 --- py_baselib.h 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 3,6 **** --- 3,7 ---- #include "Python.h" + #include "engine.h" #include "guiapply.h" Index: fftfile.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/fftfile.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** fftfile.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- fftfile.cpp 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 743,746 **** --- 743,748 ---- bool found = false; DataNode *packNode, *deleteNode; + packNode=0; + deleteNode=0; std::string temp; *************** *** 1033,1036 **** --- 1035,1040 ---- bool found = false; DataNode *packNode, *deleteNode; + packNode=0; + deleteNode=0; std::string temp; Index: engine.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** engine.h 21 Aug 2005 11:29:49 -0000 1.2 --- engine.h 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 44,47 **** --- 44,50 ---- ~Engine(); void Quit(); + void StartGame(); + void CleanUpGame(); + void SetMainModule(std::string modulename); Unit *GetMainShip(); void SetMainShip(Unit *ship); *************** *** 62,65 **** --- 65,70 ---- void AddStarfield(StarField *stars, bool above); private: + bool running; + std::string mainmodule; Unit *mainship; Scenario *mainscen; Index: scenario.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** scenario.h 19 Aug 2005 22:39:52 -0000 1.3 --- scenario.h 23 Aug 2005 03:40:09 -0000 1.4 *************** *** 3,6 **** --- 3,7 ---- #include <string> + #include "Python.h" #include "fftfile.h" #include "gui.h" *************** *** 37,40 **** --- 38,42 ---- std::string GetDesc(); std::string GetOpenMessage(); + std::string GetModuleName(); int GetStartX(); int GetStartY(); *************** *** 49,70 **** std::string mapfn; std::string openmessage; Map *scnmap; - std::string valvictory[50]; - std::string compvictory[50]; - int conditionset[50]; - int meet[50]; - int victory[50]; - bool get[50]; - bool got[50]; - std::string getwhat[50]; - int victnext; - int condnext; - std::string valloss[50]; - std::string comploss[50]; - int lconditionset[50]; - int lmeet[50]; - int loss[50]; - int lossnext; - int lcondnext; int startx; int starty; --- 51,56 ---- std::string mapfn; std::string openmessage; + std::string modulename; Map *scnmap; int startx; int starty; Index: engine.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** engine.cpp 21 Aug 2005 11:29:49 -0000 1.2 --- engine.cpp 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 4,18 **** extern PyMethodDef catchMethods[]; ! PyObject* module; ! PyObject* catchmodule; ! PyObject* objectiveModule; Engine::Engine() { Log::Write("Initializing Engine"); mainship=0; mainscen=0; maininput=0; mainmap=0; fonts.clear(); guis.clear(); --- 4,21 ---- extern PyMethodDef catchMethods[]; ! PyObject *module; ! PyObject *mainModule; ! PyObject *catchmodule; ! //PyObject *objectiveModule; Engine::Engine() { Log::Write("Initializing Engine"); + running=false; mainship=0; mainscen=0; maininput=0; mainmap=0; + mainmodule=""; fonts.clear(); guis.clear(); *************** *** 28,32 **** catchmodule = Py_InitModule3("catch", catchMethods, "catch sysout and syserr.\n"); ! PyRun_SimpleString("import sys; sys.path.insert(0, '.')"); PyObject* sysModule = PyImport_ImportModule("sys"); --- 31,35 ---- catchmodule = Py_InitModule3("catch", catchMethods, "catch sysout and syserr.\n"); ! PyRun_SimpleString("import sys; sys.path.insert(0, './scenario')"); PyObject* sysModule = PyImport_ImportModule("sys"); *************** *** 34,37 **** --- 37,42 ---- PyObject_SetAttrString(sysModule, "stderr", catchmodule); + /* + PyRun_SimpleString( "import fft\n" *************** *** 47,50 **** --- 52,56 ---- else Log::Write("method is false"); Log::Write("got through!"); + */ } Engine::~Engine() *************** *** 78,90 **** Mix_CloseAudio(); Py_XDECREF(module); Py_XDECREF(catchmodule); ! Py_XDECREF(objectiveModule); ! Py_Finalize(); PHYSFS_deinit(); TTF_Quit(); SDL_Quit(); Log::Write("Thank you for playing!"); } Unit *Engine::GetMainShip() { --- 84,135 ---- Mix_CloseAudio(); + this->CleanUpGame(); Py_XDECREF(module); Py_XDECREF(catchmodule); ! //Py_XDECREF(objectiveModule); PHYSFS_deinit(); TTF_Quit(); SDL_Quit(); + Py_Finalize(); Log::Write("Thank you for playing!"); } + void Engine::StartGame() + { + PyObject* sysModule = PyImport_ImportModule("sys"); + PyObject_SetAttrString(sysModule, "stdout", catchmodule); + PyObject_SetAttrString(sysModule, "stderr", catchmodule); + if (!strcmp(mainmodule.c_str(),"")) + { + Log::Write("The main module hasn't been set yet"); + return; + } + PyObject *pModuleName = PyString_FromString(mainmodule.c_str()); + if (PyErr_Occurred()) + { + Log::Write("Could not create Python string from %s",mainmodule.c_str()); + PyErr_Print(); + return; + } + mainModule = PyImport_Import(pModuleName); + if (mainModule == NULL) + { + //Log::Write("Could not import file %s",mainmodule.c_str()); + return; + } + else running=true; + } + void Engine::CleanUpGame() + { + running=false; + Py_XDECREF(mainModule); + char c[2048]; + sprintf(c,"del sys.modules['%s']",mainmodule.c_str()); + PyRun_SimpleString(c); + } + void Engine::SetMainModule(std::string modulename) + { + if (!running) mainmodule=modulename; + else Log::Write("\nWARNING:\nAttempted to set a new module while the game is already running\n"); + } Unit *Engine::GetMainShip() { Index: py_baselib.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** py_baselib.cpp 21 Aug 2005 11:29:49 -0000 1.2 --- py_baselib.cpp 23 Aug 2005 03:40:09 -0000 1.3 *************** *** 43,46 **** --- 43,53 ---- Log::Write("Exiting the game via fft.Exit() with message \"%s\"",ExitStr); ExitToMenuBox(SCREEN_WIDTH, SCREEN_HEIGHT, ExitStr); + engine->CleanUpGame(); + //This part is designed to stifle the exception from showing up in the log. + //Must be reinstated to catchmodule when loading a new module + PyObject* sysModule = PyImport_ImportModule("sys"); + PyObject_SetAttrString(sysModule, "stdout", Py_None); + PyObject_SetAttrString(sysModule, "stderr", Py_None); + PyErr_SetString(PyExc_RuntimeError, "stopping execution"); Py_INCREF(Py_None); |
From: TomT64 <to...@us...> - 2005-08-21 11:29:58
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5247 Modified Files: fftrader.dev fftrader.dsp Log Message: Update to Python Engine, still no scripting Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** fftrader.dev 19 Aug 2005 22:39:52 -0000 1.11 --- fftrader.dev 21 Aug 2005 11:29:49 -0000 1.12 *************** *** 2,6 **** FileName=fftrader.dev Name=fftrader ! UnitCount=38 Type=0 Ver=1 --- 2,6 ---- FileName=fftrader.dev Name=fftrader ! UnitCount=35 Type=0 Ver=1 *************** *** 30,35 **** CustomMakefile= ! [Unit2] ! FileName=src\units.cpp CompileCpp=1 Folder=fftrader --- 30,35 ---- CustomMakefile= ! [Unit12] ! FileName=src\gui.h CompileCpp=1 Folder=fftrader *************** *** 40,45 **** BuildCmd= ! [Unit3] ! FileName=src\main.cpp CompileCpp=1 Folder=fftrader --- 40,45 ---- BuildCmd= ! [Unit13] ! FileName=src\guiapply.cpp CompileCpp=1 Folder=fftrader *************** *** 50,55 **** BuildCmd= ! [Unit4] ! FileName=src\gui.h CompileCpp=1 Folder=fftrader --- 50,55 ---- BuildCmd= ! [Unit14] ! FileName=src\guiapply.h CompileCpp=1 Folder=fftrader *************** *** 60,65 **** BuildCmd= ! [Unit5] ! FileName=src\map.h CompileCpp=1 Folder=fftrader --- 60,65 ---- BuildCmd= ! [Unit18] ! FileName=src\log.h CompileCpp=1 Folder=fftrader *************** *** 70,75 **** BuildCmd= ! [Unit6] ! FileName=src\map.cpp CompileCpp=1 Folder=fftrader --- 70,75 ---- BuildCmd= ! [Unit22] ! FileName=src\mapobject.cpp CompileCpp=1 Folder=fftrader *************** *** 80,85 **** BuildCmd= ! [Unit7] ! FileName=src\mapobject.h CompileCpp=1 Folder=fftrader --- 80,103 ---- BuildCmd= ! [VersionInfo] ! Major=0 ! Minor=1 ! Release=1 ! Build=1 ! LanguageID=1033 ! CharsetID=1252 ! CompanyName= ! FileVersion= ! FileDescription=Developed using the Dev-C++ IDE ! InternalName= ! LegalCopyright= ! LegalTrademarks= ! OriginalFilename= ! ProductName= ! ProductVersion= ! AutoIncBuildNr=0 ! ! [Unit24] ! FileName=src\math.cpp CompileCpp=1 Folder=fftrader *************** *** 90,95 **** BuildCmd= ! [Unit8] ! FileName=src\shop.h CompileCpp=1 Folder=fftrader --- 108,113 ---- BuildCmd= ! [Unit26] ! FileName=src\py_baselib.cpp CompileCpp=1 Folder=fftrader *************** *** 100,105 **** BuildCmd= ! [Unit9] ! FileName=src\fftfile.h CompileCpp=1 Folder=fftrader --- 118,123 ---- BuildCmd= ! [Unit27] ! FileName=src\py_baselib.h CompileCpp=1 Folder=fftrader *************** *** 110,115 **** BuildCmd= ! [Unit10] ! FileName=src\shop.cpp CompileCpp=1 Folder=fftrader --- 128,133 ---- BuildCmd= ! [Unit28] ! FileName=src\resource.h CompileCpp=1 Folder=fftrader *************** *** 120,125 **** BuildCmd= ! [Unit11] ! FileName=src\fftfile.cpp CompileCpp=1 Folder=fftrader --- 138,143 ---- BuildCmd= ! [Unit20] ! FileName=src\map.cpp CompileCpp=1 Folder=fftrader *************** *** 130,135 **** BuildCmd= ! [Unit12] ! FileName=src\mapobject.cpp CompileCpp=1 Folder=fftrader --- 148,153 ---- BuildCmd= ! [Unit32] ! FileName=src\shop.cpp CompileCpp=1 Folder=fftrader *************** *** 140,145 **** BuildCmd= ! [Unit13] ! FileName=src\scenario.cpp CompileCpp=1 Folder=fftrader --- 158,163 ---- BuildCmd= ! [Unit33] ! FileName=src\shop.h CompileCpp=1 Folder=fftrader *************** *** 150,155 **** BuildCmd= ! [Unit14] ! FileName=src\scenario.h CompileCpp=1 Folder=fftrader --- 168,173 ---- BuildCmd= ! [Unit34] ! FileName=src\units.cpp CompileCpp=1 Folder=fftrader *************** *** 160,165 **** BuildCmd= ! [Unit15] ! FileName=src\bitmask.h CompileCpp=1 Folder=fftrader --- 178,183 ---- BuildCmd= ! [Unit39] ! FileName=src\py_classes.h CompileCpp=1 Folder=fftrader *************** *** 170,185 **** BuildCmd= ! [Unit16] ! FileName=src\resource.rc CompileCpp=1 Folder=fftrader Compile=1 ! Link=0 Priority=1000 OverrideBuildCmd=0 BuildCmd= ! [Unit17] ! FileName=src\resource.h Folder=fftrader Compile=1 --- 188,204 ---- BuildCmd= ! [Unit40] ! FileName=src\py_objective.cpp CompileCpp=1 Folder=fftrader Compile=1 ! Link=1 Priority=1000 OverrideBuildCmd=0 BuildCmd= ! [Unit35] ! FileName=src\units.h ! CompileCpp=1 Folder=fftrader Compile=1 *************** *** 188,195 **** OverrideBuildCmd=0 BuildCmd= - CompileCpp=1 ! [Unit18] ! FileName=src\math.h CompileCpp=1 Folder=fftrader --- 207,213 ---- OverrideBuildCmd=0 BuildCmd= ! [Unit36] ! FileName=src\engine.h CompileCpp=1 Folder=fftrader *************** *** 200,205 **** BuildCmd= ! [Unit19] ! FileName=src\math.cpp CompileCpp=1 Folder=fftrader --- 218,223 ---- BuildCmd= ! [Unit1] ! FileName=src\aries.cpp CompileCpp=1 Folder=fftrader *************** *** 210,215 **** BuildCmd= ! [Unit21] ! FileName=src\input.h CompileCpp=1 Folder=fftrader --- 228,233 ---- BuildCmd= ! [Unit2] ! FileName=src\aries.h CompileCpp=1 Folder=fftrader *************** *** 220,226 **** BuildCmd= ! [Unit22] ! FileName=src\input.cpp ! CompileCpp=1 Folder=fftrader Compile=1 --- 238,244 ---- BuildCmd= ! [Unit3] ! FileName=src\bitmask.c ! CompileCpp=0 Folder=fftrader Compile=1 *************** *** 228,235 **** Priority=1000 OverrideBuildCmd=0 ! BuildCmd= ! [Unit23] ! FileName=src\guiapply.cpp CompileCpp=1 Folder=fftrader --- 246,253 ---- Priority=1000 OverrideBuildCmd=0 ! BuildCmd=$(CC) -c bitmask.c -o ./out/bitmask.o $(CFLAGS) ! [Unit4] ! FileName=src\bitmask.h CompileCpp=1 Folder=fftrader *************** *** 240,263 **** BuildCmd= ! [VersionInfo] ! Major=0 ! Minor=1 ! Release=1 ! Build=1 ! LanguageID=1033 ! CharsetID=1252 ! CompanyName= ! FileVersion= ! FileDescription=Developed using the Dev-C++ IDE ! InternalName= ! LegalCopyright= ! LegalTrademarks= ! OriginalFilename= ! ProductName= ! ProductVersion= ! AutoIncBuildNr=0 ! ! [Unit24] ! FileName=src\gui.cpp CompileCpp=1 Folder=fftrader --- 258,263 ---- BuildCmd= ! [Unit5] ! FileName=src\engine.cpp CompileCpp=1 Folder=fftrader *************** *** 268,274 **** BuildCmd= ! [Unit25] ! FileName=src\bitmask.c ! CompileCpp=0 Folder=fftrader Compile=1 --- 268,274 ---- BuildCmd= ! [Unit6] ! FileName=src\engine.h ! CompileCpp=1 Folder=fftrader Compile=1 *************** *** 276,283 **** Priority=1000 OverrideBuildCmd=0 ! BuildCmd=$(CC) -c bitmask.c -o ./out/bitmask.o $(CFLAGS) ! [Unit26] ! FileName=src\mac.h CompileCpp=1 Folder=fftrader --- 276,283 ---- Priority=1000 OverrideBuildCmd=0 ! BuildCmd= ! [Unit7] ! FileName=src\fftfile.cpp CompileCpp=1 Folder=fftrader *************** *** 288,293 **** BuildCmd= ! [Unit27] ! FileName=src\graphics.cpp CompileCpp=1 Folder=fftrader --- 288,293 ---- BuildCmd= ! [Unit8] ! FileName=src\fftfile.h CompileCpp=1 Folder=fftrader *************** *** 298,303 **** BuildCmd= ! [Unit28] ! FileName=src\graphics.h CompileCpp=1 Folder=fftrader --- 298,303 ---- BuildCmd= ! [Unit9] ! FileName=src\graphics.cpp CompileCpp=1 Folder=fftrader *************** *** 308,313 **** BuildCmd= ! [Unit29] ! FileName=src\aries.h CompileCpp=1 Folder=fftrader --- 308,313 ---- BuildCmd= ! [Unit10] ! FileName=src\graphics.h CompileCpp=1 Folder=fftrader *************** *** 318,323 **** BuildCmd= ! [Unit20] ! FileName=src\guiapply.h CompileCpp=1 Folder=fftrader --- 318,323 ---- BuildCmd= ! [Unit11] ! FileName=src\gui.cpp CompileCpp=1 Folder=fftrader *************** *** 328,333 **** BuildCmd= ! [Unit1] ! FileName=src\units.h CompileCpp=1 Folder=fftrader --- 328,333 ---- BuildCmd= ! [Unit15] ! FileName=src\input.cpp CompileCpp=1 Folder=fftrader *************** *** 338,343 **** BuildCmd= ! [Unit30] ! FileName=src\aries.cpp CompileCpp=1 Folder=fftrader --- 338,343 ---- BuildCmd= ! [Unit16] ! FileName=src\input.h CompileCpp=1 Folder=fftrader *************** *** 348,352 **** BuildCmd= ! [Unit31] FileName=src\log.cpp CompileCpp=1 --- 348,352 ---- BuildCmd= ! [Unit17] FileName=src\log.cpp CompileCpp=1 *************** *** 358,363 **** BuildCmd= ! [Unit32] ! FileName=src\log.h CompileCpp=1 Folder=fftrader --- 358,363 ---- BuildCmd= ! [Unit19] ! FileName=src\main.cpp CompileCpp=1 Folder=fftrader *************** *** 368,373 **** BuildCmd= ! [Unit33] ! FileName=src\py_baselib.cpp CompileCpp=1 Folder=fftrader --- 368,373 ---- BuildCmd= ! [Unit21] ! FileName=src\map.h CompileCpp=1 Folder=fftrader *************** *** 378,383 **** BuildCmd= ! [Unit34] ! FileName=src\py_baselib.h CompileCpp=1 Folder=fftrader --- 378,383 ---- BuildCmd= ! [Unit23] ! FileName=src\mapobject.h CompileCpp=1 Folder=fftrader *************** *** 388,393 **** BuildCmd= ! [Unit35] ! FileName=src\py_load.h CompileCpp=1 Folder=fftrader --- 388,393 ---- BuildCmd= ! [Unit25] ! FileName=src\math.h CompileCpp=1 Folder=fftrader *************** *** 398,413 **** BuildCmd= ! [Unit36] ! FileName=src\py_load.cpp ! CompileCpp=1 Folder=fftrader Compile=1 ! Link=1 Priority=1000 OverrideBuildCmd=0 BuildCmd= ! [Unit37] ! FileName=src\engine.cpp CompileCpp=1 Folder=fftrader --- 398,412 ---- BuildCmd= ! [Unit29] ! FileName=src\resource.rc Folder=fftrader Compile=1 ! Link=0 Priority=1000 OverrideBuildCmd=0 BuildCmd= ! [Unit30] ! FileName=src\scenario.cpp CompileCpp=1 Folder=fftrader *************** *** 418,423 **** BuildCmd= ! [Unit38] ! FileName=src\engine.h CompileCpp=1 Folder=fftrader --- 417,422 ---- BuildCmd= ! [Unit31] ! FileName=src\scenario.h CompileCpp=1 Folder=fftrader Index: fftrader.dsp =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dsp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** fftrader.dsp 19 Aug 2005 22:39:52 -0000 1.12 --- fftrader.dsp 21 Aug 2005 11:29:49 -0000 1.13 *************** *** 150,157 **** # Begin Source File - SOURCE=.\src\py_load.cpp - # End Source File - # Begin Source File - SOURCE=.\src\scenario.cpp # End Source File --- 150,153 ---- *************** *** 222,229 **** # Begin Source File - SOURCE=.\src\py_load.h - # End Source File - # Begin Source File - SOURCE=.\src\scenario.h # End Source File --- 218,221 ---- |
From: TomT64 <to...@us...> - 2005-08-21 11:29:58
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5247/src Modified Files: engine.cpp engine.h py_baselib.cpp py_baselib.h Removed Files: py_load.cpp py_load.h Log Message: Update to Python Engine, still no scripting Index: engine.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** engine.cpp 19 Aug 2005 22:39:52 -0000 1.1 --- engine.cpp 21 Aug 2005 11:29:49 -0000 1.2 *************** *** 1,4 **** --- 1,11 ---- #include "engine.h" + extern PyMethodDef fftMethods[]; + extern PyMethodDef catchMethods[]; + + PyObject* module; + PyObject* catchmodule; + PyObject* objectiveModule; + Engine::Engine() { *************** *** 14,18 **** starfields.clear(); Py_Initialize(); ! LoadPythonLibraries(); } Engine::~Engine() --- 21,50 ---- starfields.clear(); Py_Initialize(); ! Log::Write("Loading FFTrader Python Library"); ! PyImport_AddModule("fft"); ! module = Py_InitModule3("fft", fftMethods, "fft standard module.\n"); ! ! PyImport_AddModule("catch"); ! catchmodule = Py_InitModule3("catch", catchMethods, "catch sysout and syserr.\n"); ! ! PyRun_SimpleString("import sys; sys.path.insert(0, '.')"); ! ! PyObject* sysModule = PyImport_ImportModule("sys"); ! PyObject_SetAttrString(sysModule, "stdout", catchmodule); ! PyObject_SetAttrString(sysModule, "stderr", catchmodule); ! ! PyRun_SimpleString( ! "import fft\n" ! "def MyFunc():\n" ! "\treturn 1\n" ! "fft.Victory=MyFunc\n" ! ); ! PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there), ! PyObject *pFunc = PyDict_GetItemString(pDict, "Victory"); ! Log::Write("ok so far"); ! PyObject *test=PyObject_CallFunction(pFunc, 0); ! if(PyObject_IsTrue(test)) Log::Write("method is true"); ! else Log::Write("method is false"); ! Log::Write("got through!"); } Engine::~Engine() *************** *** 46,49 **** --- 78,84 ---- Mix_CloseAudio(); + Py_XDECREF(module); + Py_XDECREF(catchmodule); + Py_XDECREF(objectiveModule); Py_Finalize(); PHYSFS_deinit(); --- py_load.h DELETED --- Index: py_baselib.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** py_baselib.h 19 Aug 2005 22:39:52 -0000 1.1 --- py_baselib.h 21 Aug 2005 11:29:49 -0000 1.2 *************** *** 6,9 **** --- 6,11 ---- PyObject* fft_log(PyObject* self, PyObject* args); + PyObject* fft_victory(PyObject* self); + PyObject* fft_loss(PyObject* self); PyObject* fft_exit(PyObject* self, PyObject* args); Index: engine.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** engine.h 19 Aug 2005 22:39:52 -0000 1.1 --- engine.h 21 Aug 2005 11:29:49 -0000 1.2 *************** *** 4,12 **** #include <deque> #include <string> #include "SDL_mixer.h" #include "SDL_ttf.h" #include "gui.h" #include "log.h" - #include "py_load.h" #include "scenario.h" #include "units.h" --- 4,12 ---- #include <deque> #include <string> + #include "Python.h" #include "SDL_mixer.h" #include "SDL_ttf.h" #include "gui.h" #include "log.h" #include "scenario.h" #include "units.h" --- py_load.cpp DELETED --- Index: py_baselib.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** py_baselib.cpp 19 Aug 2005 22:39:52 -0000 1.1 --- py_baselib.cpp 21 Aug 2005 11:29:49 -0000 1.2 *************** *** 7,10 **** --- 7,12 ---- { {"Exit", fft_exit, METH_VARARGS, "Exit(message)\nExits the current game displaying \"message\", then returns to the main menu\n"}, + {"Victory", (PyCFunction)fft_victory, METH_NOARGS, "Victory()\nFunction which exists for the sole purpose of determining when victory conditions are met. To make this work, you have to create your own victory function (returning a non zero number on loss, and a 0 otherwise) and set fft.Victory equal to it. The function must have no arguments to work properly. This function will have no effect when called from the script.\n"}, + {"Loss", (PyCFunction)fft_loss, METH_NOARGS, "Loss()\nFunction which exists for the sole purpose of determining when losing conditions are met. To make this work, you have to create your own loss function (returning a non zero number on loss, and a 0 otherwise) and set fft.Loss equal to it. The function must have no arguments to work properly. This function will have no effect when called from the script.\n"}, {0} }; *************** *** 26,29 **** --- 28,39 ---- return Py_None; } + PyObject* fft_victory(PyObject* self) + { + return Py_BuildValue("i", 0); + } + PyObject* fft_loss(PyObject* self) + { + return Py_BuildValue("i", 0); + } PyObject* fft_exit(PyObject* self, PyObject* args) { |
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25444/src Modified Files: guiapply.cpp guiapply.h main.cpp scenario.h Added Files: engine.cpp engine.h py_baselib.cpp py_baselib.h py_load.cpp py_load.h Log Message: Started adding Python to the engine Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.cpp 19 Aug 2005 08:22:34 -0000 1.2 --- main.cpp 19 Aug 2005 22:39:52 -0000 1.3 *************** *** 10,13 **** --- 10,14 ---- SDL_gfx >= 2.0.8 physfs (with zip support) >= 0.1.9 + Python 2.4.x SDL and its libraries may be found easily through Google *************** *** 51,54 **** --- 52,56 ---- Scenario *mainScen; Unit *ship; + Engine *engine; Map *map; GUI *gui2; *************** *** 106,111 **** // We initalize the random number generator srand(time(NULL)); ! ! // We store the state of keys here SDL_Surface *screen=SDL_GetVideoSurface(); --- 108,112 ---- // We initalize the random number generator srand(time(NULL)); ! engine=new Engine(); SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 128,131 **** --- 129,133 ---- delete fftinput; fftinput=prefs->GetInput(); + engine->SetInput(fftinput); PHYSFS_addToSearchPath("fpk/base.fpk", 1); //load base packfile SCREEN_WIDTH = 640; *************** *** 144,147 **** --- 146,150 ---- // handle error } + engine->AddFont("font10",font); font2=LoadTTF("fonts/arial.ttf", 14); if(!font2) { *************** *** 149,152 **** --- 152,156 ---- // handle error } + engine->AddFont("font14",font2); Log::Write("Main Fonts loaded"); *************** *** 171,174 **** --- 175,179 ---- SDL_WM_SetCaption("Final Frontier Trader", "Final Frontier Trader"); SDL_Surface *icon = LoadICON("gfx/ico/fftico.png"); + engine->AddSurface("main icon",icon); SDL_WM_SetIcon(icon, NULL); Log::Write("Icon and caption in place"); *************** *** 180,183 **** --- 185,189 ---- SDL_Surface *bg = LoadIMG("gfx/startupbg.png"); + engine->AddSurface("splash screen",bg); DrawIMG(bg,0,0); SDL_Flip(screen); *************** *** 188,191 **** --- 194,199 ---- stars->Init(SCREEN_WIDTH, SCREEN_HEIGHT); stars2->Init(SCREEN_WIDTH, SCREEN_HEIGHT); + engine->AddStarfield(stars, false); + engine->AddStarfield(stars2, true); Log::Write("Beginning warp stars initialized"); *************** *** 207,214 **** --- 215,224 ---- ship = new Unit; ship->Init(0, 0, "gfx/ship/ship.png","base.fpk",(float)0.1); + engine->SetMainShip(ship); Log::Write("Main ship initialized"); map = new Map; map->Init(1); + engine->SetMap(map); Log::Write("Map initialized"); *************** *** 219,226 **** --- 229,239 ---- shot = LoadSound("sound/shoot.wav"); explode = LoadSound("sound/expl01.wav"); + engine->AddSound("shot", shot); + engine->AddSound("explode", explode); Log::Write("Audio initialized and sounds loaded"); gui2=new GUI; gui2->Init(); + engine->AddGUI("openmessage",gui2); SDL_Delay(1000); *************** *** 233,237 **** screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE|SDL_FULLSCREEN); } ! else exit(0); } else if (fullscreen) --- 246,250 ---- screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE|SDL_FULLSCREEN); } ! else engine->Quit(); } else if (fullscreen) *************** *** 241,245 **** screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN); } ! else exit(0); } else if (software) screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_SWSURFACE); --- 254,258 ---- screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN); } ! else engine->Quit(); } else if (software) screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_SWSURFACE); *************** *** 282,303 **** /* clean up */ ! SDL_FreeSurface(bg); ! delete fftinput; ! delete gui2; ! delete stars; ! delete stars2; ! delete ship; ! delete map; ! delete mainScen; ! Mix_FreeChunk(shot); ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! SDL_FreeSurface(icon); ! TTF_CloseFont(font); ! TTF_CloseFont(font2); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! Log::Write("Thank you for playing!"); return 0; --- 295,299 ---- /* clean up */ ! engine->Quit(); return 0; *************** *** 334,353 **** // close button clicked case SDL_QUIT: - delete fftinput; - delete gui2; delete gui3; ! delete stars; ! delete stars2; ! delete ship; ! delete map; ! Mix_FreeChunk(shot); ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! TTF_CloseFont(font); ! TTF_CloseFont(font2); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); break; --- 330,335 ---- // close button clicked case SDL_QUIT: delete gui3; ! engine->Quit(); break; *************** *** 540,566 **** fpkships=LoadShipsFromScen(mainScen); int quit=NewShipOptions(SCREEN_WIDTH, SCREEN_HEIGHT, fpkships); ! if (quit==-1) ! { ! delete fftinput; ! delete gui2; ! delete stars; ! delete stars2; ! delete ship; ! delete map; ! delete mainScen; ! Mix_FreeChunk(shot); ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! TTF_CloseFont(font); ! TTF_CloseFont(font2); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); ! } ! if (quit==1) ! { ! return false; ! } Uint32 ticks=SDL_GetTicks(); Log::Write("Loading Game..."); --- 522,527 ---- fpkships=LoadShipsFromScen(mainScen); int quit=NewShipOptions(SCREEN_WIDTH, SCREEN_HEIGHT, fpkships); ! if (quit==-1) engine->Quit(); ! if (quit==1) return false; Uint32 ticks=SDL_GetTicks(); Log::Write("Loading Game..."); *************** *** 571,574 **** --- 532,536 ---- map = new Map; map->Init(zoom); + engine->SetMap(map); Log::Write("Setting map to scenario"); mainScen->SetMap(map); *************** *** 658,661 **** --- 620,624 ---- Log::Write("Variables set, displaying opening message"); TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); + engine->AddFont("font9",font9); while(!done) { *************** *** 1078,1082 **** } } - TTF_CloseFont(font9); delete FPS; return done; --- 1041,1044 ---- Index: guiapply.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/guiapply.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** guiapply.h 19 Aug 2005 07:32:29 -0000 1.1 --- guiapply.h 19 Aug 2005 22:39:52 -0000 1.2 *************** *** 2,12 **** #define __GUIAPPLY_H__ #include "gui.h" #include "graphics.h" #include "input.h" #include "fftfile.h" - #include "units.h" ! extern Unit *ship; extern FFTInput *fftinput; extern Preferences *prefs; --- 2,12 ---- #define __GUIAPPLY_H__ + #include "engine.h" #include "gui.h" #include "graphics.h" #include "input.h" #include "fftfile.h" ! extern Engine *engine; extern FFTInput *fftinput; extern Preferences *prefs; --- NEW FILE: engine.cpp --- #include "engine.h" Engine::Engine() { Log::Write("Initializing Engine"); mainship=0; mainscen=0; maininput=0; mainmap=0; fonts.clear(); guis.clear(); sounds.clear(); surfaces.clear(); starfields.clear(); Py_Initialize(); LoadPythonLibraries(); } Engine::~Engine() { this->Quit(); } void Engine::Quit() { int i; for(i=0; i<(int)sounds.size(); i++) { Mix_FreeChunk(sounds[i].sound); } for(i=0; i<(int)fonts.size(); i++) { TTF_CloseFont(fonts[i].font); } for(i=0; i<(int)surfaces.size(); i++) { SDL_FreeSurface(surfaces[i].surface); } delete mainmap; delete mainship; delete mainscen; delete maininput; fonts.clear(); guis.clear(); sounds.clear(); surfaces.clear(); starfields.clear(); Mix_CloseAudio(); Py_Finalize(); PHYSFS_deinit(); TTF_Quit(); SDL_Quit(); Log::Write("Thank you for playing!"); } Unit *Engine::GetMainShip() { return mainship; } void Engine::SetMainShip(Unit *ship) { mainship=ship; } Scenario *Engine::GetMainScenario() { return mainscen; } void Engine::SetMainScenario(Scenario *scen) { mainscen=scen; } FFTInput *Engine::GetInput() { return maininput; } void Engine::SetInput(FFTInput *input) { maininput=input; } Map *Engine::GetMap() { return mainmap; } void Engine::SetMap(Map* map) { mainmap=map; } TTF_Font *Engine::GetFont(std::string name) { int i; for(i=0; i<(int)fonts.size(); i++) { if (!strcmp(name.c_str(),fonts[i].name.c_str())) return fonts[i].font; } return 0; } void Engine::AddFont(std::string name, TTF_Font *font) { if(this->GetFont(name)) { FFTFont fftfont; fftfont.font=font; fftfont.name=name; fonts.push_back(fftfont); } else { int i; for(i=0; i<(int)fonts.size(); i++) { if (!strcmp(name.c_str(),fonts[i].name.c_str())) { TTF_CloseFont(fonts[i].font); fonts[i].font=font; } } } } Mix_Chunk *Engine::GetSound(std::string name) { int i; for(i=0; i<(int)sounds.size(); i++) { if (!strcmp(name.c_str(),sounds[i].name.c_str())) return sounds[i].sound; } return 0; } void Engine::AddSound(std::string name, Mix_Chunk *sound) { if(this->GetSound(name)) { FFTSound fftsound; fftsound.sound=sound; fftsound.name=name; sounds.push_back(fftsound); } else { int i; for(i=0; i<(int)sounds.size(); i++) { if (!strcmp(name.c_str(),sounds[i].name.c_str())) { Mix_FreeChunk(sounds[i].sound); sounds[i].sound=sound; } } } } GUI *Engine::GetGUI(std::string name) { int i; for(i=0; i<(int)guis.size(); i++) { if (!strcmp(name.c_str(),guis[i].name.c_str())) return guis[i].gui; } return 0; } void Engine::AddGUI(std::string name, GUI *gui) { if(this->GetSound(name)) { FFTGUI fftgui; fftgui.gui=gui; fftgui.name=name; guis.push_back(fftgui); } else { int i; for(i=0; i<(int)guis.size(); i++) { if (!strcmp(name.c_str(),guis[i].name.c_str())) { delete guis[i].gui; guis[i].gui=gui; } } } } SDL_Surface *Engine::GetSurface(std::string name) { int i; for(i=0; i<(int)surfaces.size(); i++) { if (!strcmp(name.c_str(),surfaces[i].name.c_str())) return surfaces[i].surface; } return 0; } void Engine::AddSurface(std::string name, SDL_Surface *surface) { if(this->GetSound(name)) { FFTSurface fftsurface; fftsurface.surface=surface; fftsurface.name=name; surfaces.push_back(fftsurface); } else { int i; for(i=0; i<(int)surfaces.size(); i++) { if (!strcmp(name.c_str(),surfaces[i].name.c_str())) { delete surfaces[i].surface; surfaces[i].surface=surface; } } } } void Engine::AddStarfield(StarField *stars, bool above) { FFTStars fftstars; fftstars.stars=stars; fftstars.above=above; starfields.push_back(fftstars); } --- NEW FILE: py_load.h --- #ifndef __PY_LOAD_H__ #define __PY_LOAD_H__ #include "Python.h" #include "log.h" void LoadPythonLibraries(); #endif /* __PY_LOAD_H__ */ --- NEW FILE: py_baselib.h --- #ifndef __PY_BASELIB_H__ #define __PY_BASELIB_H__ #include "Python.h" #include "guiapply.h" PyObject* fft_log(PyObject* self, PyObject* args); PyObject* fft_exit(PyObject* self, PyObject* args); #endif /* __PY_BASELIB_H__ */ --- NEW FILE: engine.h --- #ifndef __ENGINE_H__ #define __ENGINE_H__ #include <deque> #include <string> #include "SDL_mixer.h" #include "SDL_ttf.h" #include "gui.h" #include "log.h" #include "py_load.h" #include "scenario.h" #include "units.h" struct FFTFont { TTF_Font *font; std::string name; }; struct FFTGUI { GUI *gui; std::string name; }; struct FFTStars { StarField *stars; bool above; }; struct FFTSound { Mix_Chunk *sound; std::string name; }; struct FFTSurface { SDL_Surface *surface; std::string name; }; class Engine { public: Engine(); ~Engine(); void Quit(); Unit *GetMainShip(); void SetMainShip(Unit *ship); Scenario *GetMainScenario(); void SetMainScenario(Scenario *scen); FFTInput *GetInput(); void SetInput(FFTInput *input); Map *GetMap(); void SetMap(Map* map); TTF_Font *GetFont(std::string name); void AddFont(std::string name, TTF_Font *font); Mix_Chunk *GetSound(std::string name); void AddSound(std::string name, Mix_Chunk *sound); GUI *GetGUI(std::string name); void AddGUI(std::string name, GUI *gui); SDL_Surface *GetSurface(std::string name); void AddSurface(std::string name, SDL_Surface *surface); void AddStarfield(StarField *stars, bool above); private: Unit *mainship; Scenario *mainscen; FFTInput *maininput; Map *mainmap; std::deque<FFTFont> fonts; std::deque<FFTGUI> guis; std::deque<FFTSound> sounds; std::deque<FFTSurface> surfaces; std::deque<FFTStars> starfields; }; #endif /* __ENGINE_H__ */ Index: scenario.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scenario.h 19 Aug 2005 08:22:34 -0000 1.2 --- scenario.h 19 Aug 2005 22:39:52 -0000 1.3 *************** *** 2,11 **** #define __FFTSCEN_H__ - #include "Python.h" #include <string> #include "fftfile.h" #include "gui.h" #include "map.h" - #include "units.h" using aries::newNode; --- 2,9 ---- *************** *** 16,21 **** using aries::NodeList; - extern Unit *ship; - void LoadMap(Map *map, const std::string& filename, float zoom); --- 14,17 ---- Index: guiapply.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/guiapply.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** guiapply.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- guiapply.cpp 19 Aug 2005 22:39:52 -0000 1.2 *************** *** 47,51 **** // close button clicked case SDL_QUIT: ! done=-1; break; --- 47,55 ---- // close button clicked case SDL_QUIT: ! TTF_CloseFont(font); ! delete startingGUI; ! delete stars; ! delete stars2; ! engine->Quit(); break; *************** *** 705,717 **** // close button clicked case SDL_QUIT: - delete fftinput; delete gui3; ! delete ship; ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); break; --- 709,715 ---- // close button clicked case SDL_QUIT: delete gui3; ! SDL_FreeSurface(bg); ! engine->Quit(); break; *************** *** 805,817 **** // close button clicked case SDL_QUIT: - delete fftinput; delete gui3; ! delete ship; ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); break; --- 803,809 ---- // close button clicked case SDL_QUIT: delete gui3; ! SDL_FreeSurface(bg); ! engine->Quit(); break; *************** *** 904,916 **** // close button clicked case SDL_QUIT: - delete fftinput; delete gui3; ! delete ship; ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); break; --- 896,902 ---- // close button clicked case SDL_QUIT: delete gui3; ! SDL_FreeSurface(bg); ! engine->Quit(); break; *************** *** 992,1004 **** // close button clicked case SDL_QUIT: - delete fftinput; delete gui3; ! delete ship; ! Mix_FreeChunk(explode); ! Mix_CloseAudio(); ! PHYSFS_deinit(); ! TTF_Quit(); ! SDL_Quit(); ! exit(0); break; --- 978,984 ---- // close button clicked case SDL_QUIT: delete gui3; ! SDL_FreeSurface(bg); ! engine->Quit(); break; --- NEW FILE: py_load.cpp --- #include "py_load.h" extern PyMethodDef fftMethods[]; extern PyMethodDef catchMethods[]; void LoadPythonLibraries() { Log::Write("Loading FFTrader Python Library"); PyImport_AddModule("fft"); PyObject* module = Py_InitModule3("fft", fftMethods, "fft standard module.\n"); PyImport_AddModule("catch"); PyObject* catchmodule = Py_InitModule3("catch", catchMethods, "catch sysout and syserr.\n"); PyRun_SimpleString("import sys; sys.path.insert(0, '.')"); PyObject* sysModule = PyImport_ImportModule("sys"); PyObject_SetAttrString(sysModule, "stdout", catchmodule); PyObject_SetAttrString(sysModule, "stderr", catchmodule); } --- NEW FILE: py_baselib.cpp --- #include "py_baselib.h" extern int SCREEN_WIDTH; extern int SCREEN_HEIGHT; PyMethodDef fftMethods[] = { {"Exit", fft_exit, METH_VARARGS, "Exit(message)\nExits the current game displaying \"message\", then returns to the main menu\n"}, {0} }; PyMethodDef catchMethods[] = { {"write", fft_log, METH_VARARGS, "write function to override sysout and syserr"}, {0} }; PyObject* fft_log(PyObject* self, PyObject* args) { char* LogStr = NULL; if (!PyArg_ParseTuple(args, "s", &LogStr)) return NULL; Log::Writen(LogStr); Py_INCREF(Py_None); return Py_None; } PyObject* fft_exit(PyObject* self, PyObject* args) { char* ExitStr = NULL; if (!PyArg_ParseTuple(args, "s", &ExitStr)) return NULL; Log::Write("Exiting the game via fft.Exit() with message \"%s\"",ExitStr); ExitToMenuBox(SCREEN_WIDTH, SCREEN_HEIGHT, ExitStr); Py_INCREF(Py_None); return Py_None; } |
From: TomT64 <to...@us...> - 2005-08-19 22:39:59
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25444 Modified Files: fftrader.dev fftrader.dsp Log Message: Started adding Python to the engine Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** fftrader.dev 19 Aug 2005 08:22:34 -0000 1.10 --- fftrader.dev 19 Aug 2005 22:39:52 -0000 1.11 *************** *** 2,6 **** FileName=fftrader.dev Name=fftrader ! UnitCount=32 Type=0 Ver=1 --- 2,6 ---- FileName=fftrader.dev Name=fftrader ! UnitCount=38 Type=0 Ver=1 *************** *** 13,17 **** Compiler= CppCompiler=_@@_ ! Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lz_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 Icon= --- 13,17 ---- Compiler= CppCompiler=_@@_ ! Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lpython24_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 Icon= *************** *** 368,369 **** --- 368,429 ---- BuildCmd= + [Unit33] + FileName=src\py_baselib.cpp + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit34] + FileName=src\py_baselib.h + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit35] + FileName=src\py_load.h + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit36] + FileName=src\py_load.cpp + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit37] + FileName=src\engine.cpp + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit38] + FileName=src\engine.h + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + Index: fftrader.dsp =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dsp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** fftrader.dsp 19 Aug 2005 08:23:49 -0000 1.11 --- fftrader.dsp 19 Aug 2005 22:39:52 -0000 1.12 *************** *** 54,58 **** LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDLmain.lib SDL.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib SDL_gfx.lib physfs.lib opengl32.lib /nologo /subsystem:windows /machine:I386 /out:"fftrader.exe" # SUBTRACT LINK32 /pdb:none --- 54,58 ---- LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDLmain.lib SDL.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib SDL_gfx.lib physfs.lib opengl32.lib python24.lib /nologo /subsystem:windows /machine:I386 /out:"fftrader.exe" # SUBTRACT LINK32 /pdb:none *************** *** 81,85 **** LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDLmain.lib SDL.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib SDL_gfx.lib physfs.lib opengl32.lib /nologo /subsystem:windows /debug /machine:I386 /out:"fftrader-debug.exe" /pdbtype:sept !ENDIF --- 81,85 ---- LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDLmain.lib SDL.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib SDL_gfx.lib physfs.lib opengl32.lib python24_d.lib /nologo /subsystem:windows /debug /machine:I386 /out:"fftrader-debug.exe" /pdbtype:sept !ENDIF *************** *** 102,105 **** --- 102,109 ---- # Begin Source File + SOURCE=.\src\engine.cpp + # End Source File + # Begin Source File + SOURCE=.\src\fftfile.cpp # End Source File *************** *** 142,145 **** --- 146,157 ---- # Begin Source File + SOURCE=.\src\py_baselib.cpp + # End Source File + # Begin Source File + + SOURCE=.\src\py_load.cpp + # End Source File + # Begin Source File + SOURCE=.\src\scenario.cpp # End Source File *************** *** 166,169 **** --- 178,185 ---- # Begin Source File + SOURCE=.\src\engine.h + # End Source File + # Begin Source File + SOURCE=.\src\fftfile.h # End Source File *************** *** 202,205 **** --- 218,229 ---- # Begin Source File + SOURCE=.\src\py_baselib.h + # End Source File + # Begin Source File + + SOURCE=.\src\py_load.h + # End Source File + # Begin Source File + SOURCE=.\src\scenario.h # End Source File |
From: TomT64 <to...@us...> - 2005-08-19 08:23:58
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26221 Modified Files: fftrader.dsp Log Message: Added Logger Index: fftrader.dsp =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dsp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** fftrader.dsp 19 Aug 2005 07:32:29 -0000 1.10 --- fftrader.dsp 19 Aug 2005 08:23:49 -0000 1.11 *************** *** 122,125 **** --- 122,129 ---- # Begin Source File + SOURCE=.\src\log.cpp + # End Source File + # Begin Source File + SOURCE=.\src\main.cpp # End Source File *************** *** 182,185 **** --- 186,193 ---- # Begin Source File + SOURCE=.\src\log.h + # End Source File + # Begin Source File + SOURCE=.\src\map.h # End Source File |
From: TomT64 <to...@us...> - 2005-08-19 08:22:46
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26008/src Modified Files: fftfile.cpp fftfile.h log.cpp log.h main.cpp map.cpp mapobject.cpp scenario.cpp scenario.h shop.cpp shop.h units.cpp units.h Log Message: Added Logger Index: units.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/units.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** units.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- units.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 685,689 **** this->RemoveWeaponFromSlot(slotid); this->NextWeapon(); ! if (LOG) printf("Removed and changed weapon\n"); } } --- 685,689 ---- this->RemoveWeaponFromSlot(slotid); this->NextWeapon(); ! Log::Write("Removed and changed weapon"); } } *************** *** 1089,1096 **** void Unit::FPK_NewImages(std::string fpk, std::string imagename) { ! if (LOG) printf("FPK_NewImages: Loading new image (%s) from fpk %s\n",imagename.c_str(),fpk.c_str()); usingfpk=fpk; imgload=imagename; ! if (LOG) printf("FPK_NewImages: Freeing existing images\n"); FreeImages(); if(hasShield) --- 1089,1096 ---- void Unit::FPK_NewImages(std::string fpk, std::string imagename) { ! Log::Write("FPK_NewImages: Loading new image (%s) from fpk %s",imagename.c_str(),fpk.c_str()); usingfpk=fpk; imgload=imagename; ! Log::Write("FPK_NewImages: Freeing existing images"); FreeImages(); if(hasShield) *************** *** 1104,1111 **** hasShield=false; } ! if (LOG) printf("FPK_NewImages: Loading new images\n"); LoadImages(0, 71); int i; ! if (LOG) printf("FPK_NewImages: Making new bitmasks\n"); for (i=0; i<UNITS_NUM_FRAMES; i++) { --- 1104,1111 ---- hasShield=false; } ! Log::Write("FPK_NewImages: Loading new images"); LoadImages(0, 71); int i; ! Log::Write("FPK_NewImages: Making new bitmasks"); for (i=0; i<UNITS_NUM_FRAMES; i++) { *************** *** 1127,1131 **** if (end<0) { end=0; } if (start<0) { start=0; } ! if (LOG) printf("Unit::LoadImages: Loading base image (%s) from fpk %s\n",imgload.c_str(),usingfpk.c_str()); temp=FPK_LoadIMG(usingfpk, imgload); if (dispimg) --- 1127,1131 ---- if (end<0) { end=0; } if (start<0) { start=0; } ! Log::Write("Unit::LoadImages: Loading base image (%s) from fpk %s",imgload.c_str(),usingfpk.c_str()); temp=FPK_LoadIMG(usingfpk, imgload); if (dispimg) *************** *** 1134,1149 **** dispimg=0; } ! if (LOG) printf("Unit::LoadImages: Setting display image\n"); dispimg=rotozoomSurface(temp, 0, 0.5, SMOOTH); if (cr>0 || cg>0 || cb>0) { ! if (LOG) printf("Unit::LoadImages: Colorizing images\n"); ColorizeSurface(temp, cr, cg, cb); ColorizeSurface(dispimg, cr, cg, cb); } ! if (LOG) printf("Unit::LoadImages: Freeing images and reloading: "); for (i=start; i<=end; i++) { ! if (LOG) printf("%d, ",i); if (image[i]) { --- 1134,1149 ---- dispimg=0; } ! Log::Write("Unit::LoadImages: Setting display image"); dispimg=rotozoomSurface(temp, 0, 0.5, SMOOTH); if (cr>0 || cg>0 || cb>0) { ! Log::Write("Unit::LoadImages: Colorizing images"); ColorizeSurface(temp, cr, cg, cb); ColorizeSurface(dispimg, cr, cg, cb); } ! Log::Writen("Unit::LoadImages: Freeing images and reloading: "); for (i=start; i<=end; i++) { ! Log::Writen("%d, ",i); if (image[i]) { *************** *** 1153,1160 **** image[i]=rotozoomSurface(temp, 360-i*angleinc, zoom, SMOOTH); } ! if (LOG) printf("\n"); if (hasShield) { ! if (LOG) printf("Loading shield\n"); SDL_FreeSurface(temp); temp=0; --- 1153,1160 ---- image[i]=rotozoomSurface(temp, 360-i*angleinc, zoom, SMOOTH); } ! Log::Writen("\n"); if (hasShield) { ! Log::Write("Loading shield"); SDL_FreeSurface(temp); temp=0; Index: main.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/main.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- main.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 58,63 **** int SMOOTH=1; bool FPSSHOW=false; ! bool LOG=false; ! std::string VERSION="0.66"; static int mainLoop(); --- 58,62 ---- int SMOOTH=1; bool FPSSHOW=false; ! std::string VERSION="0.70 alpha"; static int mainLoop(); *************** *** 100,108 **** if (!strcmp(argv[i],"-log")) { ! LOG=true; } } } ! if (LOG) printf("Final Frontier Trader\nversion %s\nby TomT64\n------------\n\n",VERSION.c_str()); // We initalize the random number generator srand(time(NULL)); --- 99,107 ---- if (!strcmp(argv[i],"-log")) { ! Log::Init("fft.log"); } } } ! Log::Write("Final Frontier Trader\nversion %s\nby TomT64\n------------\n",VERSION.c_str()); // We initalize the random number generator srand(time(NULL)); *************** *** 115,131 **** if (!init) { ! printf("Failed to initialize PHYSFS. Reason: %s\n",PHYSFS_getLastError()); exit(1); } ! if (LOG) ! { ! printf("PHYSFS initialized successfully\n"); ! char **i; ! for (i = PHYSFS_getSearchPath(); *i != NULL; i++) ! printf("[%s] is in the search path.at the beginning of execution\n", *i); ! } PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 0); //fpk dir PHYSFS_setWriteDir(PHYSFS_getBaseDir()); ! if (LOG) printf("Loading Preferences\n"); prefs=new Preferences("prefs"); delete fftinput; --- 114,128 ---- if (!init) { ! Log::Write("Failed to initialize PHYSFS. Reason: %s",PHYSFS_getLastError()); exit(1); } ! Log::Write("PHYSFS initialized successfully"); ! char **i; ! for (i = PHYSFS_getSearchPath(); *i != NULL; i++) ! Log::Write("[%s] is in the search path.at the beginning of execution", *i); ! PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 0); //fpk dir PHYSFS_setWriteDir(PHYSFS_getBaseDir()); ! Log::Write("Loading Preferences"); prefs=new Preferences("prefs"); delete fftinput; *************** *** 136,173 **** if(TTF_Init()==-1) { ! printf("TTF_Init: %s\n", TTF_GetError()); exit(2); } ! if (LOG) printf("SDL_ttf initialized successfully\n"); // load font font=LoadTTF("fonts/arial.ttf", 10); if(!font) { ! printf("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s\n", TTF_GetError()); // handle error } font2=LoadTTF("fonts/arial.ttf", 14); if(!font2) { ! printf("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s\n", TTF_GetError()); // handle error } ! if (LOG) printf("Main Fonts loaded\n"); /* initialize SDL */ #ifdef DEBUG if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) { ! fprintf(stderr, "Could not initialize SDL: %s\n", ! SDL_GetError()); return -1; } #else if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0 ) { ! fprintf(stderr, "Could not initialize SDL: %s\n", ! SDL_GetError()); return -1; } #endif ! if (LOG) printf("SDL initialized successfully\n"); //atexit(SDL_Quit); --- 133,168 ---- if(TTF_Init()==-1) { ! Log::Write("TTF_Init: %s", TTF_GetError()); exit(2); } ! Log::Write("SDL_ttf initialized successfully"); // load font font=LoadTTF("fonts/arial.ttf", 10); if(!font) { ! Log::Write("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } font2=LoadTTF("fonts/arial.ttf", 14); if(!font2) { ! Log::Write("Unable to Open font 'fonts/arial.ttf' - TTF_OpenFont: %s", TTF_GetError()); // handle error } ! Log::Write("Main Fonts loaded"); /* initialize SDL */ #ifdef DEBUG if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) < 0 ) { ! Log::Write("Could not initialize SDL: %s",SDL_GetError()); return -1; } #else if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0 ) { ! Log::Write("Could not initialize SDL: %s",SDL_GetError()); return -1; } #endif ! Log::Write("SDL initialized successfully"); //atexit(SDL_Quit); *************** *** 177,191 **** SDL_Surface *icon = LoadICON("gfx/ico/fftico.png"); SDL_WM_SetIcon(icon, NULL); ! if (LOG) printf("Icon and caption in place\n"); /* create window */ screen = SDL_SetVideoMode(400, 300, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); //CenterWindow(); ! if (LOG) printf("Video mode set and centered\n"); SDL_Surface *bg = LoadIMG("gfx/startupbg.png"); DrawIMG(bg,0,0); SDL_Flip(screen); ! if (LOG) printf("Splash screen displayed\n"); stars = new StarField; --- 172,186 ---- SDL_Surface *icon = LoadICON("gfx/ico/fftico.png"); SDL_WM_SetIcon(icon, NULL); ! Log::Write("Icon and caption in place"); /* create window */ screen = SDL_SetVideoMode(400, 300, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); //CenterWindow(); ! Log::Write("Video mode set and centered"); SDL_Surface *bg = LoadIMG("gfx/startupbg.png"); DrawIMG(bg,0,0); SDL_Flip(screen); ! Log::Write("Splash screen displayed"); stars = new StarField; *************** *** 193,197 **** stars->Init(SCREEN_WIDTH, SCREEN_HEIGHT); stars2->Init(SCREEN_WIDTH, SCREEN_HEIGHT); ! if (LOG) printf("Beginning warp stars initialized\n"); char **k; --- 188,192 ---- stars->Init(SCREEN_WIDTH, SCREEN_HEIGHT); stars2->Init(SCREEN_WIDTH, SCREEN_HEIGHT); ! Log::Write("Beginning warp stars initialized"); char **k; *************** *** 208,229 **** } PHYSFS_freeList(fpklist); ! if (LOG) printf("All FPKs placed in search path\n"); ship = new Unit; ship->Init(0, 0, "gfx/ship/ship.png","base.fpk",(float)0.1); ! if (LOG) printf("Main ship initialized\n"); map = new Map; map->Init(1); ! if (LOG) printf("Map initialized\n"); if(Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 2048) < 0) { ! printf("Warning: Couldn't set 22050 Hz 16-bit audio\n\ ! - Reason: %s\n", SDL_GetError()); } shot = LoadSound("sound/shoot.wav"); explode = LoadSound("sound/expl01.wav"); ! if (LOG) printf("Audio initialized and sounds loaded\n"); gui2=new GUI; --- 203,223 ---- } PHYSFS_freeList(fpklist); ! Log::Write("All FPKs placed in search path"); ship = new Unit; ship->Init(0, 0, "gfx/ship/ship.png","base.fpk",(float)0.1); ! Log::Write("Main ship initialized"); map = new Map; map->Init(1); ! Log::Write("Map initialized"); if(Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 2048) < 0) { ! Log::Write("Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s", SDL_GetError()); } shot = LoadSound("sound/shoot.wav"); explode = LoadSound("sound/expl01.wav"); ! Log::Write("Audio initialized and sounds loaded"); gui2=new GUI; *************** *** 252,288 **** else screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); CenterWindow(); ! if (LOG) ! { ! printf("Main window set to 640x480 "); ! if (fullscreen) printf("at fullscreen "); ! else printf("at windowed "); ! if (software) printf("software mode"); ! else printf("hardware mode"); ! printf(" and centered\n"); ! } int done=0; int maintemp; int GUIresult; ! if (LOG) printf("Proceeding to main loop\n"); while(!done) { GUIresult=RunStartingGUI(SCREEN_WIDTH, SCREEN_HEIGHT); ! if (LOG) printf("Option from Starting GUI selected\n"); if (GUIresult==-1) { done=1; ! if (LOG) printf("Exiting game\n"); } if (GUIresult==2) { bool goahead=false; ! if (LOG) printf("Entering New Game\n"); goahead=LoadScenario(); if (goahead) { ! if (LOG) printf("Proceeding to main game play\n"); maintemp=mainLoop(); ! if (LOG) printf("Main gameplay exited\n"); if (maintemp==-1) done=1; } --- 246,279 ---- else screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); CenterWindow(); ! Log::Writen("Main window set to 640x480 "); ! if (fullscreen) Log::Writen("at fullscreen "); ! else Log::Writen("at windowed "); ! if (software) Log::Writen("software mode"); ! else Log::Writen("hardware mode"); ! Log::Write(" and centered"); int done=0; int maintemp; int GUIresult; ! Log::Write("Proceeding to main loop"); while(!done) { GUIresult=RunStartingGUI(SCREEN_WIDTH, SCREEN_HEIGHT); ! Log::Write("Option from Starting GUI selected"); if (GUIresult==-1) { done=1; ! Log::Write("Exiting game"); } if (GUIresult==2) { bool goahead=false; ! Log::Write("Entering New Game"); goahead=LoadScenario(); if (goahead) { ! Log::Write("Proceeding to main game play"); maintemp=mainLoop(); ! Log::Write("Main gameplay exited"); if (maintemp==-1) done=1; } *************** *** 308,312 **** TTF_Quit(); SDL_Quit(); ! if (LOG) printf("Thank you for playing!\n"); return 0; --- 299,303 ---- TTF_Quit(); SDL_Quit(); ! Log::Write("Thank you for playing!"); return 0; *************** *** 315,319 **** static int AskToQuitGame() { ! if (LOG) printf("AskToQuitGame()\n"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 306,310 ---- static int AskToQuitGame() { ! Log::Write("AskToQuitGame()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 424,428 **** static int InGameMenu() { ! if (LOG) printf("InGameMenu()\n"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 415,419 ---- static int InGameMenu() { ! Log::Write("InGameMenu()"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 524,535 **** { bool goahead; ! if (LOG) printf("LoadScenario()\n"); ! if (LOG) printf("Entering Scenario selection\n"); std::string scenselect=ChooseScenario(); if (!strcmp(scenselect.c_str(),"")) return false; ! if (LOG) printf("Scenario Selection is %s\n",scenselect.c_str()); delete mainScen; mainScen = new Scenario(); ! if (LOG) printf("Reading Scenario information\n"); mainScen->ReadOnly(scenselect); goahead=ShipSelect(zoom, scenselect); --- 515,526 ---- { bool goahead; ! Log::Write("LoadScenario()"); ! Log::Write("Entering Scenario selection"); std::string scenselect=ChooseScenario(); if (!strcmp(scenselect.c_str(),"")) return false; ! Log::Write("Scenario Selection is %s",scenselect.c_str()); delete mainScen; mainScen = new Scenario(); ! Log::Write("Reading Scenario information"); mainScen->ReadOnly(scenselect); goahead=ShipSelect(zoom, scenselect); *************** *** 541,545 **** static bool ShipSelect(float zoom, std::string scenselect) { ! if (LOG) printf("Entering ship selection\n"); SDL_Surface *screen=SDL_GetVideoSurface(); ship->SetZoom(zoom); --- 532,536 ---- static bool ShipSelect(float zoom, std::string scenselect) { ! Log::Write("Entering ship selection"); SDL_Surface *screen=SDL_GetVideoSurface(); ship->SetZoom(zoom); *************** *** 573,577 **** } Uint32 ticks=SDL_GetTicks(); ! if (LOG) printf("Loading Game...\n"); SDL_FillRect(screen,0,0); centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); --- 564,568 ---- } Uint32 ticks=SDL_GetTicks(); ! Log::Write("Loading Game..."); SDL_FillRect(screen,0,0); centerString(font2, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, "Loading Game....", white); *************** *** 580,610 **** map = new Map; map->Init(zoom); ! if (LOG) printf("Setting map to scenario\n"); mainScen->SetMap(map); ! if (LOG) printf("Loading map file\n"); LoadMap(map, mainScen->GetMapFn(), zoom); delete gui2; ! if (LOG) printf("Creating opening message\n"); std::string message=mainScen->GetOpenMessage(); gui2=MakeCenterOKWindow(message); ! if (LOG) printf("Placing ship\n"); ship->SetAngle(mainScen->GetStartAngle()); ! if (LOG) printf("Ship: Angle: %d",mainScen->GetStartAngle()); ship->SetSpeed(mainScen->GetStartSpeed()); ! if (LOG) printf(" Speed: %d",mainScen->GetStartSpeed()); ship->SetWarp(false); ship->SetX(mainScen->GetStartX()); ! if (LOG) printf(" X: %d",mainScen->GetStartX()); ship->SetY(mainScen->GetStartY()); ! if (LOG) printf(" Y: %d",mainScen->GetStartY()); ! if (LOG) printf(" Remaining credits: %d\n",ship->GetCredits()); //ship->SetZoom(zoom); ! //if (LOG) printf("Loading images\n"); //ship->ReloadImages(); ! if (LOG) printf("Adjusting shoot point\n"); ship->AdjustShootPoint(); ! if (LOG) printf("Adding main ship to map\n"); map->AddMainShip(ship); ! if (LOG) printf("Starting up Scenario\n"); mainScen->Startup(); Uint32 timepassed=SDL_GetTicks()-ticks; --- 571,601 ---- map = new Map; map->Init(zoom); ! Log::Write("Setting map to scenario"); mainScen->SetMap(map); ! Log::Write("Loading map file"); LoadMap(map, mainScen->GetMapFn(), zoom); delete gui2; ! Log::Write("Creating opening message"); std::string message=mainScen->GetOpenMessage(); gui2=MakeCenterOKWindow(message); ! Log::Write("Placing ship"); ship->SetAngle(mainScen->GetStartAngle()); ! Log::Writen("Ship: Angle: %d",mainScen->GetStartAngle()); ship->SetSpeed(mainScen->GetStartSpeed()); ! Log::Writen(" Speed: %d",mainScen->GetStartSpeed()); ship->SetWarp(false); ship->SetX(mainScen->GetStartX()); ! Log::Writen(" X: %d",mainScen->GetStartX()); ship->SetY(mainScen->GetStartY()); ! Log::Writen(" Y: %d",mainScen->GetStartY()); ! Log::Write(" Remaining credits: %d",ship->GetCredits()); //ship->SetZoom(zoom); ! //Log::Write("Loading images"); //ship->ReloadImages(); ! Log::Write("Adjusting shoot point"); ship->AdjustShootPoint(); ! Log::Write("Adding main ship to map"); map->AddMainShip(ship); ! Log::Write("Starting up Scenario"); mainScen->Startup(); Uint32 timepassed=SDL_GetTicks()-ticks; *************** *** 612,616 **** Uint32 secs=(unsigned int)((double)timepassed/1000.0); Uint32 mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Scenario loaded in %d minutes, %d seconds, and %d milliseconds\n",mins,secs,ms); return true; } --- 603,607 ---- Uint32 secs=(unsigned int)((double)timepassed/1000.0); Uint32 mins=(unsigned int)((double)secs/60.0); ! Log::Write("Scenario loaded in %d minutes, %d seconds, and %d milliseconds",mins,secs,ms); return true; } *************** *** 618,622 **** static int mainLoop() { ! if (LOG) printf("Main Loop begin\n"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); --- 609,613 ---- static int mainLoop() { ! Log::Write("Main Loop begin"); SDL_Event event; SDL_Surface *screen=SDL_GetVideoSurface(); *************** *** 665,669 **** map->CheckSectors(sx, sy); float zoom=0.5; ! if (LOG) printf("Variables set, displaying opening message\n"); TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); while(!done) --- 656,660 ---- map->CheckSectors(sx, sy); float zoom=0.5; ! Log::Write("Variables set, displaying opening message"); TTF_Font *font9=TTF_OpenFont("fonts/arial.ttf", 9); while(!done) *************** *** 744,748 **** char disppause[100]; sprintf(disppause, "Press '%s' to unpause", fftinput->GetPauseStr().c_str()); ! if (LOG) printf("Entering gameplay loop\n"); while(!done) { --- 735,739 ---- char disppause[100]; sprintf(disppause, "Press '%s' to unpause", fftinput->GetPauseStr().c_str()); ! Log::Write("Entering gameplay loop"); while(!done) { *************** *** 757,761 **** { paused=true; ! if (LOG) printf("Game was paused because the window lost focus\n"); if (paused) { --- 748,752 ---- { paused=true; ! Log::Write("Game was paused because the window lost focus"); if (paused) { *************** *** 807,815 **** { zoom+=0.25; ! if (LOG) printf("Zooming ship\n"); ship->SetZoom(zoom); ! if (LOG) printf("Loading Ship images\n"); ship->ReloadImages(); ! if (LOG) printf("Zooming map\n"); map->SetZoom(zoom); } --- 798,806 ---- { zoom+=0.25; ! Log::Write("Zooming ship"); ship->SetZoom(zoom); ! Log::Write("Loading Ship images"); ship->ReloadImages(); ! Log::Write("Zooming map"); map->SetZoom(zoom); } *************** *** 820,828 **** { zoom-=0.25; ! if (LOG) printf("Zooming ship\n"); ship->SetZoom(zoom); ! if (LOG) printf("Loading Ship images\n"); ship->ReloadImages(); ! if (LOG) printf("Zooming map\n"); map->SetZoom(zoom); } --- 811,819 ---- { zoom-=0.25; ! Log::Write("Zooming ship"); ship->SetZoom(zoom); ! Log::Write("Loading Ship images"); ship->ReloadImages(); ! Log::Write("Zooming map"); map->SetZoom(zoom); } Index: units.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/units.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** units.h 19 Aug 2005 07:32:29 -0000 1.1 --- units.h 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- #include "graphics.h" #include "fftfile.h" + #include "log.h" #include "math.h" *************** *** 21,25 **** extern Mix_Chunk *shot; extern int SMOOTH; - extern bool LOG; typedef struct{ --- 22,25 ---- Index: shop.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/shop.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** shop.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- shop.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 20,24 **** ShipyardShop::ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting) { ! if (LOG) printf("New ShipyardShop\n"); int i; x=sx; --- 20,24 ---- ShipyardShop::ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting) { ! Log::Write("New ShipyardShop"); int i; x=sx; *************** *** 66,70 **** } } ! if (LOG) printf("Max FPKShips=%d\n",shipmax); cur=0; curcolor=0; --- 66,70 ---- } } ! Log::Write("Max FPKShips=%d",shipmax); cur=0; curcolor=0; *************** *** 154,188 **** if ((int)ship->GetCredits()>=(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75))) { ! if (LOG) printf("Giving New Ship\n"); ! if (LOG) printf("Colorizing ship\n"); ship->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); ! if (LOG) printf("Getting New ship images\n"); ship->FPK_NewImages(ships[cur]->GetFPK(), ships[cur]->GetImageFN()); ! if (LOG) printf("Setting max speed\n"); ship->SetMaxSpeed(engine->GetMaxSpeed()); ! if (LOG) printf("Setting max warp speed\n"); ship->SetMaxWarp(engine->GetMaxWarpSpeed()); ! if (LOG) printf("Setting max safe warp speed\n"); ship->SetMaxSafeWarp(engine->GetMaxSafeWarpSpeed()); ! if (LOG) printf("Setting turn delay\n"); ship->SetTurnDelay(engine->GetTurnDelay()); ! if (LOG) printf("Setting warp turn delay\n"); ship->SetWarpTurnDelay(engine->GetWarpTurnDelay()); ! if (LOG) printf("Filling slots\n"); ship->FillSlots(ships[cur]->GetSlots(),ships[cur]->GetSlotCount()); ! if (LOG) printf("Setting shoot point\n"); ship->SetShootPoint(ships[cur]->GetShootX(),ships[cur]->GetShootY()); ! if (LOG) printf("Setting overheat\n"); ship->SetOverHeatMax(engine->GetOverHeatMax()); ! if (LOG) printf("Adding weapons\n"); ship->AddWeaponToSlot(101,"base.fpk","gfx/object/bullet.png"); //ship->AddWeaponToSlot(102,"base.fpk","gfx/object/bullet2.png"); ! if (LOG && ships[cur]->HasShield()) printf("Adding shield\n"); if (ships[cur]->HasShield()) ship->AddShield(ships[cur]->GetShieldFN()); ! if (LOG) printf("Setting battle hits\n"); ship->SetHullHitMax(ships[cur]->GetHullHitMax()); ship->SetShieldHitMax(10); ship->ResetHits(); ! if (LOG) printf("Ship loaded\n"); ship->SetCredits((int)(ship->GetCredits()-(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)))); ship->SetPriceBought(ships[cur]->GetPrice()); --- 154,188 ---- if ((int)ship->GetCredits()>=(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75))) { ! Log::Write("Giving New Ship"); ! Log::Write("Colorizing ship"); ship->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); ! Log::Write("Getting New ship images"); ship->FPK_NewImages(ships[cur]->GetFPK(), ships[cur]->GetImageFN()); ! Log::Write("Setting max speed"); ship->SetMaxSpeed(engine->GetMaxSpeed()); ! Log::Write("Setting max warp speed"); ship->SetMaxWarp(engine->GetMaxWarpSpeed()); ! Log::Write("Setting max safe warp speed"); ship->SetMaxSafeWarp(engine->GetMaxSafeWarpSpeed()); ! Log::Write("Setting turn delay"); ship->SetTurnDelay(engine->GetTurnDelay()); ! Log::Write("Setting warp turn delay"); ship->SetWarpTurnDelay(engine->GetWarpTurnDelay()); ! Log::Write("Filling slots"); ship->FillSlots(ships[cur]->GetSlots(),ships[cur]->GetSlotCount()); ! Log::Write("Setting shoot point"); ship->SetShootPoint(ships[cur]->GetShootX(),ships[cur]->GetShootY()); ! Log::Write("Setting overheat"); ship->SetOverHeatMax(engine->GetOverHeatMax()); ! Log::Write("Adding weapons"); ship->AddWeaponToSlot(101,"base.fpk","gfx/object/bullet.png"); //ship->AddWeaponToSlot(102,"base.fpk","gfx/object/bullet2.png"); ! if (ships[cur]->HasShield()) Log::Write("Adding shield"); if (ships[cur]->HasShield()) ship->AddShield(ships[cur]->GetShieldFN()); ! Log::Write("Setting battle hits"); ship->SetHullHitMax(ships[cur]->GetHullHitMax()); ship->SetShieldHitMax(10); ship->ResetHits(); ! Log::Write("Ship loaded"); ship->SetCredits((int)(ship->GetCredits()-(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)))); ship->SetPriceBought(ships[cur]->GetPrice()); *************** *** 325,332 **** cury+=80; } ! if (LOG) printf("column=%d, cury=%d\n",column,cury); curx=x+(column*100)+80; slotshow->MakeWindow(curx, cury, 80, 66); ! if (LOG) printf("Window %d, %d, %d, %d\n",curx, cury, 80, 66); sprintf(c, "ID: %d", slots[i].id); std::string slotid=c; --- 325,332 ---- cury+=80; } ! Log::Write("column=%d, cury=%d",column,cury); curx=x+(column*100)+80; slotshow->MakeWindow(curx, cury, 80, 66); ! Log::Write("Window %d, %d, %d, %d",curx, cury, 80, 66); sprintf(c, "ID: %d", slots[i].id); std::string slotid=c; *************** *** 354,358 **** int NewShipOptions(int w, int h, FPKShip **fpkships) { ! if (LOG) printf("Inside Ship options\n"); SDL_Event event; ShipyardShop *shipyard=new ShipyardShop(0,0,w,h,fpkships,true); --- 354,358 ---- int NewShipOptions(int w, int h, FPKShip **fpkships) { ! Log::Write("Inside Ship options"); SDL_Event event; ShipyardShop *shipyard=new ShipyardShop(0,0,w,h,fpkships,true); *************** *** 373,377 **** } delete shipyard; ! if (LOG) printf("End Ship options\n"); return done; } --- 373,377 ---- } delete shipyard; ! Log::Write("End Ship options"); return done; } Index: fftfile.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/fftfile.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fftfile.h 19 Aug 2005 07:32:29 -0000 1.1 --- fftfile.h 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 15,18 **** --- 15,19 ---- #include "aries.h" #include "input.h" + #include "log.h" using aries::newNode; Index: shop.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/shop.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** shop.h 19 Aug 2005 07:32:29 -0000 1.1 --- shop.h 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 8,12 **** extern Unit *ship; - extern bool LOG; typedef struct{ --- 8,11 ---- Index: scenario.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scenario.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- scenario.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 10,14 **** Uint32 secs=0; Uint32 mins=0; ! if (LOG) printf("LoadMap() at ticks=%d\n",ticks); struct Local { --- 10,14 ---- Uint32 secs=0; Uint32 mins=0; ! Log::Write("LoadMap() at ticks=%d",ticks); struct Local { *************** *** 41,45 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); for (iter = mapobjects.begin(); iter != mapobjects.end(); iter++) { --- 41,45 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = mapobjects.begin(); iter != mapobjects.end(); iter++) { *************** *** 77,81 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); } DataNodeList bullets = objectsNode->getChildren("bullet"); --- 77,81 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Map Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList bullets = objectsNode->getChildren("bullet"); *************** *** 86,90 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); for (iter = bullets.begin(); iter != bullets.end(); iter++) { --- 86,90 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = bullets.begin(); iter != bullets.end(); iter++) { *************** *** 113,117 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); } DataNodeList actobjects = objectsNode->getChildren("actobject"); --- 113,117 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Bullets, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList actobjects = objectsNode->getChildren("actobject"); *************** *** 122,126 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); std::string imagefn; SDL_Surface *image=0; --- 122,126 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); std::string imagefn; SDL_Surface *image=0; *************** *** 217,221 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); } DataNodeList aiships = objectsNode->getChildren("aiship"); --- 217,221 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Active Objects, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList aiships = objectsNode->getChildren("aiship"); *************** *** 226,230 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); for (iter = aiships.begin(); iter != aiships.end(); iter++) { --- 226,230 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = aiships.begin(); iter != aiships.end(); iter++) { *************** *** 345,349 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); } DataNodeList stations = objectsNode->getChildren("station"); --- 345,349 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading AI Ships, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } DataNodeList stations = objectsNode->getChildren("station"); *************** *** 354,358 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); for (iter = stations.begin(); iter != stations.end(); iter++) { --- 354,358 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); for (iter = stations.begin(); iter != stations.end(); iter++) { *************** *** 520,526 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin\n", mins, secs, ms); } ! if (LOG) printf("Loading Animations\n"); StaticAnim *anim=new StaticAnim; anim->LoadFrames("gfx/anim/explosion"); --- 520,526 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Stations, %d minutes, %d seconds, %d ms after LoadMap() begin", mins, secs, ms); } ! Log::Write("Loading Animations"); StaticAnim *anim=new StaticAnim; anim->LoadFrames("gfx/anim/explosion"); *************** *** 530,534 **** secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! if (LOG) printf("Done Loading Map, %d minutes, %d seconds, %d ms total\n", mins, secs, ms); delete rootNode; } --- 530,534 ---- secs=(unsigned int)((double)timepassed/1000.0); mins=(unsigned int)((double)secs/60.0); ! Log::Write("Done Loading Map, %d minutes, %d seconds, %d ms total", mins, secs, ms); delete rootNode; } *************** *** 874,878 **** if (!victnext && !lossnext) { ! fprintf(stderr, "There are no victory conditions or loss conditions! This should never happen!"); exit(1); } --- 874,878 ---- if (!victnext && !lossnext) { ! Log::Write("There are no victory conditions or loss conditions! This should never happen!"); exit(1); } *************** *** 970,974 **** if (!victnext && !lossnext) { ! fprintf(stderr, "There are no victory conditions AND no loss conditions! This should never happen!"); exit(1); } --- 970,974 ---- if (!victnext && !lossnext) { ! Log::Write("There are no victory conditions AND no loss conditions! This should never happen!"); exit(1); } *************** *** 1318,1322 **** Uint32 ticks=SDL_GetTicks(); SDL_Event event; ! bool printfd=false; while (SDL_GetTicks()<ticks+30000) { --- 1318,1322 ---- Uint32 ticks=SDL_GetTicks(); SDL_Event event; ! bool logged=false; while (SDL_GetTicks()<ticks+30000) { *************** *** 1333,1345 **** SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (LOG && !printfd) printf("%s\n",msghead.c_str()); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (LOG && !printfd) printf("%s\n",msg[i].c_str()); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); SDL_Flip(screen); ! printfd=true; } exit(1); --- 1333,1345 ---- SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::Write(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::Write(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); SDL_Flip(screen); ! logged=true; } exit(1); *************** *** 1347,1351 **** FPKShip **LoadShipsFromScen(Scenario *Scen) { ! if (LOG) printf("Inside LoadShipsFromScen\n"); char **fpklist; char **k; --- 1347,1351 ---- FPKShip **LoadShipsFromScen(Scenario *Scen) { ! Log::Write("Inside LoadShipsFromScen"); char **fpklist; char **k; Index: scenario.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/scenario.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scenario.h 19 Aug 2005 07:32:29 -0000 1.1 --- scenario.h 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 17,21 **** extern Unit *ship; - extern bool LOG; void LoadMap(Map *map, const std::string& filename, float zoom); --- 17,20 ---- Index: mapobject.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/mapobject.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mapobject.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- mapobject.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 501,505 **** ship->SetCredits(ship->GetCredits()-shop.buyitems[buycur].price); ship->AddWeaponToSlot(bayid,shop.buyitems[buycur].fpk,shop.buyitems[buycur].imagefn,shop.buyitems[buycur].amount); ! if (LOG) printf("Inserted %d of ammo into bay id %d\n",shop.buyitems[buycur].amount,bayid); } } --- 501,505 ---- ship->SetCredits(ship->GetCredits()-shop.buyitems[buycur].price); ship->AddWeaponToSlot(bayid,shop.buyitems[buycur].fpk,shop.buyitems[buycur].imagefn,shop.buyitems[buycur].amount); ! Log::Write("Inserted %d of ammo into bay id %d\n",shop.buyitems[buycur].amount,bayid); } } Index: fftfile.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/fftfile.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fftfile.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- fftfile.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 2,7 **** #include <stack> - extern bool LOG; - char PHYSFS_getc(PHYSFS_file *fp) { --- 2,5 ---- *************** *** 10,14 **** return buffer; } ! else printf(PHYSFS_getLastError()); return 0; } --- 8,12 ---- return buffer; } ! else Log::Write(PHYSFS_getLastError()); return 0; } *************** *** 545,549 **** Uint32 ticks=SDL_GetTicks(); SDL_Event event; ! bool printfd=false; while (SDL_GetTicks()<ticks+30000) { --- 543,547 ---- Uint32 ticks=SDL_GetTicks(); SDL_Event event; ! bool logged=false; while (SDL_GetTicks()<ticks+30000) { *************** *** 560,572 **** SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (LOG && !printfd) printf("%s\n",msghead.c_str()); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (LOG && !printfd) printf("%s\n",msg[i].c_str()); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); SDL_Flip(screen); ! printfd=true; } exit(1); --- 558,570 ---- SDL_FillRect(screen,0,0); drawString(font, screen->w/2-200, 20, msghead, white); ! if (!logged) Log::Write(msghead); for (i=0; i<=end; i++) { drawString(font, screen->w/2-200, 40+(i*20), msg[i], white); ! if (!logged) Log::Write(msg[i]); } drawString(font, screen->w/2-200, 40+((i+1)*20), "This game will autoclose in 30 seconds", white); SDL_Flip(screen); ! logged=true; } exit(1); *************** *** 645,649 **** FPKShip::FPKShip(int listindex, int num) { ! if (LOG) printf("New FPKShip\n"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) --- 643,647 ---- FPKShip::FPKShip(int listindex, int num) { ! Log::Write("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) *************** *** 655,671 **** shootx=0; shooty=0; ! //if (LOG) printf("FPKShip CP\n"); this->ZeroSlots(); ! //if (LOG) printf("FPKShip CP\n"); this->GetFileInfo(listindex, num); ! //if (LOG) printf("FPKShip CP\n"); image=LoadIMG(imagefn); ! //if (LOG) printf("FPKShip CP\n"); if (hasShield) shield=LoadIMG(shieldfn); ! //if (LOG) printf("FPKShip CP\n"); } FPKShip::FPKShip(std::string sfpk, std::string shipname) { ! if (LOG) printf("New FPKShip\n"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) --- 653,669 ---- shootx=0; shooty=0; ! //Log::Write("FPKShip CP"); this->ZeroSlots(); ! //Log::Write("FPKShip CP"); this->GetFileInfo(listindex, num); ! //Log::Write("FPKShip CP"); image=LoadIMG(imagefn); ! //Log::Write("FPKShip CP"); if (hasShield) shield=LoadIMG(shieldfn); ! //Log::Write("FPKShip CP"); } FPKShip::FPKShip(std::string sfpk, std::string shipname) { ! Log::Write("New FPKShip"); int i; for(i=0; i<__MAXSHIPSLOTS; i++) *************** *** 691,695 **** void FPKShip::GetFileInfo(int listindex, int num) { ! if (LOG) printf("FPKShip::GetFileInfo Begin\n"); char **spath = PHYSFS_getSearchPath(); --- 689,693 ---- void FPKShip::GetFileInfo(int listindex, int num) { ! Log::Write("FPKShip::GetFileInfo Begin"); char **spath = PHYSFS_getSearchPath(); *************** *** 739,743 **** void FPKShip::GetFileInfo(std::string sfpk, std::string shipname) { ! if (LOG) printf("FPKShip::GetFileInfo Begin\n"); fpk = sfpk; --- 737,741 ---- void FPKShip::GetFileInfo(std::string sfpk, std::string shipname) { ! Log::Write("FPKShip::GetFileInfo Begin"); fpk = sfpk; *************** *** 786,794 **** if (ships[num]->hasChild("displayname")) name=ships[num]->getChild("displayname")->getString(); else FPK_Invalid(temp, "displayname command not found in a playership in FPK"); ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); if (ships[num]->hasChild("image")) imagefn=ships[num]->getChild("image")->getString(); else FPK_Invalid(temp, "image command not found in a playership in FPK"); ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); if (ships[num]->hasChild("shield")) --- 784,792 ---- if (ships[num]->hasChild("displayname")) name=ships[num]->getChild("displayname")->getString(); else FPK_Invalid(temp, "displayname command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("image")) imagefn=ships[num]->getChild("image")->getString(); else FPK_Invalid(temp, "image command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shield")) *************** *** 798,802 **** } else hasShield=false; ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); if (ships[num]->hasChild("price")) --- 796,800 ---- } else hasShield=false; ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("price")) *************** *** 831,835 **** } else FPK_Invalid(temp, "dimensions command not found in a playership in FPK"); ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); if (ships[num]->hasChild("shootpoint")) --- 829,833 ---- } else FPK_Invalid(temp, "dimensions command not found in a playership in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (ships[num]->hasChild("shootpoint")) *************** *** 849,856 **** shooty=image->h/2; } ! //if (LOG) printf("FPKShip::GetFileInfo CP shootpoint\n"); DataNodeList shipslots = ships[num]->getChildren("slot"); ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); slotcount=shipslots.size(); int j=0; --- 847,854 ---- shooty=image->h/2; } ! //Log::Write("FPKShip::GetFileInfo CP shootpoint"); DataNodeList shipslots = ships[num]->getChildren("slot"); ! //Log::Write("FPKShip::GetFileInfo CP"); slotcount=shipslots.size(); int j=0; *************** *** 1017,1021 **** FPKEngine::FPKEngine(std::string sfpk, std::string sengine) { ! if (LOG) printf("New FPKShip\n"); image=0; price=0; --- 1015,1019 ---- FPKEngine::FPKEngine(std::string sfpk, std::string sengine) { ! Log::Write("New FPKShip"); image=0; price=0; *************** *** 1029,1033 **** void FPKEngine::GetFileInfo(std::string sfpk, std::string sengine) { ! if (LOG) printf("FPKEngine::GetFileInfo Begin\n"); fpk = sfpk; --- 1027,1031 ---- void FPKEngine::GetFileInfo(std::string sfpk, std::string sengine) { ! Log::Write("FPKEngine::GetFileInfo Begin"); fpk = sfpk; *************** *** 1126,1130 **** if (engines[num]->hasChild("turndelay")) turndelay=atoi(engines[num]->getChild("turndelay")->getString().c_str()); else FPK_Invalid(temp, "turndelay command not found in an engine in FPK"); ! //if (LOG) printf("FPKShip::GetFileInfo CP\n"); if (engines[num]->hasChild("turndelaywarp")) warpturndelay=atoi(engines[num]->getChild("turndelaywarp")->getString().c_str()); --- 1124,1128 ---- if (engines[num]->hasChild("turndelay")) turndelay=atoi(engines[num]->getChild("turndelay")->getString().c_str()); else FPK_Invalid(temp, "turndelay command not found in an engine in FPK"); ! //Log::Write("FPKShip::GetFileInfo CP"); if (engines[num]->hasChild("turndelaywarp")) warpturndelay=atoi(engines[num]->getChild("turndelaywarp")->getString().c_str()); Index: log.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/log.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** log.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- log.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 16,20 **** logFile.open(fname); }; - void Log::Write(const std::string& s) { --- 16,19 ---- *************** *** 22,25 **** --- 21,34 ---- logFile << s << std::endl; }; + void Log::Write(const char* s, ...) + { + if (!isLogging) return; + va_list lst; + va_start(lst, s); + char buffer[2048]; + vsprintf(buffer, s, lst); + logFile << buffer; + logFile << std::endl; + }; void Log::Writen(const std::string& s) { *************** *** 27,29 **** --- 36,47 ---- logFile << s; }; + void Log::Writen(const char* s, ...) + { + if (!isLogging) return; + va_list lst; + va_start(lst, s); + char buffer[2048]; + vsprintf(buffer, s, lst); + logFile << buffer; + }; Index: map.cpp =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/map.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** map.cpp 19 Aug 2005 07:32:29 -0000 1.1 --- map.cpp 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 598,602 **** bullet->Init(x,y,img,image,fpk,zoom); if (slotid) mainship->ReduceAmmo(slotid); ! if (LOG) printf("Bullet spawned and ammo reduced, bay id=%d\n",slotid); bullet->SetSpeed(speed); bullet->SetAngle(angle); --- 598,602 ---- bullet->Init(x,y,img,image,fpk,zoom); if (slotid) mainship->ReduceAmmo(slotid); ! Log::Write("Bullet spawned and ammo reduced, bay id=%d",slotid); bullet->SetSpeed(speed); bullet->SetAngle(angle); Index: log.h =================================================================== RCS file: /cvsroot/fftrader/fftrader/src/log.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** log.h 19 Aug 2005 07:32:29 -0000 1.1 --- log.h 19 Aug 2005 08:22:34 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- #include <fstream> #include <string> + #include <stdarg.h> #include <stdio.h> *************** *** 8,12 **** --- 9,15 ---- void Init(const char* fname); void Write(const std::string& s); + void Write(const char* s, ...); void Writen(const std::string& s); + void Writen(const char* s, ...); }; |
From: TomT64 <to...@us...> - 2005-08-19 08:22:43
|
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26008 Modified Files: CHANGELOG.txt README.txt TODO.txt fftrader.dev Log Message: Added Logger Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/fftrader/fftrader/CHANGELOG.txt,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** CHANGELOG.txt 27 Sep 2004 01:50:21 -0000 1.30 --- CHANGELOG.txt 19 Aug 2005 08:22:34 -0000 1.31 *************** *** 1,5 **** CHANGELOG ! 0.67 - Made several adjustments and additions to the source in order to allow easy compiling on Mac OS X. --- 1,9 ---- CHANGELOG ! 0.70 ! - Added a logger that logs to file "fft.log" ! - Moved source files to src/ subdirectory ! ! 0.67 (never released) - Made several adjustments and additions to the source in order to allow easy compiling on Mac OS X. Index: TODO.txt =================================================================== RCS file: /cvsroot/fftrader/fftrader/TODO.txt,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** TODO.txt 27 Sep 2004 01:50:21 -0000 1.34 --- TODO.txt 19 Aug 2005 08:22:34 -0000 1.35 *************** *** 1,8 **** TODO: ! for 0.67 release: Shipyard: -Add a shop to buy stuff for ship hulls, and force this shop to ! contain at least one engine from an FPK -Make shields buyable (in shop), and not default on ships, but keep shield image for each ship, and make having a shield image necessary. --- 1,12 ---- TODO: ! for 0.70 release: ! -Add Python to the engine, phase out aries Shipyard: -Add a shop to buy stuff for ship hulls, and force this shop to ! contain at least one engine from an FPK. ! -If starting ship shop contains only one engine, allow a scenario ! option to automatically add that engine to the ship selected at no ! cost. -Make shields buyable (in shop), and not default on ships, but keep shield image for each ship, and make having a shield image necessary. *************** *** 20,25 **** bay, to the shop on the station. -Arbitrarize buying code - - for 0.70 release: -A near-complete (or at least added to modularly) scenario system -More advanced Artificial Intelligence in ships --- 24,27 ---- Index: README.txt =================================================================== RCS file: /cvsroot/fftrader/fftrader/README.txt,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** README.txt 10 Sep 2004 22:03:04 -0000 1.21 --- README.txt 19 Aug 2005 08:22:34 -0000 1.22 *************** *** 1,5 **** ! Final Frontier Trader 0.67 ReadMe ------------------- Thank you for downloading Final Frontier Trader You can donate money to this project via the link below: --- 1,9 ---- ! Final Frontier Trader 0.70 alpha ReadMe ------------------- + ******************** + Read this with a grain of salt + ******************** + Thank you for downloading Final Frontier Trader You can donate money to this project via the link below: Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fftrader.dev 19 Aug 2005 07:32:29 -0000 1.9 --- fftrader.dev 19 Aug 2005 08:22:34 -0000 1.10 *************** *** 2,6 **** FileName=fftrader.dev Name=fftrader ! UnitCount=30 Type=0 Ver=1 --- 2,6 ---- FileName=fftrader.dev Name=fftrader ! UnitCount=32 Type=0 Ver=1 *************** *** 348,349 **** --- 348,369 ---- BuildCmd= + [Unit31] + FileName=src\log.cpp + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + + [Unit32] + FileName=src\log.h + CompileCpp=1 + Folder=fftrader + Compile=1 + Link=1 + Priority=1000 + OverrideBuildCmd=0 + BuildCmd= + |
From: TomT64 <to...@us...> - 2005-08-19 07:33:47
|
Update of /cvsroot/fftrader/fftrader/osx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16493/osx Removed Files: test.txt Log Message: --- test.txt DELETED --- |
From: TomT64 <to...@us...> - 2005-08-19 07:33:22
|
Update of /cvsroot/fftrader/fftrader/osx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16443/osx Added Files: test.txt Log Message: - Added log files to be used a bit later, and put sources in a subdirectory --- NEW FILE: test.txt --- |
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16344/src Added Files: aries.cpp aries.h bitmask.c bitmask.h fftfile.cpp fftfile.h fftrader.ico graphics.cpp graphics.h gui.cpp gui.h guiapply.cpp guiapply.h input.cpp input.h log.cpp log.h mac.h mac.m main.cpp map.cpp map.h mapobject.cpp mapobject.h math.cpp math.h resource.h resource.rc scenario.cpp scenario.h shop.cpp shop.h units.cpp units.h Log Message: - Added log files to be used a bit later, and put sources in a subdirectory --- NEW FILE: main.cpp --- /* Final Frontier Trader by TomT64 Requires the following libraries: SDL >= 1.2.4 SDL_image >= 1.2.2 SDL_mixer >= 1.2.4 SDL_ttf >= 2.0.6 SDL_gfx >= 2.0.8 physfs (with zip support) >= 0.1.9 SDL and its libraries may be found easily through Google or SDL's website (http://www.libsdl.org). PhysFS may be found at its website (http://www.icculus.org/physfs/) */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> [...1054 lines suppressed...] } if (mainScen->CheckLoss()) { std::string message="Game Over. You failed to complete your objectives."; done=ExitToMenuBox(SCREEN_WIDTH,SCREEN_HEIGHT,message); } } SDL_framerateDelay(FPS); lastpausetime=SDL_GetTicks(); } if (paused) { pausetime=SDL_GetTicks()-lastpausetime; } } TTF_CloseFont(font9); delete FPS; return done; } --- NEW FILE: shop.cpp --- #include "shop.h" BuyShop::BuyShop(int sx, int sy, int sw, int sh, __shop sshop, bool sstarting) { } BuyShop::~BuyShop() { } void BuyShop::ResetValues() { } void BuyShop::Display() { } int BuyShop::PollEvent(SDL_Event event) { return 0; } ShipyardShop::ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting) { if (LOG) printf("New ShipyardShop\n"); int i; x=sx; y=sy; w=sw; h=sh; click=-1; slottopline=0; slotlines=0; sGUI=new GUI; slotGUI=new GUI; slotshow=new GUI; starting=sstarting; showslots=false; font=TTF_OpenFont("fonts/arial.ttf", 12); font14=TTF_OpenFont("fonts/arial.ttf", 14); cr[0]=0; cg[0]=0; cb[0]=0; //none cr[1]=0; cg[1]=255; cb[1]=255; //cyan cr[2]=0; cg[2]=255; cb[2]=0; //green cr[3]=103; cg[3]=8; cb[3]=123; //violet cr[4]=255; cg[4]=255; cb[4]=0; //yellow cr[5]=255; cg[5]=255; cb[5]=255; //white numcolors=6; sGUI->Init(); prev=sGUI->MakeButton(x+35, y+h-75, 40, "< Prev"); back=-1; if (starting) back=sGUI->MakeButton(x+(w/2)-70, y+h-40, 140, "Back to Scenario Selection"); select=sGUI->MakeButton(x+(w/2)-95, y+h-75, 90, "Select this Ship"); viewslots=sGUI->MakeButton(x+(w/2)+5, y+h-75, 90, "View Slots"); next=sGUI->MakeButton(x+w-75, y+h-75, 40, "Next >"); prevcolor=sGUI->MakeButton(x+w-115, y+(h/2)-40, 80, "< Prev Color"); nextcolor=sGUI->MakeButton(x+w-115, y+(h/2)+16, 80, "Next Color >"); slotGUI->Init(); slotpageup=slotGUI->MakeDirButton(x+w-40, y+50, 0); back2=slotGUI->MakeButton(x+(w/2)-55, y+h-75, 110, "Back to Ship Select"); slotpagedown=slotGUI->MakeDirButton(x+w-40, y+h-85, 1); this->ReloadSlotShowGUI(fpkships[0]); shipmax=0; for(i=0; i<100; i++) { if(!fpkships[i]) { shipmax=i; break; } } if (LOG) printf("Max FPKShips=%d\n",shipmax); cur=0; curcolor=0; ships=fpkships; ships[cur]->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); engine=new FPKEngine("base.fpk", "Warp 5 Engine"); } ShipyardShop::~ShipyardShop() { int i; for(i=0; i<shipmax; i++) { delete ships[i]; } delete engine; TTF_CloseFont(font); TTF_CloseFont(font14); delete sGUI; delete slotGUI; delete slotshow; } void ShipyardShop::ResetValues() { cur=0; curcolor=0; } void ShipyardShop::Display() { if(!showslots) { this->DisplayShipInfo(ships[cur], curcolor); sGUI->Draw(); } else { this->DisplayShipSlots(ships[cur]); slotGUI->Draw(); } } int ShipyardShop::PollEvent(SDL_Event event) { int getx, gety; int done=0; // an event was found switch (event.type) { // close button clicked case SDL_QUIT: done=-1; break; // handle the keyboard case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: done = 1; break; default: break; } break; case SDL_MOUSEMOTION: SDL_GetMouseState(&getx, &gety); if (!showslots) sGUI->SendMouseMotion(getx,gety); if (showslots) slotGUI->SendMouseMotion(getx,gety); break; case SDL_MOUSEBUTTONDOWN: SDL_GetMouseState(&getx, &gety); if (!showslots) click = sGUI->SendMouseClick(getx, gety); if (showslots) click = slotGUI->SendMouseClick(getx, gety); break; case SDL_MOUSEBUTTONUP: SDL_GetMouseState(&getx, &gety); if (click!=-1 && click==sGUI->SendMouseClick(getx, gety) && !showslots) { if (click==prev) { if (cur-1<0) cur=shipmax-1; else cur--; ships[cur]->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); delete slotshow; slotshow=new GUI; this->ReloadSlotShowGUI(ships[cur]); } if (click==select) { if ((int)ship->GetCredits()>=(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75))) { if (LOG) printf("Giving New Ship\n"); if (LOG) printf("Colorizing ship\n"); ship->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); if (LOG) printf("Getting New ship images\n"); ship->FPK_NewImages(ships[cur]->GetFPK(), ships[cur]->GetImageFN()); if (LOG) printf("Setting max speed\n"); ship->SetMaxSpeed(engine->GetMaxSpeed()); if (LOG) printf("Setting max warp speed\n"); ship->SetMaxWarp(engine->GetMaxWarpSpeed()); if (LOG) printf("Setting max safe warp speed\n"); ship->SetMaxSafeWarp(engine->GetMaxSafeWarpSpeed()); if (LOG) printf("Setting turn delay\n"); ship->SetTurnDelay(engine->GetTurnDelay()); if (LOG) printf("Setting warp turn delay\n"); ship->SetWarpTurnDelay(engine->GetWarpTurnDelay()); if (LOG) printf("Filling slots\n"); ship->FillSlots(ships[cur]->GetSlots(),ships[cur]->GetSlotCount()); if (LOG) printf("Setting shoot point\n"); ship->SetShootPoint(ships[cur]->GetShootX(),ships[cur]->GetShootY()); if (LOG) printf("Setting overheat\n"); ship->SetOverHeatMax(engine->GetOverHeatMax()); if (LOG) printf("Adding weapons\n"); ship->AddWeaponToSlot(101,"base.fpk","gfx/object/bullet.png"); //ship->AddWeaponToSlot(102,"base.fpk","gfx/object/bullet2.png"); if (LOG && ships[cur]->HasShield()) printf("Adding shield\n"); if (ships[cur]->HasShield()) ship->AddShield(ships[cur]->GetShieldFN()); if (LOG) printf("Setting battle hits\n"); ship->SetHullHitMax(ships[cur]->GetHullHitMax()); ship->SetShieldHitMax(10); ship->ResetHits(); if (LOG) printf("Ship loaded\n"); ship->SetCredits((int)(ship->GetCredits()-(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)))); ship->SetPriceBought(ships[cur]->GetPrice()); done=2; } } if (click==viewslots) { showslots=true; } if (click==back) { done=1; } if (click==next) { if (cur+1>=shipmax) cur=0; else cur++; ships[cur]->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); delete slotshow; slotshow=new GUI; this->ReloadSlotShowGUI(ships[cur]); } if (click==prevcolor) { if (curcolor-1>=0) curcolor--; else curcolor=numcolors-1; ships[cur]->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); } if (click==nextcolor) { if (curcolor+1<numcolors) curcolor++; else curcolor=0; ships[cur]->Colorize(cr[curcolor], cg[curcolor], cb[curcolor]); } } if (click!=-1 && click==slotGUI->SendMouseClick(getx, gety) && showslots) { if (click==back2) { showslots=false; } if (click==slotpageup && slotlines>1) { if (slottopline>0) slottopline--; else slottopline=0; delete slotshow; slotshow=new GUI; this->ReloadSlotShowGUI(ships[cur]); } if (click==slotpagedown && slotlines>1) { if (slottopline<slotlines-max_y) slottopline++; else slottopline=slotlines-max_y; delete slotshow; slotshow=new GUI; this->ReloadSlotShowGUI(ships[cur]); } } slotGUI->UpdateButtons(); sGUI->UpdateButtons(); click=-1; break; default: break; } return done; } void ShipyardShop::DisplayShipInfo(FPKShip *curship, int curcolor) { SDL_Surface *screen=SDL_GetVideoSurface(); SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; if (starting) centerString(font14, x+(w/2), y+20, "Ship Selection", white); int price=(int)(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)); char c[300]; sprintf(c, "Price: %d", price); std::string shipprice=c; centerString(font, x+(w/2), y+40, curship->GetName(), white); centerString(font, x+(w/2), y+54, shipprice, white); if (starting) { sprintf(c, "Credits: %d", ship->GetCredits()); std::string scredits=c; drawString(font, x+20, (y+h)-110, scredits, white); } drawString(font, x+w-150, y+60, "Width: ", white); drawString(font, x+w-40, y+60, curship->GetSW(), white); drawString(font, x+w-150, y+76, "Length: ", white); drawString(font, x+w-40, y+76, curship->GetSL(), white); drawString(font, x+w-150, y+92, "Depth: ", white); drawString(font, x+w-40, y+92, curship->GetSD(), white); DrawIMG(curship->GetImage(),x+(w/2)-curship->GetImage()->w/2,y+(h/2)-curship->GetImage()->h/2); if(curship->HasShield()) DrawIMG(curship->GetShield(),x+(w/2)-curship->GetShield()->w/2,y+(h/2)-curship->GetShield()->h/2); rectangleRGBA(screen, x+w-120, y+(h/2)-9, x+w-30, y+(h/2)+9, 255, 255, 255, 255); if (cr[curcolor] || cg[curcolor] || cb[curcolor]) boxRGBA(screen, x+w-119, y+(h/2)-8, x+w-31, y+(h/2)+8, cr[curcolor], cg[curcolor], cb[curcolor], 255); } void ShipyardShop::DisplayShipSlots(FPKShip *curship) { SDL_Surface *screen=SDL_GetVideoSurface(); SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; if (starting) centerString(font14, x+(w/2), y+20, "Ship Slots", white); char c[500]; int price=(int)(ships[cur]->GetPrice()-(ship->GetPriceBought()*0.75)); sprintf(c, "Price: %d", price); std::string shipprice=c; centerString(font, x+(w/2), y+40, curship->GetName(), white); centerString(font, x+(w/2), y+54, shipprice, white); if (starting) { sprintf(c, "Credits: %d", ship->GetCredits()); std::string scredits=c; drawString(font, x+20, (y+h)-110, scredits, white); } slotshow->Draw(); } void ShipyardShop::ReloadSlotShowGUI(FPKShip *curship) { char c[500]; //determine how many slots can fit on one line int max_x=(w-160)/100; //160 is our pixel cushion max_y=(h-180)/86; //180 is our pixel cushion __ship_slot *slots=curship->GetSlots(); slotshow->Init(); int i; int column=0; int curx=0; int cury=y+70; int displaynum=0; int start=slottopline*max_x; if (start>curship->GetSlotCount()) start=0; if (curship->GetSlotCount()>(max_x*max_y)) displaynum=max_x*max_y; else displaynum=curship->GetSlotCount(); int end=displaynum+start; if (end>curship->GetSlotCount()) end=curship->GetSlotCount(); for(i=start; i<end; i++) { if (column>=max_x) { column=0; cury+=80; } if (LOG) printf("column=%d, cury=%d\n",column,cury); curx=x+(column*100)+80; slotshow->MakeWindow(curx, cury, 80, 66); if (LOG) printf("Window %d, %d, %d, %d\n",curx, cury, 80, 66); sprintf(c, "ID: %d", slots[i].id); std::string slotid=c; std::string slottype="Type: "; slottype+=slots[i].type; sprintf(c, "Width: %d", slots[i].w); std::string width=c; sprintf(c, "Length: %d", slots[i].l); std::string length=c; sprintf(c, "Depth: %d", slots[i].d); std::string depth=c; slotshow->MakeStaticLeft(curx+4, cury+2, 76, 64, slotid, 8); slotshow->MakeStaticLeft(curx+4, cury+14, 76, 52, slottype, 8); slotshow->MakeStaticLeft(curx+4, cury+26, 76, 40, width, 8); slotshow->MakeStaticLeft(curx+4, cury+38, 76, 28, length, 8); slotshow->MakeStaticLeft(curx+4, cury+50, 76, 16, depth, 8); column++; } slotlines=curship->GetSlotCount()/max_x; if (curship->GetSlotCount()%max_x!=0) slotlines+=1; if (start) slotshow->MakeStaticLeft(x+(max_x*100)+84, y+90, 76, 64, "More /\\", 8); if (end<curship->GetSlotCount()) slotshow->MakeStaticLeft(x+(max_x*100)+84, y+90+((max_y-1)*80), 76, 64, "More \\/", 8); } int NewShipOptions(int w, int h, FPKShip **fpkships) { if (LOG) printf("Inside Ship options\n"); SDL_Event event; ShipyardShop *shipyard=new ShipyardShop(0,0,w,h,fpkships,true); SDL_Surface *screen=SDL_GetVideoSurface(); int done=0; while(!done) { Slock(); SDL_FillRect(screen,0,0); while (SDL_PollEvent(&event)) { int donetemp=shipyard->PollEvent(event); if (donetemp) done=donetemp; } shipyard->Display(); Sulock(); SDL_Flip(screen); } delete shipyard; if (LOG) printf("End Ship options\n"); return done; } --- NEW FILE: shop.h --- #ifndef __FFTSHOP_H__ #define __FFTSHOP_H__ #include <string> #include "fftfile.h" #include "gui.h" #include "units.h" extern Unit *ship; extern bool LOG; typedef struct{ std::string type; std::string baytype; std::string holdweapon; std::string name; std::string desc; std::string imagefn; std::string fpk; unsigned int price; unsigned int baseprice; SDL_Surface *dispimage; int holdamount; int baseimport; int amount; int bayw; int bayl; int bayd; int cargounits; }__shopitem; typedef struct{ __shopitem buyitems[30]; int stock[30]; int buynext; }__shop; class BuyShop { public: BuyShop(int sx, int sy, int sw, int sh, __shop sshop, bool sstarting=false); ~BuyShop(); void ResetValues(); void Display(); int PollEvent(SDL_Event event); private: bool starting; __shop shop; int x; int y; int w; int h; TTF_Font *font; TTF_Font *font14; }; class ShipyardShop { public: ShipyardShop(int sx, int sy, int sw, int sh, FPKShip **fpkships, bool sstarting=false); ~ShipyardShop(); void ResetValues(); void Display(); int PollEvent(SDL_Event event); void DisplayShipInfo(FPKShip *curship, int curcolor); void DisplayShipSlots(FPKShip *curship); void ReloadSlotShowGUI(FPKShip *curship); private: GUI *sGUI; GUI *slotGUI; GUI *slotshow; bool starting; int prev; int back; int select; int viewslots; int next; int slotpageup; int slotpagedown; int back2; int prevcolor; int nextcolor; FPKShip **ships; FPKEngine *engine; int shipmax; int x; int y; int w; int h; int cur; int curcolor; int click; int slottopline; int slotlines; int max_y; bool showslots; Uint8 cr[6]; Uint8 cg[6]; Uint8 cb[6]; int numcolors; TTF_Font *font; TTF_Font *font14; }; int NewShipOptions(int w, int h, FPKShip **fpkships); #endif /* __FFTSHOP_H__ */ --- NEW FILE: resource.rc --- #include "resource.h" IDI_ICON1 ICON DISCARDABLE "fftrader.ico" --- NEW FILE: mapobject.cpp --- #include "mapobject.h" MapObject::~MapObject() { if (image) SDL_FreeSurface(image); } void MapObject::Init(int sx, int sy, std::string img, std::string ffpk, float zzoom) { x=sx; y=sy; imgload=img; fpk=ffpk; zoom=zzoom; image=0; loaded=false; mmr=0; mmg=255; mmb=0; } [...1018 lines suppressed...] //int price=(int)(shop.buyitems[i].baseprice*((float)pm/(float)10)); //This sets the price to the basic price * profit //int perc_difference=(int)((float)100/(float)shop.buyitems[i].baseimport*(float)difference); //int mod_price=(int)((100-perc_difference)*(5*((float)pm/(float)10))); int perc_difference=(int)((float)100/(float)shop.buyitems[i].baseimport*(float)difference); int mod_price=shop.buyitems[i].baseprice+(int)(perc_difference*((float)pm/(float)10)); shop.buyitems[i].price=mod_price; } } ticks=SDL_GetTicks(); } } void Station::AddToWaitTime(Uint32 time) { ticks+=time; } Uint32 Station::GetTicks() { return ticks; } --- NEW FILE: input.cpp --- #include "input.h" FFTInput::FFTInput() { FFTKEY_fire1=SDLK_LCTRL; FFTKEY_fire2=SDLK_RCTRL; FFTKEY_warp1=SDLK_LALT; FFTKEY_warp2=SDLK_RALT; FFTKEY_up=SDLK_UP; FFTKEY_down=SDLK_DOWN; FFTKEY_left=SDLK_LEFT; FFTKEY_right=SDLK_RIGHT; FFTKEY_allstop=SDLK_SPACE; FFTKEY_cancel=SDLK_ESCAPE; FFTKEY_minimapzoomin=SDLK_KP_PLUS; FFTKEY_minimapzoomout=SDLK_KP_MINUS; FFTKEY_pause=SDLK_p; FFTKEY_zoomin=SDLK_z; FFTKEY_zoomout=SDLK_x; FFTKEY_prevweapon=SDLK_SLASH; FFTKEY_nextweapon=SDLK_RSHIFT; FFTKEY_dock=SDLK_d; FFTKEY_prevtarget=SDLK_r; FFTKEY_nexttarget=SDLK_t; } int FFTInput::GetFire1() { return FFTKEY_fire1; } int FFTInput::GetFire2() { return FFTKEY_fire2; } int FFTInput::GetWarp1() { return FFTKEY_warp1; } int FFTInput::GetWarp2() { return FFTKEY_warp2; } int FFTInput::GetUp() { return FFTKEY_up; } int FFTInput::GetDown() { return FFTKEY_down; } int FFTInput::GetLeft() { return FFTKEY_left; } int FFTInput::GetRight() { return FFTKEY_right; } int FFTInput::GetAllStop() { return FFTKEY_allstop; } int FFTInput::GetCancel() { return FFTKEY_cancel; } int FFTInput::GetMiniMapZoomIn() { return FFTKEY_minimapzoomin; } int FFTInput::GetMiniMapZoomOut() { return FFTKEY_minimapzoomout; } int FFTInput::GetPause() { return FFTKEY_pause; } int FFTInput::GetZoomIn() { return FFTKEY_zoomin; } int FFTInput::GetZoomOut() { return FFTKEY_zoomout; } int FFTInput::GetPrevWeapon() { return FFTKEY_prevweapon; } int FFTInput::GetNextWeapon() { return FFTKEY_nextweapon; } int FFTInput::GetDock() { return FFTKEY_dock; } int FFTInput::GetPrevTarget() { return FFTKEY_prevtarget; } int FFTInput::GetNextTarget() { return FFTKEY_nexttarget; } std::string FFTInput::GetFire1Str() { return KeyCodeToString(FFTKEY_fire1); } std::string FFTInput::GetFire2Str() { return KeyCodeToString(FFTKEY_fire2); } std::string FFTInput::GetWarp1Str() { return KeyCodeToString(FFTKEY_warp1); } std::string FFTInput::GetWarp2Str() { return KeyCodeToString(FFTKEY_warp2); } std::string FFTInput::GetUpStr() { return KeyCodeToString(FFTKEY_up); } std::string FFTInput::GetDownStr() { return KeyCodeToString(FFTKEY_down); } std::string FFTInput::GetLeftStr() { return KeyCodeToString(FFTKEY_left); } std::string FFTInput::GetRightStr() { return KeyCodeToString(FFTKEY_right); } std::string FFTInput::GetAllStopStr() { return KeyCodeToString(FFTKEY_allstop); } std::string FFTInput::GetCancelStr() { return KeyCodeToString(FFTKEY_cancel); } std::string FFTInput::GetMiniMapZoomInStr() { return KeyCodeToString(FFTKEY_minimapzoomin); } std::string FFTInput::GetMiniMapZoomOutStr() { return KeyCodeToString(FFTKEY_minimapzoomout); } std::string FFTInput::GetPauseStr() { return KeyCodeToString(FFTKEY_pause); } std::string FFTInput::GetZoomInStr() { return KeyCodeToString(FFTKEY_zoomin); } std::string FFTInput::GetZoomOutStr() { return KeyCodeToString(FFTKEY_zoomout); } std::string FFTInput::GetPrevWeaponStr() { return KeyCodeToString(FFTKEY_prevweapon); } std::string FFTInput::GetNextWeaponStr() { return KeyCodeToString(FFTKEY_nextweapon); } std::string FFTInput::GetDockStr() { return KeyCodeToString(FFTKEY_dock); } std::string FFTInput::GetPrevTargetStr() { return KeyCodeToString(FFTKEY_prevtarget); } std::string FFTInput::GetNextTargetStr() { return KeyCodeToString(FFTKEY_nexttarget); } void FFTInput::SetFire1(int sdlKeyCode) { FFTKEY_fire1=sdlKeyCode; } void FFTInput::SetFire2(int sdlKeyCode) { FFTKEY_fire2=sdlKeyCode; } void FFTInput::SetWarp1(int sdlKeyCode) { FFTKEY_warp1=sdlKeyCode; } void FFTInput::SetWarp2(int sdlKeyCode) { FFTKEY_warp2=sdlKeyCode; } void FFTInput::SetUp(int sdlKeyCode) { FFTKEY_up=sdlKeyCode; } void FFTInput::SetDown(int sdlKeyCode) { FFTKEY_down=sdlKeyCode; } void FFTInput::SetLeft(int sdlKeyCode) { FFTKEY_left=sdlKeyCode; } void FFTInput::SetRight(int sdlKeyCode) { FFTKEY_right=sdlKeyCode; } void FFTInput::SetAllStop(int sdlKeyCode) { FFTKEY_allstop=sdlKeyCode; } void FFTInput::SetCancel(int sdlKeyCode) { FFTKEY_cancel=sdlKeyCode; } void FFTInput::SetMiniMapZoomIn(int sdlKeyCode) { FFTKEY_minimapzoomin=sdlKeyCode; } void FFTInput::SetMiniMapZoomOut(int sdlKeyCode) { FFTKEY_minimapzoomout=sdlKeyCode; } void FFTInput::SetPause(int sdlKeyCode) { FFTKEY_pause=sdlKeyCode; } void FFTInput::SetZoomIn(int sdlKeyCode) { FFTKEY_zoomin=sdlKeyCode; } void FFTInput::SetZoomOut(int sdlKeyCode) { FFTKEY_zoomout=sdlKeyCode; } void FFTInput::SetPrevWeapon(int sdlKeyCode) { FFTKEY_prevweapon=sdlKeyCode; } void FFTInput::SetNextWeapon(int sdlKeyCode) { FFTKEY_nextweapon=sdlKeyCode; } void FFTInput::SetDock(int sdlKeyCode) { FFTKEY_dock=sdlKeyCode; } void FFTInput::SetPrevTarget(int sdlKeyCode) { FFTKEY_prevtarget=sdlKeyCode; } void FFTInput::SetNextTarget(int sdlKeyCode) { FFTKEY_nexttarget=sdlKeyCode; } bool FFTInput::KeyInUse(int sdlKeyCode) { if (sdlKeyCode==FFTKEY_fire1) return true; else if (sdlKeyCode==FFTKEY_fire2) return true; else if (sdlKeyCode==FFTKEY_warp1) return true; else if (sdlKeyCode==FFTKEY_warp2) return true; else if (sdlKeyCode==FFTKEY_up) return true; else if (sdlKeyCode==FFTKEY_down) return true; else if (sdlKeyCode==FFTKEY_left) return true; else if (sdlKeyCode==FFTKEY_right) return true; else if (sdlKeyCode==FFTKEY_allstop) return true; else if (sdlKeyCode==FFTKEY_cancel) return true; else if (sdlKeyCode==FFTKEY_minimapzoomin) return true; else if (sdlKeyCode==FFTKEY_minimapzoomout) return true; else if (sdlKeyCode==FFTKEY_pause) return true; else if (sdlKeyCode==FFTKEY_zoomin) return true; else if (sdlKeyCode==FFTKEY_zoomout) return true; else if (sdlKeyCode==FFTKEY_prevweapon) return true; else if (sdlKeyCode==FFTKEY_nextweapon) return true; else if (sdlKeyCode==FFTKEY_dock) return true; else if (sdlKeyCode==FFTKEY_prevtarget) return true; else if (sdlKeyCode==FFTKEY_nexttarget) return true; else return false; } std::string FFTInput::KeyCodeToString(int sdlKeyCode) { std::string key; switch(sdlKeyCode) { case SDLK_BACKSPACE: key="backspace"; break; case SDLK_TAB: key="TAB"; break; case SDLK_CLEAR: key="Clear"; break; case SDLK_RETURN: key="ENTER"; break; case SDLK_PAUSE: key="pause"; break; case SDLK_ESCAPE: key="escape"; break; case SDLK_SPACE: key="space"; break; case SDLK_EXCLAIM: key="!"; break; case SDLK_QUOTEDBL: key="\"\""; break; case SDLK_HASH: key="#"; break; case SDLK_DOLLAR: key="$"; break; case SDLK_AMPERSAND: key="&"; break; case SDLK_QUOTE: key="\""; break; case SDLK_ASTERISK: key="*"; break; case SDLK_PLUS: key="+"; break; case SDLK_COMMA: key=","; break; case SDLK_MINUS: key="-"; break; case SDLK_PERIOD: key="."; break; case SDLK_SLASH: key="/"; break; case SDLK_0: key="0"; break; case SDLK_1: key="1"; break; case SDLK_2: key="2"; break; case SDLK_3: key="3"; break; case SDLK_4: key="4"; break; case SDLK_5: key="5"; break; case SDLK_6: key="6"; break; case SDLK_7: key="7"; break; case SDLK_8: key="8"; break; case SDLK_9: key="9"; break; case SDLK_COLON: key=":"; break; case SDLK_SEMICOLON: key=";"; break; case SDLK_LESS: key="<"; break; case SDLK_EQUALS: key="="; break; case SDLK_GREATER: key=">"; break; case SDLK_QUESTION: key="?"; break; case SDLK_AT: key="@"; break; case SDLK_LEFTBRACKET: key="["; break; case SDLK_BACKSLASH: key="\\"; break; case SDLK_RIGHTBRACKET: key="]"; break; case SDLK_CARET: key="^"; break; case SDLK_UNDERSCORE: key="_"; break; case SDLK_BACKQUOTE: key="`"; break; case SDLK_a: key="a"; break; case SDLK_b: key="b"; break; case SDLK_c: key="c"; break; case SDLK_d: key="d"; break; case SDLK_e: key="e"; break; case SDLK_f: key="f"; break; case SDLK_g: key="g"; break; case SDLK_h: key="h"; break; case SDLK_i: key="i"; break; case SDLK_j: key="j"; break; case SDLK_k: key="k"; break; case SDLK_l: key="l"; break; case SDLK_m: key="m"; break; case SDLK_n: key="n"; break; case SDLK_o: key="o"; break; case SDLK_p: key="p"; break; case SDLK_q: key="q"; break; case SDLK_r: key="r"; break; case SDLK_s: key="s"; break; case SDLK_t: key="t"; break; case SDLK_u: key="u"; break; case SDLK_v: key="v"; break; case SDLK_w: key="w"; break; case SDLK_x: key="x"; break; case SDLK_y: key="y"; break; case SDLK_z: key="z"; break; case SDLK_DELETE: key="delete"; break; case SDLK_KP0: key="keypad 0"; break; case SDLK_KP1: key="keypad 1"; break; case SDLK_KP2: key="keypad 2"; break; case SDLK_KP3: key="keypad 3"; break; case SDLK_KP4: key="keypad 4"; break; case SDLK_KP5: key="keypad 5"; break; case SDLK_KP6: key="keypad 6"; break; case SDLK_KP7: key="keypad 7"; break; case SDLK_KP8: key="keypad 8"; break; case SDLK_KP9: key="keypad 9"; break; case SDLK_KP_PERIOD: key="keypad ."; break; case SDLK_KP_DIVIDE: key="keypad /"; break; case SDLK_KP_MULTIPLY: key="keypad *"; break; case SDLK_KP_MINUS: key="keypad -"; break; case SDLK_KP_PLUS: key="keypad +"; break; case SDLK_KP_ENTER: key="keypad enter"; break; case SDLK_KP_EQUALS: key="keypad ="; break; case SDLK_UP: key="up"; break; case SDLK_DOWN: key="down"; break; case SDLK_RIGHT: key="right"; break; case SDLK_LEFT: key="left"; break; case SDLK_INSERT: key="insert"; break; case SDLK_HOME: key="home"; break; case SDLK_END: key="end"; break; case SDLK_PAGEUP: key="page up"; break; case SDLK_PAGEDOWN: key="page down"; break; case SDLK_F1: key="F1"; break; case SDLK_F2: key="F2"; break; case SDLK_F3: key="F3"; break; case SDLK_F4: key="F4"; break; case SDLK_F5: key="F5"; break; case SDLK_F6: key="F6"; break; case SDLK_F7: key="F7"; break; case SDLK_F8: key="F8"; break; case SDLK_F9: key="F9"; break; case SDLK_F10: key="F10"; break; case SDLK_F11: key="F11"; break; case SDLK_F12: key="F12"; break; case SDLK_F13: key="F13"; break; case SDLK_F14: key="F14"; break; case SDLK_F15: key="F15"; break; case SDLK_NUMLOCK: key="numlock"; break; case SDLK_CAPSLOCK: key="capslock"; break; case SDLK_SCROLLOCK: key="scrollock"; break; case SDLK_RSHIFT: key="right shift"; break; case SDLK_LSHIFT: key="left shift"; break; case SDLK_RCTRL: key="right ctrl"; break; case SDLK_LCTRL: key="left ctrl"; break; case SDLK_RALT: key="right alt"; break; case SDLK_LALT: key="left alt"; break; case SDLK_RMETA: key="right meta"; break; case SDLK_LMETA: key="left meta"; break; case SDLK_LSUPER: key="left windows key"; break; case SDLK_RSUPER: key="right windows key"; break; case SDLK_MODE: key="mode shift"; break; case SDLK_HELP: key="help"; break; case SDLK_PRINT: key="print-screen"; break; case SDLK_SYSREQ: key="SysRq"; break; case SDLK_BREAK: key="break"; break; case SDLK_MENU: key="menu"; break; case SDLK_POWER: key="power"; break; case SDLK_EURO: key="euro"; break; } return key; } int FFTInput::StringToKeyCode(std::string str) { int key=0; if (!strcmp(str.c_str(),"backspace")) key=SDLK_BACKSPACE; if(!strcmp(str.c_str(),"TAB")) key=SDLK_TAB; if(!strcmp(str.c_str(),"Clear")) key=SDLK_CLEAR; if(!strcmp(str.c_str(),"ENTER")) key=SDLK_RETURN; if(!strcmp(str.c_str(),"pause")) key=SDLK_PAUSE; if(!strcmp(str.c_str(),"escape")) key=SDLK_ESCAPE; if(!strcmp(str.c_str(),"space")) key=SDLK_SPACE; if(!strcmp(str.c_str(),"!")) key=SDLK_EXCLAIM; if(!strcmp(str.c_str(),"\"\"")) key=SDLK_QUOTEDBL; if(!strcmp(str.c_str(),"#")) key=SDLK_HASH; if(!strcmp(str.c_str(),"$")) key=SDLK_DOLLAR; if(!strcmp(str.c_str(),"&")) key=SDLK_AMPERSAND; if(!strcmp(str.c_str(),"\"")) key=SDLK_QUOTE; if(!strcmp(str.c_str(),"*")) key=SDLK_ASTERISK; if(!strcmp(str.c_str(),"+")) key=SDLK_PLUS; if(!strcmp(str.c_str(),",")) key=SDLK_COMMA; if(!strcmp(str.c_str(),"-")) key=SDLK_MINUS; if(!strcmp(str.c_str(),".")) key=SDLK_PERIOD; if(!strcmp(str.c_str(),"/")) key=SDLK_SLASH; if(!strcmp(str.c_str(),"0")) key=SDLK_0; if(!strcmp(str.c_str(),"1")) key=SDLK_1; if(!strcmp(str.c_str(),"2")) key=SDLK_2; if(!strcmp(str.c_str(),"3")) key=SDLK_3; if(!strcmp(str.c_str(),"4")) key=SDLK_4; if(!strcmp(str.c_str(),"5")) key=SDLK_5; if(!strcmp(str.c_str(),"6")) key=SDLK_6; if(!strcmp(str.c_str(),"7")) key=SDLK_7; if(!strcmp(str.c_str(),"8")) key=SDLK_8; if(!strcmp(str.c_str(),"9")) key=SDLK_9; if(!strcmp(str.c_str(),":")) key=SDLK_COLON; if(!strcmp(str.c_str(),";")) key=SDLK_SEMICOLON; if(!strcmp(str.c_str(),"<")) key=SDLK_LESS; if(!strcmp(str.c_str(),"=")) key=SDLK_EQUALS; if(!strcmp(str.c_str(),">")) key=SDLK_GREATER; if(!strcmp(str.c_str(),"?")) key=SDLK_QUESTION; if(!strcmp(str.c_str(),"@")) key=SDLK_AT; if(!strcmp(str.c_str(),"[")) key=SDLK_LEFTBRACKET; if(!strcmp(str.c_str(),"\\")) key=SDLK_BACKSLASH; if(!strcmp(str.c_str(),"]")) key=SDLK_RIGHTBRACKET; if(!strcmp(str.c_str(),"^")) key=SDLK_CARET; if(!strcmp(str.c_str(),"_")) key=SDLK_UNDERSCORE; if(!strcmp(str.c_str(),"`")) key=SDLK_BACKQUOTE; if(!strcmp(str.c_str(),"a")) key=SDLK_a; if(!strcmp(str.c_str(),"b")) key=SDLK_b; if(!strcmp(str.c_str(),"c")) key=SDLK_c; if(!strcmp(str.c_str(),"d")) key=SDLK_d; if(!strcmp(str.c_str(),"e")) key=SDLK_e; if(!strcmp(str.c_str(),"f")) key=SDLK_f; if(!strcmp(str.c_str(),"g")) key=SDLK_g; if(!strcmp(str.c_str(),"h")) key=SDLK_h; if(!strcmp(str.c_str(),"i")) key=SDLK_i; if(!strcmp(str.c_str(),"j")) key=SDLK_j; if(!strcmp(str.c_str(),"k")) key=SDLK_k; if(!strcmp(str.c_str(),"l")) key=SDLK_l; if(!strcmp(str.c_str(),"m")) key=SDLK_m; if(!strcmp(str.c_str(),"n")) key=SDLK_n; if(!strcmp(str.c_str(),"o")) key=SDLK_o; if(!strcmp(str.c_str(),"p")) key=SDLK_p; if(!strcmp(str.c_str(),"q")) key=SDLK_q; if(!strcmp(str.c_str(),"r")) key=SDLK_r; if(!strcmp(str.c_str(),"s")) key=SDLK_s; if(!strcmp(str.c_str(),"t")) key=SDLK_t; if(!strcmp(str.c_str(),"u")) key=SDLK_u; if(!strcmp(str.c_str(),"v")) key=SDLK_v; if(!strcmp(str.c_str(),"w")) key=SDLK_w; if(!strcmp(str.c_str(),"x")) key=SDLK_x; if(!strcmp(str.c_str(),"y")) key=SDLK_y; if(!strcmp(str.c_str(),"z")) key=SDLK_z; if(!strcmp(str.c_str(),"delete")) key=SDLK_DELETE; if(!strcmp(str.c_str(),"keypad 0")) key=SDLK_KP0; if(!strcmp(str.c_str(),"keypad 1")) key=SDLK_KP1; if(!strcmp(str.c_str(),"keypad 2")) key=SDLK_KP2; if(!strcmp(str.c_str(),"keypad 3")) key=SDLK_KP3; if(!strcmp(str.c_str(),"keypad 4")) key=SDLK_KP4; if(!strcmp(str.c_str(),"keypad 5")) key=SDLK_KP5; if(!strcmp(str.c_str(),"keypad 6")) key=SDLK_KP6; if(!strcmp(str.c_str(),"keypad 7")) key=SDLK_KP7; if(!strcmp(str.c_str(),"keypad 8")) key=SDLK_KP8; if(!strcmp(str.c_str(),"keypad 9")) key=SDLK_KP9; if(!strcmp(str.c_str(),"keypad .")) key=SDLK_KP_PERIOD; if(!strcmp(str.c_str(),"keypad /")) key=SDLK_KP_DIVIDE; if(!strcmp(str.c_str(),"keypad *")) key=SDLK_KP_MULTIPLY; if(!strcmp(str.c_str(),"keypad -")) key=SDLK_KP_MINUS; if(!strcmp(str.c_str(),"keypad +")) key=SDLK_KP_PLUS; if(!strcmp(str.c_str(),"keypad enter")) key=SDLK_KP_ENTER; if(!strcmp(str.c_str(),"keypad =")) key=SDLK_KP_EQUALS; if(!strcmp(str.c_str(),"up")) key=SDLK_UP; if(!strcmp(str.c_str(),"down")) key=SDLK_DOWN; if(!strcmp(str.c_str(),"right")) key=SDLK_RIGHT; if(!strcmp(str.c_str(),"left")) key=SDLK_LEFT; if(!strcmp(str.c_str(),"insert")) key=SDLK_INSERT; if(!strcmp(str.c_str(),"home")) key=SDLK_HOME; if(!strcmp(str.c_str(),"end")) key=SDLK_END; if(!strcmp(str.c_str(),"page up")) key=SDLK_PAGEUP; if(!strcmp(str.c_str(),"page down")) key=SDLK_PAGEDOWN; if(!strcmp(str.c_str(),"F1")) key=SDLK_F1; if(!strcmp(str.c_str(),"F2")) key=SDLK_F2; if(!strcmp(str.c_str(),"F3")) key=SDLK_F3; if(!strcmp(str.c_str(),"F4")) key=SDLK_F4; if(!strcmp(str.c_str(),"F5")) key=SDLK_F5; if(!strcmp(str.c_str(),"F6")) key=SDLK_F6; if(!strcmp(str.c_str(),"F7")) key=SDLK_F7; if(!strcmp(str.c_str(),"F8")) key=SDLK_F8; if(!strcmp(str.c_str(),"F9")) key=SDLK_F9; if(!strcmp(str.c_str(),"F10")) key=SDLK_F10; if(!strcmp(str.c_str(),"F11")) key=SDLK_F11; if(!strcmp(str.c_str(),"F12")) key=SDLK_F12; if(!strcmp(str.c_str(),"F13")) key=SDLK_F13; if(!strcmp(str.c_str(),"F14")) key=SDLK_F14; if(!strcmp(str.c_str(),"F15")) key=SDLK_F15; if(!strcmp(str.c_str(),"numlock")) key=SDLK_NUMLOCK; if(!strcmp(str.c_str(),"capslock")) key=SDLK_CAPSLOCK; if(!strcmp(str.c_str(),"scrollock")) key=SDLK_SCROLLOCK; if(!strcmp(str.c_str(),"right shift")) key=SDLK_RSHIFT; if(!strcmp(str.c_str(),"left shift")) key=SDLK_LSHIFT; if(!strcmp(str.c_str(),"right ctrl")) key=SDLK_RCTRL; if(!strcmp(str.c_str(),"left ctrl")) key=SDLK_LCTRL; if(!strcmp(str.c_str(),"right alt")) key=SDLK_RALT; if(!strcmp(str.c_str(),"left alt")) key=SDLK_LALT; if(!strcmp(str.c_str(),"right meta")) key=SDLK_RMETA; if(!strcmp(str.c_str(),"left meta")) key=SDLK_LMETA; if(!strcmp(str.c_str(),"left windows key")) key=SDLK_LSUPER; if(!strcmp(str.c_str(),"right windows key")) key=SDLK_RSUPER; if(!strcmp(str.c_str(),"mode shift")) key=SDLK_MODE; if(!strcmp(str.c_str(),"help")) key=SDLK_HELP; if(!strcmp(str.c_str(),"print-screen")) key=SDLK_PRINT; if(!strcmp(str.c_str(),"SysRq")) key=SDLK_SYSREQ; if(!strcmp(str.c_str(),"break")) key=SDLK_BREAK; if(!strcmp(str.c_str(),"menu")) key=SDLK_MENU; if(!strcmp(str.c_str(),"power")) key=SDLK_POWER; if(!strcmp(str.c_str(),"euro")) key=SDLK_EURO; return key; } --- NEW FILE: input.h --- #ifndef _INPUT_H #define _INPUT_H #include <string> #include "SDL.h" class FFTInput { public: FFTInput(); ~FFTInput() {}; int GetFire1(); int GetFire2(); int GetWarp1(); int GetWarp2(); int GetUp(); int GetDown(); int GetLeft(); int GetRight(); int GetAllStop(); int GetCancel(); int GetMiniMapZoomIn(); int GetMiniMapZoomOut(); int GetPause(); int GetZoomIn(); int GetZoomOut(); int GetPrevWeapon(); int GetNextWeapon(); int GetDock(); int GetPrevTarget(); int GetNextTarget(); std::string GetFire1Str(); std::string GetFire2Str(); std::string GetWarp1Str(); std::string GetWarp2Str(); std::string GetUpStr(); std::string GetDownStr(); std::string GetLeftStr(); std::string GetRightStr(); std::string GetAllStopStr(); std::string GetCancelStr(); std::string GetMiniMapZoomInStr(); std::string GetMiniMapZoomOutStr(); std::string GetPauseStr(); std::string GetZoomInStr(); std::string GetZoomOutStr(); std::string GetPrevWeaponStr(); std::string GetNextWeaponStr(); std::string GetDockStr(); std::string GetPrevTargetStr(); std::string GetNextTargetStr(); void SetFire1(int sdlKeyCode); void SetFire2(int sdlKeyCode); void SetWarp1(int sdlKeyCode); void SetWarp2(int sdlKeyCode); void SetUp(int sdlKeyCode); void SetDown(int sdlKeyCode); void SetLeft(int sdlKeyCode); void SetRight(int sdlKeyCode); void SetAllStop(int sdlKeyCode); void SetCancel(int sdlKeyCode); void SetMiniMapZoomIn(int sdlKeyCode); void SetMiniMapZoomOut(int sdlKeyCode); void SetPause(int sdlKeyCode); void SetZoomIn(int sdlKeyCode); void SetZoomOut(int sdlKeyCode); void SetPrevWeapon(int sdlKeyCode); void SetNextWeapon(int sdlKeyCode); void SetDock(int sdlKeyCode); void SetPrevTarget(int sdlKeyCode); void SetNextTarget(int sdlKeyCode); bool KeyInUse(int sdlKeyCode); std::string KeyCodeToString(int sdlKeyCode); int StringToKeyCode(std::string str); private: int FFTKEY_fire1; int FFTKEY_fire2; int FFTKEY_warp1; int FFTKEY_warp2; int FFTKEY_up; int FFTKEY_down; int FFTKEY_left; int FFTKEY_right; int FFTKEY_allstop; int FFTKEY_cancel; int FFTKEY_minimapzoomin; int FFTKEY_minimapzoomout; int FFTKEY_pause; int FFTKEY_zoomin; int FFTKEY_zoomout; int FFTKEY_prevweapon; int FFTKEY_nextweapon; int FFTKEY_dock; int FFTKEY_prevtarget; int FFTKEY_nexttarget; }; #endif /* _INPUT_H */ --- NEW FILE: units.h --- #ifndef __UNITS_H__ #define __UNITS_H__ #define PI 3.1415926535897932384626433832795 #define UNITS_NUM_FRAMES 72 #include <string> #include "SDL_mixer.h" #include "graphics.h" #include "fftfile.h" #include "math.h" #define AI_STATE_STOP 1000 #define AI_STATE_RUN 1001 #define AI_STATE_ATTACK 1002 #define AI_STATE_LOOK 1003 #define AI_STATE_IGNORE 1004 #define AI_STATE_WAITLOOK 1005 extern Mix_Chunk *explode; extern Mix_Chunk *shot; extern int SMOOTH; extern bool LOG; typedef struct{ std::string type; unsigned int priceBought; }__cargo; class Unit { public: Unit(); ~Unit(); void Reset(); void CleanUp(); void Init(int sx, int sy, std::string img, std::string fpk, float zzoom); void Init(int sx, int sy, std::string img, SDL_Surface *img2, std::string fpk, float zzoom); void Display(int sx, int sy); void StatusDisplay(int sx, int sy, int sw, int sh, TTF_Font *font); void SetSpeed(int sSpeed); void SetAngle(int sAngle); void SetX(int sx); void SetY(int sy); void SetAI(std::string ai); void SetAIState(int state); void Move(int sx, int sy); void SetMMR(Uint8 sr); void SetMMG(Uint8 sg); void SetMMB(Uint8 sb); void SetWarp(bool sw); void SetName(std::string sname); void SetZoom(float szoom); void SetMaxSpeed(int ms); void SetMaxWarp(int mw); void SetMaxSafeWarp(int msw); void SetTurnDelay(int td); void SetWarpTurnDelay(int tdw); void SetHullHitMax(int hhm); void SetShieldHitMax(int shm); void SetOverHeatMax(int ohm); void SetShootPoint(int sx, int sy); void SetCredits(unsigned int cred); void SetPriceBought(unsigned int spricebought); void AdjustShootPoint(); void ResetHits(); void SetHullHits(int hh); void SetShieldHits(int sh); void PrevWeapon(); void NextWeapon(); void Rotate(int rotation); void EnableWarp(); void DisableWarp(); void AddShield(std::string shieldpic); void AddWeaponToSlot(int slotid, std::string fpk, std::string fn, int amount=0); void RemoveWeaponFromSlot(int slotid); void ReduceAmmo(int slotid); void AddWeaponBayToSlot(int slotid, std::string holdweapon, int holdamount); void RemoveWeaponBayFromSlot(int slotid); void AddCargoBayToSlot(int slotid, int units); void RemoveCargoBayFromSlot(int slotid); void AddToCargo(__cargo newcargo); void SortCargo(); void RemoveFromCargo(int cargoindex); void RemoveAmountFromCargo(std::string type, int quantity); __ship_slot GetCurWeaponSlot(); int GetWidth(); int GetHeight(); int GetImageWidth(); int GetImageHeight(); int GetDispImageW(); int GetDispImageH(); Uint8 GetMMR(); Uint8 GetMMG(); Uint8 GetMMB(); int GetSpeed(); int GetAngle(); int GetX(); int GetY(); double GetDX(); double GetDY(); int GetNegX(); int GetNegY(); int GetSectorX(); int GetSectorY(); int GetMaxSpeed(); int GetMaxWarp(); int GetMaxSafeWarp(); int GetTurnDelay(); int GetWarpTurnDelay(); int GetMaxHullHits(); int GetHullHits(); int GetMaxShieldHits(); int GetShieldHits(); int GetShootX(); int GetShootY(); unsigned int GetCredits(); unsigned int GetPriceBought(); int GetCargoUnits(); int GetCargoFill(); float GetZoom(); std::string GetCurWeaponFN(); std::string GetCurWeaponFPK(); std::string GetName(); bool AtWarp(); bool WarpEnabled(); bool HasShield(); void Hit(); bool IsAIFiring(); bool IsOverHeated(); void Orbit(); void Orbit(int sx, int sy, int rad); void SetOrbit(bool orbit); bool IsOrbiter(); void FreeImages(); void FPK_NewImages(std::string fpk, std::string imagename); void ReloadImages(); void LoadImages(int start, int end); bool IsLoaded(int pic); bool ShieldIsLoaded(int pic); SDL_Surface *GetCurImage(); void DisplayDispImage(int x, int y); void ZeroSlots(); void FillSlots(__ship_slot *sls, int max); __ship_slot *GetSlots(); __cargo *GetCargo(); int GetNumSlots(); int GetHeatSeekingBay(); int GetHeatSeekingAmmoFill(); int GetHeatSeekingAmmoSpace(); void Colorize(Uint8 r, Uint8 g, Uint8 b); bitmask *mask[UNITS_NUM_FRAMES]; bitmask *smask[UNITS_NUM_FRAMES]; int radius, orbitx, orbity; private: int angleinc; int angle; double angle2; int speed; std::string imgload; std::string usingfpk; SDL_Surface *image[UNITS_NUM_FRAMES]; SDL_Surface *dispimg; int x; int y; double dx; double dy; std::string aiscript; Uint32 aiwait; int aistate; int aiwaitfor; Uint8 mmr; Uint8 mmg; Uint8 mmb; Uint8 cr; Uint8 cg; Uint8 cb; bool warp; bool warpenabled; bool orbiter; std::string name; float zoom; SDL_Surface *shield[UNITS_NUM_FRAMES]; std::string shieldload; bool hasShield; bool hadShield; int maxspeed; int maxwarp; int maxsafewarp; int turndelay; int warpturndelay; int curweapon; int overheatcount, overheatmax; Uint32 overheatwait; int hullhitmax, shieldhitmax, numshieldhits, numhullhits; int shootx, shooty, origshootx, origshooty; bool aifire; std::string curweaponfn; std::string curweaponfpk; __ship_slot slots[__MAXSHIPSLOTS]; int numslots; unsigned int credits; unsigned int pricebought; int cargounits; int cargofill; __cargo cargo[1000]; }; #endif /* __UNITS_H__ */ --- NEW FILE: graphics.cpp --- #include "graphics.h" #include "mac.h" void CenterWindow() { SDL_Surface *screen=SDL_GetVideoSurface(); SDL_SysWMinfo info; SDL_VERSION(&info.version); if ( SDL_GetWMInfo(&info) > 0 ) { #ifdef __unix if ( info.subsystem == SDL_SYSWM_X11 ) { info.info.x11.lock_func(); int w = DisplayWidth(info.info.x11.display, DefaultScreen(info.info.x11.display)); int h = DisplayHeight(info.info.x11.display, DefaultScreen(info.info.x11.display)); int x = (w - screen->w)/2; int y = (h - screen->h)/2; XMoveWindow(info.info.x11.display, info.info.x11.wmwindow, x, y); info.info.x11.unlock_func(); } #endif // unix #ifdef WIN32 { RECT rc; HWND hwnd = info.window; int w=GetSystemMetrics(SM_CXSCREEN); int h=GetSystemMetrics(SM_CYSCREEN); GetWindowRect(hwnd, &rc); int x = (w - (rc.right-rc.left))/2; int y = (h - (rc.bottom-rc.top))/2; SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE|SWP_NOZORDER); } #endif // win } #if defined(__APPLE__) && defined(__GNUC__) // mac mac_CenterWindow(); #endif } static bool screen_locked = false; int safeBlitToScreen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect) { SDL_Surface *screen=SDL_GetVideoSurface(); bool lock = SDL_MUSTLOCK(screen); if (lock && screen_locked) SDL_UnlockSurface(screen); int res = SDL_BlitSurface(src, srcrect, screen, dstrect); if (lock && screen_locked) SDL_LockSurface(screen); return res; } void drawString(TTF_Font *font, int x, int y, std::string text, SDL_Color color) { SDL_Surface *temp=TTF_RenderText_Blended(font, text.c_str(), color); SDL_Rect fontpos; fontpos.x=x; fontpos.y=y; safeBlitToScreen(temp, NULL, &fontpos); SDL_FreeSurface(temp); } void centerString(TTF_Font *font, int x, int y, std::string text, SDL_Color color) { SDL_Surface *temp=TTF_RenderText_Blended(font, text.c_str(), color); SDL_Rect fontpos; fontpos.x=x-(int)temp->w/2; fontpos.y=y-(int)temp->h/2; safeBlitToScreen(temp, NULL, &fontpos); SDL_FreeSurface(temp); } void DrawIMG(SDL_Surface *img, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; safeBlitToScreen(img, NULL, &dest); } void DrawIMG(SDL_Surface *img, int x, int y, int w, int h) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_Rect dest2; dest2.x = 0; dest2.y = 0; dest2.w = w; dest2.h = h; safeBlitToScreen(img, &dest2, &dest); } void DrawPixel(int x, int y, Uint8 R, Uint8 G, Uint8 B) { SDL_Surface *screen=SDL_GetVideoSurface(); Uint32 color = SDL_MapRGB(screen->format, R, G, B); switch (screen->format->BytesPerPixel) { case 1: // Assuming 8-bpp { Uint8 *bufp; bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; *bufp = color; } break; case 2: // Probably 15-bpp or 16-bpp { Uint16 *bufp; bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; *bufp = color; } break; case 3: // Slow 24-bpp mode, usually not used { Uint8 *bufp; bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3; if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { bufp[0] = color; bufp[1] = color >> 8; bufp[2] = color >> 16; } else { bufp[2] = color; bufp[1] = color >> 8; bufp[0] = color >> 16; } } break; case 4: // Probably 32-bpp { Uint32 *bufp; bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x; *bufp = color; } break; } } void Slock() { SDL_Surface *screen=SDL_GetVideoSurface(); if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { return; } else { screen_locked = true; } } } void Sulock() { SDL_Surface *screen=SDL_GetVideoSurface(); if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); screen_locked = false; } } /* * Return the pixel value at (x, y) * NOTE: The surface must be locked before calling this! */ Uint32 getpixel(SDL_Surface *surface, int x, int y) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: return *p; case 2: return *(Uint16 *)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; case 4: return *(Uint32 *)p; default: return 0; /* shouldn't happen, but avoids warnings */ } } void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } } bitmask *MakeMask(SDL_Surface *surface) { int i, j; Uint8 r1=0; Uint8 g1=0; Uint8 b1=0; Uint8 a1=255; SDL_Rect *r; SDL_Rect rr; rr.x=0; rr.y=0; rr.w=surface->w; rr.h=surface->h; r=&rr; bitmask *mask; if ( SDL_MUSTLOCK(surface) ) { SDL_LockSurface(surface); } mask=bitmask_create(r->w,r->h); for (j = r->y; j < r->h + r->y; j++) { for (i=r->x; i < r->w + r->x; i++) { SDL_GetRGBA(getpixel(surface, i, j), surface->format, &r1, &g1, &b1, &a1); if (a1>128) { bitmask_setbit(mask,i-r->x,j-r->y); } } } if ( SDL_MUSTLOCK(surface) ) { SDL_UnlockSurface(surface); } return mask; } bool BoxCollision(SDL_Rect dest, SDL_Rect src) { // calculate box collision return ((((src.x >= dest.x) && (src.x <= (dest.x+dest.w))) && ((src.y >= dest.y) && (src.y <= (dest.y+dest.h)))) || ((((src.x+src.w) >= dest.x) && ((src.x+src.w) <= (dest.x+dest.w))) && (((src.y+src.h) >= dest.y) && ((src.y+src.h) <= (dest.y+dest.h))))); } void ColorizeSurface(SDL_Surface *surf, Uint8 r, Uint8 g, Uint8 b) { boxRGBA(surf, 0, 0, surf->w, surf->h, r, g, b, 128); } //StarField class void StarField::Init(int fieldw, int fieldh) { int i, sfSize, x, y; width=fieldw; height=fieldh; sfSize=sizeof(starfieldx)/sizeof(starfieldx[0]); for(i=0; i<sfSize; i++) { x=rand()%width; y=rand()%height; starfieldx[i]=x; starfieldy[i]=y; } } void StarField::Display(int x, int y) { int i, sfSize, tx, ty; sfSize=sizeof(starfieldx)/sizeof(starfieldx[0]); for(i=0; i<sfSize; i++) { if (starfieldx[i]+x >= width) { tx=(starfieldx[i]+x)%width; } else { if (starfieldx[i]+x < 0) { tx=((starfieldx[i]+x)%width)+width; } else { tx=starfieldx[i]+x; } } if (starfieldy[i]+y >= height-1) { ty=(starfieldy[i]+y)%(height-1); } else { if (starfieldy[i]+y < 0) { ty=((starfieldy[i]+y)%(height-1))+(height-1); } else { ty=starfieldy[i]+y; } } DrawPixel(tx, ty, 255, 255, 255); } } void StarField::DisplayWarp(int x, int y, int angle, int length) { SDL_Surface *screen=SDL_GetVideoSurface(); int i, sfSize, tx, ty, tx2, ty2; double xsub, ysub; bool blitok; sfSize=sizeof(starfieldx)/sizeof(starfieldx[0]); xsub=-(sin(angle*(PI/180))); ysub=(cos(angle*(PI/180))); for(i=0; i<sfSize; i++) { blitok=true; if (starfieldx[i]+x >= width) { tx=(starfieldx[i]+x)%width; } else { if (starfieldx[i]+x < 0) { tx=((starfieldx[i]+x)%width)+width; } else { tx=starfieldx[i]+x; } } if (starfieldy[i]+y >= height-1) { ty=(starfieldy[i]+y)%(height-1); } else { if (starfieldy[i]+y < 0) { ty=((starfieldy[i]+y)%(height-1))+(height-1); } else { ty=starfieldy[i]+y; } } if (starfieldx[i]+x-(int)(xsub*length) >= width) { tx2=(starfieldx[i]+x-(int)(xsub*length))%width; } else { if (starfieldx[i]+x-(int)(xsub*length) < 0) { tx2=((starfieldx[i]+x-(int)(xsub*length))%width)+width; } else { tx2=starfieldx[i]+x-(int)(xsub*length); } } if (starfieldy[i]+y-(int)(ysub*length) >= height-1) { ty2=(starfieldy[i]+y-(int)(ysub*length))%(height-1); } else { if (starfieldy[i]+y-(int)(ysub*length) < 0) { ty2=((starfieldy[i]+y-(int)(ysub*length))%(height-1)) +(height-1); } else { ty2=starfieldy[i]+y-(int)(ysub*length); } } if (angle>=0 && angle<=180) { if (tx>tx2) { blitok=false; } } if (angle>=180 && angle<=360) { if (tx<tx2) { blitok=false; } } if ((angle>=270 && angle<=360) || (angle>=0 && angle<=90)) { if (ty<ty2) { blitok=false; } } if (angle<=270 && angle>=90) { if (ty>ty2) { blitok=false; } } if (blitok) { lineRGBA(screen, tx, ty, tx2, ty2, 255, 255, 255, 255); } } } StaticAnim::StaticAnim() { int i; for(i=0; i<12; i++) { anim[i]=0; } nextframe=0; w=0; h=0; zoom=1; } StaticAnim::~StaticAnim() { int i; for(i=0; i<12; i++) { if (anim[i]) SDL_FreeSurface(anim[i]); } } void StaticAnim::SetX(int sx) { x=sx; } void StaticAnim::SetY(int sy) { y=sy; } void StaticAnim::LoadFrames(std::string sanim) { int i; animbase=sanim; SDL_Surface *temp; char send[60]; for(i=1; i<13; i++) { sprintf(send,"%s%02d.png",sanim.c_str(), i); temp=LoadIMG(send); if (anim[i-1]) SDL_FreeSurface(anim[i-1]); anim[i-1]=rotozoomSurface(temp, 0, zoom, SMOOTH); SDL_FreeSurface(temp); if (i==1) { w=anim[i-1]->w; h=anim[i-1]->h; } } } void StaticAnim::DisplayNext(int sx, int sy) { DrawIMG(anim[nextframe], sx, sy); nextframe++; } void StaticAnim::IncNext() { nextframe++; } SDL_Surface *StaticAnim::GetAnim(int index) { return anim[index]; } int StaticAnim::GetNextFrame() { return nextframe; } int StaticAnim::GetCurFrame() { if (nextframe>=12) { nextframe=0; return -1; } else return nextframe; } int StaticAnim::GetX() { return x; } int StaticAnim::GetY() { return y; } int StaticAnim::GetWidth() { return w; } int StaticAnim::GetHeight() { return h; } float StaticAnim::GetZoom() { return zoom; } std::string StaticAnim::GetBase() { return animbase; } void StaticAnim::SetZoom(float szoom) { zoom=szoom; } --- NEW FILE: scenario.cpp --- #include "scenario.h" void LoadMap(Map *map, const std::string& filename, float zoom) { __scen_bullet scenbullets[50]; int nextbullet=0; Uint32 ticks=SDL_GetTicks(); Uint32 timepassed=0; Uint32 ms=0; Uint32 secs=0; Uint32 mins=0; if (LOG) printf("LoadMap() at ticks=%d\n",ticks); struct Local { static std::string getStringNode(DataNode* parent, const std::string& name) { DataNode* n = parent->getChild(name); return n->getString(); } [...1351 lines suppressed...] } PHYSFS_freeList(fpklist); //make sure the ship that shows up first is the right one! temp=0; for(i=0; i<fpks; i++) { for(j=temp; j<total[i]+temp; j++) { FPKShip *tempship=new FPKShip(i, j-temp); if (Scen->ShipIsAllowed(tempship->GetName(),tempship->GetFPK())) { fpkships[j]=tempship; } else delete tempship; } temp=j; } return fpkships; } --- NEW FILE: bitmask.h --- /* * bitmask.c 1.0 * ------------- * Simple and efficient bitmask collision detection routines * Copyright (C) 2002 Ulf Ekstrom except for the bitcount function. * * A bitmask is a simple array of bits, which can be used for * 2d collision detection. Set 'unoccupied' area to zero and * occupies areas to one and use the bitmask_overlap*() functions * to check for collisions. * The current implementation uses 32 bit wide stripes to hold * the masks, but should work just as well with 64 bit sizes. * (Note that the current bitcount function is 32 bit only!) * * The overlap tests uses the following offsets (which may be negative): * * +----+----------.. * |A | yoffset * | +-+----------.. * +--|B * |xoffset * | | * : : * * For optimal collision detection performance combine these functions * with some kind of pre-sorting to avoid comparing objects far from * each other. * * BUGS: No known bugs, even though they may certainly be in here somewhere. * Possible performance improvements could be to remove the div in * bitmask_overlap_pos() and to implement wider stripes if the masks used * are wider than 64 bits on the average. * * Performance of the various functions goes something like: * (relative timings, smaller is better) * * bitmask_overlap() 1.0 * bitmask_overlap_pos() 1.3 * bitmask_overlap_area() 1.6 * * For maximum performance on my machine I use gcc with * -O2 -fomit-frame-pointer -funroll-loops * * * If you can make these functions faster or have found any bugs please * email Ulf Ekstrom, ul...@if... * * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef BITMASK_H #define BITMASK_H #include <limits.h> /* Define INLINE for different compilers. */ #ifndef INLINE # ifdef __GNUC__ # define INLINE __inline__ # else # ifdef _MSC_VER # define INLINE __inline # else # define INLINE # endif # endif #endif #define BITW unsigned long int #define BITW_LEN (sizeof(BITW)*CHAR_BIT) #define BITW_MASK (BITW_LEN - 1) #define BITN(n) ((BITW)1 << (n)) typedef struct bitmask { int w,h; BITW *bits; } bitmask; /* Creates a bitmask of width w and height h. * The mask is automatically cleared when created. */ bitmask *bitmask_create(int w, int h); void bitmask_free(bitmask *m); /* Returns nonzero if the bit at (x,y) is set. * Coordinates start at (0,0) */ static INLINE int bitmask_getbit(const bitmask *m,int x,int y) { return m->bits[x/BITW_LEN*m->h + y] & BITN(x & BITW_MASK); } /* Sets the bit at (x,y) */ static INLINE void bitmask_setbit(bitmask *m,int x,int y) { m->bits[x/BITW_LEN*m->h + y] |= BITN(x & BITW_MASK); } /* Clears the bit at (x,y) */ static INLINE void bitmask_clearbit(bitmask *m,int x,int y) { m->bits[x/BITW_LEN*m->h + y] &= ~BITN(x & BITW_MASK); } /* Returns nonzero if the masks overlap with the given offset. */ int bitmask_overlap(const bitmask *a,const bitmask *b,int xoffset, int yoffset); /* Like bitmask_overlap(), but will also give a point of intersection. * x and y are given in the coordinates of mask a, and are untouched if the is * no overlap. */ int bitmask_overlap_pos(const bitmask *a,const bitmask *b,int xoffset, int yoffset, int *x, int *y); /* Returns the number of overlapping 'pixels' */ int bitmask_overlap_area(const bitmask *a,const bitmask *b,int xoffset, int yoffset); /* Draws mask b onto mask a (bitwise OR) * Can be used to compose large (game background?) mask from * several submasks, which may speed up the testing. */ void bitmask_draw(bitmask *a,bitmask *b,int xoffset, int yoffset); #endif --- NEW FILE: fftrader.ico --- (This appears to be a binary file; contents omitted.) --- NEW FILE: bitmask.c --- /* * bitmask.c 1.0 * ------------- * Simple and efficient bitmask collision detection routines * Copyright (C) 2002 Ulf Ekstrom except for the bitcount function. * * > See the header file for more info. < * * Please email bugs and comments to Ulf Ekstrom, ul...@if... * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #if defined(__APPLE__) && defined(__GNUC__) #include <stdlib.h> #else #include <malloc.h> #endif #include "bitmask.h" #define MIN(a,b) ((a) < (b) ? (a) : (b)) bitmask *bitmask_create(int w, int h) { bitmask *temp = malloc(sizeof(bitmask)); if (! temp) return 0; temp->w = w; temp->h = h; temp->bits = calloc(h*((w - 1)/BITW_LEN + 1),sizeof(BITW)); if (! temp->bits) { free(temp); return 0; } else return temp; } void bitmask_free(bitmask *m) { free(m->bits); free(m); } int bitmask_overlap(const bitmask *a,const bitmask *b,int xoffset, int yoffset) { BITW *a_entry,*a_end; BITW *b_entry; BITW *ap,*bp; int shift,rshift,i,astripes,bstripes; if ((xoffset >= a->w) || (yoffset >= a->h) || (yoffset <= - b->h)) return 0; if (xoffset >= 0) { if (yoffset >= 0) { a_entry = a->bits + a->h*(xoffset/BITW_LEN) + yoffset; a_end = a_entry + MIN(b->h,a->h - yoffset); b_entry = b->bits; } else { a_entry = a->bits + a->h*(xoffset/BITW_LEN); a_end = a_entry + MIN(b->h + yoffset,a->h); b_entry = b->bits - yoffset; } shift = xoffset & BITW_MASK; if (shift) { rshift = BITW_LEN - shift; astripes = (a->w - 1)/BITW_LEN - xoffset/BITW_LEN; bstripes = (b->w - 1)/BITW_LEN + 1; if (bstripes > astripes) /* zig-zag .. zig*/ { for (i=0;i<astripes;i++) { for (ap = a_entry,bp = b_entry;ap < a_end;) /* Join these two to one loop */ if ((*ap++ >> shift) & *bp++) return 1; a_entry += a->h; a_end += a->h; for (ap = a_entry,bp = b_entry;ap < a_end;) if ((*ap++ << rshift) & *bp++) return 1; b_entry += b->h; } for (ap = a_entry,bp = b_entry;ap < a_end;) if ((*ap++ >> shift) & *bp++) return 1; return 0; } else /* zig-zag */ { for (i=0;i<bstripes;i++) { for (ap = a_entry,bp = b_entry;ap < a_end;) if ((*ap++ >> shift) & *bp++) return 1; a_entry += a->h; a_end += a->h; for (ap = a_entry,bp = b_entry;ap < a_end;) if ((*ap++ << rshift) & *bp++) return 1; b_entry += b->h; } return 0; } } else /* xoffset is a multiple of the stripe width, and the above routines wont work */ { astripes = (MIN(b->w,a->w - xoffset) - 1)/BITW_LEN + 1; for (i=0;i<astripes;i++) { for (ap = a_entry,bp = b_entry;ap < a_end;) if (*ap++ & *bp++) return 1; a_entry += a->h; a_end += a->h; b_entry += b->h; } return 0; } } else return bitmask_overlap(b,a,-xoffset,-yoffset); } /* Will hang if there are no bits set in w! */ static INLINE int firstsetbit(BITW w) { int i = 0; while ((w & 1) == 0) { i++; w/=2; } return i; } /* x and y are given in the coordinates of mask a, and are untouched if the is no overlap */ int bitmask_overlap_pos(const bitmask *a,const bitmask *b,int xoffset, int yoffset, int *x, int *y) { BITW *a_entry,*a_end; BITW *b_entry; BITW *ap,*bp; int shift,rshift,i,astripes,bstripes; if ((xoffset >= a->w) || (yoffset >= a->h) || (yoffset <= - b->h)) return 0; if (xoffset >= 0) { if (yoffset >= 0) { a_entry = a->bits + a->h*(xoffset/BITW_LEN) + yoffset; a_end = a_entry + MIN(b->h,a->h - yoffset); b_entry = b->bits; } else { a_entry = a->bits + a->h*(xoffset/BITW_LEN); a_end = a_entry + MIN(b->h + yoffset,a->h); b_entry = b->bits - yoffset; } shift = xoffset... [truncated message content] |
From: TomT64 <to...@us...> - 2005-08-19 07:32:40
|
Update of /cvsroot/fftrader/fftrader/src/osx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16344/src/osx Added Files: .DS_Store FFT.icns Info.plist SDLMain.h SDLMain.m Log Message: - Added log files to be used a bit later, and put sources in a subdirectory --- NEW FILE: Info.plist --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> <plist version="0.9"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleDocumentTypes</key> <array> </array> <key>CFBundleExecutable</key> <string>APPNAME</string> <key>CFBundleGetInfoString</key> <string>APPNAME APPVERS</string> <key>CFBundleIconFile</key> <string>APPNAME.icns</string> <key>CFBundleIdentifier</key> <string>APPID</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>APPNAME</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> <string>APPVERS</string> <key>CFBundleSignature</key> <string>APPSIG</string> <key>CFBundleVersion</key> <string>APPVERS</string> </dict> </plist> --- NEW FILE: SDLMain.m --- /* SDLMain.m - main entry point for our Cocoa-ized SDL app Initial Version: Darrell Walisser <dwa...@pu...> Non-NIB-Code & other changes: Max Horn <ma...@qu...> Feel free to customize this file to suit your needs */ #import "SDL.h" #import "SDLMain.h" #import <sys/param.h> /* for MAXPATHLEN */ #import <unistd.h> /* Use this flag to determine whether we use SDLMain.nib or not */ #define SDL_USE_NIB_FILE 0 static int gArgc; static char **gArgv; static BOOL gFinderLaunch; #if SDL_USE_NIB_FILE /* A helper category for NSString */ @interface NSString (ReplaceSubString) - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #else /* An internal Apple class used to setup Apple menus */ @interface NSAppleMenuController:NSObject {} - (void)controlMenu:(NSMenu *)aMenu; @end #endif @interface SDLApplication : NSApplication @end @implementation SDLApplication /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { /* Post a SDL_QUIT event */ SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); } @end /* The main class of the application, the application's delegate */ @implementation SDLMain /* Set the working directory to the .app's parent directory */ - (void) setupWorkingDirectory:(BOOL)shouldChdir { char parentdir[MAXPATHLEN]; char *c; strncpy ( parentdir, gArgv[0], sizeof(parentdir) ); c = (char*) parentdir; while (*c != '\0') /* go to end */ c++; while (*c != '/') /* back up to parent */ c--; *c++ = '\0'; /* cut off last part (binary name) */ if (shouldChdir) { assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */ } } #if SDL_USE_NIB_FILE /* Fix menu to contain the real app name instead of "SDL App" */ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName { NSRange aRange; NSEnumerator *enumerator; NSMenuItem *menuItem; aRange = [[aMenu title] rangeOfString:@"SDL App"]; if (aRange.length != 0) [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; enumerator = [[aMenu itemArray] objectEnumerator]; while ((menuItem = [enumerator nextObject])) { aRange = [[menuItem title] rangeOfString:@"SDL App"]; if (aRange.length != 0) [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } [ aMenu sizeToFit ]; } #else void setupAppleMenu(void) { /* warning: this code is very odd */ NSAppleMenuController *appleMenuController; NSMenu *appleMenu; NSMenuItem *appleMenuItem; appleMenuController = [[NSAppleMenuController alloc] init]; appleMenu = [[NSMenu alloc] initWithTitle:@""]; appleMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [appleMenuItem setSubmenu:appleMenu]; /* yes, we do need to add it and then remove it -- if you don't add it, it doesn't get displayed if you don't remove it, you have an extra, titleless item in the menubar when you remove it, it appears to stick around very, very odd */ [[NSApp mainMenu] addItem:appleMenuItem]; [appleMenuController controlMenu:appleMenu]; [[NSApp mainMenu] removeItem:appleMenuItem]; [appleMenu release]; [appleMenuItem release]; } /* Create a window menu */ void setupWindowMenu(void) { NSMenu *windowMenu; NSMenuItem *windowMenuItem; NSMenuItem *menuItem; windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; /* "Minimize" item */ menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [windowMenu addItem:menuItem]; [menuItem release]; /* Put menu into the menubar */ windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; [windowMenuItem setSubmenu:windowMenu]; [[NSApp mainMenu] addItem:windowMenuItem]; /* Tell the application object that this is now the window menu */ [NSApp setWindowsMenu:windowMenu]; /* Finally give up our references to the objects */ [windowMenu release]; [windowMenuItem release]; } /* Replacement for NSApplicationMain */ void CustomApplicationMain (argc, argv) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDLMain *sdlMain; /* Ensure the application object is initialised */ [SDLApplication sharedApplication]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; setupAppleMenu(); setupWindowMenu(); /* Create SDLMain and make it the app delegate */ sdlMain = [[SDLMain alloc] init]; [NSApp setDelegate:sdlMain]; /* Start the main event loop */ [NSApp run]; [sdlMain release]; [pool release]; } #endif /* Called when the internal event loop has just started running */ - (void) applicationDidFinishLaunching: (NSNotification *) note { int status; /* Set the working directory to the .app's parent directory */ [self setupWorkingDirectory:gFinderLaunch]; #if SDL_USE_NIB_FILE /* Set the main menu to contain the real app name instead of "SDL App" */ [self fixMenu:[NSApp mainMenu] withAppName:[[NSProcessInfo processInfo] processName]]; #endif /* Hand off to main application code */ status = SDL_main (gArgc, gArgv); /* We're done, thank you for playing */ exit(status); } @end @implementation NSString (ReplaceSubString) - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString { unsigned int bufferSize; unsigned int selfLen = [self length]; unsigned int aStringLen = [aString length]; unichar *buffer; NSRange localRange; NSString *result; bufferSize = selfLen + aStringLen - aRange.length; buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); /* Get first part into buffer */ localRange.location = 0; localRange.length = aRange.location; [self getCharacters:buffer range:localRange]; /* Get middle part into buffer */ localRange.location = 0; localRange.length = aStringLen; [aString getCharacters:(buffer+aRange.location) range:localRange]; /* Get last part into buffer */ localRange.location = aRange.location + aRange.length; localRange.length = selfLen - localRange.location; [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; /* Build output string */ result = [NSString stringWithCharacters:buffer length:bufferSize]; NSDeallocateMemoryPages(buffer, bufferSize); return result; } @end #ifdef main # undef main #endif /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ int i; /* This is passed if we are launched by double-clicking */ if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { gArgc = 1; gFinderLaunch = YES; } else { gArgc = argc; gFinderLaunch = NO; } gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1)); assert (gArgv != NULL); for (i = 0; i < gArgc; i++) gArgv[i] = argv[i]; gArgv[i] = NULL; #if SDL_USE_NIB_FILE [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); #endif return 0; } --- NEW FILE: FFT.icns --- (This appears to be a binary file; contents omitted.) --- NEW FILE: .DS_Store --- (This appears to be a binary file; contents omitted.) --- NEW FILE: SDLMain.h --- /* SDLMain.m - main entry point for our Cocoa-ized SDL app Initial Version: Darrell Walisser <dwa...@pu...> Non-NIB-Code & other changes: Max Horn <ma...@qu...> Feel free to customize this file to suit your needs */ #import <Cocoa/Cocoa.h> @interface SDLMain : NSObject @end |
Update of /cvsroot/fftrader/fftrader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16344 Modified Files: Makefile fftrader.dev fftrader.dsp Removed Files: CHANGELOG README TODO aries.cpp aries.h bitmask.c bitmask.h fftfile.cpp fftfile.h fftrader.ico graphics.cpp graphics.h gui.cpp gui.h guiapply.cpp guiapply.h input.cpp input.h mac.h mac.m main.cpp map.cpp map.h mapobject.cpp mapobject.h math.cpp math.h resource.h resource.rc scenario.cpp scenario.h shop.cpp shop.h units.cpp units.h Log Message: - Added log files to be used a bit later, and put sources in a subdirectory --- main.cpp DELETED --- --- shop.cpp DELETED --- --- shop.h DELETED --- --- resource.rc DELETED --- --- mapobject.cpp DELETED --- --- input.cpp DELETED --- --- input.h DELETED --- --- units.h DELETED --- --- graphics.cpp DELETED --- --- TODO DELETED --- --- scenario.cpp DELETED --- Index: fftrader.dsp =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dsp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fftrader.dsp 7 Sep 2004 21:36:31 -0000 1.9 --- fftrader.dsp 19 Aug 2005 07:32:29 -0000 1.10 *************** *** 94,150 **** # Begin Source File ! SOURCE=.\aries.cpp # End Source File # Begin Source File ! SOURCE=.\bitmask.c # End Source File # Begin Source File ! SOURCE=.\fftfile.cpp # End Source File # Begin Source File ! SOURCE=.\graphics.cpp # End Source File # Begin Source File ! SOURCE=.\gui.cpp # End Source File # Begin Source File ! SOURCE=.\guiapply.cpp # End Source File # Begin Source File ! SOURCE=.\input.cpp # End Source File # Begin Source File ! SOURCE=.\main.cpp # End Source File # Begin Source File ! SOURCE=.\map.cpp # End Source File # Begin Source File ! SOURCE=.\mapobject.cpp # End Source File # Begin Source File ! SOURCE=.\math.cpp # End Source File # Begin Source File ! SOURCE=.\scenario.cpp # End Source File # Begin Source File ! SOURCE=.\shop.cpp # End Source File # Begin Source File ! SOURCE=.\units.cpp # End Source File # End Group --- 94,150 ---- # Begin Source File ! SOURCE=.\src\aries.cpp # End Source File # Begin Source File ! SOURCE=.\src\bitmask.c # End Source File # Begin Source File ! SOURCE=.\src\fftfile.cpp # End Source File # Begin Source File ! SOURCE=.\src\graphics.cpp # End Source File # Begin Source File ! SOURCE=.\src\gui.cpp # End Source File # Begin Source File ! SOURCE=.\src\guiapply.cpp # End Source File # Begin Source File ! SOURCE=.\src\input.cpp # End Source File # Begin Source File ! SOURCE=.\src\main.cpp # End Source File # Begin Source File ! SOURCE=.\src\map.cpp # End Source File # Begin Source File ! SOURCE=.\src\mapobject.cpp # End Source File # Begin Source File ! SOURCE=.\src\math.cpp # End Source File # Begin Source File ! SOURCE=.\src\scenario.cpp # End Source File # Begin Source File ! SOURCE=.\src\shop.cpp # End Source File # Begin Source File ! SOURCE=.\src\units.cpp # End Source File # End Group *************** *** 154,206 **** # Begin Source File ! SOURCE=.\aries.h # End Source File # Begin Source File ! SOURCE=.\bitmask.h # End Source File # Begin Source File ! SOURCE=.\fftfile.h # End Source File # Begin Source File ! SOURCE=.\graphics.h # End Source File # Begin Source File ! SOURCE=.\gui.h # End Source File # Begin Source File ! SOURCE=.\guiapply.h # End Source File # Begin Source File ! SOURCE=.\input.h # End Source File # Begin Source File ! SOURCE=.\map.h # End Source File # Begin Source File ! SOURCE=.\mapobject.h # End Source File # Begin Source File ! SOURCE=.\math.h # End Source File # Begin Source File ! SOURCE=.\scenario.h # End Source File # Begin Source File ! SOURCE=.\shop.h # End Source File # Begin Source File ! SOURCE=.\units.h # End Source File # End Group --- 154,206 ---- # Begin Source File ! SOURCE=.\src\aries.h # End Source File # Begin Source File ! SOURCE=.\src\bitmask.h # End Source File # Begin Source File ! SOURCE=.\src\fftfile.h # End Source File # Begin Source File ! SOURCE=.\src\graphics.h # End Source File # Begin Source File ! SOURCE=.\src\gui.h # End Source File # Begin Source File ! SOURCE=.\src\guiapply.h # End Source File # Begin Source File ! SOURCE=.\src\input.h # End Source File # Begin Source File ! SOURCE=.\src\map.h # End Source File # Begin Source File ! SOURCE=.\src\mapobject.h # End Source File # Begin Source File ! SOURCE=.\src\math.h # End Source File # Begin Source File ! SOURCE=.\src\scenario.h # End Source File # Begin Source File ! SOURCE=.\src\shop.h # End Source File # Begin Source File ! SOURCE=.\src\units.h # End Source File # End Group *************** *** 210,218 **** # Begin Source File ! SOURCE=.\fftrader.ico # End Source File # Begin Source File ! SOURCE=.\resource.rc # End Source File # End Group --- 210,218 ---- # Begin Source File ! SOURCE=.\src\fftrader.ico # End Source File # Begin Source File ! SOURCE=.\src\resource.rc # End Source File # End Group --- bitmask.h DELETED --- --- fftrader.ico DELETED --- --- README DELETED --- --- bitmask.c DELETED --- --- fftfile.h DELETED --- --- aries.h DELETED --- Index: Makefile =================================================================== RCS file: /cvsroot/fftrader/fftrader/Makefile,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile 3 Sep 2004 05:36:17 -0000 1.12 --- Makefile 19 Aug 2005 07:32:29 -0000 1.13 *************** *** 2,6 **** sdl_LIBS := $(shell sdl-config --libs) fft_CPPFLAGS = -Wall -ansi -O2 ! fft_LIBS = -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_gfx -lphysfs DEBUG=1 --- 2,6 ---- sdl_LIBS := $(shell sdl-config --libs) fft_CPPFLAGS = -Wall -ansi -O2 ! fft_LIBS = -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_gfx -lz DEBUG=1 *************** *** 11,17 **** LD=$(CXX) ! C_SRCS = $(wildcard *.c) C_OBJS = $(patsubst %.c,%.o,$(C_SRCS)) ! CXX_SRCS = $(wildcard *.cpp) CXX_OBJS = $(patsubst %.cpp,%.o,$(CXX_SRCS)) --- 11,17 ---- LD=$(CXX) ! C_SRCS = $(wildcard src/*.c) C_OBJS = $(patsubst %.c,%.o,$(C_SRCS)) ! CXX_SRCS = $(wildcard src/*.cpp) CXX_OBJS = $(patsubst %.cpp,%.o,$(CXX_SRCS)) *************** *** 49,53 **** $(EMBED_FRAMEWORKS) $(OTHER_FRAMEWORKS)) ! EMBED_LIBS = physfs readline ncurses EMBEDDED_LIBS = $(patsubst %,FFT.app/Contents/Resources/lib%.dylib,\ $(EMBED_LIBS)) --- 49,53 ---- $(EMBED_FRAMEWORKS) $(OTHER_FRAMEWORKS)) ! EMBED_LIBS = readline ncurses EMBEDDED_LIBS = $(patsubst %,FFT.app/Contents/Resources/lib%.dylib,\ $(EMBED_LIBS)) *************** *** 58,64 **** OSX_NAME = Final Frontier Trader OSX_ID = net.sourceforge.fftrader ! VERS = 0.66 ! SDLMain.o: osx/SDLMain.m $(CC) -c -Iosx $(sdl_CPPFLAGS) $(filter-out -ansi,$(fft_CPPFLAGS)) \ $(CFLAGS) $< -o $@ --- 58,64 ---- OSX_NAME = Final Frontier Trader OSX_ID = net.sourceforge.fftrader ! VERS = 0.70 ! SDLMain.o: src/osx/SDLMain.m $(CC) -c -Iosx $(sdl_CPPFLAGS) $(filter-out -ansi,$(fft_CPPFLAGS)) \ $(CFLAGS) $< -o $@ *************** *** 76,86 **** 'if(m,$(LIB_DIR)/(([^.]+)\S+),){system("install_name_tool -change $(LIBDIR)/$$1 \@executable_path/../Resources/$$2.dylib $@")}' ! FFT.app: osx/Info.plist osx/FFT.icns mkdir -p FFT.app/Contents/Resources FFT.app/Contents/Frameworks echo -n "APPL$(OSX_SIG)" > FFT.app/Contents/PkgInfo sed -e 's,APPNAME,$(OSX_NAME),g' -e 's,APPVERS,$(VERS),g' \ -e 's,APPID,$(OSX_ID),g' -e 's,APPSIG,$(OSX_SIG),g' \ ! osx/Info.plist > FFT.app/Contents/Info.plist ! cp osx/FFT.icns "FFT.app/Contents/Resources/$(OSX_NAME).icns" FFT.app/Contents/MacOS: --- 76,86 ---- 'if(m,$(LIB_DIR)/(([^.]+)\S+),){system("install_name_tool -change $(LIBDIR)/$$1 \@executable_path/../Resources/$$2.dylib $@")}' ! FFT.app: src/osx/Info.plist src/osx/FFT.icns mkdir -p FFT.app/Contents/Resources FFT.app/Contents/Frameworks echo -n "APPL$(OSX_SIG)" > FFT.app/Contents/PkgInfo sed -e 's,APPNAME,$(OSX_NAME),g' -e 's,APPVERS,$(VERS),g' \ -e 's,APPID,$(OSX_ID),g' -e 's,APPSIG,$(OSX_SIG),g' \ ! src/osx/Info.plist > FFT.app/Contents/Info.plist ! cp src/osx/FFT.icns "FFT.app/Contents/Resources/$(OSX_NAME).icns" FFT.app/Contents/MacOS: --- aries.cpp DELETED --- --- guiapply.h DELETED --- --- CHANGELOG DELETED --- --- scenario.h DELETED --- Index: fftrader.dev =================================================================== RCS file: /cvsroot/fftrader/fftrader/fftrader.dev,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** fftrader.dev 24 Sep 2004 22:23:14 -0000 1.8 --- fftrader.dev 19 Aug 2005 07:32:29 -0000 1.9 *************** *** 2,6 **** FileName=fftrader.dev Name=fftrader ! UnitCount=29 Type=0 Ver=1 --- 2,6 ---- FileName=fftrader.dev Name=fftrader ! UnitCount=30 Type=0 Ver=1 *************** *** 9,21 **** Libs= PrivateResource=fftrader_private.rc ! ResourceIncludes= MakeIncludes= Compiler= CppCompiler=_@@_ ! Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 Icon= ExeOutput= ! ObjectOutput= OverrideOutput=1 OverrideOutputName=fftrader-devcpp.exe --- 9,21 ---- Libs= PrivateResource=fftrader_private.rc ! ResourceIncludes=src/ MakeIncludes= Compiler= CppCompiler=_@@_ ! Linker=-lmingw32_@@_-lSDLmain_@@_-lSDL_@@_-lSDL_image_@@_-lSDL_mixer_@@_-lSDL_ttf_@@_-lSDL_gfx_@@_-lz_@@_-lphysfs_@@_-lstdc++_@@_ IsCpp=1 Icon= ExeOutput= ! ObjectOutput=./out OverrideOutput=1 OverrideOutputName=fftrader-devcpp.exe *************** *** 26,45 **** SupportXPThemes=0 CompilerSet=0 ! CompilerSettings=0000010001001000000100 UseCustomMakefile=0 CustomMakefile= - [Unit1] - FileName=aries.cpp - CompileCpp=1 - Folder=fftrader - Compile=1 - Link=1 - Priority=1000 - OverrideBuildCmd=0 - BuildCmd= - [Unit2] ! FileName=aries.h CompileCpp=1 Folder=fftrader --- 26,35 ---- SupportXPThemes=0 CompilerSet=0 ! CompilerSettings=0000000001001000000100 UseCustomMakefile=0 CustomMakefile= [Unit2] ! FileName=src\units.cpp CompileCpp=1 Folder=fftrader *************** *** 51,56 **** [Unit3] ! FileName=bitmask.c ! CompileCpp=0 Folder=fftrader Compile=1 --- 41,46 ---- [Unit3] ! FileName=src\main.cpp ! CompileCpp=1 Folder=fftrader Compile=1 *************** *** 58,65 **** Priority=1000 OverrideBuildCmd=0 ! BuildCmd=$(CC) -c bitmask.c -o bitmask.o $(CFLAGS) [Unit4] ! FileName=bitmask.h CompileCpp=1 Folder=fftrader --- 48,55 ---- Priority=1000 OverrideBuildCmd=0 ! BuildCmd= [Unit4] ! FileName=src\gui.h CompileCpp=1 Folder=fftrader *************** *** 71,75 **** [Unit5] ! FileName=fftfile.cpp CompileCpp=1 Folder=fftrader --- 61,65 ---- [Unit5] ! FileName=src\map.h CompileCpp=1 Folder=fftrader *************** *** 81,85 **** [Unit6] ! FileName=fftfile.h CompileCpp=1 Folder=fftrader --- 71,75 ---- [Unit6] ! FileName=src\map.cpp CompileCpp=1 Folder=fftrader *************** *** 91,95 **** [Unit7] ! FileName=graphics.cpp CompileCpp=1 Folder=fftrader --- 81,85 ---- [Unit7] ! FileName=src\mapobject.h CompileCpp=1 Folder=fftrader *************** *** 101,105 **** [Unit8] ! FileName=graphics.h CompileCpp=1 Folder=fftrader --- 91,95 ---- [Unit8] ! FileName=src\shop.h CompileCpp=1 Folder=fftrader *************** *** 111,115 **** [Unit9] ! FileName=gui.cpp CompileCpp=1 Folder=fftrader --- 101,105 ---- [Unit9] ! FileName=src\fftfile.h CompileCpp=1 Folder=fftrader *************** *** 121,125 **** [Unit10] ! FileName=gui.h CompileCpp=1 Folder=fftrader --- 111,115 ---- [Unit10] ! FileName=src\shop.cpp CompileCpp=1 Folder=fftrader *************** *** 131,135 **** [Unit11] ! FileName=input.cpp CompileCpp=1 Folder=fftrader --- 121,125 ---- [Unit11] ! FileName=src\fftfile.cpp CompileCpp=1 Folder=fftrader *************** *** 141,145 **** [Unit12] ! FileName=input.h CompileCpp=1 Folder=fftrader --- 131,135 ---- [Unit12] ! FileName=src\mapobject.cpp CompileCpp=1 Folder=fftrader *************** *** 151,155 **** [Unit13] ! FileName=main.cpp CompileCpp=1 Folder=fftrader --- 141,145 ---- [Unit13] ! FileName=src\scenario.cpp CompileCpp=1 Folder=fftrader *************** *** 161,165 **** [Unit14] ! FileName=math.cpp CompileCpp=1 Folder=fftrader --- 151,155 ---- [Unit14] ! FileName=src\scenario.h CompileCpp=1 Folder=fftrader *************** *** 171,175 **** [Unit15] ! FileName=math.h CompileCpp=1 Folder=fftrader --- 161,165 ---- [Unit15] ! FileName=src\bitmask.h CompileCpp=1 Folder=fftrader *************** *** 181,189 **** [Unit16] ! FileName=resource.h CompileCpp=1 Folder=fftrader Compile=1 ! Link=1 Priority=1000 OverrideBuildCmd=0 --- 171,179 ---- [Unit16] ! FileName=src\resource.rc CompileCpp=1 Folder=fftrader Compile=1 ! Link=0 Priority=1000 OverrideBuildCmd=0 *************** *** 191,204 **** [Unit17] ! FileName=resource.rc Folder=fftrader Compile=1 ! Link=0 Priority=1000 OverrideBuildCmd=0 BuildCmd= [Unit18] ! FileName=scenario.cpp CompileCpp=1 Folder=fftrader --- 181,195 ---- [Unit17] ! FileName=src\resource.h Folder=fftrader Compile=1 ! Link=1 Priority=1000 OverrideBuildCmd=0 BuildCmd= + CompileCpp=1 [Unit18] ! FileName=src\math.h CompileCpp=1 Folder=fftrader *************** *** 210,214 **** [Unit19] ! FileName=scenario.h CompileCpp=1 Folder=fftrader --- 201,205 ---- [Unit19] ! FileName=src\math.cpp CompileCpp=1 Folder=fftrader *************** *** 220,224 **** [Unit21] ! FileName=units.h CompileCpp=1 Folder=fftrader --- 211,215 ---- [Unit21] ! FileName=src\input.h CompileCpp=1 Folder=fftrader *************** *** 230,234 **** [Unit22] ! FileName=guiapply.cpp CompileCpp=1 Folder=fftrader --- 221,225 ---- [Unit22] ! FileName=src\input.cpp CompileCpp=1 Folder=fftrader *************** *** 240,244 **** [Unit23] ! FileName=guiapply.h CompileCpp=1 Folder=fftrader --- 231,235 ---- [Unit23] ! FileName=src\guiapply.cpp CompileCpp=1 Folder=fftrader *************** *** 268,272 **** [Unit24] ! FileName=mapobject.h CompileCpp=1 Folder=fftrader --- 259,263 ---- [Unit24] ! FileName=src\gui.cpp CompileCpp=1 Folder=fftrader *************** *** 278,283 **** [Unit25] ! FileName=map.cpp ! CompileCpp=1 Folder=fftrader Compile=1 --- 269,274 ---- [Unit25] ! FileName=src\bitmask.c ! CompileCpp=0 Folder=fftrader Compile=1 *************** *** 285,292 **** Priority=1000 OverrideBuildCmd=0 ! BuildCmd= [Unit26] ! FileName=map.h CompileCpp=1 Folder=fftrader --- 276,283 ---- Priority=1000 OverrideBuildCmd=0 ! BuildCmd=$(CC) -c bitmask.c -o ./out/bitmask.o $(CFLAGS) [Unit26] ! FileName=src\mac.h CompileCpp=1 Folder=fftrader *************** *** 298,302 **** [Unit27] ! FileName=mapobject.cpp CompileCpp=1 Folder=fftrader --- 289,293 ---- [Unit27] ! FileName=src\graphics.cpp CompileCpp=1 Folder=fftrader *************** *** 308,312 **** [Unit28] ! FileName=shop.h CompileCpp=1 Folder=fftrader --- 299,303 ---- [Unit28] ! FileName=src\graphics.h CompileCpp=1 Folder=fftrader *************** *** 318,322 **** [Unit29] ! FileName=shop.cpp CompileCpp=1 Folder=fftrader --- 309,313 ---- [Unit29] ! FileName=src\aries.h CompileCpp=1 Folder=fftrader *************** *** 328,332 **** [Unit20] ! FileName=units.cpp CompileCpp=1 Folder=fftrader --- 319,343 ---- [Unit20] ! FileName=src\guiapply.h ! CompileCpp=1 ! Folder=fftrader ! Compile=1 ! Link=1 ! Priority=1000 ! OverrideBuildCmd=0 ! BuildCmd= ! ! [Unit1] ! FileName=src\units.h ! CompileCpp=1 ! Folder=fftrader ! Compile=1 ! Link=1 ! Priority=1000 ! OverrideBuildCmd=0 ! BuildCmd= ! ! [Unit30] ! FileName=src\aries.cpp CompileCpp=1 Folder=fftrader --- fftfile.cpp DELETED --- --- gui.h DELETED --- --- map.cpp DELETED --- --- map.h DELETED --- --- gui.cpp DELETED --- --- resource.h DELETED --- --- units.cpp DELETED --- --- math.h DELETED --- --- mapobject.h DELETED --- --- math.cpp DELETED --- --- guiapply.cpp DELETED --- --- mac.h DELETED --- --- graphics.h DELETED --- --- mac.m DELETED --- |
From: TomT64 <to...@us...> - 2005-08-19 07:32:40
|
Update of /cvsroot/fftrader/fftrader/osx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16344/osx Removed Files: FFT.icns Info.plist SDLMain.h SDLMain.m Log Message: - Added log files to be used a bit later, and put sources in a subdirectory --- Info.plist DELETED --- --- SDLMain.m DELETED --- --- FFT.icns DELETED --- --- SDLMain.h DELETED --- |
From: TomT64 <to...@us...> - 2005-08-19 07:30:47
|
Update of /cvsroot/fftrader/fftrader/src/osx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16109/osx Log Message: Directory /cvsroot/fftrader/fftrader/src/osx added to the repository |
From: TomT64 <to...@us...> - 2005-08-19 07:30:47
|
Update of /cvsroot/fftrader/fftrader/src/Debug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16109/Debug Log Message: Directory /cvsroot/fftrader/fftrader/src/Debug added to the repository |
From: TomT64 <to...@us...> - 2005-08-19 07:29:25
|
Update of /cvsroot/fftrader/fftrader/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15838/src Log Message: Directory /cvsroot/fftrader/fftrader/src added to the repository |
From: David C. <in...@us...> - 2005-01-09 05:10:24
|
Update of /cvsroot/fftrader/fftrader3d/src/engine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9024/src/engine Modified Files: main.h Added Files: gfxconsole.cpp gfxconsole.h Removed Files: console.cpp console.h Log Message: Index: main.h =================================================================== RCS file: /cvsroot/fftrader/fftrader3d/src/engine/main.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.h 5 Jan 2005 22:06:00 -0000 1.1 --- main.h 9 Jan 2005 05:10:14 -0000 1.2 *************** *** 15,19 **** #include "entity.h" ! #include "console.h" #include "model.h" --- 15,19 ---- #include "entity.h" ! #include "gfxconsole.h" #include "model.h" --- console.h DELETED --- --- console.cpp DELETED --- --- NEW FILE: gfxconsole.h --- #ifndef GFXCONSOLE_H #define GFXCONSOLE_H #include <common/console.h> #include <gltext.h> class GraphicsConsole : public Console { public: virtual void render(); }; #endif --- NEW FILE: gfxconsole.cpp --- #include "gfxconsole.h" #include <gl/gl.h> void GraphicsConsole::render() { gltext::FontPtr myFont(gltext::OpenFont("fonts/arial.ttf", 14)); gltext::FontRendererPtr myRenderer(gltext::CreateRenderer(gltext::MIPMAP, myFont)); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255, 255, 255, 255); glPushMatrix(); glTranslatef(0, 0, 0); myRenderer->render("This is the end, my friend.. see you soon again :("); glPopMatrix(); glDisable(GL_BLEND); } |
Update of /cvsroot/fftrader/fftrader3d/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/src/common Added Files: aries.cpp aries.h config.cpp config.h console.cpp console.h datalib.h log.cpp log.h Log Message: Initial checkin --- NEW FILE: config.h --- #ifndef CONFIG_H #define CONFIG_H #include <string> #include <map> class ConfigFile { private: std::map<std::string, std::string> keyMap; public: void addKey(const char* keyName, const char* keyValue); void delKey(const char* keyName); void loadConfig(const char* fileName); void saveConfig(const char* fileName); std::string operator [](const std::string& keyName); int getKey (const std::string& keyName); }; #endif --- NEW FILE: config.cpp --- #include "config.h" #include <fstream> void ConfigFile::addKey(const char* keyName, const char* keyValue) { keyMap[keyName] = keyValue; } void ConfigFile::delKey(const char* keyName) { } int ConfigFile::getKey(const std::string& keyName) { return atoi(keyMap[keyName].c_str()); } void ConfigFile::loadConfig(const char* fileName) { std::string key, value; std::ifstream configFile(fileName); while(configFile) { configFile >> key >> value; addKey(key.c_str(), value.c_str()); } } void ConfigFile::saveConfig(const char* fileName) { } std::string ConfigFile::operator [](const std::string& keyName) { std::map<std::string, std::string>::iterator i = keyMap.find(keyName); if (i == keyMap.end()) return ""; return i->second; } --- NEW FILE: console.h --- #ifndef CONSOLE_H #define CONSOLE_H #include <string> #include <vector> #include <list> #include <iostream> enum t_consoleType { CTYPE_INT, CTYPE_CHAR, CTYPE_FLOAT, CTYPE_STRING, CTYPE_FUNCTION }; typedef void (*t_consoleFunction)(const std::vector<std::string> &); typedef struct t_consoleItem { std::string name; t_consoleType type; union { void *varPtr; t_consoleFunction function; }; }; class Console { public: void addItem(const std::string &itemName, void *itemPtr, t_consoleType itemType); void delItem(const std::string &itemName); void print(const std::string &lineText); virtual void render() = 0; void parseCmdLine(); private: std::list<t_consoleItem> itemList; std::string cmdLine; protected: std::list<std::string> lineBuffer; }; #endif --- NEW FILE: aries.cpp --- #include "aries.h" #include <iostream> #include <fstream> #include <sstream> #include <stack> #include <cassert> #include <stdexcept> namespace aries { // Helper functions for the parser bool isWhiteSpace(char c) { return c==' ' || c=='\t' || c=='\n' || c=='\r'; //static const std::string whiteSpace(" \t\n\r"); //return whiteSpace.find(c) != std::string::npos; } std::string readIdentifier(std::istream& stream) { std::stringstream ss; do { char c = stream.peek(); if (isWhiteSpace(c) || !stream.good()) break; stream.get(); ss << c; } while (true); return ss.str(); } void eatWhiteSpace(std::istream& stream) { // C++ badly needs a // do { ... } while (condition) { ... } // construct. do { char c = stream.peek(); if (isWhiteSpace(c) || !stream.good()) break; stream.get(); } while (1); } // Removes all leading and trailing whitespace from the string. std::string stripString(const std::string& str) { uint start = 0; uint end = str.length(); while (isWhiteSpace(str[start]) && start < str.length()) start++; while (isWhiteSpace(str[end - 1]) && end > 0) end--; if (start >= end) return ""; else return str.substr(start, end - start); } DataNode* Node::readDocument(std::istream& stream) { std::stack<DataNode*> docStack; // I don't want to recurse for some reason, so I keep the context in an explicit stack. DataNode* rootNode = new DataNode("root"); docStack.push(rootNode); /* * Read a character. * If it's not an opening parenth, then grab characters until we get to a parenth, and pack it into a single StringNode. * If it is, then grab characters up until a space, then create a new DataNode, and parse its children. * If it is a closing parenth, then the node is complete. We resume parsing its parent. */ while (stream.good()) { assert(docStack.size() >= 1); char c = stream.get(); if (c == '(') { std::string nodeName = stripString(readIdentifier(stream)); DataNode* newNode = new DataNode(nodeName); docStack.top()->addChild(newNode); docStack.push(newNode); } else if (c == ')') { // the root node is 1, and you may not actually terminate that node, as it is implicit, and not part // of the document itself. if (docStack.size() < 2) throw std::runtime_error("Malformed markup document"); docStack.pop(); } else { std::stringstream ss; while (c != '(' && c != ')' && stream.good()) { ss << c; c = stream.get(); } stream.unget(); std::string s = stripString(ss.str()); if (s.length()) docStack.top()->addChild(s); } } return rootNode; } //------------------------------------------------------------------------- StringNode::StringNode(const std::string& str) : _str(str) {} bool StringNode::isString() const { return true; } std::string StringNode::toString() const { return _str; } Node* StringNode::clone() const { return new StringNode(_str); } std::ostream& StringNode::write(std::ostream& stream) const { stream << _str; return stream; } //------------------------------------------------------------------------- DataNode::DataNode(const std::string& name) : _name(name) {} DataNode::~DataNode() { for (uint i = 0; i < _children.size(); i++) delete _children[i]; } bool DataNode::isString() const { return false; } std::string DataNode::toString() const { std::stringstream ss; write(ss, 0); return ss.str(); } Node* DataNode::clone() const { DataNode* newNode = new DataNode(_name); for (uint i = 0; i < _children.size(); i++) { newNode->addChild(*_children[i]); } return newNode; } std::string DataNode::getString() const { for (unsigned int i = 0; i < _children.size(); i++) { if (_children[i]->isString()) return _children[i]->toString(); } return ""; } const NodeList& DataNode::getChildren() const { return _children; } NodeList& DataNode::getChildren() { return _children; } DataNodeList DataNode::getChildren(const std::string& name) const { DataNodeList list; for (NodeList::const_iterator i = _children.begin(); i != _children.end(); i++) { Node* n = *i; if (!n->isString() && reinterpret_cast<DataNode*>(n)->getName() == name) list.push_back(reinterpret_cast<DataNode*>(n)); } return list; } DataNode* DataNode::getChild(const std::string& name) const { DataNode* n = getChild(name, 0); if (!n) throw std::runtime_error(std::string("Unable to find node ") + name); else return n; /*for (NodeList::const_iterator i = _children.begin(); i != _children.end(); i++) { Node* n = *i; if (!n->isString() && reinterpret_cast<DataNode*>(n)->getName() == name) return reinterpret_cast<DataNode*>(n); } throw std::runtime_error(std::string("Unable to find node ") + name);*/ } DataNode* DataNode::getChild(const std::string& name, DataNode* defaultValue) const { for (NodeList::const_iterator i = _children.begin(); i != _children.end(); i++) { Node* n = *i; if (!n->isString() && reinterpret_cast<DataNode*>(n)->getName() == name) return reinterpret_cast<DataNode*>(n); } return defaultValue; } bool DataNode::hasChild(const std::string& name) const { for (NodeList::const_iterator i = _children.begin(); i != _children.end(); i++) { Node* n = *i; if (!n->isString() && reinterpret_cast<DataNode*>(n)->getName() == name) return true; } return false; } std::string DataNode::getName() const { return _name; } DataNode* DataNode::addChild(const std::string& str) { return addChild(new StringNode(str)); } DataNode* DataNode::addChild(int n) { char c[32]; sprintf(c, "%i", n); return addChild(std::string(c)); } /*DataNode* DataNode::addChild(double d) { char c[32]; sprintf(c, "%d", d); return addChild(std::string(c)); }*/ DataNode* DataNode::addChild(Node* n) { _children.push_back(n); return this; } DataNode* DataNode::addChild(const Node& n) { _children.push_back(n.clone()); return this; } std::ostream& DataNode::write(std::ostream& stream) const { write(stream, 0); return stream; } void DataNode::write(std::ostream& stream, uint indentLevel) const { indentLevel += 1; stream << "(" << _name << " "; if (_children.size() == 1 && _children[0]->isString()) { // When there's just one string node, no newlines. It's ugly looking. stream << _children[0]->toString() << ")"; } else { for (uint i = 0; i < _children.size(); i++) { stream << "\n"; stream << std::string(indentLevel, '\t'); if (_children[i]->isString()) stream << _children[i]->toString(); else reinterpret_cast<DataNode*>(_children[i])->write(stream, indentLevel); } stream << "\n"; stream << std::string(indentLevel - 1, '\t'); stream << ")"; } } void unittest() { aries::DataNode* root = new aries::DataNode("root"); root->addChild(aries::StringNode("wee!")) ->addChild( aries::newNode("child") ->addChild("String data!") ) ->addChild( aries::newNode("child2") ->addChild( aries::newNode("child3") ->addChild("nesting!") ->addChild("This is so hot.") ) ) ->addChild("FEEL THE BURN"); std::stringstream ss; ss << root; std::cout << ss.str() << std::endl; aries::DataNode* n = aries::Node::readDocument(ss); std::cout << n << std::endl; delete root; delete n; } DataNode* newNode(const std::string& str) { return new DataNode(str); } } std::ostream& operator << (std::ostream& stream, aries::Node* node) { node->write(stream); return stream; } std::istream& operator >> (std::istream& stream, aries::DataNode*& node) { node = aries::Node::readDocument(stream); return stream; } --- NEW FILE: aries.h --- /** * Aries - The simplest markup language ever made. * Coded by Andy Friesen. * * Pseudo-BNF because I don't recall how BNF works exactly: * * Node :== string | (nodeName OneOrMoreNodes) * * Look like lisp? Guess what inspired it. * Extremely easy to parse, extremely easy to read. * Much less verbose than XML as well, though the lack of an analogue to * attributes makes automated conversion more or less impossible. * * Text is brought into the markup literally, with only leading and trailing * whitespace removed. (of course, you could always cut it up into tokens * yourself) Thus, if exact whitespace is important to you, just enclose the * datum in quotes. (or anything that's not parenthesis, really) * * Gay little example from an alternate dimension where HTML has been turned * into an Aries-based markup: * * (html * (head * (title tSBUPoNiP) * ) * (body * (font (size 3)(bold (underline * News * (-- Note that this markup has no comment system. Thus, we agree to * ignore all nodes that are named "--". Voila. Comments. ^_^ * * Note that comments can nest, due to the fact that they're not * really comments at all. I do have misgivings about forcing * comments to balance parenths, though. Maybe comments should be * added to the spec. * ) * ))) * (p * (bold (underline October 20)) * (br) Minor update. * (ul * (li v2 8 bit fonts added. v2.7 will (italics always) assume they * use v2's default palette; if they do not, you will have to * convert them to something else first. ) * (li major optimization concerning WinMapEd's image import feature. * The speed increase should be considerable. ) * (li v2.7 now uses (a (href http://www.python.org) Python 2.2). This * has a number of exceptional new language features. I highly * reccomend that you check the official site to see what's new. ) * ) * ) * ) */ /* * Legal garbage: * * Copyright (c) 2003 Andy Friesen * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from * the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source distribution. * */ // Source modified to compile in VC6 // -TomT64 #ifndef ARIES_H #define ARIES_H #include <string> #include <vector> namespace aries { typedef unsigned int uint; typedef std::vector<struct Node*> NodeList; typedef std::vector<struct DataNode*> DataNodeList; /** * Base class for all document nodes. * (there are only two anyway) */ struct Node { virtual ~Node(){} /** * Basically required so that RTTI doesn't need to be enabled. Returns true if the node * is a StringNode, false if it is a DataNode */ virtual bool isString() const = 0; /** * Returns a string representation of the node. */ virtual std::string toString() const = 0; /** * Creates a clone of the node, and returns it. The caller assumes ownership of the new node. */ virtual Node* clone() const = 0; /** * Writes the node to the stream. * The overloaded << operator calls this. */ virtual std::ostream& write(std::ostream& stream) const = 0; /** * Reads a document from the stream, and returns a node containing the document. * Note that, if you have a single root in your document, a la XML, that it will * be the only child of the node returned. * * operator >> calls this. */ static struct DataNode* readDocument(std::istream& stream); }; struct StringNode : Node { StringNode(const std::string& str); virtual bool isString() const; virtual std::string toString() const; virtual Node* clone() const; virtual std::ostream& write(std::ostream& stream) const; private: std::string _str; }; struct DataNode : Node { DataNode(const std::string& name); virtual ~DataNode(); virtual bool isString() const; virtual std::string toString() const; virtual Node* clone() const; std::string getString() const; ///< Returns the string data of the first string node, or "" if there isn't one. NodeList& getChildren(); ///< Returns a list of the children const NodeList& getChildren() const; ///< ditto DataNodeList getChildren(const std::string& name) const; ///< Returns all data nodes with the specified node name DataNode* getChild(const std::string& name) const; ///< Returns the first data node with the specified name. Throws a std::runtime_error if the child does not exist. DataNode* getChild(const std::string& name, DataNode* defaultValue) const; ///< Returns the first data node with the specified name, or defaultValue if the node cannot be found. bool hasChild(const std::string& name) const; ///< Returns true if the node has a child by this name. std::string getName() const; ///< Returns the name of the node DataNode* addChild(const std::string& str); ///< Creates a StringNode and adds it as a new child DataNode* addChild(int i); //DataNode* addChild(double d); DataNode* addChild(const Node& n); ///< Adds a copy of the node as a child DataNode* addChild(Node* n); ///< Adds the node as a child. The node assumes ownership of the pointer. (so don't delete it yourself) virtual std::ostream& write(std::ostream& stream) const; private: void write(std::ostream& stream, unsigned int indentLevel = 0) const; NodeList _children; std::string _name; }; void unittest(); ///< Pretty crappy unit test, but it's better than nothing. /** * since VC7 does not consider new DataNode(...)->addChild(...) to be valid C++, * You'll have to either put parenths around it, or use this. */ DataNode* newNode(const std::string& str); } std::ostream& operator << (std::ostream& stream, aries::Node* node); /// Converts the node (and its children) to a human readable format, and dumps it to the stream. std::istream& operator >> (std::istream& stream, aries::DataNode*& node); /// Reads the document in from the stream, and returns the root node. The caller assumes ownership of the pointer. #endif --- NEW FILE: log.cpp --- #include "log.h" #include <stdarg.h> #include <ios> #include <stdio.h> using std::endl; namespace Log { bool logInit = false; std::ofstream logFile; }; void Log::Init(const char *fileName) { if (logInit) return; logInit = true; logFile.open(fileName); } void Log::Write(const char* logText) { if (!logInit) return; logFile << logText; } void Log::Write(const std::string& logText) { if (!logInit) return; logFile << logText; } --- NEW FILE: log.h --- #ifndef LOG_H #define LOG_H #include <fstream> namespace Log { void Init(const char* fileName); void Write(const char* logText); void Write(const std::string& logText); }; #endif --- NEW FILE: datalib.h --- #ifndef DATALIB_H #define DATALIB_H #include <vector> #include <iostream> //Debug using namespace std; template <class T> class DataLib { private: std::vector<std::string> nameList; std::vector<T*> dataList; public: DataLib() {}; ~DataLib(); T* load(const char* Name); }; template<class T> DataLib<T>::~DataLib() { // cout << "DataLib Deconstructor" << "\t" << dataList.size() << "\t" << nameList.size() << "\t" << this << endl; typename vector<T*>::iterator i; for(i = dataList.begin(); i != dataList.end(); i++) { delete *i; } } template<class T> T* DataLib<T>::load(const char* fileName) { for(int i=0; i<nameList.size(); i++) { if (fileName == nameList[i]) { // cout << fileName << " == " << nameList[i] << "\t - Returning Addr: " << &dataList[i] << endl; return dataList[i]; } } T *newData = new T(fileName); nameList.push_back(fileName); dataList.push_back(newData); // cout << fileName << " != " << nameList[nameList.size() - 1] << "\t - Returning Addr: " << &dataList[dataList.size() - 1] << endl; return dataList[dataList.size() - 1]; } #endif --- NEW FILE: console.cpp --- #include "console.h" #include <iostream> using namespace std; void Console::addItem(const std::string &itemName, void *itemPtr, t_consoleType itemType) { t_consoleItem newItem; newItem.name = itemName; newItem.type = itemType; if(itemType == CTYPE_FUNCTION) newItem.function = (t_consoleFunction)itemPtr; else newItem.varPtr = itemPtr; itemList.push_back(newItem); } void Console::delItem(const std::string &itemName) { std::list<t_consoleItem>::iterator iter; for(iter = itemList.begin(); iter != itemList.end(); iter++) { if(iter->name == itemName) { itemList.erase(iter); return; } } } void Console::parseCmdLine() { std::vector<std::string> arguments; //Tokenize the son of a .... std::string::size_type lastPos = cmdLine.find_first_not_of(" ", 0); std::string::size_type index = cmdLine.find_first_of(" ", lastPos); while(index != std::string::npos || std::string::npos != lastPos) { arguments.push_back(cmdLine.substr(lastPos, index - lastPos)); lastPos = cmdLine.find_first_not_of(" ", index); index = cmdLine.find_first_of(" ", lastPos); } //What to do.. what to do... std::list<t_consoleItem>::iterator iter; for(iter = itemList.begin(); iter != itemList.end(); iter++) { if(iter->name == arguments[0]) { switch(iter->type) { case CTYPE_INT: if(arguments.size() > 2) return; else if(arguments.size() == 2) *((int*)(*iter).varPtr) = (int)atoi(arguments[1].c_str()); // std::ostringstream ss; // ss << (*iter).name << " = " << *((int*)(*iter).varPtr) << endl; lineBuffer.push_back("BOOP"); break; case CTYPE_FUNCTION: (*iter).function(arguments); break; } return; } } //Didn't find anything to do, blame the user. std::cout << "Error: not variable or command '" << cmdLine << "'" << std::endl; } |