Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1215 closed defect (fixed)

[PATCH] Trade can occur between two incomplete buildings

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

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 (6)

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

Download all attachments as: .zip

Change History (24)

comment:1 by historic_bruno, 12 years ago

Milestone: BacklogAlpha 10
Priority: Should HaveMust Have

comment:2 by Kieran P, 12 years ago

Priority: Must HaveRelease Blocker

comment:3 by O.Davoodi, 12 years ago

Keywords: review added
Summary: Trade can occur between two incomplete buildings[PATCH] Trade can occur between two incomplete buildings

comment:4 by historic_bruno, 12 years ago

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 by O.Davoodi, 12 years ago

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

by O.Davoodi, 12 years ago

Attachment: patch2.patch added

by O.Davoodi, 12 years ago

Attachment: patch3.patch added

comment:6 by O.Davoodi, 12 years ago

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

comment:7 by Kieran P, 12 years ago

Keywords: patch added
Owner: set to O.Davoodi

in reply to:  6 comment:8 by historic_bruno, 12 years ago

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 by O.Davoodi, 12 years ago

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 by leper, 12 years ago

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.

in reply to:  10 comment:11 by O.Davoodi, 12 years ago

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 12 years ago by O.Davoodi (previous) (diff)

by O.Davoodi, 12 years ago

Attachment: finalPatch1.patch added

by O.Davoodi, 12 years ago

Attachment: finalPatch2.patch added

comment:12 by O.Davoodi, 12 years ago

Much a cleaner way.

comment:13 by leper, 12 years ago

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 :-) .

in reply to:  13 comment:14 by historic_bruno, 12 years ago

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 by Philip Taylor, 12 years ago

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.

by O.Davoodi, 12 years ago

Attachment: input.js.patch added

Patch that fixes the problem of trading with incomplete markets.

by O.Davoodi, 12 years ago

Attachment: Trader.js.patch added

comment:16 by O.Davoodi, 12 years ago

Updated the patch.

comment:17 by leper, 12 years ago

Resolution: fixed
Status: newclosed

In 11440:

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

comment:18 by leper, 12 years ago

Keywords: 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.