diff --git a/common.mk b/common.mk index 0eaeff2..d879f35 100644 --- a/common.mk +++ b/common.mk @@ -37,7 +37,7 @@ OBJS += testMission.o textures.o text.o title.o transition.o OBJS += util.o OBJS += waypoints.o widgets.o -DIST_FILES = data gfx manual music sound src LICENSE makefile README.md CHANGELOG +DIST_FILES = data gfx manual music sound src LICENSE makefile* common.mk README.md CHANGELOG # top-level rule to create the program. all: $(TARGET) @@ -49,6 +49,19 @@ all: $(TARGET) # linking the program. $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LIBS) + +install: + cp $(TARGET) $(BIN_DIR) + mkdir -p $(DATA_DIR) + cp -r data $(DATA_DIR) + cp -r gfx $(DATA_DIR) + cp -r manual $(DATA_DIR) + cp -r music $(DATA_DIR) + cp -r sound $(DATA_DIR) + +uninstall: + $(RM) $(BIN_DIR)/$(TARGET) + $(RM) -rf $(DATA_DIR) # prepare an archive for the program dist: @@ -58,7 +71,7 @@ dist: git log --oneline --decorate >$(PROG)-$(VERSION)/CHANGELOG.raw tar czf $(PROG)-$(VERSION).$(REVISION)-src.tar.gz $(PROG)-$(VERSION) mkdir -p dist - $(RM) -rf dist + $(RM) -rf dist/* mv $(PROG)-$(VERSION).$(REVISION)-src.tar.gz dist $(RM) -rf $(PROG)-$(VERSION) diff --git a/Makefile b/makefile similarity index 67% rename from Makefile rename to makefile index d0c49b4..023faca 100644 --- a/Makefile +++ b/makefile @@ -1,5 +1,7 @@ CC = gcc EXEEXT = +BIN_DIR = /usr/bin +DATA_DIR = /opt/tbftss SEARCHPATH += src/plat/unix OBJS += unixInit.o diff --git a/Makefile.win32 b/makefile.win32 similarity index 100% rename from Makefile.win32 rename to makefile.win32 diff --git a/src/battle/bullets.c b/src/battle/bullets.c index acb35fe..2b8009a 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -36,7 +36,7 @@ void initBulletDefs(void) memset(&bulletDef, 0, sizeof(Bullet) * BT_MAX); - text = readFile("data/battle/bullets.json"); + text = readFile(getFileLocation("data/battle/bullets.json")); root = cJSON_Parse(text); diff --git a/src/battle/bullets.h b/src/battle/bullets.h index d86c25e..7e960dd 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -43,6 +43,7 @@ extern void addMissileExplosion(Bullet *b); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void playSound(int id); +extern char *getFileLocation(char *filename); extern Battle battle; extern Colors colors; diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 14d0073..263dcf3 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -597,7 +597,7 @@ void loadFighterDefs(void) cJSON *root, *node; char *text; - text = readFile("data/fighters/list.json"); + text = readFile(getFileLocation("data/fighters/list.json")); root = cJSON_Parse(text); memset(&defHead, 0, sizeof(Entity)); @@ -621,7 +621,7 @@ static void loadFighterDef(char *filename) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); - text = readFile(filename); + text = readFile(getFileLocation(filename)); f = malloc(sizeof(Entity)); memset(f, 0, sizeof(Entity)); diff --git a/src/battle/fighters.h b/src/battle/fighters.h index d39f494..cd5e8f8 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -49,6 +49,7 @@ extern void addShieldSplinterEffect(Entity *ent); extern void completeMission(void); extern void drawShieldHitEffect(Entity *e); extern void runScriptFunction(char *format, ...); +extern char *getFileLocation(char *filename); extern App app; extern Battle battle; diff --git a/src/battle/items.c b/src/battle/items.c index a5a3933..fcb8fd9 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -31,7 +31,7 @@ void loadItemDefs(void) char *text; Entity *e; - text = readFile("data/battle/items.json"); + text = readFile(getFileLocation("data/battle/items.json")); root = cJSON_Parse(text); diff --git a/src/battle/items.h b/src/battle/items.h index 91df009..b1ed312 100644 --- a/src/battle/items.h +++ b/src/battle/items.h @@ -32,6 +32,7 @@ extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int extern void playBattleSound(int id, int x, int y); extern void addHudMessage(SDL_Color c, char *format, ...); extern void updateObjective(char *name, int type); +extern char *getFileLocation(char *filename); extern Battle battle; extern Entity *self; diff --git a/src/defs.h b/src/defs.h index 91a6efe..03d7089 100644 --- a/src/defs.h +++ b/src/defs.h @@ -22,6 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define REVISION 0 #endif +#ifndef DATA_DIR +#define DATA_DIR "" +#endif + #define PI 3.14159265358979323846 #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) diff --git a/src/draw/text.c b/src/draw/text.c index 9823204..8fa5bf5 100644 --- a/src/draw/text.c +++ b/src/draw/text.c @@ -230,7 +230,7 @@ static void loadFont(int size) { SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "loadFonts(%d)", size); - font[size] = TTF_OpenFont("data/fonts/Roboto-Medium.ttf", size); + font[size] = TTF_OpenFont(getFileLocation("data/fonts/Roboto-Medium.ttf"), size); } static unsigned long hashcode(const char *str, int size) diff --git a/src/draw/text.h b/src/draw/text.h index 7c5ef08..0841622 100644 --- a/src/draw/text.h +++ b/src/draw/text.h @@ -25,5 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../structs.h" extern void blit(SDL_Texture *texture, int x, int y, int centered); +extern char *getFileLocation(char *filename); extern App app; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index b40cb49..ec2fd69 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -38,7 +38,7 @@ void loadMission(char *filename) stopMusic(); - text = readFile(filename); + text = readFile(getFileLocation(filename)); srand(hashcode(filename)); diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index da99384..710f19e 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -44,6 +44,7 @@ extern void failIncompleteObjectives(void); extern void completeConditions(void); extern void retreatEnemies(void); extern void initScript(cJSON *missionJSON); +extern char *getFileLocation(char *filename); extern Battle battle; extern Entity *player; diff --git a/src/galaxy/starSystems.c b/src/galaxy/starSystems.c index 8b55518..8792c4f 100644 --- a/src/galaxy/starSystems.c +++ b/src/galaxy/starSystems.c @@ -28,7 +28,7 @@ void initStarSystems(void) cJSON *root, *node; char *text; - text = readFile("data/galaxy/starSystems.json"); + text = readFile(getFileLocation("data/galaxy/starSystems.json")); root = cJSON_Parse(text); for (node = cJSON_GetObjectItem(root, "starSystems")->child ; node != NULL ; node = node->next) @@ -81,7 +81,7 @@ static void loadMissionMeta(char *filename, StarSystem *starSystem) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); - text = readFile(filename); + text = readFile(getFileLocation(filename)); root = cJSON_Parse(text); diff --git a/src/galaxy/starSystems.h b/src/galaxy/starSystems.h index 3165067..7872b06 100644 --- a/src/galaxy/starSystems.h +++ b/src/galaxy/starSystems.h @@ -27,5 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(char *filename); extern long lookup(char *name); extern int isMissionAvailable(Mission *mission, Mission *prev); +extern char *getFileLocation(char *filename); extern Game game; diff --git a/src/system/init.c b/src/system/init.c index 8354416..39b04e8 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -151,7 +151,7 @@ static void loadConfig(void) } else { - text = readFile("data/app/config.json"); + text = readFile(getFileLocation("data/app/config.json")); } root = cJSON_Parse(text); diff --git a/src/system/init.h b/src/system/init.h index 95cfc1c..9db7edb 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -56,6 +56,7 @@ extern void destroyWidgets(void); extern void expireTexts(void); extern void initInput(void); extern void createSaveFolder(void); +extern char *getFileLocation(char *filename); extern App app; extern Colors colors; diff --git a/src/system/io.c b/src/system/io.c index 86ad4d4..471b827 100644 --- a/src/system/io.c +++ b/src/system/io.c @@ -73,3 +73,17 @@ char *getSaveFilePath(char *filename) return path; } + +char *getFileLocation(char *filename) +{ + static char path[MAX_FILENAME_LENGTH]; + + if (fileExists(filename)) + { + return filename; + } + + sprintf(path, "%s/%s\n", DATA_DIR, filename); + + return path; +} diff --git a/src/system/sound.c b/src/system/sound.c index d52f9cf..1906402 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -91,28 +91,27 @@ void playBattleSound(int id, int x, int y) static void loadSounds(void) { - sounds[SND_ARMOUR_HIT] = Mix_LoadWAV("sound/275151__bird-man__gun-shot.ogg"); - sounds[SND_SHIELD_HIT] = Mix_LoadWAV("sound/49678__ejfortin__energy-short-sword-7.ogg"); - sounds[SND_PLASMA] = Mix_LoadWAV("sound/268344__julien-matthey__jm-noiz-laser-01.ogg"); - sounds[SND_LASER] = Mix_LoadWAV("sound/18382__inferno__hvylas.ogg"); - sounds[SND_MAG] = Mix_LoadWAV("sound/146725__fins__laser.ogg"); - sounds[SND_SHIELD_BREAK] = Mix_LoadWAV("sound/322603__clippysounds__glass-break.ogg"); - sounds[SND_PARTICLE] = Mix_LoadWAV("sound/77087__supraliminal__laser-short.ogg"); - sounds[SND_MISSILE] = Mix_LoadWAV("sound/65787__iwilldstroyu__laserrocket.ogg"); - sounds[SND_BOOST] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg"); - /*sounds[SND_ECM] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg");*/ - sounds[SND_RADIO] = Mix_LoadWAV("sound/321906__bruce965__walkie-talkie-roger-beep.ogg"); - sounds[SND_INCOMING] = Mix_LoadWAV("sound/242856__plasterbrain__nuclear-alarm.ogg"); - sounds[SND_GET_ITEM] = Mix_LoadWAV("sound/88275__s-dij__gbc-reload-06.ogg"); - sounds[SND_EXPLOSION_1] = Mix_LoadWAV("sound/162265__qubodup__explosive.ogg"); - sounds[SND_EXPLOSION_2] = Mix_LoadWAV("sound/207322__animationisaac__short-explosion.ogg"); - sounds[SND_EXPLOSION_3] = Mix_LoadWAV("sound/254071__tb0y298__firework-explosion.ogg"); - sounds[SND_EXPLOSION_4] = Mix_LoadWAV("sound/47252__nthompson__bad-explosion.ogg"); + sounds[SND_ARMOUR_HIT] = Mix_LoadWAV(getFileLocation("sound/275151__bird-man__gun-shot.ogg")); + sounds[SND_SHIELD_HIT] = Mix_LoadWAV(getFileLocation("sound/49678__ejfortin__energy-short-sword-7.ogg")); + sounds[SND_PLASMA] = Mix_LoadWAV(getFileLocation("sound/268344__julien-matthey__jm-noiz-laser-01.ogg")); + sounds[SND_LASER] = Mix_LoadWAV(getFileLocation("sound/18382__inferno__hvylas.ogg")); + sounds[SND_MAG] = Mix_LoadWAV(getFileLocation("sound/146725__fins__laser.ogg")); + sounds[SND_SHIELD_BREAK] = Mix_LoadWAV(getFileLocation("sound/322603__clippysounds__glass-break.ogg")); + sounds[SND_PARTICLE] = Mix_LoadWAV(getFileLocation("sound/77087__supraliminal__laser-short.ogg")); + sounds[SND_MISSILE] = Mix_LoadWAV(getFileLocation("sound/65787__iwilldstroyu__laserrocket.ogg")); + sounds[SND_BOOST] = Mix_LoadWAV(getFileLocation("sound/18380__inferno__hvrl.ogg")); + sounds[SND_RADIO] = Mix_LoadWAV(getFileLocation("sound/321906__bruce965__walkie-talkie-roger-beep.ogg")); + sounds[SND_INCOMING] = Mix_LoadWAV(getFileLocation("sound/242856__plasterbrain__nuclear-alarm.ogg")); + sounds[SND_GET_ITEM] = Mix_LoadWAV(getFileLocation("sound/88275__s-dij__gbc-reload-06.ogg")); + sounds[SND_EXPLOSION_1] = Mix_LoadWAV(getFileLocation("sound/162265__qubodup__explosive.ogg")); + sounds[SND_EXPLOSION_2] = Mix_LoadWAV(getFileLocation("sound/207322__animationisaac__short-explosion.ogg")); + sounds[SND_EXPLOSION_3] = Mix_LoadWAV(getFileLocation("sound/254071__tb0y298__firework-explosion.ogg")); + sounds[SND_EXPLOSION_4] = Mix_LoadWAV(getFileLocation("sound/47252__nthompson__bad-explosion.ogg")); - sounds[SND_GUI_CLICK] = Mix_LoadWAV("sound/257786__xtrgamr__mouse-click.ogg"); - sounds[SND_GUI_SELECT] = Mix_LoadWAV("sound/321104__nsstudios__blip2.ogg"); - sounds[SND_GUI_CLOSE] = Mix_LoadWAV("sound/178064__jorickhoofd__slam-door-shut.ogg"); - sounds[SND_GUI_DENIED] = Mix_LoadWAV("sound/249300__suntemple__access-denied.ogg"); + sounds[SND_GUI_CLICK] = Mix_LoadWAV(getFileLocation("sound/257786__xtrgamr__mouse-click.ogg")); + sounds[SND_GUI_SELECT] = Mix_LoadWAV(getFileLocation("sound/321104__nsstudios__blip2.ogg")); + sounds[SND_GUI_CLOSE] = Mix_LoadWAV(getFileLocation("sound/178064__jorickhoofd__slam-door-shut.ogg")); + sounds[SND_GUI_DENIED] = Mix_LoadWAV(getFileLocation("sound/249300__suntemple__access-denied.ogg")); } void destroySounds(void) diff --git a/src/system/sound.h b/src/system/sound.h index 2f1af63..92f92c4 100644 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -28,5 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_BATTLE_SOUND_DISTANCE 1500 extern int getDistance(int x1, int y1, int x2, int y2); +extern char *getFileLocation(char *filename); extern Entity *player; diff --git a/src/system/textures.c b/src/system/textures.c index f85ed5a..072cf19 100644 --- a/src/system/textures.c +++ b/src/system/textures.c @@ -60,7 +60,7 @@ static SDL_Texture *loadTexture(char *filename) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); - texture = IMG_LoadTexture(app.renderer, filename); + texture = IMG_LoadTexture(app.renderer, getFileLocation(filename)); addTextureToCache(filename, texture); diff --git a/src/system/textures.h b/src/system/textures.h index 4a072bc..66e64c4 100644 --- a/src/system/textures.h +++ b/src/system/textures.h @@ -23,4 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" +extern char *getFileLocation(char *filename); + extern App app; diff --git a/src/system/widgets.c b/src/system/widgets.c index 953036c..8bf0adf 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -45,7 +45,7 @@ void initWidgets(void) optionsLeft = getTexture("gfx/widgets/optionsLeft.png"); optionsRight = getTexture("gfx/widgets/optionsRight.png"); - loadWidgets("data/widgets/list.json"); + loadWidgets(getFileLocation("data/widgets/list.json")); drawingWidgets = 0; } @@ -231,12 +231,12 @@ static void loadWidgets(char *filename) cJSON *root, *node; char *text; - text = readFile(filename); + text = readFile(getFileLocation(filename)); root = cJSON_Parse(text); for (node = root->child ; node != NULL ; node = node->next) { - loadWidgetSet(node->valuestring); + loadWidgetSet(getFileLocation(node->valuestring)); } cJSON_Delete(root); @@ -251,7 +251,7 @@ static void loadWidgetSet(char *filename) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); - text = readFile(filename); + text = readFile(getFileLocation(filename)); root = cJSON_Parse(text); for (node = root->child ; node != NULL ; node = node->next) diff --git a/src/system/widgets.h b/src/system/widgets.h index 7bbf529..1aa715f 100644 --- a/src/system/widgets.h +++ b/src/system/widgets.h @@ -32,6 +32,7 @@ extern void blit(SDL_Texture *texture, int x, int y, int centered); extern SDL_Texture *getTexture(char *filename); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern void playSound(int id); +extern char *getFileLocation(char *filename); extern App app; extern Colors colors;