CCG/Example: DriverCommand: Difference between revisions

From TrainzOnline
< CCG
Jump to navigationJump to search
Pev (talk | contribs)
Ek.skirl (talk | contribs)
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 14: Line 14:
'''thumb.jpg''' - The thumbnail image for this asset. A 240x180 jpeg.
'''thumb.jpg''' - The thumbnail image for this asset. A 240x180 jpeg.


'''driveto.texture.txt''' - The texture.txt file. See the section on Texture.txt files on Page 96 for more information.
'''driveto.texture.txt''' - The texture.txt file. See the section on [[Texture_file|Texture.txt]] files for more information.


'''driveto.tga''' - The texture file for the drivercommand icon.
'''driveto.tga''' - The texture file for the drivercommand icon.
Line 24: Line 24:


'''drivetoschedulecommand.gs''' - A trainz script file which is a dependency of "drivercommand.gs".
'''drivetoschedulecommand.gs''' - A trainz script file which is a dependency of "drivercommand.gs".
===Version hint===
!!! This example is an older version without async search of industries and the newer menu building methods !!!
The current Drive To driver command asset contains a commented newer code version.


===Config.txt File Listing===
===Config.txt File Listing===
Line 65: Line 69:


===DriverToCommand.gs File Listing===
===DriverToCommand.gs File Listing===
  //
  //
  // DriverToCommand.gs
  // DriverToCommand.gs
