File: body.h

package info (click to toggle)
warmux 1%3A11.04.1%2Brepack2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 126,388 kB
  • sloc: cpp: 186,040; xml: 8,909; sh: 3,358; makefile: 1,052; ansic: 713
file content (152 lines) | stat: -rw-r--r-- 6,083 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/******************************************************************************
 *  Warmux is a convivial mass murder game.
 *  Copyright (C) 2001-2011 Warmux Team.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 ******************************************************************************
 * Character of a team.
 *****************************************************************************/

#ifndef BODY_H
#define BODY_H
#include <map>

#include <vector>
#include <WARMUX_base.h>
#include <WARMUX_point.h>

// Forward declarations
class Character;
class BodyList;
class Member;
class member_mvt;
class Movement;
class Clothe;
class Profile;
class junction;
typedef struct _xmlNode xmlNode;
typedef std::vector<const xmlNode*> xmlNodeArray;

class Body
{
  friend class BodyList;

  std::map<std::string, Member *>   members_lst;
  std::map<std::string, Clothe *>   clothes_lst;
  std::map<std::string, Movement *> mvt_lst;
  const Clothe *                    current_clothe;
  Movement *                        current_mvt;
  uint                              current_loop;
  uint                              current_frame;

  // When a movement/clothe is played once, those variables save the previous state
  const Clothe *                    previous_clothe;
  Movement *                        previous_mvt;
  bool                              mvt_locked;

  // For weapon position handling
  Member *                          weapon_member;

  // Time elapsed since last refresh
  uint                              last_refresh;

  bool                              walking;
  Double                            main_rotation_rad;
  std::vector<junction *>           skel_lst; // Body skeleton:
                                              // Order to use to build the body
                                              // First element: member to build
                                              // Secnd element: parent member
  LRDirection                       direction;
  int                               animation_number;
  bool                              need_rebuild;
  bool                              need_refreshsprites;
  const Character *                 owner;
  const xmlNode *                   mainXmlNode;
  const std::string                 mainFolder;

  void ResetMovement() const;
  void ApplyMovement(Movement * mvt,
                     uint       frame);
  void ApplySqueleton();

  void ProcessFollowCrosshair(member_mvt & mb_mvt);
  void ProcessFollowHalfCrosshair(member_mvt & mb_mvt);
  void ProcessFollowSpeed(member_mvt & mb_mvt);
  void ProcessFollowDirection(member_mvt & mb_mvt);
  void ProcessFollowCursor(member_mvt & mb_mvt,
                           Member *     member);

  void BuildSqueleton();
  void AddChildMembers(Member * parent);
  void DrawWeaponMember(const Point2i & _pos);
  void LoadMembers(xmlNodeArray &      nodes,
                   const std::string & main_folder);
  void LoadClothes(xmlNodeArray &  nodes,
                   const xmlNode * xml);
  void LoadMovements(xmlNodeArray &  nodes,
                     const xmlNode * xml);
  void FreeSkeletonVector();

public:
  Body(const xmlNode *     xml,
       const std::string & main_folder);
  Body(const Body & cpy);
  void Init(void);
  ~Body();

  //// MISC
  void                    Draw(const Point2i & pos);
  void                    PlayAnimation();
  void                    Build();
  void                    UpdateWeaponPosition(const Point2i & pos);
  void                    StartWalking();
  void                    StopWalking();
  bool                    IsWalking() const { return walking; };
  void                    MakeParticles(const Point2i & pos);
  void                    MakeTeleportParticles(const Point2i & pos,
                                                const Point2i & dst);
  void                    DebugState() const;
  void                    Rebuild(void) { need_rebuild = true; }

  //// SETTERS
  void                    SetClothe(const std::string & name);
  void                    SetMovement(const std::string & name);
  // use this only during one movement ...
  void                    SetClotheOnce(const std::string & name);
  // play the movement only once ...
  void                    SetMovementOnce(const std::string & name);
  void                    SetRotation(Double angle);
  void                    SetFrame(uint no);
  void                    SetDirection(LRDirection dir)    { direction = dir; need_refreshsprites = true; }
  inline void             SetOwner(const Character * belonger) { owner = belonger; }

  //// GETTERS
  static Point2i          GetSize() { return Point2i(30,45); };
  const std::string &     GetMovement() const;
  const std::string &     GetClothe() const;
  std::string             GetFrameLoop() const;
  void                    GetTestRect(uint & l,
                                      uint & r,
                                      uint & t,
                                      uint & b) const;
  const LRDirection & GetDirection() const { return direction; };
  void                    GetRelativeHandPosition(Point2i & result) const;
  uint                    GetMovementDuration() const;
  uint                    GetFrame() const { return current_frame; };
  uint                    GetFrameCount() const;
  void                    RefreshSprites();
};

#endif //BODY_H