~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/economy/economy.cc

  • Committer: Wideland's Bunnybot
  • Date: 2017-01-20 08:56:17 UTC
  • mfrom: (8241.2.2 bug-1656671)
  • Revision ID: bunnybot@widelands.org-20170120085617-sosqusycfek80k3r
MergedĀ lp:~widelands-dev/widelands/bug-1656671.

Show diffs side-by-side

added added

removed removed

Lines of Context:
700
700
/**
701
701
 * Walk all Requests and find potential transfer candidates.
702
702
*/
703
 
void Economy::process_requests(Game& game, RSPairStruct& s) {
 
703
void Economy::process_requests(Game& game, RSPairStruct* supply_pairs) {
 
704
        // Algorithm can decide that wares are not to be delivered to constructionsite
 
705
        // right now, therefore we need to shcedule next pairing
 
706
        bool postponed_pairing_needed = false;
704
707
        for (Request* temp_req : requests_) {
705
708
                Request& req = *temp_req;
706
709
 
725
728
                        int32_t const idletime = game.get_gametime() + 15000 + 2 * cost - req.get_required_time();
726
729
                        // If the building wouldn't have to idle, we wait with the request
727
730
                        if (idletime < -200) {
728
 
                                if (s.nexttimer < 0 || s.nexttimer > -idletime)
729
 
                                        s.nexttimer = -idletime;
 
731
                                if (supply_pairs->nexttimer < 0 || supply_pairs->nexttimer > -idletime)
 
732
                                        supply_pairs->nexttimer = -idletime;
730
733
 
731
734
                                continue;
732
735
                        }
734
737
 
735
738
                int32_t const priority = req.get_priority(cost);
736
739
                if (priority < 0) {
 
740
                        // We dont "pair" the req with supply now, and dont set s.nexttimer right now
 
741
                        // but should not forget about this productionsite waiting for the building material
 
742
                        postponed_pairing_needed = true;
737
743
                        continue;
738
744
                }
739
745
 
742
748
                rsp.request = &req;
743
749
                rsp.supply = supp;
744
750
                rsp.priority = priority;
745
 
                rsp.pairid = ++s.pairid;
 
751
                rsp.pairid = ++supply_pairs->pairid;
746
752
 
747
 
                s.queue.push(rsp);
 
753
                supply_pairs->queue.push(rsp);
 
754
        }
 
755
        if (postponed_pairing_needed && supply_pairs->nexttimer < 0) {
 
756
                // so no other pair set the timer, so we set them now for after 30 seconds
 
757
                supply_pairs->nexttimer = 30 * 1000;
748
758
        }
749
759
}
750
760
 
756
766
        rsps.nexttimer = -1;
757
767
 
758
768
        //  Try to fulfill Requests.
759
 
        process_requests(game, rsps);
 
769
        process_requests(game, &rsps);
760
770
 
761
771
        //  Now execute request/supply pairs.
762
772
        while (!rsps.queue.empty()) {