summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-05-22 19:48:11 +0000
committerpeter1138 <peter1138@openttd.org>2007-05-22 19:48:11 +0000
commit2125b963871bee82d48cd9b684352e54ab2610ed (patch)
tree2f72d3272da86043ee08907353ec8e4e0d74b928
parentb7748a686eca83d53eddf0be888e6f58eb12d054 (diff)
downloadopenttd-2125b963871bee82d48cd9b684352e54ab2610ed.tar.xz
(svn r9898) -Fix (r9874): Many...
- Group protection status wasn't changed via a command. - Group renaming didn't check group owner (and in fact changed the owner, just like renaming a sign...). - Added owner checks to other group commands. - Invalidate window data after the command has been completed instead of after the command has been sent. This fixes gui issues in network play.
-rw-r--r--src/command.cpp3
-rw-r--r--src/command.h1
-rw-r--r--src/group_cmd.cpp64
-rw-r--r--src/group_gui.cpp52
4 files changed, 86 insertions, 34 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 3fa2bcfec..8c4322350 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -174,6 +174,8 @@ DEF_COMMAND(CmdDeleteGroup);
DEF_COMMAND(CmdAddVehicleGroup);
DEF_COMMAND(CmdAddSharedVehicleGroup);
DEF_COMMAND(CmdRemoveAllVehiclesGroup);
+DEF_COMMAND(CmdSetGroupReplaceProtection);
+
/* The master command table */
static const Command _command_proc_table[] = {
{CmdBuildRailroadTrack, 0}, /* 0 */
@@ -325,6 +327,7 @@ static const Command _command_proc_table[] = {
{CmdAddVehicleGroup, 0}, /* 123 */
{CmdAddSharedVehicleGroup, 0}, /* 124 */
{CmdRemoveAllVehiclesGroup, 0}, /* 125 */
+ {CmdSetGroupReplaceProtection, 0}, /* 126 */
};
/* This function range-checks a cmd, and checks if the cmd is not NULL */
diff --git a/src/command.h b/src/command.h
index 4cf9844e3..0440466dc 100644
--- a/src/command.h
+++ b/src/command.h
@@ -149,6 +149,7 @@ enum {
CMD_ADD_VEHICLE_GROUP = 123,
CMD_ADD_SHARED_VEHICLE_GROUP = 124,
CMD_REMOVE_ALL_VEHICLES_GROUP = 125,
+ CMD_SET_GROUP_REPLACE_PROTECTION = 126,
};
enum {
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 72032e0c7..bf445b3c3 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -15,6 +15,8 @@
#include "train.h"
#include "aircraft.h"
#include "string.h"
+#include "window.h"
+#include "vehicle_gui.h"
/**
* Update the num engines of a groupID. Decrease the old one and increase the new one
@@ -73,6 +75,18 @@ void InitializeGroup(void)
}
+static WindowClass GetWCForVT(VehicleType vt)
+{
+ switch (vt) {
+ default:
+ case VEH_TRAIN: return WC_TRAINS_LIST;
+ case VEH_ROAD: return WC_ROADVEH_LIST;
+ case VEH_SHIP: return WC_SHIPS_LIST;
+ case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
+ }
+}
+
+
/**
* Add a vehicle to a group
* @param tile unused
@@ -92,6 +106,8 @@ int32 CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
g->string_id = STR_SV_GROUP_NAME;
g->replace_protection = false;
g->vehicle_type = vt;
+
+ InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
@@ -131,9 +147,13 @@ int32 CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
}
+ VehicleType vt = g->vehicle_type;
+
/* Delete the Replace Vehicle Windows */
DeleteWindowById(WC_REPLACE_VEHICLE, g->vehicle_type);
DeleteGroup(g);
+
+ InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
@@ -151,18 +171,20 @@ int32 CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
+ Group *g = GetGroup(p1);
+ if (g->owner != _current_player) return CMD_ERROR;
+
/* Create the name */
StringID str = AllocateName(_cmd_text, 0);
if (str == STR_NULL) return CMD_ERROR;
if (flags & DC_EXEC) {
- Group *g = GetGroup(p1);
-
/* Delete the old name */
DeleteName(g->string_id);
/* Assign the new one */
g->string_id = str;
- g->owner = _current_player;
+
+ InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
@@ -183,6 +205,9 @@ int32 CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
+ Group *g = GetGroup(new_g);
+ if (g->owner != _current_player) return CMD_ERROR;
+
Vehicle *v = GetVehicle(p2);
if (v->owner != _current_player || (v->type == VEH_TRAIN && !IsFrontEngine(v))) return CMD_ERROR;
@@ -205,6 +230,7 @@ int32 CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Update the Replace Vehicle Windows */
InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
+ InvalidateWindowData(GetWCForVT(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
@@ -242,6 +268,8 @@ int32 CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p
}
}
}
+
+ InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
@@ -260,6 +288,9 @@ int32 CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32
VehicleType type = (VehicleType)p2;
if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
+ Group *g = GetGroup(p1);
+ if (g->owner != _current_player) return CMD_ERROR;
+
if (flags & DC_EXEC) {
GroupID old_g = p1;
uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
@@ -276,6 +307,33 @@ int32 CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32
CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
}
}
+
+ InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player);
+ }
+
+ return 0;
+}
+
+
+/**
+ * (Un)set global replace protection from a group
+ * @param tile unused
+ * @param p1 index of group array
+ * - p1 bit 0-15 : GroupID
+ * @param p2
+ * - p2 bit 0 : 1 to set or 0 to clear protection.
+ */
+int32 CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ if (!IsValidGroupID(p1)) return CMD_ERROR;
+
+ Group *g = GetGroup(p1);
+ if (g->owner != _current_player) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ g->replace_protection = HASBIT(p2, 0);
+
+ InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
}
return 0;
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 4d5ab44eb..4d19ba925 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -296,6 +296,13 @@ static void GroupWndProc(Window *w, WindowEvent *e)
gv->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
switch(e->event) {
+ case WE_INVALIDATE_DATA:
+ gv->l.flags |= VL_REBUILD;
+ gl->l.flags |= VL_REBUILD;
+ UpdateGroupActionDropdown(w, gv->group_sel);
+ SetWindowDirty(w);
+ break;
+
case WE_CREATE:
CreateVehicleGroupWindow(w);
break;
@@ -543,22 +550,16 @@ static void GroupWndProc(Window *w, WindowEvent *e)
}
case GRP_WIDGET_CREATE_GROUP: // Create a new group
- if (!CmdFailed(DoCommandP(0, gv->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE)))) {
- gl->l.flags |= VL_REBUILD;
- UpdateGroupActionDropdown(w, gv->group_sel);
- SetWindowDirty(w);
- }
+ DoCommandP(0, gv->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE));
break;
- case GRP_WIDGET_DELETE_GROUP: // Delete the selected group
- if (!CmdFailed(DoCommandP(0, gv->group_sel, 0, NULL, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE)))) {
- gv->group_sel = DEFAULT_GROUP;
- gv->l.flags |= VL_REBUILD;
- gl->l.flags |= VL_REBUILD;
- UpdateGroupActionDropdown(w, gv->group_sel);
- SetWindowDirty(w);
- }
+ case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group
+ GroupID group = gv->group_sel;
+ gv->group_sel = DEFAULT_GROUP;
+
+ DoCommandP(0, group, 0, NULL, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE));
break;
+ }
case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
assert(!IsDefaultGroupID(gv->group_sel));
@@ -593,9 +594,9 @@ static void GroupWndProc(Window *w, WindowEvent *e)
case GRP_WIDGET_REPLACE_PROTECTION:
if (!IsDefaultGroupID(gv->group_sel)) {
- Group *g = GetGroup(gv->group_sel);
+ const Group *g = GetGroup(gv->group_sel);
- g->replace_protection = !g->replace_protection;
+ DoCommandP(0, gv->group_sel, !g->replace_protection, NULL, CMD_SET_GROUP_REPLACE_PROTECTION);
}
break;
}
@@ -605,9 +606,7 @@ static void GroupWndProc(Window *w, WindowEvent *e)
case WE_DRAGDROP: {
switch (e->we.click.widget) {
case GRP_WIDGET_ALL_VEHICLES: // All trains
- if (!CmdFailed(DoCommandP(0, DEFAULT_GROUP , gv->vehicle_sel, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE)))) {
- gv->l.flags |= VL_REBUILD;
- }
+ DoCommandP(0, DEFAULT_GROUP, gv->vehicle_sel, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
gv->vehicle_sel = INVALID_VEHICLE;
@@ -629,9 +628,7 @@ static void GroupWndProc(Window *w, WindowEvent *e)
if (id_g >= gl->l.list_length) return;
- if (!CmdFailed(DoCommandP(0, gl->sort_list[id_g]->index , vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE)))) {
- gv->l.flags |= VL_REBUILD;
- }
+ DoCommandP(0, gl->sort_list[id_g]->index, vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
break;
}
@@ -673,10 +670,7 @@ static void GroupWndProc(Window *w, WindowEvent *e)
if (!StrEmpty(e->we.edittext.str)) {
_cmd_text = e->we.edittext.str;
- if (!CmdFailed(DoCommandP(0, gv->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME)))) {
- SetWindowDirty(w);
- gl->l.flags |= VL_REBUILD;
- }
+ DoCommandP(0, gv->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME));
}
break;
@@ -719,16 +713,12 @@ static void GroupWndProc(Window *w, WindowEvent *e)
case 3: // Add shared Vehicles
assert(!IsDefaultGroupID(gv->group_sel));
- if (!CmdFailed(DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE)))) {
- gv->l.flags |= VL_REBUILD;
- }
+ DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
break;
case 4: // Remove all Vehicles from the selected group
assert(!IsDefaultGroupID(gv->group_sel));
- if (!CmdFailed(DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES)))) {
- gv->l.flags |= VL_REBUILD;
- }
+ DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
break;
default: NOT_REACHED();
}