src/newgrf_engine.cpp
changeset 7993 76b0eb3e19c9
parent 7988 6075538f6111
child 8044 72c3e2bc6429
equal deleted inserted replaced
7992:8ac3fcd8d570 7993:76b0eb3e19c9
   514 			{
   514 			{
   515 				const Vehicle* u;
   515 				const Vehicle* u;
   516 				byte chain_before = 0;
   516 				byte chain_before = 0;
   517 				byte chain_after  = 0;
   517 				byte chain_after  = 0;
   518 
   518 
   519 				for (u = GetFirstVehicleInChain(v); u != v; u = u->Next()) {
   519 				for (u = v->First(); u != v; u = u->Next()) {
   520 					chain_before++;
   520 					chain_before++;
   521 					if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0;
   521 					if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0;
   522 				}
   522 				}
   523 
   523 
   524 				while (u->Next() != NULL && (variable == 0x40 || u->Next()->engine_type == v->engine_type)) {
   524 				while (u->Next() != NULL && (variable == 0x40 || u->Next()->engine_type == v->engine_type)) {
   608 			 * B - current wagon to next wagon, 0 if wagon is last
   608 			 * B - current wagon to next wagon, 0 if wagon is last
   609 			 * T - previous wagon to next wagon, 0 in an S-bend
   609 			 * T - previous wagon to next wagon, 0 in an S-bend
   610 			 */
   610 			 */
   611 			if (v->type != VEH_TRAIN) return 0;
   611 			if (v->type != VEH_TRAIN) return 0;
   612 
   612 
   613 			const Vehicle *u_p = GetPrevVehicleInChain(v);
   613 			const Vehicle *u_p = v->Previous();
   614 			const Vehicle *u_n = v->Next();
   614 			const Vehicle *u_n = v->Next();
   615 			DirDiff f = (u_p == NULL) ?  DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
   615 			DirDiff f = (u_p == NULL) ?  DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
   616 			DirDiff b = (u_n == NULL) ?  DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
   616 			DirDiff b = (u_n == NULL) ?  DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
   617 			DirDiff t = ChangeDirDiff(f, b);
   617 			DirDiff t = ChangeDirDiff(f, b);
   618 
   618 
   756 				case 0x73: return v->u.rail.cached_veh_length;
   756 				case 0x73: return v->u.rail.cached_veh_length;
   757 				case 0x74: return v->u.rail.cached_power;
   757 				case 0x74: return v->u.rail.cached_power;
   758 				case 0x75: return GB(v->u.rail.cached_power,  8, 24);
   758 				case 0x75: return GB(v->u.rail.cached_power,  8, 24);
   759 				case 0x76: return GB(v->u.rail.cached_power, 16, 16);
   759 				case 0x76: return GB(v->u.rail.cached_power, 16, 16);
   760 				case 0x77: return GB(v->u.rail.cached_power, 24,  8);
   760 				case 0x77: return GB(v->u.rail.cached_power, 24,  8);
   761 				case 0x7C: return v->first->index;
   761 				case 0x7C: return v->First()->index;
   762 				case 0x7D: return GB(v->first->index, 8, 8);
   762 				case 0x7D: return GB(v->First()->index, 8, 8);
   763 				case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
   763 				case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
   764 			}
   764 			}
   765 			break;
   765 			break;
   766 
   766 
   767 		case VEH_ROAD:
   767 		case VEH_ROAD:
   802 	bool in_motion;
   802 	bool in_motion;
   803 
   803 
   804 	if (v == NULL) return group->g.real.loading[0];
   804 	if (v == NULL) return group->g.real.loading[0];
   805 
   805 
   806 	if (v->type == VEH_TRAIN) {
   806 	if (v->type == VEH_TRAIN) {
   807 		in_motion = GetFirstVehicleInChain(v)->current_order.type != OT_LOADING;
   807 		in_motion = v->First()->current_order.type != OT_LOADING;
   808 	} else {
   808 	} else {
   809 		in_motion = v->current_order.type != OT_LOADING;
   809 		in_motion = v->current_order.type != OT_LOADING;
   810 	}
   810 	}
   811 
   811 
   812 	totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
   812 	totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
   830 	res->SetTriggers   = &VehicleSetTriggers;
   830 	res->SetTriggers   = &VehicleSetTriggers;
   831 	res->GetVariable   = &VehicleGetVariable;
   831 	res->GetVariable   = &VehicleGetVariable;
   832 	res->ResolveReal   = &VehicleResolveReal;
   832 	res->ResolveReal   = &VehicleResolveReal;
   833 
   833 
   834 	res->u.vehicle.self   = v;
   834 	res->u.vehicle.self   = v;
   835 	res->u.vehicle.parent = (v != NULL && v->HasFront()) ? GetFirstVehicleInChain(v) : v;
   835 	res->u.vehicle.parent = (v != NULL && v->HasFront()) ? v->First() : v;
   836 
   836 
   837 	res->u.vehicle.self_type = engine_type;
   837 	res->u.vehicle.self_type = engine_type;
   838 
   838 
   839 	res->info_view = false;
   839 	res->info_view = false;
   840 
   840 
  1031 			 * same for all triggered vehicles in the chain (to get
  1031 			 * same for all triggered vehicles in the chain (to get
  1032 			 * all the random-cargo wagons carry the same cargo,
  1032 			 * all the random-cargo wagons carry the same cargo,
  1033 			 * i.e.), so we give them all the NEW_CARGO triggered
  1033 			 * i.e.), so we give them all the NEW_CARGO triggered
  1034 			 * vehicle's portion of random bits. */
  1034 			 * vehicle's portion of random bits. */
  1035 			assert(first);
  1035 			assert(first);
  1036 			DoTriggerVehicle((v->type == VEH_TRAIN) ? GetFirstVehicleInChain(v) : v, VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
  1036 			DoTriggerVehicle((v->type == VEH_TRAIN) ? v->First() : v, VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
  1037 			break;
  1037 			break;
  1038 
  1038 
  1039 		case VEHICLE_TRIGGER_DEPOT:
  1039 		case VEHICLE_TRIGGER_DEPOT:
  1040 			/* We now trigger the next vehicle in chain recursively.
  1040 			/* We now trigger the next vehicle in chain recursively.
  1041 			 * The random bits portions may be different for each
  1041 			 * The random bits portions may be different for each