Line 84: Line 87:
  class DriveToCommand isclass DriverCommand
  class DriveToCommand isclass DriverCommand
  {
  {
//
    //
// Initialize parent object and add handlers to process messages for this driver command object.
    // Initialize parent object and add handlers to process messages for this driver command object.
     //
     //
     public void Init(Asset asset)
     public void Init(Asset asset)
     {
     {
        inherited(asset);
      inherited(asset);
    AddHandler(me, "DriveToIndustry", null, "DriveTo");
      AddHandler(me, "DriveToIndustry", null, "DriveTo");
  AddHandler(me, "DriveToIndustryTrack", null,"DriveToTrack");
      AddHandler(me, "DriveToIndustryTrack", null,"DriveToTrack");
     }
     }
   
     //
     //
// Adds industry destination menu items for all industries to the given menu along with submenus of
    // Adds industry destination menu items for all industries to the given menu along with submenus of
// destination tracks for all industries added.
    // destination tracks for all industries added.
//
    //
public void AddCommandMenuItem(DriverCharacter driver,Menu menu)
    public void AddCommandMenuItem(DriverCharacter driver,Menu menu)
     {
     {
        Train train;
      Train train;
        if (driver)
      if (driver)
        {
      {
            train = driver.GetTrain();
          train = driver.GetTrain();
            if (!train)
          if (!train)  
                return;
            return;
        }
      }
        StringTable strTable = GetAsset().GetStringTable();
      StringTable strTable = GetAsset().GetStringTable();
            Menu industriesMenu = Constructors.NewMenu();
      Menu industriesMenu = Constructors.NewMenu();
            GameObject[] industryList = World.GetIndustryList();
      GameObject[] industryList = World.GetIndustryList();
            int i, industryCount = industryList.size();
      int i, industryCount = industryList.size();
            if (!industryCount)
      if (!industryCount)
    // we dont bother with a `Drive To' command if there are no industries
          // we dont bother with a `Drive To' command if there are no industries
                return;
          return;
            for (i = 0; i < industryCount; i++)
      for (i = 0; i < industryCount; i++)
            {
      {
              Industry industry = cast<Industry>(industryList[i]);
          Industry industry = cast<Industry>(industryList[i]);
            string localisedName = industry.GetLocalisedName();
          string localisedName = industry.GetLocalisedName();
            string[] locationNames = new string[0];
          string[] locationNames = new string[0];
            string[] locationTracks = new string[0];
          string[] locationTracks = new string[0];
 
          industry.AppendDriverDestinations(locationNames,locationTracks);
        industry.AppendDriverDestinations(locationNames,locationTracks);
          if (localisedName.size())
                  if (localisedName.size())
            if (locationNames.size())
              if (locationNames.size())
            {
              {
                Menu submenu = Constructors.NewMenu();
                  Menu submenu = Constructors.NewMenu();
                int j;
                  int j;
                for (j = 0; j < locationNames.size(); j++)
                  for (j = 0; j < locationNames.size(); j++)
                if (locationNames[j] and locationNames[j].size() and locationTracks[j] and locationTracks[j].size())
            if (locationNames[j] and locationNames[j].size() and
                  submenu.AddItem(locationNames[j], me, "DriveToIndustryTrack", industry.GetId() + " " + locationTracks[j]);
  locationTracks[j] and locationTracks[j].size())
                else
 
                  if (train)
                    submenu.AddItem(locationNames[j], me, "DriveToIndustryTrack", industry.GetId() + " " +
                      train.Exception("Error in `track names' of industry `" + localisedName + "'");
  locationTracks[j]);
                industriesMenu.AddSubmenu(localisedName + " >",submenu);
 
            }
  else if (train)
            else
 
                industriesMenu.AddItem(localisedName, me,"DriveToIndustry", industry.GetName());
            train.Exception("Error in `track names' of industry `"
          industriesMenu.SubdivideItems();
  + localisedName + "'");
          menu.AddSubmenu(strTable.GetString("driver_command_drive_to") + " >", industriesMenu);
 
      }
        industriesMenu.AddSubmenu(localisedName + " >",submenu);
              }
              else
          industriesMenu.AddItem(localisedName, me,"DriveToIndustry", industry.GetName());
        }
        industriesMenu.SubdivideItems();
      menu.AddSubmenu(strTable.GetString("driver_
  command_drive_to") + " >", industriesMenu);
     }
     }
   
     //
     //
     // Called by either DriveTo() or DriveToTrack() to play one of  random driver acknowledgments.
     // Called by either DriveTo() or DriveToTrack() to play one of  random driver acknowledgments.
     //
     //
 
    void PlayConfirmation(void)
void PlayConfirmation(void)
    {
{
      KUID kuid = GetAsset().LookupKUIDTable("command-sounds");
  KUID kuid = GetAsset().LookupKUIDTable("command-sounds");
      Library libCommandSounds = World.GetLibrary(kuid);
    Library libCommandSounds = World.GetLibrary(kuid);
      if (libCommandSounds)
    if (libCommandSounds)
          libCommandSounds.LibraryCall("PlayConfirmation",null, null);
    {
    }
    libCommandSounds.LibraryCall("PlayConfirmation",null, null);
   
    }
    //
}
    // Create the schedule command
DriverScheduleCommand CreateScheduleCommand(DriverCharacter driver, Soup soup)
    //
{
    DriverScheduleCommand CreateScheduleCommand(DriverCharacter driver, Soup soup)
  DriveToScheduleCommand cmd = new DriveToScheduleCommand();
    {
    cmd.Init(driver, me);
      DriveToScheduleCommand cmd = new DriveToScheduleCommand();
    cmd.SetParent(me);
      cmd.Init(driver, me);
    cmd.SetProperties(soup);
      cmd.SetParent(me);
 
      cmd.SetProperties(soup);
    return cast<DriverScheduleCommand>cmd;
      return cast<DriverScheduleCommand>cmd;
}
    }
//
   
// Handler method to drive a train to an industry (no specific destination track though).
    //
//
    // Handler method to drive a train to an industry (no specific destination track though).
void DriveTo(Message msg)
    //
{
    void DriveTo(Message msg)
    DriverCommands commands = GetDriverCommands(msg);
    {
    DriverCharacter driver = cast<DriverCharacter>(msg.src);
    string industryName = msg.minor;
 
        // schedule our command
    Soup soup = Constructors.NewSoup();
    soup.SetNamedTag("industryName", industryName);
 
  DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
    commands.AddDriverScheduleCommand(cmd);
                        if (driver)
                                  PlayConfirmation();
  }
 
  //
  // Handler method to drive a train to a specific track in an industry.
  //
 
  void DriveToTrack(Message msg)
  {
       DriverCommands commands = GetDriverCommands(msg);
       DriverCommands commands = GetDriverCommands(msg);
 
       DriverCharacter driver = cast<DriverCharacter>(msg.src);
       DriverCharacter driver = cast<DriverCharacter>(msg.src);
       string msgData = msg.minor;
       string industryName = msg.minor;
      int industryId = Str.UnpackInt(msgData);
      string trackName = Str.UnpackString(msgData);
 
      GameObject industry = Router.GetGameObject(industryId);
 
      if (!industry)
        return;
 
       // schedule our command
       // schedule our command
 
       Soup soup = Constructors.NewSoup();
       Soup soup = Constructors.NewSoup();
       soup.SetNamedTag("industryName", industry.GetName());
       soup.SetNamedTag("industryName", industryName);
      soup.SetNamedTag("trackName", trackName);
 
       DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
       DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
 
       commands.AddDriverScheduleCommand(cmd);
       commands.AddDriverScheduleCommand(cmd);
      if (driver) PlayConfirmation();
    }
    
    
                        if (driver)
     //
                            PlayConfirmation();
     // Handler method to drive a train to a specific track in an industry.
  }
    //
 
    void DriveToTrack(Message msg)
 
    {
//
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)
{
  DriveToScheduleCommand cmd = newDriveToScheduleCommand();
 
    cmd.Init(driver, me);
    cmd.SetParent(me);
    cmd.SetProperties(soup);
 
    return cast<DriverScheduleCommand>cmd;
}
//
// Handler method to drive a train to an industry (no specific destination track though).
//
void DriveTo(Message msg)
{
              DriverCommands commands = GetDriverCommands(msg);
    DriverCharacter driver = cast<DriverCharacter>(msg.src);
    string industryName = msg.minor;
 
        // schedule our command
 
    Soup soup = Constructors.NewSoup();
    soup.SetNamedTag("industryName", industryName);
 
  DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
 
    commands.AddDriverScheduleCommand(cmd);
 
//
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)
{
  DriveToScheduleCommand cmd = new DriveToScheduleCommand();
 
    cmd.Init(driver, me);
    cmd.SetParent(me);
    cmd.SetProperties(soup);
 
    return cast<DriverScheduleCommand>cmd;
}
//
// Handler method to drive a train to an industry (no specific destination track though).
//
 
void DriveTo(Message msg)
{
              DriverCommands commands = GetDriverCommands(msg);
    DriverCharacter driver = cast<DriverCharacter>(msg.src);
 
    string industryName = msg.minor;
 
        // schedule our command
 
    Soup soup = Constructors.NewSoup();
    soup.SetNamedTag("industryName", industryName);
 
  DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
    commands.AddDriverScheduleCommand(cmd);
 
    if (driver)
          PlayConfirmation();
  }
  //
  // Handler method to drive a train to a specific track in an industry.
  //
  void DriveToTrack(Message msg)
  {
       DriverCommands commands = GetDriverCommands(msg);
       DriverCommands commands = GetDriverCommands(msg);
       DriverCharacter driver = cast<DriverCharacter>(msg.src);
       DriverCharacter driver = cast<DriverCharacter>(msg.src);
       string msgData = msg.minor;
       string msgData = msg.minor;
       int industryId = Str.UnpackInt(msgData);
       int industryId = Str.UnpackInt(msgData);
       
       string trackName = Str.UnpackString(msgData);
       string trackName = Str.UnpackString(msgData);
       
       GameObject industry = Router.GetGameObject(industryId);
       GameObject industry = Router.GetGameObject(industryId);
     
       if (!industry) return;
       if (!industry)
        return;
 
       // schedule our command
       // schedule our command
 
       Soup soup = Constructors.NewSoup();
       Soup soup = Constructors.NewSoup();
       soup.SetNamedTag("industryName", industry.GetName());
       soup.SetNamedTag("industryName", industry.GetName());
       soup.SetNamedTag("trackName", trackName);
       soup.SetNamedTag("trackName", trackName);
   
      DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
    DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
 
       commands.AddDriverScheduleCommand(cmd);
       commands.AddDriverScheduleCommand(cmd);
                        if (driver)
      if (driver) PlayConfirmation();
                                  PlayConfirmation();
     }
  }
};
  }
  //
  // Handler method to drive a train to a specific track in an industry.
  //
  void DriveToTrack(Message msg)
  {
                DriverCommands commands = GetDriverCommands(msg);
      DriverCharacter driver = cast<DriverCharacter>(msg.src);
 
      string msgData = msg.minor;
      int industryId = Str.UnpackInt(msgData);
      string trackName = Str.UnpackString(msgData);
      GameObject industry = Router.GetGameObject(industryId);
 
      if (!industry)
        return;
 
      // schedule our command
 
      Soup soup = Constructors.NewSoup();
      soup.SetNamedTag("industryName", industry.GetName());
      soup.SetNamedTag("trackName", trackName);
 
     DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
 
      commands.AddDriverScheduleCommand(cmd);
                        if (driver)
                                  PlayConfirmation();
  }
  };


