[Change] Randomized planet landing a little.

This commit is contained in:
Allanis 2013-03-10 18:19:16 +00:00
parent 5b4adca3bb
commit 669e14ee13

View File

@ -379,7 +379,11 @@ static int ai_pushtask(lua_State* L) {
// Only pointer valid is Vec2* in Lua. // Only pointer valid is Vec2* in Lua.
t->dtype = TYPE_PTR; t->dtype = TYPE_PTR;
t->dat.target = MALLOC_L(Vec2); t->dat.target = MALLOC_L(Vec2);
vectcpy(t->dat.target, (Vec2*)lua_topointer(L,3)); // No idea why vectcpy doesn't work here..
((Vec2*)t->dat.target)->x = ((Vec2*)lua_topointer(L,3))->x;
((Vec2*)t->dat.target)->y = ((Vec2*)lua_topointer(L,3))->y;
((Vec2*)t->dat.target)->mod = ((Vec2*)lua_topointer(L,3))->mod;
((Vec2*)t->dat.target)->angle = ((Vec2*)lua_topointer(L,3))->angle;
} else } else
t->dtype = TYPE_NULL; t->dtype = TYPE_NULL;
} }
@ -671,6 +675,7 @@ static int ai_getrndplanet(lua_State* L) {
Planet** planets; Planet** planets;
int nplanets, i; int nplanets, i;
Vec2 v;
planets = malloc(sizeof(Planet*) * cur_system->nplanets); planets = malloc(sizeof(Planet*) * cur_system->nplanets);
for(nplanets = 0, i = 0; i < cur_system->nplanets; i++) for(nplanets = 0, i = 0; i < cur_system->nplanets; i++)
@ -685,7 +690,10 @@ static int ai_getrndplanet(lua_State* L) {
// We can actually get a random planet now. // We can actually get a random planet now.
i = RNG(0,nplanets-1); i = RNG(0,nplanets-1);
lua_pushlightuserdata(L, &planets[i]->pos); vectcpy(&v, &planets[i]->pos);
vect_cadd(&v, RNG(0, planets[i]->gfx_space->sw)-planets[i]->gfx_space->sw/2.,
RNG(0, planets[i]->gfx_space->sh)-planets[i]->gfx_space->sh/2.);
lua_pushlightuserdata(L, &v);
free(planets); free(planets);
return 1; return 1;
} }