src/group_cmd.cpp
changeset 8754 5dae65402806
parent 8750 fdd6054e7bae
child 8760 ce0891c412ce
equal deleted inserted replaced
8753:33e297b1595d 8754:5dae65402806
    50 	this->owner = owner;
    50 	this->owner = owner;
    51 }
    51 }
    52 
    52 
    53 Group::~Group()
    53 Group::~Group()
    54 {
    54 {
    55 	DeleteName(this->string_id);
    55 	free(this->name);
    56 	this->owner = INVALID_PLAYER;
    56 	this->owner = INVALID_PLAYER;
    57 }
    57 }
    58 
    58 
    59 bool Group::IsValid() const
    59 bool Group::IsValid() const
    60 {
    60 {
   184 	Group *g = GetGroup(p1);
   184 	Group *g = GetGroup(p1);
   185 	if (g->owner != _current_player) return CMD_ERROR;
   185 	if (g->owner != _current_player) return CMD_ERROR;
   186 
   186 
   187 	if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
   187 	if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
   188 
   188 
   189 	/* Create the name */
       
   190 	StringID str = AllocateName(_cmd_text, 0);
       
   191 	if (str == STR_NULL) return CMD_ERROR;
       
   192 
       
   193 	if (flags & DC_EXEC) {
   189 	if (flags & DC_EXEC) {
   194 		/* Delete the old name */
   190 		/* Delete the old name */
   195 		DeleteName(g->string_id);
   191 		free(g->name);
   196 		/* Assign the new one */
   192 		/* Assign the new one */
   197 		g->string_id = str;
   193 		g->name = strdup(_cmd_text);
   198 
   194 
   199 		InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
   195 		InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
   200 	} else {
       
   201 		DeleteName(str);
       
   202 	}
   196 	}
   203 
   197 
   204 	return CommandCost();
   198 	return CommandCost();
   205 }
   199 }
   206 
   200 
   431 	}
   425 	}
   432 }
   426 }
   433 
   427 
   434 
   428 
   435 static const SaveLoad _group_desc[] = {
   429 static const SaveLoad _group_desc[] = {
   436   SLE_VAR(Group, string_id,          SLE_UINT16),
   430   SLE_CONDVAR(Group, name,           SLE_NAME,    0, 83),
       
   431   SLE_CONDSTR(Group, name,           SLE_STR, 0, 84, SL_MAX_VERSION),
   437   SLE_VAR(Group, num_vehicle,        SLE_UINT16),
   432   SLE_VAR(Group, num_vehicle,        SLE_UINT16),
   438   SLE_VAR(Group, owner,              SLE_UINT8),
   433   SLE_VAR(Group, owner,              SLE_UINT8),
   439   SLE_VAR(Group, vehicle_type,       SLE_UINT8),
   434   SLE_VAR(Group, vehicle_type,       SLE_UINT8),
   440   SLE_VAR(Group, replace_protection, SLE_BOOL),
   435   SLE_VAR(Group, replace_protection, SLE_BOOL),
   441   SLE_END()
   436   SLE_END()