And the dependent script
And the dependent script
Line 384: Line 227:
  class DriveToScheduleCommand isclass DriverScheduleCommand
  class DriveToScheduleCommand isclass DriverScheduleCommand
  {
  {
  public string industryName; // Name of the industry to drive to.
    public string industryName;   // Name of the industry to drive to.
  public string trackName;       // Name of the track in the industry to drive to.
    public string trackName;     // Name of the track in the industry to drive to.
    DriveToCommand parent;
    DriveToCommand parent;
    public void SetParent(DriveToCommand newParent)
   
    {
    //
        parent = newParent;
    //
    }
    //
//
    public void SetParent(DriveToCommand newParent)
// Starts executing this schedule command on the given driver character.
    {
//
      parent = newParent;
    }
   
    //
    // Starts executing this schedule command on the given driver character.
    //
     public bool BeginExecute(DriverCharacter driver)
     public bool BeginExecute(DriverCharacter driver)
     {
     {
        Train train = driver.GetTrain();
      Train train = driver.GetTrain();
       if (!train)
       if (!train)
          // cant drive if we dont have a train
          // cant drive if we dont have a train
          return false;
          return false;
    Industry industry = cast<Industry>(Router.GetGameObject(industryName));
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
       if (!industry)
       if (!industry)
          // cant drive to an industry which doesn't exist
          // cant drive to an industry which doesn't exist
          return false;
          return false;
       return driver.NavigateToIndustry(industry, trackName);
       return driver.NavigateToIndustry(industry, trackName);
  }
    }
  // we should really implement EndExecute() to allow the game to determine the success of this command
   
  //
    //
  // Provides an icon for this command so it can be seen on the driver's schedule. Uses the industry
    // we should really implement EndExecute() to allow the game to determine the success of this command
  // icon to indicate the destination.
    //
  //
   
  public object GetIcon(void)
    //
  {
    // Provides an icon for this command so it can be seen on the driver's schedule. Uses the industry
    Industry industry = cast<Industry>(Router.GetGameObject(industryName));
    // icon to indicate the destination.
    //
    public object GetIcon(void)
    {
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
       return cast<object>industry;
       return cast<object>industry;
  }
    }
  public string GetTooltip(void)
   
  {
    //
    //
    //
    public string GetTooltip(void)
    {
       StringTable strTable = GetAsset().GetStringTable();
       StringTable strTable = GetAsset().GetStringTable();
       string userTrackName = trackName;
       string userTrackName = trackName;
    Industry industry = cast<Industry>(Router.GetGameObject(industryName));
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
       if (industry)
       if (industry)
       {
       {
          string[] destNames = new string[0];
          string[] destNames = new string[0];
          string[] destTracks = new string[0];
          string[] destTracks = new string[0];
      industry.AppendDriverDestinations(destNames,destTracks);
          industry.AppendDriverDestinations(destNames,destTracks);
          int i;
          int i;
        for (i = 0; i < destNames.size(); i++)
          for (i = 0; i < destNames.size(); i++)
        {
          {
             if (destTracks[i] == trackName)
             if (destTracks[i] == trackName)
             {
             {
                userTrackName = destNames[i];
                userTrackName = destNames[i];
                break;
                break;
             }
             }
        }
          }
    }
      }
  return strTable.GetString("driver_command_drive_to") + industryName + " (" + userTrackName + ")";
      return strTable.GetString("driver_command_drive_to") + industryName + " (" + userTrackName + ")";
  }
    }
  public Soup GetProperties(void)
   
  {
    //
    Soup soup = Constructors.NewSoup();
    //
    // Save support
    //
    // Save the properties to the soup, then return the soup
    public Soup GetProperties(void)
    soup.SetNamedTag("industryName", industryName);
    {
    soup.SetNamedTag("trackName", trackName);
      Soup soup = Constructors.NewSoup();
    return soup;
      // Save support
  }
      // Save the properties to the soup, then return the soup
  public void SetProperties(Soup soup)
      soup.SetNamedTag("industryName", industryName);
  {
      soup.SetNamedTag("trackName", trackName);
    // Load support
      return soup;
    // Setup the properties from the passed in soup
    }
    industryName = soup.GetNamedTag("industryName");
   
    trackName = soup.GetNamedTag("trackName");
    //
  }
    //
  };
    //
 
    public void SetProperties(Soup soup)
 
    {
      // Load support
      // Setup the properties from the passed in soup
      industryName = soup.GetNamedTag("industryName");
      trackName = soup.GetNamedTag("trackName");
    }
};


