Exemplo n.º 1
0
        void TickUpdate() {
                ComSat.Trace(this, "TickUpdate");
                if(sabotageTime > 0) {
                        sabotageTime -= ComSat.tickRate;
                }
                if (buildQueue.Any()) {
                        var buildMe = buildQueue.Peek();
                        var prefab = prefabs[buildMe.what];

                        if(delay > 0) {
                                var advance = ComSat.tickRate;
                                if(sabotageTime > 0) {
                                        advance /= sabotageTimeMultiplier;
                                }
                                if(!powerSink.Powered()) {
                                        advance /= 2;
                                }

                                var completion = advance / prefab.buildTime;
                                var totalRemaining = prefab.buildCost - usedResources;
                                partialMetalUnit += DReal.Min(completion * prefab.buildCost.Metal, totalRemaining.Metal);
                                partialSmokeUnit += DReal.Min(completion * prefab.buildCost.MagicSmoke, totalRemaining.MagicSmoke);
                                var rs = new ResourceSet { Metal = (int)partialMetalUnit, MagicSmoke = (int)partialSmokeUnit };
                                if (resourceMan.TakeResources(entity.team, rs)) {
                                        usedResources += rs;
                                        partialMetalUnit %= 1;
                                        partialSmokeUnit %= 1;
                                        delay -= advance;
                                } else {
                                        partialMetalUnit -= completion * prefab.buildCost.Metal;
                                        partialSmokeUnit -= completion * prefab.buildCost.MagicSmoke;
                                }
                        }
                        if(delay <= 0) {
                                if (!resourceMan.TakeResources(entity.team, prefab.buildCost - usedResources)) return;

                                // Timer expired and we're building something.
                                print("Build new " + prefab);
                                var prefabSize = (DReal)prefab.collisionRadiusNumerator / prefab.collisionRadiusDenominator;
                                var wiggle = ((ComSat.RandomValue() % 5) / 5) * ((ComSat.RandomValue() % 2 == 0) ? 1 : -1);
                                var position = prefab.buildAtPoint
                                        ? buildMe.position
                                        : (entity.position + DVector2.FromAngle(entity.rotation + wiggle) * (entity.collisionRadius + prefabSize + 2 + wiggle));
                                ComSat.SpawnEntity(entity, prefab.gameObject, position, 0);
                                if(buildMe.buildCollider != null) {
                                        buildMan.RemovePendingBuild(buildMe.buildCollider);
                                }
                                if (!buildMe.repeat) buildQueue.Dequeue();
                                ResetBuildTime();
                        }
                }
        }
Exemplo n.º 2
0
 void TickUpdate()
 {
     ComSat.Trace(this, "TickUpdate");
     if (ComSat.EntityExists(target))
     {
         moving      = true;
         destination = target.position;
         if ((destination - entity.position).sqrMagnitude < detonateRange * detonateRange)
         {
             Detonate();
             return;
         }
     }
     else if (targets != null && targets.Any())
     {
         PickNewTarget();
     }
     if (moving)
     {
         if ((ComSat.RandomValue() % 500) == 0)
         {
             Detonate();
             return;
         }
         if ((destination - entity.position).sqrMagnitude < sqrPositioningAccuracy)
         {
             // Close enough.
             moving = false;
             motor.Stop();
         }
         else
         {
             motor.MoveTowards(destination);
         }
     }
 }