From 6c50e56894ecb63012acf60d7749d0853cbf4a20 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 16 Mar 2013 19:04:19 +0000 Subject: [PATCH] [Add] "special" techs. Basically finished tech stuff. --- TODO | 1 - src/land.c | 4 ++-- src/outfit.c | 12 +++++++++--- src/outfit.h | 2 +- src/ship.c | 12 +++++++++--- src/ship.h | 2 +- src/space.c | 4 ++-- src/space.h | 6 ++++-- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 6da91f5..70100a6 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ Vital: -- Missions -- Save -- Allow multiple ships in storage. - -- Tech system. -- Commodities. -- Main Menu. diff --git a/src/land.c b/src/land.c index 2ee4cf0..a613dfd 100644 --- a/src/land.c +++ b/src/land.c @@ -137,7 +137,7 @@ static void outfits(void) { &gl_smallFont, NULL, NULL); // Set up the outfits to buy/sell. - outfits = outfit_getTech(&noutfits, planet->tech[0]); // TODO: Special tech. + outfits = outfit_getTech(&noutfits, planet->tech, PLANET_TECH_MAX); window_addList(secondary_wid, 20, 40, 200, OUTFITS_HEIGHT-80, "lstOutfits", outfits, noutfits, 0, outfits_update); @@ -310,7 +310,7 @@ static void shipyard(void) { &gl_smallFont, NULL, NULL); // Setup the ships to buy/sell. - ships = ship_getTech(&nships, planet->tech[0]); + ships = ship_getTech(&nships, planet->tech, PLANET_TECH_MAX); window_addList(secondary_wid, 20, 40, 200, SHIPYARD_HEIGHT-80, "lstShipyard", ships, nships, 0, shipyard_update); diff --git a/src/outfit.c b/src/outfit.c index 61e0671..8dd39ab 100644 --- a/src/outfit.c +++ b/src/outfit.c @@ -39,15 +39,21 @@ Outfit* outfit_get(const char* name) { } // Return all the outfits. -char** outfit_getTech(int* n, const int tech) { - int i; +char** outfit_getTech(int* n, const int* tech, const int techmax) { + int i, j; char** outfitnames = malloc(sizeof(Outfit*) * outfits); *n = 0; for(i = 0; i < outfits; i++) - if(outfit_stack[i].tech <= tech) { + if(outfit_stack[i].tech <= tech[0]) { outfitnames[*n] = strdup(outfit_stack[i].name); (*n)++; + } else { + for(j = 0; j < techmax; j++) + if(tech[j] == outfit_stack[i].tech) { + outfitnames[*n] = strdup(outfit_stack[i].name); + (*n)++; + } } // Actual size is bigger, but it'll just get freed ;). diff --git a/src/outfit.h b/src/outfit.h index 1ad4eb9..cb56c61 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -83,7 +83,7 @@ typedef struct Outfit_ { // Get. Outfit* outfit_get(const char* name); -char** outfit_getTech(int* n, const int tech); +char** outfit_getTech(int* n, const int* tech, const int techmax); // Outfit types. int outfit_isWeapon(const Outfit* o); int outfit_isLauncher(const Outfit* o); diff --git a/src/ship.c b/src/ship.c index 86309de..9d4c64b 100644 --- a/src/ship.c +++ b/src/ship.c @@ -46,15 +46,21 @@ static char* ship_classes[] = { }; // Return all the ships in text form. -char** ship_getTech(int* n, const int tech) { - int i; +char** ship_getTech(int* n, const int* tech, const int techmax) { + int i, j; char** shipnames = malloc(sizeof(Ship*) * ships); *n = 0; for(i = 0; i < ships; i++) - if(ship_stack[i].tech <= tech) { + if(ship_stack[i].tech <= tech[0]) { shipnames[*n] = strdup(ship_stack[i].name); (*n)++; + } else { + for(j = 0; j < techmax; j++) + if(tech[j] == ship_stack[i].tech) { + shipnames[*n] = strdup(ship_stack[i].name); + (*n)++; + } } return shipnames; diff --git a/src/ship.h b/src/ship.h index 0a00b6e..1728cce 100644 --- a/src/ship.h +++ b/src/ship.h @@ -63,7 +63,7 @@ typedef struct Ship_ { // Get. Ship* ship_get(const char* name); -char** ship_getTech(int* n, const int tech); +char** ship_getTech(int* n, const int* tech, const int techmax); char* ship_class(Ship* p); // Load/quit. diff --git a/src/space.c b/src/space.c index e5046a7..f1c76da 100644 --- a/src/space.c +++ b/src/space.c @@ -381,12 +381,12 @@ static Planet* planet_get(const char* name) { tmp->tech[0] = xml_getInt(ccur); } else if(xml_isNode(ccur, "special")) { - for(i = 1; i < 8; i++) + for(i = 1; i < PLANET_TECH_MAX; i++) if(tmp->tech[i]==0) { tmp->tech[i] = xml_getInt(ccur); break; } - if(i == 8) WARN("Planet '%s' has tooo many" + if(i == PLANET_TECH_MAX) WARN("Planet '%s' has tooo many" "'special tech' entries", tmp->name); } } while((ccur = ccur->next)); diff --git a/src/space.h b/src/space.h index c84b1c4..dac3628 100644 --- a/src/space.h +++ b/src/space.h @@ -6,6 +6,8 @@ #define MIN_HYPERSPACE_DIST 1500 #define MAX_HYPERSPACE_VEL 25 +#define PLANET_TECH_MAX 8 + // Planet types. I didn't take them from Star Trek, I promise. typedef enum PlanetClass_ { PLANET_CLASS_NULL = 0, @@ -55,8 +57,8 @@ typedef struct Planet_ { unsigned int services; // Offered services. // tech[0] stores global tech level (everything that and below) while - // tech[1-7] stores the unique tech levels. - int tech[8]; + // tech[1-PLANET_TECH_MAX] stores the unique tech levels. + int tech[PLANET_TECH_MAX]; glTexture* gfx_space; // Graphics in space. glTexture* gfx_exterior; // Graphics in the exterior.