[Change] Using either Fleets or FleetGroups when loading starsystems.
This commit is contained in:
parent
4ddb216e6a
commit
72d88644b6
85
src/space.c
85
src/space.c
@ -990,11 +990,61 @@ int system_rmFleet(StarSystem* sys, SystemFleet* fleet) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a FleetGroup to a star system.
|
||||||
|
* @param sys Star System to add fleet to.
|
||||||
|
* @param fltgrp FleetGroup to add.
|
||||||
|
* @return 0 on success.
|
||||||
|
*/
|
||||||
|
int system_addFleetGroup(StarSystem* sys, FleetGroup* fltgrp) {
|
||||||
|
int i;
|
||||||
|
SystemFleet fleet;
|
||||||
|
|
||||||
|
if(sys == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Add all the fleets. */
|
||||||
|
for(i = 0; i < fltgrp->nfleets; i++) {
|
||||||
|
fleet.fleet = fltgrp->fleets[i];
|
||||||
|
fleet.chance = fltgrp->chance[i];
|
||||||
|
if(system_addFleet(sys, &fleet))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes a fleetgroup from a star system.
|
||||||
|
* @param sys Star System to remove fleet from.
|
||||||
|
* @param fltgrp FleetGroup to remove.
|
||||||
|
* @return 0 on success.
|
||||||
|
*/
|
||||||
|
int system_rmFleetGroup(StarSystem* sys, FleetGroup* fltgrp) {
|
||||||
|
int i;
|
||||||
|
SystemFleet fleet;
|
||||||
|
|
||||||
|
if(sys == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Add all the fleets. */
|
||||||
|
for(i = 0; i < fltgrp->nfleets; i++) {
|
||||||
|
fleet.fleet = fltgrp->fleets[i];
|
||||||
|
fleet.chance = fltgrp->chance[i];
|
||||||
|
if(system_rmFleet(sys, &fleet))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse node 'parent' which should be the node of a system. */
|
/* Parse node 'parent' which should be the node of a system. */
|
||||||
/* Return the StarSystem fully loaded. */
|
/* Return the StarSystem fully loaded. */
|
||||||
static StarSystem* system_parse(StarSystem* sys, const xmlNodePtr parent) {
|
static StarSystem* system_parse(StarSystem* sys, const xmlNodePtr parent) {
|
||||||
Planet* planet;
|
Planet* planet;
|
||||||
SystemFleet fleet;
|
SystemFleet fleet;
|
||||||
|
Fleet* flt;
|
||||||
|
FleetGroup* fltgrp;
|
||||||
char* ptrc;
|
char* ptrc;
|
||||||
xmlNodePtr cur, node;
|
xmlNodePtr cur, node;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
@ -1061,21 +1111,36 @@ static StarSystem* system_parse(StarSystem* sys, const xmlNodePtr parent) {
|
|||||||
cur = node->children;
|
cur = node->children;
|
||||||
do {
|
do {
|
||||||
if(xml_isNode(cur, "fleet")) {
|
if(xml_isNode(cur, "fleet")) {
|
||||||
memset(&fleet, 0, sizeof(SystemFleet));
|
/* Load the fleet. */
|
||||||
|
flt = fleet_get(xml_get(cur));
|
||||||
|
if(flt != NULL) {
|
||||||
|
/* Get the fleet. */
|
||||||
|
fleet.fleet = flt;
|
||||||
|
|
||||||
fleet.fleet = fleet_get(xml_get(cur));
|
/* Get the chance. */
|
||||||
if(fleet.fleet == NULL)
|
xmlr_attr(cur, "chance", ptrc); /* Mallocs ptrc */
|
||||||
WARN("Fleet %s for Star System %s not found", xml_get(cur), sys->name);
|
fleet.chance = (ptrc == NULL) ? 0 : atoi(ptrc);
|
||||||
|
|
||||||
xmlr_attr(cur, "chance", ptrc); /* mallocs ptrc. */
|
|
||||||
if(ptrc == NULL) fleet.chance = 0; /* Gives warning. */
|
|
||||||
else fleet.chance = atoi(ptrc);
|
|
||||||
if(fleet.chance == 0)
|
if(fleet.chance == 0)
|
||||||
WARN("Fleet %s for Star System %s has 0%% chance to appear",
|
WARN("Fleet '%s' for Star System '%s' has 0%% chance to appear",
|
||||||
fleet.fleet->name, sys->name);
|
fleet.fleet->name, sys->name);
|
||||||
if(ptrc) free(ptrc); /* Free the ptrc. */
|
|
||||||
|
|
||||||
|
if(ptrc)
|
||||||
|
free(ptrc); /* Free the ptrc */
|
||||||
|
|
||||||
|
/* Add the fleet. */
|
||||||
system_addFleet(sys, &fleet);
|
system_addFleet(sys, &fleet);
|
||||||
|
} else {
|
||||||
|
/* Try to load it as a FleetGroup. */
|
||||||
|
fltgrp = fleet_getGroup(xml_get(cur));
|
||||||
|
if(fltgrp == NULL) {
|
||||||
|
WARN("Fleet '%s' for Star System '%s' not found",
|
||||||
|
xml_get(cur), sys->name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the fleetgroup. */
|
||||||
|
system_addFleetGroup(sys, fltgrp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while(xml_nextNode(cur));
|
} while(xml_nextNode(cur));
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,8 @@ int system_addPlanet(StarSystem* sys, char* planetname);
|
|||||||
int system_rmPlanet(StarSystem* sys, char* planetname);
|
int system_rmPlanet(StarSystem* sys, char* planetname);
|
||||||
int system_addFleet(StarSystem* sys, SystemFleet* fleet);
|
int system_addFleet(StarSystem* sys, SystemFleet* fleet);
|
||||||
int system_rmFleet(StarSystem* sys, SystemFleet* fleet);
|
int system_rmFleet(StarSystem* sys, SystemFleet* fleet);
|
||||||
|
int system_addFleetGroup(StarSystem* sys, FleetGroup* fltgrp);
|
||||||
|
int system_rmFleetGroup(StarSystem* sys, FleetGroup* fltgrp);
|
||||||
|
|
||||||
/* Render. */
|
/* Render. */
|
||||||
void space_render(const double dt);
|
void space_render(const double dt);
|
||||||
|
Loading…
Reference in New Issue
Block a user