Exemplo n.º 1
0
    void InstantiateModel(RailType railType)
    {
        //Destroy the existing rail
        if (instancedRail != null)
        {
            Destroy(instancedRail.gameObject);
        }

        switch (railType)
        {
        case RailType.Horizontal:
        case RailType.Vertical:
            instancedRail = Instantiate(railStraightPrefab, transform);
            break;

        case RailType.TopRight:
        case RailType.RightBottom:
        case RailType.BottomLeft:
        case RailType.LeftTop:
            instancedRail = Instantiate(railTurnPrefab, transform);
            break;
        }

        currentType = railType;
    }
Exemplo n.º 2
0
    void OnTileTypeChanged(RailType newType)
    {
        //Instantiation
        //If the new type is None, simply destroy our existing model if any
        if (newType == RailType.None)
        {
            if (instancedRail != null)
            {
                Destroy(instancedRail.gameObject);
            }
            return;
        }

        if (currentType.IsStraight() && instancedRail != null)
        {
            if (newType.IsTurn())
            {
                InstantiateModel(newType);
            }
        }
        else if (currentType.IsTurn() && instancedRail != null)
        {
            if (newType.IsStraight())
            {
                InstantiateModel(newType);
            }
        }
        //No existing model
        else
        {
            InstantiateModel(newType);
        }

        RotateRailModel(newType);
    }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rail"/> class.
 /// </summary>
 /// <param name="id">The database ID of the rail</param>
 /// <param name="number">The number associated with the rail</param>
 /// <param name="type">The type which indicates what the rail is used for</param>
 /// <param name="line">The line which the Rail is associated with</param>
 public Rail(int id, int number, RailType type, Line line)
     : this(id)
 {
     this.Number = number;
     this.Type = type;
     this.Line = line;
     this.Sectors = new List<Sector>();
 }
Exemplo n.º 4
0
/**
 * Returns the 'cost' of clearing the specified railtype.
 * @param railtype The railtype being removed.
 * @return The cost.
 */
        public static Money RailClearCost(RailType railtype)
        {
            /* Clearing rail in fact earns money, but if the build cost is set
             * very low then a loophole exists where money can be made.
             * In this case we limit the removal earnings to 3/4s of the build
             * cost.
             */
            Debug.Assert(railtype < RailType.RAILTYPE_END);
            return(Math.Max(_price[PR_CLEAR_RAIL], -RailBuildCost(railtype) * 3 / 4));
        }
Exemplo n.º 5
0
 public static void MakeRailNormal(this TileIndex t, Owner o, TrackBits b, RailType r)
 {
     TileMap.SetTileType(t, TileType.MP_RAILWAY);
     TileMap.SetTileOwner(t, o);
     Map._m[t].m2 = 0;
     Map._m[t].m3 = (byte)r;
     Map._m[t].m4 = 0;
     Map._m[t].m5 = (byte)((int)RailTileType.RAIL_TILE_NORMAL << 6 | b);
     BitMath.SB(Map._me[t].m6, 2, 4, 0);
     Map._me[t].m7 = 0;
 }
Exemplo n.º 6
0
/**
 * Generic part to make a bridge ramp for both roads and rails.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param bridgetype the type of bridge this bridge ramp belongs to
 * @param d          the direction this ramp must be facing
 * @param tt         the transport type of the bridge
 * @param rt         the road or rail type
 * @note this function should not be called directly.
 */
        public static void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d,
                                          TransportType tt, RailType rt)
        {
            TileMap.SetTileType(t, TileType.MP_TUNNELBRIDGE);
            TileMap.SetTileOwner(t, o);
            Map._m[t].m2 = 0;
            Map._m[t].m3 = (byte)rt;
            Map._m[t].m4 = 0;
            Map._m[t].m5 = (byte)(1 << 7 | (byte)tt << 2 | (byte)d);
            BitMath.SB(ref Map._me[t].m6, 2, 4, bridgetype);
            Map._me[t].m7 = 0;
        }
Exemplo n.º 7
0
/**
 * Make a level crossing.
 * @param t       Tile to make a level crossing.
 * @param road    New owner of road.
 * @param tram    New owner of tram tracks.
 * @param rail    New owner of the rail track.
 * @param roaddir Axis of the road.
 * @param rat     New rail type.
 * @param rot     New present road types.
 * @param town    Town ID if the road is a town-owned road.
 */
        public static void MakeRoadCrossing(this TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir,
                                            RailType rat, RoadTypes rot, uint town)
        {
            TileMap.SetTileType(t, TileType.MP_ROAD);
            TileMap.SetTileOwner(t, rail);
            Map._m[t].m2  = town;
            Map._m[t].m3  = rat;
            Map._m[t].m4  = 0;
            Map._m[t].m5  = RoadTileType.ROAD_TILE_CROSSING << 6 | roaddir;
            Map._me[t].m6 = BitMath.SB(Map._me[t].m6, 2, 4, 0);
            Map._me[t].m7 = rot << 6 | road;
            SetRoadOwner(t, RoadType.ROADTYPE_TRAM, tram);
        }
