From 5e68d640855db3e0f3a5c3a9c41e5d1a791d3e13 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 22 Mar 2013 18:44:29 +0000 Subject: [PATCH] [Fix] Uninitailized code error. --- src/ai.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ai.c b/src/ai.c index d8b250a..7db97a1 100644 --- a/src/ai.c +++ b/src/ai.c @@ -331,9 +331,10 @@ void ai_think(Pilot* pilot) { L = cur_pilot->ai->L; // Set the AI profile to the current pilot's. // Clean up some variables. - pilot_acc = pilot_turn = 0.; - pilot_flags = 0; - pilot_target = 0; + pilot_acc = 0.; + pilot_turn = 0.; + pilot_flags = 0; + pilot_target = 0; // Control function if pilot is idle or tick is up. if((cur_pilot->tcontrol < SDL_GetTicks()) || (cur_pilot->task == NULL)) { @@ -341,7 +342,7 @@ void ai_think(Pilot* pilot) { lua_getglobal(L, "control_rate"); cur_pilot->tcontrol = SDL_GetTicks() + 1000*(int)lua_tonumber(L, -1); } - if(cur_pilot->task != NULL) + if(cur_pilot->task) // Pilot has a currently running task. ai_run(cur_pilot->task->name); @@ -535,8 +536,11 @@ static int ai_pshield(lua_State* L) { // Get the distance from the pointer. static int ai_getdistance(lua_State* L) { + Vec2* vect; + MIN_ARGS(1); - Vec2* vect = (Vec2*)lua_topointer(L,1); + vect = (lua_islightuserdata(L,1)) ? + (Vec2*)lua_topointer(L,1) : NULL; lua_pushnumber(L, vect_dist(vect, &cur_pilot->solid->pos)); return 1; } @@ -672,16 +676,16 @@ static int ai_face(lua_State* L) { vect_cset(&sv, VX(cur_pilot->solid->pos) + FACE_WVEL*VX(cur_pilot->solid->vel), VY(cur_pilot->solid->pos) + FACE_WVEL*VY(cur_pilot->solid->vel)); - if(v != NULL) - // Target is static. - diff = angle_diff(cur_pilot->solid->dir, - (n==-1) ? VANGLE(cur_pilot->solid->pos) : - vect_angle(&cur_pilot->solid->pos, v)); - else + if(v == NULL) // Target is dynamic. diff = angle_diff(cur_pilot->solid->dir, (n==-1) ? VANGLE(sv) : vect_angle(&sv, &tv)); + else + // Target is static. + diff = angle_diff(cur_pilot->solid->dir, + (n==-1) ? VANGLE(cur_pilot->solid->pos) : + vect_angle(&cur_pilot->solid->pos, v)); pilot_turn = mod*diff;