|
ORTS
|
00001 #ifndef ServerObjData_H 00002 #define ServerObjData_H 00003 00004 // $Id: ServerObjData.H 6867 2008-04-05 18:59:22Z furtak $ 00005 00006 // This is an ORTS file (c) Michael Buro, licensed under the GPL 00007 00008 #include "Global.H" 00009 #include "Coord.H" 00010 #include "Array.H" 00011 #include "PlayerSet.H" 00012 #include "Object.H" 00013 #include "SType.H" 00014 #include "SaveLoad.H" 00015 00016 class GameObj; 00017 00018 typedef Array<GameObj*> Neighbors; 00019 00020 //=================================================================== 00021 00022 /** Cached motion & sight properties. 00023 Pointers to oft-used variables so they don't have to be repeatedly located. 00024 Update GameObj::init_sod() if properties change. 00025 */ 00026 00027 class ServerObjData : public SaveLoad { 00028 00029 public: 00030 00031 sintptr *shape; 00032 sintptr *x, *y; 00033 sintptr *x1, *y1; // rectangle upper left / line endpoint 00034 sintptr *x2, *y2; // rectangle lower right / line endpoint 00035 sintptr *radius; 00036 00037 bool is_boundary; 00038 00039 sintptr *owner; 00040 00041 sintptr *max_speed; 00042 sintptr *speed; ///< It may be possible for an object to be moving with zero speed, 00043 ///< if, say, it's caught in a spell, or it hops. 00044 sintptr *is_moving; ///< The object is at least trying to move and hasn't encountered an obstacle. 00045 sintptr *zcat; 00046 sintptr *collides; ///< Collision mask determines which objects can collide. 00047 sintptr *ncollides; ///< Exceptions to the collision mask, objects with intersecting masks don't collide. 00048 00049 sintptr *sight; ///< Visibility radius. 360 degree vision for now. 00050 sintptr *cloaked; ///< >= 1 if cannot be seen by non-detectors, enemies 00051 sintptr *cloaked2; ///< >= 1 iff can only be seen by allies 00052 sintptr *detector; ///< True iff the object can see cloaked units. 00053 00054 //------------------------------------- 00055 00056 struct PrevData { 00057 sint4 shape; 00058 sint4 x, y; 00059 sint4 x1, y1; 00060 sint4 x2, y2; 00061 sint4 radius; 00062 00063 sint4 owner; 00064 00065 sint4 max_speed; 00066 sint4 speed; 00067 sint4 is_moving; 00068 sint4 zcat; 00069 sint4 collides; 00070 sint4 ncollides; 00071 00072 sint4 sight; 00073 sint4 cloaked; 00074 sint4 cloaked2; 00075 sint4 detector; 00076 00077 PrevData(); 00078 } prev; 00079 00080 //------------------------------------- 00081 00082 PlayerSet seen_by, prev_seen_by; 00083 Array<sint4> last_lost; // sight of 00084 00085 bool in_game, is_global, is_shared; 00086 00087 ServerObjData() { 00088 is_boundary = false; 00089 in_game = false; 00090 is_global = false; 00091 is_shared = false; 00092 00093 shape = 0; 00094 x = y = 0; 00095 x1 = y1 = 0; 00096 x2 = y2 = 0; 00097 radius = 0; 00098 owner = 0; 00099 max_speed = speed = 0; 00100 is_moving = 0; 00101 zcat = 0; 00102 collides = 0; 00103 ncollides = 0; 00104 sight = 0; 00105 cloaked = 0; 00106 cloaked2 = 0; 00107 detector = 0; 00108 } 00109 00110 void copy_to_prev(); 00111 00112 void save(std::ostream &os) const; 00113 void load(std::istream &is); 00114 }; 00115 00116 /** Data used by the server for object motion and collisions. 00117 Distinguished by being information not available to the scripts. 00118 */ 00119 00120 class ServerMotionData : public SaveLoad { 00121 00122 public: 00123 00124 ScalarPoint start_f_pos; ///< Position the current straight line movement started from (in fine coordinates). 00125 ScalarPoint target_f_pos; ///< Movement destination (in fine coordinates). 00126 ScalarPoint f_delta; ///< Vector from the start to the target in fine units. 00127 00128 real8 inv_ttt; ///< 1 / time to reach target 00129 00130 ScalarPoint fine_pos; ///< Sub-grid pos (sv_pos is nearest grid point) 00131 ScalarPoint fine_heading; ///< Movement vector in fine coordinates. 00132 ScalarPoint bc_fine_center;///< Motion bounding circle center. 00133 Scalar bc_fine_r; ///< Motion bounding circle radius. 00134 sint4 ticks_so_far; ///< Number of ticks the object has moved along the current path. 00135 sint4 ticks_total; ///< Total number of ticks needed to move from the start to the destination. 00136 00137 uint4 neighbor_magic; ///< For Game::move_objects(). 00138 uint4 visit_magic; 00139 uint4 unique_magic; ///< For Game::handle_component(). 00140 00141 Neighbors neighbors; 00142 00143 ServerMotionData() { 00144 inv_ttt = 0; 00145 fine_pos.x = fine_pos.y = -1; 00146 bc_fine_center.x = bc_fine_center.y = -1; 00147 bc_fine_r = -1; 00148 ticks_so_far = ticks_total = -1; 00149 visit_magic = neighbor_magic = unique_magic = 0; 00150 } 00151 00152 void save(std::ostream &os) const; 00153 void load(std::istream &is); 00154 }; 00155 00156 //=================================================================== 00157 00158 #endif