Changeset - r6621:c0fe19bbb51d
[Not reviewed]
master
0 7 0
rubidium - 17 years ago 2007-05-15 11:28:22
rubidium@openttd.org
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
7 files changed with 15 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -128,24 +128,25 @@ static const WindowDesc _aircraft_depot_
 
};
 

	
 
extern int WagonLengthToPixels(int len);
 

	
 
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (!success) return;
 
	switch(GetVehicle(p1)->type) {
 
		case VEH_TRAIN:    CcCloneTrain(   true, tile, p1, p2); break;
 
		case VEH_ROAD:     CcCloneRoadVeh( true, tile, p1, p2); break;
 
		case VEH_SHIP:     CcCloneShip(    true, tile, p1, p2); break;
 
		case VEH_AIRCRAFT: CcCloneAircraft(true, tile, p1, p2); break;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
static inline void ShowVehicleViewWindow(const Vehicle *v)
 
{
 
	switch (v->type) {
 
		case VEH_TRAIN:    ShowTrainViewWindow(v);    break;
 
		case VEH_ROAD:     ShowRoadVehViewWindow(v);  break;
 
		case VEH_SHIP:     ShowShipViewWindow(v);     break;
 
		case VEH_AIRCRAFT: ShowAircraftViewWindow(v); break;
 
		default: NOT_REACHED();
 
	}
src/economy.cpp
Show inline comments
 
@@ -356,24 +356,25 @@ void ChangeOwnershipOfPlayerItems(Player
 
					DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
					DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
 
					DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
 
					DeleteVehicle(v);
 
				} else {
 
					v->owner = new_player;
 
					if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++;
 
					switch (v->type) {
 
						case VEH_TRAIN:    if (IsFrontEngine(v)) v->unitnumber = ++num_train; break;
 
						case VEH_ROAD:     v->unitnumber = ++num_road; break;
 
						case VEH_SHIP:     v->unitnumber = ++num_ship; break;
 
						case VEH_AIRCRAFT: if (IsNormalAircraft(v)) v->unitnumber = ++num_aircraft; break;
 
						default: NOT_REACHED();
 
					}
 
				}
 
			}
 
		}
 
	}
 

	
 
	/*  Change ownership of tiles */
 
	{
 
		TileIndex tile = 0;
 
		do {
 
			ChangeTileOwner(tile, old_player, new_player);
 
		} while (++tile != MapSize());
src/network/network_server.cpp
Show inline comments
 
@@ -1292,27 +1292,25 @@ void NetworkPopulateCompanyInfo()
 
					_network_player_info[v->owner].num_vehicle[2]++;
 
				}
 
				break;
 

	
 
			case VEH_AIRCRAFT:
 
				if (IsNormalAircraft(v)) _network_player_info[v->owner].num_vehicle[3]++;
 
				break;
 

	
 
			case VEH_SHIP:
 
				_network_player_info[v->owner].num_vehicle[4]++;
 
				break;
 

	
 
			case VEH_SPECIAL:
 
			case VEH_DISASTER:
 
				break;
 
			default: break;
 
		}
 
	}
 

	
 
	// Go through all stations and count the types of stations
 
	FOR_ALL_STATIONS(s) {
 
		if (IsValidPlayer(s->owner)) {
 
			NetworkPlayerInfo *npi = &_network_player_info[s->owner];
 

	
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[0]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[2]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[3]++;
src/newgrf_engine.cpp
Show inline comments
 
@@ -761,24 +761,26 @@ static uint32 VehicleGetVariable(const R
 
				case 0x68: return v->u.road.crashed_ctr;
 
				case 0x69: return GB(v->u.road.crashed_ctr, 8, 8);
 
			}
 
			break;
 

	
 
		case VEH_AIRCRAFT:
 
			switch (variable - 0x80) {
 
				case 0x62: return MapAircraftMovementState(v);  // Current movement state
 
				case 0x63: return v->u.air.targetairport;       // Airport to which the action refers
 
				case 0x66: return MapAircraftMovementAction(v); // Current movement action
 
			}
 
			break;
 

	
 
		default: break;
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled vehicle property 0x%X, type 0x%X", variable, v->type);
 

	
 
	*available = false;
 
	return UINT_MAX;
 
}
 

	
 

	
 
static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const SpriteGroup *group)
 
