[Add] Planets now have commodities. Nothing can be done with them yet ;)
This commit is contained in:
		
							parent
							
								
									4f0420d82f
								
							
						
					
					
						commit
						aa4112f2df
					
				@ -14,7 +14,10 @@
 | 
				
			|||||||
			<tech>
 | 
								<tech>
 | 
				
			||||||
				<main>3</main>
 | 
									<main>3</main>
 | 
				
			||||||
			</tech>
 | 
								</tech>
 | 
				
			||||||
			<commodities>1</commodities>
 | 
								<commodities>
 | 
				
			||||||
 | 
									<commodity>Food</commodity>
 | 
				
			||||||
 | 
									<commodity>Ore</commodity>
 | 
				
			||||||
 | 
								</commodities>
 | 
				
			||||||
		</general>
 | 
							</general>
 | 
				
			||||||
		<GFX>
 | 
							<GFX>
 | 
				
			||||||
      <space>konosphere.png</space>
 | 
					      <space>konosphere.png</space>
 | 
				
			||||||
@ -35,7 +38,10 @@
 | 
				
			|||||||
			<tech>
 | 
								<tech>
 | 
				
			||||||
				<main>4</main>
 | 
									<main>4</main>
 | 
				
			||||||
			</tech>
 | 
								</tech>
 | 
				
			||||||
			<commodities>1</commodities>
 | 
								<commodities>
 | 
				
			||||||
 | 
									<commodity>Food</commodity>
 | 
				
			||||||
 | 
									<commodity>Ore</commodity>
 | 
				
			||||||
 | 
								</commodities>
 | 
				
			||||||
		</general>
 | 
							</general>
 | 
				
			||||||
		<GFX>
 | 
							<GFX>
 | 
				
			||||||
      <space>saracraft.png</space>
 | 
					      <space>saracraft.png</space>
 | 
				
			||||||
@ -56,7 +62,9 @@
 | 
				
			|||||||
			<tech>
 | 
								<tech>
 | 
				
			||||||
				<main>5</main>
 | 
									<main>5</main>
 | 
				
			||||||
			</tech>
 | 
								</tech>
 | 
				
			||||||
			<commodities>1</commodities>
 | 
								<commodities>
 | 
				
			||||||
 | 
									<commodity>Food</commodity>
 | 
				
			||||||
 | 
								</commodities>
 | 
				
			||||||
		</general>
 | 
							</general>
 | 
				
			||||||
		<GFX>
 | 
							<GFX>
 | 
				
			||||||
      <space>station00.png</space>
 | 
					      <space>station00.png</space>
 | 
				
			||||||
 | 
				
			|||||||
