70 SignID AIObject::GetNewSignID() |
70 SignID AIObject::GetNewSignID() |
71 { |
71 { |
72 return AIObject::GetDoCommandStruct(_current_player)->new_sign_id; |
72 return AIObject::GetDoCommandStruct(_current_player)->new_sign_id; |
73 } |
73 } |
74 |
74 |
75 void **AIObject::GetEventPointer() |
75 void *&AIObject::GetEventPointer() |
76 { |
76 { |
77 return &AIObject::GetDoCommandStruct(_current_player)->event_data; |
77 return AIObject::GetDoCommandStruct(_current_player)->event_data; |
78 } |
78 } |
79 |
79 |
80 AIObject::AIDoCommandStruct *AIObject::GetDoCommandStruct(PlayerID player) |
80 AIObject::AIDoCommandStruct *AIObject::GetDoCommandStruct(PlayerID player) |
81 { |
81 { |
82 /* Storage for data on per-AI level */ |
82 /* Storage for data on per-AI level */ |
83 static AIObject::AIDoCommandStruct command_struct[MAX_PLAYERS]; |
83 static AIObject::AIDoCommandStruct command_struct[MAX_PLAYERS]; |
|
84 static bool initialized = false; |
|
85 |
|
86 /* Make sure all memory is NULL when we start */ |
|
87 if (!initialized) { |
|
88 initialized = true; |
|
89 memset(&command_struct, 0, sizeof(command_struct)); |
|
90 } |
84 |
91 |
85 return &command_struct[player]; |
92 return &command_struct[player]; |
86 } |
93 } |
87 |
94 |
88 void AIObject::ResetInternalPlayerData() |
95 void AIObject::ResetInternalPlayerData() |
89 { |
96 { |
90 AIObject::AIDoCommandStruct *command_struct = GetDoCommandStruct(_current_player); |
97 AIObject::AIDoCommandStruct *command_struct = GetDoCommandStruct(_current_player); |
91 command_struct->mode = NULL; |
98 command_struct->mode = NULL; |
92 command_struct->delay = 1; |
99 command_struct->delay = 1; |
93 command_struct->costs = CommandCost(); |
100 command_struct->costs = CommandCost(); |
|
101 if (command_struct->event_data != NULL) AIEventController::FreeEventPointer(); |
|
102 command_struct->event_data = NULL; |
94 } |
103 } |
95 |
104 |
96 bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc) |
105 bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc) |
97 { |
106 { |
98 uint32 flags = 0; |
107 uint32 flags = 0; |