===Download this asset===
===Download this asset===
Line 464: Line 326:


A version of this asset is a ''built-in'' for TS2010, TS12.  
A version of this asset is a ''built-in'' for TS2010, TS12.  


==Return to CCG Index==
==Return to CCG Index==

Latest revision as of 18:17, 15 February 2025

Driver-Command

Directory Structure

A typical asset of this kind has the following File\Directory Structure:


Required Files

config.txt - The config file for the asset.

thumb.jpg - The thumbnail image for this asset. A 240x180 jpeg.

driveto.texture.txt - The texture.txt file. See the section on Texture.txt files for more information.

driveto.tga - The texture file for the drivercommand icon.

shows image and alpha channel for 64x64 pixel TGA.


drivetocommand.gs - The trainz script file referenced in the config.txt.

drivetoschedulecommand.gs - A trainz script file which is a dependency of "drivercommand.gs".

Version hint

!!! This example is an older version without async search of industries and the newer menu building methods !!!

The current Drive To driver command asset contains a commented newer code version.

Config.txt File Listing

kuid                           <kuid:56113:1268>
trainz-build                   2.5
category-class                 "YD"
category-region                "00"
category-era                   "1800s;1810s;1820s"
username                       "testDriverCommand"
kind                           "drivercommand"
supports-null-driver-character  1
script                          "DriveToCommand.gs"
class                           "DriveToCommand"
description                     "Test command. This does the same thing as `Drive To'."
string-table
{
  description                   "Allows a driver character to take a train either to a 
                                  destination industry or a specific track in a destination industry."
  driver_command_drive_to       "Drive To "
}
kuid-table
{
  command-sounds                <kuid:-3:10219>
}
thumbnails
{
  0
    {
      image                     "thumb.jpg"
      width                     240
      height                    180
    }
  1
    {
      image                     "driveto.tga"
      width                     64
      height                    64
     }
}


