src/character/body.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Character of a team.
00020  *****************************************************************************/
00021 
00022 #ifndef BODY_H
00023 #define BODY_H
00024 #include <map>
00025 #include "body_list.h"
00026 #include "clothe.h"
00027 #include "member.h"
00028 #include "movement.h"
00029 #include "../tool/resource_manager.h"
00030 #include "../tool/point.h"
00031 #include "../tool/xml_document.h"
00032 class Character;
00033 class BodyList;
00034 class Member;
00035 class Clothe;
00036 
00037 class c_junction
00038 {
00039 public:
00040   Member* member;
00041   Member* parent;
00042   c_junction() { member = NULL; parent = NULL; } ;
00043 };
00044 
00045 typedef class c_junction junction;
00046 
00047 class Body
00048 {
00049 public:
00050   typedef enum
00051   {
00052     DIRECTION_LEFT = -1,
00053     DIRECTION_RIGHT = 1
00054   } Direction_t;
00055 private:
00056   friend class BodyList;
00057   std::map<std::string, Member*> members_lst;
00058   std::map<std::string, Clothe*> clothes_lst;
00059   std::map<std::string, Movement*> mvt_lst;
00060 
00061   Clothe* current_clothe;
00062   Movement* current_mvt;
00063 
00064   // When a movement/clothe is played once, those variable saves the previous state;
00065   Movement* play_once_mvt_sauv;
00066   Clothe* play_once_clothe_sauv;
00067   uint play_once_frame_sauv;
00068 
00069   // For weapon position handling
00070   Member* weapon_member;
00071   Point2i weapon_pos;
00072 
00073   uint last_refresh; // Time elapsed since last refresh
00074   uint current_frame;
00075   int walk_events;
00076 
00077   double main_rotation_rad;
00078 
00079   std::vector<junction> squel_lst; // Squeleton of the body:
00080                                         // Order to use to build the body
00081                                         // First element: member to build
00082                                         // Secnd element: parent member
00083   Body::Direction_t direction;
00084 
00085   int animation_number;
00086   bool need_rebuild;
00087 
00088   void ResetMovement();
00089   void ApplyMovement(Movement* mvt, uint frame);
00090   void ApplySqueleton();
00091 
00092   void BuildSqueleton();
00093   void AddChildMembers(Member* parent);
00094   const Character* owner;
00095 
00096 public:
00097 
00098   Body(xmlpp::Element *xml, Profile* res);
00099   Body(Body *_body);
00100   ~Body();
00101 
00102   Point2i GetSize() {return Point2i(30,45);};
00103 
00104   void Draw(const Point2i& pos);
00105   void SetClothe(std::string name);
00106   void SetMovement(std::string name);
00107   void SetClotheOnce(std::string name); //use this only during one movement
00108   void SetMovementOnce(std::string name); //play the movement only once
00109   void SetRotation(double angle);
00110   void SetFrame(uint no);
00111   void SetDirection(Body::Direction_t dir);
00112   inline void SetOwner(const Character* belonger) { owner = belonger; };
00113   void PlayAnimation();
00114   void Build();
00115 
00116   const std::string& GetMovement();
00117   const std::string& GetClothe();
00118   void GetTestRect(uint &l, uint &r, uint &t, uint &b);
00119   const Direction_t &GetDirection() const;
00120   const Point2i &GetHandPosition() const;
00121   uint GetMovementDuration();
00122   uint GetFrame() { return current_frame; };
00123   uint GetFrameCount();
00124 
00125   void StartWalk();
00126   void StopWalk();
00127   void ResetWalk();
00128   bool IsWalking() { return walk_events > 0 && current_mvt->type == "walk";};
00129 
00130   void MakeParticles(const Point2i& pos);
00131   void MakeTeleportParticles(const Point2i& pos, const Point2i& dst);
00132 };
00133 
00134 #endif //BODY_H

Generated on Mon Jan 1 13:10:55 2007 for Wormux by  doxygen 1.4.7