(svn r2891) Fix indentation

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
tron 19 years ago
parent f914a7eca6
commit a38d2f15b7

@ -34,7 +34,8 @@
#include "depot.h"
// This function is called after StartUp. It is the init of an AI
static void AiNew_State_FirstTime(Player *p) {
static void AiNew_State_FirstTime(Player *p)
{
// This assert is used to protect those function from misuse
// You have quickly a small mistake in the state-array
// With that, everything would go wrong. Finding that, is almost impossible
@ -65,6 +66,7 @@ static void AiNew_State_FirstTime(Player *p) {
p->ainew.state = AI_STATE_WAKE_UP;
}
// This function just waste some time
// It keeps it more real. The AI can build on such tempo no normal user
// can ever keep up with that. The competitor_speed already delays a bit
@ -72,7 +74,8 @@ static void AiNew_State_FirstTime(Player *p) {
//
// Let's say, we sleep between one and three days if the AI is put on Very Fast.
// This means that on Very Slow it will be between 16 and 48 days.. slow enough?
static void AiNew_State_Nothing(Player *p) {
static void AiNew_State_Nothing(Player *p)
{
assert(p->ainew.state == AI_STATE_NOTHING);
// If we are done idling, start over again
if (p->ainew.idle == 0) p->ainew.idle = RandomRange(DAY_TICKS * 2) + DAY_TICKS;
@ -83,12 +86,14 @@ static void AiNew_State_Nothing(Player *p) {
}
}
// This function picks out a task we are going to do.
// Currently supported:
// - Make new route
// - Check route
// - Build HQ
static void AiNew_State_WakeUp(Player *p) {
static void AiNew_State_WakeUp(Player *p)
{
int32 money;
int c;
assert(p->ainew.state == AI_STATE_WAKE_UP);
@ -108,7 +113,8 @@ static void AiNew_State_WakeUp(Player *p) {
// Let's pick an action!
if (p->ainew.action == AI_ACTION_NONE) {
c = Random() & 0xFF;
if (p->current_loan > 0 && p->old_economy[1].income > AI_MINIMUM_INCOME_FOR_LOAN &&
if (p->current_loan > 0 &&
p->old_economy[1].income > AI_MINIMUM_INCOME_FOR_LOAN &&
c < 10) {
p->ainew.action = AI_ACTION_REPAY_LOAN;
} else if (p->ainew.last_vehiclecheck_date + AI_DAYS_BETWEEN_VEHICLE_CHECKS < _date) {
@ -118,8 +124,10 @@ static void AiNew_State_WakeUp(Player *p) {
} else if (c < 100 && !_patches.ai_disable_veh_roadveh) {
// Do we have any spots for road-vehicles left open?
if (GetFreeUnitNumber(VEH_Road) <= _patches.max_roadveh) {
if (c < 85) p->ainew.action = AI_ACTION_TRUCK_ROUTE;
else p->ainew.action = AI_ACTION_BUS_ROUTE;
if (c < 85)
p->ainew.action = AI_ACTION_TRUCK_ROUTE;
else
p->ainew.action = AI_ACTION_BUS_ROUTE;
}
}/* else if (c < 200 && !_patches.ai_disable_veh_train) {
if (GetFreeUnitNumber(VEH_Train) <= _patches.max_trains) {
@ -136,18 +144,23 @@ static void AiNew_State_WakeUp(Player *p) {
}
if (_patches.ai_disable_veh_roadveh && (
p->ainew.action == AI_ACTION_BUS_ROUTE || p->ainew.action == AI_ACTION_TRUCK_ROUTE)) {
p->ainew.action == AI_ACTION_BUS_ROUTE ||
p->ainew.action == AI_ACTION_TRUCK_ROUTE
)) {
p->ainew.action = AI_ACTION_NONE;
return;
}
if (_patches.ai_disable_veh_roadveh && (
p->ainew.action == AI_ACTION_BUS_ROUTE || p->ainew.action == AI_ACTION_TRUCK_ROUTE)) {
p->ainew.action == AI_ACTION_BUS_ROUTE ||
p->ainew.action == AI_ACTION_TRUCK_ROUTE
)) {
p->ainew.action = AI_ACTION_NONE;
return;
}
if (p->ainew.action == AI_ACTION_REPAY_LOAN && money > AI_MINIMUM_LOAN_REPAY_MONEY) {
if (p->ainew.action == AI_ACTION_REPAY_LOAN &&
money > AI_MINIMUM_LOAN_REPAY_MONEY) {
// We start repaying some money..
p->ainew.state = AI_STATE_REPAY_MONEY;
return;
@ -160,7 +173,8 @@ static void AiNew_State_WakeUp(Player *p) {
// It is useless to start finding a route if we don't have enough money
// to build the route anyway..
if (p->ainew.action == AI_ACTION_BUS_ROUTE && money > AI_MINIMUM_BUS_ROUTE_MONEY) {
if (p->ainew.action == AI_ACTION_BUS_ROUTE &&
money > AI_MINIMUM_BUS_ROUTE_MONEY) {
if (GetFreeUnitNumber(VEH_Road) > _patches.max_roadveh) {
p->ainew.action = AI_ACTION_NONE;
return;
@ -170,7 +184,8 @@ static void AiNew_State_WakeUp(Player *p) {
p->ainew.tbt = AI_BUS; // Bus-route
return;
}
if (p->ainew.action == AI_ACTION_TRUCK_ROUTE && money > AI_MINIMUM_TRUCK_ROUTE_MONEY) {
if (p->ainew.action == AI_ACTION_TRUCK_ROUTE &&
money > AI_MINIMUM_TRUCK_ROUTE_MONEY) {
if (GetFreeUnitNumber(VEH_Road) > _patches.max_roadveh) {
p->ainew.action = AI_ACTION_NONE;
return;
@ -185,13 +200,17 @@ static void AiNew_State_WakeUp(Player *p) {
p->ainew.state = AI_STATE_NOTHING;
}
static void AiNew_State_ActionDone(Player *p) {
static void AiNew_State_ActionDone(Player *p)
{
p->ainew.action = AI_ACTION_NONE;
p->ainew.state = AI_STATE_NOTHING;
}
// Check if a city or industry is good enough to start a route there
static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) {
static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
{
if (type == AI_CITY) {
Town *t = GetTown(ic);
Station *st;
@ -318,8 +337,10 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) {
return true;
}
// This functions tries to locate a good route
static void AiNew_State_LocateRoute(Player *p) {
static void AiNew_State_LocateRoute(Player *p)
{
assert(p->ainew.state == AI_STATE_LOCATE_ROUTE);
// For now, we only support PASSENGERS, CITY and BUSSES
@ -511,9 +532,11 @@ static void AiNew_State_LocateRoute(Player *p) {
p->ainew.last_id = p->ainew.temp;
}
// Check if there are not more than a certain amount of vehicles pointed to a certain
// station. This to prevent 10 busses going to one station, which gives... problems ;)
static bool AiNew_CheckVehicleStation(Player *p, Station *st) {
static bool AiNew_CheckVehicleStation(Player *p, Station *st)
{
int count = 0;
Vehicle *v;
@ -536,7 +559,8 @@ static bool AiNew_CheckVehicleStation(Player *p, Station *st) {
}
// This function finds a good spot for a station
static void AiNew_State_FindStation(Player *p) {
static void AiNew_State_FindStation(Player *p)
{
TileIndex tile;
Station *st;
int i, count = 0;
@ -688,8 +712,10 @@ static void AiNew_State_FindStation(Player *p) {
}
}
// We try to find a path between 2 points
static void AiNew_State_FindPath(Player *p) {
static void AiNew_State_FindPath(Player *p)
{
int r;
assert(p->ainew.state == AI_STATE_FIND_PATH);
@ -746,8 +772,10 @@ static void AiNew_State_FindPath(Player *p) {
// In any other case, we are still busy finding the route...
}
// This function tries to locate a good place for a depot!
static void AiNew_State_FindDepot(Player *p) {
static void AiNew_State_FindDepot(Player *p)
{
// To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there..
// Simple, easy, works!
// To make the depot stand in the middle of the route, we start from the center..
@ -802,7 +830,8 @@ static void AiNew_State_FindDepot(Player *p) {
// And because it is not build yet, we can't see it on the tile..
// So check the surrounding tiles :)
if (tile + TileOffsByDir(j) == p->ainew.path_info.route[i-1] ||
tile + TileOffsByDir(j) == p->ainew.path_info.route[i+1]) continue;
tile + TileOffsByDir(j) == p->ainew.path_info.route[i+1])
continue;
// Not around a bridge?
if (p->ainew.path_info.route_extra[i] != 0) continue;
if (IsTileType(tile, MP_TUNNELBRIDGE)) continue;
@ -836,7 +865,8 @@ static void AiNew_State_FindDepot(Player *p) {
// It works pretty simple: get the length, see how much we move around
// and hussle that, and you know how many vehicles there are needed.
// It returns the cost for the vehicles
static int AiNew_HowManyVehicles(Player *p) {
static int AiNew_HowManyVehicles(Player *p)
{
if (p->ainew.tbt == AI_BUS) {
// For bus-routes we look at the time before we are back in the station
int i, length, tiles_a_day;
@ -886,7 +916,8 @@ static int AiNew_HowManyVehicles(Player *p) {
// - If the route went okay
// - Calculates the amount of money needed to build the route
// - Calculates how much vehicles needed for the route
static void AiNew_State_VerifyRoute(Player *p) {
static void AiNew_State_VerifyRoute(Player *p)
{
int res, i;
assert(p->ainew.state == AI_STATE_VERIFY_ROUTE);
@ -942,15 +973,16 @@ static void AiNew_State_VerifyRoute(Player *p) {
DEBUG(ai,1)("[AiNew] The route is set and buildable.. going to build it!");
}
// Build the stations
static void AiNew_State_BuildStation(Player *p) {
static void AiNew_State_BuildStation(Player *p)
{
int res = 0;
assert(p->ainew.state == AI_STATE_BUILD_STATION);
if (p->ainew.temp == 0) {
if (!IsTileType(p->ainew.from_tile, MP_STATION))
res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.from_tile, 0, 0, p->ainew.from_direction, DC_EXEC);
}
else {
} else {
if (!IsTileType(p->ainew.to_tile, MP_STATION))
res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.to_tile, 0, 0, p->ainew.to_direction, DC_EXEC);
p->ainew.state = AI_STATE_BUILD_PATH;
@ -966,8 +998,10 @@ static void AiNew_State_BuildStation(Player *p) {
p->ainew.temp++;
}
// Build the path
static void AiNew_State_BuildPath(Player *p) {
static void AiNew_State_BuildPath(Player *p)
{
assert(p->ainew.state == AI_STATE_BUILD_PATH);
// p->ainew.temp is set to -1 when this function is called for the first time
if (p->ainew.temp == -1) {
@ -1059,8 +1093,10 @@ static void AiNew_State_BuildPath(Player *p) {
}
}
// Builds the depot
static void AiNew_State_BuildDepot(Player *p) {
static void AiNew_State_BuildDepot(Player *p)
{
int res = 0;
assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
@ -1092,8 +1128,10 @@ static void AiNew_State_BuildDepot(Player *p) {
p->ainew.veh_main_id = (VehicleID)-1;
}
// Build vehicles
static void AiNew_State_BuildVehicle(Player *p) {
static void AiNew_State_BuildVehicle(Player *p)
{
int res;
assert(p->ainew.state == AI_STATE_BUILD_VEHICLE);
@ -1130,8 +1168,10 @@ static void AiNew_State_BuildVehicle(Player *p) {
p->ainew.state = AI_STATE_GIVE_ORDERS;
}
// Put the stations in the order list
static void AiNew_State_GiveOrders(Player *p) {
static void AiNew_State_GiveOrders(Player *p)
{
int idx;
Order order;
@ -1180,8 +1220,10 @@ static void AiNew_State_GiveOrders(Player *p) {
p->ainew.state = AI_STATE_START_VEHICLE;
}
// Start the vehicle
static void AiNew_State_StartVehicle(Player *p) {
static void AiNew_State_StartVehicle(Player *p)
{
assert(p->ainew.state == AI_STATE_START_VEHICLE);
// 3, 2, 1... go! (give START_STOP command ;))
@ -1190,15 +1232,19 @@ static void AiNew_State_StartVehicle(Player *p) {
p->ainew.state = AI_STATE_BUILD_VEHICLE;
}
// Repays money
static void AiNew_State_RepayMoney(Player *p) {
static void AiNew_State_RepayMoney(Player *p)
{
int i;
for (i=0;i<AI_LOAN_REPAY;i++)
DoCommandByTile(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
p->ainew.state = AI_STATE_ACTION_DONE;
}
static void AiNew_CheckVehicle(Player *p, Vehicle *v) {
static void AiNew_CheckVehicle(Player *p, Vehicle *v)
{
// When a vehicle is under the 6 months, we don't check for anything
if (v->age < 180) return;
@ -1232,14 +1278,16 @@ static void AiNew_CheckVehicle(Player *p, Vehicle *v) {
if (v->type == VEH_Road)
ret = DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT);
// This means we can not find a depot :s
// if (CmdFailed(ret))
// if (CmdFailed(ret))
}
}
}
}
// Checks all vehicles if they are still valid and make money and stuff
static void AiNew_State_CheckAllVehicles(Player *p) {
static void AiNew_State_CheckAllVehicles(Player *p)
{
Vehicle *v;
FOR_ALL_VEHICLES(v) {
@ -1254,6 +1302,7 @@ static void AiNew_State_CheckAllVehicles(Player *p) {
p->ainew.state = AI_STATE_ACTION_DONE;
}
// Using the technique simular to the original AI
// Keeps things logical
// It really should be in the same order as the AI_STATE's are!
@ -1279,15 +1328,17 @@ static AiNew_StateFunction* const _ainew_state[] = {
NULL,
};
static void AiNew_OnTick(Player *p) {
static void AiNew_OnTick(Player *p)
{
if (_ainew_state[p->ainew.state] != NULL)
_ainew_state[p->ainew.state](p);
}
void AiNewDoGameLoop(Player *p) {
void AiNewDoGameLoop(Player *p)
{
// If it is a human player, it is not an AI, so bubye!
if (IS_HUMAN_PLAYER(_current_player))
return;
if (IS_HUMAN_PLAYER(_current_player)) return;
if (p->ainew.state == AI_STATE_STARTUP) {
// The AI just got alive!
@ -1306,15 +1357,19 @@ void AiNewDoGameLoop(Player *p) {
case 0: // Very slow
if (!(p->ainew.tick&8)) return;
break;
case 1: // Slow
if (!(p->ainew.tick&4)) return;
break;
case 2:
if (!(p->ainew.tick&2)) return;
break;
case 3:
if (!(p->ainew.tick&1)) return;
break;
case 4: // Very fast
default: // Cool, a new speed setting.. ;) VERY fast ;)
break;

Loading…
Cancel
Save