Exemplo n.º 1
0
        // TODO Check and clean this method
        public static Track FindStationNamed(Station station)
        {
            if (station == null || String1.IsNullOrWhiteSpaces(station.StationName))
            {
                return(null);
            }

            string stationName = station.StationName;

            // for(t = Globals.layout; t != null; t = t.next) {
            foreach (Track t in Globals.LayoutList)
            {
                if (t.station == null)
                {
                    continue;
                }

                if (!stationName.Equals(t.station))
                {
                    continue;
                }

                switch (t.TrackType)
                {
                case trktype.TRACK:
                    // if(t.type == trktype.TRACK && t.isstation && !Globals.wxStrncmp(name, t.station, len)) {
                    if (t.isstation)
                    {
                        return(t);
                    }

                    break;

                case trktype.TEXT:
                    // if(t.type == trktype.TEXT && !wxStrcmp(stationName, t.station) &&
                    // ((t.wlinkx && t.wlinky) || (t.elinkx && t.elinky)))
                    if ((t.wlinkx != 0 && t.wlinky != 0) || (t.elinkx != 0 && t.elinky != 0))
                    {
                        return(t);
                    }
                    break;

                case trktype.SWITCH:
                    // if(t.type == trktype.SWITCH && !wxStrcmp(stationName, t.station))
                    return(t);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        //public Train() {
        //  //next = 0;
        //  //name = 0;		/* train name or number */
        //  //status = train_READY;	/* status: running, waiting etc. */
        //  //sdirection = W_E;	/* starting direction: W_E or E_W */
        //  //direction = W_E;	/* current direction: W_E or E_W */
        //  //timein = 0;		/* time it shows up on territory */
        //  //timeout = 0;		/* time it should be out of territory */
        //  //entrance = 0;
        //  //exit = 0;
        //  //exited = 0;		/* if wrongdest, where we exited */
        //  //timeexited = 0;		/* when we exited */
        //  //memset(notes, 0, sizeof(notes));
        //  //nnotes = 0;
        //  //wrongdest = 0;		/* train arrived at wrong destination */
        //  //type = 0;		/* train type */
        //  //_gotDelay = 0;		/* we computed a delay upon entry in the territory */
        //  //_inDelay = 0;		/* the computed delay, in minutes */
        //  //newsched = 0;		/* must update schedule window for this train */
        //  //curspeed = 0;		/* current speed */
        //  //maxspeed = 0;		/* absolute maximum speed */
        //  //curmaxspeed = 0;	/* current (absolute or track) maximum speed */
        //  //speedlimit = 0;		/* last speed limit seen */
        //  //timelate = 0;		/* minutes late arriving at all stations */
        //  //timedelay = 0;		/* minutes late entering territory */
        //  //timered = 0;		/* minutes stopped at red signal */
        //  //trackpos = 0;		/* how much of lengthy tracks we travelled */
        //  //stops = 0;		/* list of scheduled stops */
        //  //laststop = 0;		/* last in list of scheduled stops */
        //  //length = 0;		/* current train length in meters */
        //  //entryLength = 0;	/* train length at entry into territory */
        //  ////	pathpos = 0;		/* index into path[] of train head */
        //  //path = 0;		/* track elements to be travelled by train head */
        //  //tail = 0;		/* descriptor of train's end (if length != 0) */
        //  //pathtravelled = 0;	/* meters travelled in current path */
        //  //disttostop = 0;		/* distance until next stop */
        //  //stoppoint = 0;
        //  //disttoslow = 0;	        /* distance until next speed limit signal */
        //  //slowpoint = 0;
        //  //position = 0;		/* where the train is in the territory */
        //  //timedep = 0;		/* expected time of departure from station */
        //  //fleet = 0;		/* list of signals waiting for tail to pass */
        //  //waitfor = 0;		/* must wait for this train to exit territory*/
        //  //waittime = 0;	        /* how many minutes after waitee has arrived we depart */
        //  //stock = 0;		/* next train which uses this train's stock */
        //  //epix = 0; wpix = 0;	/* indexes to east and west pixmaps */
        //  //ecarpix = 0; wcarpix = 0;/* indexes of east abd west car pixmaps (if length != 0) */
        //  //outof = 0;		/* ignore this station when checking shunting */
        //  //stopping = 0;		/* we are stopping/stopped at this station */
        //  //oldstatus = train_READY;
        //  //arrived = 0;		/* if true we are just shunting */
        //  //shunting = 0;
        //  //days = 0;		/* which day this train is running */
        //  //flags = 0;		/* performance flags (TFLG_*) */
        //  //needfindstop = 0;	/* terrible hack! */
        //  //merging = 0;		/* will merge with this train */
        //  //entryDelay = 0;
        //  //isExternal = 0;         /* train does not run in this scenario */
        //  //startDelay = 0;
        //  //myStartDelay = 0;
        //  //accelRate = 0;          // 3.8r
        //  //power = 0;              // 3.9

        //  //// start to use C++ methods to make the code cleaner

        //  //stateProgram = 0;
        //  //_interpreterData = 0;
        //  //_lastUpdate = 0;
        //}

        //~Train()	    // recursive for tails!
        //{
        //  //TrainStop ts, ts1;

        //  //if(this.tail) {
        //  //  Globals.delete(this.tail);
        //  //  this.tail = 0;
        //  //}
        //  //if(this.path)
        //  //  Vector_delete(this.path);
        //  //if(this.name)
        //  //  Globals.free(this.name);
        //  //if(this.entrance)
        //  //  Globals.free(this.entrance);
        //  //if(this.exit)
        //  //  Globals.free(this.exit);
        //  //for(ts = this.stops; ts; ts = ts1) {
        //  //  ts1 = ts.next;
        //  //  if(ts.station)
        //  //    Globals.free(ts.station);
        //  //  Globals.free(ts);
        //  //}
        //}


        //public void Get(TrainInfo info) {
        //  //string buff;

        //  //if(_gotDelay && _inDelay) {
        //  //  buff = String.Format( wxPorting.T("%s"), format_time(this.timein));
        //  //  buff + Globals.wxStrlen(buff) = String.Format( wxPorting.T(" (%s)"), format_time(this.timein + this._inDelay));
        //  //  info.entering_time = String.Copy( buff);;
        //  //} else
        //  //  info.entering_time = String.Copy( format_time(this.timein));
        //  //info.leaving_time = String.Copy( format_time(this.timeout));
        //  //info.current_speed = String.Format( wxPorting.T("%d"), (int)this.curspeed);
        //  //info.current_delay = String.Format( wxPorting.T("%d"), this.timedelay / 60);
        //  //info.current_late = String.Format( wxPorting.T("%d"), this.timelate);
        //  ////disp_columns[4] = this.name;
        //  ////disp_columns[1] = this.entrance;
        //  ////disp_columns[2] = this.exit;
        //  //info.current_status = String.Copy( train_status(this));
        //  ///*	current_status + Globals.wxStrlen(current_status) = String.Format(
        //  //      wxPorting.T("  pos: %ld - %ld"), t.pathtravelled, t.trackpos);*/
        //}


        //public bool CanTravelOn(Vector path) {
        //  throw new NotImplementedException();

        //  //int i;

        //  //if(!this.power)    // no power specified, means can travel anywhere
        //  //  return true;
        //  //for(i = 0; i < path._size; ++i) {
        //  //  Track* trk = path.TrackAt(i);
        //  //  if(trk.type == TEXT) // we reached an exit
        //  //    return true;
        //  //  if(!trk.power)
        //  //    return false;
        //  //  if(wxStrcmp(trk.power, this.power)) {
        //  //    return false; // different power specified (e.g. 3000V vs. 10000V)
        //  //  }
        //  //}
        //  //return true;
        //}


        public void ParseProgram()
        {
            String p;

            if (String1.IsNullOrWhiteSpaces(this.stateProgram))
            {
                return;
            }
            _interpreterData = new TrainInterpreterData();

            TrainInterpreterData interp = (TrainInterpreterData)_interpreterData;

            p = this.stateProgram;
            while (String1.IsNullOrWhiteSpaces(p) == false)
            {
                String p1 = p;
                while (p.Length > 0 && (p[0] == ' ' || p[0] == '\t' || p[0] == '\r' || p[0] == '\n'))
                {
                    p = p.Substring(1);
                }
                if (Globals.match(ref p, wxPorting.T("OnInit:")))
                {
                    p1             = p;
                    interp._onInit = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnEntry:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onEntry = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnExit:")))
                {
                    p              = Globals.next_token(p);
                    p1             = p;
                    interp._onExit = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnStop:")))
                {
                    p              = Globals.next_token(p);
                    p1             = p;
                    interp._onStop = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnWaiting:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onWaiting = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnStart:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onStart = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnAssign:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onAssign = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnArrived:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onArrived = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnReverse:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onReverse = Globals.ParseStatements(ref p);
                }
                else if (Globals.match(ref p, wxPorting.T("OnShunt:")))
                {
                    p  = Globals.next_token(p);
                    p1 = p;
                    interp._onShunt = Globals.ParseStatements(ref p);
                }
                if (p1 == p) // error! couldn't parse token
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public static void pointer_at(Coord cell)
        {
            Track         t;
            Signal        sig;
            Train         tr;
            int           x  = cell.x;
            int           y  = cell.y;
            String        p  = "";
            StringBuilder sb = new StringBuilder();

            tooltipString = "";
            // TODO Re-Enable this case
            if (false) // (tr = findTrain(x, y))) {
            //status_line = String.Format(wxPorting.T("%d,%d: %s %s"), x, y, tr.name, train_status0(tr, 1));
            //tr.SetTooltip();
            {
            }
            else if ((t = findTrack(x, y)) != null || (t = findSwitch(x, y)) != null)
            {
                sb.AppendFormat("{0:D},{1:D}: {2} ", x, y, wxPorting.L("speed"));
                for (x = 0; x < Config.NTTYPES; ++x)
                {
                    if (x > 0)
                    {
                        sb.Append("/");
                    }
                    sb.AppendFormat("{0:D}", t.speed[x]);
                }
                sb.AppendFormat((" Km/h, {0} {1:D} m"), wxPorting.L("length"), t.length);
                if (t.isstation)
                {
                    sb.AppendFormat("  {0}: {1}", wxPorting.L("Station"), t.station);
                }
            }
            else if ((t = findText(x, y)) != null)
            {
                sb.AppendFormat(
                    "{0:D},{1:D}: {2} {3}",
                    x, y, wxPorting.L("entry/exit"), t.station
                    );
                add_linked_info_to_status(sb, t);
            }
            else if ((sig = findSignal(x, y)) != null)
            {
                if (sig.controls != null)
                {
                    sb.AppendFormat(
                        "{0:D},{1:D}: {2} {3} {4} {5:D}, {0:D}",
                        x, y,
                        wxPorting.L("Signal"),
                        sig.station != null ? sig.station.FullName : wxPorting.T(""),
                        wxPorting.L("controls"),
                        sig.controls.x, sig.controls.y
                        );
                }
                else
                {
                    sb.AppendFormat(
                        "{0:D},{1:D}: {2} {3}",
                        x, y,
                        wxPorting.L("Signal"),
                        sig.station != null ? sig.station.FullName : wxPorting.T("")
                        );
                }
                if (String1.IsNullOrWhiteSpaces(sig.stateProgram) == false)
                {
                    sb.AppendFormat(
                        wxPorting.T("  {0}: \"{1}\""),
                        wxPorting.L("script"), sig.stateProgram
                        );
                    sb.AppendFormat(
                        wxPorting.T("  {0}: \"{1}\""),
                        wxPorting.L("aspect"),
                        sig._currentState != null ? sig._currentState : wxPorting.T("?")
                        );
                }
            }
            else if ((t = findTrackType(x, y, trktype.TRIGGER)) != null)
            {
                sb.AppendFormat("{0:D},{1:D}: {2} - {3}  . ({4:D},{5:D})  Prob.: ",
                                x, y,
                                wxPorting.L("Trigger"),
                                t.station != null ? t.station.FullName : wxPorting.T(""),
                                t.wlinkx, t.wlinky
                                );
                for (x = 0; x < Config.NTTYPES; ++x)
                {
                    if (x > 0)
                    {
                        sb.Append("/");
                    }
                    sb.AppendFormat("{0:D}", t.speed[x]);
                }
            }
            else if ((t = findTrackType(x, y, trktype.ITIN)) != null)
            {
                sb.AppendFormat(
                    "{0:D},{1:D}: {2} - {3}",
                    x, y, wxPorting.L("Itinerary"),
                    t.station != null ? t.station.FullName : wxPorting.T("")
                    );
            }
            else if ((t = findTrackType(x, y, trktype.IMAGE)) != null)
            {
                sb.AppendFormat(
                    "{0:D},{1:D}: {2} {3}",
                    x, y, wxPorting.L("Image"),
                    t.station != null ? t.station.FullName : wxPorting.T("")
                    );
                add_linked_info_to_status(sb, t);
            }
            else
            {
                // status_line[0] = 0;
            }
            labelList.status_line = sb.ToString();
            repaint_labels();
        }