Ticket #1871: numworker.diff

File numworker.diff, 10.3 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/gui/session/session.xml

     
    866866                <object size="90 -2 126 34" name="attackAndArmorStats" type="image" sprite="stretched:session/icons/stances/defensive.png" tooltip="Attack and Armor" tooltip_style="sessionToolTip"/>
    867867
    868868                <!-- Resource carrying icon/counter -->
     869                <!-- Used also for number of gatherers/builders -->
    869870                <object size="100%-78 -2 100%-28 34" type="text" name="resourceCarryingText" style="CarryingTextRight"/>
    870                 <object size="100%-36 -2 100% 34" type="image" name="resourceCarryingIcon"/>
     871                <object size="100%-36 -2 100% 34" type="image" name="resourceCarryingIcon" tooltip_style="sessionToolTip"/>
    871872            </object>
    872873           
    873874            <!-- Big unit icon -->
  • binaries/data/mods/public/gui/session/selection_details.js

     
    131131        getGUIObjectByName("resourceCarryingText").hidden = false;
    132132        getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/resources/"+carried.type+".png";
    133133        getGUIObjectByName("resourceCarryingText").caption = carried.amount + " / " + carried.max;
     134        getGUIObjectByName("resourceCarryingIcon").tooltip = "";
    134135    }
    135136    // Use the same indicators for traders
    136137    else if (entState.trader && entState.trader.goods.amount > 0)
     
    139140        getGUIObjectByName("resourceCarryingText").hidden = false;
    140141        getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/resources/"+entState.trader.goods.type+".png";
    141142        getGUIObjectByName("resourceCarryingText").caption = entState.trader.goods.amount;
     143        getGUIObjectByName("resourceCarryingIcon").tooltip = "";
    142144    }
     145    // And for number of workers
     146    else if (entState.foundation)
     147    {
     148        getGUIObjectByName("resourceCarryingIcon").hidden = false;
     149        getGUIObjectByName("resourceCarryingText").hidden = false;
     150        getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png";
     151        getGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders + "    ";
     152        getGUIObjectByName("resourceCarryingIcon").tooltip = "number of builders";
     153    }
     154    else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints))
     155    {
     156        getGUIObjectByName("resourceCarryingIcon").hidden = false;
     157        getGUIObjectByName("resourceCarryingText").hidden = false;
     158        getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png";
     159        getGUIObjectByName("resourceCarryingText").caption = entState.resourceSupply.gatherers.length + " / " + entState.resourceSupply.maxGatherers + "    ";
     160        getGUIObjectByName("resourceCarryingIcon").tooltip = "number/max of gatherers";
     161    }
    143162    else
    144163    {
    145164        getGUIObjectByName("resourceCarryingIcon").hidden = true;
     
    148167
    149168    // Set Player details
    150169    getGUIObjectByName("specific").caption = specificName;
    151         getGUIObjectByName("player").caption = playerName;
     170    getGUIObjectByName("player").caption = playerName;
    152171    getGUIObjectByName("playerColorBackground").sprite = "colour: " + playerColor;
    153172   
    154173    if (genericName)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    235235    if (cmpFoundation)
    236236    {
    237237        ret.foundation = {
    238             "progress": cmpFoundation.GetBuildPercentage()
     238            "progress": cmpFoundation.GetBuildPercentage(),
     239            "numBuilders": cmpFoundation.GetNumBuilders(),
    239240        };
    240241    }
    241242
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    1212    // its obstruction once there's nothing in the way.
    1313    this.committed = false;
    1414
    15     // Set up a timer so we can count the number of builders in a 1-second period.
    16     // (We assume each builder only builds once per second, which is what UnitAI
    17     // implements.)
    18     var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    19     this.timer = cmpTimer.SetInterval(this.entity, IID_Foundation, "UpdateTimeout", 1000, 1000, {});
    20     this.recentBuilders = []; // builder entities since the last timeout
    21     this.numRecentBuilders = 0; // number of builder entities as of the last timeout
     15    this.builders = []; // builder entities
    2216    this.buildMultiplier = 1; // Multiplier for the amount of work builders do.
    2317   
    2418    this.previewEntity = INVALID_ENTITY;
    2519};
    2620
    27 Foundation.prototype.UpdateTimeout = function()
    28 {
    29     this.numRecentBuilders = this.recentBuilders.length;
    30     this.recentBuilders = [];
    31     this.SetBuildMultiplier();
    32 
    33     Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.numRecentBuilders);
    34 };
    35 
    3621Foundation.prototype.InitialiseConstruction = function(owner, template)
    3722{
    3823    this.finalTemplateName = template;
     
    8065    return Math.floor(this.GetBuildProgress() * 100);
    8166};
    8267
     68Foundation.prototype.GetNumBuilders = function()
     69{
     70    return this.builders.length;
     71};
     72
    8373Foundation.prototype.IsFinished = function()
    8474{
    8575    return (this.GetBuildProgress() == 1.0);
     
    115105                cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled);
    116106        }
    117107    }
    118 
    119     // Reset the timer
    120     var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    121     cmpTimer.CancelTimer(this.timer);
    122108};
    123109
    124110/**
    125  * Adds a builder to the counter. Used indirectly by UnitAI to signal that
    126  * a unit has started the construction timer and will actually build soon.
     111 * Adds or removes a builder to the counter.
    127112 */
    128113Foundation.prototype.AddBuilder = function(builderEnt)
    129114{
    130     if (this.recentBuilders.indexOf(builderEnt) != -1)
    131         return;
     115    if (this.builders.indexOf(builderEnt) === -1)
     116    {
     117        this.builders.push(builderEnt);
     118        Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.builders.length);
     119        this.SetBuildMultiplier();
     120    }
     121};
    132122
    133     this.recentBuilders.push(builderEnt);
    134     if (this.recentBuilders.length > this.numRecentBuilders)
     123Foundation.prototype.RemoveBuilder = function(builderEnt)
     124{
     125    if (this.builders.indexOf(builderEnt) !== -1)
    135126    {
    136         this.numRecentBuilders = this.recentBuilders.length;
     127        this.builders.splice(this.builders.indexOf(builderEnt),1);
     128        Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.builders.length);
    137129        this.SetBuildMultiplier();
    138130    }
    139131};
    140132
    141133/**
    142134 * Sets the build rate multiplier, which is applied to all builders.
     135 * Yields a total rate of construction equal to numBuilders^0.7
    143136 */
     137
    144138Foundation.prototype.SetBuildMultiplier = function()
    145139{
    146     // Yields a total rate of construction equal to numRecentBuilders^0.7
    147     this.buildMultiplier = Math.pow(this.numRecentBuilders, 0.7) / this.numRecentBuilders;
     140    var numBuilders = this.builders.length;
     141    if (numBuilders == 0)
     142        this.buildMultiplier = 1;
     143    else
     144        this.buildMultiplier = Math.pow(numBuilders, 0.7) / numBuilders;
    148145};
    149146
    150147/**
     
    241238    var cmpCost = Engine.QueryInterface(this.entity, IID_Cost);
    242239    var amount = work / cmpCost.GetBuildTime();
    243240
    244     // Record this builder so we can count the total number
    245     this.AddBuilder(builderEnt);
    246 
    247241    // Add an appropriate proportion of hitpoints
    248242    var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    249243    var maxHealth = cmpHealth.GetMaxHitpoints();
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    21032103
    21042104                    this.order.data.force = false;
    21052105
    2106                     var target = this.order.data.target;
     2106                    this.repairTarget = this.order.data.target; // temporary, deleted in "leave".
    21072107                    // Check we can still reach and repair the target
    2108                     if (!this.CheckTargetRange(target, IID_Builder) || !this.CanRepair(target))
     2108                    if (!this.CheckTargetRange(this.repairTarget, IID_Builder) || !this.CanRepair(this.repairTarget))
    21092109                    {
    21102110                        // Can't reach it, no longer owned by ally, or it doesn't exist any more
    21112111                        this.FinishOrder();
     
    21132113                    }
    21142114                    else
    21152115                    {
    2116                         var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);
     2116                        var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation);
    21172117                        if (cmpFoundation)
    21182118                            cmpFoundation.AddBuilder(this.entity);
    21192119                    }
     
    21242124                },
    21252125
    21262126                "leave": function() {
     2127                    var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation);
     2128                    if (cmpFoundation)
     2129                        cmpFoundation.RemoveBuilder(this.entity);
     2130                    delete this.repairTarget;
    21272131                    this.StopTimer();
    21282132                },
    21292133
    21302134                "Timer": function(msg) {
    2131                     var target = this.order.data.target;
    21322135                    // Check we can still reach and repair the target
    2133                     if (!this.CheckTargetRange(target, IID_Builder) || !this.CanRepair(target))
     2136                    if (!this.CheckTargetRange(this.repairTarget, IID_Builder) || !this.CanRepair(this.repairTarget))
    21342137                    {
    21352138                        // Can't reach it, no longer owned by ally, or it doesn't exist any more
    21362139                        this.FinishOrder();
     
    21382141                    }
    21392142                   
    21402143                    var cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder);
    2141                     cmpBuilder.PerformBuilding(target);
     2144                    cmpBuilder.PerformBuilding(this.repairTarget);
    21422145                },
    21432146            },
    21442147
     
    25922595            cmpSupply.RemoveGatherer(this.entity);
    25932596        delete this.gatheringTarget;
    25942597    }
    2595    
     2598    // And the Foundation builder count
     2599    if (this.repairTarget)
     2600    {
     2601        var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation);
     2602        if (cmpFoundation)
     2603            cmpFoundation.RemoveBuilder(this.entity);
     2604        delete this.repairTarget;
     2605    }
     2606
    25962607    // Clean up range queries
    25972608    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    25982609    if (this.losRangeQuery)