File: movementmanager.cpp

package info (click to toggle)
opencity 0.0.6.4stable-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,624 kB
  • ctags: 3,534
  • sloc: cpp: 26,121; xml: 4,453; sh: 3,743; ansic: 585; makefile: 472
file content (197 lines) | stat: -rw-r--r-- 4,265 bytes parent folder | download | duplicates (7)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/***************************************************************************
					movementmanager.cpp  -  description
							-------------------
	begin                : may 16th, 2004
	copyright            : (C) 2004-2007 by Duong Khang NGUYEN
	email                : neoneurone @ gmail com

	$Id: movementmanager.cpp 375 2008-10-28 14:47:15Z neoneurone $
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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     *
 *   any later version.                                                    *
 *                                                                         *
 ***************************************************************************/

// Useful enumerations
#include "opencity_direction.h"

// OpenCity headers
#include "movement.h"
#include "movementmanager.h"
#include "graphicmanager.h"


   /*=====================================================================*/
MovementManager::MovementManager(
	const GraphicManager* gm,
	const Map* map):
_uiCount(0),
pcGraphicMgr( gm ),
pcMap( map )
{
	OPENCITY_DEBUG("ctor");

   // tab movement initialization
	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		tabmvt[ i ] = NULL;
	}
}


   /*=====================================================================*/
MovementManager::~MovementManager()
{
	OPENCITY_DEBUG("dtor");

	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		delete tabmvt[ i ];
		tabmvt[ i ] = NULL;		// Safe
	}
	_uiCount = 0;
}


   /*=====================================================================*/
const int
MovementManager::Add(
	Movement* const pNew )
{
	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		if (tabmvt[ i ] == NULL) {
			tabmvt[ i ] = pNew;
			++_uiCount;
			return i;
		}
	}

	return -1;
}


   /*=====================================================================*/
const bool
MovementManager::IsFull()
{
	return _uiCount == OC_MOVEMENT_MAX;
}


   /*=====================================================================*/
void
MovementManager::Remove(
	const int ciIndex )
{
// IF the user has specified the index of the element
// THEN only remove that element
	if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
		if (tabmvt[ ciIndex ] != NULL) {
			delete tabmvt[ ciIndex ];
			tabmvt[ ciIndex ] = NULL;
			--_uiCount;
		}
		return;
	}

// ELSE remove all the contained movement
	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		if (tabmvt[ i ] != NULL) {
			delete tabmvt[ i ];
			tabmvt[ i ] = NULL;
		}
	}
	_uiCount = 0;
}


   /*=====================================================================*/
void
MovementManager::Move(
	const int ciIndex )
{
// IF the user has specified the index of the element
// THEN only call that element
	if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
		if (tabmvt[ ciIndex ] != NULL and tabmvt[ ciIndex ]->Move() == false) {
			delete tabmvt[ ciIndex ];
			tabmvt[ ciIndex ] = NULL;
			--_uiCount;
		}
		return;
	}

// ELSE move all the contained movement
	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		if (tabmvt[ i ] != NULL and tabmvt[ i ]->Move() == false) {
			delete tabmvt[ i ];
			tabmvt[ i ] = NULL;
			--_uiCount;
		}
	}
}


   /*=====================================================================*/
void
MovementManager::Display(
	const int ciIndex )
{
// IF the user has specified the index of the element
// THEN only call that element
	if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
		if (tabmvt[ ciIndex ] != NULL)
			this->pcGraphicMgr->Display(
				tabmvt[ ciIndex ]->_fCurrentW,
				tabmvt[ ciIndex ]->_fCurrentL,
				tabmvt[ ciIndex ]->_fCurrentH,
				tabmvt[ ciIndex ] );
		return;
	}

// ELSE display all the contained movement
	for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
		if (tabmvt[ i ] != NULL)
			this->pcGraphicMgr->Display(
				tabmvt[ i ]->_fCurrentW,
				tabmvt[ i ]->_fCurrentL,
				tabmvt[ i ]->_fCurrentH,
				tabmvt[ i ] );
	}
}