Ticket #744: free_worker-27-02-2011.diff

File free_worker-27-02-2011.diff, 6.0 KB (added by veprbl, 13 years ago)
  • binaries/data/mods/public/gui/session/session.xml

     
    1515    <script file="gui/session/unit_commands.js"/>
    1616    <script file="gui/session/messages.js"/>
    1717    <script file="gui/session/utility_functions.js"/>
     18    <script file="gui/session/freeworker.js"/>
    1819
    1920    <object name="sn" hotkey="session.gui.toggle">
    2021        <action on="Tick">
     
    387388    </object> <!-- END OF TOP PANEL -->
    388389
    389390    <!-- ================================  ================================ -->
     391    <!-- Free Worker Button -->
     392    <!-- ================================  ================================ -->
     393    <object name="freeWorkerPanel"
     394        size="50%-544 100%-32 50%-512 100%"
     395        type="image"
     396        sprite="mapPanel"
     397        hidden="false"
     398        ghost="false"
     399    >
     400        <object type="button"
     401            name="freeWorkerButton"
     402            size="0 0 100% 100%"
     403            tooltip_style="sessionToolTip"
     404        >
     405            <object size="0 0 100% 100%" type="image" sprite="freeWorker" name="freeWorkerButtonImage" ghost="true" />
     406            <action on="Press">findFreeWorker();</action>
     407        </object>
     408    </object>
     409
     410    <!-- ================================  ================================ -->
    390411    <!-- START of BOTTOM PANEL -->
    391412    <!-- ================================  ================================ -->
    392413    <object size="50%-512 100%-180 50%+512 100%">
  • binaries/data/mods/public/gui/session/freeworker.js

     
     1function findFreeWorker()
     2{
     3    var ent, pos;
     4
     5    [ent, pos] = Engine.GuiInterfaceCall("FindFreeWorker");
     6
     7    if (ent)
     8    {
     9        g_Selection.reset()
     10        g_Selection.addList([ent]);
     11        Engine.SetCameraTarget(pos.x, pos.y, pos.z);
     12    }
     13}
     14 No newline at end of file
  • binaries/data/mods/public/gui/session/sprites.xml

     
    99        />
    1010    </sprite>
    1111
     12    <sprite name="freeWorker">
     13        <image
     14            texture="session/icons/single/repair.png"
     15            cell_size="32 32"
     16            size="0 0 100% 100%"
     17        />
     18    </sprite>
     19
    1220    <!-- ================================  ================================ -->
    1321    <!-- Unit Command Icons -->
    1422    <!-- ================================  ================================ -->
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    473473    cmpRangeManager.SetDebugOverlay(enabled);
    474474};
    475475
     476var _prevWorker = undefined
     477
     478GuiInterface.prototype.FindFreeWorker = function(player)
     479{
     480    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     481    var nearby = rangeMan.GetEntitiesByPlayer(player); //   var nearby = rangeMan.ExecuteQuery(this.entity, 0, -1, [player], IID_UnitAI);
     482
     483    var worker = null;
     484
     485    for each (var ent in nearby)
     486    {
     487        var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     488        var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
     489
     490        if (cmpIdentity && cmpUnitAI && cmpUnitAI.IsIdle())
     491        {
     492            var classes = cmpIdentity.GetClassesList();
     493
     494            if (classes.indexOf("Worker") != -1)
     495            {
     496                if (worker == null)
     497                {
     498                    worker = ent;
     499                }
     500
     501                if (ent > _prevWorker)
     502                {
     503                    worker = ent;
     504                    break;
     505                }
     506            }
     507        }
     508    }
     509
     510    if (worker == null)
     511    {
     512        return [null, null]
     513    }
     514
     515    var cmpPosition = Engine.QueryInterface(worker, IID_Position);
     516
     517    if (cmpPosition)
     518    {
     519        _prevWorker = worker;
     520        return [worker, cmpPosition.GetPosition()];
     521    }
     522    else
     523    {
     524        return [null, null];
     525    }
     526};
     527
    476528// List the GuiInterface functions that can be safely called by GUI scripts.
    477529// (GUI scripts are non-deterministic and untrusted, so these functions must be
    478530// appropriately careful. They are called with a first argument "player", which is
     
    495547    "SetPathfinderDebugOverlay": 1,
    496548    "SetObstructionDebugOverlay": 1,
    497549    "SetMotionDebugOverlay": 1,
    498     "SetRangeDebugOverlay": 1
     550    "SetRangeDebugOverlay": 1,
     551
     552    "FindFreeWorker": 1
    499553};
    500554
    501555GuiInterface.prototype.ScriptCall = function(player, name, args)
  • binaries/data/mods/public/simulation/components/Identity.js

     
    7777                        "<value>Animal</value>" +
    7878                        "<value>Organic</value>" +
    7979                        "<value>Structure</value>" +
     80                        "<value>Worker</value>" +
    8081                        "<value>Civic</value>" +
    8182                        "<value>CivCentre</value>" +
    8283                        "<value>Economic</value>" +
  • binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml

     
    44    <GenericName>Female Citizen</GenericName>
    55    <History>Women in the ancient world took on a variety of roles - from leadership (Celts) to servant (Greeks). Women are hard workers, the economic backbone of any civilisation. In history, it was typical when all the males (capable of fighting) were killed for the females, children, and elderly to be sold as slaves.</History>
    66    <Tooltip>Gather resources, build civic structures, and inspire nearby males to work faster.</Tooltip>
     7    <Classes>Worker</Classes>
    78  </Identity>
    89  <Cost>
    910    <Resources>