Exemplo n.º 8
0
        private MyPGM GetSwitch(RailType rt, bool Right)
        {
            MyPGM FlipFlopSwitch = new MyPGM(Size, Size, m_Switch);

            FlipFlopSwitch.SetValue(0, 0, (byte)rt);
            if (Right)
            {
                FlipFlopSwitch.SetValue(5, 1, 128);
            }
            else
            {
                FlipFlopSwitch.SetValue(2, 1, 128);
            }

            return(FlipFlopSwitch);
        }
Exemplo n.º 9
0
/**
 * Calculates the cost of rail conversion
 * @param from The railtype we are converting from
 * @param to   The railtype we are converting to
 * @return Cost per TrackBit
 */
        public static Money RailConvertCost(RailType from, RailType to)
        {
            /* Get the costs for removing and building anew
             * A conversion can never be more costly */
            Money rebuildcost = RailBuildCost(to) + RailClearCost(from);

            /* Conversion between somewhat compatible railtypes:
             * Pay 1/8 of the target rail cost (labour costs) and additionally any difference in the
             * build costs, if the target type is more expensive (material upgrade costs).
             * Upgrade can never be more expensive than re-building. */
            if (HasPowerOnRail(from, to) || HasPowerOnRail(to, from))
            {
                Money upgradecost = RailBuildCost(to) / 8 +
                                    Math.Max((Money)0, RailBuildCost(to) - RailBuildCost(from));
                return(Math.Min(upgradecost, rebuildcost));
            }

            /* make the price the same as remove + build new type for rail types
             * which are not compatible in any way */
            return(rebuildcost);
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
    void RotateRailModel(RailType railType)
    {
        //Rotation
        switch (railType)
        {
        case RailType.Horizontal:
        case RailType.RightBottom:
            instancedRail.localEulerAngles = Vector3.up * 90;
            break;

        case RailType.Vertical:
        case RailType.TopRight:
            instancedRail.localEulerAngles = Vector3.zero;
            break;

        case RailType.BottomLeft:
            instancedRail.localEulerAngles = Vector3.up * 180;
            break;

        case RailType.LeftTop:
            instancedRail.localEulerAngles = Vector3.up * 270;
            break;
        }
    }
Exemplo n.º 12
0
 /**
  * Convert the tracks on all tiles within a rectangle to another RailType.
  * @param start_tile One corner of the rectangle.
  * @param end_tile The opposite corner of the rectangle.
  * @param convert_to The RailType you want to convert the rails to.
  * @exception AIRail.ERR_UNSUITABLE_TRACK
  * @returns Whether at least some rail has been converted successfully.
  */
 public static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, RailType convert_to)
 {
     throw null;
 }
Exemplo n.º 13
0
 /**
  * Check if a train build for a rail type has power on another rail type.
  * @param engine_rail_type The rail type the train is build for.
  * @param track_rail_type The type you want to check.
  * @returns Whether a train build for 'engine_rail_type' has power on 'track_rail_type'.
  */
 public static bool TrainHasPowerOnRail(RailType engine_rail_type, RailType track_rail_type)
 {
     throw null;
 }
Exemplo n.º 14
0
 /**
  * Check if a train build for a rail type can run on another rail type.
  * @param engine_rail_type The rail type the train is build for.
  * @param track_rail_type The type you want to check.
  * @returns Whether a train build for 'engine_rail_type' can run on 'track_rail_type'.
  * @note Even if a train can run on a RailType that doesn't mean that it'll be
  *   able to power the train. Use TrainHasPowerOnRail for that.
  */
 public static bool TrainCanRunOnRail(RailType engine_rail_type, RailType track_rail_type)
 {
     throw null;
 }
Exemplo n.º 15
0
 /**
  * Validate functions for rail building.
  * @param rail the railtype to check.
  * @return true if the current company may build the rail.
  */
 public bool ValParamRailtype(RailType rail)
 {
     return(rail < RailType.RAILTYPE_END && HasRailtypeAvail(_current_company, rail));
 }
Exemplo n.º 16
0
 public Parking(RailType type) : base(type)
 {
 }
Exemplo n.º 17
0
 /**
  * Check if a train vehicle can run on a RailType.
  * @param engine_id The engine to check.
  * @param track_rail_type The type you want to check.
  * @returns Whether an engine of type 'engine_id' can run on 'track_rail_type'.
  * @note Even if a train can run on a RailType that doesn't mean that it'll be
  *   able to power the train. Use HasPowerOnRail for that.
  */
 public static bool CanRunOnRail(EngineID engine_id, RailType track_rail_type)
 {
     throw null;
 }
Exemplo n.º 18
0
 /**
  * Get the maintenance cost factor of a railtype.
  * @param railtype The railtype to get the maintenance factor of.
  * @returns Maintenance cost factor of the railtype.
  */
 public static int GetMaintenanceCostFactor(RailType railtype)
 {
     throw null;
 }
