truelight@84: #ifndef AI_H truelight@84: #define AI_H truelight@84: truelight@84: #include "aystar.h" truelight@84: truelight@84: /* truelight@84: * These defines can be altered to change the behavoir of the AI truelight@84: * truelight@84: * WARNING: truelight@84: * This can also alter the AI in a negative way. I will never claim these settings truelight@84: * are perfect, but don't change them if you don't know what the effect is. truelight@84: */ truelight@84: truelight@84: // How many times it the H multiplied. The higher, the more it will go straight to the truelight@84: // end point. The lower, how more it will find the route with the lowest cost. truelight@84: // also: the lower, the longer it takes before route is calculated.. truelight@84: #define AI_PATHFINDER_H_MULTIPLER 100 truelight@84: truelight@84: // How many loops may AyStar do before it stops truelight@84: // 0 = infinite truelight@84: #define AI_PATHFINDER_LOOPS_PER_TICK 5 truelight@84: truelight@84: // How long may the AI search for one route? truelight@84: // 0 = infinite truelight@84: // This number is the number of tiles tested. truelight@84: // It takes (AI_PATHFINDER_MAX_SEARCH_NODES / AI_PATHFINDER_LOOPS_PER_TICK) ticks truelight@84: // to get here.. with 5000 / 10 = 500. 500 / 74 (one day) = 8 days till it aborts truelight@84: // (that is: if the AI is on VERY FAST! :p truelight@84: #define AI_PATHFINDER_MAX_SEARCH_NODES 5000 truelight@84: truelight@84: // If you enable this, the AI is not allowed to make 90degree turns truelight@84: #define AI_PATHFINDER_NO_90DEGREES_TURN truelight@84: truelight@84: // Below are defines for the g-calculation truelight@84: truelight@84: // Standard penalty given to a tile truelight@84: #define AI_PATHFINDER_PENALTY 150 truelight@84: // The penalty given to a tile that is going up truelight@84: #define AI_PATHFINDER_TILE_GOES_UP_PENALTY 450 truelight@84: // Changing direction is a penalty, to prevent curved ways (with that: slow ways) truelight@84: #define AI_PATHFINDER_DIRECTION_CHANGE_PENALTY 200 truelight@84: // Same penalty, only for when road already exists truelight@84: #define AI_PATHFINDER_DIRECTION_CHANGE_ON_EXISTING_ROAD_PENALTY 50 truelight@84: // A diagonal track cost the same as a straigh, but a diagonal is faster... so give truelight@84: // a bonus for using diagonal track truelight@84: #ifdef AI_PATHFINDER_NO_90DEGREES_TURN truelight@84: #define AI_PATHFINDER_DIAGONAL_BONUS 95 truelight@84: #else truelight@84: #define AI_PATHFINDER_DIAGONAL_BONUS 75 truelight@84: #endif truelight@84: // If a roadblock already exists, it gets a bonus truelight@84: #define AI_PATHFINDER_ROAD_ALREADY_EXISTS_BONUS 140 truelight@84: // To prevent 3 direction changes in 3 tiles, this penalty is given in such situation truelight@84: #define AI_PATHFINDER_CURVE_PENALTY 200 truelight@84: truelight@84: // Penalty a bridge gets per length truelight@84: #define AI_PATHFINDER_BRIDGE_PENALTY 180 truelight@84: // The penalty for a bridge going up truelight@84: #define AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY 1000 truelight@84: truelight@84: // Tunnels are expensive... truelight@84: // Because of that, every tile the cost is increased with 1/8th of his value truelight@84: // This is also true if you are building a tunnel yourself truelight@84: #define AI_PATHFINDER_TUNNEL_PENALTY 350 truelight@84: truelight@84: /* truelight@84: * Ai_New defines truelight@84: */ truelight@84: truelight@84: // How long may we search cities and industry for a new route? truelight@84: #define AI_LOCATE_ROUTE_MAX_COUNTER 200 truelight@84: truelight@84: // How many days must there be between building the first station and the second station truelight@84: // within one city. This number is in days and should be more then 4 months. truelight@84: #define AI_CHECKCITY_DATE_BETWEEN 180 truelight@84: truelight@84: // How many cargo is needed for one station in a city? truelight@84: #define AI_CHECKCITY_CARGO_PER_STATION 60 truelight@84: // How much cargo must there not be used in a city before we can build a new station? truelight@84: #define AI_CHECKCITY_NEEDED_CARGO 50 truelight@84: // When there is already a station which takes the same good and the rating of that truelight@84: // city is higher then this numer, we are not going to attempt to build anything truelight@84: // there truelight@84: #define AI_CHECKCITY_CARGO_RATING 50 truelight@84: // But, there is a chance of 1 out of this number, that we do ;) truelight@84: #define AI_CHECKCITY_CARGO_RATING_CHANCE 5 truelight@84: // If a city is too small to contain a station, there is a small chance truelight@84: // that we still do so.. just to make the city bigger! truelight@84: #define AI_CHECKCITY_CITY_CHANCE 5 truelight@84: truelight@84: // This number indicates for every unit of cargo, how many tiles two stations maybe be away truelight@84: // from eachother. In other words: if we have 120 units of cargo in one station, and 120 units truelight@84: // of the cargo in the other station, both stations can be 96 units away from eachother, if the truelight@84: // next number is 0.4. truelight@84: #define AI_LOCATEROUTE_BUS_CARGO_DISTANCE 0.4 truelight@84: #define AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE 0.7 truelight@84: // In whole tiles, the minimum distance for a truck route truelight@84: #define AI_LOCATEROUTE_TRUCK_MIN_DISTANCE 30 truelight@84: truelight@84: // The amount of tiles in a square from -X to +X that is scanned for a station spot truelight@84: // (so if this number is 10, 20x20 = 400 tiles are scanned for _the_ perfect spot truelight@84: // Safe values are between 15 and 5 truelight@84: #define AI_FINDSTATION_TILE_RANGE 10 truelight@84: truelight@84: // Building on normal speed goes very fast. Idle this amount of ticks between every truelight@84: // building part. It is calculated like this: (4 - competitor_speed) * num + 1 truelight@84: // where competitor_speed is between 0 (very slow) to 4 (very fast) truelight@84: #define AI_BUILDPATH_PAUSE 10 truelight@84: truelight@84: // Minimum % of reliabilty a vehicle has to have before the AI buys it truelight@84: #define AI_VEHICLE_MIN_RELIABILTY 60 truelight@84: truelight@84: // The minimum amount of money a player should always have truelight@84: #define AI_MINIMUM_MONEY 15000 truelight@84: truelight@84: // If the most cheap route is build, how much is it going to cost.. truelight@84: // This is to prevent the AI from trying to build a route which can not be paid for truelight@84: #define AI_MINIMUM_BUS_ROUTE_MONEY 25000 truelight@84: #define AI_MINIMUM_TRUCK_ROUTE_MONEY 35000 truelight@84: truelight@84: // The minimum amount of money before we are going to repay any money truelight@84: #define AI_MINIMUM_LOAN_REPAY_MONEY 40000 truelight@84: // How many repays do we do if we have enough money to do so? truelight@84: // Every repay is 10000 truelight@84: #define AI_LOAN_REPAY 2 truelight@84: // How much income must we have before paying back a loan? Month-based (and looked at the last month) truelight@84: #define AI_MINIMUM_INCOME_FOR_LOAN 7000 truelight@84: truelight@84: // If there is time as much cargo in the station then the vehicle can handle truelight@84: // reuse the station instead of building a new one! truelight@84: #define AI_STATION_REUSE_MULTIPLER 2 truelight@84: truelight@84: // No more then this amount of vehicles per station.. truelight@84: #define AI_CHECK_MAX_VEHICLE_PER_STATION 10 truelight@84: truelight@84: // How many thick between building 2 vehicles truelight@84: #define AI_BUILD_VEHICLE_TIME_BETWEEN 74 truelight@84: truelight@84: /* truelight@84: * End of defines truelight@84: */ truelight@84: truelight@84: truelight@84: // This stops 90degrees curves truelight@84: static const byte _illegal_curves[6] = { truelight@84: 255, 255, // Horz and vert, don't have the effect truelight@84: 5, // upleft and upright are not valid truelight@84: 4, // downright and downleft are not valid truelight@84: 2, // downleft and upleft are not valid truelight@84: 3, // upright and downright are not valid truelight@84: }; truelight@84: truelight@84: static const TileIndexDiff _tiles_around[4] = { truelight@84: TILE_XY(-1,0), truelight@84: TILE_XY(0,1), truelight@84: TILE_XY(1,0), truelight@84: TILE_XY(0,-1), truelight@84: }; truelight@84: truelight@84: enum { truelight@84: AI_STATE_STARTUP = 0, truelight@84: AI_STATE_FIRST_TIME, truelight@84: AI_STATE_NOTHING, truelight@84: AI_STATE_WAKE_UP, truelight@84: AI_STATE_LOCATE_ROUTE, truelight@84: AI_STATE_FIND_STATION, truelight@84: AI_STATE_FIND_PATH, truelight@84: AI_STATE_FIND_DEPOT, truelight@84: AI_STATE_VERIFY_ROUTE, truelight@84: AI_STATE_BUILD_STATION, truelight@84: AI_STATE_BUILD_PATH, truelight@84: AI_STATE_BUILD_DEPOT, truelight@84: AI_STATE_BUILD_VEHICLE, truelight@84: AI_STATE_GIVE_ORDERS, truelight@84: AI_STATE_START_VEHICLE, truelight@84: AI_STATE_REPAY_MONEY, truelight@84: AI_STATE_ACTION_DONE, truelight@84: AI_STATE_STOP, // Temporary function to stop the AI truelight@84: }; truelight@84: truelight@84: // Used for tbt (train/bus/truck) truelight@84: enum { truelight@84: AI_TRAIN = 0, truelight@84: AI_BUS, truelight@84: AI_TRUCK, truelight@84: }; truelight@84: truelight@84: enum { truelight@84: AI_ACTION_NONE = 0, truelight@84: AI_ACTION_BUS_ROUTE, truelight@84: AI_ACTION_TRUCK_ROUTE, truelight@84: AI_ACTION_REPAY_LOAN, truelight@84: }; truelight@84: truelight@84: // Used for from_type/to_type truelight@84: enum { truelight@84: AI_NO_TYPE = 0, truelight@84: AI_CITY, truelight@84: AI_INDUSTRY, truelight@84: }; truelight@84: truelight@84: #define AI_NO_CARGO 0xFF // Means that there is no cargo defined yet (used for industry) truelight@84: #define AI_NEED_CARGO 0xFE // Used when the AI needs to find out a cargo for the route truelight@84: #define AI_STATION_RANGE TILE_XY(TILE_X_MAX, TILE_Y_MAX) truelight@84: truelight@84: #define AI_PATHFINDER_NO_DIRECTION (byte)-1 truelight@84: truelight@84: // Flags used in user_data truelight@84: #define AI_PATHFINDER_FLAG_BRIDGE 1 truelight@84: #define AI_PATHFINDER_FLAG_TUNNEL 2 truelight@84: truelight@84: // A macro for mp_street, where 0x20 is depot truelight@84: // mp_tunnelbridge, where 0xf0 is a bridge, and 0x4/0x2 means: roadtunnel/bridge truelight@84: #define AI_PATHFINDER_IS_ROAD(tile) ((IS_TILETYPE(tile, MP_STREET) && !(_map5[tile] & 0x20)) || \ truelight@84: (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && \ truelight@84: (((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) || \ truelight@84: ((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2)))) truelight@84: truelight@84: typedef void AiNew_StateFunction(Player *p); truelight@84: truelight@84: // ai_new.c truelight@84: void AiNewDoGameLoop(Player *p); truelight@84: truelight@84: // ai_pathfinder.c truelight@84: AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFinderInfo); truelight@84: void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo); truelight@84: truelight@84: // ai_shared.c truelight@84: int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c); truelight@84: int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c); truelight@84: int AiNew_GetDirection(uint tile_a, uint tile_b); truelight@84: truelight@84: // ai_build.c truelight@84: bool AiNew_Build_CompanyHQ(Player *p, uint tile); truelight@84: int AiNew_Build_Station(Player *p, byte type, uint tile, byte length, byte numtracks, byte direction, byte flag); truelight@84: int AiNew_Build_Bridge(Player *p, uint tile_a, uint tile_b, byte flag); truelight@84: int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag); truelight@84: int AiNew_PickVehicle(Player *p); truelight@84: int AiNew_Build_Vehicle(Player *p, uint tile, byte flag); truelight@84: int AiNew_Build_Depot(Player *p, uint tile, byte direction, byte flag); truelight@84: truelight@84: truelight@84: #endif