decouplecommand4.gs
include "DriverCommand.gs"
include "World.gs"
include "Browser.gs"
include "KUID.gs"
include "Industry.gs"
include "decouple4.gs"
class DecoupleCommand4 isclass DriverCommand
{
public void Init(Asset asset)
{
inherited(asset);
AddHandler(me, "DecoupleItem", null, "Decouple");
}
public void AddCommandMenuItem(DriverCharacter driver, Menu menu)
{
StringTable strTable = GetAsset().GetStringTable();
Menu itemMenu=Constructors.NewMenu();
int k;
for (k = 1; k < 76; k++)
{
itemMenu.AddItem(strTable.GetString("vagonov")+k, me, "DecoupleItem", k);
}
itemMenu.SubdivideItems(true);
menu.AddSubmenu(strTable.GetString("driver_command_decouple"), itemMenu);
}
void PlayConfirmation(void)
{
KUID kuid = GetAsset().LookupKUIDTable("command-sounds");
Library libCommandSounds = World.GetLibrary(kuid);
if (libCommandSounds)
{
libCommandSounds.LibraryCall("PlayConfirmation", null, null);
}
}
DriverScheduleCommand CreateScheduleCommand(DriverCharacter driver, Soup soup)
{
Decouple4 cmd = new Decouple4();
cmd.Init(driver, me);
cmd.SetProperties(soup);
cmd.SetParent(me);
return cast<DriverScheduleCommand>cmd;
}
void Decouple(Message msg)
{
DriverCommands commands = GetDriverCommands(msg);
DriverCharacter driver = cast<DriverCharacter>(msg.src);
string vehicleName = msg.minor;
// naplánovat náš příkaz
Soup soup = Constructors.NewSoup();
soup.SetNamedTag("vehicleNumber", vehicleName);
Decouple4ScheduleCommand cmd = cast<Decouple4ScheduleCommand>CreateScheduleCommand(driver, soup);
commands.AddDriverScheduleCommand(cmd);
if (driver)
PlayConfirmation();
}
};
decouple4.gs
include "DriverCommand.gs"
include "World.gs"
include "Browser.gs"
include "KUID.gs"
include "Industry.gs"
include "decouplecommand4.gs"
include "Schedule.gs"
class Decouple4CustomCommand isclass CustomCommand
{
public int vehicle_number;
public DriverCharacter driver;
public void HandleDecoupleCommand4(Train train)
{
Vehicle[] veh=train.GetVehicles();
if(veh.size()<=vehicle_number)
return;
if (!veh[vehicle_number].GetDirectionRelativeToTrain())
veh[vehicle_number].Uncouple(Vehicle.COUPLE_BACK);
else
veh[vehicle_number].Uncouple(Vehicle.COUPLE_FRONT);
}
public bool Execute(Train train, int px, int py, int pz)
{
//train.SetAutopilotMode(Train.CONTROL_AUTOPILOT);
// Řekněte průmyslu, aby se postaral o naše velení
HandleDecoupleCommand4(train);
return true;
}
};
class Decouple4ScheduleCommand isclass DriverScheduleCommand
{
public string vehicleNumber;
DecoupleCommand4 parent;
public void SetParent(DecoupleCommand4 newParent)
{
parent = newParent;
}
public bool BeginExecute(DriverCharacter driver)
{
Train train = driver.GetTrain();
if (!train)
// nemůžeme oddělit, pokud nemáme vlak
return false;
Decouple4CustomCommand command = new Decouple4CustomCommand();
command.driver = driver;
command.vehicle_number = Str.ToInt(vehicleNumber);
Interface.Log("Decouple4ScheduleCommand.BeginExecute> enter");
// získat ovladač, který provede tento příkaz
driver.DriverCustomCommand(command);
driver.DriverIssueSchedule();
Interface.Log("Decouple4ScheduleCommand.BeginExecute> exit");
return true;
}
// měli bychom skutečně implementovat EndExecute(), aby hra mohla určit úspěšnost tohoto příkazu
public object GetIcon(void)
{
return cast<object>parent;
}
public string GetTooltip(void)
{
StringTable strTable = GetAsset().GetStringTable();
return strTable.GetString("tt_decouple") + vehicleNumber;
}
public Soup GetProperties(void)
{
Soup soup = Constructors.NewSoup();
// Uložit podporu
// Uložte vlastnosti do polévky a poté polévku vraťte
soup.SetNamedTag("vehicleNumber", vehicleNumber);
return soup;
}
public void SetProperties(Soup soup)
{
// Načíst zatížení
// Nastavte vlastnosti z předané polévky
vehicleNumber = soup.GetNamedTag("vehicleNumber");
}
};
config.txt
kind "drivercommand"
script "decouplecommand4"
class "DecoupleCommand4"
supports-null-driver-character 1