Пример #1
0
        public void LoadAssembly(string name, int squadNumber, int team, byte[][] map)
        {
            assembly         = Assembly.Load(name);
            Name             = AssemblyTitle;
            this.SquadNumber = squadNumber;
            this.Team        = team;

            Type[] types = assembly.GetTypes();

            foreach (Type t in types)
            {
                // This will get the first found MsgExchangeType - therefore no more than one MsgExchangeType should be in the plugin
                if (t.BaseType == typeof(MarvinsArena.Robot.BaseRobot) ||
                    t.BaseType == typeof(MarvinsArena.Robot.EnhancedRobot) ||
                    t.BaseType == typeof(MarvinsArena.Robot.TeamRobot))
                {
                    ConstructorInfo ci = t.GetConstructor(Type.EmptyTypes);
                    object          o  = ci.Invoke(null);

                    if (o == null)
                    {
                        throw new MarvinsArenaException("Error while constructing robot.");
                    }

                    irobot    = ((MarvinsArena.Robot.IRobot)o);
                    robot     = ((MarvinsArena.Robot.BaseRobot)o);
                    robotCore = new MarvinsArena.Robot.Core.RobotCore(Name, squadNumber, team);
                    gameCore  = new MarvinsArena.Robot.Core.GameCore(map);

                    if (t.BaseType == typeof(MarvinsArena.Robot.EnhancedRobot))
                    {
                        MarvinsArena.Robot.EnhancedRobot enhancedRobot = ((MarvinsArena.Robot.EnhancedRobot)o);
                        enhancedRobot.InternalSetCoreRobot(robotCore);
                        enhancedRobot.InternalSetCoreGame(gameCore);
                    }
                    else if (t.BaseType == typeof(MarvinsArena.Robot.TeamRobot))
                    {
                        MarvinsArena.Robot.TeamRobot teamRobot = ((MarvinsArena.Robot.TeamRobot)o);
                        teamRobot.InternalSetCoreRobot(robotCore);
                        teamRobot.InternalSetCoreGame(gameCore);
                    }
                    else
                    {
                        robot.InternalSetCoreRobot(robotCore);
                        robot.InternalSetCoreGame(gameCore);
                    }
                    irobot.Initialize();

                    if (t.BaseType == typeof(MarvinsArena.Robot.BaseRobot))
                    {
                        RobotType = LoadedRobotType.Robot;
                    }
                    if (t.BaseType == typeof(MarvinsArena.Robot.EnhancedRobot))
                    {
                        RobotType = LoadedRobotType.EnhancedRobot;
                    }
                    if (t.BaseType == typeof(MarvinsArena.Robot.TeamRobot))
                    {
                        RobotType = LoadedRobotType.TeamRobot;
                    }

                    return;
                }
            }

            throw new MarvinsArenaException("No MsgExchangeType found!");
        }
Пример #2
0
 /// <summary>
 /// This method is internally called by the engine. You must not call it!
 /// </summary>
 /// <param name="gameBase">Reference to game core</param>
 public new void InternalSetCoreGame(MarvinsArena.Robot.Core.GameCore gameBase)
 {
     this.gameBase = gameBase;
     base.InternalSetCoreGame(gameBase);
 }