MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateDeltaXY

Method UpdateDeltaXY

src/roadveh_cmd.cpp:405–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403}
404
405void RoadVehicle::UpdateDeltaXY()
406{
407 /* Set common defaults. */
408 this->bounds = {{-1, -1, 0}, {3, 3, 6}, {}};
409
410 if (!IsDiagonalDirection(this->direction)) {
411 static const Point _sign_table[] = {
412 /* x, y */
413 {-1, -1}, // DIR_N
414 {-1, 1}, // DIR_E
415 { 1, 1}, // DIR_S
416 { 1, -1}, // DIR_W
417 };
418
419 int half_shorten = (VEHICLE_LENGTH - this->gcache.cached_veh_length) / 2;
420
421 /* For all straight directions, move the bound box to the centre of the vehicle, but keep the size. */
422 this->bounds.offset.x -= half_shorten * _sign_table[DirToDiagDir(this->direction)].x;
423 this->bounds.offset.y -= half_shorten * _sign_table[DirToDiagDir(this->direction)].y;
424 } else {
425 /* Unlike trains, road vehicles do not have their offsets moved to the centre. */
426 switch (this->direction) {
427 /* Shorten southern corner of the bounding box according the vehicle length. */
428 case DIR_NE:
429 this->bounds.origin.x = -3;
430 this->bounds.extent.x = this->gcache.cached_veh_length;
431 this->bounds.offset.x = 1;
432 break;
433
434 case DIR_NW:
435 this->bounds.origin.y = -3;
436 this->bounds.extent.y = this->gcache.cached_veh_length;
437 this->bounds.offset.y = 1;
438 break;
439
440 /* Move northern corner of the bounding box down according to vehicle length. */
441 case DIR_SW:
442 this->bounds.origin.x = -3 + (VEHICLE_LENGTH - this->gcache.cached_veh_length);
443 this->bounds.extent.x = this->gcache.cached_veh_length;
444 this->bounds.offset.x = 1 - (VEHICLE_LENGTH - this->gcache.cached_veh_length);
445 break;
446
447 case DIR_SE:
448 this->bounds.origin.y = -3 + (VEHICLE_LENGTH - this->gcache.cached_veh_length);
449 this->bounds.extent.y = this->gcache.cached_veh_length;
450 this->bounds.offset.y = 1 - (VEHICLE_LENGTH - this->gcache.cached_veh_length);
451 break;
452
453 default:
454 NOT_REACHED();
455 }
456 }
457}
458
459/**
460 * Calculates the maximum speed of the vehicle under its current conditions.

Callers

nothing calls this directly

Calls 3

IsDiagonalDirectionFunction · 0.85
DirToDiagDirFunction · 0.85
NOT_REACHEDFunction · 0.85

Tested by

no test coverage detected