Mercurial > hg > openttd
comparison src/roadveh_cmd.cpp @ 7134:e1c4f52f82cd draft
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 01 Jul 2007 19:11:47 +0000 |
parents | c1b9f000066e |
children | 45123abbc930 |
comparison
equal
deleted
inserted
replaced
7133:148c6c10ffa7 | 7134:e1c4f52f82cd |
---|---|
83 /** Converts the exit direction of a depot to trackdir the vehicle is going to drive to */ | 83 /** Converts the exit direction of a depot to trackdir the vehicle is going to drive to */ |
84 static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = { | 84 static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = { |
85 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW | 85 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW |
86 }; | 86 }; |
87 | 87 |
88 int GetRoadVehImage(const Vehicle* v, Direction direction) | 88 int RoadVehicle::GetImage(Direction direction) const |
89 { | 89 { |
90 int img = v->spritenum; | 90 int img = this->spritenum; |
91 int image; | 91 int image; |
92 | 92 |
93 if (is_custom_sprite(img)) { | 93 if (is_custom_sprite(img)) { |
94 image = GetCustomVehicleSprite(v, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img))); | 94 image = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img))); |
95 if (image != 0) return image; | 95 if (image != 0) return image; |
96 img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; | 96 img = orig_road_vehicle_info[this->engine_type - ROAD_ENGINES_INDEX].image_index; |
97 } | 97 } |
98 | 98 |
99 image = direction + _roadveh_images[img]; | 99 image = direction + _roadveh_images[img]; |
100 if (v->cargo.Count() >= v->cargo_cap / 2U) image += _roadveh_full_adder[img]; | 100 if (this->cargo.Count() >= this->cargo_cap / 2U) image += _roadveh_full_adder[img]; |
101 return image; | 101 return image; |
102 } | 102 } |
103 | 103 |
104 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal) | 104 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal) |
105 { | 105 { |
553 } | 553 } |
554 | 554 |
555 | 555 |
556 void RoadVehicle::MarkDirty() | 556 void RoadVehicle::MarkDirty() |
557 { | 557 { |
558 this->cur_image = GetRoadVehImage(this, this->direction); | 558 this->cur_image = this->GetImage(this->direction); |
559 MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); | 559 MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); |
560 } | 560 } |
561 | 561 |
562 void RoadVehicle::UpdateDeltaXY(Direction direction) | 562 void RoadVehicle::UpdateDeltaXY(Direction direction) |
563 { | 563 { |
639 uint32 r = Random(); | 639 uint32 r = Random(); |
640 | 640 |
641 v->direction = ChangeDir(v->direction, delta[r & 3]); | 641 v->direction = ChangeDir(v->direction, delta[r & 3]); |
642 BeginVehicleMove(v); | 642 BeginVehicleMove(v); |
643 v->UpdateDeltaXY(v->direction); | 643 v->UpdateDeltaXY(v->direction); |
644 v->cur_image = GetRoadVehImage(v, v->direction); | 644 v->cur_image = v->GetImage(v->direction); |
645 SetRoadVehPosition(v, v->x_pos, v->y_pos); | 645 SetRoadVehPosition(v, v->x_pos, v->y_pos); |
646 } while ((v = v->next) != NULL); | 646 } while ((v = v->next) != NULL); |
647 } | 647 } |
648 | 648 |
649 static void RoadVehIsCrashed(Vehicle *v) | 649 static void RoadVehIsCrashed(Vehicle *v) |
1364 | 1364 |
1365 v->vehstatus &= ~VS_HIDDEN; | 1365 v->vehstatus &= ~VS_HIDDEN; |
1366 v->u.road.state = tdir; | 1366 v->u.road.state = tdir; |
1367 v->u.road.frame = RVC_DEPOT_START_FRAME; | 1367 v->u.road.frame = RVC_DEPOT_START_FRAME; |
1368 | 1368 |
1369 v->cur_image = GetRoadVehImage(v, v->direction); | 1369 v->cur_image = v->GetImage(v->direction); |
1370 v->UpdateDeltaXY(v->direction); | 1370 v->UpdateDeltaXY(v->direction); |
1371 SetRoadVehPosition(v,x,y); | 1371 SetRoadVehPosition(v,x,y); |
1372 | 1372 |
1373 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); | 1373 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1374 | 1374 |
1457 return false; | 1457 return false; |
1458 } | 1458 } |
1459 | 1459 |
1460 if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { | 1460 if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { |
1461 /* Vehicle has just entered a bridge or tunnel */ | 1461 /* Vehicle has just entered a bridge or tunnel */ |
1462 v->cur_image = GetRoadVehImage(v, v->direction); | 1462 v->cur_image = v->GetImage(v->direction); |
1463 v->UpdateDeltaXY(v->direction); | 1463 v->UpdateDeltaXY(v->direction); |
1464 SetRoadVehPosition(v,gp.x,gp.y); | 1464 SetRoadVehPosition(v,gp.x,gp.y); |
1465 return true; | 1465 return true; |
1466 } | 1466 } |
1467 | 1467 |
1572 if (newdir != v->direction) { | 1572 if (newdir != v->direction) { |
1573 v->direction = newdir; | 1573 v->direction = newdir; |
1574 v->cur_speed -= v->cur_speed >> 2; | 1574 v->cur_speed -= v->cur_speed >> 2; |
1575 } | 1575 } |
1576 | 1576 |
1577 v->cur_image = GetRoadVehImage(v, newdir); | 1577 v->cur_image = v->GetImage(newdir); |
1578 v->UpdateDeltaXY(v->direction); | 1578 v->UpdateDeltaXY(v->direction); |
1579 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); | 1579 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
1580 return true; | 1580 return true; |
1581 } | 1581 } |
1582 | 1582 |
1612 if (newdir != v->direction) { | 1612 if (newdir != v->direction) { |
1613 v->direction = newdir; | 1613 v->direction = newdir; |
1614 v->cur_speed -= v->cur_speed >> 2; | 1614 v->cur_speed -= v->cur_speed >> 2; |
1615 } | 1615 } |
1616 | 1616 |
1617 v->cur_image = GetRoadVehImage(v, newdir); | 1617 v->cur_image = v->GetImage(newdir); |
1618 v->UpdateDeltaXY(v->direction); | 1618 v->UpdateDeltaXY(v->direction); |
1619 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); | 1619 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
1620 return true; | 1620 return true; |
1621 } | 1621 } |
1622 | 1622 |
1654 if (new_dir != old_dir) { | 1654 if (new_dir != old_dir) { |
1655 v->direction = new_dir; | 1655 v->direction = new_dir; |
1656 v->cur_speed -= (v->cur_speed >> 2); | 1656 v->cur_speed -= (v->cur_speed >> 2); |
1657 if (old_dir != v->u.road.state) { | 1657 if (old_dir != v->u.road.state) { |
1658 /* The vehicle is in a road stop */ | 1658 /* The vehicle is in a road stop */ |
1659 v->cur_image = GetRoadVehImage(v, new_dir); | 1659 v->cur_image = v->GetImage(new_dir); |
1660 v->UpdateDeltaXY(v->direction); | 1660 v->UpdateDeltaXY(v->direction); |
1661 SetRoadVehPosition(v, v->x_pos, v->y_pos); | 1661 SetRoadVehPosition(v, v->x_pos, v->y_pos); |
1662 /* Note, return here means that the frame counter is not incremented | 1662 /* Note, return here means that the frame counter is not incremented |
1663 * for vehicles changing direction in a road stop. This causes frames to | 1663 * for vehicles changing direction in a road stop. This causes frames to |
1664 * be repeated. (XXX) Is this intended? */ | 1664 * be repeated. (XXX) Is this intended? */ |
1774 | 1774 |
1775 /* Move to next frame unless vehicle arrived at a stop position | 1775 /* Move to next frame unless vehicle arrived at a stop position |
1776 * in a depot or entered a tunnel/bridge */ | 1776 * in a depot or entered a tunnel/bridge */ |
1777 if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++; | 1777 if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++; |
1778 | 1778 |
1779 v->cur_image = GetRoadVehImage(v, v->direction); | 1779 v->cur_image = v->GetImage(v->direction); |
1780 v->UpdateDeltaXY(v->direction); | 1780 v->UpdateDeltaXY(v->direction); |
1781 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); | 1781 RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
1782 return true; | 1782 return true; |
1783 } | 1783 } |
1784 | 1784 |