[Add] Adding spawns. It's uh.. Not working? I'll work on it some more later..
This commit is contained in:
parent
1b77a4276b
commit
6b1228a4af
2
src/ai.c
2
src/ai.c
@ -686,7 +686,7 @@ static int ai_hyperspace(lua_State* L) {
|
|||||||
int dist;
|
int dist;
|
||||||
|
|
||||||
dist = space_hyperspace(cur_pilot);
|
dist = space_hyperspace(cur_pilot);
|
||||||
if(dist == 0) return 0;
|
if(dist == 0.) return 0;
|
||||||
|
|
||||||
lua_pushnumber(L,dist);
|
lua_pushnumber(L,dist);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -249,6 +249,7 @@ static void update_space(void) {
|
|||||||
pause_delay((unsigned int)dt*1000.);
|
pause_delay((unsigned int)dt*1000.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
space_update(dt);
|
||||||
weapons_update(dt);
|
weapons_update(dt);
|
||||||
spfx_update(dt);
|
spfx_update(dt);
|
||||||
pilots_update(dt);
|
pilots_update(dt);
|
||||||
|
@ -11,6 +11,8 @@ int paused = 0; // Are we paused.
|
|||||||
// From pilot.c
|
// From pilot.c
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
extern int pilots;
|
||||||
|
// From space.c
|
||||||
|
extern unsigned int spawn_timer;
|
||||||
// From main.c
|
// From main.c
|
||||||
extern unsigned int gtime;
|
extern unsigned int gtime;
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ void pause(void) {
|
|||||||
pilots_pause();
|
pilots_pause();
|
||||||
weapons_pause();
|
weapons_pause();
|
||||||
spfx_pause();
|
spfx_pause();
|
||||||
|
spawn_timer -= SDL_GetTicks();
|
||||||
|
|
||||||
paused = 1; // We should unpause it.
|
paused = 1; // We should unpause it.
|
||||||
}
|
}
|
||||||
@ -35,6 +38,7 @@ void unpause(void) {
|
|||||||
pilots_unpause();
|
pilots_unpause();
|
||||||
weapons_unpause();
|
weapons_unpause();
|
||||||
spfx_unpause();
|
spfx_unpause();
|
||||||
|
spawn_timer += SDL_GetTicks();
|
||||||
|
|
||||||
paused = 0;
|
paused = 0;
|
||||||
}
|
}
|
||||||
|
87
src/space.c
87
src/space.c
@ -36,6 +36,7 @@
|
|||||||
#define FLAG_ASTEROIDSSET (1<<2)
|
#define FLAG_ASTEROIDSSET (1<<2)
|
||||||
#define FLAG_INTEFERENCESET (1<<3)
|
#define FLAG_INTEFERENCESET (1<<3)
|
||||||
|
|
||||||
|
// Star system stack and co.
|
||||||
StarSystem* systems = NULL; // Star system stack.
|
StarSystem* systems = NULL; // Star system stack.
|
||||||
static int nsystems = 0; // Number of star systems.
|
static int nsystems = 0; // Number of star systems.
|
||||||
static int nplanets = 0; // Total number of loaded planets - A little silly.
|
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";
|
char* stardate = "Stardate";
|
||||||
unsigned int date = 0; // time since epoch.
|
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.
|
#define STAR_BUF 100 // Area to leave around screen, more = less repitition.
|
||||||
typedef struct Star_ {
|
typedef struct Star_ {
|
||||||
double x, y; // Position. It is simpler ligher to use two doubles than the physics.
|
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
|
// Intern
|
||||||
static Planet* planet_get(const char* name);
|
static Planet* planet_get(const char* name);
|
||||||
|
static void space_addFleet(Fleet* fleet);
|
||||||
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);
|
||||||
@ -176,10 +182,64 @@ int space_hyperspace(Pilot* p) {
|
|||||||
return 0;
|
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.
|
// Init the system.
|
||||||
void space_init(const char* sysname) {
|
void space_init(const char* sysname) {
|
||||||
int i, j;
|
int i;
|
||||||
Vec2 v, vn;
|
|
||||||
|
|
||||||
// Cleanup some stuff.
|
// Cleanup some stuff.
|
||||||
player_clear(); // Clears targets.
|
player_clear(); // Clears targets.
|
||||||
@ -209,27 +269,12 @@ void space_init(const char* sysname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set up fleets -> pilots.
|
// Set up fleets -> pilots.
|
||||||
vectnull(&vn);
|
|
||||||
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) {// Check fleet.
|
if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) // Fleet check (50% chance).
|
||||||
// Simulate ships coming from hyperspace.
|
space_addFleet(cur_system->fleets[i].fleet);
|
||||||
vect_pset(&v, 2*RNG(MIN_HYPERSPACE_DIST/2, MIN_HYPERSPACE_DIST), RNG(0, 360)*M_PI/180.);
|
|
||||||
|
|
||||||
for(j = 0; j < cur_system->fleets[i].fleet->npilots; j++)
|
// Start the spawn timer.
|
||||||
if(RNG(0,100) <= cur_system->fleets[i].fleet->pilots[j].chance) {
|
spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the planets of name 'name'.
|
// Load the planets of name 'name'.
|
||||||
|
@ -88,6 +88,9 @@ void space_exit(void);
|
|||||||
void space_render(double dt);
|
void space_render(double dt);
|
||||||
void planets_render(void);
|
void planets_render(void);
|
||||||
|
|
||||||
|
// Update.
|
||||||
|
void space_update(const double dt);
|
||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
int space_canHyperspace(Pilot* p);
|
int space_canHyperspace(Pilot* p);
|
||||||
int space_hyperspace(Pilot* p);
|
int space_hyperspace(Pilot* p);
|
||||||
|
Loading…
Reference in New Issue
Block a user