Example #1
0
File: Unit.cs Project: corefan/yad2
 public Unit(ObjectID id, short typeID, String ammo, BoardObjectClass boc, Position pos, Map map, Simulation sim, short ammoDamageRange, short damageDestroyRange, short damageDestroy, short ammoSpeed)
     : base(id, boc, pos)
 {
     this._typeID               = typeID;
     this._map                  = map;
     this._simulation           = sim;
     this._lastPosition         = pos;
     this._direction            = Direction.North;
     this._currentPath          = new Queue <Position>();
     this._damageDestroy        = damageDestroy;
     this.damageDestroyRange    = damageDestroyRange;
     this.ammoDamageRange       = ammoDamageRange;
     this._mapInput             = new MapInput(sim.Map);
     this._mapInput.IsMoveable += new MapInput.MoveCheckDelegate(this.IsMoveable);
     this._ammoSpeed            = ammoSpeed;
     if (ammo == "Bullet")
     {
         this._ammoType = AmmoType.Bullet;
     }
     else if (ammo == "Rocket")
     {
         this._ammoType = AmmoType.Rocket;
     }
     else if (ammo == "Sonic")
     {
         this._ammoType = AmmoType.Sonic;
     }
     else
     {
         this._ammoType = AmmoType.None;
     }
 }
Example #2
0
 public override void Deserialize(System.IO.BinaryReader reader)
 {
     base.Deserialize(reader);
     unitID   = reader.ReadInt32();
     unitType = reader.ReadInt16();
     unitKind = (BoardObjectClass)reader.ReadInt16();
     position = new Position();
     position.Deserialize(reader);
 }
Example #3
0
        /// <summary>
        /// This will be null for Server.
        /// </summary>
        //Animation animation;

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="pID">playerID</param>
        /// <param name="oID">objectID</param>
        /// <param name="pos">position</param>
        public BoardObject(ObjectID objectID, BoardObjectClass ot, Position pos)
        {
            this.objectID         = objectID;
            this.position         = pos;
            this.boardObjectClass = ot;
        }
Example #4
0
        protected override void onMessageCreate(CreateUnitMessage cum)
        {
            InfoLog.WriteInfo("MessageCreate", EPrefix.Test);
            int              cost = 0;
            Player           p    = players[cum.IdPlayer];
            BoardObjectClass boc  = cum.UnitKind;
            Unit             u    = null;
            ObjectID         id   = new ObjectID(cum.IdPlayer, p.GenerateObjectID());

            InfoLog.WriteInfo(id.ToString() + " unit created: " + cum.Type, EPrefix.GObj);
            if (boc == BoardObjectClass.UnitTank)
            {
                if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.tanksMap[cum.UnitType].Cost))
                {
                    return;
                }
                u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[cum.UnitType], cum.Position, this._map, this);
                players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.tanksMap[cum.UnitType].Cost;
            }
            else if (boc == BoardObjectClass.UnitTrooper)
            {
                if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.troopersMap[cum.UnitType].Cost))
                {
                    return;
                }
                u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[cum.UnitType], cum.Position, this._map, this);
                players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.troopersMap[cum.UnitType].Cost;
            }
            else if (boc == BoardObjectClass.UnitHarvester)
            {
                if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.harvestersMap[cum.UnitType].Cost))
                {
                    return;
                }
                u = new UnitHarvester(id, GlobalSettings.Wrapper.harvestersMap[cum.UnitType], cum.Position, this._map, this, GlobalSettings.Wrapper.harvestersMap[cum.UnitType].__Speed);
                ((UnitHarvester)u).SpiceUnload += new SpiceUnloadDelegate(SpiceUnload);
                players[cum.IdPlayer].Credits  -= GlobalSettings.Wrapper.harvestersMap[cum.UnitType].Cost;
            }
            else if (boc == BoardObjectClass.UnitMCV)
            {
                if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.mcvsMap[cum.UnitType].Cost))
                {
                    return;
                }
                u = new UnitMCV(id, GlobalSettings.Wrapper.mcvsMap[cum.UnitType], cum.Position, this._map, this);
                players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.mcvsMap[cum.UnitType].Cost;
            }
            else if (boc == BoardObjectClass.UnitSandworm)
            {
                u = new UnitSandworm(id, GlobalSettings.Wrapper.sandwormsMap[cum.UnitType], cum.Position, this._map, this, GlobalSettings.Wrapper.sandwormsMap[cum.UnitType].__Speed);
                Sandworms[id.ObjectId] = (UnitSandworm)u;
                return;
                //} else if (boc == BoardObjectClass.UnitTank) {
                //    u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[cum.UnitType], cum.Position, this._map, this);
                //} else if (boc == BoardObjectClass.UnitTrooper) {
                //    u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[cum.UnitType], cum.Position, this._map, this);
            }
            OnCreditsUpdate(cum.IdPlayer, cost);
            p.AddUnit(u);
            ClearFogOfWar(u);

            OnUnitCompleted(u);
        }