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
|
217 | 217 | hotkey.click.left = "Z" |
218 | 218 | hotkey.click.right = "C" |
219 | 219 | |
| 220 | hotkey.selection.group.left = "Ctrl+LeftArrow" |
| 221 | hotkey.selection.group.right = "Ctrl+RightArrow" |
| 222 | hotkey.selection.group.up = "Ctrl+UpArrow" |
| 223 | hotkey.selection.group.down = "Ctrl+DownArrow" |
220 | 224 | ; > SESSION CONTROLS |
221 | 225 | hotkey.session.kill = Delete ; Destroy selected units |
222 | 226 | hotkey.session.garrison = Ctrl ; Modifier to garrison when clicking on building |
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)
|
1591 | 1591 | } |
1592 | 1592 | } |
1593 | 1593 | |
| 1594 | function 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 | |
1594 | 1606 | function handleHotkey(ev) |
1595 | 1607 | { |
1596 | 1608 | if (ev.hotkey && ev.hotkey.indexOf("selection.group.") == 0) |
… |
… |
function performGroup(action, x)
|
1663 | 1675 | preSelectedAction = ACTION_FORMATION; |
1664 | 1676 | inputState = INPUT_ACTION_STATE; |
1665 | 1677 | 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; |
1666 | 1698 | } |
1667 | 1699 | if (inputState == INPUT_ACTION_STATE) |
1668 | 1700 | inputState = INPUT_NORMAL; |
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 = {
|
204 | 204 | this.SetNextState("INDIVIDUAL.WALKING"); |
205 | 205 | }, |
206 | 206 | |
207 | | "Order.WalkToTarget": function(msg) { |
| 207 | "Order.WalkTo": function(msg) { |
208 | 208 | // Let players move captured domestic animals around |
209 | 209 | if (this.IsAnimal() && !this.IsDomestic()) |
210 | 210 | { |
211 | 211 | this.FinishOrder(); |
212 | 212 | return; |
213 | 213 | } |
| 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); |
214 | 219 | |
215 | | var ok = this.MoveToTarget(this.order.data.target); |
216 | 220 | if (ok) |
217 | 221 | { |
218 | 222 | // We've started walking to the given point |
… |
… |
var UnitFsmSpec = {
|
1656 | 1660 | // Ignore all orders that animals might otherwise respond to |
1657 | 1661 | "Order.FormationWalk": function() { }, |
1658 | 1662 | "Order.Walk": function() { }, |
1659 | | "Order.WalkToTarget": function() { }, |
| 1663 | "Order.WalkTo": function() { }, |
1660 | 1664 | "Order.Attack": function() { }, |
1661 | 1665 | |
1662 | 1666 | "Attacked": function(msg) { |
… |
… |
UnitAI.prototype.MoveToTargetRangeExplicit = function(target, min, max)
|
2410 | 2414 | return cmpUnitMotion.MoveToTargetRange(target, min, max); |
2411 | 2415 | }; |
2412 | 2416 | |
| 2417 | UnitAI.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 | |
2413 | 2437 | UnitAI.prototype.CheckTargetRange = function(target, iid, type) |
2414 | 2438 | { |
2415 | 2439 | var cmpRanged = Engine.QueryInterface(this.entity, iid); |
… |
… |
UnitAI.prototype.ComputeWalkingDistance = function()
|
2722 | 2746 | |
2723 | 2747 | break; // and continue the loop |
2724 | 2748 | |
2725 | | case "WalkToTarget": |
| 2749 | case "WalkTo": |
2726 | 2750 | case "WalkToTargetRange": // This doesn't move to the target (just into range), but a later order will. |
2727 | 2751 | case "Flee": |
2728 | 2752 | case "LeaveFoundation": |
… |
… |
UnitAI.prototype.Walk = function(x, z, queued)
|
2779 | 2803 | */ |
2780 | 2804 | UnitAI.prototype.WalkToTarget = function(target, queued) |
2781 | 2805 | { |
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 | */ |
| 2812 | UnitAI.prototype.WalkDirection = function(direction) |
| 2813 | { |
| 2814 | this.AddOrder("WalkTo", { "direction": direction, "force": false }); |
2783 | 2815 | }; |
2784 | 2816 | |
2785 | 2817 | /** |
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)
|
60 | 60 | cmpUnitAI.Walk(cmd.x, cmd.z, cmd.queued); |
61 | 61 | }); |
62 | 62 | 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; |
63 | 69 | |
64 | 70 | case "attack": |
65 | 71 | if (g_DebugCommands && !IsOwnedByEnemyOfPlayer(player, cmd.target)) |
diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp
index 0712f3b..7728f28 100644
a
|
b
|
float CGameView::GetCullFOV() const
|
1049 | 1049 | return m->ViewFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum; |
1050 | 1050 | } |
1051 | 1051 | |
| 1052 | float CGameView::getOrientation() const |
| 1053 | { |
| 1054 | CVector3D cameraIn = m->ViewCamera.m_Orientation.GetIn(); |
| 1055 | return atan2(cameraIn.X, cameraIn.Z); |
| 1056 | } |
| 1057 | |
| 1058 | |
1052 | 1059 | void CGameView::SetCameraProjection() |
1053 | 1060 | { |
1054 | 1061 | m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV); |
diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h
index 9f214ab..ea8d389 100644
a
|
b
|
public:
|
94 | 94 | float GetFar() const; |
95 | 95 | float GetFOV() const; |
96 | 96 | float GetCullFOV() const; |
| 97 | float getOrientation() const; |
97 | 98 | |
98 | 99 | // Set projection of current camera using near, far, and FOV values |
99 | 100 | void SetCameraProjection(); |
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))
|
445 | 445 | return INVALID_ENTITY; |
446 | 446 | } |
447 | 447 | |
| 448 | float GetCameraOrientation(void* UNUSED(cbdata)) |
| 449 | { |
| 450 | return g_Game->GetView()->getOrientation(); |
| 451 | } |
| 452 | |
448 | 453 | bool HotkeyIsPressed_(void* UNUSED(cbdata), std::string hotkeyName) |
449 | 454 | { |
450 | 455 | return HotkeyIsPressed(hotkeyName); |
… |
… |
void GuiScriptingInit(ScriptInterface& scriptInterface)
|
631 | 636 | scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollowFPS>("CameraFollowFPS"); |
632 | 637 | scriptInterface.RegisterFunction<void, entity_pos_t, entity_pos_t, &CameraMoveTo>("CameraMoveTo"); |
633 | 638 | scriptInterface.RegisterFunction<entity_id_t, &GetFollowedEntity>("GetFollowedEntity"); |
| 639 | scriptInterface.RegisterFunction<float, &GetCameraOrientation>("GetCameraOrientation"); |
634 | 640 | scriptInterface.RegisterFunction<bool, std::string, &HotkeyIsPressed_>("HotkeyIsPressed"); |
635 | 641 | scriptInterface.RegisterFunction<void, std::wstring, &DisplayErrorDialog>("DisplayErrorDialog"); |
636 | 642 | scriptInterface.RegisterFunction<CScriptVal, &GetProfilerState>("GetProfilerState"); |