--- a/src/group_cmd.cpp Mon Dec 03 23:39:38 2007 +0000
+++ b/src/group_cmd.cpp Tue Jan 22 21:00:30 2008 +0000
@@ -5,21 +5,24 @@
#include "stdafx.h"
#include "openttd.h"
#include "variables.h"
-#include "functions.h"
-#include "player.h"
-#include "table/strings.h"
-#include "command.h"
-#include "vehicle.h"
+#include "command_func.h"
#include "saveload.h"
#include "debug.h"
#include "group.h"
#include "train.h"
#include "aircraft.h"
-#include "string.h"
-#include "window.h"
#include "vehicle_gui.h"
-#include "strings.h"
#include "misc/autoptr.hpp"
+#include "strings_func.h"
+#include "functions.h"
+#include "window_func.h"
+#include "vehicle_func.h"
+#include "autoreplace_base.h"
+#include "autoreplace_func.h"
+#include "string_func.h"
+#include "player_func.h"
+
+#include "table/strings.h"
/**
* Update the num engines of a groupID. Decrease the old one and increase the new one
@@ -43,20 +46,20 @@
DEFINE_OLD_POOL_GENERIC(Group, Group)
-Group::Group(StringID str)
+Group::Group(PlayerID owner)
{
- this->string_id = str;
+ this->owner = owner;
}
Group::~Group()
{
- DeleteName(this->string_id);
- this->string_id = STR_NULL;
+ free(this->name);
+ this->owner = INVALID_PLAYER;
}
bool Group::IsValid() const
{
- return this->string_id != STR_NULL;
+ return this->owner != INVALID_PLAYER;
}
void InitializeGroup(void)
@@ -91,13 +94,12 @@
AutoPtrT<Group> g_auto_delete;
- Group *g = new Group(STR_EMPTY);
+ Group *g = new Group(_current_player);
if (g == NULL) return CMD_ERROR;
g_auto_delete = g;
if (flags & DC_EXEC) {
- g->owner = _current_player;
g->replace_protection = false;
g->vehicle_type = vt;
@@ -185,15 +187,11 @@
if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
- /* Create the name */
- StringID str = AllocateName(_cmd_text, 0);
- if (str == STR_NULL) return CMD_ERROR;
-
if (flags & DC_EXEC) {
/* Delete the old name */
- DeleteName(g->string_id);
+ free(g->name);
/* Assign the new one */
- g->string_id = str;
+ g->name = strdup(_cmd_text);
InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
}
@@ -405,19 +403,33 @@
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
}
+uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e)
+{
+ if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e];
-void RemoveAllGroupsForPlayer(const Player *p)
+ uint num = GetPlayer(p)->num_engines[id_e];
+ if (!IsDefaultGroupID(id_g)) return num;
+
+ const Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->owner == p) num -= g->num_engines[id_e];
+ }
+ return num;
+}
+
+void RemoveAllGroupsForPlayer(const PlayerID p)
{
Group *g;
FOR_ALL_GROUPS(g) {
- if (p->index == g->owner) delete g;
+ if (p == g->owner) delete g;
}
}
static const SaveLoad _group_desc[] = {
- SLE_VAR(Group, string_id, SLE_UINT16),
+ SLE_CONDVAR(Group, name, SLE_NAME, 0, 83),
+ SLE_CONDSTR(Group, name, SLE_STR, 0, 84, SL_MAX_VERSION),
SLE_VAR(Group, num_vehicle, SLE_UINT16),
SLE_VAR(Group, owner, SLE_UINT8),
SLE_VAR(Group, vehicle_type, SLE_UINT8),