chiark / gitweb /
direction command
authorian <ian>
Wed, 16 Jul 2008 20:51:49 +0000 (20:51 +0000)
committerian <ian>
Wed, 16 Jul 2008 20:51:49 +0000 (20:51 +0000)
hostside/README.commands
hostside/commands.c

index 08ef4ad608bbccfdc29591e7f6de0fe4c52e1c8a..463dd534e5833e596505ecda9dcc729167781d32 100644 (file)
@@ -199,6 +199,8 @@ INCOMPLETE LIST OF OTHER COMMANDS
  movfeat++ <as above>                          } see route++
  !movfeat                                      } see !route
 
+ direction forwards|backwards|change <train>
+
 DIRECT NMRA AND PIC INSTRUCTIONS
 
                                             Example (always the same msg):
index 12d904c753a483b25aa57e0631eb8eaf4531526d..52d28757ee2748aa5dedba656306abe5a88b408b 100644 (file)
@@ -347,6 +347,23 @@ static int cmd_invert(ParseState *ps, const CmdInfo *ci) {
   return 0;
 }
 
+static int cmd_direction(ParseState *ps, const CmdInfo *ci) {
+  Train *tra;
+  int backwards;
+
+  MUSTECR( ps_needword(ps) );
+  if (!thiswordstrcmp(ps,"forwards")) backwards= 0;
+  else if (!thiswordstrcmp(ps,"backwards")) backwards= 1;
+  else if (!thiswordstrcmp(ps,"change")) backwards= !tra->backwards;
+  else return badcmd(ps, "direction must be forwards|backwards|change");
+
+  MUSTECR( ps_needtrain(ps,&tra) );
+  MUSTECR( ps_neednoargs(ps) );
+  
+  MUSTECRPREDICT( safety_setdirection(tra,backwards,CMDPPC) );
+  return 0;
+}
+
 /*---------- general machinery and the command table ----------*/ 
  
 void command_doline(ParseState *ps, CommandInput *cmdi_arg) {
@@ -396,5 +413,6 @@ const CmdInfo toplevel_cmds[]= {
   { "!invert",    cmd_invert,     CIXF_ANYSTA|CIXF_FORCE   },
   { "speed",      cmd_speed                                },
   { "!speed",     cmd_speed,      CIXF_ANYSTA|CIXF_FORCE   },
+  { "direction",  cmd_direction                            },
   { 0 }
 };