src/newgrf_engine.cpp
branchnoai
changeset 9703 d2a6acdbd665
parent 9701 d1ac22c62f64
child 9722 ebf0ece7d8f6
equal deleted inserted replaced
9702:e782b59f1f6a 9703:d2a6acdbd665
   507 
   507 
   508 	/* Calculated vehicle parameters */
   508 	/* Calculated vehicle parameters */
   509 	switch (variable) {
   509 	switch (variable) {
   510 		case 0x40: // Get length of consist
   510 		case 0x40: // Get length of consist
   511 		case 0x41: // Get length of same consecutive wagons
   511 		case 0x41: // Get length of same consecutive wagons
   512 			if (!v->HasFront()) return 1;
       
   513 
       
   514 			{
   512 			{
   515 				const Vehicle* u;
   513 				const Vehicle* u;
   516 				byte chain_before = 0;
   514 				byte chain_before = 0;
   517 				byte chain_after  = 0;
   515 				byte chain_after  = 0;
   518 
   516 
   548 				/* Skip empty engines */
   546 				/* Skip empty engines */
   549 				if (u->cargo_cap == 0) continue;
   547 				if (u->cargo_cap == 0) continue;
   550 
   548 
   551 				cargo_classes |= GetCargo(u->cargo_type)->classes;
   549 				cargo_classes |= GetCargo(u->cargo_type)->classes;
   552 				common_cargos[u->cargo_type]++;
   550 				common_cargos[u->cargo_type]++;
   553 				user_def_data |= RailVehInfo(u->engine_type)->user_def_data;
   551 				if (v->type == VEH_TRAIN) user_def_data |= RailVehInfo(u->engine_type)->user_def_data;
   554 				common_subtypes[u->cargo_subtype]++;
   552 				common_subtypes[u->cargo_subtype]++;
   555 			}
   553 			}
   556 
   554 
   557 			/* Pick the most common cargo type */
   555 			/* Pick the most common cargo type */
   558 			for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
   556 			for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
   797 static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const SpriteGroup *group)
   795 static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const SpriteGroup *group)
   798 {
   796 {
   799 	const Vehicle *v = object->u.vehicle.self;
   797 	const Vehicle *v = object->u.vehicle.self;
   800 	uint totalsets;
   798 	uint totalsets;
   801 	uint set;
   799 	uint set;
   802 	bool in_motion;
       
   803 
   800 
   804 	if (v == NULL) return group->g.real.loading[0];
   801 	if (v == NULL) return group->g.real.loading[0];
   805 
   802 
   806 	if (v->type == VEH_TRAIN) {
   803 	bool in_motion = v->First()->current_order.type != OT_LOADING;
   807 		in_motion = v->First()->current_order.type != OT_LOADING;
       
   808 	} else {
       
   809 		in_motion = v->current_order.type != OT_LOADING;
       
   810 	}
       
   811 
   804 
   812 	totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
   805 	totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
   813 
   806 
   814 	if (v->cargo.Count() == v->cargo_cap || totalsets == 1) {
   807 	if (v->cargo.Count() == v->cargo_cap || totalsets == 1) {
   815 		set = totalsets - 1;
   808 		set = totalsets - 1;
   830 	res->SetTriggers   = &VehicleSetTriggers;
   823 	res->SetTriggers   = &VehicleSetTriggers;
   831 	res->GetVariable   = &VehicleGetVariable;
   824 	res->GetVariable   = &VehicleGetVariable;
   832 	res->ResolveReal   = &VehicleResolveReal;
   825 	res->ResolveReal   = &VehicleResolveReal;
   833 
   826 
   834 	res->u.vehicle.self   = v;
   827 	res->u.vehicle.self   = v;
   835 	res->u.vehicle.parent = (v != NULL && v->HasFront()) ? v->First() : v;
   828 	res->u.vehicle.parent = (v != NULL) ? v->First() : v;
   836 
   829 
   837 	res->u.vehicle.self_type = engine_type;
   830 	res->u.vehicle.self_type = engine_type;
   838 
   831 
   839 	res->info_view = false;
   832 	res->info_view = false;
   840 
   833 
  1031 			 * same for all triggered vehicles in the chain (to get
  1024 			 * same for all triggered vehicles in the chain (to get
  1032 			 * all the random-cargo wagons carry the same cargo,
  1025 			 * all the random-cargo wagons carry the same cargo,
  1033 			 * i.e.), so we give them all the NEW_CARGO triggered
  1026 			 * i.e.), so we give them all the NEW_CARGO triggered
  1034 			 * vehicle's portion of random bits. */
  1027 			 * vehicle's portion of random bits. */
  1035 			assert(first);
  1028 			assert(first);
  1036 			DoTriggerVehicle((v->type == VEH_TRAIN) ? v->First() : v, VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
  1029 			DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
  1037 			break;
  1030 			break;
  1038 
  1031 
  1039 		case VEHICLE_TRIGGER_DEPOT:
  1032 		case VEHICLE_TRIGGER_DEPOT:
  1040 			/* We now trigger the next vehicle in chain recursively.
  1033 			/* We now trigger the next vehicle in chain recursively.
  1041 			 * The random bits portions may be different for each
  1034 			 * The random bits portions may be different for each