コード例 #1
0
        /// <summary>
        /// Creates and adds a new vehicle to the arena
        /// </summary>
        public Vehicle newVehicle(VehInfo type, Team team, Player creator, Helpers.ObjectState state, Action <Vehicle> setupCB, Type classType)
        {       //Too many vehicles?
            if (_vehicles.Count == maxVehicles)
            {
                Log.write(TLog.Warning, "Vehicle list full.");
                return(null);
            }

            //We want to continue wrapping around the vehicleid limits
            //looking for empty spots.
            ushort vk;

            for (vk = _lastVehicleKey; vk <= UInt16.MaxValue; ++vk)
            {   //If we've reached the maximum, wrap around
                if (vk == UInt16.MaxValue)
                {
                    vk = 5001;
                    continue;
                }

                //Does such a vehicle exist?
                if (_vehicles.getObjByID(vk) != null)
                {
                    continue;
                }

                //We have a space!
                break;
            }

            //TODO: There might be some kind of strange bug regarding re-used vehicle
            //		ids, even if you attempt to dispose of them.
            _lastVehicleKey = (ushort)(vk + 1);

            //Create our vehicle class
            Vehicle veh;

            if (classType == null)
            {
                if (type.Type == VehInfo.Types.Computer)
                {
                    veh = new Computer(type as VehInfo.Computer, this);
                }
                else
                {
                    veh = new Vehicle(type, this);
                }
            }
            else
            {
                veh = Activator.CreateInstance(classType, type, this) as Vehicle;
            }

            veh._id = vk;

            veh._team    = team;
            veh._creator = creator;
            veh._oldTeam = creator != null ? creator._team : null;

            veh._tickUnoccupied = veh._tickCreation = Environment.TickCount;

            if (state != null)
            {
                veh._state.positionX = state.positionX;
                veh._state.positionY = state.positionY;
                veh._state.positionZ = state.positionZ;
                veh._state.yaw       = state.yaw;

                if (veh._type.Type == VehInfo.Types.Computer)
                {
                    veh._state.fireAngle = state.yaw; //Temporary fix for computer updates rotating north by default, perm fix would be sc_vehices.cs packet fix
                }
                if (veh._type.Type == VehInfo.Types.Dependent)
                {
                    VehInfo.Dependent dep = veh._type as VehInfo.Dependent;
                    veh._state.pitch = (byte)(dep.ChildElevationLowAngle > 0 ? dep.ChildElevationLowAngle : 0);
                }
            }

            veh.assignDefaultState();

            //Custom setup?
            if (setupCB != null)
            {
                setupCB(veh);
            }

            //This uses the new ID automatically
            _vehicles.Add(veh);

            //Notify everyone of the new vehicle
            Helpers.Object_Vehicles(Players, veh);

            //Handle dependent vehicles?
            int slot = 0;

            foreach (int vid in veh._type.ChildVehicles)
            {   //Nothing?
                slot++;

                if (vid <= 0)
                {
                    continue;
                }

                //Find the vehicle type
                VehInfo childType = _server._assets.getVehicleByID(vid);

                if (childType == null)
                {
                    Log.write(TLog.Error, "Invalid child vehicle id '{0}' for {1}.", vid, type);
                    continue;
                }

                //Create it!
                Vehicle child = newVehicle(childType, team, creator, state,
                                           delegate(Vehicle c)
                {
                    c._parent     = veh;
                    c._parentSlot = slot - 1;
                }
                                           );

                veh._childs.Add(child);

                //Notify everyone of the new vehicle
                Helpers.Object_Vehicles(Players, child);
            }

            //If it's not a spectator or dependent vehicle, let the arena pass it to the script
            if (type.Type != VehInfo.Types.Dependent && type.Type != VehInfo.Types.Spectator)
            {
                handleVehicleCreation(veh, team, creator);
            }

            return(veh);
        }
コード例 #2
0
 /// <summary>
 /// Creates and adds a new vehicle to the arena
 /// </summary>
 public Vehicle newVehicle(VehInfo type, Team team, Player creator, Helpers.ObjectState state)
 {       //Redirect
     return(newVehicle(type, team, creator, state, null));
 }
コード例 #3
0
 /// <summary>
 /// Creates and adds a new vehicle to the arena
 /// </summary>
 public Vehicle newVehicle(VehInfo type, Team team, Player creator, Helpers.ObjectState state, Action <Vehicle> setupCB)
 {
     return(newVehicle(type, team, creator, state, setupCB, null));
 }
コード例 #4
0
 /// <summary>
 /// Creates and adds a new vehicle to the arena
 /// </summary>
 public Vehicle newVehicle(VehInfo type, Team team, Player creator)
 {       //Redirect
     return(newVehicle(type, team, creator, null, null));
 }