[REQUEST] AI Economy Control

Discussion in 'Mod Discussions' started by SoulSector, March 19, 2014.

  1. SoulSector

    SoulSector New Member

    Messages:
    1
    Likes Received:
    0
    Hello everybody.

    As we all know we used to have a controller to set our own economy rate for AI. This has since been replaced with difficulty levels although a developer has mentioned that it will return (I can't remember the source but I believe it was a Steam Discussion).

    Although after delving into the user options I was able to set my own economy rate for AI based on the values below. I tested with Sandbox to 0.1 and the AI did create a base and try to harass me lightly a little later on, proving to me that this worked.

    I was curious is it possible to create a dialogue box or slider on the New Game screen utilizing this method to bring back the ability of having more control over AI Economy and possibly our own (haven't looked far enough to figure out how to change my own Economy Rate but I believe it is lines 133 - 139)?

    Snippet from new_game.js [Lines 141 - 148]
    Code:
            self.aiLevel = ko.observable(level); /* 0:easy 1:normal 2:hard 3:sandbox */
            self.aiLevel.subscribe(function (value) {
                switch (value) {
                    case '0': self.economyFactor(0); break;
                    case '1': self.economyFactor(0.5); break;
                    case '2': self.economyFactor(1.0); break;
                    case '3': self.economyFactor(1.5); break;             
                };
    Thanks in advance for anybody willing to contribute towards this request.
  2. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Yeah, we would have to create a new lobby input and knockout data-bind it to model.economyFactor.
  3. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    I noticed a few things in the new_game.js tied into the AI economy settings..

    There are 2 main functions in the new_game.js that have the AI difficulty level tied into them.

    In the first function "SlotViewModel" there is this..
    Code:
           self.easyAi = ko.computed(function () { return self.economyFactor() < 1; });
           self.normalAi = ko.computed(function () { return self.economyFactor() === 1; });
           self.hardAi = ko.computed(function () { return self.economyFactor() > 1; });
    and in the second function "ArmyViewModel" there is the code posted in the OP....
    Code:
            self.economyFactor = ko.observable(_.isFinite(options.economy_factor) ? options.economy_factor : 1);
            self.economyFactor.subscribe(function (value) {
                _.invoke(self.slots(), 'economyFactor', value);
    
    and
    Code:
            var level = '2';
            if (self.economyFactor() === 0)
                level = '0';
            else if (self.economyFactor() < 1)
                level = '1';
            else if (self.economyFactor() > 1)
                level = '3';
       
            self.aiLevel = ko.observable(level); /* 0:easy 1:normal 2:hard 3:sandbox */
            self.aiLevel.subscribe(function (value) {
                switch (value) {
                    case '0': self.economyFactor(0); break;
                    case '1': self.economyFactor(0.5); break;
                    case '2': self.economyFactor(1.0); break;
                    case '3': self.economyFactor(1.5); break;          
                };
                model.send_message('modify_army', {
                    army_index: self.index(),
                    options: { economy_factor: self.economyFactor() }
    

    My thoughts and what i was going to do was extend the amount of difficulty levels in the case statement across the 2 functions and add in a "Meduim" and "Very Hard" difficulty to the list.


    Just add in a case '4' and a case '5' with the eco adjusted to match the label.
    And add in the required code in the first function to make the 2 extra buttons in the dropdown list of difficulties.


    Also side note,
    Lower down in the "ArmyVeiwModel" function there is this...
    Code:
            self.metal = ko.observable(1000);
            self.energy = ko.observable(1000);
            self.rate = ko.observable(1.0);
    
    I think that sets the base metal and energy rates of both AI and player or just the player.

Share This Page