[Fix] Improved sanity on some AI functions.
This commit is contained in:
		
							parent
							
								
									869a6d7dbe
								
							
						
					
					
						commit
						e10841653d
					
				| @ -6,12 +6,24 @@ control_rate = 2 | ||||
| -- Required "control" function. | ||||
| function control() | ||||
|  task = ai.taskname() | ||||
|  if task == "hyperspace" then | ||||
|  enemy = ai.getenemy() | ||||
| 
 | ||||
|  -- Runaway if enemy is near. | ||||
|  if task ~= "runaway" and enemy ~= nil and ai.dist(enemy) < 500 then | ||||
|    ai.poptask(); | ||||
|    ai.pushtask(0, "runaway", enemy) | ||||
| 
 | ||||
|  -- Enter hyperspace if possible. | ||||
|  elseif task == "hyperspace" then | ||||
|   ai.hyperspace() -- Try to go to hyperspace. | ||||
| 
 | ||||
|  -- Try to jump when far enough away. | ||||
|  elseif task == "runaway" then | ||||
|   if ai.dist(ai.pos(ai.targetid())) > 300 then | ||||
|   if ai.dist(ai.pos(ai.targetid())) > 400 then | ||||
|    ai.hyperspace() | ||||
|   end | ||||
| 
 | ||||
|  -- Find something to do. | ||||
|  elseif task == "none" then | ||||
|     planet = ai.landplanet() | ||||
|   -- Planet must exist. | ||||
| @ -80,7 +92,7 @@ function stop() | ||||
|   if ai.isstopped() then | ||||
|   ai.stop() | ||||
|     ai.poptask() | ||||
|     ai.settimer(0, rnd.int(8000, 15000)) | ||||
|     ai.settimer(0, rnd.int(8000, 15000)) -- We wait during a while. | ||||
|     ai.pushtask(0, "land") | ||||
|  else | ||||
|   ai.brake() | ||||
|  | ||||
							
								
								
									
										21
									
								
								src/ai.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/ai.c
									
									
									
									
									
								
							| @ -548,6 +548,7 @@ static int ai_pshield(lua_State* L) { | ||||
| static int ai_getdistance(lua_State* L) { | ||||
|   Vec2* vect; | ||||
|   Pilot* pilot; | ||||
|   unsigned int n; | ||||
| 
 | ||||
|   LLUA_MIN_ARGS(1); | ||||
| 
 | ||||
| @ -557,13 +558,16 @@ static int ai_getdistance(lua_State* L) { | ||||
| 
 | ||||
|   /* Pilot id as parameter. */ | ||||
|   else if(lua_isnumber(L, 1)) { | ||||
|     n = (unsigned int)lua_tonumber(L,1); | ||||
|     pilot = pilot_get((unsigned int) lua_tonumber(L, 1)); | ||||
|     vect = &pilot->solid->pos; | ||||
|   } else { | ||||
|     /* Wrong parameter. */ | ||||
|     LLUA_INVALID_PARAMETER(); | ||||
|     if(pilot == NULL) { | ||||
|       LLUA_DEBUG("Pilot '%d' not found in stack", n); | ||||
|       return 0; | ||||
|     } | ||||
|     vect = &pilot->solid->pos; | ||||
|   } else | ||||
|     /* Wrong parameter. */ | ||||
|     LLUA_INVALID_PARAMETER(); | ||||
| 
 | ||||
|   lua_pushnumber(L, vect_dist(vect, &cur_pilot->solid->pos)); | ||||
|   return 1; | ||||
| @ -917,7 +921,14 @@ static int ai_shoot(lua_State* L) { | ||||
| 
 | ||||
| /* Get the nearest enemy. */ | ||||
| static int ai_getenemy(lua_State* L) { | ||||
|   lua_pushnumber(L,pilot_getNearestEnemy(cur_pilot)); | ||||
|   unsigned int p; | ||||
| 
 | ||||
|   p = pilot_getNearestEnemy(cur_pilot); | ||||
| 
 | ||||
|   if(p == 0) /* No enemy found. */ | ||||
|     return 0; | ||||
| 
 | ||||
|   lua_pushnumber(L,p); | ||||
|   return 1; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis