summaryrefslogtreecommitdiff
path: root/ship_gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'ship_gui.c')
-rw-r--r--ship_gui.c58
1 files changed, 21 insertions, 37 deletions
diff --git a/ship_gui.c b/ship_gui.c
index 49006f9bf..90c12eab6 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -138,7 +138,7 @@ static const WindowDesc _ship_refit_desc = {
ShipRefitWndProc,
};
-static void ShowShipRefitWindow(Vehicle *v)
+static void ShowShipRefitWindow(const Vehicle* v)
{
Window *w;
@@ -287,7 +287,7 @@ static const WindowDesc _ship_details_desc = {
ShipDetailsWndProc
};
-static void ShowShipDetailsWindow(Vehicle *v)
+static void ShowShipDetailsWindow(const Vehicle* v)
{
Window *w;
VehicleID veh = v->index;
@@ -314,11 +314,11 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
void CcCloneShip(bool success, uint tile, uint32 p1, uint32 p2)
{
- Vehicle *v;
- if (!success) return;
+ if (success) {
+ const Vehicle* v = GetVehicle(_new_aircraft_id);
- v = GetVehicle(_new_ship_id);
- ShowShipViewWindow(v);
+ ShowShipViewWindow(v);
+ }
}
static void NewShipWndProc(Window *w, WindowEvent *e)
@@ -528,9 +528,9 @@ static void ShipViewWndProc(Window *w, WindowEvent *e) {
} break;
case WE_CLICK: {
- Vehicle *v = GetVehicle(w->window_number);
+ const Vehicle* v = GetVehicle(w->window_number);
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 5: /* start stop */
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
break;
@@ -551,8 +551,6 @@ static void ShipViewWndProc(Window *w, WindowEvent *e) {
break;
case 11: {
/* clone vehicle */
- Vehicle *v;
- v = GetVehicle(w->window_number);
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
} break;
}
@@ -611,12 +609,11 @@ static const WindowDesc _ship_view_desc = {
ShipViewWndProc
};
-void ShowShipViewWindow(Vehicle *v)
+void ShowShipViewWindow(const Vehicle* v)
{
- Window *w;
+ Window* w = AllocateWindowDescFront(&_ship_view_desc, v->index);
- w = AllocateWindowDescFront(&_ship_view_desc, v->index);
- if (w) {
+ if (w != NULL) {
w->caption_color = v->owner;
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
}
@@ -745,34 +742,22 @@ static void ShipDepotClick(Window *w, int x, int y)
* @param *v is the original vehicle to clone
* @param *w is the window of the depot where the clone is build
*/
-static bool HandleCloneVehClick(Vehicle *v, Window *w)
+static void HandleCloneVehClick(const Vehicle* v, const Window* w)
{
+ if (v == NULL || v->type != VEH_Ship) return;
- if (!v){
- return false;
- }
-
- if (v->type != VEH_Ship) {
- // it's not a ship, do nothing
- return false;
- }
-
-
- DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,CcCloneShip,CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
+ DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip,
+ CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)
+ );
ResetObjectToPlace();
-
- return true;
}
-static void ClonePlaceObj(uint tile, Window *w)
+static void ClonePlaceObj(TileIndex tile, const Window* w)
{
- Vehicle *v;
+ Vehicle* v = CheckMouseOverVehicle();
-
- v = CheckMouseOverVehicle();
- if (v && HandleCloneVehClick(v, w))
- return;
+ if (v != NULL) HandleCloneVehClick(v, w);
}
static void ShipDepotWndProc(Window *w, WindowEvent *e) {
@@ -812,7 +797,6 @@ static void ShipDepotWndProc(Window *w, WindowEvent *e) {
break;
case WE_PLACE_OBJ: {
- //ClonePlaceObj(e->place.tile, w);
ClonePlaceObj(w->window_number, w);
} break;
@@ -823,9 +807,9 @@ static void ShipDepotWndProc(Window *w, WindowEvent *e) {
// check if a vehicle in a depot was clicked..
case WE_MOUSELOOP: {
- Vehicle *v = _place_clicked_vehicle;
+ const Vehicle* v = _place_clicked_vehicle;
- // since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
+ // since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
if (v != NULL && HASBIT(w->click_state, 8)) {
_place_clicked_vehicle = NULL;
HandleCloneVehClick(v, w);