Exemplo n.º 19
0
/**
 * Make a bridge ramp for rails.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param bridgetype the type of bridge this bridge ramp belongs to
 * @param d          the direction this ramp must be facing
 * @param r          the rail type of the bridge
 */
        public static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
        {
            MakeBridgeRamp(t, o, bridgetype, d, TransportType.TRANSPORT_RAIL, r);
        }
Exemplo n.º 20
0
/**
 * Calculates the maintenance cost of a number of track bits.
 * @param railtype The railtype to get the cost of.
 * @param num Number of track bits of this railtype.
 * @param total_num Total number of track bits of all railtypes.
 * @return Total cost.
 */
        public static Money RailMaintenanceCost(this RailType railtype, uint num, uint total_num)
        {
            Debug.Assert(railtype < RailType.RAILTYPE_END);
            return((_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype).maintenance_multiplier *num *
                    (1 + IntSqrt(total_num))) >> 11);    // 4 bits fraction for the multiplier and 7 bits scaling.
        }
Exemplo n.º 21
0
 public static bool IsStraight(this RailType railType)
 {
     return(railType == RailType.Horizontal || railType == RailType.Vertical);
 }
Exemplo n.º 22
0
 public static bool IsTurn(this RailType railType)
 {
     return(railType == RailType.TopRight || railType == RailType.RightBottom || railType == RailType.BottomLeft || railType == RailType.LeftTop);
 }
Exemplo n.º 23
0
 /**
  * Get the baseprice of building a rail-related object.
  * @param railtype the railtype that is build (on)
  * @param build_type the type of object to build
  * @returns The baseprice of building the given object.
  */
 public static long GetBuildCost(RailType railtype, BuildType build_type)
 {
     throw null;
 }
Exemplo n.º 24
0
 /**
  * Get the maximum speed of trains running on this railtype.
  * @param railtype The railtype to get the maximum speed of.
  * @returns The maximum speed trains can run on this railtype
  *   or 0 if there is no limit.
  * @note The speed is in OpenTTD's internal speed unit.
  *       This is mph / 1.6, which is roughly km/h.
  *       To get km/h multiply this number by 1.00584.
  */
 public static int GetMaxSpeed(RailType railtype)
 {
     throw null;
 }
Exemplo n.º 25
0
 public Warehouse(RailType type, char key) : base(type)
 {
     Key = key;
 }
Exemplo n.º 26
0
 /**
  * Get the name of a rail type.
  * @param rail_type The rail type to get the name of.
  * @returns The name the rail type has.
  * @note Since there is no string with only the name of the track, the text which
  *  is shown in the dropdown where you can chose a track type is returned. This
  *  means that the name could be something like "Maglev construction" instead
  *  of just "Maglev".
  */
 public static string GetName(RailType rail_type)
 {
     throw null;
 }
Exemplo n.º 27
0
 /**
  * Check if a given RailType is available.
  * @param rail_type The RailType to check for.
  * @returns True if this RailType can be used.
  */
 public static bool IsRailTypeAvailable(RailType rail_type)
 {
     throw null;
 }
Exemplo n.º 28
0
 /**
  * Check if a train engine has power on a RailType.
  * @param engine_id The engine to check.
  * @param track_rail_type Another RailType.
  * @returns Whether an engine of type 'engine_id' has power on 'track_rail_type'.
  */
 public static bool HasPowerOnRail(EngineID engine_id, RailType track_rail_type)
 {
     throw null;
 }
Exemplo n.º 29
0
 /// <summary>Set the RailType for all further ScriptRail functions.</summary><param name="rail_type">The RailType to set.</param>
 public static void SetCurrentRailType(RailType rail_type)
 {
     throw null;
 }
Exemplo n.º 30
0
        private FillerRailSelectPropertyPanel AddRailProperty(FillerContour contour, UIComponent parent, string name, PropertyValue <int> railA, PropertyValue <int> railB, RailType railType, string label)
        {
            var rail         = new FillerRail(contour.GetCorrectIndex(railA), contour.GetCorrectIndex(railB));
            var railProperty = ComponentPool.Get <FillerRailSelectPropertyPanel>(parent, name);

            railProperty.Text = label;
            railProperty.Init(railType);
            railProperty.Value           = rail;
            railProperty.OnValueChanged += RailPropertyChanged;
            return(railProperty);

            void RailPropertyChanged(FillerRail rail)
            {
                railA.Value = rail.A;
                railB.Value = rail.B;
            }
        }
Exemplo n.º 31
0
 /**
  * Finds out if a company has a certain railtype available
  * @param company the company in question
  * @param railtype requested RailType
  * @return true if company has requested RailType available
  */
 public bool HasRailtypeAvail(CompanyID company, RailType railtype)
 {
     return(BitMath.HasBit(Company.Get(company).avail_railtypes, railtype));
 }