~ubuntu-branches/debian/squeeze/simutrans/squeeze

« back to all changes in this revision

Viewing changes to vehicle/simverkehr.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ansgar Burchardt
  • Date: 2009-10-18 15:29:14 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091018152914-ip7am3dx1tl27uyb
Tags: 102.2+svn2786-1
* New upstream release.
  + Refresh patches.
  + Update translations.
* debian/rules: Add get-orig-source target.
* debian/rules: Add update-translations target.
* debian/README.source: Document get-orig-source and update-translations
  targets.
* Bump Standards-Version to 3.8.3 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
 
48
48
verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt) :
49
 
   vehikel_basis_t(welt)
 
49
        vehikel_basis_t(welt)
50
50
{
51
51
        set_besitzer( welt->get_spieler(1) );
52
52
        time_to_life = -1;
78
78
 
79
79
 
80
80
verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt, koord3d pos) :
81
 
   vehikel_basis_t(welt, pos)
 
81
        vehikel_basis_t(welt, pos)
82
82
{
83
83
        // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
84
84
        grund_t *from = welt->lookup(pos);
139
139
}
140
140
 
141
141
 
142
 
void
143
 
verkehrsteilnehmer_t::hop()
 
142
void verkehrsteilnehmer_t::hop()
144
143
{
145
144
        // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
146
145
        grund_t *from = welt->lookup(pos_next);
299
298
 
300
299
 
301
300
static weighted_vector_tpl<const stadtauto_besch_t*> liste_timeline;
302
 
static weighted_vector_tpl<const stadtauto_besch_t*> liste;
303
301
stringhashtable_tpl<const stadtauto_besch_t *> stadtauto_t::table;
304
302
 
305
 
void stadtauto_t::built_timeline_liste(karte_t *welt)
306
 
{
307
 
        if (!liste.empty()) {
308
 
                // this list will contain all citycars
309
 
                liste_timeline.clear();
310
 
                const int month_now = welt->get_current_month();
311
 
 
312
 
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","year=%i, month=%i", month_now/12, month_now%12+1);
313
 
 
314
 
                // check for every citycar, if still ok ...
315
 
                for (weighted_vector_tpl<const stadtauto_besch_t*>::const_iterator i = liste.begin(), end = liste.end(); i != end; ++i) {
316
 
                        const stadtauto_besch_t* info = *i;
317
 
                        const int intro_month = info->get_intro_year_month();
318
 
                        const int retire_month = info->get_retire_year_month();
319
 
 
320
 
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","iyear=%i, imonth=%i", intro_month/12, intro_month%12+1);
321
 
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","ryear=%i, rmonth=%i", retire_month/12, retire_month%12+1);
322
 
 
323
 
                        if (!welt->use_timeline() || (intro_month <= month_now && month_now < retire_month)) {
324
 
                                liste_timeline.append(info, info->get_gewichtung(), 1);
325
 
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","adding %s to liste",info->get_name());
326
 
                        }
327
 
                }
328
 
        }
329
 
}
330
 
 
331
 
 
332
 
 
333
303
bool stadtauto_t::register_besch(const stadtauto_besch_t *besch)
334
304
{
335
 
        liste.append(besch, besch->get_gewichtung(), 1);
 
305
        if(  table.remove(besch->get_name())  ) {
 
306
                dbg->warning( "stadtauto_besch_t::register_besch()", "Object %s was overlaid by addon!", besch->get_name() );
 
307
        }
336
308
        table.put(besch->get_name(), besch);
337
309
        // correct for driving on left side
338
310
        if(umgebung_t::drive_on_left) {
353
325
 
354
326
 
355
327
 
356
 
bool stadtauto_t::laden_erfolgreich()
 
328
bool stadtauto_t::alles_geladen()
357
329
{
358
 
        if (liste.empty()) {
 
330
        if(table.empty()) {
359
331
                DBG_MESSAGE("stadtauto_t", "No citycars found - feature disabled");
360
332
        }
361
333
        return true;
362
334
}
363
335
 
364
336
 
 
337
void stadtauto_t::built_timeline_liste(karte_t *welt)
 
338
{
 
339
        // this list will contain all citycars
 
340
        liste_timeline.clear();
 
341
 
 
342
        if(  !table.empty()  ) {
 
343
                const int month_now = welt->get_current_month();
 
344
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","year=%i, month=%i", month_now/12, month_now%12+1);
 
345
 
 
346
                // check for every citycar, if still ok ...
 
347
                stringhashtable_iterator_tpl<const stadtauto_besch_t *>iter(table);
 
348
                while(   iter.next()  ) {
 
349
                        const stadtauto_besch_t* info = iter.get_current_value();
 
350
                        const int intro_month = info->get_intro_year_month();
 
351
                        const int retire_month = info->get_retire_year_month();
 
352
 
 
353
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","iyear=%i, imonth=%i", intro_month/12, intro_month%12+1);
 
354
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","ryear=%i, rmonth=%i", retire_month/12, retire_month%12+1);
 
355
 
 
356
                        if (!welt->use_timeline() || (intro_month <= month_now && month_now < retire_month)) {
 
357
                                liste_timeline.append(info, info->get_gewichtung(), 1);
 
358
//DBG_DEBUG("stadtauto_t::built_timeline_liste()","adding %s to liste",info->get_name());
 
359
                        }
 
360
                }
 
361
        }
 
362
}
 
363
 
 
364
 
 
365
 
365
366
bool stadtauto_t::list_empty()
366
367
{
367
368
        return liste_timeline.empty();
368
369
}
369
370
 
370
371
 
 
372
 
371
373
stadtauto_t::~stadtauto_t()
372
374
{
373
375
        welt->buche( -1, karte_t::WORLD_CITYCARS );
374
376
}
375
377
 
376
378
 
377
 
stadtauto_t::stadtauto_t(karte_t *welt, loadsave_t *file)
378
 
 : verkehrsteilnehmer_t(welt)
 
379
stadtauto_t::stadtauto_t(karte_t *welt, loadsave_t *file) :
 
380
        verkehrsteilnehmer_t(welt)
379
381
{
380
382
        rdwr(file);
381
383
        ms_traffic_jam = 0;
391
393
#else
392
394
stadtauto_t::stadtauto_t(karte_t *welt, koord3d pos, koord )
393
395
#endif
394
 
 : verkehrsteilnehmer_t(welt, pos)
 
396
        : verkehrsteilnehmer_t(welt, pos)
395
397
{
396
 
        besch = liste_timeline.at_weight(simrand(liste_timeline.get_sum_weight()));
397
 
        if(!besch) {
398
 
                besch = liste.at_weight(simrand(liste.get_sum_weight()));
399
 
        }
 
398
        besch = liste_timeline.empty() ? NULL : liste_timeline.at_weight(simrand(liste_timeline.get_sum_weight()));
400
399
        pos_next_next = koord3d::invalid;
401
400
        time_to_life = welt->get_einstellungen()->get_stadtauto_duration() << welt->ticks_bits_per_tag;
402
401
        current_speed = 48;
411
410
 
412
411
 
413
412
 
414
 
bool
415
 
stadtauto_t::sync_step(long delta_t)
 
413
bool stadtauto_t::sync_step(long delta_t)
416
414
{
417
415
        if(time_to_life<=0) {
418
416
                // remove obj
419
 
                return false;
 
417
                return false;
420
418
        }
421
419
 
422
420
        time_to_life -= delta_t;
465
463
                file->rdwr_str(s, 256);
466
464
                besch = table.get(s);
467
465
 
468
 
                if (besch == 0 && !liste_timeline.empty()) {
 
466
                if(  besch == 0  &&  !liste_timeline.empty()  ) {
469
467
                        dbg->warning("stadtauto_t::rdwr()", "Object '%s' not found in table, trying random stadtauto object type",s);
470
468
                        besch = liste_timeline.at_weight(simrand(liste_timeline.get_sum_weight()));
471
469
                }
472
 
                if (besch == 0 && !liste.empty()) {
473
 
                        dbg->warning("stadtauto_t::rdwr()", "Object '%s' not found in table, trying random stadtauto object type",s);
474
 
                        besch = liste.at_weight(simrand(liste.get_sum_weight()));
475
 
                }
476
470
 
477
471
                if(besch == 0) {
478
472
                        dbg->warning("stadtauto_t::rdwr()", "loading game with private cars, but no private car objects found in PAK files.");
659
653
stadtauto_t::betrete_feld()
660
654
{
661
655
#ifdef DESTINATION_CITYCARS
662
 
        if(target!=koord::invalid  &&  abs_distance(pos_next.get_2d(),target)<10) {
 
656
        if(target!=koord::invalid  &&  koord_distance(pos_next.get_2d(),target)<10) {
663
657
                // delete it ...
664
658
                time_to_life = 0;
665
659
 
677
671
 
678
672
 
679
673
 
680
 
bool
681
 
stadtauto_t::hop_check()
 
674
bool stadtauto_t::hop_check()
682
675
{
683
676
        // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
684
677
        grund_t *from = welt->lookup(pos_next);
757
750
                                                }
758
751
                                        }
759
752
#ifdef DESTINATION_CITYCARS
760
 
                                        unsigned long dist=abs_distance( to->get_pos().get_2d(), target );
 
753
                                        unsigned long dist=koord_distance( to->get_pos().get_2d(), target );
761
754
                                        posliste.append( to->get_pos(), dist*dist );
762
755
#else
763
756
                                        // ok, now check if we are allowed to go here (i.e. no cars blocking)
823
816
 
824
817
 
825
818
 
826
 
void
827
 
stadtauto_t::hop()
 
819
void stadtauto_t::hop()
828
820
{
829
821
        // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
830
822
        grund_t *to = welt->lookup(pos_next);
856
848
 
857
849
 
858
850
 
859
 
void
860
 
stadtauto_t::calc_bild()
 
851
void stadtauto_t::calc_bild()
861
852
{
862
 
        if(welt->lookup(get_pos())->ist_im_tunnel()) {
863
 
                set_bild( IMG_LEER);
864
 
        }
865
 
        else {
866
 
                set_bild(besch->get_bild_nr(ribi_t::get_dir(get_fahrtrichtung())));
867
 
        }
 
853
        set_bild(besch->get_bild_nr(ribi_t::get_dir(get_fahrtrichtung())));
868
854
}
869
855
 
870
856
 
871
857
 
872
 
void
873
 
stadtauto_t::calc_current_speed()
 
858
void stadtauto_t::calc_current_speed()
874
859
{
875
860
        const weg_t * weg = welt->lookup(get_pos())->get_weg(road_wt);
876
861
        const uint16 max_speed = besch->get_geschw();