src/ai/api/ai_engine.cpp
branchnoai
changeset 10194 c9fdeb7450da
parent 10190 6e4a90ed8830
child 10196 aecabd927420
equal deleted inserted replaced
10193:9f73edc0c57a 10194:c9fdeb7450da
    36 	return engine_name;
    36 	return engine_name;
    37 }
    37 }
    38 
    38 
    39 /* static */ CargoID AIEngine::GetCargoType(EngineID engine_id)
    39 /* static */ CargoID AIEngine::GetCargoType(EngineID engine_id)
    40 {
    40 {
    41 	if (!IsValidEngine(engine_id)) return 0;
    41 	if (!IsValidEngine(engine_id)) return -1;
    42 
    42 
    43 	switch (::GetEngine(engine_id)->type) {
    43 	switch (::GetEngine(engine_id)->type) {
    44 		case VEH_ROAD: {
    44 		case VEH_ROAD: {
    45 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
    45 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
    46 			return vi->cargo_type;
    46 			return vi->cargo_type;
    72 	if (GetCargoType(engine_id) == cargo_id) return true;
    72 	if (GetCargoType(engine_id) == cargo_id) return true;
    73 	if (cargo_id == CT_MAIL && ::GetEngine(engine_id)->type == VEH_AIRCRAFT) return true;
    73 	if (cargo_id == CT_MAIL && ::GetEngine(engine_id)->type == VEH_AIRCRAFT) return true;
    74 	return ::CanRefitTo(engine_id, cargo_id);
    74 	return ::CanRefitTo(engine_id, cargo_id);
    75 }
    75 }
    76 
    76 
    77 /* static */ uint32 AIEngine::GetCapacity(EngineID engine_id)
    77 /* static */ int32 AIEngine::GetCapacity(EngineID engine_id)
    78 {
    78 {
    79 	if (!IsValidEngine(engine_id)) return 0;
    79 	if (!IsValidEngine(engine_id)) return -1;
    80 
    80 
    81 	switch (::GetEngine(engine_id)->type) {
    81 	switch (::GetEngine(engine_id)->type) {
    82 		case VEH_ROAD:
    82 		case VEH_ROAD:
    83 		case VEH_TRAIN: {
    83 		case VEH_TRAIN: {
    84 			uint16 *capacities = GetCapacityOfArticulatedParts(engine_id, ::GetEngine(engine_id)->type);
    84 			uint16 *capacities = GetCapacityOfArticulatedParts(engine_id, ::GetEngine(engine_id)->type);
    85 			for (CargoID c = 0; c < NUM_CARGO; c++) {
    85 			for (CargoID c = 0; c < NUM_CARGO; c++) {
    86 				if (capacities[c] == 0) continue;
    86 				if (capacities[c] == 0) continue;
    87 				return capacities[c];
    87 				return capacities[c];
    88 			}
    88 			}
    89 			return 0;
    89 			return -1;
    90 		} break;
    90 		} break;
    91 
    91 
    92 		case VEH_SHIP: {
    92 		case VEH_SHIP: {
    93 			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
    93 			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
    94 			return vi->capacity;
    94 			return vi->capacity;
   101 
   101 
   102 		default: NOT_REACHED();
   102 		default: NOT_REACHED();
   103 	}
   103 	}
   104 }
   104 }
   105 
   105 
   106 /* static */ uint32 AIEngine::GetReliability(EngineID engine_id)
   106 /* static */ int32 AIEngine::GetReliability(EngineID engine_id)
   107 {
   107 {
   108 	if (!IsValidEngine(engine_id)) return 0;
   108 	if (!IsValidEngine(engine_id)) return -1;
   109 
   109 
   110 	return (::GetEngine(engine_id)->reliability * 100 >> 16);
   110 	return (::GetEngine(engine_id)->reliability * 100 >> 16);
   111 }
   111 }
   112 
   112 
   113 /* static */ uint32 AIEngine::GetMaxSpeed(EngineID engine_id)
   113 /* static */ int32 AIEngine::GetMaxSpeed(EngineID engine_id)
   114 {
   114 {
   115 	if (!IsValidEngine(engine_id)) return 0;
   115 	if (!IsValidEngine(engine_id)) return -1;
   116 
   116 
   117 	switch (::GetEngine(engine_id)->type) {
   117 	switch (::GetEngine(engine_id)->type) {
   118 		case VEH_ROAD: {
   118 		case VEH_ROAD: {
   119 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
   119 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
   120 			/* Internal speeds are km/h * 2 */
   120 			/* Internal speeds are km/h * 2 */
   139 
   139 
   140 		default: NOT_REACHED();
   140 		default: NOT_REACHED();
   141 	}
   141 	}
   142 }
   142 }
   143 
   143 
   144 /* static */ uint32 AIEngine::GetPrice(EngineID engine_id)
   144 /* static */ int32 AIEngine::GetPrice(EngineID engine_id)
   145 {
   145 {
   146 	if (!IsValidEngine(engine_id)) return 0;
   146 	if (!IsValidEngine(engine_id)) return -1;
   147 
   147 
   148 	switch (::GetEngine(engine_id)->type) {
   148 	switch (::GetEngine(engine_id)->type) {
   149 		case VEH_ROAD: {
   149 		case VEH_ROAD: {
   150 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
   150 			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
   151 			return (_price.roadveh_base >> 3) * vi->base_cost >> 5;
   151 			return (_price.roadveh_base >> 3) * vi->base_cost >> 5;
   168 
   168 
   169 		default: NOT_REACHED();
   169 		default: NOT_REACHED();
   170 	}
   170 	}
   171 }
   171 }
   172 
   172 
   173 /* static */ uint32 AIEngine::GetMaxAge(EngineID engine_id)
   173 /* static */ int32 AIEngine::GetMaxAge(EngineID engine_id)
   174 {
   174 {
   175 	if (!IsValidEngine(engine_id)) return 0;
   175 	if (!IsValidEngine(engine_id)) return -1;
   176 
   176 
   177 	return ::GetEngine(engine_id)->lifelength * 366;
   177 	return ::GetEngine(engine_id)->lifelength * 366;
   178 }
   178 }
   179 
   179 
   180 /* static */ Money AIEngine::GetRunningCost(EngineID engine_id)
   180 /* static */ Money AIEngine::GetRunningCost(EngineID engine_id)
   181 {
   181 {
   182 	if (!IsValidEngine(engine_id)) return 0;
   182 	if (!IsValidEngine(engine_id)) return -1;
   183 
   183 
   184 	/* We need to create an instance in order to obtain GetRunningCost.
   184 	/* We need to create an instance in order to obtain GetRunningCost.
   185 	 *  This means we temporary allocate a vehicle in the pool, but
   185 	 *  This means we temporary allocate a vehicle in the pool, but
   186 	 *  there is no other way.. */
   186 	 *  there is no other way.. */
   187 	Vehicle *vehicle;
   187 	Vehicle *vehicle;