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

« back to all changes in this revision

Viewing changes to simwerkz.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:
21
21
#include "bauer/fabrikbauer.h"
22
22
#include "bauer/vehikelbauer.h"
23
23
 
24
 
#include "boden/boden.h"
25
24
#include "boden/grund.h"
26
25
#include "boden/wasser.h"
27
 
#include "boden/wege/strasse.h"
28
26
#include "boden/wege/schiene.h"
29
 
#include "boden/wege/kanal.h"
30
27
#include "boden/tunnelboden.h"
31
28
#include "boden/monorailboden.h"
32
29
 
38
35
 
39
36
#include "besch/grund_besch.h"
40
37
#include "besch/haus_besch.h"
41
 
#include "besch/skin_besch.h"
42
38
#include "besch/roadsign_besch.h"
43
39
#include "besch/tunnel_besch.h"
44
 
#include "besch/groundobj_besch.h"
45
 
#include "besch/roadsign_besch.h"
46
40
 
47
41
#include "vehicle/simvehikel.h"
48
42
#include "vehicle/simverkehr.h"
59
53
#include "gui/signal_spacing.h"
60
54
#include "gui/stadt_info.h"
61
55
#include "gui/trafficlight_info.h"
 
56
#include "gui/privatesign_info.h"
62
57
 
63
58
#include "dings/zeiger.h"
64
59
#include "dings/bruecke.h"
73
68
#include "dings/field.h"
74
69
#include "dings/label.h"
75
70
 
76
 
#include "dataobj/tabfile.h"
77
71
#include "dataobj/einstellungen.h"
78
72
#include "dataobj/umgebung.h"
79
73
#include "dataobj/fahrplan.h"
161
155
                if(enables&4) {
162
156
                        n += sprintf( werkzeug_t::toolstr+n, " %s", translator::translate("Fracht") );
163
157
                }
164
 
        }
165
 
        else if(  !welt->get_einstellungen()->is_seperate_halt_capacities()  ) {
 
158
        } else if (!welt->get_settings().is_seperate_halt_capacities()) {
166
159
                n += sprintf( werkzeug_t::toolstr+n, ", %s %d", translator::translate("Storage capacity"), level*32 );
167
160
        }
168
161
 
588
581
                }
589
582
                DBG_MESSAGE("wkz_remover()",  "removing building" );
590
583
                const haus_tile_besch_t *tile  = gb->get_tile();
591
 
                koord size = tile->get_besch()->get_groesse( tile->get_layout() );
592
584
 
593
585
                // get startpos
594
586
                koord k=tile->get_offset();
830
822
                                ok = (n!=0);
831
823
                        }
832
824
                        if(n>0) {
833
 
                                spieler_t::accounting(sp, welt->get_einstellungen()->cst_alter_land*n, pos, COST_CONSTRUCTION);
 
825
                                spieler_t::accounting(sp, welt->get_settings().cst_alter_land * n, pos, COST_CONSTRUCTION);
834
826
                        }
835
827
                        return !ok ? "Tile not empty." : (n ? NULL : "");
836
828
                }
918
910
                                ok = (n!=0);
919
911
                        }
920
912
                        if(n>0) {
921
 
                                spieler_t::accounting(sp, welt->get_einstellungen()->cst_alter_land*n, pos, COST_CONSTRUCTION);
 
913
                                spieler_t::accounting(sp, welt->get_settings().cst_alter_land * n, pos, COST_CONSTRUCTION);
922
914
                        }
923
915
                        return !ok ? "Tile not empty." : (n ? NULL : "");
924
916
                }
1040
1032
                }
1041
1033
 
1042
1034
 
1043
 
                if(new_slope == RESTORE_SLOPE) {
 
1035
                if(  new_slope == RESTORE_SLOPE  ) {
1044
1036
                        // prissi: special action: set to natural slope
1045
1037
                        sint8 min_hgt;
1046
1038
                        new_slope = welt->recalc_natural_slope(pos.get_2d(),min_hgt);
1047
1039
                        new_pos = koord3d(pos.get_2d(), min_hgt);
1048
1040
                        DBG_MESSAGE("natural_slope","%i",new_slope);
1049
1041
                }
1050
 
                else if(new_slope == ALL_DOWN_SLOPE) {
 
1042
                else if(  new_slope == ALL_DOWN_SLOPE  ) {
1051
1043
                        new_slope = hang_t::flach;
1052
1044
                        // is more intuitive: if there is a slope, first downgrade it
1053
 
                        if (gr1->get_grund_hang()==0  ) {
 
1045
                        if(  gr1->get_grund_hang()==0  ) {
1054
1046
                                new_pos.z -= Z_TILE_STEP;
1055
1047
                        }
1056
1048
                }
1057
 
                else if(new_slope == ALL_UP_SLOPE) {
 
1049
                else if(  new_slope == ALL_UP_SLOPE  ) {
1058
1050
                        new_slope = hang_t::flach;
1059
1051
                        new_pos.z += Z_TILE_STEP;
1060
1052
                }
1134
1126
                                // not empty ...
1135
1127
                                return "Tile not empty.";
1136
1128
                        }
 
1129
                        // check way ownership
 
1130
                        if(gr1->hat_wege()) {
 
1131
                                if(gr1->get_weg_nr(0)->ist_entfernbar(sp)!=NULL) {
 
1132
                                        return "Tile not empty.";
 
1133
                                }
 
1134
                                if(gr1->has_two_ways()  &&  gr1->get_weg_nr(1)->ist_entfernbar(sp)!=NULL) {
 
1135
                                        return "Tile not empty.";
 
1136
                                }
 
1137
                        }
1137
1138
 
1138
1139
                        // ok, was sucess
1139
1140
                        if(!gr1->ist_wasser()  &&  new_slope==0  &&  new_pos.z==welt->get_grundwasser()  &&  gr1->get_typ()!=grund_t::tunnelboden  ) {
1143
1144
                                gr1 = welt->lookup_kartenboden(new_pos.get_2d());
1144
1145
                        }
1145
1146
                        else if(gr1->ist_wasser()  &&  (new_pos.z>welt->get_grundwasser()  ||  new_slope!=0)) {
 
1147
                                // build underwater hill first
 
1148
                                if (!welt->ebne_planquadrat(sp, pos.get_2d(), welt->get_grundwasser(), false, true)) {
 
1149
                                        return "Tile not empty.";
 
1150
                                }
1146
1151
                                gr1->obj_loesche_alle(sp);
1147
1152
                                welt->access(pos.get_2d())->kartenboden_setzen( new boden_t(welt,new_pos,new_slope) );
1148
1153
                                gr1 = welt->lookup_kartenboden(new_pos.get_2d());
1197
1202
                                }
1198
1203
                                reliefkarte_t::get_karte()->calc_map_pixel(pos.get_2d());
1199
1204
                        }
1200
 
                        spieler_t::accounting(sp, new_slope==RESTORE_SLOPE?welt->get_einstellungen()->cst_alter_land:welt->get_einstellungen()->cst_set_slope, pos.get_2d(), COST_CONSTRUCTION);
 
1205
                        settings_t const& s = welt->get_settings();
 
1206
                        spieler_t::accounting(sp, new_slope == RESTORE_SLOPE ? s.cst_alter_land : s.cst_set_slope, pos.get_2d(), COST_CONSTRUCTION);
1201
1207
                }
1202
1208
 
1203
1209
        }
1289
1295
 
1290
1296
 
1291
1297
// transformer for electricity supply
1292
 
const char *wkz_transformer_t::get_tooltip( spieler_t *sp )
 
1298
const char* wkz_transformer_t::get_tooltip(const spieler_t *sp) const
1293
1299
{
1294
 
        sprintf(toolstr, "%s, %ld$ (%ld$)", translator::translate("Build drain"), (long)(sp->get_welt()->get_einstellungen()->cst_transformer/-100l), (long)(sp->get_welt()->get_einstellungen()->cst_maintain_transformer<<(sp->get_welt()->ticks_per_world_month_shift-18))/-100l );
 
1300
        settings_t const& s = sp->get_welt()->get_settings();
 
1301
        sprintf(toolstr, "%s, %ld$ (%ld$)", translator::translate("Build drain"), (long)(s.cst_transformer / -100), (long)(s.cst_maintain_transformer << (sp->get_welt()->ticks_per_world_month_shift - 18)) / -100);
1295
1302
        return toolstr;
1296
1303
}
1297
1304
 
1357
1364
                                // buildings the game crashes. To avoid this problem cities
1358
1365
                                // always belong to player 1
1359
1366
 
1360
 
                                int citizens=(int)(welt->get_einstellungen()->get_mittlere_einwohnerzahl()*0.9);
 
1367
                                int const citizens = (int)(welt->get_settings().get_mittlere_einwohnerzahl() * 0.9);