DriverToCommand.gs File Listing

//
// DriverToCommand.gs
//
// Copyright (C) 2003 Auran Developments Pty Ltd
// All Rights Reserved.
//
include "DriverCommand.gs"
include "World.gs"
include "Browser.gs"
include "KUID.gs"
include "Industry.gs"
include "DriveToScheduleCommand.gs"
//
// Driver command that allows a driver character to take a train either to a destination industry
// or a specific track in a destination industry.
//
class DriveToCommand isclass DriverCommand
{
   //
   // Initialize parent object and add handlers to process messages for this driver command object.
   //
   public void Init(Asset asset)
   {
      inherited(asset);
      AddHandler(me, "DriveToIndustry", null, "DriveTo");
      AddHandler(me, "DriveToIndustryTrack", null,"DriveToTrack");
   }
   
   //
   // Adds industry destination menu items for all industries to the given menu along with submenus of
   // destination tracks for all industries added.
   //
   public void AddCommandMenuItem(DriverCharacter driver,Menu menu)
   {
      Train train;
      if (driver)
      {
         train = driver.GetTrain();
         if (!train) 
            return;
      }
      StringTable strTable = GetAsset().GetStringTable();
      Menu industriesMenu = Constructors.NewMenu();
      GameObject[] industryList = World.GetIndustryList();
      int i, industryCount = industryList.size();
      if (!industryCount)
         // we dont bother with a `Drive To' command if there are no industries
         return;
      for (i = 0; i < industryCount; i++)
      {
         Industry industry = cast<Industry>(industryList[i]);
         string localisedName = industry.GetLocalisedName();
         string[] locationNames = new string[0];
         string[] locationTracks = new string[0];
         industry.AppendDriverDestinations(locationNames,locationTracks);
         if (localisedName.size())
            if (locationNames.size())
            {
               Menu submenu = Constructors.NewMenu();
               int j;
               for (j = 0; j < locationNames.size(); j++)
               if (locationNames[j] and locationNames[j].size() and locationTracks[j] and locationTracks[j].size())
                  submenu.AddItem(locationNames[j], me, "DriveToIndustryTrack", industry.GetId() + " " + locationTracks[j]);
               else 
                  if (train)
                     train.Exception("Error in `track names' of industry `" + localisedName + "'");
               industriesMenu.AddSubmenu(localisedName + " >",submenu);
            }
            else
               industriesMenu.AddItem(localisedName, me,"DriveToIndustry", industry.GetName());
         industriesMenu.SubdivideItems();
         menu.AddSubmenu(strTable.GetString("driver_command_drive_to") + " >", industriesMenu);
      }
   }
   
