--- a/src/ship_cmd.cpp Wed Jun 13 11:17:30 2007 +0000
+++ b/src/ship_cmd.cpp Wed Jun 13 11:45:14 2007 +0000
@@ -165,6 +165,7 @@
return;
}
+ if (v->current_order.type == OT_LOADING) v->LeaveStation();
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
v->current_order.dest = depot->index;
@@ -187,7 +188,7 @@
if (v->vehstatus & VS_STOPPED) return;
- cost = ShipVehInfo(v->engine_type)->running_cost * _eco->GetPrice(CEconomy::SHIP_RUNNING) / 364;
+ cost = GetVehicleProperty(v, 0x0F, ShipVehInfo(v->engine_type)->running_cost) * _eco->GetPrice(CEconomy::SHIP_RUNNING) / 364;
v->profit_this_year -= cost >> 8;
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN);
@@ -229,19 +230,24 @@
}
}
-static void MarkShipDirty(Vehicle *v)
+void Ship::MarkDirty()
{
- v->cur_image = GetShipImage(v, v->direction);
- MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
+ this->cur_image = GetShipImage(this, this->direction);
+ MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
}
-static void PlayShipSound(Vehicle *v)
+static void PlayShipSound(const Vehicle *v)
{
if (!PlayVehicleSound(v, VSE_START)) {
SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v);
}
}
+void Ship::PlayLeaveStationSound() const
+{
+ PlayShipSound(this);
+}
+
static void ProcessShipOrder(Vehicle *v)
{
const Order *order;
@@ -300,66 +306,34 @@
InvalidateWindowClasses(WC_SHIPS_LIST);
}
-static void HandleShipLoading(Vehicle *v)
+void Ship::UpdateDeltaXY(Direction direction)
{
- switch (v->current_order.type) {
- case OT_LOADING: {
- if (--v->load_unload_time_rem) return;
-
- if (CanFillVehicle(v) && (
- v->current_order.flags & OF_FULL_LOAD ||
- (_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED))
- )) {
- SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
- if (LoadUnloadVehicle(v, false)) {
- InvalidateWindow(WC_SHIPS_LIST, v->owner);
- MarkShipDirty(v);
- }
- return;
- }
- PlayShipSound(v);
-
- Order b = v->current_order;
- v->LeaveStation();
- if (!(b.flags & OF_NON_STOP)) return;
- break;
- }
-
- case OT_DUMMY: break;
-
- default: return;
- }
-
- v->cur_order_index++;
- InvalidateVehicleOrder(v);
-}
-
-static void UpdateShipDeltaXY(Vehicle *v, int dir)
-{
-#define MKIT(d,c,b,a) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0)
+#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)
static const uint32 _delta_xy_table[8] = {
- MKIT( -3, -3, 6, 6),
- MKIT(-16, -3, 32, 6),
- MKIT( -3, -3, 6, 6),
- MKIT( -3, -16, 6, 32),
- MKIT( -3, -3, 6, 6),
- MKIT(-16, -3, 32, 6),
- MKIT( -3, -3, 6, 6),
- MKIT( -3, -16, 6, 32),
+ MKIT( 6, 6, -3, -3),
+ MKIT( 6, 32, -3, -16),
+ MKIT( 6, 6, -3, -3),
+ MKIT(32, 6, -16, -3),
+ MKIT( 6, 6, -3, -3),
+ MKIT( 6, 32, -3, -16),
+ MKIT( 6, 6, -3, -3),
+ MKIT(32, 6, -16, -3),
};
#undef MKIT
- uint32 x = _delta_xy_table[dir];
- v->x_offs = GB(x, 0, 8);
- v->y_offs = GB(x, 8, 8);
- v->sprite_width = GB(x, 16, 8);
- v->sprite_height = GB(x, 24, 8);
+
+ uint32 x = _delta_xy_table[direction];
+ this->x_offs = GB(x, 0, 8);
+ this->y_offs = GB(x, 8, 8);
+ this->sprite_width = GB(x, 16, 8);
+ this->sprite_height = GB(x, 24, 8);
+ this->z_height = 6;
}
void RecalcShipStuff(Vehicle *v)
{
- UpdateShipDeltaXY(v, v->direction);
+ v->UpdateDeltaXY(v->direction);
v->cur_image = GetShipImage(v, v->direction);
- MarkShipDirty(v);
+ v->MarkDirty();
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
}
@@ -428,7 +402,7 @@
static int32 EstimateShipCost(EngineID engine_type)
{
- return ShipVehInfo(engine_type)->base_cost * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5;
+ return GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5;
}
static void ShipArrivesAt(const Vehicle* v, Station* st)
@@ -683,7 +657,7 @@
if (v->vehstatus & VS_STOPPED) return;
ProcessShipOrder(v);
- HandleShipLoading(v);
+ v->HandleLoading();
if (v->current_order.type == OT_LOADING) return;
@@ -735,17 +709,8 @@
/* Process station in the orderlist. */
st = GetStation(v->current_order.dest);
if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
- v->BeginLoading();
- v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER;
- v->current_order.flags |= OF_NON_STOP;
ShipArrivesAt(v, st);
-
- SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
- if (LoadUnloadVehicle(v, true)) {
- InvalidateWindow(WC_SHIPS_LIST, v->owner);
- MarkShipDirty(v);
- }
- InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
+ v->BeginLoading();
} else { // leave stations without docks right aways
v->current_order.type = OT_LEAVESTATION;
v->cur_order_index++;
@@ -797,7 +762,7 @@
v->z_pos = GetSlopeZ(gp.x, gp.y);
getout:
- UpdateShipDeltaXY(v, dir);
+ v->UpdateDeltaXY(dir);
v->cur_image = GetShipImage(v, dir);
VehiclePositionChanged(v);
EndVehicleMove(v);
@@ -882,11 +847,7 @@
v->y_pos = y;
v->z_pos = GetSlopeZ(x, y);
- v->z_height = 6;
- v->sprite_width = 6;
- v->sprite_height = 6;
- v->x_offs = -3;
- v->y_offs = -3;
+ v->UpdateDeltaXY(v->direction);
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
v->spritenum = svi->image_index;
@@ -912,12 +873,14 @@
v->date_of_last_service = _date;
v->build_year = _cur_year;
v->cur_image = 0x0E5E;
- v->type = VEH_SHIP;
+ v = new (v) Ship();
v->random_bits = VehicleRandomBits();
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
+ v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
+
VehiclePositionChanged(v);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -1087,6 +1050,8 @@
* @param p2 various bitstuffed elements
* - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
* - p2 = (bit 8-15) - the new cargo subtype to refit to
+ * - p2 = (bit 16) - refit only this vehicle (ignored)
+ * @return cost of refit or error
*/
int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
@@ -1128,7 +1093,7 @@
}
if (capacity == CALLBACK_FAILED) {
- capacity = ShipVehInfo(v->engine_type)->capacity;
+ capacity = GetVehicleProperty(v, 0x0D, ShipVehInfo(v->engine_type)->capacity);
}
_returned_refit_capacity = capacity;