Ticket #1260: show-carry-anim.patch
File show-carry-anim.patch, 12.2 KB (added by , 12 years ago) |
---|
-
source/simulation2/components/ICmpVisual.cpp
24 24 BEGIN_INTERFACE_WRAPPER(Visual) 25 25 DEFINE_INTERFACE_METHOD_4("SelectAnimation", void, ICmpVisual, SelectAnimation, std::string, bool, fixed, std::wstring) 26 26 DEFINE_INTERFACE_METHOD_1("SelectMovementAnimation", void, ICmpVisual, SelectMovementAnimation, fixed) 27 DEFINE_INTERFACE_METHOD_1("ResetMoveAnimation", void, ICmpVisual, ResetMoveAnimation, std::string) 28 DEFINE_INTERFACE_METHOD_2("ReplaceMoveAnimation", void, ICmpVisual, ReplaceMoveAnimation, std::string, std::string) 27 29 DEFINE_INTERFACE_METHOD_1("SetAnimationSyncRepeat", void, ICmpVisual, SetAnimationSyncRepeat, fixed) 28 30 DEFINE_INTERFACE_METHOD_1("SetAnimationSyncOffset", void, ICmpVisual, SetAnimationSyncOffset, fixed) 29 31 DEFINE_INTERFACE_METHOD_4("SetShadingColour", void, ICmpVisual, SetShadingColour, fixed, fixed, fixed, fixed) -
source/simulation2/components/ICmpUnitMotion.h
79 79 virtual void StopMoving() = 0; 80 80 81 81 /** 82 * Get the current movement speed. 83 */ 84 virtual fixed GetCurrentSpeed() = 0; 85 86 /** 82 87 * Set the current movement speed. 83 88 */ 84 89 virtual void SetSpeed(fixed speed) = 0; -
source/simulation2/components/CCmpAIManager.cpp
261 261 }; 262 262 263 263 CAIWorker() : 264 m_ScriptRuntime(ScriptInterface::CreateRuntime( )),264 m_ScriptRuntime(ScriptInterface::CreateRuntime(20000000)), 265 265 m_ScriptInterface("Engine", "AI", m_ScriptRuntime), 266 266 m_TurnNum(0), 267 267 m_CommandsComputed(true), -
source/simulation2/components/CCmpVisualActor.cpp
23 23 #include "ICmpOwnership.h" 24 24 #include "ICmpPosition.h" 25 25 #include "ICmpRangeManager.h" 26 #include "ICmpUnitMotion.h" 26 27 #include "ICmpVision.h" 27 28 #include "simulation2/MessageTypes.h" 28 29 #include "simulation2/components/ICmpFootprint.h" … … 59 60 60 61 fixed m_R, m_G, m_B; // shading colour 61 62 63 std::map<std::string, std::string> m_AnimOverride; 64 62 65 ICmpRangeManager::ELosVisibility m_Visibility; // only valid between Interpolate and RenderSubmit 63 66 64 67 // Current animation state … … 372 375 } 373 376 } 374 377 378 virtual void ReplaceMoveAnimation(std::string name, std::string replace) 379 { 380 m_AnimOverride[name] = replace; 381 } 382 383 virtual void ResetMoveAnimation(std::string name) 384 { 385 std::map<std::string, std::string>::const_iterator it = m_AnimOverride.find(name); 386 if (it != m_AnimOverride.end()) 387 m_AnimOverride.erase(name); 388 } 389 375 390 virtual void SetUnitEntitySelection(const CStr& selection) 376 391 { 377 392 if (m_Unit) … … 566 581 model.SetCustomSelectionShape(shapeDescriptor); 567 582 } 568 583 569 void CCmpVisualActor::Update(fixed turnLength)584 void CCmpVisualActor::Update(fixed UNUSED(turnLength)) 570 585 { 571 586 if (m_Unit == NULL) 572 587 return; … … 580 595 if (!cmpPosition || !cmpPosition->IsInWorld()) 581 596 return; 582 597 583 float speed = cmpPosition->GetDistanceTravelled().ToFloat() / turnLength.ToFloat(); 598 CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), GetEntityId()); 599 if (!cmpUnitMotion) 600 return; 584 601 602 float speed = cmpUnitMotion->GetCurrentSpeed().ToFloat(); 603 604 std::string name; 585 605 if (speed == 0.0f) 606 name = "idle"; 607 else 608 name = (speed < m_AnimRunThreshold.ToFloat()) ? "walk" : "run"; 609 610 std::map<std::string, std::string>::const_iterator it = m_AnimOverride.find(name); 611 if (it != m_AnimOverride.end()) 612 name = it->second; 613 614 m_Unit->SetEntitySelection(name); 615 if (speed == 0.0f) 586 616 { 587 m_Unit->SetEntitySelection( "idle");617 m_Unit->SetEntitySelection(name); 588 618 if (m_Unit->GetAnimation()) 589 m_Unit->GetAnimation()->SetAnimationState( "idle", false, 1.f, 0.f, L"");619 m_Unit->GetAnimation()->SetAnimationState(name, false, 1.f, 0.f, L""); 590 620 } 591 else if (speed < m_AnimRunThreshold.ToFloat())592 {593 m_Unit->SetEntitySelection("walk");594 if (m_Unit->GetAnimation())595 m_Unit->GetAnimation()->SetAnimationState("walk", false, speed, 0.f, L"");596 }597 621 else 598 622 { 599 m_Unit->SetEntitySelection( "run");623 m_Unit->SetEntitySelection(name); 600 624 if (m_Unit->GetAnimation()) 601 m_Unit->GetAnimation()->SetAnimationState( "run", false, speed, 0.f, L"");625 m_Unit->GetAnimation()->SetAnimationState(name, false, speed, 0.f, L""); 602 626 } 603 627 } 604 628 } -
source/simulation2/components/ICmpUnitMotion.cpp
29 29 DEFINE_INTERFACE_METHOD_3("MoveToFormationOffset", void, ICmpUnitMotion, MoveToFormationOffset, entity_id_t, entity_pos_t, entity_pos_t) 30 30 DEFINE_INTERFACE_METHOD_2("FaceTowardsPoint", void, ICmpUnitMotion, FaceTowardsPoint, entity_pos_t, entity_pos_t) 31 31 DEFINE_INTERFACE_METHOD_0("StopMoving", void, ICmpUnitMotion, StopMoving) 32 DEFINE_INTERFACE_METHOD_0("GetCurrentSpeed", fixed, ICmpUnitMotion, GetCurrentSpeed) 32 33 DEFINE_INTERFACE_METHOD_1("SetSpeed", void, ICmpUnitMotion, SetSpeed, fixed) 33 34 DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed) 34 35 DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed) … … 71 72 m_Script.CallVoid("StopMoving"); 72 73 } 73 74 75 virtual fixed GetCurrentSpeed() 76 { 77 return m_Script.Call<fixed>("GetCurrentSpeed"); 78 } 79 74 80 virtual void SetSpeed(fixed speed) 75 81 { 76 82 m_Script.CallVoid("SetSpeed", speed); -
source/simulation2/components/CCmpUnitMotion.cpp
227 227 228 228 fixed m_Speed; 229 229 230 // Current mean speed (over the last turn). 231 fixed m_CurSpeed; 232 230 233 // Currently active paths (storing waypoints in reverse order). 231 234 // The last item in each path is the point we're currently heading towards. 232 235 ICmpPathfinder::Path m_LongPath; … … 278 281 279 282 m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed(); 280 283 m_Speed = m_WalkSpeed; 284 m_CurSpeed = fixed::Zero(); 281 285 282 286 if (paramNode.GetChild("Run").IsOk()) 283 287 { … … 405 409 return m_PassClass; 406 410 } 407 411 412 virtual fixed GetCurrentSpeed() 413 { 414 return m_CurSpeed; 415 } 416 408 417 virtual void SetSpeed(fixed speed) 409 418 { 410 419 m_Speed = speed; … … 484 493 if (cmpObstruction) 485 494 cmpObstruction->SetMovingFlag(false); 486 495 496 // No longer moving, so speed is 0. 497 m_CurSpeed = fixed::Zero(); 498 487 499 CMessageMotionChanged msg(false, false); 488 500 GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); 489 501 } … … 858 870 if (pos != initialPos) 859 871 cmpPosition->MoveTo(pos.X, pos.Y); 860 872 873 // Calculate the mean speed over this past turn. 874 m_CurSpeed = cmpPosition->GetDistanceTravelled() / dt; 875 861 876 if (wasObstructed) 862 877 { 863 878 // Oops, we hit something (very likely another unit). -
source/simulation2/components/ICmpVisual.h
92 92 virtual void SelectAnimation(std::string name, bool once, fixed speed, std::wstring soundgroup) = 0; 93 93 94 94 /** 95 * Replaces a specified animation with another. Only affects the special speed-based 96 * animation determination behaviour. 97 * @param name Animation to match. 98 * @param replace Animation that should replace the matched animation. 99 */ 100 virtual void ReplaceMoveAnimation(std::string name, std::string replace) = 0; 101 102 /** 103 * Ensures that the given animation will be used when it normally would be, 104 * removing reference to any animation that might replace it. 105 * @param name Animation name to remove from the replacement map. 106 */ 107 virtual void ResetMoveAnimation(std::string name) = 0; 108 109 /** 95 110 * Sets the specified entity selection on the underlying unit. 96 111 */ 97 112 virtual void SetUnitEntitySelection(const CStr& selection) = 0; -
binaries/data/mods/public/simulation/components/UnitAI.js
818 818 819 819 "APPROACHING": { 820 820 "enter": function () { 821 // Show weapons rather than carried resources. 822 this.SetGathererAnimationOverride(true); 823 821 824 this.SelectAnimation("move"); 822 825 this.StartTimer(1000, 1000); 823 826 }, 824 827 825 828 "leave": function() { 829 // Show carried resources when walking. 830 this.SetGathererAnimationOverride(); 831 826 832 this.StopTimer(); 827 833 }, 828 834 … … 933 939 934 940 "CHASING": { 935 941 "enter": function () { 942 // Show weapons rather than carried resources. 943 this.SetGathererAnimationOverride(true); 944 936 945 this.SelectAnimation("move"); 937 946 this.StartTimer(1000, 1000); 938 947 }, 939 948 940 949 "leave": function() { 950 // Show carried resources when walking. 951 this.SetGathererAnimationOverride(); 952 941 953 this.StopTimer(); 942 954 }, 943 955 … … 1086 1098 1087 1099 "leave": function() { 1088 1100 this.StopTimer(); 1101 1102 // Show the carried resource, if we've gathered anything. 1103 this.SetGathererAnimationOverride(); 1089 1104 }, 1090 1105 1091 1106 "Timer": function(msg) { … … 1319 1334 "RETURNRESOURCE": { 1320 1335 "APPROACHING": { 1321 1336 "enter": function () { 1322 // Work out what we're carrying, in order to select an appropriate animation 1323 var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); 1324 var type = cmpResourceGatherer.GetLastCarriedType(); 1325 if (type) 1326 { 1327 var typename = "carry_" + type.generic; 1328 1329 // Special case for meat 1330 if (type.specific == "meat") 1331 typename = "carry_" + type.specific; 1332 1333 this.SelectAnimation(typename, false, this.GetWalkSpeed()); 1334 } 1335 else 1336 { 1337 // We're returning empty-handed 1338 this.SelectAnimation("move"); 1339 } 1337 this.SelectAnimation("move"); 1340 1338 }, 1341 1339 1342 1340 "MoveCompleted": function() { … … 1357 1355 var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); 1358 1356 cmpResourceGatherer.CommitResources(dropsiteTypes); 1359 1357 1358 // Stop showing the carried resource animation. 1359 this.SetGathererAnimationOverride(); 1360 1360 1361 // Our next order should always be a Gather, 1361 1362 // so just switch back to that order 1362 1363 this.FinishOrder(); … … 1546 1547 "GARRISON": { 1547 1548 "APPROACHING": { 1548 1549 "enter": function() { 1549 this.SelectAnimation(" walk", false, this.GetWalkSpeed());1550 this.SelectAnimation("move"); 1550 1551 }, 1551 1552 1552 1553 "MoveCompleted": function() { … … 2420 2421 } 2421 2422 }; 2422 2423 2424 UnitAI.prototype.SetGathererAnimationOverride = function(disable) 2425 { 2426 var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); 2427 if (!cmpResourceGatherer) 2428 return; 2429 2430 var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); 2431 if (!cmpVisual) 2432 return; 2433 2434 // Remove the animation override, so that weapons are shown again. 2435 if (disable) 2436 { 2437 cmpVisual.ResetMoveAnimation("walk"); 2438 return; 2439 } 2440 2441 // Work out what we're carrying, in order to select an appropriate animation 2442 var type = cmpResourceGatherer.GetLastCarriedType(); 2443 if (type) 2444 { 2445 var typename = "carry_" + type.generic; 2446 2447 // Special case for meat 2448 if (type.specific == "meat") 2449 typename = "carry_" + type.specific; 2450 2451 cmpVisual.ReplaceMoveAnimation("walk", typename); 2452 } 2453 else 2454 cmpVisual.ResetMoveAnimation("walk"); 2455 } 2456 2423 2457 UnitAI.prototype.SelectAnimation = function(name, once, speed, sound) 2424 2458 { 2425 2459 var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);