~ubuntu-branches/ubuntu/raring/simutrans/raring-proposed

« back to all changes in this revision

Viewing changes to dataobj/crossing_logic.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2011-11-03 19:59:02 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20111103195902-uopgwf488mfctb75
Tags: 111.0-1
* New upstream release.
* debian/rules: Update get-orig-source target for new upstream release.
* Use xz compression for source and binary packages.
* Use override_* targets to simplify debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "../besch/kreuzung_besch.h"
18
18
 
19
 
#include "../utils/simstring.h"
20
19
#include "../utils/cbuffer_t.h"
21
20
 
22
21
#include "../tpl/slist_tpl.h"
44
43
 */
45
44
void crossing_logic_t::info(cbuffer_t & buf) const
46
45
{
47
 
        static const char *state_str[4] = { "invalid", "open", "request closing", "closed" };
 
46
        static char const* const state_str[4] = { "invalid", "open", "request closing", "closed" };
48
47
        assert(zustand<4);
49
 
        buf.append( translator::translate("\nway1 reserved by") );
50
 
        buf.append( on_way1.get_count() );
51
 
        buf.append( translator::translate("\nway2 reserved by") );
52
 
        buf.append( on_way2.get_count() );
53
 
        buf.append( translator::translate( "cars.\nstate") );
54
 
        buf.append( translator::translate(state_str[zustand]) );
 
48
        buf.printf("%s%u%s%u%s%s",
 
49
                translator::translate("\nway1 reserved by"), on_way1.get_count(),
 
50
                translator::translate("\nway2 reserved by"), on_way2.get_count(),
 
51
                translator::translate("cars.\nstate"), translator::translate(state_str[zustand])
 
52
        );
55
53
}
56
54
 
57
55
 
58
56
 
59
 
// after merging two crossings ...
 
57
// after merging or splitting two crossings ...
60
58
void crossing_logic_t::recalc_state()
61
59
{
62
60
        if(  !crossings.empty()  ) {
299
297
        minivec_tpl<crossing_logic_t *>crossings_logics;
300
298
        welt = w;
301
299
 
302
 
        crossings.append( start_cr );
 
300
        crossings.append_unique( start_cr );
 
301
        if (crossing_logic_t *start_logic = start_cr->get_logic() ) {
 
302
                crossings_logics.append(start_logic);
 
303
        }
303
304
        // go nord/west
304
305
        while(1) {
305
306
                pos += zv;
348
349
        if(  found_logic == NULL ) {
349
350
                found_logic = new crossing_logic_t( start_cr->get_besch() );
350
351
        }
351
 
        crossings.append(start_cr);
352
352
 
353
353
        // set new crossing logic to all
354
354
        slist_iterator_tpl<crossing_t *> iter(crossings);
357
357
                cr->set_logic( found_logic );
358
358
                found_logic->append_crossing( cr );
359
359
        }
 
360
        found_logic->set_state( zustand );
360
361
        found_logic->recalc_state();
361
 
        if(  zustand!=CROSSING_INVALID  ) {
362
 
                found_logic->set_state( zustand );
363
 
        }
364
362
}
365
363
 
366
364
 
373
371
                delete this;
374
372
        }
375
373
        else {
376
 
                // because we do not know, which tile is going where
377
 
                zustand = CROSSING_INVALID;
378
 
                for(  uint i=0;  i<crossings.get_count();  i++  ) {
379
 
                        add( welt, crossings[i], CROSSING_INVALID );
 
374
                // check for a crossing to the east/south
 
375
                koord3d pos = cr->get_pos();
 
376
                const koord zv = cr->get_dir() ? koord::west : koord::nord;
 
377
                const grund_t *gr = welt->lookup( pos-zv );
 
378
                if(  gr  ) {
 
379
                        crossing_t *found_cr = gr->find<crossing_t>();
 
380
                        if(  found_cr  &&  have_crossings_same_wt(found_cr->get_besch(),cr->get_besch())  ) {
 
381
                                // crossing to the east/south so split logic from any found to the north/west
 
382
                                crossing_logic_t *split_logic = NULL;
 
383
                                while(1) {
 
384
                                        pos += zv;
 
385
                                        gr = welt->lookup( pos );
 
386
                                        if(  gr == NULL  ) {
 
387
                                                break;
 
388
                                        }
 
389
                                        found_cr = gr->find<crossing_t>();
 
390
                                        if(  found_cr == NULL  ||  !have_crossings_same_wt(found_cr->get_besch(),cr->get_besch())  ) {
 
391
                                                break;
 
392
                                        }
 
393
                                        assert(this==found_cr->get_logic());
 
394
 
 
395
                                        if(  !split_logic  ) {
 
396
                                                split_logic = new crossing_logic_t( cr->get_besch() );
 
397
                                        }
 
398
                                        crossings.remove( found_cr );
 
399
                                        found_cr->set_logic( split_logic );
 
400
                                        split_logic->append_crossing( found_cr );
 
401
                                }
 
402
 
 
403
                                if(  split_logic  ) {
 
404
                                        split_logic->set_state( CROSSING_INVALID );
 
405
                                        split_logic->recalc_state();
 
406
                                }
 
407
                        }
380
408
                }
 
409
                set_state( CROSSING_INVALID );
381
410
                recalc_state();
382
411
        }
383
412
}