[Add] Pilots sort of start as landed.

This commit is contained in:
Allanis 2013-10-09 22:16:28 +01:00
parent c2d4f39a72
commit 8feb19e20c

View File

@ -72,7 +72,7 @@ static int mstars = 0; /* Memory stars are taking. */
/* Intern. */ /* Intern. */
static Planet* planet_pull(const char* name); static Planet* planet_pull(const char* name);
static void space_renderStars(const double dt); static void space_renderStars(const double dt);
static void space_addFleet(Fleet* fleet); static void space_addFleet(Fleet* fleet, int init);
static StarSystem* system_parse(const xmlNodePtr parent); static StarSystem* system_parse(const xmlNodePtr parent);
static void system_parseJumps(const xmlNodePtr parent); static void system_parseJumps(const xmlNodePtr parent);
static PlanetClass planetclass_get(const char a); static PlanetClass planetclass_get(const char a);
@ -390,7 +390,7 @@ void space_update(const double dt) {
j += cur_system->fleets[i].chance; j += cur_system->fleets[i].chance;
if(f < j) { if(f < j) {
/* Add one fleet. */ /* Add one fleet. */
space_addFleet(cur_system->fleets[i].fleet); space_addFleet(cur_system->fleets[i].fleet, 0);
break; break;
} }
} }
@ -398,26 +398,71 @@ void space_update(const double dt) {
} }
} }
/* Crate a fleet. */ /**
static void space_addFleet(Fleet* fleet) { * @fn static void space_addFleet(Fleet* fleet)
*
* @brief Create a fleet.
* @param fleet Fleet to add to the system.
* @param init Is being run during the space initialization.
*/
static void space_addFleet(Fleet* fleet, int init) {
FleetPilot* plt; FleetPilot* plt;
int i; Planet* planet;
int i, c;
double a; double a;
Vec2 vv, vp, vn; Vec2 vv, vp, vn;
/* Simulate them coming from hyperspace. */ /* Simulate them coming from hyperspace. */
vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*3), vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*3),
RNG(0, 360)*M_PI/180.); RNG(0, 360)*M_PI/180.);
/* Needed to determine angle. */
vectnull(&vn); vectnull(&vn);
/* c will determin how to create the fleet. */
if(init == 1)
c = RNG(0, 1);
else c = 0;
/* Simulate they came from hyperspace. */
if(c == 0) {
vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*3.),
RNG(0,360)*M_PI/180.);
}
/* Starting out landed. */
else if(c == 1) {
/* Get friendly planet to land on. */
planet = NULL;
for(i = 0; i < cur_system->nplanets; i++)
if(planet_hasService(&cur_system->planets[i], PLANET_SERVICE_BASIC) &&
!areEnemies(fleet->faction, cur_system->planets[i].faction)) {
planet = &cur_system->planets[i];
break;
}
/* No suitable planet found. */
if(planet == NULL) {
vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*3.),
RNG(0, 360)*M_PI/180.);
c = 0;
} else /* Set position to be planet position. */
vectcpy(&vp, &planet->pos);
}
for(i = 0; i < fleet->npilots; i++) for(i = 0; i < fleet->npilots; i++)
plt = &fleet->pilots[i]; plt = &fleet->pilots[i];
if(RNG(0, 100) <= plt->chance) { if(RNG(0, 100) <= plt->chance) {
vect_cadd(&vp, RNG(75, 150) * (RNG(0,1) ? 1 : -1), vect_cadd(&vp, RNG(75, 150) * (RNG(0,1) ? 1 : -1),
RNG(75, 150) * (RNG(0,1) ? 1 : -1)); RNG(75, 150) * (RNG(0,1) ? 1 : -1));
a = vect_angle(&vp, &vn); a = vect_angle(&vp, &vn);
vect_pset(&vv, plt->ship->speed * 2., a);
/* Entering via hyperspace. */
if(c == 0)
vect_pset(&vv, plt->ship->speed * 3., a);
/* Starting out landed. */
else if(c == 1)
vectnull(&vv);
pilot_create(plt->ship, pilot_create(plt->ship,
plt->name, plt->name,
@ -473,7 +518,7 @@ void space_init(const char* sysname) {
/* Set up fleets -> pilots. */ /* Set up fleets -> pilots. */
for(i = 0; i < cur_system->nfleets; i++) for(i = 0; i < cur_system->nfleets; i++)
if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) /* Fleet check (50% chance). */ if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) /* Fleet check (50% chance). */
space_addFleet(cur_system->fleets[i].fleet); space_addFleet(cur_system->fleets[i].fleet, 1);
/* Start the spawn timer. */ /* Start the spawn timer. */
spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1); spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1);