Ticket #1822: 1822.patch

File 1822.patch, 2.5 KB (added by leper, 11 years ago)

WIP fix for #1822 and #1821

  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    878878            this.SetNextStateAlwaysEntering("MEMBER");
    879879        },
    880880
     881        "Order.Trade": function(msg) {
     882            //this.AddOrder("Trade", { "target": target, "source": source, "force": false }, queued);
     883            var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     884            // We don't want to rearrange the formation if the individual units are carrying
     885            // out a task and one of the members dies/leaves the formation.
     886            cmpFormation.SetRearrange(false);
     887            cmpFormation.CallMemberFunction("SetupTradeRoute", [msg.data.target, msg.data.source, false]);
     888
     889            this.SetNextStateAlwaysEntering("MEMBER");
     890        },
     891
    881892        "Order.Pack": function(msg) {
    882893            var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
    883894            // We don't want to rearrange the formation if the individual units are carrying
     
    36823693
    36833694            break; // and continue the loop
    36843695
     3696        case "Trade": // Added here for formation trading only, but that doesn't make that much sense
    36853697        case "WalkToTarget":
    36863698        case "WalkToTargetRange": // This doesn't move to the target (just into range), but a later order will.
    36873699        case "Flee":
     
    39203932    }
    39213933
    39223934    var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
     3935    // Formation controller probably (TODO: make this explicit?)
     3936    if (!cmpTrader)
     3937    {
     3938        this.AddOrder("Trade", { "target": target, "source": source, "force": false }, queued);
     3939        return;
     3940    }
     3941
    39233942    var marketsChanged = cmpTrader.SetTargetMarket(target, source);
    39243943    if (marketsChanged)
    39253944    {
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    428428        break;
    429429
    430430    case "setup-trade-route":
    431         for each (var ent in cmd.entities)
    432         {
    433             var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
    434             if (cmpUnitAI)
    435                 cmpUnitAI.SetupTradeRoute(cmd.target, cmd.source);
    436         }
     431        var entities = FilterEntityList(cmd.entities, player, controlAllUnits);
     432        GetFormationUnitAIs(entities, player).forEach(function(cmpUnitAI) {
     433            cmpUnitAI.SetupTradeRoute(cmd.target,cmd.source, cmd.queued);
     434        });
    437435        break;
    438436
    439437    case "select-trading-goods":