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