1361
1368
                                //  stadt_t *stadt = new stadt_t(welt, welt->get_spieler(1), pos,citizens/10+simrand(2*citizens+1));
1362
1369
 
1363
1370
                                // always start with 1/10 citicens
1367
1374
                                stadt->laden_abschliessen();
1368
1375
                                stadt->verbinde_fabriken();
1369
1376
 
1370
 
                                spieler_t::accounting(sp, welt->get_einstellungen()->cst_found_city, pos.get_2d(), COST_CONSTRUCTION);
 
1377
                                spieler_t::accounting(sp, welt->get_settings().cst_found_city, pos.get_2d(), COST_CONSTRUCTION);
1371
1378
                                reliefkarte_t::get_karte()->calc_map();
1372
1379
                                return NULL;
1373
1380
                        }
1414
1421
                                gebaeude_t *gb_part = gr->find<gebaeude_t>();
1415
1422
                                // there may be buildings with holes
1416
1423
                                if(  gb_part  &&  gb_part->get_tile()->get_besch()==hb  &&  spieler_t::check_owner(gb_part->get_besitzer(),sp)  ) {
1417
 
                                        spieler_t::add_maintenance( old_owner, -welt->get_einstellungen()->maint_building*hb->get_level() );
1418
 
                                        spieler_t::add_maintenance( sp, +welt->get_einstellungen()->maint_building*hb->get_level() );
 
1424
                                        sint32 const maint = welt->get_settings().maint_building * hb->get_level();
 
1425
                                        spieler_t::add_maintenance(old_owner, -maint);
 
1426
                                        spieler_t::add_maintenance(sp,        +maint);
1419
1427
                                        gb->set_besitzer(sp);
1420
 
                                        sp->buche( -welt->get_einstellungen()->maint_building*hb->get_level(), k+pos.get_2d(), COST_CONSTRUCTION);
 
1428
                                        sp->buche(-maint, k + pos.get_2d(), COST_CONSTRUCTION);
1421
1429
                                }
1422
1430
                        }
1423
1431
                }
1439
1447
        stadt_t *city = welt->suche_naechste_stadt(pos.get_2d());
1440
1448
        if(city!=NULL) {
1441
1449
                city->change_size( atoi(default_param) );
 
1450
                // Knightly : update the links from other cities to this city
 
1451
                const weighted_vector_tpl<stadt_t *> &cities = welt->get_staedte();
 
1452
                for(  uint32 c=0;  c<cities.get_count();  ++c  ) {
 
1453
                        cities[c]->remove_target_city(city);
 
1454
                        cities[c]->add_target_city(city);
 
1455
                }
1442
1456
                return NULL;
1443
1457
        }
1444
1458
        return "";
1463
1477
                        besch = baum_t::find_tree(default_param+3);
1464
1478
                }
1465
1479
                if(besch  &&  baum_t::plant_tree_on_coordinate( welt, pos.get_2d(), besch, check_climates, random_age )  ) {
1466
 
                        spieler_t::accounting( sp, welt->get_einstellungen()->cst_remove_tree, pos.get_2d(), COST_CONSTRUCTION );
 
1480
                        spieler_t::accounting(sp, welt->get_settings().cst_remove_tree, pos.get_2d(), COST_CONSTRUCTION);
1467
1481
                        return NULL;
1468
1482
                }
1469
1483
                return "";
