Exemple #1
0
 public override void AttackCommand(Entity target)
 {
     if (!motor.Reachable(target.position))
     {
         return;
     }
     if (target.team == entity.team)
     {
         foreach (var collector in target.GetComponents <ResourceCollectionPoint>())
         {
             if (collector.resourceId == resourceId)
             {
                 this.collector = collector;
                 motor.Stop();
                 is_idle             = false;
                 moving_to_collector = true;
             }
         }
     }
     foreach (var resource in target.GetComponents <ResourceSource>())
     {
         if (resource.resourceId == resourceId && !resource.occupied)
         {
             this.resource = resource;
             motor.Stop();
             is_idle             = false;
             moving_to_collector = false;
         }
     }
 }
Exemple #2
0
 public override void OnTick()
 {
     if (source != null && (source.occupied || source.Depleted()))
     {
         source = null;
         motor.Stop();
     }
     if (source != null)
     {
         var dist = World.current.map.Distance(entity.position, source.entity.position);
         if (dist < 1)
         {
             var ent = World.current.Instantiate(mineTypes.First(kv => kv.Key == source.resourceId).Value,
                                                 entity.team,
                                                 source.entity.position);
             ent.rotation = entity.rotation;
             var mine = ent.GetComponent <Mine>();
             mine.source = source;
             entity.Destroy();
         }
         else
         {
             motor.MoveTo(source.entity.position);
         }
     }
 }
Exemple #3
0
        public override void AttackCommand(Entity target)
        {
            var src = target.GetComponents <ResourceSource>().Where(s => IsResourceCompatible(s.resourceId) && !s.Depleted() && !s.occupied).FirstOrDefault();

            if (src != null)
            {
                motor.Stop();
                source = src;
            }
        }
Exemple #4
0
 public override void OnTick()
 {
     if (collector != null && !collector.entity.isAlive)
     {
         collector = null;
     }
     if (resource != null && !resource.entity.isAlive)
     {
         resource = null;
     }
     if (resource != null && resource.occupied)
     {
         resource = null;
     }
     if (is_idle)
     {
         return;
     }
     if (moving_to_collector)
     {
         if (collector == null)
         {
             // Find the nearest collector.
             var ent = World.current.entities
                       .Where(e => e.team == entity.team && e.GetComponents <ResourceCollectionPoint>().Any(s => s.resourceId == resourceId))
                       .OrderBy(e => World.current.map.Distance(entity.position, e.position))
                       .FirstOrDefault();
             if (ent != null)
             {
                 collector = ent.GetComponents <ResourceCollectionPoint>().Where(s => s.resourceId == resourceId).FirstOrDefault();
             }
         }
         if (collector == null)
         {
             motor.Stop();
             is_idle = true;
             return;
         }
         var dist = World.current.map.Distance(new DVector3(entity.position.x, 0, entity.position.z),
                                               new DVector3(collector.entity.position.x, 0, collector.entity.position.z));
         if (dist < 3)
         {
             motor.Stop();
             // At the dropoff, disgorge the tank contents.
             var transfered = DReal.Min(fill, fillRate * World.deltaTime);
             collector.Receive(transfered);
             fill -= transfered;
         }
         else
         {
             motor.MoveTo(collector.entity.position);
         }
         // If the tank is empty, move to the resource.
         if (fill <= 0)
         {
             moving_to_collector = false;
             motor.Stop();
         }
     }
     else
     {
         if (resource != null && resource.remainingCount <= 0)
         {
             resource = null;
         }
         if (resource == null)
         {
             // Find the nearest resource.
             var ent = World.current.entities
                       .Where(e => e.GetComponents <ResourceSource>().Any(s => s.resourceId == resourceId && s.remainingCount > 0 && !s.occupied))
                       .OrderBy(e => World.current.map.Distance(entity.position, e.position))
                       .FirstOrDefault();
             if (ent != null)
             {
                 resource = ent.GetComponents <ResourceSource>().Where(s => s.resourceId == resourceId && s.remainingCount > 0 && !s.occupied).FirstOrDefault();
             }
         }
         if (resource == null)
         {
             motor.Stop();
             moving_to_collector = true;
             return;
         }
         var dist = World.current.map.Distance(new DVector3(entity.position.x, 0, entity.position.z),
                                               new DVector3(resource.entity.position.x, 0, resource.entity.position.z));
         if (dist < 3)
         {
             motor.Stop();
             // At the pickup, fill the tank.
             var transfered = DReal.Min(capacity - fill, fillRate * World.deltaTime);
             fill += resource.Take(transfered);
         }
         else
         {
             motor.MoveTo(resource.entity.position);
         }
         // If the tank is full, move to the collector.
         if (fill >= capacity)
         {
             moving_to_collector = true;
             motor.Stop();
         }
     }
 }
Exemple #5
0
 public override void MoveCommand(DVector3 position)
 {
     source = null;
     motor.MoveTo(position);
 }
Exemple #6
0
        public Entity Instantiate(string prototypeName, int team, DVector3 position)
        {
            var proto = entityPrototypes[prototypeName];
            var ent   = new Entity(team, position, proto);

            foreach (var cproto in proto.components)
            {
                Component comp = null;
                if (cproto.kind == "Wizard")
                {
                    comp = new Wizard(ent, cproto);
                }
                else if (cproto.kind == "WizardTower")
                {
                    comp = new WizardTower(ent, cproto);
                }
                else if (cproto.kind == "BasicUnit")
                {
                    comp = new BasicUnit(ent, cproto);
                }
                else if (cproto.kind == "GroundMotor")
                {
                    comp = new GroundMotor(ent, cproto);
                }
                else if (cproto.kind == "AirMotor")
                {
                    comp = new AirMotor(ent, cproto);
                }
                else if (cproto.kind == "ResourceCollectionPoint")
                {
                    comp = new ResourceCollectionPoint(ent, cproto);
                }
                else if (cproto.kind == "ResourceHarvester")
                {
                    comp = new ResourceHarvester(ent, cproto);
                }
                else if (cproto.kind == "Truck")
                {
                    comp = new Truck(ent, cproto);
                }
                else if (cproto.kind == "MineTruck")
                {
                    comp = new MineTruck(ent, cproto);
                }
                else if (cproto.kind == "Mine")
                {
                    comp = new Mine(ent, cproto);
                }
                else if (cproto.kind == "Factory")
                {
                    comp = new Factory(ent, cproto);
                }
                else if (cproto.kind == "ResourceSource")
                {
                    comp = new ResourceSource(ent, cproto);
                }
                else if (cproto.kind == "ProjectileWeapon")
                {
                    comp = new ProjectileWeapon(ent, cproto);
                }
                else if (cproto.kind == "Projectile")
                {
                    comp = new Projectile(ent, cproto);
                }
                else if (cproto.kind == "Collider")
                {
                    comp = new Collider(ent, cproto);
                }
                else if (cproto.kind == "HitscanWeapon")
                {
                    comp = new HitscanWeapon(ent, cproto);
                }
                else if (cproto.kind == "Health")
                {
                    comp = new Health(ent, cproto);
                }
                else if (cproto.kind == "BuildRadius")
                {
                    comp = new BuildRadius(ent, cproto);
                }
                else if (cproto.kind == "Team")
                {
                    comp = new Team(ent, cproto);
                }
                else if (cproto.kind == "ResourcePool")
                {
                    comp = new ResourcePool(ent, cproto);
                }
                else
                {
                    Logger.Log("Unknown component type {0}", cproto.kind);
                }
                ent.AddComponent(comp);
            }
            return(ent);
        }