src/group_cmd.cpp
author rubidium
Thu, 24 Apr 2008 11:48:09 +0000
branch0.6
changeset 10323 57d8fd25473e
parent 9146 2c8c94a75544
permissions -rw-r--r--
(svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
- Fix: Make the town rating tests use less memory and much quicker (r12859)
- Fix: Usage of AutoPtr made (trying to) build stuff very expensive (r12857, r12855)
- Fix: Use YAPF for fairly old savegames from before YAPF was introduced (r12845)
- Fix: The industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway (r12844)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     1
/* $Id$ */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     2
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     3
/** @file group_cmd.cpp Handling of the engine groups */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     4
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     5
#include "stdafx.h"
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     6
#include "openttd.h"
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
     7
#include "variables.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
     8
#include "command_func.h"
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
     9
#include "saveload.h"
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    10
#include "debug.h"
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    11
#include "group.h"
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    12
#include "train.h"
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    13
#include "aircraft.h"
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    14
#include "vehicle_gui.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8602
diff changeset
    15
#include "strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8612
diff changeset
    16
#include "functions.h"
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8612
diff changeset
    17
#include "window_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8627
diff changeset
    18
#include "vehicle_func.h"
8708
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8676
diff changeset
    19
#include "autoreplace_base.h"
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8676
diff changeset
    20
#include "autoreplace_func.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8708
diff changeset
    21
#include "string_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8749
diff changeset
    22
#include "player_func.h"
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    23
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    24
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    25
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    26
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    27
 * Update the num engines of a groupID. Decrease the old one and increase the new one
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    28
 * @note called in SetTrainGroupID and UpdateTrainGroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    29
 * @param i     EngineID we have to update
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    30
 * @param old_g index of the old group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    31
 * @param new_g index of the new group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    32
 */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    33
static inline void UpdateNumEngineGroup(EngineID i, GroupID old_g, GroupID new_g)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    34
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    35
	if (old_g != new_g) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    36
		/* Decrease the num engines of EngineID i of the old group if it's not the default one */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    37
		if (!IsDefaultGroupID(old_g) && IsValidGroupID(old_g)) GetGroup(old_g)->num_engines[i]--;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    38
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    39
		/* Increase the num engines of EngineID i of the new group if it's not the new one */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    40
		if (!IsDefaultGroupID(new_g) && IsValidGroupID(new_g)) GetGroup(new_g)->num_engines[i]++;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    41
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    42
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    43
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    44
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    45
DEFINE_OLD_POOL_GENERIC(Group, Group)
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    46
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    47
8749
33c19f20a5db (svn r11817) -Codechange: Base vehicle group validity on owner, not name.
peter1138
parents: 8733
diff changeset
    48
Group::Group(PlayerID owner)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    49
{
8749
33c19f20a5db (svn r11817) -Codechange: Base vehicle group validity on owner, not name.
peter1138
parents: 8733
diff changeset
    50
	this->owner = owner;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    51
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    52
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    53
Group::~Group()
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    54
{
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
    55
	free(this->name);
8749
33c19f20a5db (svn r11817) -Codechange: Base vehicle group validity on owner, not name.
peter1138
parents: 8733
diff changeset
    56
	this->owner = INVALID_PLAYER;
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    57
}
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    58
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    59
bool Group::IsValid() const
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    60
{
8749
33c19f20a5db (svn r11817) -Codechange: Base vehicle group validity on owner, not name.
peter1138
parents: 8733
diff changeset
    61
	return this->owner != INVALID_PLAYER;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    62
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    63
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    64
void InitializeGroup(void)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    65
{
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    66
	_Group_pool.CleanPool();
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    67
	_Group_pool.AddBlockToPool();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    68
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    69
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    70
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    71
static WindowClass GetWCForVT(VehicleType vt)
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    72
{
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    73
	switch (vt) {
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    74
		default:
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    75
		case VEH_TRAIN:    return WC_TRAINS_LIST;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    76
		case VEH_ROAD:     return WC_ROADVEH_LIST;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    77
		case VEH_SHIP:     return WC_SHIPS_LIST;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    78
		case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    79
	}
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    80
}
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    81
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
    82
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    83
/**
7693
d93ae92f9a2f (svn r10475) -Fix [FS#996]: some wrong comments for a few of the (vehicle) group related actions.
rubidium
parents: 7593
diff changeset
    84
 * Create a new vehicle group.
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    85
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    86
 * @param p1   vehicle type
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    87
 * @param p2   unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    88
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
    89
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    90
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    91
	VehicleType vt = (VehicleType)p1;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    92
	if (!IsPlayerBuildableVehicleType(vt)) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    93
10323
57d8fd25473e (svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
rubidium
parents: 9146
diff changeset
    94
	if (!Group::CanAllocateItem()) return CMD_ERROR;
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
    95
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    96
	if (flags & DC_EXEC) {
10323
57d8fd25473e (svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
rubidium
parents: 9146
diff changeset
    97
		Group *g = new Group(_current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    98
		g->replace_protection = false;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
    99
		g->vehicle_type = vt;
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   100
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   101
		InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   102
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   103
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   104
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   105
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   106
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   107
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   108
/**
7693
d93ae92f9a2f (svn r10475) -Fix [FS#996]: some wrong comments for a few of the (vehicle) group related actions.
rubidium
parents: 7593
diff changeset
   109
 * Add all vehicles in the given group to the default group and then deletes the group.
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   110
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   111
 * @param p1   index of array group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   112
 *      - p1 bit 0-15 : GroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   113
 * @param p2   unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   114
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   115
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   116
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   117
	if (!IsValidGroupID(p1)) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   118
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   119
	Group *g = GetGroup(p1);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   120
	if (g->owner != _current_player) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   121
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   122
	if (flags & DC_EXEC) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   123
		Vehicle *v;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   124
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   125
		/* Add all vehicles belong to the group to the default group */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   126
		FOR_ALL_VEHICLES(v) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   127
			if (v->group_id == g->index && v->type == g->vehicle_type) v->group_id = DEFAULT_GROUP;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   128
		}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   129
9146
2c8c94a75544 (svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents: 8760
diff changeset
   130
		/* Update backupped orders if needed */
2c8c94a75544 (svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents: 8760
diff changeset
   131
		if (_backup_orders_data.group == g->index) _backup_orders_data.group = DEFAULT_GROUP;
2c8c94a75544 (svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents: 8760
diff changeset
   132
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   133
		/* If we set an autoreplace for the group we delete, remove it. */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   134
		if (_current_player < MAX_PLAYERS) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   135
			Player *p;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   136
			EngineRenew *er;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   137
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   138
			p = GetPlayer(_current_player);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   139
			FOR_ALL_ENGINE_RENEWS(er) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   140
				if (er->group_id == g->index) RemoveEngineReplacementForPlayer(p, er->from, g->index, flags);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   141
			}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   142
		}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   143
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   144
		VehicleType vt = g->vehicle_type;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   145
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   146
		/* Delete the Replace Vehicle Windows */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   147
		DeleteWindowById(WC_REPLACE_VEHICLE, g->vehicle_type);
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
   148
		delete g;
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   149
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   150
		InvalidateWindowData(GetWCForVT(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   151
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   152
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   153
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   154
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   155
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   156
static bool IsUniqueGroupName(const char *name)
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   157
{
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   158
	const Group *g;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   159
	char buf[512];
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   160
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   161
	FOR_ALL_GROUPS(g) {
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   162
		SetDParam(0, g->index);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   163
		GetString(buf, STR_GROUP_NAME, lastof(buf));
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   164
		if (strcmp(buf, name) == 0) return false;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   165
	}
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   166
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   167
	return true;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   168
}
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   169
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   170
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   171
 * Rename a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   172
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   173
 * @param p1   index of array group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   174
 *   - p1 bit 0-15 : GroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   175
 * @param p2   unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   176
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   177
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   178
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   179
	if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   180
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   181
	Group *g = GetGroup(p1);
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   182
	if (g->owner != _current_player) return CMD_ERROR;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   183
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   184
	if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7547
diff changeset
   185
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   186
	if (flags & DC_EXEC) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   187
		/* Delete the old name */
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   188
		free(g->name);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   189
		/* Assign the new one */
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   190
		g->name = strdup(_cmd_text);
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   191
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   192
		InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   193
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   194
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   195
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   196
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   197
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   198
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   199
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   200
 * Add a vehicle to a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   201
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   202
 * @param p1   index of array group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   203
 *   - p1 bit 0-15 : GroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   204
 * @param p2   vehicle to add to a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   205
 *   - p2 bit 0-15 : VehicleID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   206
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   207
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   208
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   209
	GroupID new_g = p1;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   210
7147
d1a898108501 (svn r9882) -Fix (r9874): the "default group" is also a valid group in some cases.
rubidium
parents: 7139
diff changeset
   211
	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   212
8000
d2741bf5e5af (svn r11019) -Fix [FS#1176]: Vehicles in a group must always have the same type when adding new vehicles to a group. Patch by SmatZ.
rubidium
parents: 7988
diff changeset
   213
	Vehicle *v = GetVehicle(p2);
d2741bf5e5af (svn r11019) -Fix [FS#1176]: Vehicles in a group must always have the same type when adding new vehicles to a group. Patch by SmatZ.
rubidium
parents: 7988
diff changeset
   214
7167
81de19c8486a (svn r9902) -Fix (r9898): Don't check group owner when adding a vehicle to the 'default' group.
peter1138
parents: 7163
diff changeset
   215
	if (IsValidGroupID(new_g)) {
81de19c8486a (svn r9902) -Fix (r9898): Don't check group owner when adding a vehicle to the 'default' group.
peter1138
parents: 7163
diff changeset
   216
		Group *g = GetGroup(new_g);
8000
d2741bf5e5af (svn r11019) -Fix [FS#1176]: Vehicles in a group must always have the same type when adding new vehicles to a group. Patch by SmatZ.
rubidium
parents: 7988
diff changeset
   217
		if (g->owner != _current_player || g->vehicle_type != v->type) return CMD_ERROR;
7167
81de19c8486a (svn r9902) -Fix (r9898): Don't check group owner when adding a vehicle to the 'default' group.
peter1138
parents: 7163
diff changeset
   218
	}
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   219
7269
c7f39d91255e (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 7167
diff changeset
   220
	if (v->owner != _current_player || !v->IsPrimaryVehicle()) return CMD_ERROR;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   221
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   222
	if (flags & DC_EXEC) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   223
		DecreaseGroupNumVehicle(v->group_id);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   224
		IncreaseGroupNumVehicle(new_g);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   225
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   226
		switch (v->type) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   227
			default: NOT_REACHED();
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   228
			case VEH_TRAIN:
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   229
				SetTrainGroupID(v, new_g);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   230
				break;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   231
			case VEH_ROAD:
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   232
			case VEH_SHIP:
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   233
			case VEH_AIRCRAFT:
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   234
				if (IsEngineCountable(v)) UpdateNumEngineGroup(v->engine_type, v->group_id, new_g);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   235
				v->group_id = new_g;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   236
				break;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   237
		}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   238
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   239
		/* Update the Replace Vehicle Windows */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   240
		InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   241
		InvalidateWindowData(GetWCForVT(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   242
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   243
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   244
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   245
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   246
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   247
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   248
 * Add all shared vehicles of all vehicles from a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   249
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   250
 * @param p1   index of group array
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   251
 *  - p1 bit 0-15 : GroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   252
 * @param p2   type of vehicles
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   253
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   254
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   255
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   256
	VehicleType type = (VehicleType)p2;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   257
	if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   258
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   259
	if (flags & DC_EXEC) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   260
		Vehicle *v;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   261
		VehicleType type = (VehicleType)p2;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   262
		GroupID id_g = p1;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   263
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   264
		/* Find the first front engine which belong to the group id_g
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   265
		 * then add all shared vehicles of this front engine to the group id_g */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   266
		FOR_ALL_VEHICLES(v) {
7269
c7f39d91255e (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 7167
diff changeset
   267
			if (v->type == type && v->IsPrimaryVehicle()) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   268
				if (v->group_id != id_g) continue;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   269
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   270
				/* For each shared vehicles add it to the group */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   271
				for (Vehicle *v2 = GetFirstVehicleFromSharedList(v); v2 != NULL; v2 = v2->next_shared) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   272
					if (v2->group_id != id_g) CmdAddVehicleGroup(tile, flags, id_g, v2->index);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   273
				}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   274
			}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   275
		}
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   276
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   277
		InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   278
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   279
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   280
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   281
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   282
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   283
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   284
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   285
 * Remove all vehicles from a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   286
 * @param tile unused
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   287
 * @param p1   index of group array
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   288
 * - p1 bit 0-15 : GroupID
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   289
 * @param p2   type of vehicles
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   290
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   291
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   292
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   293
	VehicleType type = (VehicleType)p2;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   294
	if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   295
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   296
	Group *g = GetGroup(p1);
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   297
	if (g->owner != _current_player) return CMD_ERROR;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   298
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   299
	if (flags & DC_EXEC) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   300
		GroupID old_g = p1;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   301
		Vehicle *v;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   302
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   303
		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   304
		FOR_ALL_VEHICLES(v) {
7269
c7f39d91255e (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 7167
diff changeset
   305
			if (v->type == type && v->IsPrimaryVehicle()) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   306
				if (v->group_id != old_g) continue;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   307
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   308
				/* Add The Vehicle to the default group */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   309
				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   310
			}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   311
		}
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   312
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   313
		InvalidateWindowData(GetWCForVT(type), (type << 11) | VLW_GROUP_LIST | _current_player);
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   314
	}
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   315
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   316
	return CommandCost();
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   317
}
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   318
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   319
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   320
/**
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   321
 * (Un)set global replace protection from a group
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   322
 * @param tile unused
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   323
 * @param p1   index of group array
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   324
 * - p1 bit 0-15 : GroupID
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   325
 * @param p2
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   326
 * - p2 bit 0    : 1 to set or 0 to clear protection.
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   327
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7269
diff changeset
   328
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   329
{
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   330
	if (!IsValidGroupID(p1)) return CMD_ERROR;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   331
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   332
	Group *g = GetGroup(p1);
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   333
	if (g->owner != _current_player) return CMD_ERROR;
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   334
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   335
	if (flags & DC_EXEC) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8044
diff changeset
   336
		g->replace_protection = HasBit(p2, 0);
7163
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   337
09e65bfbc08b (svn r9898) -Fix (r9874): Many...
peter1138
parents: 7147
diff changeset
   338
		InvalidateWindowData(GetWCForVT(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   339
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   340
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   341
	return CommandCost();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   342
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   343
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   344
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   345
 * Decrease the num_vehicle variable before delete an front engine from a group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   346
 * @note Called in CmdSellRailWagon and DeleteLasWagon,
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   347
 * @param v     FrontEngine of the train we want to remove.
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   348
 */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   349
void RemoveVehicleFromGroup(const Vehicle *v)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   350
{
8044
72c3e2bc6429 (svn r11068) -Codechange: remove Vehicle::HasFront as all vehicles have the Vehicle::first pointer correctly set.
rubidium
parents: 8000
diff changeset
   351
	if (!v->IsValid() || !v->IsPrimaryVehicle()) return;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   352
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   353
	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   354
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   355
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   356
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   357
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   358
 * Affect the groupID of a train to new_g.
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   359
 * @note called in CmdAddVehicleGroup and CmdMoveRailVehicle
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   360
 * @param v     First vehicle of the chain.
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   361
 * @param new_g index of array group
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   362
 */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   363
void SetTrainGroupID(Vehicle *v, GroupID new_g)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   364
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   365
	if (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g)) return;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   366
7883
7777bca58ae0 (svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents: 7878
diff changeset
   367
	assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v));
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   368
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7909
diff changeset
   369
	for (Vehicle *u = v; u != NULL; u = u->Next()) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   370
		if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   371
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   372
		u->group_id = new_g;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   373
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   374
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   375
	/* Update the Replace Vehicle Windows */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   376
	InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   377
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   378
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   379
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   380
/**
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   381
 * Recalculates the groupID of a train. Should be called each time a vehicle is added
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   382
 * to/removed from the chain,.
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   383
 * @note this needs to be called too for 'wagon chains' (in the depot, without an engine)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   384
 * @note Called in CmdBuildRailVehicle, CmdBuildRailWagon, CmdMoveRailVehicle, CmdSellRailWagon
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   385
 * @param v First vehicle of the chain.
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   386
 */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   387
void UpdateTrainGroupID(Vehicle *v)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   388
{
7883
7777bca58ae0 (svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents: 7878
diff changeset
   389
	assert(v->IsValid() && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v)));
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   390
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   391
	GroupID new_g = IsFrontEngine(v) ? v->group_id : (GroupID)DEFAULT_GROUP;
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7909
diff changeset
   392
	for (Vehicle *u = v; u != NULL; u = u->Next()) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   393
		if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   394
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   395
		u->group_id = new_g;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   396
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   397
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   398
	/* Update the Replace Vehicle Windows */
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   399
	InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   400
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   401
8733
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   402
uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e)
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   403
{
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   404
	if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e];
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   405
8733
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   406
	uint num = GetPlayer(p)->num_engines[id_e];
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   407
	if (!IsDefaultGroupID(id_g)) return num;
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   408
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   409
	const Group *g;
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   410
	FOR_ALL_GROUPS(g) {
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   411
		if (g->owner == p) num -= g->num_engines[id_e];
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   412
	}
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   413
	return num;
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   414
}
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   415
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   416
void RemoveAllGroupsForPlayer(const PlayerID p)
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   417
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   418
	Group *g;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   419
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   420
	FOR_ALL_GROUPS(g) {
8733
9e2d2a2619ff (svn r11801) -Codechange: remove some unneeded includes from some header files.
rubidium
parents: 8710
diff changeset
   421
		if (p == g->owner) delete g;
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   422
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   423
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   424
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   425
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   426
static const SaveLoad _group_desc[] = {
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   427
  SLE_CONDVAR(Group, name,           SLE_NAME,    0, 83),
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   428
  SLE_CONDSTR(Group, name,           SLE_STR, 0, 84, SL_MAX_VERSION),
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   429
  SLE_VAR(Group, num_vehicle,        SLE_UINT16),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   430
  SLE_VAR(Group, owner,              SLE_UINT8),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   431
  SLE_VAR(Group, vehicle_type,       SLE_UINT8),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   432
  SLE_VAR(Group, replace_protection, SLE_BOOL),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   433
  SLE_END()
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   434
};
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   435
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   436
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   437
static void Save_GROUP(void)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   438
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   439
	Group *g;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   440
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   441
	FOR_ALL_GROUPS(g) {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   442
		SlSetArrayIndex(g->index);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   443
		SlObject(g, _group_desc);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   444
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   445
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   446
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   447
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   448
static void Load_GROUP(void)
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   449
{
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   450
	int index;
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   451
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   452
	while ((index = SlIterateArray()) != -1) {
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7693
diff changeset
   453
		Group *g = new (index) Group();
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   454
		SlObject(g, _group_desc);
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   455
	}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   456
}
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   457
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   458
extern const ChunkHandler _group_chunk_handlers[] = {
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   459
	{ 'GRPS', Save_GROUP, Load_GROUP, CH_ARRAY | CH_LAST},
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
diff changeset
   460
};