[Add] Adding spawns. It's uh.. Not working? I'll work on it some more later..

This commit is contained in:
Allanis 2013-02-28 02:36:45 +00:00
parent 1b77a4276b
commit 6b1228a4af
5 changed files with 76 additions and 23 deletions

View File

@ -686,7 +686,7 @@ static int ai_hyperspace(lua_State* L) {
int dist;
dist = space_hyperspace(cur_pilot);
if(dist == 0) return 0;
if(dist == 0.) return 0;
lua_pushnumber(L,dist);
return 1;

View File

@ -249,6 +249,7 @@ static void update_space(void) {
pause_delay((unsigned int)dt*1000.);
return;
}
space_update(dt);
weapons_update(dt);
spfx_update(dt);
pilots_update(dt);

View File

@ -11,6 +11,8 @@ int paused = 0; // Are we paused.
// From pilot.c
extern Pilot** pilot_stack;
extern int pilots;
// From space.c
extern unsigned int spawn_timer;
// From main.c
extern unsigned int gtime;
@ -25,6 +27,7 @@ void pause(void) {
pilots_pause();
weapons_pause();
spfx_pause();
spawn_timer -= SDL_GetTicks();
paused = 1; // We should unpause it.
}
@ -35,6 +38,7 @@ void unpause(void) {
pilots_unpause();
weapons_unpause();
spfx_unpause();
spawn_timer += SDL_GetTicks();
paused = 0;
}

View File

@ -36,6 +36,7 @@
#define FLAG_ASTEROIDSSET (1<<2)
#define FLAG_INTEFERENCESET (1<<3)
// Star system stack and co.
StarSystem* systems = NULL; // Star system stack.
static int nsystems = 0; // Number of star systems.
static int nplanets = 0; // Total number of loaded planets - A little silly.
@ -45,6 +46,10 @@ StarSystem* cur_system = NULL; // Current star system.
char* stardate = "Stardate";
unsigned int date = 0; // time since epoch.
// Fleet spawn rate.
unsigned int spawn_timer = 0; // Controls spawn rate.
// Star stack and co.
#define STAR_BUF 100 // Area to leave around screen, more = less repitition.
typedef struct Star_ {
double x, y; // Position. It is simpler ligher to use two doubles than the physics.
@ -57,6 +62,7 @@ static int mstars = 0; // Memory stars are taking.
// Intern
static Planet* planet_get(const char* name);
static void space_addFleet(Fleet* fleet);
static StarSystem* system_parse(const xmlNodePtr parent);
static void system_parseJumps(const xmlNodePtr parent);
static PlanetClass planetclass_get(const char a);
@ -176,10 +182,64 @@ int space_hyperspace(Pilot* p) {
return 0;
}
// Basically used for spawning fleets.
void space_update(const double dt) {
unsigned int t;
int i, j, f;
(void)dt; // Don't need it right now.
if(cur_system->nfleets == 0)
// Please stop checking that there are no fleets.
spawn_timer = t + 300000;
if(spawn_timer < t) {
// Time to possibly spawn.
// Spawn chance is based on overall percentage.
f = RNG(0, 100*cur_system->nfleets);
j = 0;
for(i = 0; i < cur_system->nfleets; i++) {
j += cur_system->fleets[i].chance;
if(f < j) {
// Add one fleet.
space_addFleet(cur_system->fleets[i].fleet);
break;
}
}
spawn_timer = t + 60000./(float)cur_system->nfleets;
}
}
// Crate a fleet.
static void space_addFleet(Fleet* fleet) {
int i;
Vec2 v, vn;
// Simulate them coming from hyperspace.
vect_pset(&v, 2*RNG(MIN_HYPERSPACE_DIST/2, MIN_HYPERSPACE_DIST),
RNG(0, 360)*M_PI/180.);
vectnull(&vn);
for(i = 0; i < fleet->npilots; i++)
if(RNG(0, 100) <= fleet->pilots[i].chance) {
vect_cadd(&v, RNG(75, 150) * (RNG(0,1) ? 1 : -1),
RNG(75, 150) * (RNG(0,1) ? 1 : -1));
pilot_create(fleet->pilots[i].ship,
fleet->pilots[i].name,
fleet->faction,
fleet->ai,
vect_angle(&v, &vn),
&v,
NULL,
0);
}
}
// Init the system.
void space_init(const char* sysname) {
int i, j;
Vec2 v, vn;
int i;
// Cleanup some stuff.
player_clear(); // Clears targets.
@ -209,27 +269,12 @@ void space_init(const char* sysname) {
}
}
// Set up fleets -> pilots.
vectnull(&vn);
for(i = 0; i < cur_system->nfleets; i++)
if(RNG(0,100) <= cur_system->fleets[i].chance) {// Check fleet.
// Simulate ships coming from hyperspace.
vect_pset(&v, 2*RNG(MIN_HYPERSPACE_DIST/2, MIN_HYPERSPACE_DIST), RNG(0, 360)*M_PI/180.);
if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) // Fleet check (50% chance).
space_addFleet(cur_system->fleets[i].fleet);
for(j = 0; j < cur_system->fleets[i].fleet->npilots; j++)
if(RNG(0,100) <= cur_system->fleets[i].fleet->pilots[j].chance) {
// Other ships in the fleet should start split up.
vect_cadd(&v, RNG(75, 150) * (RNG(0,1) ? 1 : -1),
RNG(75, 150) * (RNG(0,1) ? 1 : -1));
pilot_create(cur_system->fleets[i].fleet->pilots[j].ship,
cur_system->fleets[i].fleet->pilots[j].name,
cur_system->fleets[i].fleet->faction,
cur_system->fleets[i].fleet->ai,
vect_angle(&v,&vn),
&v,
NULL,
0);
}
}
// Start the spawn timer.
spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1);
}
// Load the planets of name 'name'.

View File

@ -88,6 +88,9 @@ void space_exit(void);
void space_render(double dt);
void planets_render(void);
// Update.
void space_update(const double dt);
// Misc.
int space_canHyperspace(Pilot* p);
int space_hyperspace(Pilot* p);