Changeset - r6667:b4b3f745e39c
[Not reviewed]
master
0 4 0
peter1138 - 17 years ago 2007-05-22 19:48:11
peter1138@openttd.org
(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.
4 files changed with 86 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -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 */
src/command.h
Show inline comments
 
@@ -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 {
src/group_cmd.cpp
Show inline comments
 
@@ -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, uin
 
		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, uin
 
			}
 
		}
 

	
 
		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, uin
 
{
 
	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,
 

	
 
	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,
 

	
 
		/* 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
 
				}
 
			}
 
		}
 

	
 
		InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player);
 
	}
 

	
 
	return 0;
 
@@ -260,6 +288,9 @@ int32 CmdRemoveAllVehiclesGroup(TileInde
 
	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(TileInde
 
				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;
src/group_gui.cpp
Show inline comments
 
@@ -296,6 +296,13 @@ static void GroupWndProc(Window *w, Wind
 
	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, Wind
 
				}
 

	
 
				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, Wind
 

	
 
				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, Wind
 
		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, Wind
 

	
 
					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, Wind
 
			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, Wind
 
						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();
 
					}
0 comments (0 inline, 0 general)