src/ai/api/ai_object.cpp
branchnoai
changeset 10977 6c1a6657c7db
parent 10668 495789401303
child 10978 13fd0364b2c6
equal deleted inserted replaced
10976:5cbf268679ae 10977:6c1a6657c7db
     6 #include "ai_log.hpp"
     6 #include "ai_log.hpp"
     7 #include "ai_error.hpp"
     7 #include "ai_error.hpp"
     8 #include "table/strings.h"
     8 #include "table/strings.h"
     9 #include "../../openttd.h"
     9 #include "../../openttd.h"
    10 #include "../../command_func.h"
    10 #include "../../command_func.h"
       
    11 #include "../../map_func.h"
    11 #include "../../network/network.h"
    12 #include "../../network/network.h"
    12 #include "../../player_func.h"
    13 #include "../../player_func.h"
    13 #include "../../signs_func.h"
    14 #include "../../signs_func.h"
       
    15 #include "../../tunnelbridge.h"
    14 #include "../../vehicle_func.h"
    16 #include "../../vehicle_func.h"
    15 #include "../ai.h"
    17 #include "../ai.h"
    16 #include "../ai_threads.h"
    18 #include "../ai_threads.h"
    17 
    19 
    18 struct AIObject::AIDoCommandStruct {
    20 struct AIObject::AIDoCommandStruct {
    22 	CommandCost costs;
    24 	CommandCost costs;
    23 	uint last_error;
    25 	uint last_error;
    24 	bool last_command_res;
    26 	bool last_command_res;
    25 	VehicleID new_vehicle_id;
    27 	VehicleID new_vehicle_id;
    26 	SignID new_sign_id;
    28 	SignID new_sign_id;
       
    29 	TileIndex new_tunnel_endtile;
    27 	RoadType road_type;
    30 	RoadType road_type;
    28 	void *event_data;
    31 	void *event_data;
    29 	void *log_data;
    32 	void *log_data;
    30 };
    33 };
    31 
    34 
   117 }
   120 }
   118 
   121 
   119 SignID AIObject::GetNewSignID()
   122 SignID AIObject::GetNewSignID()
   120 {
   123 {
   121 	return GetDoCommandStruct(_current_player)->new_sign_id;
   124 	return GetDoCommandStruct(_current_player)->new_sign_id;
       
   125 }
       
   126 
       
   127 void AIObject::SetNewTunnelEndtile(TileIndex tile)
       
   128 {
       
   129 	GetDoCommandStruct(_current_player)->new_tunnel_endtile = tile;
       
   130 }
       
   131 
       
   132 TileIndex AIObject::GetNewTunnelEndtile()
       
   133 {
       
   134 	return GetDoCommandStruct(_current_player)->new_tunnel_endtile;
   122 }
   135 }
   123 
   136 
   124 void *&AIObject::GetEventPointer()
   137 void *&AIObject::GetEventPointer()
   125 {
   138 {
   126 	return GetDoCommandStruct(_current_player)->event_data;
   139 	return GetDoCommandStruct(_current_player)->event_data;
   216 		/* For SinglePlayer we execute the command immediatly */
   229 		/* For SinglePlayer we execute the command immediatly */
   217 		::DoCommandP(tile, p1, p2, NULL, procc);
   230 		::DoCommandP(tile, p1, p2, NULL, procc);
   218 		/* Store some values inside the AIObject static memory */
   231 		/* Store some values inside the AIObject static memory */
   219 		SetNewVehicleID(_new_vehicle_id);
   232 		SetNewVehicleID(_new_vehicle_id);
   220 		SetNewSignID(_new_sign_id);
   233 		SetNewSignID(_new_sign_id);
       
   234 		SetNewTunnelEndtile(_build_tunnel_endtile);
   221 
   235 
   222 		/* Suspend the AI player for 1 tick, so it simulates MultiPlayer */
   236 		/* Suspend the AI player for 1 tick, so it simulates MultiPlayer */
   223 		::AI_SuspendPlayer(_current_player, GetDoCommandDelay());
   237 		::AI_SuspendPlayer(_current_player, GetDoCommandDelay());
   224 	}
   238 	}
   225 
   239