src/vehicle.cpp
changeset 6247 7d81e3a5d803
parent 6198 5e278ec7c0f9
child 6248 e4a2ed7e5613
equal deleted inserted replaced
6246:75451000349d 6247:7d81e3a5d803
   215 	v->right_coord = pt.x + spr->width + 2;
   215 	v->right_coord = pt.x + spr->width + 2;
   216 	v->bottom_coord = pt.y + spr->height + 2;
   216 	v->bottom_coord = pt.y + spr->height + 2;
   217 }
   217 }
   218 
   218 
   219 // Called after load to update coordinates
   219 // Called after load to update coordinates
   220 void AfterLoadVehicles(void)
   220 void AfterLoadVehicles()
   221 {
   221 {
   222 	Vehicle *v;
   222 	Vehicle *v;
   223 
   223 
   224 	FOR_ALL_VEHICLES(v) {
   224 	FOR_ALL_VEHICLES(v) {
   225 		v->first = NULL;
   225 		v->first = NULL;
   282 
   282 
   283 /**
   283 /**
   284  * Get a value for a vehicle's random_bits.
   284  * Get a value for a vehicle's random_bits.
   285  * @return A random value from 0 to 255.
   285  * @return A random value from 0 to 255.
   286  */
   286  */
   287 byte VehicleRandomBits(void)
   287 byte VehicleRandomBits()
   288 {
   288 {
   289 	return GB(Random(), 0, 8);
   289 	return GB(Random(), 0, 8);
   290 }
   290 }
   291 
   291 
   292 Vehicle *ForceAllocateSpecialVehicle(void)
   292 Vehicle *ForceAllocateSpecialVehicle()
   293 {
   293 {
   294 	/* This stays a strange story.. there should always be room for special
   294 	/* This stays a strange story.. there should always be room for special
   295 	 * vehicles (special effects all over the map), but with 65k of vehicles
   295 	 * vehicles (special effects all over the map), but with 65k of vehicles
   296 	 * is this realistic to double-check for that? For now we just reserve
   296 	 * is this realistic to double-check for that? For now we just reserve
   297 	 * BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only
   297 	 * BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only
   342 
   342 
   343 	return NULL;
   343 	return NULL;
   344 }
   344 }
   345 
   345 
   346 
   346 
   347 Vehicle *AllocateVehicle(void)
   347 Vehicle *AllocateVehicle()
   348 {
   348 {
   349 	VehicleID counter = 0;
   349 	VehicleID counter = 0;
   350 	return AllocateSingleVehicle(&counter);
   350 	return AllocateSingleVehicle(&counter);
   351 }
   351 }
   352 
   352 
   444 		v->next_hash = *new_hash;
   444 		v->next_hash = *new_hash;
   445 		*new_hash = v;
   445 		*new_hash = v;
   446 	}
   446 	}
   447 }
   447 }
   448 
   448 
   449 void ResetVehiclePosHash(void)
   449 void ResetVehiclePosHash()
   450 {
   450 {
   451 	memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash));
   451 	memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash));
   452 }
   452 }
   453 
   453 
   454 void InitializeVehicles(void)
   454 void InitializeVehicles()
   455 {
   455 {
   456 	uint i;
   456 	uint i;
   457 
   457 
   458 	/* Clean the vehicle pool, and reserve enough blocks
   458 	/* Clean the vehicle pool, and reserve enough blocks
   459 	 *  for the special vehicles, plus one for all the other
   459 	 *  for the special vehicles, plus one for all the other
   645 	Aircraft_Tick,
   645 	Aircraft_Tick,
   646 	EffectVehicle_Tick,
   646 	EffectVehicle_Tick,
   647 	DisasterVehicle_Tick,
   647 	DisasterVehicle_Tick,
   648 };
   648 };
   649 
   649 
   650 void CallVehicleTicks(void)
   650 void CallVehicleTicks()
   651 {
   651 {
   652 	Vehicle *v;
   652 	Vehicle *v;
   653 
   653 
   654 #ifdef ENABLE_NETWORK
   654 #ifdef ENABLE_NETWORK
   655 	// hotfix for desync problem:
   655 	// hotfix for desync problem:
  3221 	_special_desc,
  3221 	_special_desc,
  3222 	_disaster_desc,
  3222 	_disaster_desc,
  3223 };
  3223 };
  3224 
  3224 
  3225 // Will be called when the vehicles need to be saved.
  3225 // Will be called when the vehicles need to be saved.
  3226 static void Save_VEHS(void)
  3226 static void Save_VEHS()
  3227 {
  3227 {
  3228 	Vehicle *v;
  3228 	Vehicle *v;
  3229 	// Write the vehicles
  3229 	// Write the vehicles
  3230 	FOR_ALL_VEHICLES(v) {
  3230 	FOR_ALL_VEHICLES(v) {
  3231 		SlSetArrayIndex(v->index);
  3231 		SlSetArrayIndex(v->index);
  3232 		SlObject(v, (SaveLoad*)_veh_descs[v->type]);
  3232 		SlObject(v, (SaveLoad*)_veh_descs[v->type]);
  3233 	}
  3233 	}
  3234 }
  3234 }
  3235 
  3235 
  3236 // Will be called when vehicles need to be loaded.
  3236 // Will be called when vehicles need to be loaded.
  3237 static void Load_VEHS(void)
  3237 static void Load_VEHS()
  3238 {
  3238 {
  3239 	int index;
  3239 	int index;
  3240 	Vehicle *v;
  3240 	Vehicle *v;
  3241 
  3241 
  3242 	while ((index = SlIterateArray()) != -1) {
  3242 	while ((index = SlIterateArray()) != -1) {