Ticket #1515: directed_unit_movement.patch

File directed_unit_movement.patch, 8.2 KB (added by picobyte, 12 years ago)

units move relative to the camera now. we still need to compute how far we can go

  • binaries/data/config/default.cfg

    commit 06252c6065f7d691e954e0b4832eadad7e842e14
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Mon Jun 25 22:51:31 2012 +0200
    
        units move, relative to the camera. we still need to compute how far
        we can go
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg
    index 55c4941..33676a9 100644
    a b hotkey.selection.group.ungarrison.0 = M  
    217217hotkey.click.left = "Z"
    218218hotkey.click.right = "C"
    219219
     220hotkey.selection.group.left = "Ctrl+LeftArrow"
     221hotkey.selection.group.right = "Ctrl+RightArrow"
     222hotkey.selection.group.up = "Ctrl+UpArrow"
     223hotkey.selection.group.down = "Ctrl+DownArrow"
    220224; > SESSION CONTROLS
    221225hotkey.session.kill = Delete                ; Destroy selected units
    222226hotkey.session.garrison = Ctrl              ; Modifier to garrison when clicking on building
  • binaries/data/mods/public/gui/session/input.js

    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index f4cc878..66d3ed6 100644
    a b function performFormation(entity, formationName)  
    15911591    }
    15921592}
    15931593
     1594function walkDirection(direction)
     1595{
     1596    var selection = g_Selection.toList();
     1597    if (selection.length) {
     1598        Engine.PostNetworkCommand({
     1599            "type": "walk-direction",
     1600            "entities": selection,
     1601            "direction": direction
     1602        });
     1603    }
     1604}
     1605
    15941606function handleHotkey(ev)
    15951607{
    15961608    if (ev.hotkey && ev.hotkey.indexOf("selection.group.") == 0)
    function performGroup(action, x)  
    16631675        preSelectedAction = ACTION_FORMATION;
    16641676        inputState = INPUT_ACTION_STATE;
    16651677        return;
     1678    case "up":
     1679        walkDirection(2 * Math.PI + Engine.GetCameraOrientation());
     1680        inputState = INPUT_NORMAL;
     1681        preSelectedAction = ACTION_NONE;
     1682        return;
     1683    case "right":
     1684        walkDirection(0.5 * Math.PI + Engine.GetCameraOrientation());
     1685        inputState = INPUT_NORMAL;
     1686        preSelectedAction = ACTION_NONE;
     1687        return;
     1688    case "down":
     1689        walkDirection(Math.PI + Engine.GetCameraOrientation());
     1690        inputState = INPUT_NORMAL;
     1691        preSelectedAction = ACTION_NONE;
     1692        return;
     1693    case "left":
     1694        walkDirection(1.5 * Math.PI + Engine.GetCameraOrientation());
     1695        inputState = INPUT_NORMAL;
     1696        preSelectedAction = ACTION_NONE;
     1697        return;
    16661698    }
    16671699    if (inputState == INPUT_ACTION_STATE)
    16681700        inputState = INPUT_NORMAL;
  • binaries/data/mods/public/simulation/components/UnitAI.js

    diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js
    index 5448635..26b652b 100644
    a b var UnitFsmSpec = {  
    204204            this.SetNextState("INDIVIDUAL.WALKING");
    205205    },
    206206
    207     "Order.WalkToTarget": function(msg) {
     207    "Order.WalkTo": function(msg) {
    208208        // Let players move captured domestic animals around
    209209        if (this.IsAnimal() && !this.IsDomestic())
    210210        {
    211211            this.FinishOrder();
    212212            return;
    213213        }
     214        var ok;
     215        if (this.order.data.target)
     216            ok = this.MoveToTarget(this.order.data.target);
     217        else if (this.order.data.direction)
     218            ok = this.MoveDirection(this.order.data.direction);
    214219
    215         var ok = this.MoveToTarget(this.order.data.target);
    216220        if (ok)
    217221        {
    218222            // We've started walking to the given point
    var UnitFsmSpec = {  
    16561660            // Ignore all orders that animals might otherwise respond to
    16571661            "Order.FormationWalk": function() { },
    16581662            "Order.Walk": function() { },
    1659             "Order.WalkToTarget": function() { },
     1663            "Order.WalkTo": function() { },
    16601664            "Order.Attack": function() { },
    16611665
    16621666            "Attacked": function(msg) {
    UnitAI.prototype.MoveToTargetRangeExplicit = function(target, min, max)  
    24102414    return cmpUnitMotion.MoveToTargetRange(target, min, max);
    24112415};
    24122416
     2417UnitAI.prototype.MoveDirection = function(angle)
     2418{
     2419    // where are we?
     2420    var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     2421    if (!cmpPosition || !cmpPosition.IsInWorld())
     2422        return false;
     2423
     2424    var targetPos = cmpPosition.GetPosition();
     2425    var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
     2426
     2427    // TODO: How far can we go until we meet an obstacle?
     2428    var distance = 50.0;
     2429
     2430    targetPos.x += Math.sin(angle) * distance;
     2431    targetPos.z += Math.cos(angle) * distance;
     2432
     2433    this.MoveToPoint(targetPos.x, targetPos.z)
     2434    return true;
     2435};
     2436
    24132437UnitAI.prototype.CheckTargetRange = function(target, iid, type)
    24142438{
    24152439    var cmpRanged = Engine.QueryInterface(this.entity, iid);
    UnitAI.prototype.ComputeWalkingDistance = function()  
    27222746
    27232747            break; // and continue the loop
    27242748
    2725         case "WalkToTarget":
     2749        case "WalkTo":
    27262750        case "WalkToTargetRange": // This doesn't move to the target (just into range), but a later order will.
    27272751        case "Flee":
    27282752        case "LeaveFoundation":
    UnitAI.prototype.Walk = function(x, z, queued)  
    27792803 */
    27802804UnitAI.prototype.WalkToTarget = function(target, queued)
    27812805{
    2782     this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued);
     2806    this.AddOrder("WalkTo", { "target": target, "force": true }, queued);
     2807};
     2808
     2809/**
     2810 * Adds walk-direction order to queue, but respond to events e.g. attack response
     2811 */
     2812UnitAI.prototype.WalkDirection = function(direction)
     2813{
     2814    this.AddOrder("WalkTo", { "direction": direction, "force": false });
    27832815};
    27842816
    27852817/**
  • binaries/data/mods/public/simulation/helpers/Commands.js

    diff --git a/binaries/data/mods/public/simulation/helpers/Commands.js b/binaries/data/mods/public/simulation/helpers/Commands.js
    index 0f481ec..0dc45cb 100644
    a b function ProcessCommand(player, cmd)  
    6060            cmpUnitAI.Walk(cmd.x, cmd.z, cmd.queued);
    6161        });
    6262        break;
     63    case "walk-direction":
     64        var entities = FilterEntityList(cmd.entities, player, controlAllUnits);
     65        GetFormationUnitAIs(entities, player).forEach(function(cmpUnitAI) {
     66            cmpUnitAI.WalkDirection(cmd.direction);
     67        });
     68        break;
    6369
    6470    case "attack":
    6571        if (g_DebugCommands && !IsOwnedByEnemyOfPlayer(player, cmd.target))
  • source/graphics/GameView.cpp

    diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp
    index 0712f3b..7728f28 100644
    a b float CGameView::GetCullFOV() const  
    10491049    return m->ViewFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum;
    10501050}
    10511051
     1052float CGameView::getOrientation() const
     1053{
     1054    CVector3D cameraIn = m->ViewCamera.m_Orientation.GetIn();
     1055    return atan2(cameraIn.X, cameraIn.Z);
     1056}
     1057
     1058
    10521059void CGameView::SetCameraProjection()
    10531060{
    10541061    m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
  • source/graphics/GameView.h

    diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h
    index 9f214ab..ea8d389 100644
    a b public:  
    9494    float GetFar() const;
    9595    float GetFOV() const;
    9696    float GetCullFOV() const;
     97    float getOrientation() const;
    9798
    9899    // Set projection of current camera using near, far, and FOV values
    99100    void SetCameraProjection();
  • source/gui/scripting/ScriptFunctions.cpp

    diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp
    index adadec1..727b43b 100644
    a b entity_id_t GetFollowedEntity(void* UNUSED(cbdata))  
    445445    return INVALID_ENTITY;
    446446}
    447447
     448float GetCameraOrientation(void* UNUSED(cbdata))
     449{
     450    return g_Game->GetView()->getOrientation();
     451}
     452
    448453bool HotkeyIsPressed_(void* UNUSED(cbdata), std::string hotkeyName)
    449454{
    450455    return HotkeyIsPressed(hotkeyName);
    void GuiScriptingInit(ScriptInterface& scriptInterface)  
    631636    scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollowFPS>("CameraFollowFPS");
    632637    scriptInterface.RegisterFunction<void, entity_pos_t, entity_pos_t, &CameraMoveTo>("CameraMoveTo");
    633638    scriptInterface.RegisterFunction<entity_id_t, &GetFollowedEntity>("GetFollowedEntity");
     639    scriptInterface.RegisterFunction<float, &GetCameraOrientation>("GetCameraOrientation");
    634640    scriptInterface.RegisterFunction<bool, std::string, &HotkeyIsPressed_>("HotkeyIsPressed");
    635641    scriptInterface.RegisterFunction<void, std::wstring, &DisplayErrorDialog>("DisplayErrorDialog");
    636642    scriptInterface.RegisterFunction<CScriptVal, &GetProfilerState>("GetProfilerState");