diff --git a/src/ai.c b/src/ai.c index bc03a08..81ddc21 100644 --- a/src/ai.c +++ b/src/ai.c @@ -379,7 +379,11 @@ static int ai_pushtask(lua_State* L) { // Only pointer valid is Vec2* in Lua. t->dtype = TYPE_PTR; 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 t->dtype = TYPE_NULL; } @@ -671,6 +675,7 @@ static int ai_getrndplanet(lua_State* L) { Planet** planets; int nplanets, i; + Vec2 v; planets = malloc(sizeof(Planet*) * cur_system->nplanets); 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. 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); return 1; }