Exemplo n.º 1
0
        /**
         * Get the rail type for a given label.
         * @param label the railtype label.
         * @param allow_alternate_labels Search in the alternate label lists as well.
         * @return the railtype.
         */
        RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
        {
            /* Loop through each rail type until the label is found */
            for (var r = RailType.RAILTYPE_BEGIN; r != RailType.RAILTYPE_END; r++)
            {
                RailtypeInfo rti = GetRailTypeInfo(r);
                if (rti.label == label)
                {
                    return(r);
                }
            }

            if (allow_alternate_labels)
            {
                /* Test if any rail type defines the label as an alternate. */
                for (var r = RailType.RAILTYPE_BEGIN; r != RailType.RAILTYPE_END; r++)
                {
                    RailtypeInfo rti = GetRailTypeInfo(r);
                    if (rti.alternate_labels.Contains(label))
                    {
                        return(r);
                    }
                }
            }

            /* No matching label was found, so it is invalid */
            return(RailType.INVALID_RAILTYPE);
        }
Exemplo n.º 2
0
        /**
         * Add the rail types that are to be introduced at the given date.
         * @param current The currently available railtypes.
         * @param date    The date for the introduction comparisons.
         * @return The rail types that should be available when date
         *         introduced rail types are taken into account as well.
         */
        public RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date)
        {
            RailTypes rts = current;

            for (RailType rt = RailType.RAILTYPE_BEGIN; rt != RailType.RAILTYPE_END; rt++)
            {
                RailtypeInfo rti = GetRailTypeInfo(rt);
                /* Unused rail type. */
                if (rti.label == 0)
                {
                    continue;
                }

                /* Not date introduced. */
                if (!MathFuncs.IsInsideMM(rti.introduction_date, 0, MAX_DAY))
                {
                    continue;
                }

                /* Not yet introduced at this date. */
                if (rti.introduction_date > date)
                {
                    continue;
                }

                /* Have we introduced all required railtypes? */
                RailTypes required = rti.introduction_required_railtypes;
                if ((rts & required) != required)
                {
                    continue;
                }

                rts |= rti.introduces_railtypes;
            }

            /* When we added railtypes we need to run this method again; the added
             * railtypes might enable more rail types to become introduced. */
            return(rts == current ? rts : AddDateIntroducedRailTypes(rts, date));
        }