src/ai/trolly/trolly.h
branchcustombridgeheads
changeset 5643 3778051e8095
parent 3946 c9e039a60682
child 6720 35756db7e577
equal deleted inserted replaced
5642:bfa6074e2833 5643:3778051e8095
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef AI_TROLLY_H
       
     4 #define AI_TROLLY_H
       
     5 
       
     6 #include "../../aystar.h"
       
     7 #include "../../player.h"
       
     8 
       
     9 /*
       
    10  * These defines can be altered to change the behavoir of the AI
       
    11  *
       
    12  * WARNING:
       
    13  *   This can also alter the AI in a negative way. I will never claim these settings
       
    14  *   are perfect, but don't change them if you don't know what the effect is.
       
    15  */
       
    16 
       
    17 // How many times it the H multiplied. The higher, the more it will go straight to the
       
    18 //   end point. The lower, how more it will find the route with the lowest cost.
       
    19 //   also: the lower, the longer it takes before route is calculated..
       
    20 #define AI_PATHFINDER_H_MULTIPLER 100
       
    21 
       
    22 // How many loops may AyStar do before it stops
       
    23 //   0 = infinite
       
    24 #define AI_PATHFINDER_LOOPS_PER_TICK 5
       
    25 
       
    26 // How long may the AI search for one route?
       
    27 //   0 = infinite
       
    28 // This number is the number of tiles tested.
       
    29 //  It takes (AI_PATHFINDER_MAX_SEARCH_NODES / AI_PATHFINDER_LOOPS_PER_TICK) ticks
       
    30 //  to get here.. with 5000 / 10 = 500. 500 / 74 (one day) = 8 days till it aborts
       
    31 //   (that is: if the AI is on VERY FAST! :p
       
    32 #define AI_PATHFINDER_MAX_SEARCH_NODES 5000
       
    33 
       
    34 // If you enable this, the AI is not allowed to make 90degree turns
       
    35 #define AI_PATHFINDER_NO_90DEGREES_TURN
       
    36 
       
    37 // Below are defines for the g-calculation
       
    38 
       
    39 // Standard penalty given to a tile
       
    40 #define AI_PATHFINDER_PENALTY 150
       
    41 // The penalty given to a tile that is going up
       
    42 #define AI_PATHFINDER_TILE_GOES_UP_PENALTY 450
       
    43 // The penalty given to a tile which would have to use fundation
       
    44 #define AI_PATHFINDER_FOUNDATION_PENALTY 100
       
    45 // Changing direction is a penalty, to prevent curved ways (with that: slow ways)
       
    46 #define AI_PATHFINDER_DIRECTION_CHANGE_PENALTY 200
       
    47 // Same penalty, only for when road already exists
       
    48 #define AI_PATHFINDER_DIRECTION_CHANGE_ON_EXISTING_ROAD_PENALTY 50
       
    49 // A diagonal track cost the same as a straigh, but a diagonal is faster... so give
       
    50 //  a bonus for using diagonal track
       
    51 #ifdef AI_PATHFINDER_NO_90DEGREES_TURN
       
    52 #define AI_PATHFINDER_DIAGONAL_BONUS 95
       
    53 #else
       
    54 #define AI_PATHFINDER_DIAGONAL_BONUS 75
       
    55 #endif
       
    56 // If a roadblock already exists, it gets a bonus
       
    57 #define AI_PATHFINDER_ROAD_ALREADY_EXISTS_BONUS 140
       
    58 // To prevent 3 direction changes in 3 tiles, this penalty is given in such situation
       
    59 #define AI_PATHFINDER_CURVE_PENALTY 200
       
    60 
       
    61 // Penalty a bridge gets per length
       
    62 #define AI_PATHFINDER_BRIDGE_PENALTY 180
       
    63 // The penalty for a bridge going up
       
    64 #define AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY 1000
       
    65 
       
    66 // Tunnels are expensive...
       
    67 //  Because of that, every tile the cost is increased with 1/8th of his value
       
    68 //  This is also true if you are building a tunnel yourself
       
    69 #define AI_PATHFINDER_TUNNEL_PENALTY 350
       
    70 
       
    71 /*
       
    72  * Ai_New defines
       
    73  */
       
    74 
       
    75 // How long may we search cities and industry for a new route?
       
    76 #define AI_LOCATE_ROUTE_MAX_COUNTER 200
       
    77 
       
    78 // How many days must there be between building the first station and the second station
       
    79 //  within one city. This number is in days and should be more than 4 months.
       
    80 #define AI_CHECKCITY_DATE_BETWEEN 180
       
    81 
       
    82 // How many cargo is needed for one station in a city?
       
    83 #define AI_CHECKCITY_CARGO_PER_STATION 60
       
    84 // How much cargo must there not be used in a city before we can build a new station?
       
    85 #define AI_CHECKCITY_NEEDED_CARGO 50
       
    86 // When there is already a station which takes the same good and the rating of that
       
    87 //  city is higher then this numer, we are not going to attempt to build anything
       
    88 //  there
       
    89 #define AI_CHECKCITY_CARGO_RATING 50
       
    90 // But, there is a chance of 1 out of this number, that we do ;)
       
    91 #define AI_CHECKCITY_CARGO_RATING_CHANCE 5
       
    92 // If a city is too small to contain a station, there is a small chance
       
    93 //  that we still do so.. just to make the city bigger!
       
    94 #define AI_CHECKCITY_CITY_CHANCE 5
       
    95 
       
    96 // This number indicates for every unit of cargo, how many tiles two stations maybe be away
       
    97 //  from eachother. In other words: if we have 120 units of cargo in one station, and 120 units
       
    98 //  of the cargo in the other station, both stations can be 96 units away from eachother, if the
       
    99 //  next number is 0.4.
       
   100 #define AI_LOCATEROUTE_BUS_CARGO_DISTANCE 0.4
       
   101 #define AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE 0.7
       
   102 // In whole tiles, the minimum distance for a truck route
       
   103 #define AI_LOCATEROUTE_TRUCK_MIN_DISTANCE 30
       
   104 
       
   105 // The amount of tiles in a square from -X to +X that is scanned for a station spot
       
   106 //  (so if this number is 10, 20x20 = 400 tiles are scanned for _the_ perfect spot
       
   107 // Safe values are between 15 and 5
       
   108 #define AI_FINDSTATION_TILE_RANGE 10
       
   109 
       
   110 // Building on normal speed goes very fast. Idle this amount of ticks between every
       
   111 //  building part. It is calculated like this: (4 - competitor_speed) * num + 1
       
   112 //  where competitor_speed is between 0 (very slow) to 4 (very fast)
       
   113 #define AI_BUILDPATH_PAUSE 10
       
   114 
       
   115 // Minimum % of reliabilty a vehicle has to have before the AI buys it
       
   116 #define AI_VEHICLE_MIN_RELIABILTY 60
       
   117 
       
   118 // The minimum amount of money a player should always have
       
   119 #define AI_MINIMUM_MONEY 15000
       
   120 
       
   121 // If the most cheap route is build, how much is it going to cost..
       
   122 // This is to prevent the AI from trying to build a route which can not be paid for
       
   123 #define AI_MINIMUM_BUS_ROUTE_MONEY 25000
       
   124 #define AI_MINIMUM_TRUCK_ROUTE_MONEY 35000
       
   125 
       
   126 // The minimum amount of money before we are going to repay any money
       
   127 #define AI_MINIMUM_LOAN_REPAY_MONEY 40000
       
   128 // How many repays do we do if we have enough money to do so?
       
   129 //  Every repay is 10000
       
   130 #define AI_LOAN_REPAY 2
       
   131 // How much income must we have before paying back a loan? Month-based (and looked at the last month)
       
   132 #define AI_MINIMUM_INCOME_FOR_LOAN 7000
       
   133 
       
   134 // If there is <num> time as much cargo in the station then the vehicle can handle
       
   135 //  reuse the station instead of building a new one!
       
   136 #define AI_STATION_REUSE_MULTIPLER 2
       
   137 
       
   138 // No more than this amount of vehicles per station..
       
   139 #define AI_CHECK_MAX_VEHICLE_PER_STATION 10
       
   140 
       
   141 // How many thick between building 2 vehicles
       
   142 #define AI_BUILD_VEHICLE_TIME_BETWEEN DAY_TICKS
       
   143 
       
   144 // How many days must there between vehicle checks
       
   145 //  The more often, the less non-money-making lines there will be
       
   146 //   but the unfair it may seem to a human player
       
   147 #define AI_DAYS_BETWEEN_VEHICLE_CHECKS 30
       
   148 
       
   149 // How money profit does a vehicle needs to make to stay in order
       
   150 //  This is the profit of this year + profit of last year
       
   151 //  But also for vehicles that are just one year old. In other words:
       
   152 //   Vehicles of 2 years do easier meet this setting then vehicles
       
   153 //   of one year. This is a very good thing. New vehicles are filtered,
       
   154 //   while old vehicles stay longer, because we do get less in return.
       
   155 #define AI_MINIMUM_ROUTE_PROFIT 1000
       
   156 
       
   157 // A vehicle is considered lost when he his cargo is more than 180 days old
       
   158 #define AI_VEHICLE_LOST_DAYS 180
       
   159 
       
   160 // How many times may the AI try to find a route before it gives up
       
   161 #define AI_MAX_TRIES_FOR_SAME_ROUTE 8
       
   162 
       
   163 /*
       
   164  * End of defines
       
   165  */
       
   166 
       
   167 // This stops 90degrees curves
       
   168 static const byte _illegal_curves[6] = {
       
   169 	255, 255, // Horz and vert, don't have the effect
       
   170 	5, // upleft and upright are not valid
       
   171 	4, // downright and downleft are not valid
       
   172 	2, // downleft and upleft are not valid
       
   173 	3, // upright and downright are not valid
       
   174 };
       
   175 
       
   176 enum {
       
   177 	AI_STATE_STARTUP = 0,
       
   178 	AI_STATE_FIRST_TIME,
       
   179 	AI_STATE_NOTHING,
       
   180 	AI_STATE_WAKE_UP,
       
   181 	AI_STATE_LOCATE_ROUTE,
       
   182 	AI_STATE_FIND_STATION,
       
   183 	AI_STATE_FIND_PATH,
       
   184 	AI_STATE_FIND_DEPOT,
       
   185 	AI_STATE_VERIFY_ROUTE,
       
   186 	AI_STATE_BUILD_STATION,
       
   187 	AI_STATE_BUILD_PATH,
       
   188 	AI_STATE_BUILD_DEPOT,
       
   189 	AI_STATE_BUILD_VEHICLE,
       
   190 	AI_STATE_WAIT_FOR_BUILD,
       
   191 	AI_STATE_GIVE_ORDERS,
       
   192 	AI_STATE_START_VEHICLE,
       
   193 	AI_STATE_REPAY_MONEY,
       
   194 	AI_STATE_CHECK_ALL_VEHICLES,
       
   195 	AI_STATE_ACTION_DONE,
       
   196 	AI_STATE_STOP, // Temporary function to stop the AI
       
   197 };
       
   198 
       
   199 // Used for tbt (train/bus/truck)
       
   200 enum {
       
   201 	AI_TRAIN = 0,
       
   202 	AI_BUS,
       
   203 	AI_TRUCK,
       
   204 };
       
   205 
       
   206 enum {
       
   207 	AI_ACTION_NONE = 0,
       
   208 	AI_ACTION_BUS_ROUTE,
       
   209 	AI_ACTION_TRUCK_ROUTE,
       
   210 	AI_ACTION_REPAY_LOAN,
       
   211 	AI_ACTION_CHECK_ALL_VEHICLES,
       
   212 };
       
   213 
       
   214 // Used for from_type/to_type
       
   215 enum {
       
   216 	AI_NO_TYPE = 0,
       
   217 	AI_CITY,
       
   218 	AI_INDUSTRY,
       
   219 };
       
   220 
       
   221 // Flags for in the vehicle
       
   222 enum {
       
   223 	AI_VEHICLEFLAG_SELL = 1,
       
   224 	// Remember, flags must be in power of 2
       
   225 };
       
   226 
       
   227 #define AI_NO_CARGO 0xFF // Means that there is no cargo defined yet (used for industry)
       
   228 #define AI_NEED_CARGO 0xFE // Used when the AI needs to find out a cargo for the route
       
   229 #define AI_STATION_RANGE TileXY(MapMaxX(), MapMaxY())
       
   230 
       
   231 #define AI_PATHFINDER_NO_DIRECTION (byte)-1
       
   232 
       
   233 // Flags used in user_data
       
   234 #define AI_PATHFINDER_FLAG_BRIDGE 1
       
   235 #define AI_PATHFINDER_FLAG_TUNNEL 2
       
   236 
       
   237 typedef void AiNew_StateFunction(Player *p);
       
   238 
       
   239 // ai_new.c
       
   240 void AiNewDoGameLoop(Player *p);
       
   241 
       
   242 // ai_pathfinder.c
       
   243 AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFinderInfo);
       
   244 void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo);
       
   245 
       
   246 // ai_shared.c
       
   247 int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
       
   248 int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
       
   249 DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b);
       
   250 bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag);
       
   251 uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);
       
   252 
       
   253 // ai_build.c
       
   254 bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile);
       
   255 int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
       
   256 int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
       
   257 int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
       
   258 EngineID AiNew_PickVehicle(Player *p);
       
   259 int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
       
   260 int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
       
   261 
       
   262 #endif /* AI_TROLLY_H */