Ticket #1215 (closed defect: fixed)

Opened 14 months ago

Last modified 14 months ago

[PATCH] Trade can occur between two incomplete buildings

Reported by: gudo Owned by: Spahbod
Priority: Release Blocker Milestone: Alpha 10
Component: UI & Simulation Keywords: trade, patch
Cc:

Description

When setting up a trade route, it is possible to trade between two incomplete structures.

Place two Market foundations, but do not build them. Attempt to establish a trade route between the two Trade will happen successfully.

Attachments

patch2.patch (2.5 KB) - added by Spahbod 14 months ago.
patch3.patch (661 bytes) - added by Spahbod 14 months ago.
finalPatch1.patch (552 bytes) - added by Spahbod 14 months ago.
finalPatch2.patch (4.7 KB) - added by Spahbod 14 months ago.
input.js.patch (3.3 KB) - added by Spahbod 14 months ago.
Patch that fixes the problem of trading with incomplete markets.
Trader.js.patch (568 bytes) - added by Spahbod 14 months ago.

Change History

comment:1 Changed 14 months ago by historic_bruno

  • Priority changed from Should Have to Must Have
  • Milestone changed from Backlog to Alpha 10

comment:2 Changed 14 months ago by k776

  • Priority changed from Must Have to Release Blocker

comment:3 Changed 14 months ago by Spahbod

  • Keywords trade, review added; trade removed
  • Summary changed from Trade can occur between two incomplete buildings to [PATCH] Trade can occur between two incomplete buildings

comment:4 Changed 14 months ago by historic_bruno

At first glance it seems like a good solution for the UI side of things. Usually we add checks to both UI and simulation (so that modified UIs, AIs, etc., can't accidentally or intentionally trigger these bugs). Is there a corresponding check we can perform for the simulation? Relevant code would probably be Trader.CanTrade in Trader.js.

comment:5 Changed 14 months ago by Spahbod

Attached new patches for ticket 1215. Added the check to simulation. Note:Ignore that "train" part in input.js please.

Changed 14 months ago by Spahbod

Changed 14 months ago by Spahbod

comment:6 follow-up: ↓ 8 Changed 14 months ago by Spahbod

attached a newer patch. removed the lines from other tickets. but i'll commit them together.

comment:7 Changed 14 months ago by k776

  • Keywords patch, added
  • Owner set to Spahbod

comment:8 in reply to: ↑ 6 Changed 14 months ago by historic_bruno

Replying to Spahbod:

attached a newer patch. removed the lines from other tickets. but i'll commit them together.

How are you creating the patches? Could you apply them all locally and then create a single diff/patch from the root directory of your working copy? That makes it a bit easier to review and test :)

comment:9 Changed 14 months ago by Spahbod

For reasons unknown I can't create a single patch. It seems that my session, helpers and components svn folders are separate. I can't make a single patch of them.

comment:10 follow-up: ↓ 11 Changed 14 months ago by leper

Do you really need to pass targetState? You can achieve the same thing with using the already present cmpTargetIdentity to check if the target is a foundation. Maybe you need to create a cmpTargetFoundation to check this.

But code like if (!this.CanTrade(currentMarket, currentMarket)) seems strange.

comment:11 in reply to: ↑ 10 Changed 14 months ago by Spahbod

Replying to leper:

Do you really need to pass targetState? You can achieve the same thing with using the already present cmpTargetIdentity to check if the target is a foundation. Maybe you need to create a cmpTargetFoundation to check this.

But code like if (!this.CanTrade(currentMarket, currentMarket)) seems strange.

I tried cmpTargetIdentity and got a bunch of errors and warnings.

But I changed the patch.

Last edited 14 months ago by Spahbod (previous) (diff)

Changed 14 months ago by Spahbod

Changed 14 months ago by Spahbod

comment:12 Changed 14 months ago by Spahbod

Much a cleaner way.

comment:13 follow-up: ↓ 14 Changed 14 months ago by leper

Sorry, I meant using Foundation.js as you do now.

You have some changes from your batch training patch in finalPatch2.patch. I would also name the variable like the others. Like cmpTargetFoundation instead of targetState. Apart from that the patch is looking good, though I am not really able to review it :-) .

comment:14 in reply to: ↑ 13 Changed 14 months ago by historic_bruno

Replying to leper:

I would also name the variable like the others. Like cmpTargetFoundation instead of targetState. Apart from that the patch is looking good, though I am not really able to review it :-) .

Indeed the convention is to name component references like "cmpFoundation", although I don't think it's been added to Coding_Conventions yet. (The reason we use e.g. targetState in GUI scripts is because they don't access components directly, only a limited entity state created by GUIInterface so it would be wrong to call them cmpFoo.)

I'll move the SVN conversation to forum messages to avoid cluttering this ticket.

comment:15 Changed 14 months ago by Philip

Yep, it should be cmpTargetFoundation to be consistent with the other variables in that function.

Couple of things in input.js:

  • Needs spaces around the "&&"
  • Rather than indenting the switch and adding a long if/else, better to do
    if (tradingDetails === null)
       return {"possible": false};
    switch (...)
    {
        ...
    }
    
    to minimise the distance between the error condition and associated return.

Changed 14 months ago by Spahbod

Patch that fixes the problem of trading with incomplete markets.

Changed 14 months ago by Spahbod

comment:16 Changed 14 months ago by Spahbod

Updated the patch.

comment:17 Changed 14 months ago by leper

  • Status changed from new to closed
  • Resolution set to fixed

In 11440:

Prevent trade with foundations, based on patch by Spahbod, fixes #1215.

comment:18 Changed 14 months ago by leper

  • Keywords patch added; patch, review removed

Thanks for the patch. I applied a slightly modified version stripped of the code from other patches.

Note: See TracTickets for help on using tickets.