239 |
239 |
240 FOR_ALL_VEHICLES(v) { |
240 FOR_ALL_VEHICLES(v) { |
241 switch (v->type) { |
241 switch (v->type) { |
242 case VEH_ROAD: |
242 case VEH_ROAD: |
243 v->cur_image = GetRoadVehImage(v, v->direction); |
243 v->cur_image = GetRoadVehImage(v, v->direction); |
244 v->u.road.roadtype = ROADTYPE_ROAD; |
244 v->u.road.roadtype = HASBIT(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; |
245 v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); |
245 v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); |
246 break; |
246 break; |
247 |
247 |
248 case VEH_TRAIN: v->cur_image = GetTrainImage(v, v->direction); break; |
248 case VEH_TRAIN: v->cur_image = GetTrainImage(v, v->direction); break; |
249 case VEH_SHIP: v->cur_image = GetShipImage(v, v->direction); break; |
249 case VEH_SHIP: v->cur_image = GetShipImage(v, v->direction); break; |
588 if (IsEngineCountable(v)) { |
588 if (IsEngineCountable(v)) { |
589 GetPlayer(v->owner)->num_engines[v->engine_type]--; |
589 GetPlayer(v->owner)->num_engines[v->engine_type]--; |
590 if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type); |
590 if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type); |
591 |
591 |
592 if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--; |
592 if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--; |
593 if (v->type != VEH_TRAIN || IsFrontEngine(v)) DecreaseGroupNumVehicle(v->group_id); |
593 if (v->IsPrimaryVehicle()) DecreaseGroupNumVehicle(v->group_id); |
594 } |
594 } |
595 |
595 |
596 DeleteVehicleNews(v->index, INVALID_STRING_ID); |
596 DeleteVehicleNews(v->index, INVALID_STRING_ID); |
597 |
597 |
598 DeleteName(v->string_id); |
598 DeleteName(v->string_id); |
607 if (IsPlayerBuildableVehicleType(v)) DeleteVehicleOrders(v); |
607 if (IsPlayerBuildableVehicleType(v)) DeleteVehicleOrders(v); |
608 |
608 |
609 /* Now remove any artic part. This will trigger an other |
609 /* Now remove any artic part. This will trigger an other |
610 * destroy vehicle, which on his turn can remove any |
610 * destroy vehicle, which on his turn can remove any |
611 * other artic parts. */ |
611 * other artic parts. */ |
612 if (EngineHasArticPart(v)) DeleteVehicle(v->next); |
612 if (v->type == VEH_TRAIN && EngineHasArticPart(v)) DeleteVehicle(v->next); |
613 } |
613 } |
614 |
614 |
615 void DeleteVehicleChain(Vehicle *v) |
615 void DeleteVehicleChain(Vehicle *v) |
616 { |
616 { |
617 do { |
617 do { |
1792 } |
1792 } |
1793 |
1793 |
1794 v = v_front; |
1794 v = v_front; |
1795 |
1795 |
1796 do { |
1796 do { |
1797 if (IsMultiheaded(v) && !IsTrainEngine(v)) { |
1797 if (v->type == VEH_TRAIN && IsMultiheaded(v) && !IsTrainEngine(v)) { |
1798 /* we build the rear ends of multiheaded trains with the front ones */ |
1798 /* we build the rear ends of multiheaded trains with the front ones */ |
1799 continue; |
1799 continue; |
1800 } |
1800 } |
1801 |
1801 |
1802 cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); |
1802 cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); |
1870 total_cost += GetRefitCost(v->engine_type); |
1870 total_cost += GetRefitCost(v->engine_type); |
1871 } |
1871 } |
1872 } |
1872 } |
1873 } while (v->type == VEH_TRAIN && EngineHasArticPart(v) && (v = GetNextArticPart(v)) != NULL); |
1873 } while (v->type == VEH_TRAIN && EngineHasArticPart(v) && (v = GetNextArticPart(v)) != NULL); |
1874 |
1874 |
1875 if (flags & DC_EXEC) w = GetNextVehicle(w); |
1875 if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(w); |
1876 } while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
1876 } while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
1877 |
1877 |
1878 /* Since we can't estimate the cost of cloning a vehicle accurately we must |
1878 /* Since we can't estimate the cost of cloning a vehicle accurately we must |
1879 * check whether the player has enough money manually. */ |
1879 * check whether the player has enough money manually. */ |
1880 if (!CheckPlayerHasMoney(total_cost)) { |
1880 if (!CheckPlayerHasMoney(total_cost)) { |
1995 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
1995 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
1996 * @return the number of vehicles added to the list |
1996 * @return the number of vehicles added to the list |
1997 */ |
1997 */ |
1998 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type) |
1998 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type) |
1999 { |
1999 { |
2000 const byte subtype = (type != VEH_AIRCRAFT) ? (byte)Train_Front : (byte)AIR_AIRCRAFT; |
|
2001 uint n = 0; |
2000 uint n = 0; |
2002 const Vehicle *v; |
2001 const Vehicle *v; |
2003 |
2002 |
2004 switch (window_type) { |
2003 switch (window_type) { |
2005 case VLW_STATION_LIST: { |
2004 case VLW_STATION_LIST: { |
2006 FOR_ALL_VEHICLES(v) { |
2005 FOR_ALL_VEHICLES(v) { |
2007 if (v->type == type && ( |
2006 if (v->type == type && v->IsPrimaryVehicle()) { |
2008 (type == VEH_TRAIN && IsFrontEngine(v)) || |
|
2009 (type != VEH_TRAIN && v->subtype <= subtype))) { |
|
2010 const Order *order; |
2007 const Order *order; |
2011 |
2008 |
2012 FOR_VEHICLE_ORDERS(v, order) { |
2009 FOR_VEHICLE_ORDERS(v, order) { |
2013 if (order->type == OT_GOTO_STATION && order->dest == index) { |
2010 if (order->type == OT_GOTO_STATION && order->dest == index) { |
2014 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50); |
2011 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50); |
2037 break; |
2034 break; |
2038 } |
2035 } |
2039 |
2036 |
2040 case VLW_STANDARD: { |
2037 case VLW_STANDARD: { |
2041 FOR_ALL_VEHICLES(v) { |
2038 FOR_ALL_VEHICLES(v) { |
2042 if (v->type == type && v->owner == owner && ( |
2039 if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) { |
2043 (type == VEH_TRAIN && IsFrontEngine(v)) || |
|
2044 (type != VEH_TRAIN && v->subtype <= subtype))) { |
|
2045 /* TODO find a better estimate on the total number of vehicles for current player */ |
2040 /* TODO find a better estimate on the total number of vehicles for current player */ |
2046 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4); |
2041 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4); |
2047 (*sort_list)[n++] = v; |
2042 (*sort_list)[n++] = v; |
2048 } |
2043 } |
2049 } |
2044 } |
2050 break; |
2045 break; |
2051 } |
2046 } |
2052 |
2047 |
2053 case VLW_DEPOT_LIST: { |
2048 case VLW_DEPOT_LIST: { |
2054 FOR_ALL_VEHICLES(v) { |
2049 FOR_ALL_VEHICLES(v) { |
2055 if (v->type == type && ( |
2050 if (v->type == type && v->IsPrimaryVehicle()) { |
2056 (type == VEH_TRAIN && IsFrontEngine(v)) || |
|
2057 (type != VEH_TRAIN && v->subtype <= subtype))) { |
|
2058 const Order *order; |
2051 const Order *order; |
2059 |
2052 |
2060 FOR_VEHICLE_ORDERS(v, order) { |
2053 FOR_VEHICLE_ORDERS(v, order) { |
2061 if (order->type == OT_GOTO_DEPOT && order->dest == index) { |
2054 if (order->type == OT_GOTO_DEPOT && order->dest == index) { |
2062 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
2055 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
2069 break; |
2062 break; |
2070 } |
2063 } |
2071 |
2064 |
2072 case VLW_GROUP_LIST: |
2065 case VLW_GROUP_LIST: |
2073 FOR_ALL_VEHICLES(v) { |
2066 FOR_ALL_VEHICLES(v) { |
2074 if (v->type == type && ( |
2067 if (v->type == type && v->IsPrimaryVehicle() && |
2075 (type == VEH_TRAIN && IsFrontEngine(v)) || |
2068 v->owner == owner && v->group_id == index) { |
2076 (type != VEH_TRAIN && v->subtype <= subtype) |
|
2077 ) && v->owner == owner && v->group_id == index) { |
|
2078 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4); |
2069 if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4); |
2079 |
2070 |
2080 (*sort_list)[n++] = v; |
2071 (*sort_list)[n++] = v; |
2081 } |
2072 } |
2082 } |
2073 } |
2518 } |
2509 } |
2519 |
2510 |
2520 case VEH_ROAD: { |
2511 case VEH_ROAD: { |
2521 const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
2512 const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
2522 if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
2513 if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
2523 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
2514 if (HASBIT(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) { |
|
2515 /* Tram */ |
|
2516 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; |
|
2517 } else { |
|
2518 /* Bus or truck */ |
|
2519 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
|
2520 } |
2524 break; |
2521 break; |
2525 } |
2522 } |
2526 |
2523 |
2527 case VEH_SHIP: { |
2524 case VEH_SHIP: { |
2528 const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |
2525 const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |