Exemple #1
0
 public ResourceGatheringController(PlayerType playerType)
 {
     this.playerType = playerType;
     gatheringModel  = new ResourceGatheringModel(playerType);
     InitialiseResourceManagementViews();
 }
    // Generate Queue of WorkerCommands
    public Queue <AI_GameBehaviourCommand> GetWorkerReassignmentCommands(Dictionary <ResourceType, int> distribution)
    {
        // Queue to output
        Queue <AI_GameBehaviourCommand> commands = new Queue <AI_GameBehaviourCommand>();

        ResourceGatheringModel resourceGatheringModel = GetResourceController().gatheringController.gatheringModel;

        // current values
        int currWoodWorkers       = resourceGatheringModel.GetNumWorkers(ResourceType.WOOD);
        int currMagicStoneWorkers = resourceGatheringModel.GetNumWorkers(ResourceType.MAGIC_STONE);
        int currIdleWorkers       = resourceGatheringModel.GetNumIdleWorkers();


        // target values
        int targetWoodWorkers       = distribution[ResourceType.WOOD];
        int targetMagicStoneWorkers = distribution[ResourceType.MAGIC_STONE];

        // differences
        int numWoodWorkersToAdd       = targetWoodWorkers - currWoodWorkers;
        int numMagicStoneWorkersToAdd = targetMagicStoneWorkers - currMagicStoneWorkers;


        // Remove Wood Workers
        if (numWoodWorkersToAdd < 0)
        {
            for (int i = numWoodWorkersToAdd; i < 0; i++)
            {
                GameBehaviourCommand    command   = WorkerCommandFactory.CreateRemoveWorkerCommand(ResourceType.WOOD, PlayerType.AI);
                AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command);
                commands.Enqueue(aiCommand);
            }
        }

        // Remove Magic Stone Workers
        if (numMagicStoneWorkersToAdd < 0)
        {
            for (int i = numMagicStoneWorkersToAdd; i < 0; i++)
            {
                GameBehaviourCommand    command   = WorkerCommandFactory.CreateRemoveWorkerCommand(ResourceType.MAGIC_STONE, PlayerType.AI);
                AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command);
                commands.Enqueue(aiCommand);
            }
        }

        // Add Wood Workers
        if (numWoodWorkersToAdd > 0)
        {
            for (int i = 0; i < numWoodWorkersToAdd; i++)
            {
                GameBehaviourCommand    command   = WorkerCommandFactory.CreateAddWorkerCommand(ResourceType.WOOD, PlayerType.AI);
                AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command);
                commands.Enqueue(aiCommand);
            }
        }

        // Add Magic Stone Workers
        if (numMagicStoneWorkersToAdd > 0)
        {
            for (int i = 0; i < numMagicStoneWorkersToAdd; i++)
            {
                GameBehaviourCommand    command   = WorkerCommandFactory.CreateAddWorkerCommand(ResourceType.MAGIC_STONE, PlayerType.AI);
                AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command);
                commands.Enqueue(aiCommand);
            }
        }

        return(commands);
    }