Esempio n. 1
0
        IEnumerable <ICommand> ICommandFilter.Preprocess(IActor _actor, ICommand _command)
        {
            var command = Compatibility.Check <TInputCommand>(this, _command);
            var actor   = Compatibility.Check <TActor>(this, _actor);

            return(Preprocess(actor, command).Cast <ICommand>());
        }
Esempio n. 2
0
        public void Initialize(Competitions competitions, GameSettings configuration, ControllerFactory controllerFactory, WorldState worldState)
        {
            Debugger.Log("World initialization");
            Debugger.Log("Starting basic fields");

            Competitions  = competitions;
            Configuration = configuration;
            WorldState    = Compatibility.Check <TWorldState>(this, worldState);

            Clocks      = new WorldClocks();
            IdGenerator = new IdGenerator();
            Scores      = new Scores(this);
            Logger      = new LogWriter(this, Configuration.EnableLog, Configuration.LogFile, Configuration, WorldState);
            Keyboard    = competitions.KeyboardFactory();
            LoggingPositionObjectIds = new List <string>();

            // setting up the parameters

            Clocks.TimeLimit = Configuration.TimeLimit;


            Debugger.Log("About to init engines");
            //Initializing world
            this.Engines = competitions.EnginesFactory(configuration);

            Debugger.Log("Init engines OK");

            Debugger.Log("Complete: basic fields. Starting engine");
            foreach (var engine in Engines)
            {
                engine.LogWriter = Logger;
            }
            Debugger.Log("Complete: engine. Starting controller factory");
            controllerFactory.Initialize(this);
            Debugger.Log("Complete: controller factory. Creating world");
            CreateWorld();
            Debugger.Log("World created");


            //Initializing actors
            actors = new List <IActor>();
            foreach (var id in competitions.Logic.Actors.Keys)
            {
                InitializeActor(
                    competitions,
                    id,
                    competitions.Logic.Actors[id],
                    controllerFactory.Create
                    );
            }

            foreach (var l in competitions.Logic.NPC)
            {
                var f = l.Item3;
                InitializeActor(competitions, l.Item1, l.Item2, (cid, a) => f(a));
            }

            Debugger.Log("Additional world initialization");
            AdditionalInitialization();
        }
Esempio n. 3
0
        void InitializeActor(Competitions competitions, string id, ActorFactory factory, Func <string, IActor, IController> controllerFactory)
        {
            Debugger.Log("Actor " + id + " initialization");
            Debugger.Log("Creating actor");
            //var factory = competitions.Logic.Actors[id];
            var e             = factory.CreateActor();
            var actorObjectId = IdGenerator.CreateNewId(e);

            Debugger.Log("Complete: actor. Creating manager");
            //var manager = competitions.Manager.CreateActorManagerFor(e);
            var rules        = factory.CreateRules();
            var preprocessor = factory.CreateCommandFilterSet();

            e.Initialize(/*manager, */ this, rules, preprocessor, actorObjectId, id);
            Debugger.Log("Comlete: manager creation. Initializing manager");
            Compatibility.Check <IActor>(this, e);
            Debugger.Log("Comlete: manager initialization. Creating actor body");

            Debugger.Log("Complete: body. Starting controller");

            var controller = controllerFactory(e.ControllerId, e);

            controller.Initialize(e);

            var controlTrigger = new ControlTrigger(controller, e, preprocessor);

            e.ControlTrigger = controlTrigger;

            Clocks.AddTrigger(controlTrigger);
            actors.Add(e);
            Debugger.Log("Actor " + id + " is initialized");
        }
Esempio n. 4
0
        public void DefineKeyboardControl(IKeyboardController _pool, string controllerId)
        {
            var pool = Compatibility.Check <KeyboardController <MoveAndGripCommand> >(this, _pool);

            this.AddGripKeys(pool, controllerId);
            this.AddSimpleMovementKeys(pool, controllerId);
            pool.StopCommand = () => new MoveAndGripCommand {
                SimpleMovement = SimpleMovement.Stand(0.1)
            };
        }
Esempio n. 5
0
 public void Initialize(IWorld world, IRules rules, CommandFilterSet filters, string actorObjectId, string controllerId)
 {
     //Manager = Compatibility.Check<TActorManager>(this, manager);
     World        = Compatibility.Check <TWorld>(this, world);
     Rules        = Compatibility.Check <TRules>(this, rules);
     FilterSet    = filters;
     ObjectId     = actorObjectId;
     ControllerId = controllerId;
     AdditionalInitialization();
 }
Esempio n. 6
0
        public UnitResponse ProcessCommand(object _command)
        {
            var command = Compatibility.Check <IDWMCommand>(this, _command);

            if (command.DifWheelMovement == null)
            {
                return(UnitResponse.Denied());
            }
            this.movement = command.DifWheelMovement;
            return(UnitResponse.Accepted(command.DifWheelMovement.Duration));
        }
Esempio n. 7
0
        public UnitResponse ProcessCommand(object _command)
        {
            var command = Compatibility.Check <ISimpleMovementCommand>(this, _command);

            Debugger.Log("Command accepted in SMUnit");
            var c = command.SimpleMovement;

            if (c == null)
            {
                currentMovement = null;
                return(UnitResponse.Denied());
            }
            currentMovement = c;
            ApplyCommand(actor.World.Clocks.CurrentTime);
            return(UnitResponse.Accepted(command.SimpleMovement.Duration));
        }
Esempio n. 8
0
        public override UnitResponse ProcessCommand(object _cmd)
        {
            var cmd = Compatibility.Check <IGripperCommand>(this, _cmd);

            Debugger.Log("Command comes to gripper, " + cmd.GripperCommand.ToString());
            switch (cmd.GripperCommand)
            {
            case GripperAction.No: return(UnitResponse.Denied());

            case GripperAction.Grip:
                Grip();
                return(UnitResponse.Accepted(rules.GrippingTime));

            case GripperAction.Release:
                Release();
                return(UnitResponse.Accepted(rules.ReleasingTime));
            }
            throw new Exception("Cannot reach this part of code");
        }
Esempio n. 9
0
 public DWMUnit(IActor actor)
 {
     this.actor = Compatibility.Check <IDWMRobot>(this, actor);
     actor.World.Clocks.AddTrigger(new TimerTrigger(UpdateSpeed, TriggerFrequency));
     rules = Compatibility.Check <IDWMRules>(this, actor.Rules);
 }
Esempio n. 10
0
 public SimpleMovementUnit(IActor actor)
 {
     this.actor = actor;
     rules      = Compatibility.Check <ISimpleMovementRules>(this, actor.Rules);
     actor.World.Clocks.AddTrigger(new TimerTrigger(ApplyCommand, commandRenewmentRate));
 }
Esempio n. 11
0
 public BaseGripperUnit(IActor actor)
 {
     this.actor = actor;
     rules      = Compatibility.Check <TRules>(this, actor.Rules);
 }
Esempio n. 12
0
 public virtual void Initialize(IActor actor)
 {
     Actor = Compatibility.Check <TActor>(this, actor);
 }