1481
1495
static const char *wkz_fahrplan_insert_aux(karte_t *welt, spieler_t *sp, koord3d pos, schedule_t *fpl, bool append){
1482
1496
        if(fpl == NULL) {
1483
1497
                dbg->warning("wkz_fahrplan_insert_aux()","Schedule is (null), doing nothing");
1484
 
                return false;
 
1498
                return 0;
1485
1499
        }
1486
1500
        grund_t *bd = welt->lookup(pos);
1487
1501
        if (bd) {
1536
1550
const weg_besch_t *wkz_wegebau_t::get_besch( uint16 timeline_year_month, bool remember ) const
1537
1551
{
1538
1552
        const weg_besch_t *besch = default_param ? wegbauer_t::get_besch(default_param,0) :NULL;
1539
 
        if(besch==NULL) {
 
1553
        if(besch==NULL  &&  default_param  ) {
1540
1554
                waytype_t wt = (waytype_t)atoi(default_param);
1541
1555
                besch = defaults[wt&63];
1542
1556
                if(besch==NULL) {
1563
1577
        return (grund_t::underground_mode==grund_t::ugm_all && !is_tram ) ? IMG_LEER : icon;
1564
1578
}
1565
1579
 
1566
 
const char *wkz_wegebau_t::get_tooltip(spieler_t *sp)
 
1580
const char* wkz_wegebau_t::get_tooltip(const spieler_t *sp) const
1567
1581
{
1568
1582
        const weg_besch_t *besch = get_besch(sp->get_welt()->get_timeline_year_month(),false);
1569
1583
        tooltip_with_price_maintenance( sp->get_welt(), besch->get_name(), -besch->get_preis(), besch->get_wartung() );
1597
1611
        }
1598
1612
}
1599
1613
 
1600
 
bool wkz_wegebau_t::is_selected( karte_t *welt ) const
 
1614
bool wkz_wegebau_t::is_selected( const karte_t *welt ) const
1601
1615
{
1602
1616
        if (welt->get_werkzeug(welt->get_active_player_nr())->get_id()!=id) {
1603
1617
                return false;
1668
1682
        }
1669
1683
        // elevated track?
1670
1684
        if(besch->get_styp()==1  &&  besch->get_wtyp()!=air_wt) {
1671
 
                bautyp = (wegbauer_t::bautyp_t)((int)bautyp|(int)wegbauer_t::elevated_flag);
 
1685
                bautyp |= wegbauer_t::elevated_flag;
1672
1686
        }
1673
1687
 
1674
1688
        bauigel.route_fuer(bautyp, besch);
1675
 
        if(is_ctrl_pressed()) {
 
1689
        if(  is_ctrl_pressed()  ) {
 
1690
                bauigel.set_keep_existing_ways( false );
 
1691
        }
 
1692
        else {
 
1693
                bauigel.set_keep_existing_faster_ways( true );
 
1694
        }
 
1695
        if(  umgebung_t::straight_way_without_control  ||  is_ctrl_pressed()  ) {
1676
1696
                DBG_MESSAGE("wkz_wegebau()", "try straight route");
1677
 
                bauigel.set_keep_existing_ways(false);
1678
1697
                bauigel.calc_straight_route(start,end);
1679
1698
        }
1680
1699
        else {
1681
 
                bauigel.set_keep_existing_faster_ways(true);
1682
1700
                bauigel.calc_route(start,end);
1683
1701
        }
1684
1702
        DBG_MESSAGE("wkz_wegebau()", "builder found route with %d sqaures length.", bauigel.get_count());
1770
1788
}
1771
1789
 
1772
1790
/* bridge construction */
1773
 
const char *wkz_brueckenbau_t::get_tooltip(spieler_t *sp)
 
1791
const char* wkz_brueckenbau_t::get_tooltip(const spieler_t *sp) const
1774
1792
{
1775
1793
        const bruecke_besch_t * besch = brueckenbauer_t::get_besch(default_param);
1776
1794
        tooltip_with_price_maintenance( sp->get_welt(), besch->get_name(), -besch->get_preis(), besch->get_wartung() );
1819
1837
                        ding_t *dt = gr->obj_bei(i);
1820
1838
                        switch(dt->get_typ()) {
1821
1839
                                case ding_t::baum:
1822
 
                                        costs -= welt->get_einstellungen()->cst_remove_tree;
 
1840
                                        costs -= welt->get_settings().cst_remove_tree;
1823
1841
                                        break;
1824
1842
                                case ding_t::groundobj:
1825
1843
                                        costs += ((groundobj_t *)dt)->get_besch()->get_preis();
1875
1893
                        ding_t *dt = gr->obj_bei(i);
1876
1894
                        switch(dt->get_typ()) {
1877
1895
                                case ding_t::baum:
1878
 
                                        costs -= welt->get_einstellungen()->cst_remove_tree;
 
1896
                                        costs -= welt->get_settings().cst_remove_tree;
1879
1897
                                        break;
1880
1898
                                case ding_t::groundobj:
1881
1899
                                        costs += ((groundobj_t *)dt)->get_besch()->get_preis();
1963
1981
                const char *error = NULL;
1964
1982
                koord3d end = brueckenbauer_t::finde_ende(welt, start, koord(test), besch, error, false, koord_distance(start, pos));
1965
1983
                if (end!=pos) {
1966
 
                        koord3d end = brueckenbauer_t::finde_ende(welt, start, koord(test), besch, error, false, koord_distance(start, pos));
1967
1984
                        return 0;
1968
1985
                }
1969
1986
                return 2;
1972
1989
 
1973
1990
 
1974
1991
/* more difficult, since this builds also underground ways */
1975
 
const char *wkz_tunnelbau_t::get_tooltip(spieler_t *sp)
 
1992
const char* wkz_tunnelbau_t::get_tooltip(const spieler_t *sp) const
1976
1993
{
1977
1994
        const tunnel_besch_t * besch = tunnelbauer_t::get_besch(default_param);
1978
1995
        tooltip_with_price_maintenance( sp->get_welt(), besch->get_name(), -besch->get_preis(), besch->get_wartung() );
1996
2013
void wkz_tunnelbau_t::calc_route( wegbauer_t &bauigel, const koord3d &start, const koord3d &end, karte_t *welt )
1997
2014
{
1998
2015
        const tunnel_besch_t *besch = tunnelbauer_t::get_besch(default_param);
1999
 
        int bt = besch->get_waytype()|wegbauer_t::tunnel_flag;
 
2016
        wegbauer_t::bautyp_t bt = (wegbauer_t::bautyp_t)(besch->get_waytype());
2000
2017
        const weg_besch_t *wb = wegbauer_t::weg_search( besch->get_waytype(), besch->get_topspeed(), welt->get_timeline_year_month(), weg_t::type_flat );
2001
 
        bauigel.route_fuer((wegbauer_t::bautyp_t)bt, wb, besch);
 
2018
        bauigel.route_fuer(bt | wegbauer_t::tunnel_flag, wb, besch);
2002
2019
        bauigel.set_keep_existing_faster_ways( !is_ctrl_pressed() );
2003
2020
        // wegbauer tries to find route to 3d coordinate if no ground at end exists or is not kartenboden
2004
2021
        bauigel.calc_straight_route(start,end);
2117
2134
        }
2118
2135
}
2119
2136
 
 
2137
 
2120
2138
/* removes a way like a driving car ... */
2121
 
const char *wkz_wayremover_t::get_tooltip(spieler_t *)
 
2139
char const* wkz_wayremover_t::get_tooltip(spieler_t const*) const
2122
2140
{
2123
2141
        switch(atoi(default_param)) {
2124
2142
                case road_wt: return translator::translate("remove roads");
2177
2195
        return 2;
2178
2196
}
2179
2197
 
2180
 
 
2181
2198
bool wkz_wayremover_t::calc_route( route_t &verbindung, spieler_t *sp, const koord3d &start, const koord3d &end )
2182
2199
{
2183
2200
        waytype_t wt = (waytype_t)atoi(default_param);
2205
2222
                else {
2206
2223
                        test_driver = new electron_t();
2207
2224
                }
2208
 
                verbindung.calc_route(sp->get_welt(), start, end, test_driver, 0);
 
2225
                verbindung.calc_route(sp->get_welt(), start, end, test_driver, 0, 0);
2209
2226
                delete test_driver;
2210
2227
        }
2211
2228
        DBG_MESSAGE("wkz_wayremover()","route with %d tile found",verbindung.get_count());
2359
2376
/* add catenary during construction */
2360
2377
const way_obj_besch_t *wkz_wayobj_t::default_electric = NULL;
2361
2378
 
2362
 
const char *wkz_wayobj_t::get_tooltip(spieler_t *sp)
 
2379
const char* wkz_wayobj_t::get_tooltip(const spieler_t *sp) const
2363
2380
{
2364
2381
        if(  build  ) {
2365
2382
                const way_obj_besch_t *besch = get_besch(sp->get_welt());
2375
2392
                return NULL;
2376
2393
        }
2377
2394
        else {
2378
 
                wt = (waytype_t)atoi( default_param );
 
2395
                waytype_t wt = (waytype_t)atoi( default_param );
2379
2396
                sprintf( toolstr, translator::translate("Remove wayobj %s"), translator::translate(weg_t::waytype_to_string(wt)) );
2380
2397
                return toolstr;
2381
2398
        }
2393
2410
        return besch;
2394
2411
}
2395
2412
 
2396
 
bool wkz_wayobj_t::is_selected( karte_t *welt ) const
 
2413
bool wkz_wayobj_t::is_selected( const karte_t *welt ) const
2397
2414
{
2398
2415
        const wkz_wayobj_t *selected = dynamic_cast<const wkz_wayobj_t *>(welt->get_werkzeug(welt->get_active_player_nr()));
2399
2416
        return (selected  &&  selected->build==build  &&  selected->get_besch(welt) == get_besch(welt));
2427
2444
        test_driver->set_flag( ding_t::not_on_map );
2428
2445
        bool can_built;
2429
2446
        if( start != to ) {
2430
 
                can_built = verbindung.calc_route(sp->get_welt(), start, to, test_driver, 0);
 
2447
                can_built = verbindung.calc_route(sp->get_welt(), start, to, test_driver, 0, 0);
2431
2448
        }
2432
2449
        else {
2433
2450
                verbindung.clear();
2565
2582
        // but we try to extend stations of Player new_owner that may be the public player
2566
2583
        spieler_t *new_owner = extend_public_halt ? welt->get_spieler(1) : sp;
2567
2584
 
2568
 
        koord size = besch->get_groesse();
2569
2585
        koord offsets;
2570
2586
        halthandle_t halt;
2571
2587
        const char *msg = "Tile not empty.";
2783
2799
 
2784
2800
        hausbauer_t::baue(welt, halt->get_besitzer(), k-offsets, rotation, besch, &halt);
2785
2801
 
2786
 
        sint64 cost = welt->get_einstellungen()->cst_multiply_post*besch->get_level()*besch->get_b()*besch->get_h();
 
2802
        settings_t const& s      = welt->get_settings();
 
2803
        sint32     const  factor = besch->get_level() * besch->get_b() * besch->get_h();
 
2804
        sint64            cost   = s.cst_multiply_post * factor;
2787
2805
        if(sp!=halt->get_besitzer()  &&  halt->get_besitzer()==welt->get_spieler(1)) {
2788
2806
                // public stops are expensive!
2789
 
                cost -= ((welt->get_einstellungen()->maint_building*besch->get_level()*besch->get_b()*besch->get_h()*60)<<(welt->ticks_per_world_month_shift-18));
 
2807
                cost -= (s.maint_building * factor * 60);
2790
2808
        }
2791
2809
        sp->buche( cost, pos, COST_CONSTRUCTION);
2792
2810
        halt->recalc_station_type();
2935
2953
                halt = sp->halt_add(pos);
2936
2954
        }
2937
2955
        hausbauer_t::baue(welt, halt->get_besitzer(), bau_pos, layout, besch, &halt);
2938
 
        sint64 costs = welt->get_einstellungen()->cst_multiply_dock*besch->get_level();
 
2956
        sint64 costs = welt->get_settings().cst_multiply_dock * besch->get_level();
2939
2957
        if(sp!=halt->get_besitzer()) {
2940
2958
                // public stops are expensive!
2941
 
                costs -= ((welt->get_einstellungen()->maint_building*besch->get_level()*60)<<(welt->ticks_per_world_month_shift-18));
 
2959
                costs -= (welt->get_settings().maint_building * besch->get_level() * 60);
2942
2960
        }
2943
2961
        for(int i=0;  i<=len;  i++ ) {
2944
2962
                koord p=pos-dx*i;
2952
2970
        }
2953
2971
 
2954
2972
        if(neu) {
2955
 
                char* name = halt->create_name(pos, "Dock", welt->get_einstellungen()->get_name_language_id() );
 
2973
                char* const name = halt->create_name(pos, "Dock");
2956
2974
                halt->set_name( name );
2957
2975
                free(name);
2958
2976
        }
3134
3152
        halt->recalc_station_type();
3135
3153
 
3136
3154
        if(neu) {
3137
 
                char* name = halt->create_name(pos, type_name, welt->get_einstellungen()->get_name_language_id() );
3138
 
                halt->set_name( name );
 
3155
                char* const name = halt->create_name(pos, type_name);
 
3156
                halt->set_name(name);
3139
3157
                free(name);
3140
3158
        }
3141
3159
 
3144
3162
        cost -= old_cost/2;
3145
3163
        if(sp!=halt->get_besitzer()) {
3146
3164
                // public stops are expensive!
3147
 
                cost -= ((welt->get_einstellungen()->maint_building*besch->get_level()*besch->get_b()*besch->get_h()*60)<<(welt->ticks_per_world_month_shift-18));
 
3165
                cost -= (welt->get_settings().maint_building * besch->get_level() * besch->get_b() * besch->get_h() * 60);
3148
3166
        }
3149
3167
        sp->buche( cost, pos, COST_CONSTRUCTION);
3150
3168
        if(umgebung_t::station_coverage_show  &&  welt->get_zeiger()->get_pos().get_2d()==pos) {
3195
3213
                        destroy_win( magic_station_building_select );
3196
3214
                        create_win( new station_building_select_t(welt, hb), w_info, magic_station_building_select);
3197
3215
                        // we do not activate building yet; else uncomment the return statement
3198
 
//                      welt->get_zeiger()->set_area( koord( welt->get_einstellungen()->get_station_coverage()*2+1, welt->get_einstellungen()->get_station_coverage()*2+1 ), true );
3199
3216
                        return false;
3200
3217
                }
3201
3218
                else if(  rotation>=0  ) {
3203
3220
                        welt->get_zeiger()->set_area( koord( hb->get_b(rotation), hb->get_h(rotation) ), false );
3204
3221
                }
3205
3222
                else {
3206
 
                        welt->get_zeiger()->set_area( koord( welt->get_einstellungen()->get_station_coverage()*2+1, welt->get_einstellungen()->get_station_coverage()*2+1 ), true );
 
3223
                        goto set_area_cov;
3207
3224
                }
3208
3225
        }
3209
3226
        else {
3210
 
                welt->get_zeiger()->set_area( koord( welt->get_einstellungen()->get_station_coverage()*2+1, welt->get_einstellungen()->get_station_coverage()*2+1 ), true );
 
3227
set_area_cov:
 
3228
                uint16 const cov = welt->get_settings().get_station_coverage() * 2 + 1;
 
3229
                welt->get_zeiger()->set_area(koord(cov, cov), true);
3211
3230
        }
3212
3231
        return true;
3213
3232
}
3228
3247
 
3229
3248
 
3230
3249
 
3231
 
char const* wkz_station_t::get_tooltip(spieler_t* const sp)
 
3250
const char* wkz_station_t::get_tooltip(const spieler_t *sp) const
3232
3251
{
3233
 
        sint8                  dummy;
3234
 
        karte_t&               welt     = *sp->get_welt();
3235
 
        einstellungen_t const& settings = *welt.get_einstellungen();
3236
 
        haus_besch_t    const& besch    = *get_besch(dummy);
3237
 
        uint32                 level    = besch.get_level();
3238
 
        sint64                 price;
 
3252
        sint8               dummy;
 
3253
        karte_t&            welt     = *sp->get_welt();
 
3254
        settings_t   const& settings = welt.get_settings();
 
3255
        haus_besch_t const& besch    = *get_besch(dummy);
 
3256
        uint32              level    = besch.get_level();
 
3257
        sint64              price;
3239
3258
        switch (besch.get_utyp()) {
3240
3259
                case haus_besch_t::generic_stop:
3241
3260
                        switch (besch.get_extra()) {
3295
3314
                return "Das Feld gehoert\neinem anderen Spieler\n";
3296
3315
        }
3297
3316
 
3298
 
        sint8 rotation;
 
3317
        sint8 rotation = 0;
3299
3318
        const haus_besch_t *besch=get_besch(rotation);
3300
3319
        const char *msg = NULL;
3301
3320
        switch (besch->get_utyp()) {
3310
3329
                                msg = wkz_station_t::wkz_station_building_aux(welt, sp, true, pos, besch, rotation );
3311
3330
                        }
3312
3331
                        break;
3313
 
                case haus_besch_t::generic_stop:
 
3332
                case haus_besch_t::generic_stop: {
 
3333
                        settings_t const& s = welt->get_settings();
3314
3334
                        switch(besch->get_extra()) {
3315
3335
                                case road_wt:
3316
 
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, road_wt, welt->get_einstellungen()->cst_multiply_roadstop, "H");
 
3336
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, road_wt, s.cst_multiply_roadstop, "H");
3317
3337
                                        break;
3318
3338
                                case track_wt:
3319
3339
                                case monorail_wt:
3320
3340
                                case maglev_wt:
3321
3341
                                case narrowgauge_wt:
3322
3342
                                case tram_wt:
3323
 
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, (waytype_t)besch->get_extra(), welt->get_einstellungen()->cst_multiply_station, "BF");
 
3343
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, (waytype_t)besch->get_extra(), s.cst_multiply_station, "BF");
3324
3344
                                        break;
3325
3345
                                case water_wt:
3326
 
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, water_wt, welt->get_einstellungen()->cst_multiply_dock, "Dock");
 
3346
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, water_wt, s.cst_multiply_dock, "Dock");
3327
3347
                                        break;
3328
3348
                                case air_wt:
3329
 
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, air_wt, welt->get_einstellungen()->cst_multiply_airterminal, "Airport");
 
3349
                                        msg = wkz_station_t::wkz_station_aux(welt, sp, pos, besch, air_wt, s.cst_multiply_airterminal, "Airport");
3330
3350
                                        break;
3331
3351
                        }
 
3352
                        break;
 
3353
                }
3332
3354
 
3333
 
                        break;
3334
3355
                default:
3335
3356
                        dbg->fatal("wkz_station_t::work()","tool called for illegal besch \"%\"", default_param );
3336
3357
        }
3350
3371
        besch = NULL;
3351
3372
}
3352
3373
 
3353
 
const char *wkz_roadsign_t::get_tooltip(spieler_t *)
 
3374
 
 
3375
char const* wkz_roadsign_t::get_tooltip(spieler_t const*) const
3354
3376
{
3355
3377
        const roadsign_besch_t * besch = roadsign_t::find_besch(default_param);
3356
3378
        if(besch) {
3401
3423
                        return error;
3402
3424
                }
3403
3425
 
 
3426
                if(  besch->is_private_way()  &&  !ribi_t::ist_gerade(dir)  ) {
 
3427
                        // only on straight tiles ...
 
3428
                        return error;
 
3429
                }
 
3430
 
3404
3431
                const bool two_way = besch->is_single_way()  ||  besch->is_signal() ||  besch->is_pre_signal();
3405
3432
 
3406
3433
                if(!(besch->is_traffic_light() || two_way)  ||  (two_way  &&  ribi_t::is_twoway(dir))  ||  (besch->is_traffic_light()  &&  ribi_t::is_threeway(dir))) {
3413
3440
                                                return "Das Feld gehoert\neinem anderen Spieler\n";
3414
3441
                                        }
3415
3442
                                }
3416
 
                        } else {
 
3443
                        }
 
