Example #1
0
        bool CanPlaceAt(Entity thing, DVector2 position) {
                var dist = (position - entity.position).sqrMagnitude;
                var prefabSize = (DReal)thing.collisionRadiusNumerator / thing.collisionRadiusDenominator;
                var minDist = (prefabSize + entity.collisionRadius) * (prefabSize + entity.collisionRadius);
                var maxDist = buildRadius * buildRadius;

                return minDist < dist && dist < maxDist &&
                        ComSat.FindEntityWithinRadius(position, prefabSize) == null &&
                        buildMan.CanBuildAt(position, prefabSize);
        }
Example #2
0
    void TickUpdate()
    {
        ComSat.Trace(this, "TickUpdate");

                if(!powerSink.poweredOn) {
                        target = null;
                        audio.Stop();
                        return;
                }

                if(!ComSat.EntityExists(target)) {
                        // Magic. Destroyed GameObjects compare against null.
                        // Explicitly set to null to avoid keeping it around.
                        target = null;
                        audio.Stop();

                        // Search for victims.
                        target = ComSat.FindEntityWithinRadius(entity.position, attackRange, entity.team);
                        if(target != null) {
                                audio.Play();
                        }
                } else {
                        var dp = target.position - entity.position;

                        DReal targetTurretAngle;

                        var projectileProjectile = projectilePrefab.GetComponent<Projectile>();
                        if(projectileProjectile != null && powerSink.Powered()) {
                                var aimSpot = Utility.PredictShot(entity.position, projectileProjectile.initialSpeed,
                                                                  target.position, target.velocity);
                                targetTurretAngle = DReal.Mod(DVector2.ToAngle(aimSpot - entity.position) - entity.rotation, DReal.TwoPI);
                        } else {
                                targetTurretAngle = DReal.Mod(DVector2.ToAngle(dp) - entity.rotation, DReal.TwoPI);
                        }

                        // Turn turret to point at target.
                        TurnTurret(targetTurretAngle);
                        // Fire when pointing the gun at the target.
                        if(targetTurretAngle == turretRotation) {
                                Fire();
                        }

                        // Stop shooting when out of range.
                        if(dp.sqrMagnitude >= attackRange * attackRange) {
                                audio.Stop();
                                target = null;
                        }
                }

                if(fireDelay > 0) {
                        fireDelay -= ComSat.tickRate;
                }
    }