summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorReimar <Reimar@Leike.name>2015-12-12 16:20:42 +0100
committerReimar <Reimar@Leike.name>2015-12-12 16:20:42 +0100
commit354cd9ff21e878c9a34866b0c3916e42e226d105 (patch)
tree8e6f2123e503c2f32eed35e629c6c0b9c01352d8 /main.cpp
parent8c66c87d920340b116c539a56505b32629275b6a (diff)
downloadRCade-354cd9ff21e878c9a34866b0c3916e42e226d105.tar
RCade-354cd9ff21e878c9a34866b0c3916e42e226d105.tar.gz
RCade-354cd9ff21e878c9a34866b0c3916e42e226d105.tar.bz2
RCade-354cd9ff21e878c9a34866b0c3916e42e226d105.tar.xz
RCade-354cd9ff21e878c9a34866b0c3916e42e226d105.zip
Now taking env variable RCADE_DATA and RCADE_SAVE. Default: data/ and save/ . also old saves are not compatibleHEADmaster
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/main.cpp b/main.cpp
index 738743d..305c67f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,11 @@
1#include "main.h" 1#include "main.h"
2
3
4string get_data_path()
5{
6 return DATA_PATH;
7}
8
2AbstractInteractive* getWeaponInfo(Weapon* w, SDL_Rect target, int textSize) 9AbstractInteractive* getWeaponInfo(Weapon* w, SDL_Rect target, int textSize)
3{ 10{
4 SDL_Rect tRect = target; 11 SDL_Rect tRect = target;
@@ -62,7 +69,7 @@ Shop::Shop(Account** nuser, int ngameMenu)
62 gameMenu = ngameMenu; 69 gameMenu = ngameMenu;
63 currentWeapon = 0; 70 currentWeapon = 0;
64 currentShip = 0; 71 currentShip = 0;
65 SDL_Surface* BG = loadBMP("data/images/bg_stars.bmp"); 72 SDL_Surface* BG = loadBMP(get_data_path() + "images/bg_stars.bmp");
66 SDL_Surface* mbg = SDL_CreateRGBSurface(0,400,400,32,0,0,0,0); 73 SDL_Surface* mbg = SDL_CreateRGBSurface(0,400,400,32,0,0,0,0);
67 SDL_FillRect(mbg,NULL,0x000102); 74 SDL_FillRect(mbg,NULL,0x000102);
68 SDL_SetColorKey(mbg,SDL_SRCCOLORKEY,0x000102); 75 SDL_SetColorKey(mbg,SDL_SRCCOLORKEY,0x000102);
@@ -88,7 +95,7 @@ Shop::Shop(Account** nuser, int ngameMenu)
88 95
89 //reading available weapons 96 //reading available weapons
90 ifstream ins; 97 ifstream ins;
91 string path = "data/weapons/"; 98 string path = get_data_path() + "weapons/";
92 ins.open((path+"weapons.txt").c_str()); 99 ins.open((path+"weapons.txt").c_str());
93 char workaround; 100 char workaround;
94 ins >> workaround; 101 ins >> workaround;
@@ -126,11 +133,11 @@ Shop::Shop(Account** nuser, int ngameMenu)
126 subRect.h = height; 133 subRect.h = height;
127 Scrollable* temps = new Scrollable(targetRect, tempm, subRect, false, true); 134 Scrollable* temps = new Scrollable(targetRect, tempm, subRect, false, true);
128 submenues.push_back(temps); 135 submenues.push_back(temps);
129 path = "data/ships/user/"; 136 path = get_data_path() + "ships/user/";
130 ins.open((path+"userships.txt").c_str()); 137 ins.open((path+"userships.txt").c_str());
131 ins >> workaround; 138 ins >> workaround;
132 vector<SDL_Surface*> shipPics; 139 vector<SDL_Surface*> shipPics;
133 Weapon empty = Weapon("data/weapons/empty.txt"); 140 Weapon empty = Weapon(get_data_path() + "weapons/empty.txt");
134 while(ins.good()) 141 while(ins.good())
135 { 142 {
136 string filepath; 143 string filepath;
@@ -270,7 +277,7 @@ void Shop::draw(SDL_Surface* screen)
270 textColor.r = 255; 277 textColor.r = 255;
271 textColor.g = 255; 278 textColor.g = 255;
272 textColor.b = 255; 279 textColor.b = 255;
273 TTF_Font *font = TTF_OpenFont("data/fonts/OpenSans-Semibold.ttf", 30); 280 TTF_Font *font = TTF_OpenFont((get_data_path() + "fonts/OpenSans-Semibold.ttf").c_str(), 30);
274 SDL_Surface* headline = NULL; 281 SDL_Surface* headline = NULL;
275 headline = TTF_RenderText_Solid(font, "Shop",textColor); 282 headline = TTF_RenderText_Solid(font, "Shop",textColor);
276 if(headline == NULL) 283 if(headline == NULL)
@@ -320,7 +327,7 @@ InventoryMenu::InventoryMenu(Account** nuser, int ngameMenu)
320 MY = 0; 327 MY = 0;
321 user = nuser; 328 user = nuser;
322 gameMenu = ngameMenu; 329 gameMenu = ngameMenu;
323 BG = new SlidingBackground(loadBMP("data/images/bg_stars.bmp"), 0, 100); 330 BG = new SlidingBackground(loadBMP(get_data_path() + "images/bg_stars.bmp"), 0, 100);
324 SDL_Rect backPos; 331 SDL_Rect backPos;
325 backPos.x = 0; 332 backPos.x = 0;
326 backPos.y = 460; 333 backPos.y = 460;
@@ -462,8 +469,8 @@ int InventoryMenu::handleEvents(SDL_Event event)
462 { 469 {
463 SDL_FreeSurface(cursor); 470 SDL_FreeSurface(cursor);
464 cursor = NULL; 471 cursor = NULL;
465 int x = event.button.x; 472// int x = event.button.x;
466 int y = event.button.y; 473// int y = event.button.y;
467 } 474 }
468 } 475 }
469 476
@@ -523,12 +530,12 @@ bool init(SDL_Surface*& screen)
523 530
524Menu* makeLoadGameMenu(SDL_Surface *screen) 531Menu* makeLoadGameMenu(SDL_Surface *screen)
525{ 532{
526 string bfile = "data/images/bg_stars.bmp"; 533 string bfile = get_data_path() + "images/bg_stars.bmp";
527 SDL_Surface *bg = loadBMP(bfile); 534 SDL_Surface *bg = loadBMP(bfile);
528 vector<string> ts; 535 vector<string> ts;
529 vector<int> ti; 536 vector<int> ti;
530 ifstream ins; 537 ifstream ins;
531 ins.open("save/saves.txt"); 538 ins.open((SAVE_PATH + "saves.txt").c_str());
532 char workaround; 539 char workaround;
533 ins >> workaround; 540 ins >> workaround;
534 int counter = 0; 541 int counter = 0;
@@ -551,7 +558,7 @@ Menu* makeLoadGameMenu(SDL_Surface *screen)
551 558
552Menu* makeMainMenu(SDL_Surface *screen) 559Menu* makeMainMenu(SDL_Surface *screen)
553{ 560{
554 string bfile = "data/images/bg_stars.bmp"; 561 string bfile = get_data_path() + "images/bg_stars.bmp";
555 SDL_Surface *bg = loadBMP(bfile); 562 SDL_Surface *bg = loadBMP(bfile);
556 vector<string> ts; 563 vector<string> ts;
557 ts.push_back("New Game"); 564 ts.push_back("New Game");
@@ -568,7 +575,7 @@ Menu* makeMainMenu(SDL_Surface *screen)
568 575
569Menu* makeGameMenu(SDL_Surface *screen) 576Menu* makeGameMenu(SDL_Surface *screen)
570{ 577{
571 string bfile = "data/images/bg_stars.bmp"; 578 string bfile = get_data_path() + "images/bg_stars.bmp";
572 SDL_Surface *bg = loadBMP(bfile); 579 SDL_Surface *bg = loadBMP(bfile);
573 vector<string> ts; 580 vector<string> ts;
574 ts.push_back("Missions"); 581 ts.push_back("Missions");
@@ -591,7 +598,7 @@ Menu* makeGameMenu(SDL_Surface *screen)
591 598
592Menu* makeLevelMenu(vector<string> levels, SDL_Surface *screen) 599Menu* makeLevelMenu(vector<string> levels, SDL_Surface *screen)
593{ 600{
594 string bfile = "data/images/bg_stars.bmp"; 601 string bfile = get_data_path() + "images/bg_stars.bmp";
595 SDL_Surface *bg = loadBMP(bfile); 602 SDL_Surface *bg = loadBMP(bfile);
596 vector<string> ts; 603 vector<string> ts;
597 vector<int> ti; 604 vector<int> ti;
@@ -619,7 +626,7 @@ GameHandler::GameHandler()
619 isGood = false; 626 isGood = false;
620 //reading available levels 627 //reading available levels
621 ifstream ins; 628 ifstream ins;
622 string path = "data/levels/"; 629 string path = get_data_path() + "levels/";
623 ins.open((path+"levels.txt").c_str()); 630 ins.open((path+"levels.txt").c_str());
624 char workaround; 631 char workaround;
625 ins >> workaround; 632 ins >> workaround;
@@ -638,7 +645,7 @@ GameHandler::GameHandler()
638 menus.push_back(makeLevelMenu(levelpaths,screen)); 645 menus.push_back(makeLevelMenu(levelpaths,screen));
639 menus.push_back(new Shop(&user, MENU | 1)); 646 menus.push_back(new Shop(&user, MENU | 1));
640 menus.push_back(makeLoadGameMenu(screen)); 647 menus.push_back(makeLoadGameMenu(screen));
641 SDL_Surface* bg = loadBMP("data/images/bg_stars.bmp"); 648 SDL_Surface* bg = loadBMP(get_data_path() + "images/bg_stars.bmp");
642 GetStringMenu* mt = new GetStringMenu("Enter your Nickname:", MENU | 0, LEVEL | 0, bg, screen); 649 GetStringMenu* mt = new GetStringMenu("Enter your Nickname:", MENU | 0, LEVEL | 0, bg, screen);
643 acname = &mt->s; 650 acname = &mt->s;
644 menus.push_back(mt); 651 menus.push_back(mt);
@@ -691,7 +698,7 @@ int GameHandler::game()
691 if(*acname != "") 698 if(*acname != "")
692 { 699 {
693 delete user; 700 delete user;
694 user = new Account("data/default/account.txt"); 701 user = new Account(get_data_path() + "default/account.txt");
695 user->name = *acname; 702 user->name = *acname;
696 menus[5]->refresh(); 703 menus[5]->refresh();
697 menus[3]->refresh(); 704 menus[3]->refresh();
@@ -710,7 +717,7 @@ int GameHandler::game()
710 if(state & LOAD) 717 if(state & LOAD)
711 { 718 {
712 ifstream ins; 719 ifstream ins;
713 ins.open("save/saves.txt"); 720 ins.open((SAVE_PATH + "saves.txt").c_str());
714 char workaround; 721 char workaround;
715 ins >> workaround; 722 ins >> workaround;
716 int counter = 0; 723 int counter = 0;
@@ -722,7 +729,7 @@ int GameHandler::game()
722 { 729 {
723 account = workaround + account; 730 account = workaround + account;
724 delete user; 731 delete user;
725 user = new Account("save/" + account + ".txt"); 732 user = new Account(SAVE_PATH + account + ".txt");
726 menus[3]->refresh(); 733 menus[3]->refresh();
727 menus[6]->refresh(); 734 menus[6]->refresh();
728 user->resetShips(); 735 user->resetShips();
@@ -802,6 +809,11 @@ int GameHandler::game()
802 809
803int main(int argc, char* args[]) 810int main(int argc, char* args[])
804{ 811{
812 if(getenv("RCADE_DATA") != NULL)
813 DATA_PATH = getenv("RCADE_DATA");
814
815 if(getenv("RCADE_SAVE") != NULL)
816 SAVE_PATH = getenv("RCADE_DATA");
805 GameHandler* GH = new GameHandler(); 817 GameHandler* GH = new GameHandler();
806 818
807// Account a = Account(); 819// Account a = Account();