3444
                        else {
3417
3445
                                // if there is already a sign, we might need to inverse the direction
3418
3446
                                rs = gr->find<roadsign_t>();
3419
3447
                                if (rs) {
3507
3535
        vehikel_t* test_driver = vehikelbauer_t::baue(start, sp, NULL, &rs_besch);
3508
3536
        bool can_built;
3509
3537
        if( start != to ) {
3510
 
                can_built = verbindung.calc_route(sp->get_welt(), start, to, test_driver, 0);
 
3538
                can_built = verbindung.calc_route(sp->get_welt(), start, to, test_driver, 0, 0);
3511
3539
                // prevent building of many signals if start and to are adjacent
3512
3540
                // but the step start->to is now allowed
3513
3541
                if (can_built  &&  koord_distance(start, to)==1  &&  verbindung.get_count()>2) {
3578
3606
                                dummy_rs->set_dir(ribi); // calls calc_bild()
3579
3607
                                zeiger->set_after_bild(dummy_rs->get_after_bild());
3580
3608
                                zeiger->set_bild(dummy_rs->get_bild());
3581
 
                                dummy_rs->set_dir(ribi_t::keine);
 
3609
                                // as set_dir also modifies the ribi-mask of the way we have to reset it here...
 
3610
                                dummy_rs->set_dir(rs ? rs->get_dir() : (ribi_t::ribi)ribi_t::keine);
3582
3611
                                cost += rs ? (rs->get_besch()==besch ? 0  : besch->get_preis()+rs->get_besch()->get_preis()) : besch->get_preis();
3583
3612
                        }
3584
3613
                }
3843
3872
}
3844
3873
 
3845
3874
 
3846
 
char const* wkz_depot_t::get_tooltip(spieler_t* const sp)
 
3875
const char* wkz_depot_t::get_tooltip(const spieler_t *sp) const
3847
3876
{
3848
 
        karte_t&               welt     = *sp->get_welt();
3849
 
        einstellungen_t const& settings = *welt.get_einstellungen();
3850
 
        haus_besch_t    const& besch    = *hausbauer_t::find_tile(default_param, 0)->get_besch();
3851
 
        char            const* tip;
3852
 
        sint64                 price;
 
3877
        karte_t&            welt     = *sp->get_welt();
 
3878
        settings_t   const& settings = welt.get_settings();
 
3879
        haus_besch_t const& besch    = *hausbauer_t::find_tile(default_param, 0)->get_besch();
 
3880
        char         const* tip;
 
3881
        sint64              price;
3853
3882
        switch (besch.get_extra()) {
3854
3883
                case road_wt:        tip = "Build road depot";        price = settings.cst_depot_road; break;
3855
3884
                case track_wt:       tip = "Build train depot";       price = settings.cst_depot_rail; break;
3869
3898
{
3870
3899
        if(sp==welt->get_spieler(1)) {
3871
3900
                // no depots for player 1
3872
 
                return false;
 
3901
                return 0;
3873
3902
        }
3874
3903
 
3875
 
        const haus_besch_t *besch = hausbauer_t::find_tile(default_param,0)->get_besch();
 
3904
        haus_besch_t const* const besch = hausbauer_t::find_tile(default_param,0)->get_besch();
 
3905
        settings_t   const&       s     = welt->get_settings();
3876
3906
        switch(besch->get_extra()) {
3877
3907
                case road_wt:
3878
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, road_wt, welt->get_einstellungen()->cst_depot_road );
 
3908
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, road_wt, s.cst_depot_road);
3879
3909
                case track_wt:
3880
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, track_wt, welt->get_einstellungen()->cst_depot_rail );
 
3910
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, track_wt, s.cst_depot_rail);
3881
3911
                case monorail_wt:
3882
3912
                        {
3883
3913
                                // since it needs also a foundation, this is slightly more complex ...
3884
 
                                const char *err = wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, monorail_wt, welt->get_einstellungen()->cst_depot_rail );
 
3914
                                char const* const err = wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, monorail_wt, s.cst_depot_rail);
