1 #ifndef __BTANKS_PLAYER_SLOT_H__ 2 #define __BTANKS_PLAYER_SLOT_H__ 3 4 /* Battle Tanks Game 5 * Copyright (C) 2006-2009 Battle Tanks team 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 /* 23 * Additional rights can be granted beyond the GNU General Public License 24 * on the terms provided in the Exception. If you modify this file, 25 * you may extend this exception to your version of the file, 26 * but you are not obligated to do so. If you do not wish to provide this 27 * exception without modification, you must delete this exception statement 28 * from your version and license this file solely under the GPL without exception. 29 */ 30 31 #include <string> 32 #include <set> 33 #include <queue> 34 35 namespace sdlx { 36 class Surface; 37 } 38 39 #include "mrt/serializable.h" 40 #include "math/v2.h" 41 #include "math/v3.h" 42 #include "sdlx/rect.h" 43 #include "player_state.h" 44 #include "netstats.h" 45 #include "team.h" 46 47 class Object; 48 class ControlMethod; 49 class Tooltip; 50 class JoinTeamControl; 51 52 class BTANKSAPI PlayerSlot : public mrt::Serializable { 53 public: 54 int id; 55 empty()56 inline const bool empty() const { return id < 0; } 57 58 ControlMethod * control_method; 59 PlayerState old_state; //help broadcast AI state changes. 60 61 v3<int> position; 62 63 bool need_sync, dont_interpolate; 64 int remote; 65 NetStats net_stats; 66 67 bool visible; 68 sdlx::Rect viewport; 69 70 v2<float> map_pos, map_vel, map_dst, map_dst_vel, map_dst_pos; 71 v2<int> map_dpos; 72 73 //respawn stuff. 74 std::string classname; 75 std::string animation; 76 77 int frags; 78 79 std::set<int> zones_reached; 80 int spawn_limit; 81 float dead_time; 82 83 int score; 84 std::string name; 85 86 bool spectator; 87 Team::ID team; 88 89 PlayerSlot(); 90 void clear(); 91 92 Object * getObject() const; 93 ~PlayerSlot(); 94 95 virtual void serialize(mrt::Serializator &s) const; 96 virtual void deserialize(const mrt::Serializator &s); 97 98 void displayLast(); 99 void displayTooltip(const std::string &area, const std::string &message); 100 void removeTooltips(); 101 void tick(const float dt); 102 void render(sdlx::Surface &window, const int x, const int y); 103 104 void createControlMethod(const std::string &name); 105 void spawn_player(const int slot_id, const std::string &classname, const std::string &animation); 106 void validatePosition(v2<float>& position); 107 void addScore(const int s); 108 currentTooltip()109 const Tooltip *currentTooltip() const { return tooltips.empty()? NULL: tooltips.front().second; } 110 void setViewport(const sdlx::Rect &rect); 111 112 void getDefaultVehicle(std::string &vehicle, std::string &animation); 113 114 void updateState(PlayerState &state, float dt); 115 void join(const Team::ID t); 116 screen2world(const v2<int> & screen)117 const v2<float> screen2world(const v2<int> &screen) const { 118 return map_pos + screen.convert<float>(); 119 } 120 121 private: 122 typedef std::queue<std::pair<float, Tooltip *> > Tooltips; 123 Tooltips tooltips; 124 125 Tooltip * last_tooltip; 126 bool last_tooltip_used; 127 128 JoinTeamControl * join_team; 129 130 float moving; 131 }; 132 133 #endif 134