src/train_cmd.cpp
changeset 7010 6f0d9f03180d
parent 7002 1bf6a62b0fcb
child 7023 7ecc645ba712
equal deleted inserted replaced
7009:9992ccf17e58 7010:6f0d9f03180d
   110 static void TrainCargoChanged(Vehicle* v)
   110 static void TrainCargoChanged(Vehicle* v)
   111 {
   111 {
   112 	uint32 weight = 0;
   112 	uint32 weight = 0;
   113 
   113 
   114 	for (Vehicle *u = v; u != NULL; u = u->next) {
   114 	for (Vehicle *u = v; u != NULL; u = u->next) {
   115 		uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo_count * FreightWagonMult(u->cargo_type) / 16;
   115 		uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16;
   116 
   116 
   117 		/* Vehicle weight is not added for articulated parts. */
   117 		/* Vehicle weight is not added for articulated parts. */
   118 		if (!IsArticulatedPart(u)) {
   118 		if (!IsArticulatedPart(u)) {
   119 			/* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */
   119 			/* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */
   120 			vweight += GetVehicleProperty(u, 0x16, RailVehInfo(u->engine_type)->weight);
   120 			vweight += GetVehicleProperty(u, 0x16, RailVehInfo(u->engine_type)->weight);
   461 		img = orig_rail_vehicle_info[v->engine_type].image_index;
   461 		img = orig_rail_vehicle_info[v->engine_type].image_index;
   462 	}
   462 	}
   463 
   463 
   464 	base = _engine_sprite_base[img] + ((direction + _engine_sprite_add[img]) & _engine_sprite_and[img]);
   464 	base = _engine_sprite_base[img] + ((direction + _engine_sprite_add[img]) & _engine_sprite_and[img]);
   465 
   465 
   466 	if (v->cargo_count >= v->cargo_cap / 2) base += _wagon_full_adder[img];
   466 	if (v->cargo.Count() >= v->cargo_cap / 2) base += _wagon_full_adder[img];
   467 	return base;
   467 	return base;
   468 }
   468 }
   469 
   469 
   470 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)
   470 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)
   471 {
   471 {
  1759 					cost.AddCost(GetRefitCost(v->engine_type));
  1759 					cost.AddCost(GetRefitCost(v->engine_type));
  1760 				}
  1760 				}
  1761 
  1761 
  1762 				num += amount;
  1762 				num += amount;
  1763 				if (flags & DC_EXEC) {
  1763 				if (flags & DC_EXEC) {
  1764 					v->cargo_count = (v->cargo_type == new_cid) ? min(amount, v->cargo_count) : 0;
  1764 					v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0);
  1765 					v->cargo_type = new_cid;
  1765 					v->cargo_type = new_cid;
  1766 					v->cargo_cap = amount;
  1766 					v->cargo_cap = amount;
  1767 					v->cargo_subtype = new_subtype;
  1767 					v->cargo_subtype = new_subtype;
  1768 					InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
  1768 					InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
  1769 					InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
  1769 					InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
  2679 
  2679 
  2680 static uint CountPassengersInTrain(const Vehicle* v)
  2680 static uint CountPassengersInTrain(const Vehicle* v)
  2681 {
  2681 {
  2682 	uint num = 0;
  2682 	uint num = 0;
  2683 	BEGIN_ENUM_WAGONS(v)
  2683 	BEGIN_ENUM_WAGONS(v)
  2684 		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo_count;
  2684 		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo.Count();
  2685 	END_ENUM_WAGONS(v)
  2685 	END_ENUM_WAGONS(v)
  2686 	return num;
  2686 	return num;
  2687 }
  2687 }
  2688 
  2688 
  2689 struct TrainCollideChecker {
  2689 struct TrainCollideChecker {
  3292 }
  3292 }
  3293 
  3293 
  3294 
  3294 
  3295 void Train_Tick(Vehicle *v)
  3295 void Train_Tick(Vehicle *v)
  3296 {
  3296 {
  3297 	if (_age_cargo_skip_counter == 0 && v->cargo_days != 0xff)
  3297 	if (_age_cargo_skip_counter == 0) v->cargo.AgeCargo();
  3298 		v->cargo_days++;
       
  3299 
  3298 
  3300 	v->tick_counter++;
  3299 	v->tick_counter++;
  3301 
  3300 
  3302 	if (IsFrontEngine(v)) {
  3301 	if (IsFrontEngine(v)) {
  3303 		v->current_order_time++;
  3302 		v->current_order_time++;