3885
3915
                                if(err==NULL) {
3886
3916
                                        grund_t *bd = welt->lookup_kartenboden(k.get_2d());
3887
3917
                                        if(hausbauer_t::elevated_foundation_besch  &&  k.z-bd->get_pos().z==1  &&  bd->ist_natur()) {
3891
3921
                                return err;
3892
3922
                        }
3893
3923
                case tram_wt:
3894
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, track_wt, welt->get_einstellungen()->cst_depot_rail );
 
3924
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, track_wt, s.cst_depot_rail);
3895
3925
                case water_wt:
3896
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, water_wt, welt->get_einstellungen()->cst_depot_ship );
 
3926
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, water_wt, s.cst_depot_ship);
3897
3927
                case air_wt:
3898
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, air_wt, welt->get_einstellungen()->cst_depot_air );
 
3928
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, air_wt, s.cst_depot_air);
3899
3929
                case maglev_wt:
3900
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, maglev_wt, welt->get_einstellungen()->cst_depot_rail );
 
3930
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, maglev_wt, s.cst_depot_rail);
3901
3931
                case narrowgauge_wt:
3902
 
                        return wkz_depot_t::wkz_depot_aux( welt, sp, k, besch, narrowgauge_wt, welt->get_einstellungen()->cst_depot_rail );
 
3932
                        return wkz_depot_t::wkz_depot_aux(welt, sp, k, besch, narrowgauge_wt, s.cst_depot_rail);
3903
3933
                default:
3904
3934
                        dbg->fatal("wkz_depot()","called with unknown besch %s",besch->get_name() );
3905
3935
                        return "";
3978
4008
                                        city->add_gebaeude_to_stadt(gb);
3979
4009
                                }
3980
4010
                        }
3981
 
                        spieler_t::accounting(sp, welt->get_einstellungen()->cst_multiply_remove_haus * besch->get_level() * size.x * size.y, pos.get_2d(), COST_CONSTRUCTION);
 
4011
                        spieler_t::accounting(sp, welt->get_settings().cst_multiply_remove_haus * besch->get_level() * size.x * size.y, pos.get_2d(), COST_CONSTRUCTION);
3982
4012
                        return NULL;
3983
4013
                }
3984
4014
        }
