Esempio n. 1
0
        /* Apply this effect to a ship */
        public void Apply(Ship ship)
        {
            if (this.advanced)
            {
                switch (this.op)
                {
                // politic
                case "sos()":
                    foreach (Ship other_ship in ship.world.ships)
                    {
                        if (Helpers.DistanceSQ(ref other_ship.location, ref ship.location) < Math.Pow(ship.world.ArenaSize.Width / 3, 2))
                        {
                            if (!ReferenceEquals(other_ship, ship))
                            {
                                if (other_ship.bot_ship && !other_ship.auto)
                                {
                                    if (other_ship.agressivity >= 1.0f && (int)other_ship.agressivity % 5 == 1)
                                    {
                                        if (other_ship.team.IsFriendWith(ship.team))
                                        {
                                            other_ship.ai_target = ship;
                                            other_ship.AISetOrder((int)Ship.AIOrder.Escort, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return;

                case "suicide()": ship.integrity = Int32.MinValue / 2; return;

                case "free()": ship.SetTeam(ship.world.wilderness_team); return;

                case "give()": return;

                case "surrender()": return;

                case "affinity()": ship.team.affinity = (AffinityEnum)Enum.Parse(typeof(AffinityEnum), this.right); return;

                // not politic
                case "effect()":
                    ship.world.effects.Add(new Effect(-1, this.right, ship.location, ship.direction, ship.speed_vec));
                    return;

                case "max_ships()": ship.team.ship_count_limit += Convert.ToInt32(this.right); return;

                case "max_upgrades()": ship.team.upgrade_slots_bonus += Convert.ToInt32(this.right); return;

                case "brightshield()": ship.BrightShield(); return;

                case "ask_surrender()": return;

                case "team_surrender()": return;

                case "warp()":
                    /* // TODO: */
                    PointF destination = ship.location;
                    if (ship.ai_formation_leader != null && (ship.AIHasOrder((int)Ship.AIOrder.Escort) || ship.AIHasOrder((int)Ship.AIOrder.Retreat)))
                    {
                        destination = ship.ai_formation_leader.location;
                    }
                    else if (ship.ai_target != null && ship.AIHasOrder((int)Ship.AIOrder.Attack))
                    {
                        destination = ship.ai_target.location;
                    }
                    else if (ship.AIHasOrder((int)Ship.AIOrder.Goto) || ship.AIHasOrder((int)Ship.AIOrder.Mine))
                    {
                        destination = ship.ai_target_point;
                    }
                    destination.X += ship.world.gameplay_random.Next(-512, 512);
                    destination.Y += ship.world.gameplay_random.Next(-512, 512);
                    ship.location  = destination;
                    return;

                case "abandon()": ship.team = ship.world.wilderness_team; return;

                case "ascend()": ship.team.has_ascended = true; return;

                case "toggle_cheats()": ship.team.cheats_enabled = !ship.team.cheats_enabled; return;

                case "team_set_cheats()": ship.team.cheats_enabled = (Convert.ToInt32(this.right) != 0); return;

                case "set_bot()": ship.bot_ship = (Convert.ToInt32(this.right) != 0); return;

                case "team_set_bot()": ship.bot_ship = (Convert.ToInt32(this.right) != 0); return;

                case "color()":
                    ship.color = Helpers.ToColor(right);
                    ship.UpdateSprite();
                    return;

                case "clear_upgrades()":
                    ship.Upgrading        = null;
                    ship.upgrade_progress = 0;
                    ship.upgrades.Clear();
                    ship.ResetStats();
                    return;

                case "launch()":
                case "summon()":
                    ship.world.ships.Add(new Ship(ship.world, ship.team, right)
                    {
                        location = new Point((int)(ship.location.X + ship.world.gameplay_random.Next(-10, 11)), (int)(ship.location.Y + ship.world.gameplay_random.Next(-10, 11)))
                    });
                    ship.world.ships[ship.world.ships.Count - 1].direction = ship.direction;
                    if (ship.world.ships[ship.world.ships.Count - 1].weapons.Count > 0 && (ship.world.ships[ship.world.ships.Count - 1].weapons[0].stats.special & (int)Weapon.SpecialBits.SelfExplode) != 0)
                    {
                        if (ship.ai_target != null && !ship.team.IsFriendWith(ship.ai_target.team))
                        {
                            ship.world.ships[ship.world.ships.Count - 1].ai_target = ship.ai_target;
                        }
                        else
                        {
                            ship.world.ships[ship.world.ships.Count - 1].ai_target = null;
                        }
                        ship.world.ships[ship.world.ships.Count - 1].ai_order    = (int)Ship.AIOrder.Attack;
                        ship.world.ships[ship.world.ships.Count - 1].agressivity = ship.agressivity * 100.0f;
                        ship.world.ships[ship.world.ships.Count - 1].bot_ship    = true;
                    }
                    else
                    {
                        ship.world.ships[ship.world.ships.Count - 1].ai_order            = (int)Ship.AIOrder.Escort;
                        ship.world.ships[ship.world.ships.Count - 1].ai_formation_leader = ship;
                    }
                    if (this.op == "launch()")
                    {
                        ship.world.ships[ship.world.ships.Count - 1].auto     = true;
                        ship.world.ships[ship.world.ships.Count - 1].lifespan = ship.world.ships[ship.world.ships.Count - 1].stats.complexity * 10;
                    }
                    return;

                default: throw new Exception("invalid op \'" + this.op + "\'");
                }
            }
            else
            {
                switch (this.left)
                {
                case "integrity": SetOp(this.op, ref ship.stats.integrity, this.right); return;

                case "ship.integrity": SetOp(this.op, ref ship.integrity, this.right); return;

                case "repair": SetOp(this.op, ref ship.stats.repair, this.right); return;

                case "shield": SetOp(this.op, ref ship.stats.shield, this.right); return;

                case "ship.shield": SetOp(this.op, ref ship.shield, this.right); return;

                case "shield_opacity":
                    SetOp(this.op, ref ship.stats.shield_opacity, this.right);
                    return;

                case "shield_regeneration":
                    SetOp(this.op, ref ship.stats.shield_regeneration, this.right);
                    return;

                case "deflectors": SetOp(this.op, ref ship.stats.deflectors, this.right); return;

                case "hot_deflectors": SetOp(this.op, ref ship.stats.hot_deflectors, this.right); return;

                case "cold_deflectors": SetOp(this.op, ref ship.stats.cold_deflectors, this.right); return;

                case "ship.deflectors": SetOp(this.op, ref ship.deflectors, this.right); return;

                case "deflectors_cooldown": SetOp(this.op, ref ship.stats.deflectors_cooldown, this.right); return;

                case "speed": SetOp(this.op, ref ship.stats.speed, this.right); return;

                case "ship.speed": SetOp(this.op, ref ship.speed, this.right); return;

                case "turn": SetOp(this.op, ref ship.stats.turn, this.right); return;

                case "weapon_salvo":
                    if (ship.weapons.Count > 0)
                    {
                        SetOp(this.op, ref ship.weapons[0].stats.salvo, this.right);
                    }
                    return;

                case "weapon_celerity":
                    if (ship.weapons.Count > 0)
                    {
                        SetOp(this.op, ref ship.weapons[0].stats.celerity, this.right);
                    }
                    return;

                case "weapon_loadtime":
                    if (ship.weapons.Count > 0)
                    {
                        SetOp(this.op, ref ship.weapons[0].stats.loadtime, this.right);
                    }
                    return;

                case "weapon_power":
                    if (ship.weapons.Count > 0)
                    {
                        SetOp(this.op, ref ship.weapons[0].stats.power, this.right);
                    }
                    return;

                case "weapon_range":
                    if (ship.weapons.Count > 0)
                    {
                        SetOp(this.op, ref ship.weapons[0].stats.range, this.right);
                    }
                    return;

                case "type":
                    SetOp(this.op, ref ship.stats.name, this.right);
                    ship.SetStats(ship.stats.name);
                    return;

                case "width": SetOp(this.op, ref ship.stats.width, this.right); return;

                default: throw new Exception("invalid left operand \'" + this.left + "\'");
                }
            }
        }