@ -33,6 +33,17 @@ void credits2str(char* str, unsigned int credits, int decimals) {
 | 
				
			|||||||
	else snprintf(str, 16, "%d", credits);
 | 
						else snprintf(str, 16, "%d", credits);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Get a commodity.
 | 
				
			||||||
 | 
					Commodity* commodity_get(const char* name) {
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						for(i = 0; i < commodity_nstack; i++)
 | 
				
			||||||
 | 
							if(strcmp(commodity_stack[i].name, name)==0)
 | 
				
			||||||
 | 
								return &commodity_stack[i];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						WARN("Commodity '%s' not found in stack", name);
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Free a commodity.
 | 
					// Free a commodity.
 | 
				
			||||||
static void commodity_freeOne(Commodity* com) {
 | 
					static void commodity_freeOne(Commodity* com) {
 | 
				
			||||||
	if(com->name) free(com->name);
 | 
						if(com->name) free(com->name);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/land.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/land.c
									
									
									
									
									
								
							@ -69,16 +69,22 @@ static void news_close(char* str);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// The local market.
 | 
					// The local market.
 | 
				
			||||||
static void commodity_exchange(void) {
 | 
					static void commodity_exchange(void) {
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						char** goods;
 | 
				
			||||||
  secondary_wid = window_create("Commodity Exchange", -1, -1,
 | 
					  secondary_wid = window_create("Commodity Exchange", -1, -1,
 | 
				
			||||||
				COMMODITY_WIDTH, COMMODITY_HEIGHT);
 | 
									COMMODITY_WIDTH, COMMODITY_HEIGHT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  window_addButton(secondary_wid, -20, 20,
 | 
					  window_addButton(secondary_wid, -20, 20,
 | 
				
			||||||
        BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
 | 
					        BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
 | 
				
			||||||
        "Close", commodity_exchange_close);
 | 
					        "Close", commodity_exchange_close);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						goods = malloc(sizeof(char*)*planet->ncommodities);
 | 
				
			||||||
 | 
						for(i = 0; i < planet->ncommodities; i++)
 | 
				
			||||||
 | 
							goods[i] = strdup(planet->commodities[i]->name);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	window_addList(secondary_wid, 20, -40,
 | 
						window_addList(secondary_wid, 20, -40,
 | 
				
			||||||
				COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
 | 
									100, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
 | 
				
			||||||
				"lstGoods", NULL, 0, 0, NULL);
 | 
									"lstGoods", goods, planet->ncommodities, 0, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void commodity_exchange_close(char* str) {
 | 
					static void commodity_exchange_close(char* str) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								src/space.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/space.c
									
									
									
									
									
								
							@ -391,6 +391,18 @@ static Planet* planet_get(const char* name) {
 | 
				
			|||||||
									}
 | 
														}
 | 
				
			||||||
								} while((ccur = ccur->next));
 | 
													} while((ccur = ccur->next));
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
												else if(xml_isNode(cur, "commodities")) {
 | 
				
			||||||
 | 
													ccur = cur->children;
 | 
				
			||||||
 | 
													do {
 | 
				
			||||||
 | 
														if(xml_isNode(ccur, "commodity")) {
 | 
				
			||||||
 | 
															tmp->commodities = realloc(tmp->commodities,
 | 
				
			||||||
 | 
																		(tmp->ncommodities+1) * sizeof(Commodity*));
 | 
				
			||||||
 | 
															tmp->commodities[tmp->ncommodities] =
 | 
				
			||||||
 | 
																		commodity_get(xml_get(ccur));
 | 
				
			||||||
 | 
															tmp->ncommodities++;
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													} while((ccur = ccur->next));
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
            } while((cur = cur->next));
 | 
					            } while((cur = cur->next));
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } while((node = node->next));
 | 
					        } while((node = node->next));
 | 
				
			||||||
@ -418,6 +430,8 @@ static Planet* planet_get(const char* name) {
 | 
				
			|||||||
		MELEMENT((planet_hasService(tmp, PLANET_SERVICE_OUTFITS) ||
 | 
							MELEMENT((planet_hasService(tmp, PLANET_SERVICE_OUTFITS) ||
 | 
				
			||||||
					planet_hasService(tmp, PLANET_SERVICE_SHIPYARD)) &&
 | 
										planet_hasService(tmp, PLANET_SERVICE_SHIPYARD)) &&
 | 
				
			||||||
					(flags&FLAG_TECHSET)==0, "tech");
 | 
										(flags&FLAG_TECHSET)==0, "tech");
 | 
				
			||||||
 | 
							MELEMENT(planet_hasService(tmp, PLANET_SERVICE_COMMODITY) &&
 | 
				
			||||||
 | 
										(tmp->ncommodities==0), "commodity");
 | 
				
			||||||
#undef MELEMENT
 | 
					#undef MELEMENT
 | 
				
			||||||
  } else
 | 
					  } else
 | 
				
			||||||
    WARN("No planet found matching name '%s'", name);
 | 
					    WARN("No planet found matching name '%s'", name);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "faction.h"
 | 
					#include "faction.h"
 | 
				
			||||||
#include "opengl.h"
 | 
					#include "opengl.h"
 | 
				
			||||||
 | 
					#include "economy.h"
 | 
				
			||||||
#include "pilot.h"
 | 
					#include "pilot.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MIN_HYPERSPACE_DIST 1500
 | 
					#define MIN_HYPERSPACE_DIST 1500
 | 
				
			||||||
@ -55,6 +56,8 @@ typedef struct Planet_ {
 | 
				
			|||||||
  char* description;  			// Planet description.
 | 
					  char* description;  			// Planet description.
 | 
				
			||||||
  char* bar_description; 		// Spaceport bar description.
 | 
					  char* bar_description; 		// Spaceport bar description.
 | 
				
			||||||
  unsigned int services;  	// Offered services.
 | 
					  unsigned int services;  	// Offered services.
 | 
				
			||||||
 | 
						Commodity** commodities; 	// Commodities sold.
 | 
				
			||||||
 | 
						int ncommodities;					// Amount in stock.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// tech[0] stores global tech level (everything that and below) while
 | 
						// tech[0] stores global tech level (everything that and below) while
 | 
				
			||||||
	// tech[1-PLANET_TECH_MAX] stores the unique tech levels.
 | 
						// tech[1-PLANET_TECH_MAX] stores the unique tech levels.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user