diff --git Makefile Makefile index c4dd72b052..c451f6159d 100644 --- Makefile +++ Makefile @@ -442,6 +442,7 @@ SOURCES += obj/leitung2.cc SOURCES += obj/pillar.cc SOURCES += obj/roadsign.cc SOURCES += obj/signal.cc +SOURCES += obj/obj.cc SOURCES += obj/tunnel.cc SOURCES += obj/wayobj.cc SOURCES += obj/wolke.cc @@ -500,7 +501,6 @@ SOURCES += simmain.cc SOURCES += simmem.cc SOURCES += simmenu.cc SOURCES += simmesg.cc -SOURCES += simobj.cc SOURCES += simplan.cc SOURCES += simskin.cc SOURCES += simsound.cc diff --git Simutrans-Main.vcxitems Simutrans-Main.vcxitems index d720f163bb..9378890171 100644 --- Simutrans-Main.vcxitems +++ Simutrans-Main.vcxitems @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -34,7 +34,6 @@ - @@ -253,6 +252,7 @@ + @@ -353,7 +353,6 @@ - @@ -605,6 +604,7 @@ + @@ -695,4 +695,4 @@ - \ No newline at end of file + diff --git bauer/wegbauer.cc bauer/wegbauer.cc index 1550fb6aaf..a9084fb03d 100644 --- bauer/wegbauer.cc +++ bauer/wegbauer.cc @@ -2256,7 +2256,7 @@ void way_builder_t::build_tunnel_and_bridges() if(start->get_grund_hang()==slope_t::flat || start->get_grund_hang()==slope_type(zv*(-1)) || start->get_grund_hang()==2*slope_type(zv*(-1))) { // code derived from simtool - + sint8 bridge_height = 0; const char *error; diff --git boden/wege/weg.cc boden/wege/weg.cc index a080e6659e..c2c7336f08 100644 --- boden/wege/weg.cc +++ boden/wege/weg.cc @@ -20,7 +20,7 @@ #include "../../simworld.h" #include "../../display/simimg.h" #include "../../simhalt.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../player/simplay.h" #include "../../obj/roadsign.h" #include "../../obj/signal.h" diff --git boden/wege/weg.h boden/wege/weg.h index 94f453650d..070badfa67 100644 --- boden/wege/weg.h +++ boden/wege/weg.h @@ -9,7 +9,7 @@ #include "../../display/simimg.h" #include "../../simtypes.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../descriptor/way_desc.h" #include "../../dataobj/koord3d.h" diff --git dataobj/objlist.cc dataobj/objlist.cc index 1c2dc520b9..2b37a38c5d 100644 --- dataobj/objlist.cc +++ dataobj/objlist.cc @@ -967,7 +967,7 @@ void objlist_t::rdwr(loadsave_t *file, koord3d current_pos) case obj_t::old_gebaeudefundament: { dummy_obj_t d(file); break; } // only factories can smoke; but then, the smoker is reinstated after loading - case obj_t::raucher: { raucher_t r(file); break; } + case obj_t::old_raucher: { raucher_t r(file); break; } // wolke is not saved any more case obj_t::sync_wolke: { wolke_t w(file); break; } @@ -1006,7 +1006,7 @@ void objlist_t::rdwr(loadsave_t *file, koord3d current_pos) obj_t *new_obj = bei((uint8)i); if(new_obj->get_typ()==obj_t::way // do not save smoke - || new_obj->get_typ()==obj_t::raucher + || new_obj->get_typ()==obj_t::old_raucher || new_obj->get_typ()==obj_t::sync_wolke || new_obj->get_typ()==obj_t::async_wolke // fields will be built by factory diff --git dataobj/objlist.h dataobj/objlist.h index 1e7c372cda..3d9df1f360 100644 --- dataobj/objlist.h +++ dataobj/objlist.h @@ -8,7 +8,7 @@ #include "../simtypes.h" -#include "../simobj.h" +#include "../obj/obj.h" class objlist_t { diff --git descriptor/reader/groundobj_reader.cc descriptor/reader/groundobj_reader.cc index 04ad6d1087..a6ff3ff4a4 100644 --- descriptor/reader/groundobj_reader.cc +++ descriptor/reader/groundobj_reader.cc @@ -6,7 +6,7 @@ #include #include "../../simunits.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../simdebug.h" #include "../../obj/groundobj.h" #include "../../vehicle/movingobj.h" diff --git descriptor/reader/skin_reader.cc descriptor/reader/skin_reader.cc index 4f5c198a71..ee3587f344 100644 --- descriptor/reader/skin_reader.cc +++ descriptor/reader/skin_reader.cc @@ -5,7 +5,7 @@ #include -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../simdebug.h" #include "../../simskin.h" diff --git descriptor/reader/tree_reader.cc descriptor/reader/tree_reader.cc index ec5d661e19..a622fb2bf4 100644 --- descriptor/reader/tree_reader.cc +++ descriptor/reader/tree_reader.cc @@ -5,7 +5,7 @@ #include -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../simdebug.h" #include "../../obj/baum.h" diff --git descriptor/writer/root_writer.cc descriptor/writer/root_writer.cc index e1205c8f34..2e17334e49 100644 --- descriptor/writer/root_writer.cc +++ descriptor/writer/root_writer.cc @@ -20,7 +20,7 @@ void root_writer_t::write_header(FILE* fp) { fprintf(fp, "Simutrans object file\n" - "Compiled with SimObjects " COMPILER_VERSION "\n\x1A" + "Compiled with objects " COMPILER_VERSION "\n\x1A" ); uint32 l = endian(uint32(COMPILER_VERSION_CODE)); diff --git display/simview.cc display/simview.cc index 6eb4cabc05..5ad98d163d 100644 --- display/simview.cc +++ display/simview.cc @@ -12,7 +12,7 @@ #include "../simticker.h" #include "../simdebug.h" -#include "../simobj.h" +#include "../obj/obj.h" #include "../simconst.h" #include "../simplan.h" #include "../simmenu.h" diff --git gui/components/gui_world_view_t.cc gui/components/gui_world_view_t.cc index 0dd9548d54..98d8baefd6 100644 --- gui/components/gui_world_view_t.cc +++ gui/components/gui_world_view_t.cc @@ -8,7 +8,7 @@ #include "gui_world_view_t.h" #include "../../simworld.h" #include "../../display/viewport.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../display/simgraph.h" #include "../../simcolor.h" #include "../../vehicle/simvehicle.h" diff --git gui/curiositylist_frame_t.cc gui/curiositylist_frame_t.cc index 00cbd0dcc1..7b2cec3cb1 100644 --- gui/curiositylist_frame_t.cc +++ gui/curiositylist_frame_t.cc @@ -109,7 +109,7 @@ bool curiositylist_frame_t::action_triggered( gui_action_creator_t *comp,value_t scrolly.sort(0); } else if(comp == &filterowner) { - if( filter_by_owner.pressed ) { + if( filter_by_owner.pressed ) { fill_list(); } } diff --git gui/factorylist_frame_t.cc gui/factorylist_frame_t.cc index 89358df64c..f9327cf89a 100644 --- gui/factorylist_frame_t.cc +++ gui/factorylist_frame_t.cc @@ -86,7 +86,7 @@ bool factorylist_frame_t::action_triggered( gui_action_creator_t *comp,value_t / scrolly.sort(0); } else if(comp == &filterowner) { - if( filter_by_owner.pressed ) { + if( filter_by_owner.pressed ) { fill_list(); } } diff --git gui/message_option_t.cc gui/message_option_t.cc index 5d8519ae48..eb13c7d5df 100644 --- gui/message_option_t.cc +++ gui/message_option_t.cc @@ -39,7 +39,7 @@ message_option_t::message_option_t() : welt->get_message()->get_message_flags( &ticker_msg, &window_msg, &auto_msg, &ignore_msg ); for( int i=0; i>i)&1)==0; buttons[i*4].add_listener(this); @@ -49,7 +49,7 @@ message_option_t::message_option_t() : while( *p < ' ' && *p ) { p++; } - for( int j=0; *p>=' '; p++ ) { + for( int j=0; *p>=' '; p++ ) { if( j < MAX_MESSAGE_OPTION_TEXTLEN-1 ) { option_texts[i][j++] = *p; option_texts[i][j] = 0; diff --git gui/message_option_t.h gui/message_option_t.h index 30d869f560..39d6cc3df4 100644 --- gui/message_option_t.h +++ gui/message_option_t.h @@ -6,6 +6,7 @@ #ifndef GUI_MESSAGE_OPTION_T_H #define GUI_MESSAGE_OPTION_T_H + #include "../simmesg.h" #include "simwin.h" diff --git gui/obj_info.h gui/obj_info.h index 69bf5352d6..c2686430a4 100644 --- gui/obj_info.h +++ gui/obj_info.h @@ -8,7 +8,7 @@ #include "../simdebug.h" -#include "../simobj.h" +#include "../obj/obj.h" #include "base_info.h" #include "components/gui_obj_view_t.h" diff --git nettools/Nettool.vcxproj nettools/Nettool.vcxproj index 439f289d1e..abed974557 100644 --- nettools/Nettool.vcxproj +++ nettools/Nettool.vcxproj @@ -105,7 +105,7 @@ - + @@ -166,4 +166,4 @@ - \ No newline at end of file + diff --git obj/baum.cc obj/baum.cc index 7b005dd8d7..0e208fad12 100644 --- obj/baum.cc +++ obj/baum.cc @@ -9,7 +9,7 @@ #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" #include "../player/simplay.h" #include "../simtypes.h" @@ -18,7 +18,7 @@ #include "../descriptor/tree_desc.h" -#include "../obj/groundobj.h" +#include "groundobj.h" #include "../utils/cbuffer_t.h" #include "../utils/simrandom.h" diff --git obj/bruecke.cc obj/bruecke.cc index a6bffecd6f..70b8575e83 100644 --- obj/bruecke.cc +++ obj/bruecke.cc @@ -5,7 +5,7 @@ #include "../simworld.h" #include "../simtypes.h" -#include "../simobj.h" +#include "obj.h" #include "../boden/grund.h" #include "../player/simplay.h" #include "../display/simimg.h" diff --git obj/bruecke.h obj/bruecke.h index 7f1fda0260..4981fef0bb 100644 --- obj/bruecke.h +++ obj/bruecke.h @@ -10,7 +10,7 @@ class karte_t; #include "../descriptor/bridge_desc.h" -#include "../simobj.h" +#include "obj.h" /** * Bridges (visible) diff --git obj/crossing.cc obj/crossing.cc index 32255f795b..0d160fd1f0 100644 --- obj/crossing.cc +++ obj/crossing.cc @@ -7,7 +7,7 @@ #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" #include "../descriptor/crossing_desc.h" diff --git obj/dummy.h obj/dummy.h index c4750ef4fe..f3fea457ee 100644 --- obj/dummy.h +++ obj/dummy.h @@ -7,7 +7,7 @@ #define OBJ_DUMMY_H -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" diff --git obj/field.cc obj/field.cc index 507901d63c..0695505d65 100644 --- obj/field.cc +++ obj/field.cc @@ -6,7 +6,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../simfab.h" #include "../display/simimg.h" diff --git obj/field.h obj/field.h index 76628467f4..c3aa02bd52 100644 --- obj/field.h +++ obj/field.h @@ -7,7 +7,7 @@ #define OBJ_FIELD_H -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" diff --git obj/gebaeude.cc obj/gebaeude.cc index c579c12767..6298dfb309 100644 --- obj/gebaeude.cc +++ obj/gebaeude.cc @@ -16,7 +16,7 @@ static pthread_mutex_t add_to_city_mutex = PTHREAD_MUTEX_INITIALIZER; #include "../bauer/hausbauer.h" #include "../gui/headquarter_info.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../simfab.h" #include "../display/simimg.h" #include "../display/simgraph.h" diff --git obj/gebaeude.h obj/gebaeude.h index dd2ce9d6b8..5fb053b21e 100644 --- obj/gebaeude.h +++ obj/gebaeude.h @@ -8,7 +8,7 @@ #include "../ifc/sync_steppable.h" -#include "../simobj.h" +#include "obj.h" #include "../simcolor.h" class building_tile_desc_t; @@ -147,7 +147,7 @@ public: const building_tile_desc_t *get_tile() const { return tile; } bool is_within_players_network(const player_t* player) const; - + void show_info() OVERRIDE; void cleanup(player_t *player) OVERRIDE; diff --git obj/groundobj.cc obj/groundobj.cc index 237a69fa29..1ee9c9bae1 100644 --- obj/groundobj.cc +++ obj/groundobj.cc @@ -5,7 +5,7 @@ #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" #include "../player/simplay.h" #include "../simtypes.h" diff --git obj/label.cc obj/label.cc index d4a169a696..9bd8017e39 100644 --- obj/label.cc +++ obj/label.cc @@ -7,7 +7,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" #include "../simskin.h" #include "../gui/simwin.h" diff --git obj/label.h obj/label.h index 16c7f6d933..8d7b353005 100644 --- obj/label.h +++ obj/label.h @@ -7,7 +7,7 @@ #define OBJ_LABEL_H -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" diff --git obj/leitung2.cc obj/leitung2.cc index 5a7452e27f..0ca0a62730 100644 --- obj/leitung2.cc +++ obj/leitung2.cc @@ -15,7 +15,7 @@ static pthread_mutex_t senke_list_mutex = PTHREAD_MUTEX_INITIALIZER; #include "leitung2.h" #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../player/simplay.h" #include "../display/simimg.h" #include "../simfab.h" diff --git obj/leitung2.h obj/leitung2.h index a17326ba04..c294178919 100644 --- obj/leitung2.h +++ obj/leitung2.h @@ -10,7 +10,7 @@ #include "../ifc/sync_steppable.h" #include "../dataobj/koord3d.h" #include "../dataobj/ribi.h" -#include "../simobj.h" +#include "obj.h" #include "../tpl/slist_tpl.h" // bitshift for converting internal power values to MW for display diff --git simobj.cc obj/obj.cc similarity index 82% rename from simobj.cc rename to obj/obj.cc index 89ee1b94ae..53efbd62dd 100644 --- simobj.cc +++ obj/obj.cc @@ -3,33 +3,33 @@ * (see LICENSE.txt) */ -#include -#include -#include - -#include "simdebug.h" -#include "display/simimg.h" -#include "simcolor.h" -#include "display/simgraph.h" -#include "display/viewport.h" -#include "gui/simwin.h" -#include "player/simplay.h" -#include "simobj.h" -#include "simworld.h" -#include "obj/baum.h" -#include "vehicle/simvehicle.h" -#include "dataobj/translator.h" -#include "dataobj/loadsave.h" -#include "boden/grund.h" -#include "gui/obj_info.h" -#include "utils/cbuffer_t.h" -#include "utils/simstring.h" - - -/** - * Pointer to the world of this thing. Static to conserve space. - * Change to instance variable once more than one world is available. - */ +#include "obj.h" + +#include "baum.h" + +#include "../boden/grund.h" +#include "../dataobj/loadsave.h" +#include "../dataobj/translator.h" +#include "../display/simimg.h" +#include "../display/simgraph.h" +#include "../display/viewport.h" +#include "../gui/obj_info.h" +#include "../gui/simwin.h" +#include "../player/simplay.h" +#include "../simcolor.h" +#include "../simdebug.h" +#include "../simworld.h" +#include "../utils/cbuffer_t.h" +#include "../utils/simstring.h" +#include "../vehicle/simvehicle.h" + +#include +#include +#include + + +/// Pointer to the world of this thing. Static to conserve space. +/// Change to instance variable once more than one world is available. karte_ptr_t obj_t::welt; bool obj_t::show_owner = false; @@ -54,6 +54,7 @@ obj_t::obj_t() init(); } + obj_t::obj_t(koord3d pos) { init(); @@ -61,12 +62,11 @@ obj_t::obj_t(koord3d pos) } -// removes an object and tries to delete it also from the corresponding objlist obj_t::~obj_t() { destroy_win((ptrdiff_t)this); - if(flags¬_on_map || !welt->is_within_limits(pos.get_2d())) { + if(get_flag(obj_t::not_on_map) || !welt->is_within_limits(pos.get_2d())) { return; } @@ -74,9 +74,9 @@ obj_t::~obj_t() grund_t *gr = welt->lookup(pos); if(!gr || !gr->obj_remove(this)) { // not found? => try harder at all map locations - dbg->warning("obj_t::~obj_t()","couldn't remove %p from %d,%d,%d",this, pos.x , pos.y, pos.z); + dbg->warning("obj_t::~obj_t()","couldn't remove %p from %d,%d,%d", this, pos.x, pos.y, pos.z); - // first: try different height ... + // first: try different height gr = welt->access(pos.get_2d())->get_boden_von_obj(this); if(gr && gr->obj_remove(this)) { dbg->warning("obj_t::~obj_t()", @@ -106,14 +106,9 @@ obj_t::~obj_t() } -/** - * sets owner of object - */ void obj_t::set_owner(player_t *player) { - int i = welt->sp2num(player); - assert(i>=0); - owner_n = (uint8)i; + owner_n = welt->sp2num(player); } @@ -123,21 +118,23 @@ player_t *obj_t::get_owner() const } -/* the only general info we can give is the name - * we want to format it nicely, - * with two linebreaks at the end => thus the little extra effort - */ -void obj_t::info(cbuffer_t & buf) const +void obj_t::info(cbuffer_t &buf) const { + // The only general info we can give is the name. + // We want to format it nicely, with two linebreaks at the end => thus the little extra effort + char translation[256]; - char const* const owner = + char const *const owner = owner_n == 1 ? translator::translate("Eigenbesitz\n") : owner_n == PLAYER_UNOWNED ? translator::translate("Kein Besitzer\n") : get_owner()->get_name(); + tstrncpy(translation, owner, lengthof(translation)); + // remove trailing linebreaks etc. rtrim(translation); buf.append( translation ); + // only append linebreaks if not empty if( buf.len()>0 ) { buf.append( "\n\n" ); @@ -150,11 +147,13 @@ void obj_t::show_info() create_win( new obj_infowin_t(this), w_info, (ptrdiff_t)this); } -bool obj_t::has_managed_lifecycle() const { + +bool obj_t::has_managed_lifecycle() const +{ return false; } -// returns NULL, if removal is allowed + const char *obj_t::is_deletable(const player_t *player) { if(owner_n==PLAYER_UNOWNED || welt->get_player(owner_n) == player || welt->get_public_player() == player) { @@ -185,14 +184,13 @@ void obj_t::rdwr(loadsave_t *file) } -/** - * draw the object - * the dirty-flag is reset from objlist_t::display_obj_fg, or objlist_t::display_overlay when multithreaded - */ void obj_t::display(int xpos, int ypos CLIP_NUM_DEF) const { + // the dirty-flag is reset from objlist_t::display_obj_fg, or objlist_t::display_overlay when multithreaded + image_id image = get_image(); image_id const outline_image = get_outline_image(); + if( image!=IMG_EMPTY || outline_image!=IMG_EMPTY ) { const int raster_width = get_current_tile_raster_width(); const bool is_dirty = get_flag(obj_t::dirty); @@ -243,7 +241,6 @@ void obj_t::display(int xpos, int ypos CLIP_NUM_DEF) const } -// called during map rotation void obj_t::rotate90() { // most basic: rotate coordinate @@ -291,10 +288,6 @@ void obj_t::display_after(int xpos, int ypos, bool) const } -/* - * when a vehicle moves or a cloud moves, it needs to mark the old spot as dirty (to copy to screen) - * sometimes they have an extra offset, this is the yoff parameter - */ void obj_t::mark_image_dirty(image_id image, sint16 yoff) const { if( image != IMG_EMPTY ) { @@ -316,7 +309,9 @@ void obj_t::mark_image_dirty(image_id image, sint16 yoff) const // too close to border => set dirty to be sure (smoke, skyscrapers, birds, or the like) KOORD_VAL xbild, ybild, wbild, hbild; display_get_image_offset( image, &xbild, &ybild, &wbild, &hbild ); + const sint16 distance_to_border = 3 - (yoff+get_yoff()+ybild)/(rasterweite/4); + if( pos.x <= distance_to_border || pos.y <= distance_to_border ) { // but only if the image is actually visible ... if( scr_pos.x+xbild+wbild >= 0 && xpos <= display_get_width() && scr_pos.y+ybild+hbild >= 0 && ypos+ybild < display_get_height() ) { diff --git obj/obj.h obj/obj.h new file mode 100644 index 0000000000..7b4772a36c --- /dev/null +++ obj/obj.h @@ -0,0 +1,273 @@ +/* + * This file is part of the Simutrans project under the Artistic License. + * (see LICENSE.txt) + */ + +#ifndef OBJ_OBJ_H +#define OBJ_OBJ_H + + +#include "../dataobj/koord3d.h" +#include "../display/clip_num.h" +#include "../display/simimg.h" +#include "../simcolor.h" +#include "../simtypes.h" + + +class cbuffer_t; +class karte_ptr_t; +class player_t; + + +/// Base class of all objects on the map, obj == thing +/// Since everything is an 'obj' on the map, we need to make this as compact and fast as possible. +class obj_t +{ +public: + // flags + enum flag_values { + no_flags = 0, ///< no special properties + dirty = 1<<0, ///< mark image dirty when drawing + not_on_map = 1<<1, ///< this object is not placed on any tile (e.g. vehicles in a depot) + is_vehicle = 1<<2, ///< this object is a vehicle obviously + highlight = 1<<3 ///< for drawing some highlighted outline + }; + + /// display only outline with player color on owner stuff + static bool show_owner; + +private: + obj_t(obj_t const &); + obj_t& operator=(obj_t const &); + + /// Coordinate of position + koord3d pos; + + /// x and y-offset of the object on the tile, used for drawing object image + /// if xoff and yoff are between 0 and OBJECT_OFFSET_STEPS-1 then + /// the top-left corner of the image is within tile boundaries + sint8 xoff, yoff; + + /// Owner of the object (1 - public player, 15 - unowned) + uint8 owner_n:4; + + /// @see flag_values + uint8 flags:4; + +private: + /// Used by all constructors to initialize all vars with safe values + void init(); + +protected: + obj_t(); + + /// since we often need access during loading + void set_player_nr(uint8 o) { owner_n = o; } + + /// Pointer to the world of this thing. Static to conserve space. + /// Change to instance variable once more than one world is available. + static karte_ptr_t welt; + +public: + /// needed for drawing images + sint8 get_player_nr() const { return owner_n; } + + /// sets owner of object + void set_owner(player_t *player); + + /// @returns owner of object + player_t *get_owner() const; + + /// routines to set, clear, get bit flags + inline void set_flag(flag_values flag) { flags |= flag; } + inline void clear_flag(flag_values flag) { flags &= ~flag; } + inline bool get_flag(flag_values flag) const { return (flags & flag) != 0; } + + /// all the different types of objects + enum typ { + undefined=-1, obj=0, baum=1, zeiger=2, + wolke=3, sync_wolke=4, async_wolke=5, + + gebaeude=7, ///< animated buildings (6 not used any more) + signal=8, + + bruecke=9, tunnel=10, + bahndepot=12, strassendepot=13, schiffdepot = 14, + + old_raucher=15, ///< obsolete + leitung = 16, pumpe = 17, senke = 18, + roadsign = 19, pillar = 20, + + airdepot = 21, monoraildepot=22, tramdepot=23, maglevdepot=24, + + wayobj = 25, + way = 26, ///< since 99.04 ways are normal things and stored in the objliste_t! + + label = 27, ///< indicates ownership + field = 28, + crossing = 29, + groundobj = 30, ///< lakes, stones + + narrowgaugedepot=31, + + // after this only moving stuff + // reserved values for vehicles: 64 to 95 + pedestrian=64, + road_user=65, + road_vehicle=66, + rail_vehicle=67, + monorail_vehicle=68, + maglev_vehicle=69, + narrowgauge_vehicle=70, + water_vehicle=80, + air_vehicle=81, + movingobj=82, + + /// other new objs (obsolete, only used during loading old games + // lagerhaus = 24, (never really used) + // gebaeude_alt=6, (very, very old?) + old_gebaeudefundament=11, ///< wall below buildings, not used any more + old_automobil=32, old_waggon=33, + old_schiff=34, old_aircraft=35, old_monorailwaggon=36, + old_verkehr=41, + old_fussgaenger=42, + old_choosesignal = 95, + old_presignal = 96, + old_roadsign = 97, + old_pillar = 98, + old_airdepot = 99, + old_monoraildepot=100, + old_tramdepot=101, + }; + + inline sint8 get_xoff() const { return xoff; } + inline sint8 get_yoff() const { return yoff; } + + /// true for all moving objects + inline bool is_moving() const { return (flags&is_vehicle) != 0; } + + /// while in principle, this should trigger the dirty, it takes just too much time to do it + /// TAKE CARE OF SET IT DIRTY YOURSELF!!! + inline void set_xoff(sint8 xoff) { this->xoff = xoff; } + inline void set_yoff(sint8 yoff) { this->yoff = yoff; } + + /// Constructor to set position of object + /// This does *not* add the object to the tile + obj_t(koord3d pos); + + /// Destructor: removes object from tile, should close any inspection windows + virtual ~obj_t(); + + /// Routine for cleanup if object is removed (ie book maintenance, cost for removal) + virtual void cleanup(player_t *) {} + + /// @returns untranslated name of object + virtual const char *get_name() const { return "Ding"; } + + /// @returns object type + /// @see obj_t::typ + virtual obj_t::typ get_typ() const = 0; + + /// waytype associated with this object + virtual waytype_t get_waytype() const { return invalid_wt; } + + /// called whenever the snowline height changes + /// return false and this object will be deleted + virtual bool check_season(const bool) { return true; } + + /// called during map rotation + virtual void rotate90(); + + /// @returns number of current image for that object + virtual image_id get_image() const = 0; + + /// give image for height > 0 (max. height currently 3) + /// IMG_EMPTY is no images + virtual image_id get_image(int /*height*/) const { return IMG_EMPTY; } + + /// this image is drawn after all get_image() on this tile + /// Currently only single height is supported for this feature + virtual image_id get_front_image() const { return IMG_EMPTY; } + + /// if a function returns a value here with TRANSPARENT_FLAGS set + /// then a transparent outline with the color from the lower 8 bit is drawn + virtual FLAGGED_PIXVAL get_outline_colour() const { return 0; } + + /// The image, that will be outlined + virtual image_id get_outline_image() const { return IMG_EMPTY; } + + /// Save and Load of object data + virtual void rdwr(loadsave_t *file); + + /// Called after the world is completely loaded from savegame + virtual void finish_rd() {} + + /// @returns position + inline koord3d get_pos() const { return pos; } + + /// set position - you would not have guessed it :) + inline void set_pos(koord3d k) { if(k!=pos) { set_flag(dirty); pos = k; } } + + /// put description of object into the buffer (used for certain windows) + /// @see simwin + virtual void info(cbuffer_t &buf) const; + + /// Opens a new info window for the object + virtual void show_info(); + + /// @retval true if the object lifecycle is managed by another system so cannot be destroyed. + /// @retval false if the object can be destroyed at any time. + virtual bool has_managed_lifecycle() const; + + /// @return NULL if OK, otherwise an error message + virtual const char *is_deletable(const player_t *player); + + /// Draw background image of object + /// (everything that could be potentially behind vehicles) + void display(int xpos, int ypos CLIP_NUM_DEF) const; + + /// Draw foreground image (everything that is in front of vehicles) +#ifdef MULTI_THREAD + virtual void display_after(int xpos, int ypos, const sint8 clip_num) const; +#else + virtual void display_after(int xpos, int ypos, bool is_global) const; +#endif + +#ifdef MULTI_THREAD + /// Draw overlays (convoi tooltips) + virtual void display_overlay(int /*xpos*/, int /*ypos*/) const {} +#endif + + /// When a vehicle moves or a cloud moves, it needs to mark the old spot as dirty (to copy to screen). + /// This routine already takes position, and offsets (x_off, y_off) into account. + /// @param yoff extra y-offset, in most cases 0, in pixels. + void mark_image_dirty(image_id image, sint16 yoff) const; + + /// Function for recalculating the image. + virtual void calc_image() {} +}; + + +/// Template to do casting of pointers based on obj_t::typ as a replacement of the slower dynamic_cast<> +template static T *obj_cast(obj_t *); + +template static inline T const *obj_cast(obj_t const *const d) +{ + return obj_cast(const_cast(d)); +} + + +/// Game objects that do not have description windows (for instance zeiger_t, wolke_t) +class obj_no_info_t : public obj_t +{ +public: + obj_no_info_t(koord3d pos) : obj_t(pos) {} + + void show_info() OVERRIDE {} + +protected: + obj_no_info_t() : obj_t() {} +}; + + +#endif diff --git obj/pillar.cc obj/pillar.cc index d10baf5d70..8b70e13a94 100644 --- obj/pillar.cc +++ obj/pillar.cc @@ -6,7 +6,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../simmem.h" #include "../display/simimg.h" @@ -17,8 +17,8 @@ #include "../boden/grund.h" #include "../dataobj/loadsave.h" -#include "../obj/pillar.h" -#include "../obj/bruecke.h" +#include "pillar.h" +#include "bruecke.h" #include "../dataobj/environment.h" diff --git obj/pillar.h obj/pillar.h index 70a8cd4d52..bc68ac004f 100644 --- obj/pillar.h +++ obj/pillar.h @@ -7,7 +7,7 @@ #define OBJ_PILLAR_H -#include "../simobj.h" +#include "obj.h" #include "../descriptor/bridge_desc.h" class loadsave_t; diff --git obj/roadsign.cc obj/roadsign.cc index 91b80e910d..3e78cab15c 100644 --- obj/roadsign.cc +++ obj/roadsign.cc @@ -7,7 +7,7 @@ #include "../simunits.h" #include "../simdebug.h" -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" #include "../player/simplay.h" #include "../simtool.h" diff --git obj/roadsign.h obj/roadsign.h index a76a782403..c8d51213fe 100644 --- obj/roadsign.h +++ obj/roadsign.h @@ -7,7 +7,7 @@ #define OBJ_ROADSIGN_H -#include "../simobj.h" +#include "obj.h" #include "../simtypes.h" #include "../descriptor/roadsign_desc.h" #include "../ifc/sync_steppable.h" diff --git obj/signal.cc obj/signal.cc index 427eba0f4a..685e8ed662 100644 --- obj/signal.cc +++ obj/signal.cc @@ -7,7 +7,7 @@ #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../boden/wege/schiene.h" #include "../boden/grund.h" #include "../display/simimg.h" diff --git obj/signal.h obj/signal.h index 2761f5da56..914f8d5825 100644 --- obj/signal.h +++ obj/signal.h @@ -9,7 +9,7 @@ #include "roadsign.h" -#include "../simobj.h" +#include "obj.h" /** diff --git obj/tunnel.cc obj/tunnel.cc index f6e565ca70..45e139c26f 100644 --- obj/tunnel.cc +++ obj/tunnel.cc @@ -6,7 +6,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../player/simplay.h" #include "../boden/grund.h" #include "../display/simimg.h" diff --git obj/tunnel.h obj/tunnel.h index c136d6b359..c60c768be7 100644 --- obj/tunnel.h +++ obj/tunnel.h @@ -7,7 +7,7 @@ #define OBJ_TUNNEL_H -#include "../simobj.h" +#include "obj.h" #include "../display/simimg.h" class tunnel_desc_t; diff --git obj/wayobj.cc obj/wayobj.cc index f67cd631da..5cb3829c5c 100644 --- obj/wayobj.cc +++ obj/wayobj.cc @@ -8,7 +8,7 @@ #include "../boden/grund.h" #include "../simworld.h" #include "../display/simimg.h" -#include "../simobj.h" +#include "obj.h" #include "../player/simplay.h" #include "../simtool.h" diff --git obj/wayobj.h obj/wayobj.h index f0efe70e04..84988a4ff1 100644 --- obj/wayobj.h +++ obj/wayobj.h @@ -9,7 +9,7 @@ #include "../simtypes.h" #include "../display/simimg.h" -#include "../simobj.h" +#include "obj.h" #include "../dataobj/ribi.h" #include "../descriptor/way_obj_desc.h" #include "../tpl/stringhashtable_tpl.h" diff --git obj/wolke.cc obj/wolke.cc index a0c4306a31..d2c2af4707 100644 --- obj/wolke.cc +++ obj/wolke.cc @@ -7,7 +7,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../utils/simrandom.h" #include "wolke.h" diff --git obj/wolke.h obj/wolke.h index 407277f5d5..86654615f2 100644 --- obj/wolke.h +++ obj/wolke.h @@ -82,7 +82,7 @@ class raucher_t : public obj_t { public: raucher_t(loadsave_t *file); - typ get_typ() const OVERRIDE { return raucher; } + typ get_typ() const OVERRIDE { return old_raucher; } image_id get_image() const OVERRIDE { return IMG_EMPTY; } }; diff --git obj/zeiger.cc obj/zeiger.cc index 1844170b69..c21514238f 100644 --- obj/zeiger.cc +++ obj/zeiger.cc @@ -8,7 +8,7 @@ #include #include "../simworld.h" -#include "../simobj.h" +#include "obj.h" #include "../simhalt.h" #include "../boden/grund.h" #include "../dataobj/environment.h" diff --git obj/zeiger.h obj/zeiger.h index c5cf345187..131e4d02d4 100644 --- obj/zeiger.h +++ obj/zeiger.h @@ -7,7 +7,7 @@ #define OBJ_ZEIGER_H -#include "../simobj.h" +#include "obj.h" #include "../simtypes.h" #include "../display/simimg.h" diff --git script/api/api_const.cc script/api/api_const.cc index 6d7681e7cf..72b6d46d13 100644 --- script/api/api_const.cc +++ script/api/api_const.cc @@ -8,7 +8,7 @@ /** @file api_const.cc exports constants */ #include "../api_param.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../simmenu.h" #include "../../simunits.h" diff --git script/api/api_map_objects.cc script/api/api_map_objects.cc index a9740387e7..ab1268728d 100644 --- script/api/api_map_objects.cc +++ script/api/api_map_objects.cc @@ -12,7 +12,7 @@ #include "../api_class.h" #include "../api_function.h" -#include "../../simobj.h" +#include "../../obj/obj.h" #include "../../simdepot.h" #include "../../simworld.h" #include "../../boden/grund.h" diff --git script/api_param.h script/api_param.h index 1434f8f9c1..602bbbf1e7 100644 --- script/api_param.h +++ script/api_param.h @@ -10,7 +10,7 @@ /** @file api_param.h templates for transfer of function call parameters */ #include "../squirrel/squirrel.h" -#include "../simobj.h" +#include "../obj/obj.h" #include "../simtypes.h" #include "../tpl/quickstone_tpl.h" #include "../utils/cbuffer_t.h" diff --git script/script_loader.h script/script_loader.h index 64e8f81847..524b6375f2 100644 --- script/script_loader.h +++ script/script_loader.h @@ -6,6 +6,7 @@ #ifndef SCRIPT_SCRIPT_LOADER_H #define SCRIPT_SCRIPT_LOADER_H + class script_vm_t; struct script_loader_t diff --git simcity.h simcity.h index 0ddc718aac..d381add5e5 100644 --- simcity.h +++ simcity.h @@ -7,7 +7,7 @@ #define SIMCITY_H -#include "simobj.h" +#include "obj/obj.h" #include "obj/gebaeude.h" #include "tpl/vector_tpl.h" diff --git simhalt.h simhalt.h index 56bc50052d..1bb89fb707 100644 --- simhalt.h +++ simhalt.h @@ -11,7 +11,7 @@ #include "linehandle_t.h" #include "halthandle_t.h" -#include "simobj.h" +#include "obj/obj.h" #include "display/simgraph.h" #include "simtypes.h" diff --git simobj.h simobj.h deleted file mode 100644 index 1298e2eb82..0000000000 --- simobj.h +++ /dev/null @@ -1,360 +0,0 @@ -/* - * This file is part of the Simutrans project under the Artistic License. - * (see LICENSE.txt) - */ - -#ifndef SIMOBJ_H -#define SIMOBJ_H - - -#include "simtypes.h" -#include "display/clip_num.h" -#include "display/simimg.h" -#include "simcolor.h" -#include "dataobj/koord3d.h" - - -class cbuffer_t; -class karte_ptr_t; -class player_t; - -/** - * Base class of all objects on the map, obj == thing - * Since everything is a 'obj' on the map, we need to make this as compact and fast as possible. - */ -class obj_t -{ -public: - // flags - enum flag_values { - no_flags=0, /// no special properties - dirty=1, /// mark image dirty when drawing - not_on_map=2, /// this object is not placed on any tile (e.g. vehicles in a depot) - is_vehicle=4, /// this object is a vehicle obviously - highlight=8 /// for drawing some highlighted outline - }; - - // display only outline with player color on owner stuff - static bool show_owner; - -private: - obj_t(obj_t const&); - obj_t& operator=(obj_t const&); - - /** - * Coordinate of position - */ - koord3d pos; - - /** - * x-offset of the object on the tile - * used for drawing object image - * if xoff and yoff are between 0 and OBJECT_OFFSET_STEPS-1 then - * the top-left corner of the image is within tile boundaries - */ - sint8 xoff; - - /** - * y-offset of the object on the tile - */ - sint8 yoff; - - /** - * Owner of the object (1 - public player, 15 - unowned) - */ - uint8 owner_n:4; - - /** - * @see flag_values - */ - uint8 flags:4; - -private: - /** - * Used by all constructors to initialize all vars with safe values - * -> single source principle - */ - void init(); - -protected: - obj_t(); - - // since we often need access during loading - void set_player_nr(uint8 o) { owner_n = o; } - - /** - * Pointer to the world of this thing. Static to conserve space. - * Change to instance variable once more than one world is available. - */ - static karte_ptr_t welt; - - -public: - // needed for drawing images - sint8 get_player_nr() const { return owner_n; } - - /** - * sets owner of object - */ - void set_owner(player_t *player); - - /** - * returns owner of object - */ - player_t * get_owner() const; - - /** - * routines to set, clear, get bit flags - */ - inline void set_flag(flag_values flag) {flags |= flag;} - inline void clear_flag(flag_values flag) {flags &= ~flag;} - inline bool get_flag(flag_values flag) const {return ((flags & flag) != 0);} - - /// all the different types of objects - enum typ { - undefined=-1, obj=0, baum=1, zeiger=2, - wolke=3, sync_wolke=4, async_wolke=5, - - gebaeude=7, // animated buildings (6 not used any more) - signal=8, - - bruecke=9, tunnel=10, - bahndepot=12, strassendepot=13, schiffdepot = 14, - - raucher=15, // obsolete - leitung = 16, pumpe = 17, senke = 18, - roadsign = 19, pillar = 20, - - airdepot = 21, monoraildepot=22, tramdepot=23, maglevdepot=24, - - wayobj = 25, - way = 26, // since 99.04 ways are normal things and stored in the objliste_t! - - label = 27, // indicates ownership - field = 28, - crossing = 29, - groundobj = 30, // lakes, stones - - narrowgaugedepot=31, - - // after this only moving stuff - // reserved values for vehicles: 64 to 95 - pedestrian=64, - road_user=65, - road_vehicle=66, - rail_vehicle=67, - monorail_vehicle=68, - maglev_vehicle=69, - narrowgauge_vehicle=70, - water_vehicle=80, - air_vehicle=81, - movingobj=82, - - // other new objs (obsolete, only used during loading old games - // lagerhaus = 24, (never really used) - // gebaeude_alt=6, (very, very old?) - old_gebaeudefundament=11, // wall below buildings, not used any more - old_automobil=32, old_waggon=33, - old_schiff=34, old_aircraft=35, old_monorailwaggon=36, - old_verkehr=41, - old_fussgaenger=42, - old_choosesignal = 95, - old_presignal = 96, - old_roadsign = 97, - old_pillar = 98, - old_airdepot = 99, - old_monoraildepot=100, - old_tramdepot=101, - }; - - inline sint8 get_xoff() const {return xoff;} - inline sint8 get_yoff() const {return yoff;} - - // true for all moving objects - inline bool is_moving() const { return flags&is_vehicle; } - - // while in principle, this should trigger the dirty, it takes just too much time to do it - // TAKE CARE OF SET IT DIRTY YOURSELF!!! - inline void set_xoff(sint8 xoff) {this->xoff = xoff; } - inline void set_yoff(sint8 yoff) {this->yoff = yoff; } - - /** - * Constructor to set position of object - * This does *not* add the object to the tile - */ - obj_t(koord3d pos); - - /** - * Destructor: removes object from tile, should close any inspection windows - */ - virtual ~obj_t(); - - /** - * Routine for cleanup if object is removed (ie book maintenance, cost for removal) - */ - virtual void cleanup(player_t *) {} - - /** - * @returns untranslated name of object - */ - virtual const char *get_name() const {return "Ding";} - - /** - * @return object type - * @see typ - */ - virtual typ get_typ() const = 0; - - /** - * waytype associated with this object - */ - virtual waytype_t get_waytype() const { return invalid_wt; } - - /** - * called whenever the snowline height changes - * return false and the obj_t will be deleted - */ - virtual bool check_season(const bool) { return true; } - - /** - * called during map rotation - */ - virtual void rotate90(); - - /** - * Every object needs an image. - * @return number of current image for that object - */ - virtual image_id get_image() const = 0; - - /** - * give image for height > 0 (max. height currently 3) - * IMG_EMPTY is no images - */ - virtual image_id get_image(int /*height*/) const {return IMG_EMPTY;} - - /** - * this image is drawn after all get_image() on this tile - * Currently only single height is supported for this feature - */ - virtual image_id get_front_image() const {return IMG_EMPTY;} - - /** - * if a function returns a value here with TRANSPARENT_FLAGS set - * then a transparent outline with the color from the lower 8 bit is drawn - */ - virtual FLAGGED_PIXVAL get_outline_colour() const {return 0;} - - /** - * The image, that will be outlined - */ - virtual image_id get_outline_image() const { return IMG_EMPTY; } - - /** - * Save and Load of object data in one routine - */ - virtual void rdwr(loadsave_t *file); - - /** - * Called after the world is completely loaded from savegame - */ - virtual void finish_rd() {} - - /** - * @return position - */ - inline koord3d get_pos() const {return pos;} - - /** - * set position - you would not have guessed it :) - */ - inline void set_pos(koord3d k) { if(k!=pos) { set_flag(dirty); pos = k;} } - - /** - * put description of object into the buffer - * (used for certain windows) - * @see simwin - */ - virtual void info(cbuffer_t & buf) const; - - /** - * Opens a new info window for the object - */ - virtual void show_info(); - - /** - * @return True if the object lifecycle is managed by another system so cannot be destroyed. - * False if the object can be destroyed at any time. - */ - virtual bool has_managed_lifecycle() const; - - /** - * @return NULL if OK, otherwise an error message - */ - virtual const char *is_deletable(const player_t *player); - - /** - * Draw background image of object - * (everything that could be potentially behind vehicles) - */ - void display(int xpos, int ypos CLIP_NUM_DEF) const; - - /** - * Draw foreground image - * (everything that is in front of vehicles) - */ -#ifdef MULTI_THREAD - virtual void display_after(int xpos, int ypos, const sint8 clip_num) const; -#else - virtual void display_after(int xpos, int ypos, bool is_global) const; -#endif - -#ifdef MULTI_THREAD - /** - * Draw overlays - * (convoi tooltips) - */ - virtual void display_overlay(int /*xpos*/, int /*ypos*/) const { return; } -#endif - - /** - * When a vehicle moves or a cloud moves, it needs to mark the old spot as dirty (to copy to screen). - * This routine already takes position, and offsets (x_off, y_off) into account. - * @param yoff extra y-offset, in most cases 0, in pixels. - */ - void mark_image_dirty(image_id image, sint16 yoff) const; - - /** - * Function for recalculating the image. - */ - virtual void calc_image() {} -}; - - -/** - * Template to do casting of pointers based on obj_t::typ - * as a replacement of the slower dynamic_cast<> - */ -template static T* obj_cast(obj_t*); - -template static inline T const* obj_cast(obj_t const* const d) -{ - return obj_cast(const_cast(d)); -} - - -/** - * Game objects that do not have description windows (for instance zeiger_t, wolke_t) - */ -class obj_no_info_t : public obj_t -{ -public: - obj_no_info_t(koord3d pos) : obj_t(pos) {} - - void show_info() OVERRIDE {} - -protected: - obj_no_info_t() : obj_t() {} -}; - -#endif diff --git simplan.cc simplan.cc index 1683faee12..83d5d44840 100644 --- simplan.cc +++ simplan.cc @@ -4,7 +4,7 @@ */ #include "simdebug.h" -#include "simobj.h" +#include "obj/obj.h" #include "simfab.h" #include "display/simgraph.h" #include "simmenu.h" diff --git simtool.h simtool.h index 5f2539c040..95fc034ac3 100644 --- simtool.h +++ simtool.h @@ -12,7 +12,7 @@ #include "simtypes.h" #include "simworld.h" #include "simmenu.h" -#include "simobj.h" +#include "obj/obj.h" #include "boden/wege/schiene.h" diff --git vehicle/movingobj.cc vehicle/movingobj.cc index 0007ef0b40..6da9e9e618 100644 --- vehicle/movingobj.cc +++ vehicle/movingobj.cc @@ -8,7 +8,7 @@ #include "../simdebug.h" #include "../simworld.h" -#include "../simobj.h" +#include "../obj/obj.h" #include "../display/simimg.h" #include "../player/simplay.h" #include "../simtypes.h" diff --git vehicle/simvehicle.h vehicle/simvehicle.h index 69ee0e6b38..fce117486c 100644 --- vehicle/simvehicle.h +++ vehicle/simvehicle.h @@ -8,7 +8,7 @@ #include "../simtypes.h" -#include "../simobj.h" +#include "../obj/obj.h" #include "../halthandle_t.h" #include "../convoihandle_t.h" #include "../ifc/simtestdriver.h"