   //
   // Called by either DriveTo() or DriveToTrack() to play one of  random driver acknowledgments.
   //
   void PlayConfirmation(void)
   {
      KUID kuid = GetAsset().LookupKUIDTable("command-sounds");
      Library libCommandSounds = World.GetLibrary(kuid);
      if (libCommandSounds)
         libCommandSounds.LibraryCall("PlayConfirmation",null, null);
   }
   
   //
   // Create the schedule command
   //
   DriverScheduleCommand CreateScheduleCommand(DriverCharacter driver, Soup soup)
   {
      DriveToScheduleCommand cmd = new DriveToScheduleCommand();
      cmd.Init(driver, me);
      cmd.SetParent(me);
      cmd.SetProperties(soup);
      return cast<DriverScheduleCommand>cmd;
   }
   
   //
   // Handler method to drive a train to an industry (no specific destination track though).
   //
   void DriveTo(Message msg)
   {
      DriverCommands commands = GetDriverCommands(msg);
      DriverCharacter driver = cast<DriverCharacter>(msg.src);
      string industryName = msg.minor;
      // schedule our command
      Soup soup = Constructors.NewSoup();
      soup.SetNamedTag("industryName", industryName);
      DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
      commands.AddDriverScheduleCommand(cmd);
      if (driver) PlayConfirmation();
   }
  