4067
4097
                if(anzahl>0) {
4068
4098
                        // at least one factory has been built
4069
4099
                        welt->change_world_position( k.get_2d(), 0, 0 );
4070
 
                        spieler_t::accounting(sp, anzahl*welt->get_einstellungen()->cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION );
 
4100
                        spieler_t::accounting(sp, anzahl * welt->get_settings().cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION);
4071
4101
 
4072
4102
                        // eventually adjust production
4073
4103
                        if(default_param  &&  strlen(default_param)>0) {
4075
4105
                        }
4076
4106
 
4077
4107
                        // crossconnect all?
4078
 
                        if(welt->get_einstellungen()->is_crossconnect_factories()) {
 
4108
                        if (welt->get_settings().is_crossconnect_factories()) {
4079
4109
                                const slist_tpl<fabrik_t *> & list = welt->get_fab_list();
4080
4110
                                slist_iterator_tpl <fabrik_t *> iter (list);
4081
4111
                                while( iter.next() ) {
4129
4159
        if(fab==NULL) {
4130
4160
                return "";
4131
4161
        }
4132
 
        int rotation = (default_param  &&  default_param[1]!='#') ? (default_param[1]-'0') % fab->get_haus()->get_all_layouts() : simrand(fab->get_haus()->get_all_layouts()-1);
4133
 
        koord size = fab->get_haus()->get_groesse(rotation);
4134
4162
 
4135
4163
// process ignore climates switch (not possible for chains!)
4136
4164
//      climate_bits cl = (default_param  &&  default_param[0]=='1') ? ALL_CLIMATES : fab->get_haus()->get_allowed_climate_bits();
4147
4175
                }
4148
4176
 
4149
4177
                // crossconnect all?
4150
 
                if(welt->get_einstellungen()->is_crossconnect_factories()) {
 
4178
                if (welt->get_settings().is_crossconnect_factories()) {
4151
4179
                        const slist_tpl<fabrik_t *> & list = welt->get_fab_list();
4152
4180
                        slist_iterator_tpl <fabrik_t *> iter (list);
4153
4181
                        while( iter.next() ) {
4155
4183
                        }
4156
4184
                }
4157
4185
                // ain't going to be cheap
4158
 
                spieler_t::accounting(sp, anzahl*welt->get_einstellungen()->cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION );
 
4186
                spieler_t::accounting(sp, anzahl * welt->get_settings().cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION);
4159
4187
                return NULL;
4160
4188
        }
4161
4189
        return "No suitable ground!";
4235
4263
                if(f) {
4236
4264
                        // at least one factory has been built
4237
4265
                        welt->change_world_position( k.get_2d(), 0, 0 );
4238
 
                        spieler_t::accounting(sp, welt->get_einstellungen()->cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION );
 
4266
                        spieler_t::accounting(sp, welt->get_settings().cst_multiply_found_industry, k.get_2d(), COST_CONSTRUCTION);
4239
4267
 
4240
4268
                        // eventually adjust production
4241
4269
                        if(default_param  &&  strlen(default_param)>0) {
4243
4271
                        }
4244
4272
 
4245
4273
                        // crossconnect all?
4246
 
                        if(welt->get_einstellungen()->is_crossconnect_factories()) {
 
4274
                        if (welt->get_settings().is_crossconnect_factories()) {
4247
4275
                                const slist_tpl<fabrik_t *> & list = welt->get_fab_list();
4248
4276
                                slist_iterator_tpl <fabrik_t *> iter (list);
4249
4277
                                while( iter.next() ) {
4296
4324
/* builds company headquarter
4297
4325
 * @author prissi
4298
4326
 */
4299
 
const haus_besch_t *wkz_headquarter_t::next_level( spieler_t *sp )
 
4327
const haus_besch_t *wkz_headquarter_t::next_level( const spieler_t *sp ) const
4300
4328
{
4301
4329
        return hausbauer_t::get_headquarter(sp->get_headquarter_level(), sp->get_welt()->get_timeline_year_month());
4302
4330
}
4303
4331
 
4304
 
const char *wkz_headquarter_t::get_tooltip( spieler_t *sp )
 
4332
const char* wkz_headquarter_t::get_tooltip(const spieler_t *sp) const
4305
4333
{
4306
 
        const haus_besch_t* besch = next_level(sp);
4307
 
        if(besch) {
4308
 
                return tooltip_with_price_maintenance( sp->get_welt(), sp->get_headquarter_level()==0 ? "build HQ" : "upgrade HQ", sp->get_welt()->get_einstellungen()->cst_multiply_headquarter*besch->get_level()*besch->get_b()*besch->get_h(), sp->get_welt()->get_einstellungen()->maint_building*besch->get_level()*besch->get_groesse().x*besch->get_groesse().y );
 
4334
        if (haus_besch_t const* const besch = next_level(sp)) {
 
4335
                settings_t  const& s      = sp->get_welt()->get_settings();
 
4336
                char const* const  tip    = sp->get_headquarter_level() == 0 ? "build HQ" : "upgrade HQ";
 
4337
                sint64      const  factor = (sint64)besch->get_level() * besch->get_b() * besch->get_h();
 
4338
                return tooltip_with_price_maintenance(sp->get_welt(), tip, factor * s.cst_multiply_headquarter, factor * s.maint_building);
4309
4339
        }
4310
4340
        return NULL;
4311
4341
}
4326
4356
const char *wkz_headquarter_t::work( karte_t *welt, spieler_t *sp, koord3d pos )
4327
4357
{
4328
4358
        bool ok=false;
 
4359
        bool built = false;
4329
4360
DBG_MESSAGE("wkz_headquarter()", "building headquarter at (%d,%d)", pos.x, pos.y);
4330
4361
 
4331
4362
        const haus_besch_t* besch = next_level(sp);
4336
4367
        }
4337
4368
 
4338
4369
        koord size = besch->get_groesse();
4339
 
        const sint64 cost = welt->get_einstellungen()->cst_multiply_headquarter * besch->get_level() * size.x * size.y;
 
4370
        sint64 const cost = welt->get_settings().cst_multiply_headquarter * besch->get_level() * size.x * size.y;
4340
4371
        if(  -cost > sp->get_finance_history_month(0,COST_CASH)  ) {
4341
4372
                return "Not enough money!";
4342
4373
        }
4347
4378
                if (!gr) {
4348
4379
                        return "";
4349
4380
                }
4350
 
                // remove previous one
 
4381
                gebaeude_t *hq = NULL;
 
4382
                // check for current head quarter
4351
4383
                koord previous = sp->get_headquarter_pos();
4352
4384
                if(previous!=koord::invalid) {
4353
 
                        grund_t *gr = welt->lookup_kartenboden(previous);
4354
 
                        gebaeude_t *prev_hq = gr->find<gebaeude_t>();
4355
 
                        sp->add_headquarter( prev_hq->get_tile()->get_besch()->get_extra(), koord::invalid );
4356
 
                        hausbauer_t::remove( welt, sp, prev_hq );
4357
 
                        // resize cursor
4358
 
                        init(welt, sp);
4359
 
                }
4360
 
 
4361
 
                int rotate = 0;
4362
 
 
4363
 
                if(welt->ist_platz_frei(pos.get_2d(), size.x, size.y, NULL, besch->get_allowed_climate_bits())) {
4364
 
                        ok = true;
4365
 
                }
4366
 
                if(!ok  &&  besch->get_all_layouts()>1  &&  size.y != size.x  &&  welt->ist_platz_frei(pos.get_2d(), size.y, size.x, NULL, besch->get_allowed_climate_bits())) {
4367
 
                        rotate = 1;
4368
 
                        ok = true;
4369
 
                }
4370
 
 
4371
 
                if(ok) {
4372
 
                        // then built is
4373
 
                        gebaeude_t *hq = hausbauer_t::baue(welt, sp, welt->lookup_kartenboden(pos.get_2d())->get_pos(), rotate, besch, NULL);
4374
 
                        stadt_t *city = welt->suche_naechste_stadt( pos.get_2d() );
4375
 
                        if(city) {
4376
 
                                city->add_gebaeude_to_stadt( hq );
4377
 
                        }
 
4385
                        grund_t *gr_hq = welt->lookup_kartenboden(previous);
 
4386
                        gebaeude_t *prev_hq = gr_hq->find<gebaeude_t>();
 
4387
                        // check if upgrade should be built at same place as current one
 
4388
                        gebaeude_t *gb = gr->find<gebaeude_t>();
 
4389
                        if (gb  &&  gb->get_besitzer()==sp  &&  prev_hq->get_tile()->get_besch()==gb->get_tile()->get_besch()) {
 
4390
                                const haus_besch_t* prev_besch = prev_hq->get_tile()->get_besch();
 
4391
                                // check if sizes fit
 
4392
                                uint8 prev_layout = prev_hq->get_tile()->get_layout();
 
4393
                                uint8 layout =  prev_layout % besch->get_all_layouts();
 
4394
                                koord size = besch->get_groesse(layout);
 
4395
                                if (prev_besch->get_groesse(prev_layout) == size) {
 
4396
                                        // check for same tile structure
 
4397
                                        ok = true;
 
4398
                                        for (sint16 x=0; x<size.x  &&  ok; x++) {
 
4399
                                                for (sint16 y=0; y<size.y  &&  ok; y++) {
 
4400
                                                        ok = (prev_besch->get_tile(prev_layout, x, y)==NULL)==(besch->get_tile(layout, x, y)==NULL);
 
4401
                                                }
 
4402
                                        }
 
4403
                                        hq = gb;
 
4404
                                        if (ok) {
 
4405
                                                // upgrade the tiles
 
4406
                                                koord pos_hq = pos.get_2d() - gb->get_tile()->get_offset();
 
4407
                                                for (sint16 x=0; x<size.x; x++) {
 
4408
                                                        for (sint16 y=0; y<size.y; y++) {
 
4409
                                                                if (const haus_tile_besch_t *tile = besch->get_tile(layout, x, y)) {
 
4410
                                                                        if (grund_t *gr = welt->lookup_kartenboden(pos_hq + koord(x,y))) {
 
4411
                                                                                if (gebaeude_t *gb = gr->find<gebaeude_t>()) {
 
4412
                                                                                        if (gb  &&  gb->get_besitzer()==sp  &&  prev_besch==gb->get_tile()->get_besch()) {
 
4413
                                                                                                gb->set_tile( tile );
 
4414
                                                                                        }
 
4415
                                                                                }
 
4416
                                                                        }
 
4417
                                                                }
 
4418
                                                        }
 
4419
                                                }
 
4420
                                                built = true;
 
4421
                                        }
 
4422
 
 
4423
                                }
 
4424
                        }
 
4425
                        // did not upgrade old one, need to remove it
 
4426
                        if (!built) {
 
4427
                                sp->add_headquarter( prev_hq->get_tile()->get_besch()->get_extra(), koord::invalid );
 
4428
                                // remove previous one
 
4429
                                hausbauer_t::remove( welt, sp, prev_hq );
 
4430
                                // resize cursor
 
4431
                                init(welt, sp);
 
4432
                        }
 
4433
                }
 
4434
 
 
4435
 
 
4436
                // build new one
 
4437
                if (!built) {
 
4438
                        int rotate = 0;
 
4439
 
 
4440
                        if(welt->ist_platz_frei(pos.get_2d(), size.x, size.y, NULL, besch->get_allowed_climate_bits())) {
 
4441
                                ok = true;
 
4442
                        }
 
4443
                        if(!ok  &&  besch->get_all_layouts()>1  &&  size.y != size.x  &&  welt->ist_platz_frei(pos.get_2d(), size.y, size.x, NULL, besch->get_allowed_climate_bits())) {
 
4444
                                rotate = 1;
 
4445
                                ok = true;
 
4446
                        }
 
4447
 
 
4448
                        if(ok) {
 
4449
                                // then built it
 
4450
                                hq = hausbauer_t::baue(welt, sp, welt->lookup_kartenboden(pos.get_2d())->get_pos(), rotate, besch, NULL);
 
4451
                                stadt_t *city = welt->suche_naechste_stadt( pos.get_2d() );
 
4452
                                if(city) {
 
4453
                                        city->add_gebaeude_to_stadt( hq );
 
4454
                                }
 
4455
                                built = true;
 
4456
                        }
 
4457
                        else {
 
4458
                                return "No suitable ground!";
 
4459
                        }
 
4460
                }
 
4461
 
 
4462
 
 
4463
                if (built) {
4378
4464
                        // sometimes those are not correct after rotation ...
4379
 
                        sp->add_headquarter( besch->get_extra()+1, hq->get_pos().get_2d()-hq->get_tile()->get_offset() );
 
4465
                        sp->add_headquarter(besch->get_extra()+1, hq->get_pos().get_2d()-hq->get_tile()->get_offset() );
4380
4466
                        sp->buche( cost, pos.get_2d(), COST_CONSTRUCTION);
4381
4467
                        // tell the world of it ...
4382
 
                        cbuffer_t buf(256);
 
4468
                        cbuffer_t buf;
4383
4469
                        buf.printf( translator::translate("%s s\nheadquarter now\nat (%i,%i)."), sp->get_name(), pos.x, pos.y );
4384
4470
                        welt->get_message()->add_message( buf, pos.get_2d(), message_t::ai, PLAYER_FLAG|sp->get_player_nr(), hq->get_tile()->get_hintergrund(0,0,0) );
4385
4471
                        // reset to query tool, since costly relocations should be avoided
4386
4472
                        if(is_local_execution()  &&  sp == welt->get_active_player()) {
4387
4473
                                welt->set_werkzeug( werkzeug_t::general_tool[WKZ_ABFRAGE], sp );
 
4474
                                welt->get_zeiger()->set_area( koord(1,1), false );
4388
4475
                        }
4389
4476
                        return NULL;
4390
4477
                }
4391
 
                else {
4392
 
                        return "No suitable ground!";
4393
 
                }
4394
4478
        }
4395
4479
        return "";
4396
4480
}
4397
4481
 
4398
4482
const char *wkz_lock_game_t::work( karte_t *welt, spieler_t *, koord3d )
4399
4483
{
4400
 
        if(  welt->get_spieler(1)->is_locked()  ||  !welt->get_einstellungen()->get_allow_player_change()  ) {
 
4484
        if (welt->get_spieler(1)->is_locked() || !welt->get_settings().get_allow_player_change()) {
4401
4485
                return "Only public player can lock games!";
4402
4486
        }
4403
4487
        welt->clear_player_password_hashes();
4404
4488
        if(  !welt->get_spieler(1)->is_locked() ) {
4405
4489
                return "In order to lock the game, you have to protect the public player by password!";
4406
4490
        }
4407
 
        welt->access_einstellungen()->set_allow_player_change( false );
 
4491
        welt->get_settings().set_allow_player_change(false);
4408
4492
        destroy_all_win( true );
4409
4493
        welt->switch_active_player( 0, true );
4410
4494
        welt->set_werkzeug( general_tool[WKZ_ABFRAGE], welt->get_spieler(0) );
4469
4553
        nw.y = min(start.y, end.y)+(wh.y/2);
4470
4554
 
4471
4555
        sint64 costs = baum_t::create_forest( welt, nw, wh );
4472
 
        spieler_t::accounting( sp, costs*welt->get_einstellungen()->cst_remove_tree, end.get_2d(), COST_CONSTRUCTION );
 
4556
        spieler_t::accounting(sp, costs * welt->get_settings().cst_remove_tree, end.get_2d(), COST_CONSTRUCTION);
4473
4557
 
4474
4558
        return NULL;
4475
4559
}
4686
4770
}
4687
4771
 
4688
4772
 
4689
 
 
4690
 
const char *wkz_daynight_level_t::get_tooltip(spieler_t *) {
 
4773
char const* wkz_daynight_level_t::get_tooltip(spieler_t const*) const
 
4774
{
4691
4775
        if(default_param  &&  strlen(default_param)>0) {
4692
4776
                if(default_param[0]=='+'  ||  default_param[0]=='-') {
4693
4777
                        sprintf(toolstr, "%s %s",
4736
4820
        return true;
4737
4821
}
4738
4822
 
4739
 
const char *wkz_make_stop_public_t::get_tooltip(spieler_t *sp) {
4740
 
        sprintf(toolstr, translator::translate("make stop public (or join with public stop next) costs %i per tile and level"), ((sp->get_welt()->get_einstellungen()->maint_building*60)<<(sp->get_welt()->ticks_per_world_month_shift-18))/100 );
 
4823
const char* wkz_make_stop_public_t::get_tooltip(const spieler_t *sp) const
 
4824
{
 
4825
        sint32 const cost = (sp->get_welt()->get_settings().maint_building * 60);
 
4826
        sprintf(toolstr, translator::translate("make stop public (or join with public stop next) costs %i per tile and level"), cost);
4741
4827
        return toolstr;
4742
4828
}
4743
4829
 
4751
4837
                        sint64 costs = halt->calc_maintenance();
4752
4838
                        // set only tooltip if it costs (us)
4753
4839
                        if(costs>0) {
4754
 
                                win_set_static_tooltip( tooltip_with_price("Building costs estimates", -((costs*60)<<(welt->ticks_per_world_month_shift-18)) ) );
4755
 
                        }
 
4840
                                win_set_static_tooltip( tooltip_with_price("Building costs estimates", costs*60 ) );
 
4841
                        }
 
4842
                }
 
4843
                else if(  const grund_t *gr = welt->lookup(p)  ) {
 
4844
                        if(  gr->get_typ()==grund_t::brueckenboden  ||  gr->get_grund_hang()!=hang_t::flach  ) {
 
4845
                                // not making ways public on bridges or slopes
 
4846
                                return "No suitable ground!";
 
4847
                        }
 
4848
                        weg_t *w = gr->get_weg_nr(0);
 
4849
                        // no need for action if already player(1) => XOR ...
 
4850
                        if(  !(w  &&  (  (w->get_besitzer()==sp)  ^  (sp==welt->get_spieler(1))  ))  ) {
 
4851
                                w = gr->get_weg_nr(1);
 
4852
                                if(  !(w  &&  (  (w->get_besitzer()==sp)  ^  (sp==welt->get_spieler(1))  ))  ) {
 
4853
                                        w = NULL;
 
4854
                                }
 
4855
                        }
 
4856
                        if(  w  ) {
 
4857
                                // no public way with signs
 
4858
                                if(  w->has_sign()  ) {
 
4859
                                        return "No suitable ground!";
 
4860
                                }
 
4861
                                sint64 costs = w->get_besch()->get_wartung();
 
4862
                                if(  gr->ist_im_tunnel()  ) {
 
4863
                                        tunnel_t *t = gr->find<tunnel_t>();
 
4864
                                        costs = t->get_besch()->get_wartung();
 
4865
                                }
 
4866
                                // set only tooltip if it costs (us)
 
4867
                                if(costs>0) {
 
4868
                                        win_set_static_tooltip( tooltip_with_price("Building costs estimates", -costs*60 ) );
 
4869
                                }
 
4870
 
 
4871
                        }
 
4872
                }
 
4873
                else {
 
4874
                        // boing ...
 
4875
                        return "";
4756
4876
                }
4757
4877
        }
4758
4878
        return NULL;
4761
4881
const char *wkz_make_stop_public_t::work( karte_t *welt, spieler_t *sp, koord3d p )
4762
4882
{
4763
4883
        const planquadrat_t *pl = welt->lookup(p.get_2d());
4764
 
        if(!pl  ||  !pl->get_halt().is_bound()) {
4765
 
                return "No stop here!";
 
4884
        if(  !pl  ||  !pl->get_halt().is_bound()  ||  pl->get_halt()->get_besitzer()==welt->get_spieler(1)  ) {
 
4885
                weg_t *w = NULL;
 
4886
                //convert a way here, if there is no halt or already public halt
 
4887
                if(  const grund_t *gr = welt->lookup(p)  ) {
 
4888
                        if(  gr->get_typ()==grund_t::brueckenboden  ||  gr->get_grund_hang()!=hang_t::flach  ) {
 
4889
                                // not making ways public on bridges or slopes
 
4890
                                return "No suitable ground!";
 
4891
                        }
 
4892
                        w = gr->get_weg_nr(0);
 
4893
                        // no need for action if already player(1) => XOR ...
 
4894
                        if(  !(w  &&  (  (w->get_besitzer()==sp)  ^  (sp==welt->get_spieler(1))  ))  ) {
 
4895
                                w = gr->get_weg_nr(1);
 
4896
                                if(  !(w  &&  (  (w->get_besitzer()==sp)  ^  (sp==welt->get_spieler(1))  ))  ) {
 
4897
                                        w = NULL;
 
4898
                                }
 
4899
                        }
 
4900
                        if(  w  ) {
 
4901
                                // no public way with signs
 
4902
                                if(  w->has_sign()  ) {
 
4903
                                        return "No suitable ground!";
 
4904
                                }
 
4905
                                // change maintenance and ownership
 
4906
                                sint64 costs = w->get_besch()->get_wartung();
 
4907
                                if(  gr->ist_im_tunnel()  ) {
 
4908
                                        tunnel_t *t = gr->find<tunnel_t>();
 
4909
                                        costs = t->get_besch()->get_wartung();
 
4910
                                        t->set_besitzer( welt->get_spieler(1) );
 
4911
                                }
 
4912
                                spieler_t::add_maintenance( w->get_besitzer(), -costs );
 
4913
                                spieler_t::accounting( w->get_besitzer(), -costs*60, gr->get_pos().get_2d(), COST_CONSTRUCTION);
 
4914
                                w->set_besitzer( welt->get_spieler(1) );
 
4915
                                w->set_flag(ding_t::dirty);
 
4916
                                spieler_t::add_maintenance( welt->get_spieler(1), costs );
 
4917
                                // now search for wayobjects
 
4918
                                for(  uint8 i=1;  i<gr->get_top();  i++  ) {
 
4919
                                        if(  wayobj_t *wo = ding_cast<wayobj_t>(gr->obj_bei(i))  ) {
 
4920
                                                costs = wo->get_besch()->get_wartung();
 
4921
                                                spieler_t::add_maintenance( wo->get_besitzer(), -costs );
 
4922
                                                spieler_t::accounting( wo->get_besitzer(), -costs*60, gr->get_pos().get_2d(), COST_CONSTRUCTION);
 
4923
                                                wo->set_besitzer( welt->get_spieler(1) );
 
4924
                                                wo->set_flag(ding_t::dirty);
 
4925
                                                spieler_t::add_maintenance( welt->get_spieler(1), costs );
 
4926
                                        }
 
4927
                                }
 
4928
                                // and add message
 
4929
                                if(  sp->get_player_nr()!=1  &&  umgebung_t::networkmode  ) {
 
4930
                                        cbuffer_t buf;
 
4931
                                        buf.printf( translator::translate("(%s) now public way."), w->get_pos().get_str() );
 
4932
                                        welt->get_message()->add_message( buf, w->get_pos().get_2d(), message_t::ai, PLAYER_FLAG|sp->get_player_nr(), IMG_LEER );
 
4933
                                }
 
4934
                        }
 
4935
                }
 
4936
                if(  w==NULL  ) {
 
4937
                        return "No stop here!";
 
4938
                }
4766
4939
        }
4767
4940
        else {
4768
4941
                halthandle_t halt = pl->get_halt();
4910
5083
        return NULL;
4911
5084
}
4912
5085
 
4913
 
const char *wkz_show_underground_t::get_tooltip(spieler_t *)
 
5086
 
 
5087
char const* wkz_show_underground_t::get_tooltip(spieler_t const*) const
4914
5088
{
4915
 
        // default default-param = U for backward compatibility
 
5089
        // no default-param == U for backward compatibility
4916
5090
        if(  default_param == NULL  ) {
4917
 
                default_param = strdup("U");
 
5091
                return translator::translate("underground mode");
4918
5092
        }
4919
5093
        // now check the default parameter
4920
5094
        switch(default_param[0]) {
4937
5111
        }
4938
5112
}
4939
5113
 
4940
 
bool wkz_show_underground_t::is_selected(karte_t *) const
 
5114
bool wkz_show_underground_t::is_selected(const karte_t *) const
4941
5115
{
4942
5116
        // default default-param = U for backward compatibility
4943
5117
        if(  default_param == NULL  ) {
4978
5152
}
4979
5153
 
4980
5154
 
 
5155
bool wkz_increase_industry_t::init( karte_t *welt, spieler_t * )
 
5156
{
 
5157
        fabrikbauer_t::increase_industry_density( welt, false );
 
5158
        return false;
 
5159
}
 
5160
 
4981
5161
 
4982
5162
/************************* internal tools, only need for networking ***************/
4983
5163
 
5502
5682
                case 'a': // activate/deactivate AI
5503
5683
                        if(welt->get_spieler(id)  &&  welt->get_spieler(id)->get_ai_id()!=spieler_t::HUMAN) {
5504
5684
                                welt->get_spieler(id)->set_active(state);
5505
 
                                welt->access_einstellungen()->set_player_active( id, welt->get_spieler(id)->is_active() );
 
5685
                                welt->get_settings().set_player_active(id, welt->get_spieler(id)->is_active());
5506
5686
                        }
5507
5687
                        break;
5508
5688
                case 'c': // change player color
5513
5693
                        }
5514
5694
                        break;
5515
5695
                case 'f': // activate/deactivate freeplay
5516
 
                        if(  welt->get_spieler(1)->is_locked()  ||  !welt->get_einstellungen()->get_allow_player_change()  ) {
 
5696
                        if (welt->get_spieler(1)->is_locked() || !welt->get_settings().get_allow_player_change()) {
5517
5697
                                dbg->error( "wkz_change_player_t::init()", "Only public player can enable freeplay!" );
5518
5698
                        }
5519
5699
                        else {
5520
 
                                welt->access_einstellungen()->set_freeplay( !welt->get_einstellungen()->is_freeplay() );
 
5700
                                welt->get_settings().set_freeplay(!welt->get_settings().is_freeplay());
5521
5701
                        }
5522
5702
                        break;
5523
5703
        }
5545
5725
        pos.z = (sint8)z;
5546
5726
        if(  grund_t *gr = welt->lookup(pos)  ) {
5547
5727
                if( roadsign_t *rs = gr->find<roadsign_t>()  ) {
5548
 
                        if(  rs->get_besch()->is_traffic_light()  &&  spieler_t::check_owner(rs->get_besitzer(),sp)  ) {
5549
 
                                if(  ns  ) {
 
5728
                        if(  (  rs->get_besch()->is_traffic_light()  ||  rs->get_besch()->is_private_way()  )  &&  spieler_t::check_owner(rs->get_besitzer(),sp)  ) {
 
5729
                                if(  ns == 1  ) {
5550
5730
                                        rs->set_ticks_ns( ticks );
5551
5731
                                }
5552
 
                                else {
 
5732
                                else if(  ns == 0  ) {
5553
5733
                                        rs->set_ticks_ow( ticks );
5554
5734
                                }
 
5735
                                else if(  ns == 2  ) {
 
5736
                                        rs->set_ticks_offset( ticks );
 
5737
                                }
5555
5738
                                // update the window
5556
 
                                trafficlight_info_t* trafficlight_win = (trafficlight_info_t*)win_get_magic((long)rs);
5557
 
                                if (trafficlight_win) {
5558
 
                                        trafficlight_win->update_data();
 
5739
                                if(  rs->get_besch()->is_traffic_light()  ) {
 
5740
                                        trafficlight_info_t* trafficlight_win = (trafficlight_info_t*)win_get_magic((long)rs);
 
5741
                                        if (trafficlight_win) {
 
5742
                                                trafficlight_win->update_data();
 
5743
                                        }
 
5744
                                }
 
5745
                                else {
 
5746
                                        privatesign_info_t* trafficlight_win = (privatesign_info_t*)win_get_magic((long)rs);
 
5747
                                        if (trafficlight_win) {
 
5748
                                                trafficlight_win->update_data();
 
5749
                                        }
5559
5750
                                }
5560
5751
                        }
5561
5752
                }
5563
5754
        return false;
5564
5755
}
5565
5756
 
 
5757
 
5566
5758
/**
5567
5759
 * change city:
5568
5760
 * g[x],[y],[allow_city_growth]
5593
5785
 
5594
5786
 
5595
5787
 
5596
 
/* Handles all action of lines. Needs a default param:
5597
 
 * [object='c|h|l|m|t'][id|pos],[name]
5598
 
 * c=convoi, h=halt, l=line,  m=marker, t=town, p=player
5599
 
 * in case of marker, id is a pos3d string
 
5788
/* Handles renaming of ingame entities. Needs a default param:
 
5789
 * [object='c|h|l|m|t|p|f'][id|pos],[name]
 
5790
 * c=convoi, h=halt, l=line,  m=marker, t=town, p=player, f=factory
 
5791
 * in case of marker / factory, id is a pos3d string
5600
5792
 */
5601
5793
bool wkz_rename_t::init(karte_t* const welt, spieler_t *sp)
5602
5794
{
5617
5809
                        }
5618
5810
                        break;
5619
5811
                case 'm':
 
5812
                case 'f':
5620
5813
                        if(  3!=sscanf( p, "%hi,%hi,%hi", &pos.x, &pos.y, &id )  ) {
5621
 
                                dbg->error( "wkz_rename_t::init", "no position given for marker! (%s)", default_param );
 
5814
                                dbg->error( "wkz_rename_t::init", "no position given for marker/factory! (%s)", default_param );
5622
5815
                                return false;
5623
5816
                        }
5624
5817
                        while(  *p>0  &&  *p++!=','  ) {
5697
5890
                                welt->get_spieler(id)->set_name(p);
5698
5891
                                return false;
5699
5892
                        }
 
5893
 
 
5894
                case 'f':
 
5895
                {
 
5896
                        if(  grund_t *gr = welt->lookup(pos)  ) {
 
5897
                                if(  gebaeude_t* gb = gr->find<gebaeude_t>()  ) {
 
5898
                                        if (  fabrik_t *fab = gb->get_fabrik()  ) {
 
5899
                                                fab->set_name(p);
 
5900
                                                return false;
 
5901
                                        }
 
5902
                                }
 
5903
                        }
 
5904
                }
5700
5905
        }
5701
5906
        // we are only getting here, if we could not process this request
5702
5907
        dbg->error( "wkz_rename_t::init", "could not perform (%s)", default_param );
5711
5916
        if(  *default_param  ) {
5712
5917
                if(  sp  ) {
5713
5918
                        if(  umgebung_t::add_player_name_to_message  ) {
5714
 
                                cbuffer_t buffer(1024);
 
5919
                                cbuffer_t buffer;
5715
5920
                                buffer.printf("[%s]\n%s", sp->get_name(), default_param);
5716
5921
                                welt->get_message()->add_message( buffer, koord::invalid, message_t::chat, PLAYER_FLAG|sp->get_player_nr(), IMG_LEER );
5717
5922
                        }