{
 
	const Vehicle *v = object->u.vehicle.self;
src/vehicle.cpp
Show inline comments
 
@@ -668,24 +668,26 @@ void CallVehicleTicks()
 
#endif //ENABLE_NETWORK
 

	
 
	_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick
 

	
 
	Station *st;
 
	FOR_ALL_STATIONS(st) LoadUnloadStation(st);
 

	
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		_vehicle_tick_procs[v->type](v);
 

	
 
		switch (v->type) {
 
			default: break;
 

	
 
			case VEH_TRAIN:
 
			case VEH_ROAD:
 
			case VEH_AIRCRAFT:
 
			case VEH_SHIP:
 
				if (v->type == VEH_TRAIN && IsTrainWagon(v)) continue;
 
				if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue;
 

	
 
				v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed;
 
				/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */
 
				if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING);
 

	
 
				/* Play an alterate running sound every 16 ticks */
 
@@ -2841,24 +2843,25 @@ static void Load_VEHS()
 

	
 
		v = GetVehicle(index);
 
		SlObject(v, (SaveLoad*)_veh_descs[SlReadByte()]);
 

	
 
		switch (v->type) {
 
			case VEH_TRAIN:    v = new (v) Train();           break;
 
			case VEH_ROAD:     v = new (v) RoadVehicle();     break;
 
			case VEH_SHIP:     v = new (v) Ship();            break;
 
			case VEH_AIRCRAFT: v = new (v) Aircraft();        break;
 
			case VEH_SPECIAL:  v = new (v) SpecialVehicle();  break;
 
			case VEH_DISASTER: v = new (v) DisasterVehicle(); break;
 
			case VEH_INVALID:  v = new (v) InvalidVehicle();  break;
 
			default: NOT_REACHED();
 
		}
 

	
 
		/* Old savegames used 'last_station_visited = 0xFF' */
 
		if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF)
 
			v->last_station_visited = INVALID_STATION;
 

	
 
		if (CheckSavegameVersion(5)) {
 
			/* Convert the current_order.type (which is a mix of type and flags, because
 
			 *  in those versions, they both were 4 bits big) to type and flags */
 
			v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
 
			v->current_order.type.m_val &= 0x0F;
 
		}
src/vehicle.h
Show inline comments
 
@@ -55,33 +55,36 @@ enum RoadVehicleStates {
 
	RVS_IN_DT_ROAD_STOP          =    6,                      ///< The vehicle is in a drive-through road stop
 

	
 
	/* Bit sets of the above specified bits */
 
	RVSB_IN_ROAD_STOP            = 1 << RVS_IN_ROAD_STOP,     ///< The vehicle is in a road stop
 
	RVSB_IN_ROAD_STOP_END        = RVSB_IN_ROAD_STOP + TRACKDIR_END,
 
	RVSB_IN_DT_ROAD_STOP         = 1 << RVS_IN_DT_ROAD_STOP,  ///< The vehicle is in a drive-through road stop
 
	RVSB_IN_DT_ROAD_STOP_END     = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
 

	
 
	RVSB_TRACKDIR_MASK           = 0x0F,                      ///< The mask used to extract track dirs
 
	RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09                       ///< Only bits 0 and 3 are used to encode the trackdir for road stops
 
};
 

	
 
enum {
 
enum VehicleType {
 
	VEH_TRAIN,
 
	VEH_ROAD,
 
	VEH_SHIP,
 
	VEH_AIRCRAFT,
 
	VEH_SPECIAL,
 
	VEH_DISASTER,
 
	VEH_END,
 
	VEH_INVALID = 0xFF,
 
} ;
 
};
 
template <> struct EnumPropsT<VehicleType> : MakeEnumPropsT<VehicleType, byte, VEH_TRAIN, VEH_END, VEH_INVALID> {};
 
typedef TinyEnumT<VehicleType> VehicleTypeByte;
 

	
 
enum VehStatus {
 
	VS_HIDDEN          = 0x01,
 
	VS_STOPPED         = 0x02,
 
	VS_UNCLICKABLE     = 0x04,
 
	VS_DEFPAL          = 0x08,
 
	VS_TRAIN_SLOWING   = 0x10,
 
	VS_SHADOW          = 0x20,
 
	VS_AIRCRAFT_BROKEN = 0x40,
 
	VS_CRASHED         = 0x80,
 
};
 

	
 
@@ -194,25 +197,25 @@ struct VehicleSpecial {
 

	
 
struct VehicleDisaster {
 
	uint16 image_override;
 
	uint16 unk2;
 
};
 

	
 
struct VehicleShip {
 
	TrackBitsByte state;
 
};
 

	
 

	
 
struct Vehicle {
 
	byte type;               // type, ie roadven,train,ship,aircraft,special
 
	VehicleTypeByte type;    ///< Type of vehicle
 
	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
 

	
 
	VehicleID index;         // NOSAVE: Index in vehicle array
 

	
 
	Vehicle *next;           // next
 
	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
 
	Vehicle *depot_list;     //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
 

	
 
	StringID string_id;      // Displayed string
 

	
 
	UnitID unitnumber;       // unit number, for display purposes only
 
	PlayerByte owner;        // which player owns the vehicle?
src/vehicle_gui.cpp
Show inline comments
 
@@ -368,24 +368,25 @@ static void VehicleRefitWndProc(Window *
 
						WP(w, refit_d).sel = (y / (int)w->resize.step_height) + w->vscroll.pos;
 
						SetWindowDirty(w);
 
					}
 
				} break;
 
				case 6: // refit button
 
					if (WP(w, refit_d).cargo != NULL) {
 
						const Vehicle *v = GetVehicle(w->window_number);
 

	
 
						if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) {
 
							int command = 0;
 

	
 
							switch (v->type) {
 
								default: NOT_REACHED();
 
								case VEH_TRAIN:    command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE);  break;
 
								case VEH_ROAD:     command = CMD_REFIT_ROAD_VEH     | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T);  break;
 
								case VEH_SHIP:     command = CMD_REFIT_SHIP         | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP);     break;
 
								case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT     | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
 
							}
 
							if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w);
 
						} else {
 
							if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8 | WP(w, refit_d).order << 16, NULL, CMD_ORDER_REFIT)) DeleteWindow(w);
 
						}
 
					}
 
					break;
 
			}
0 comments (0 inline, 0 general)