   //
   // Handler method to drive a train to a specific track in an industry.
   //
   void DriveToTrack(Message msg)
   {
      DriverCommands commands = GetDriverCommands(msg);
      DriverCharacter driver = cast<DriverCharacter>(msg.src);
      string msgData = msg.minor;
      int industryId = Str.UnpackInt(msgData);
      string trackName = Str.UnpackString(msgData);
      GameObject industry = Router.GetGameObject(industryId);
      if (!industry) return;
      // schedule our command
      Soup soup = Constructors.NewSoup();
      soup.SetNamedTag("industryName", industry.GetName());
      soup.SetNamedTag("trackName", trackName);
      DriveToScheduleCommand cmd = cast<DriveToScheduleCommand>CreateScheduleCommand(driver, soup);
      commands.AddDriverScheduleCommand(cmd);
      if (driver) PlayConfirmation();
   }
};

And the dependent script

DriveToScheduleCommand.gs File Fisting

//
// DriveToScheduleCommand.gs
//
// Copyright (C) 2003 Auran Developments Pty Ltd
// All Rights Reserved.
//
include "DriverCommand.gs"
include "World.gs"
include "Browser.gs"
include "KUID.gs"
include "Industry.gs"
include "DriveToCommand.gs"
include "Schedule.gs"
//
// Driver schedule command used by DriveToCommand to get a driver character to take a train to
// a specific track on an industry.
//
class DriveToScheduleCommand isclass DriverScheduleCommand
{
   public string industryName;   // Name of the industry to drive to.
   public string trackName;      // Name of the track in the industry to drive to.
   DriveToCommand parent;
   
   //
   //
   //
   public void SetParent(DriveToCommand newParent)
   {
      parent = newParent;
   }
   
   //
   // Starts executing this schedule command on the given driver character.
   //
   public bool BeginExecute(DriverCharacter driver)
   {
      Train train = driver.GetTrain();
      if (!train)
         // cant drive if we dont have a train
         return false;
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
      if (!industry)
         // cant drive to an industry which doesn't exist
         return false;
      return driver.NavigateToIndustry(industry, trackName);
   }
   
   //
   // we should really implement EndExecute() to allow the game to determine the success of this command
   //
   
   //
   // Provides an icon for this command so it can be seen on the driver's schedule. Uses the industry
   // icon to indicate the destination.
   //
   public object GetIcon(void)
   {
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
      return cast<object>industry;
   }
   
   //
   //
   //
   public string GetTooltip(void)
   {
      StringTable strTable = GetAsset().GetStringTable();
      string userTrackName = trackName;
      Industry industry = cast<Industry>(Router.GetGameObject(industryName));
      if (industry)
      {
         string[] destNames = new string[0];
         string[] destTracks = new string[0];
         industry.AppendDriverDestinations(destNames,destTracks);
         int i;
         for (i = 0; i < destNames.size(); i++)
         {
            if (destTracks[i] == trackName)
            {
               userTrackName = destNames[i];
               break;
            }
         }
      }
      return strTable.GetString("driver_command_drive_to") + industryName + " (" + userTrackName + ")";
   }
   
   //
   //
   //
   public Soup GetProperties(void)
   {
      Soup soup = Constructors.NewSoup();
      // Save support
      // Save the properties to the soup, then return the soup
      soup.SetNamedTag("industryName", industryName);
      soup.SetNamedTag("trackName", trackName);
      return soup;
   }
   
   //
   //
   //
   public void SetProperties(Soup soup)
   {
      // Load support
      // Setup the properties from the passed in soup
      industryName = soup.GetNamedTag("industryName");
      trackName = soup.GetNamedTag("trackName");
   }
};

Download this asset

This asset is available for download from the TRS2006 website at:

Sorry, no download available.

A version of this asset is a built-in for TS2010, TS12.

Return to CCG Index

Content Creator's Guide

Kind Examples