warn_linux_gcc.patch

abelgar, 09/22/2010 11:07 am

Download (83.8 kB)

b/code/nel/include/nel/ligo/primitive_utils.h Wed Sep 22 11:00:19 2010 +0200
162 162
	{
163 163
		while (!_IndexStack.empty())
164 164
		{
165
			if (_IndexStack.back() == ~0)
165
			// uint cast is to prevent warn with gcc but use of complement with uint is weird
166
			if (_IndexStack.back() == (uint) ~0)
166 167
			{
167 168
				_IndexStack.back() = 0;
168 169
				// we need to check the current node.
b/code/ryzom/client/src/continent_manager_build.cpp Wed Sep 22 11:00:19 2010 +0200
194 194

195 195

196 196
						// get alias and region name
197
						uint32 alias;
197
						uint32 alias = 0;
198 198
						string primName, primAlias;
199 199
						vGenRes[i]->getPropertyByName("name", primName);
200 200

b/code/ryzom/server/src/ai_data_service/pacs_scan.cpp Wed Sep 22 11:00:19 2010 +0200
2130 2130
		{
2131 2131
			uint8			*linePtr = lineBuffer;
2132 2132
			uint8			*linePtrHM = lineBufferHM;
2133
			uint8			pointBuffer;
2134
			uint8			pointBufferHM;
2133
			uint8			pointBuffer = 0;
2134
			uint8			pointBufferHM = 0;
2135 2135

2136 2136
			CMapPosition	pos(scanpos);
2137 2137

b/code/ryzom/server/src/ai_service/ai_entity_matrix.h Wed Sep 22 11:00:19 2010 +0200
241 241
	{
242 242
	public:
243 243
		inline CCellTblIteratorLinear():
244
		_matrix(NULL), _tbl(NULL), _x(0), _y(0), _runLengthRemaining(0) 
244
		_x(0), _y(0), _matrix(NULL), _tbl(NULL), _runLengthRemaining(0) 
245 245
		{
246 246
		}
247 247
		
248 248
		inline CCellTblIteratorLinear(const CAIEntityMatrix<T> *matrix,const CAIEntityMatrixIteratorTblLinear *tbl,const	CAIVector	&pos):
249
		_matrix(matrix), _tbl(tbl), _x((uint16)pos.x().asInt16Meters()), _y((uint16)pos.y().asInt16Meters()) 
249
		_x((uint16)pos.x().asInt16Meters()), _y((uint16)pos.y().asInt16Meters()), _matrix(matrix), _tbl(tbl) 
250 250
		{
251 251
#ifdef NL_DEBUG
252 252
			nlassert(_tbl!=NULL);
b/code/ryzom/server/src/ai_service/ai_entity_physical_inline.h Wed Sep 22 11:00:19 2010 +0200
1
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2
// Copyright (C) 2010  Winch Gate Property Limited
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU Affero General Public License as
6
// published by the Free Software Foundation, either version 3 of the
7
// License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU Affero General Public License for more details.
13
//
14
// You should have received a copy of the GNU Affero General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

17

18

19

20
#ifndef RYAI_ENTITY_PHYSICAL_INLINE_H
21
#define RYAI_ENTITY_PHYSICAL_INLINE_H
22

23
#include "ai.h"
24
#include "game_share/fame.h"
25
/*
26

27
  The following base class is the common parent of bots, plrs and any other
28
  physical object that has an existance in the world
29

30
*/
31

32
//////////////////////////////////////////////////////////////////////////////
33
// CAIEntityPhysical                                                        //
34
//////////////////////////////////////////////////////////////////////////////
35

36
#ifdef NL_OS_WINDOWS
37
#pragma warning (push)
38
#pragma warning (disable : 4355)
39
#endif
40

41
inline
42
CAIEntityPhysical::CAIEntityPhysical(CPersistentOfPhysical& owner, TDataSetRow const& entityIndex, NLMISC::CEntityId const& id, float radius, uint32 level, RYAI_MAP_CRUNCH::TAStarFlag const& AStarFlags)
43
: CAIEntity()
44
, _dataSetRow(entityIndex)
45
, _pos(entityIndex)
46
, CSpawnable<CPersistentOfPhysical >(owner)
47
, _id(id)
48
, _Stuned(0)
49
, _Rooted(0)
50
, _Blinded(0)
51
, _Feared(0)
52
//, _UnreachableTarget((CAIEntityPhysical*)NULL)
53
, _radius(radius)
54
, _food(_radius)
55
, _Level(level)
56
, _AStarFlags(AStarFlags)
57
{
58
	_instanceNumber.init(*CMirrors::DataSet, entityIndex, DSPropertyAI_INSTANCE);
59
	_mode.init			(*CMirrors::DataSet, entityIndex, DSPropertyMODE);
60
	_behaviour.init		(*CMirrors::DataSet, entityIndex, DSPropertyBEHAVIOUR);
61
	_targetRow.init		(*CMirrors::DataSet, entityIndex, DSPropertyTARGET_ID);
62
	_ActionFlags.init	(*CMirrors::DataSet, entityIndex, DSPropertyACTION_FLAGS);
63

64
	_RunSpeed.init		(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_RUN_SPEED);
65
	_WalkSpeed.init		(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_WALK_SPEED);
66
	
67
	_CurrentHitPoint.init	(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_HIT_POINTS);
68
	_MaxHitPoint.init		(*CMirrors::DataSet, entityIndex, DSPropertyMAX_HIT_POINTS);
69
	_VisionCounter.init		(*CMirrors::DataSet, entityIndex, DSPropertyVISION_COUNTER);
70
	_InOutpostAlias.init	(*CMirrors::DataSet, entityIndex, DSPropertyIN_OUTPOST_ZONE_ALIAS);
71
	_InOutpostSide.init		(*CMirrors::DataSet, entityIndex, DSPropertyIN_OUTPOST_ZONE_SIDE);
72

73
#ifdef NL_DEBUG
74
	const NLMISC::CDbgRefCount<CAIEntityPhysical>	&ref=*(static_cast<NLMISC::CDbgRefCount<CAIEntityPhysical> * const>(this));
75
	NLMISC::CDbgPtr<CAIEntityPhysical>	dummyPtr;
76
	
77
	nlassert(ref.getDbgRef(dummyPtr)==0);
78
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(entityIndex.getIndex())==CAIS::instance()._CAIEntityByDataSetRow.end());
79
	ref.setCheckMax(false);
80
#endif
81
	CAIS::instance()._CAIEntityByDataSetRow.insert(std::make_pair(entityIndex.getIndex(),this));	//	we don't want to register players.	
82
#ifdef NL_DEBUG
83
	ref.setCheckMax(true);
84
	nlassert(ref.getDbgRef(dummyPtr)==1);
85
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(entityIndex.getIndex())!=CAIS::instance()._CAIEntityByDataSetRow.end());
86
#endif
87

88
	CAIEntityPhysicalLocator::getInstance()->addEntity(_dataSetRow, _id, this);
89
}
90

91
inline
92
CAIEntityPhysical::~CAIEntityPhysical()
93
{
94
	CAIEntityPhysicalLocator::getInstance()->delEntity(_dataSetRow, _id, this);
95
	
96
#ifdef NL_DEBUG
97
	const NLMISC::CDbgRefCount<CAIEntityPhysical>	&ref=*(static_cast<NLMISC::CDbgRefCount<CAIEntityPhysical> * const>(this));
98
	NLMISC::CDbgPtr<CAIEntityPhysical>	dummyPtr;	
99
#endif
100

101
	// Remove healers
102
	std::multiset<IAIEntityPhysicalHealer*>::iterator it, itEnd;
103
	for (it=_Healers.begin(), itEnd=_Healers.end(); it!=itEnd; ++it)
104
	{
105
		(*it)->healerRemoved(this);
106
	}
107
	
108
	detachFromTargeting();
109
	CAIS::instance()._CAIEntityByDataSetRow.erase(dataSetRow().getIndex());
110

111
#ifdef NL_DEBUG
112
	nlassert(ref.getDbgRef(dummyPtr)==0);
113
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(dataSetRow().getIndex())==CAIS::instance()._CAIEntityByDataSetRow.end());
114
#endif
115
}
116

117
#ifdef NL_OS_WINDOWS
118
#pragma warning (pop)
119
#endif
120

121
inline
122
void CAIEntityPhysical::setActionFlags(RYZOMACTIONFLAGS::TActionFlag const& flag)
123
{
124
	_ActionFlags = (_ActionFlags.getValue() | flag );
125
}
126

127
inline
128
void CAIEntityPhysical::removeActionFlags(RYZOMACTIONFLAGS::TActionFlag const& flag)
129
{
130
	_ActionFlags = (_ActionFlags.getValue() & ~flag );
131
}
132

133
inline
134
float CAIEntityPhysical::getCollisionDist(float angTo) const
135
{
136
	return 0.5;
137
}
138

139
inline
140
bool CAIEntityPhysical::canMove() const
141
{
142
	return !isRooted() && (walkSpeed() != 0);
143
}
144

145
inline
146
float CAIEntityPhysical::walkSpeed() const
147
{
148
	return _WalkSpeed()*0.1f*SpeedFactor*getSpeedFactor();
149
}
150

151
inline
152
float CAIEntityPhysical::runSpeed() const
153
{
154
	return _RunSpeed()*0.1f*SpeedFactor*getSpeedFactor();
155
}
156

157
inline
158
void CAIEntityPhysical::setWPos(RYAI_MAP_CRUNCH::CWorldPosition const& pos)
159
{
160
	nlassert(pos.isValid());
161
	_wpos = pos;
162
}
163

164
//////////////////////////////////////////////////////////////////////////////
165
// CPersistentOfPhysical                                                    //
166
//////////////////////////////////////////////////////////////////////////////
167

168
inline
169
bool CPersistentOfPhysical::isAt16MetersPos(uint16 x, uint16 y)	const
170
{
171
	CAIEntityPhysical const* phys = getSpawnObj();
172
	if (!phys)
173
		return false;
174
	return (	(uint16)(phys->x().asInt16Meters())==x
175
		&&	(uint16)(phys->y().asInt16Meters())==y	);
176
}
177

178
inline
179
CAIEntityPhysical* CPersistentOfPhysical::getSpawnObj() const
180
{
181
	return	CPersistent<CAIEntityPhysical>::getSpawnObj();
182
}
183

184
//////////////////////////////////////////////////////////////////////////////
185
// CModEntityPhysical                                                       //
186
//////////////////////////////////////////////////////////////////////////////
187

188
inline
189
void CModEntityPhysical::setMode(MBEHAV::EMode m)
190
{
191
	if (_mode().Mode == MBEHAV::DEATH)	//	to remove (can be replaced with the above assertion in debug mode).
192
		return;
193
	
194
	if (_mode().Mode == m)
195
		return;
196
	_mode = MBEHAV::TMode(m, pos().x().asInt(), pos().y().asInt());
197
}
198

199
inline
200
void CModEntityPhysical::setTarget(CAIEntityPhysical* target)
201
{
202
	CTargetable<CAIEntityPhysical>::setTarget(target);
203
//	if (CTargetable<CAIEntityPhysical>::getTarget()==target)
204
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getTarget();
205
	if (tgt==target)
206
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
207
}
208

209
inline
210
void CModEntityPhysical::setVisualTarget(CAIEntityPhysical* target)
211
{
212
	CTargetable<CAIEntityPhysical>::setVisualTarget(target);
213
//	if (CTargetable<CAIEntityPhysical>::getVisualTarget()==target)
214
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getVisualTarget();
215
	if (tgt==target)
216
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
217
}
218

219
inline
220
void CModEntityPhysical::setUnreachableTarget(CAIEntityPhysical* target)
221
{
222
	CTargetable<CAIEntityPhysical>::setUnreachableTarget(target);
223
//	if (CTargetable<CAIEntityPhysical>::getUnreachableTarget()==target)
224
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getUnreachableTarget();
225
	if (tgt==target)
226
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
227
}
228

229
inline
230
bool CModEntityPhysical::setPos(CAIPos const& pos)
231
{
232
	RYAI_MAP_CRUNCH::CWorldPosition	wpos;
233
	if	(!CWorldContainer::getWorldMap().setWorldPosition(AITYPES::vp_auto, wpos,pos))
234
		return	false;
235
	setPos(pos, wpos);
236
	return	true;
237
}	
238

239
inline
240
bool CModEntityPhysical::moveTo(CAIPos const& newPos, RYAI_MAP_CRUNCH::TAStarFlag const& denyFlags)
241
{
242
	if (!wpos().isValid())
243
		return false;
244
	
245
	RYAI_MAP_CRUNCH::CWorldPosition	tmpWPos(wpos());
246
	if (CWorldContainer::getWorldMap().move(tmpWPos, RYAI_MAP_CRUNCH::CMapPosition(newPos), denyFlags))
247
	{
248
#ifdef NL_DEBUG
249
		nlassert(RYAI_MAP_CRUNCH::CMapPosition(newPos)==tmpWPos);
250
#endif
251
		setPos(newPos, tmpWPos);
252
		return true;
253
	}
254
	else
255
	{
256
		//	a part of move has been done.
257
		if (tmpWPos!=wpos())
258
		{
259
			CAIPos partNewPos(tmpWPos.toAIVector(),newPos.h(),newPos.theta());
260
			setPos(partNewPos, tmpWPos);
261
			return true;
262
		}
263
		
264
	}
265
	//	no move at all..
266
	return false;
267
};
268

269
inline
270
void CModEntityPhysical::resetDecalage()
271
{
272
	_Decalage.setXY(0, 0);
273
}
274

275
//////////////////////////////////////////////////////////////////////////////
276
// CWorldMapLink                                                            //
277
//////////////////////////////////////////////////////////////////////////////
278

279
template <class T>
280
void CWorldMapLink<T>::linkEntityToMatrix(const CAICoord &x,const CAICoord &y,CAIEntityMatrix<T>& matrix)
281
{
282
	_matrixListLink.link(matrix[(uint8)(y.asInt16Meters())][(uint8)(x.asInt16Meters())]);
283
}
284

285
template <class T>
286
void CWorldMapLink<T>::linkEntityToMatrix(const CAIVectorMirror &pos,CAIEntityMatrix<T>& matrix)
287
{
288
	linkEntityToMatrix(pos.x(),pos.y(),matrix);
289
}
290

291
template <class T>
292
void CWorldMapLink<T>::linkEntityToMatrix(const CAIVector &pos,CAIEntityMatrix<T>& matrix)
293
{
294
	linkEntityToMatrix(pos.x(),pos.y(),matrix);
295
}
296

297
template <class T>
298
void CWorldMapLink<T>::linkToWorldMap(T *entityPtr, const	CAIVector	&pos,CAIEntityMatrix<T>& matrix)
299
{
300
	_matrixListLink.setEntity	(entityPtr);
301
	linkEntityToMatrix			(pos,matrix);
302
}
303

304
template <class T>
305
void CWorldMapLink<T>::linkToWorldMap(T *entityPtr, const	CAIVectorMirror	&pos,CAIEntityMatrix<T>& matrix)
306
{
307
	_matrixListLink.setEntity	(entityPtr);
308
	linkEntityToMatrix			(pos,matrix);
309
}
310

311
//////////////////////////////////////////////////////////////////////////////
312
// CTargetable                                                              //
313
//////////////////////////////////////////////////////////////////////////////
314

315
template <class T>
316
CTargetable<T>::CTargetable()
317
: _FightTargetersWeight(0.f)
318
, _FightTargetersValue(0.f)
319
{
320
	for	(size_t i=0; i<TARGET_TYPE_MAX; ++i)
321
	{
322
		_TargeterCount[i] = 0;
323
		_FirstTargeters[i] = (T*)NULL;
324
	}
325
	_Target = (T*)NULL;
326
	_TargetType = TARGET_TYPE_FIGHT;
327
	_NextTargeter = (T*)NULL;
328
}
329

330
template <class T>
331
CTargetable<T>::~CTargetable()
332
{
333
	// This should be done in Derived class dtor, but just in case of since we're instanciable
334
	detachFromTargeting();
335
}
336

337
template <class T>
338
void CTargetable<T>::detachFromTargeters()
339
{
340
	for	(size_t i=0; i<TARGET_TYPE_MAX; ++i)
341
	{
342
		while (!_FirstTargeters[i].isNULL())
343
		{
344
			TPtr targeter = _FirstTargeters[i];
345
			targeter->targetDied();
346
			// This method is a bit more intrusive than targeter->setTarget(NULL), but it avoids possible infinite loops
347
			_FirstTargeters[i] = targeter->_NextTargeter;
348
			unlinkTargeter((TTargetType)i, targeter);
349
		}
350
	}
351
}
352

353
template <class T>
354
void CTargetable<T>::detachFromTargeting()
355
{
356
	setTarget((T*)NULL);
357
	detachFromTargeters();
358
}
359

360
template <class T>
361
void CTargetable<T>::linkTargeter(TTargetType type, TPtr const& targeter, TPtr const& nextTargeter)
362
{
363
	++_TargeterCount[type];
364
	if (type==TARGET_TYPE_FIGHT)
365
	{
366
		_FightTargetersWeight += targeter->fightWeight();
367
		_FightTargetersValue += targeter->fightValue();
368
	}
369
	targeter->_Target = dynamic_cast<T*>(this);
370
	targeter->_TargetType = type;
371
	targeter->_NextTargeter = nextTargeter;
372
	// Some verifications to avoid algorithm bugs
373
//	nlassert(fightTargetersFreeWeight()>=-0.00001f);
374
	nlassert(!targeter->_Target.isNULL());
375
}
376

377
template <class T>
378
void CTargetable<T>::unlinkTargeter(TTargetType type, TPtr const& targeter)
379
{
380
#ifdef NL_DEBUG
381
	nlassert((T*)targeter->_Target == this);
382
#else
383
	if ((T*)targeter->_Target != this)
384
		nlwarning("Targeter's target is not me!");
385
#endif
386
	targeter->_Target = (T*)NULL;
387
	targeter->_NextTargeter = (T*)NULL;
388
	--_TargeterCount[type];
389
	if (type==TARGET_TYPE_FIGHT)
390
	{
391
		_FightTargetersWeight -= targeter->fightWeight();
392
		_FightTargetersValue -= targeter->fightValue();
393
	}
394
}
395

396
template <class T>
397
void CTargetable<T>::addTargeter(TTargetType type, TPtr const& targeter)
398
{
399
	linkTargeter(type, targeter, _FirstTargeters[type]);
400
	_FirstTargeters[type] = targeter;
401
}
402

403
template <class T>
404
void CTargetable<T>::removeTargeter(TTargetType type, TPtr const& targeter)
405
{
406
	if (targeter.isNULL())
407
		return;
408
	if (_FirstTargeters[type] == targeter)
409
	{
410
		_FirstTargeters[type] = targeter->_NextTargeter;
411
		unlinkTargeter(type, targeter);
412
		return;
413
	}
414
	
415
	NLMISC::CDbgPtr<T> current = _FirstTargeters[type];
416
	while (!current.isNULL()) {
417
		NLMISC::CDbgPtr<T> next = current->_NextTargeter;
418
		if (next == targeter)
419
		{
420
			current->_NextTargeter = targeter->_NextTargeter;
421
			unlinkTargeter(type, targeter);
422
			break;
423
		}
424
		else
425
		{
426
			current = next;
427
		}
428
	}
429
}
430

431
template <class T>
432
void CTargetable<T>::tryToAddTargeter(TTargetType type, TPtr const& targeter)
433
{
434
	H_AUTO(CTargetable_addTargeter);
435

436
	if (type==TARGET_TYPE_FIGHT)
437
	{
438
	
439
	// Prepare data to optimize ----------------------------------------------
440
	size_t opponentCount = targeterCount();
441
	// Allocate arrays filled with 0.f
442
	float* weights = new float[opponentCount+1];
443
	float* values = new float[opponentCount+1];
444
	bool* take = new bool[opponentCount+1];
445
	for (size_t i=0; i<opponentCount+1; ++i)
446
	{
447
		weights[i] = 0.f;
448
		values[i] = 0.f;
449
		take[i] = false;
450
	}
451
	{
452
		H_AUTO(addTargeterInfoRetr);
453
		// Fill with the former opponents
454
		T* opponent = firstTargeter();
455
		size_t i = 0;
456
		while (opponent!=NULL)
457
		{
458
			weights[i] = opponent->fightWeight();
459
			values[i] = opponent->fightValue();
460
			opponent = opponent->nextTargeter();
461
			take[i] = true;
462
			++i;
463
		}
464
		// Add the new targeter
465
		weights[opponentCount] = targeter->fightWeight();
466
		values[opponentCount] = targeter->fightValue();
467
		take[opponentCount] = false;
468
	}
469
	// Create the context
470
	CKnapsackContext context(opponentCount+1, weights, values);
471
	// Configure and run the solver ------------------------------------------
472
	CKnapsackSolver solver(&context, take);
473
	{
474
		H_AUTO(addTargeterOptimize);
475
		solver.optimize(fightTargetersWeightMax(), _TargeterChoiceAlgorithm);
476
	}
477
	// Save the data ---------------------------------------------------------
478
	// If the new set is better than the old one
479
	if (solver.totalValue()>fightTargetersValue())
480
	{
481
		// Unlink the old ones if needed
482
		T* opponent = _FirstTargeters[type];
483
		TPtr* previousPtr = &_FirstTargeters[type];
484
		size_t i = 0;
485
		while (opponent!=NULL)
486
		{
487
			if (!solver.take(i))
488
			{
489
				*previousPtr = opponent->_NextTargeter;
490
				unlinkTargeter(type, opponent);
491
			}
492
			else
493
			{
494
				previousPtr = &opponent->_NextTargeter;
495
				opponent = opponent->_NextTargeter;
496
			}
497
			++i;
498
		}
499
		// Link the new targeter if needed
500
		if (solver.take(opponentCount))
501
		{
502
			addTargeter(type, targeter);
503
		}
504
#ifdef NL_DEBUG
505
		// Debug verifications
506
		{
507
			opponent = _FirstTargeters[type];
508
			float value = 0.f;
509
			float weight = 0.f;
510
			while (opponent!=NULL)
511
			{
512
				value += opponent->fightValue();
513
				weight += opponent->fightWeight();
514
				opponent = opponent->_NextTargeter;
515
			}
516
			// Verify linking system
517
			nlassert(fabs(fightTargetersValue() - value) < 0.0001);
518
			nlassert(fabs(fightTargetersWeight() - weight) < 0.0001);
519
			
520
			// Verify solver behaviour
521
			nlassert(fabs(fightTargetersValue() - solver.totalValue()) < 0.0001);
522
			nlassert(fabs(fightTargetersWeight() - solver.totalWeight()) < 0.0001);
523
		}
524
#endif
525
	}
526
	delete [] take;
527
	delete [] values;
528
	delete [] weights;
529
	
530
	}
531
	else
532
	{
533
		// Just link the new targeter (no limit on visual targeters)
534
		addTargeter(type, targeter);
535
	}
536
}
537

538
template <class T>
539
void CTargetable<T>::setTarget(T* target)
540
{
541
	setTarget(TARGET_TYPE_FIGHT, target);
542
}
543

544
template <class T>
545
void CTargetable<T>::setVisualTarget(T* target)
546
{
547
	setTarget(TARGET_TYPE_VISUAL, target);
548
}
549

550
template <class T>
551
void CTargetable<T>::setUnreachableTarget(T* target)
552
{
553
	setTarget(TARGET_TYPE_UNREACHABLE, target);
554
}
555

556
template <class T>
557
void CTargetable<T>::setTarget(TTargetType type, TPtr const& target)
558
{
559
	if (target==_Target && type==_TargetType)
560
		return;
561
	
562
	if (!_Target.isNULL())
563
	{
564
		_Target->removeTargeter(_TargetType, dynamic_cast<T*>(this));
565
	}
566
	if (!target.isNULL())
567
	{
568
		target->tryToAddTargeter(type, dynamic_cast<T*>(this));
569
	}
570
}
571

572
template <class T>
573
typename CTargetable<T>::TPtr CTargetable<T>::getTarget() const
574
{
575
	return getTarget(TARGET_TYPE_FIGHT);
576
}
577

578
template <class T>
579
typename CTargetable<T>::TPtr CTargetable<T>::getVisualTarget() const
580
{
581
	return getTarget(TARGET_TYPE_VISUAL);
582
}
583

584
template <class T>
585
typename CTargetable<T>::TPtr CTargetable<T>::getUnreachableTarget() const
586
{
587
	return getTarget(TARGET_TYPE_UNREACHABLE);
588
}
589

590
template <class T>
591
typename CTargetable<T>::TPtr CTargetable<T>::getTarget(TTargetType type) const
592
{
593
	if (_TargetType==type)
594
		return _Target;
595
	else
596
		return (T*)NULL;
597
}
598

599
template <class T>
600
uint32 CTargetable<T>::totalTargeterCount() const
601
{
602
	uint32 count = 0;
603
	for (size_t i = 0; i<TARGET_TYPE_MAX; ++i)
604
		count += _TargeterCount[i];
605
	return count;
606
}
607

608
//----------------------------------------------------------------------------
609

610
#endif
611

1
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2
// Copyright (C) 2010  Winch Gate Property Limited
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU Affero General Public License as
6
// published by the Free Software Foundation, either version 3 of the
7
// License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU Affero General Public License for more details.
13
//
14
// You should have received a copy of the GNU Affero General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

17

18

19

20
#ifndef RYAI_ENTITY_PHYSICAL_INLINE_H
21
#define RYAI_ENTITY_PHYSICAL_INLINE_H
22

23
#include "ai.h"
24
#include "game_share/fame.h"
25
/*
26

27
  The following base class is the common parent of bots, plrs and any other
28
  physical object that has an existance in the world
29

30
*/
31

32
//////////////////////////////////////////////////////////////////////////////
33
// CAIEntityPhysical                                                        //
34
//////////////////////////////////////////////////////////////////////////////
35

36
#ifdef NL_OS_WINDOWS
37
#pragma warning (push)
38
#pragma warning (disable : 4355)
39
#endif
40

41
inline
42
CAIEntityPhysical::CAIEntityPhysical(CPersistentOfPhysical& owner, TDataSetRow const& entityIndex, NLMISC::CEntityId const& id, float radius, uint32 level, RYAI_MAP_CRUNCH::TAStarFlag const& AStarFlags)
43
: CAIEntity()
44
, CSpawnable<CPersistentOfPhysical >(owner)
45
, _pos(entityIndex)
46
, _dataSetRow(entityIndex)
47
, _Stuned(0)
48
, _Rooted(0)
49
, _Blinded(0)
50
, _Feared(0)
51
//, _UnreachableTarget((CAIEntityPhysical*)NULL)
52
, _id(id)
53
, _radius(radius)
54
, _food(_radius)
55
, _Level(level)
56
, _AStarFlags(AStarFlags)
57
{
58
	_instanceNumber.init(*CMirrors::DataSet, entityIndex, DSPropertyAI_INSTANCE);
59
	_mode.init			(*CMirrors::DataSet, entityIndex, DSPropertyMODE);
60
	_behaviour.init		(*CMirrors::DataSet, entityIndex, DSPropertyBEHAVIOUR);
61
	_targetRow.init		(*CMirrors::DataSet, entityIndex, DSPropertyTARGET_ID);
62
	_ActionFlags.init	(*CMirrors::DataSet, entityIndex, DSPropertyACTION_FLAGS);
63

64
	_RunSpeed.init		(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_RUN_SPEED);
65
	_WalkSpeed.init		(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_WALK_SPEED);
66
	
67
	_CurrentHitPoint.init	(*CMirrors::DataSet, entityIndex, DSPropertyCURRENT_HIT_POINTS);
68
	_MaxHitPoint.init		(*CMirrors::DataSet, entityIndex, DSPropertyMAX_HIT_POINTS);
69
	_VisionCounter.init		(*CMirrors::DataSet, entityIndex, DSPropertyVISION_COUNTER);
70
	_InOutpostAlias.init	(*CMirrors::DataSet, entityIndex, DSPropertyIN_OUTPOST_ZONE_ALIAS);
71
	_InOutpostSide.init		(*CMirrors::DataSet, entityIndex, DSPropertyIN_OUTPOST_ZONE_SIDE);
72

73
#ifdef NL_DEBUG
74
	const NLMISC::CDbgRefCount<CAIEntityPhysical>	&ref=*(static_cast<NLMISC::CDbgRefCount<CAIEntityPhysical> * const>(this));
75
	NLMISC::CDbgPtr<CAIEntityPhysical>	dummyPtr;
76
	
77
	nlassert(ref.getDbgRef(dummyPtr)==0);
78
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(entityIndex.getIndex())==CAIS::instance()._CAIEntityByDataSetRow.end());
79
	ref.setCheckMax(false);
80
#endif
81
	CAIS::instance()._CAIEntityByDataSetRow.insert(std::make_pair(entityIndex.getIndex(),this));	//	we don't want to register players.	
82
#ifdef NL_DEBUG
83
	ref.setCheckMax(true);
84
	nlassert(ref.getDbgRef(dummyPtr)==1);
85
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(entityIndex.getIndex())!=CAIS::instance()._CAIEntityByDataSetRow.end());
86
#endif
87

88
	CAIEntityPhysicalLocator::getInstance()->addEntity(_dataSetRow, _id, this);
89
}
90

91
inline
92
CAIEntityPhysical::~CAIEntityPhysical()
93
{
94
	CAIEntityPhysicalLocator::getInstance()->delEntity(_dataSetRow, _id, this);
95
	
96
#ifdef NL_DEBUG
97
	const NLMISC::CDbgRefCount<CAIEntityPhysical>	&ref=*(static_cast<NLMISC::CDbgRefCount<CAIEntityPhysical> * const>(this));
98
	NLMISC::CDbgPtr<CAIEntityPhysical>	dummyPtr;	
99
#endif
100

101
	// Remove healers
102
	std::multiset<IAIEntityPhysicalHealer*>::iterator it, itEnd;
103
	for (it=_Healers.begin(), itEnd=_Healers.end(); it!=itEnd; ++it)
104
	{
105
		(*it)->healerRemoved(this);
106
	}
107
	
108
	detachFromTargeting();
109
	CAIS::instance()._CAIEntityByDataSetRow.erase(dataSetRow().getIndex());
110

111
#ifdef NL_DEBUG
112
	nlassert(ref.getDbgRef(dummyPtr)==0);
113
	nlassert(CAIS::instance()._CAIEntityByDataSetRow.find(dataSetRow().getIndex())==CAIS::instance()._CAIEntityByDataSetRow.end());
114
#endif
115
}
116

117
#ifdef NL_OS_WINDOWS
118
#pragma warning (pop)
119
#endif
120

121
inline
122
void CAIEntityPhysical::setActionFlags(RYZOMACTIONFLAGS::TActionFlag const& flag)
123
{
124
	_ActionFlags = (_ActionFlags.getValue() | flag );
125
}
126

127
inline
128
void CAIEntityPhysical::removeActionFlags(RYZOMACTIONFLAGS::TActionFlag const& flag)
129
{
130
	_ActionFlags = (_ActionFlags.getValue() & ~flag );
131
}
132

133
inline
134
float CAIEntityPhysical::getCollisionDist(float angTo) const
135
{
136
	return 0.5;
137
}
138

139
inline
140
bool CAIEntityPhysical::canMove() const
141
{
142
	return !isRooted() && (walkSpeed() != 0);
143
}
144

145
inline
146
float CAIEntityPhysical::walkSpeed() const
147
{
148
	return _WalkSpeed()*0.1f*SpeedFactor*getSpeedFactor();
149
}
150

151
inline
152
float CAIEntityPhysical::runSpeed() const
153
{
154
	return _RunSpeed()*0.1f*SpeedFactor*getSpeedFactor();
155
}
156

157
inline
158
void CAIEntityPhysical::setWPos(RYAI_MAP_CRUNCH::CWorldPosition const& pos)
159
{
160
	nlassert(pos.isValid());
161
	_wpos = pos;
162
}
163

164
//////////////////////////////////////////////////////////////////////////////
165
// CPersistentOfPhysical                                                    //
166
//////////////////////////////////////////////////////////////////////////////
167

168
inline
169
bool CPersistentOfPhysical::isAt16MetersPos(uint16 x, uint16 y)	const
170
{
171
	CAIEntityPhysical const* phys = getSpawnObj();
172
	if (!phys)
173
		return false;
174
	return (	(uint16)(phys->x().asInt16Meters())==x
175
		&&	(uint16)(phys->y().asInt16Meters())==y	);
176
}
177

178
inline
179
CAIEntityPhysical* CPersistentOfPhysical::getSpawnObj() const
180
{
181
	return	CPersistent<CAIEntityPhysical>::getSpawnObj();
182
}
183

184
//////////////////////////////////////////////////////////////////////////////
185
// CModEntityPhysical                                                       //
186
//////////////////////////////////////////////////////////////////////////////
187

188
inline
189
void CModEntityPhysical::setMode(MBEHAV::EMode m)
190
{
191
	if (_mode().Mode == MBEHAV::DEATH)	//	to remove (can be replaced with the above assertion in debug mode).
192
		return;
193
	
194
	if (_mode().Mode == m)
195
		return;
196
	_mode = MBEHAV::TMode(m, pos().x().asInt(), pos().y().asInt());
197
}
198

199
inline
200
void CModEntityPhysical::setTarget(CAIEntityPhysical* target)
201
{
202
	CTargetable<CAIEntityPhysical>::setTarget(target);
203
//	if (CTargetable<CAIEntityPhysical>::getTarget()==target)
204
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getTarget();
205
	if (tgt==target)
206
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
207
}
208

209
inline
210
void CModEntityPhysical::setVisualTarget(CAIEntityPhysical* target)
211
{
212
	CTargetable<CAIEntityPhysical>::setVisualTarget(target);
213
//	if (CTargetable<CAIEntityPhysical>::getVisualTarget()==target)
214
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getVisualTarget();
215
	if (tgt==target)
216
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
217
}
218

219
inline
220
void CModEntityPhysical::setUnreachableTarget(CAIEntityPhysical* target)
221
{
222
	CTargetable<CAIEntityPhysical>::setUnreachableTarget(target);
223
//	if (CTargetable<CAIEntityPhysical>::getUnreachableTarget()==target)
224
	const CAIEntityPhysical* tgt=CTargetable<CAIEntityPhysical>::getUnreachableTarget();
225
	if (tgt==target)
226
		_targetRow = target ? target->dataSetRow() : TDataSetRow();
227
}
228

229
inline
230
bool CModEntityPhysical::setPos(CAIPos const& pos)
231
{
232
	RYAI_MAP_CRUNCH::CWorldPosition	wpos;
233
	if	(!CWorldContainer::getWorldMap().setWorldPosition(AITYPES::vp_auto, wpos,pos))
234
		return	false;
235
	setPos(pos, wpos);
236
	return	true;
237
}	
238

239
inline
240
bool CModEntityPhysical::moveTo(CAIPos const& newPos, RYAI_MAP_CRUNCH::TAStarFlag const& denyFlags)
241
{
242
	if (!wpos().isValid())
243
		return false;
244
	
245
	RYAI_MAP_CRUNCH::CWorldPosition	tmpWPos(wpos());
246
	if (CWorldContainer::getWorldMap().move(tmpWPos, RYAI_MAP_CRUNCH::CMapPosition(newPos), denyFlags))
247
	{
248
#ifdef NL_DEBUG
249
		nlassert(RYAI_MAP_CRUNCH::CMapPosition(newPos)==tmpWPos);
250
#endif
251
		setPos(newPos, tmpWPos);
252
		return true;
253
	}
254
	else
255
	{
256
		//	a part of move has been done.
257
		if (tmpWPos!=wpos())
258
		{
259
			CAIPos partNewPos(tmpWPos.toAIVector(),newPos.h(),newPos.theta());
260
			setPos(partNewPos, tmpWPos);
261
			return true;
262
		}
263
		
264
	}
265
	//	no move at all..
266
	return false;
267
};
268

269
inline
270
void CModEntityPhysical::resetDecalage()
271
{
272
	_Decalage.setXY(0, 0);
273
}
274

275
//////////////////////////////////////////////////////////////////////////////
276
// CWorldMapLink                                                            //
277
//////////////////////////////////////////////////////////////////////////////
278

279
template <class T>
280
void CWorldMapLink<T>::linkEntityToMatrix(const CAICoord &x,const CAICoord &y,CAIEntityMatrix<T>& matrix)
281
{
282
	_matrixListLink.link(matrix[(uint8)(y.asInt16Meters())][(uint8)(x.asInt16Meters())]);
283
}
284

285
template <class T>
286
void CWorldMapLink<T>::linkEntityToMatrix(const CAIVectorMirror &pos,CAIEntityMatrix<T>& matrix)
287
{
288
	linkEntityToMatrix(pos.x(),pos.y(),matrix);
289
}
290

291
template <class T>
292
void CWorldMapLink<T>::linkEntityToMatrix(const CAIVector &pos,CAIEntityMatrix<T>& matrix)
293
{
294
	linkEntityToMatrix(pos.x(),pos.y(),matrix);
295
}
296

297
template <class T>
298
void CWorldMapLink<T>::linkToWorldMap(T *entityPtr, const	CAIVector	&pos,CAIEntityMatrix<T>& matrix)
299
{
300
	_matrixListLink.setEntity	(entityPtr);
301
	linkEntityToMatrix			(pos,matrix);
302
}
303

304
template <class T>
305
void CWorldMapLink<T>::linkToWorldMap(T *entityPtr, const	CAIVectorMirror	&pos,CAIEntityMatrix<T>& matrix)
306
{
307
	_matrixListLink.setEntity	(entityPtr);
308
	linkEntityToMatrix			(pos,matrix);
309
}
310

311
//////////////////////////////////////////////////////////////////////////////
312
// CTargetable                                                              //
313
//////////////////////////////////////////////////////////////////////////////
314

315
template <class T>
316
CTargetable<T>::CTargetable()
317
: _FightTargetersWeight(0.f)
318
, _FightTargetersValue(0.f)
319
{
320
	for	(size_t i=0; i<TARGET_TYPE_MAX; ++i)
321
	{
322
		_TargeterCount[i] = 0;
323
		_FirstTargeters[i] = (T*)NULL;
324
	}
325
	_Target = (T*)NULL;
326
	_TargetType = TARGET_TYPE_FIGHT;
327
	_NextTargeter = (T*)NULL;
328
}
329

330
template <class T>
331
CTargetable<T>::~CTargetable()
332
{
333
	// This should be done in Derived class dtor, but just in case of since we're instanciable
334
	detachFromTargeting();
335
}
336

337
template <class T>
338
void CTargetable<T>::detachFromTargeters()
339
{
340
	for	(size_t i=0; i<TARGET_TYPE_MAX; ++i)
341
	{
342
		while (!_FirstTargeters[i].isNULL())
343
		{
344
			TPtr targeter = _FirstTargeters[i];
345
			targeter->targetDied();
346
			// This method is a bit more intrusive than targeter->setTarget(NULL), but it avoids possible infinite loops
347
			_FirstTargeters[i] = targeter->_NextTargeter;
348
			unlinkTargeter((TTargetType)i, targeter);
349
		}
350
	}
351
}
352

353
template <class T>
354
void CTargetable<T>::detachFromTargeting()
355
{
356
	setTarget((T*)NULL);
357
	detachFromTargeters();
358
}
359

360
template <class T>
361
void CTargetable<T>::linkTargeter(TTargetType type, TPtr const& targeter, TPtr const& nextTargeter)
362
{
363
	++_TargeterCount[type];
364
	if (type==TARGET_TYPE_FIGHT)
365
	{
366
		_FightTargetersWeight += targeter->fightWeight();
367
		_FightTargetersValue += targeter->fightValue();
368
	}
369
	targeter->_Target = dynamic_cast<T*>(this);
370
	targeter->_TargetType = type;
371
	targeter->_NextTargeter = nextTargeter;
372
	// Some verifications to avoid algorithm bugs
373
//	nlassert(fightTargetersFreeWeight()>=-0.00001f);
374
	nlassert(!targeter->_Target.isNULL());
375
}
376

377
template <class T>
378
void CTargetable<T>::unlinkTargeter(TTargetType type, TPtr const& targeter)
379
{
380
#ifdef NL_DEBUG
381
	nlassert((T*)targeter->_Target == this);
382
#else
383
	if ((T*)targeter->_Target != this)
384
		nlwarning("Targeter's target is not me!");
385
#endif
386
	targeter->_Target = (T*)NULL;
387
	targeter->_NextTargeter = (T*)NULL;
388
	--_TargeterCount[type];
389
	if (type==TARGET_TYPE_FIGHT)
390
	{
391
		_FightTargetersWeight -= targeter->fightWeight();
392
		_FightTargetersValue -= targeter->fightValue();
393
	}
394
}
395

396
template <class T>
397
void CTargetable<T>::addTargeter(TTargetType type, TPtr const& targeter)
398
{
399
	linkTargeter(type, targeter, _FirstTargeters[type]);
400
	_FirstTargeters[type] = targeter;
401
}
402

403
template <class T>
404
void CTargetable<T>::removeTargeter(TTargetType type, TPtr const& targeter)
405
{
406
	if (targeter.isNULL())
407
		return;
408
	if (_FirstTargeters[type] == targeter)
409
	{
410
		_FirstTargeters[type] = targeter->_NextTargeter;
411
		unlinkTargeter(type, targeter);
412
		return;
413
	}
414
	
415
	NLMISC::CDbgPtr<T> current = _FirstTargeters[type];
416
	while (!current.isNULL()) {
417
		NLMISC::CDbgPtr<T> next = current->_NextTargeter;
418
		if (next == targeter)
419
		{
420
			current->_NextTargeter = targeter->_NextTargeter;
421
			unlinkTargeter(type, targeter);
422
			break;
423
		}
424
		else
425
		{
426
			current = next;
427
		}
428
	}
429
}
430

431
template <class T>
432
void CTargetable<T>::tryToAddTargeter(TTargetType type, TPtr const& targeter)
433
{
434
	H_AUTO(CTargetable_addTargeter);
435

436
	if (type==TARGET_TYPE_FIGHT)
437
	{
438
	
439
	// Prepare data to optimize ----------------------------------------------
440
	size_t opponentCount = targeterCount();
441
	// Allocate arrays filled with 0.f
442
	float* weights = new float[opponentCount+1];
443
	float* values = new float[opponentCount+1];
444
	bool* take = new bool[opponentCount+1];
445
	for (size_t i=0; i<opponentCount+1; ++i)
446
	{
447
		weights[i] = 0.f;
448
		values[i] = 0.f;
449
		take[i] = false;
450
	}
451
	{
452
		H_AUTO(addTargeterInfoRetr);
453
		// Fill with the former opponents
454
		T* opponent = firstTargeter();
455
		size_t i = 0;
456
		while (opponent!=NULL)
457
		{
458
			weights[i] = opponent->fightWeight();
459
			values[i] = opponent->fightValue();
460
			opponent = opponent->nextTargeter();
461
			take[i] = true;
462
			++i;
463
		}
464
		// Add the new targeter
465
		weights[opponentCount] = targeter->fightWeight();
466
		values[opponentCount] = targeter->fightValue();
467
		take[opponentCount] = false;
468
	}
469
	// Create the context
470
	CKnapsackContext context(opponentCount+1, weights, values);
471
	// Configure and run the solver ------------------------------------------
472
	CKnapsackSolver solver(&context, take);
473
	{
474
		H_AUTO(addTargeterOptimize);
475
		solver.optimize(fightTargetersWeightMax(), _TargeterChoiceAlgorithm);
476
	}
477
	// Save the data ---------------------------------------------------------
478
	// If the new set is better than the old one
479
	if (solver.totalValue()>fightTargetersValue())
480
	{
481
		// Unlink the old ones if needed
482
		T* opponent = _FirstTargeters[type];
483
		TPtr* previousPtr = &_FirstTargeters[type];
484
		size_t i = 0;
485
		while (opponent!=NULL)
486
		{
487
			if (!solver.take(i))
488
			{
489
				*previousPtr = opponent->_NextTargeter;
490
				unlinkTargeter(type, opponent);
491
			}
492
			else
493
			{
494
				previousPtr = &opponent->_NextTargeter;
495
				opponent = opponent->_NextTargeter;
496
			}
497
			++i;
498
		}
499
		// Link the new targeter if needed
500
		if (solver.take(opponentCount))
501
		{
502
			addTargeter(type, targeter);
503
		}
504
#ifdef NL_DEBUG
505
		// Debug verifications
506
		{
507
			opponent = _FirstTargeters[type];
508
			float value = 0.f;
509
			float weight = 0.f;
510
			while (opponent!=NULL)
511
			{
512
				value += opponent->fightValue();
513
				weight += opponent->fightWeight();
514
				opponent = opponent->_NextTargeter;
515
			}
516
			// Verify linking system
517
			nlassert(fabs(fightTargetersValue() - value) < 0.0001);
518
			nlassert(fabs(fightTargetersWeight() - weight) < 0.0001);
519
			
520
			// Verify solver behaviour
521
			nlassert(fabs(fightTargetersValue() - solver.totalValue()) < 0.0001);
522
			nlassert(fabs(fightTargetersWeight() - solver.totalWeight()) < 0.0001);
523
		}
524
#endif
525
	}
526
	delete [] take;
527
	delete [] values;
528
	delete [] weights;
529
	
530
	}
531
	else
532
	{
533
		// Just link the new targeter (no limit on visual targeters)
534
		addTargeter(type, targeter);
535
	}
536
}
537

538
template <class T>
539
void CTargetable<T>::setTarget(T* target)
540
{
541
	setTarget(TARGET_TYPE_FIGHT, target);
542
}
543

544
template <class T>
545
void CTargetable<T>::setVisualTarget(T* target)
546
{
547
	setTarget(TARGET_TYPE_VISUAL, target);
548
}
549

550
template <class T>
551
void CTargetable<T>::setUnreachableTarget(T* target)
552
{
553
	setTarget(TARGET_TYPE_UNREACHABLE, target);
554
}
555

556
template <class T>
557
void CTargetable<T>::setTarget(TTargetType type, TPtr const& target)
558
{
559
	if (target==_Target && type==_TargetType)
560
		return;
561
	
562
	if (!_Target.isNULL())
563
	{
564
		_Target->removeTargeter(_TargetType, dynamic_cast<T*>(this));
565
	}
566
	if (!target.isNULL())
567
	{
568
		target->tryToAddTargeter(type, dynamic_cast<T*>(this));
569
	}
570
}
571

572
template <class T>
573
typename CTargetable<T>::TPtr CTargetable<T>::getTarget() const
574
{
575
	return getTarget(TARGET_TYPE_FIGHT);
576
}
577

578
template <class T>
579
typename CTargetable<T>::TPtr CTargetable<T>::getVisualTarget() const
580
{
581
	return getTarget(TARGET_TYPE_VISUAL);
582
}
583

584
template <class T>
585
typename CTargetable<T>::TPtr CTargetable<T>::getUnreachableTarget() const
586
{
587
	return getTarget(TARGET_TYPE_UNREACHABLE);
588
}
589

590
template <class T>
591
typename CTargetable<T>::TPtr CTargetable<T>::getTarget(TTargetType type) const
592
{
593
	if (_TargetType==type)
594
		return _Target;
595
	else
596
		return (T*)NULL;
597
}
598

599
template <class T>
600
uint32 CTargetable<T>::totalTargeterCount() const
601
{
602
	uint32 count = 0;
603
	for (size_t i = 0; i<TARGET_TYPE_MAX; ++i)
604
		count += _TargeterCount[i];
605
	return count;
606
}
607

608
//----------------------------------------------------------------------------
609

610
#endif
611

b/code/ryzom/server/src/ai_service/ai_generic_fight.cpp Wed Sep 22 11:00:19 2010 +0200
67 67

68 68
CBotProfileFight::CBotProfileFight(CProfileOwner* owner, CAIEntityPhysical* ennemy)
69 69
: CBotProfileFightHeal()
70
, _Bot(NLMISC::safe_cast<CSpawnBot*>(owner))
70 71
, _Ennemy(ennemy)
71
, _Bot(NLMISC::safe_cast<CSpawnBot*>(owner))
72 72
, _PathPos(NLMISC::safe_cast<CSpawnBot*>(owner)->theta())
73
, _PathCont(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
73 74
, _RangeCalculated(false)
74 75
, _SearchAlternativePath(false)
75
, _PathCont(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
76 76
{
77 77
#ifdef NL_DEBUG_PTR
78 78
	_Bot.setData(this);
......
226 226

227 227
CBotProfileHeal::CBotProfileHeal(const TDataSetRow	&row, CProfileOwner *owner)
228 228
: CBotProfileFightHeal()
229
, _Row(row)
230 229
, _Bot(NLMISC::safe_cast<CSpawnBot*>(owner))
231 230
, _PathPos(NLMISC::safe_cast<CSpawnBot*>(owner)->theta())
231
, _PathCont(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
232
, _Row(row)
232 233
, _RangeCalculated(false)
233 234
, _SearchAlternativePath(false)
234
, _PathCont(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
235 235
{
236 236
}
237 237

......
252 252

253 253
CBotProfileFlee::CBotProfileFlee(CProfileOwner *owner)
254 254
: CAIBaseProfile()
255
, _DenyFlags(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
256
, _PathPos(NLMISC::safe_cast<CSpawnBot*>(owner)->theta())
257
, _fightFleePathContainer(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
255 258
, _Bot(NLMISC::safe_cast<CSpawnBot*>(owner))
256
, _PathPos(NLMISC::safe_cast<CSpawnBot*>(owner)->theta())
257
, _DenyFlags(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
258
, _fightFleePathContainer(NLMISC::safe_cast<CSpawnBot*>(owner)->getAStarFlag())
259 259
{
260 260
}
261 261

......
521 521
		if (!entity->isAlive())
522 522
		{
523 523
			if (ai_profile_npc_VerboseLog)
524
			{
524 525
				nldebug("<FIGHT>Entity %s have aggro for dead entity %s, forgetting it.", spawnBot->getEntityId().toString().c_str(), entity->getEntityId().toString().c_str());
526
			}
527

525 528
			spawnBot->forgetAggroFor(entity->dataSetRow());
526 529
			continue;
527 530
		}
528 531
		if (!entity->isBotAttackable())
529 532
		{
530 533
			if (ai_profile_npc_VerboseLog)
534
			{
531 535
				nldebug("<FIGHT>Entity %s have aggro for non bot attackable entity %s, forgetting it.", spawnBot->getEntityId().toString().c_str(), entity->getEntityId().toString().c_str());
536
			}
537

532 538
			spawnBot->forgetAggroFor(entity->dataSetRow());
533 539
			continue;
534 540
		}
b/code/ryzom/server/src/ai_service/ai_profile_npc.cpp Wed Sep 22 11:00:19 2010 +0200
676 676
	else
677 677
	{
678 678
		// look for aggro range parameter or set a default value
679
		float aggroRangeFloat;
679
		float aggroRangeFloat = 0.0;
680

680 681
		if (!_Grp->getProfileParameter("aggro range", aggroRangeFloat))
681 682
			_AggroRange =static_cast<uint32>( CGrpProfileBanditFactory::getDefaultBanditAggroRange() );
682 683
		else
......
991 992
	}
992 993
	
993 994
	string s;
994
	float f;
995
	float f = 0.0;
995 996
	if (_Grp->getProfileParameter("faction", s) && !s.empty())
996 997
	{
997 998
		factionIndex = CStaticFames::getInstance().getFactionIndex(s);
......
1703 1704

1704 1705
CGrpProfileFollowRoute::CGrpProfileFollowRoute(CProfileOwner *owner,const std::vector<CShape::TPosition>	&geometry,const	TVerticalPos	&verticalPos, bool dontSendEvent)
1705 1706
: CMoveProfile(owner)
1707
, _PathCont(NLMISC::safe_cast<CSpawnGroup*>(owner)->getPersistent().getAStarFlag())
1708
, _GeometryComeFromState(false)
1706 1709
, _Geometry(&geometry)
1707
, _GeometryComeFromState(false)
1708 1710
, _VerticalPos(verticalPos)
1709
, _PathCont(NLMISC::safe_cast<CSpawnGroup*>(owner)->getPersistent().getAStarFlag())
1710 1711
, _DontSendEvent(dontSendEvent)
1711 1712
{
1712 1713
	PROFILE_LOG("group", "follow_route", "ctor2", "");
......
2402 2403

2403 2404
CGrpProfileWander::CGrpProfileWander(CProfileOwner* owner, CNpcZone const* npcZone)
2404 2405
: CMoveProfile(owner)
2406
, _Social(false)
2405 2407
, _NpcZone(npcZone)
2406
, _Social(false)
2407 2408
{
2408 2409
	PROFILE_LOG("group", "wander", "ctor", "");
2409 2410
	_BotStandProfileType = BOT_STAND_AT_POS;
......
2748 2749

2749 2750
CGrpProfileWanderNoPrim::CGrpProfileWanderNoPrim(CProfileOwner* owner, NLMISC::CSmartPtr<CNpcZonePlaceNoPrim> const& npcZone)
2750 2751
: CMoveProfile(owner)
2752
, _Social(false)
2751 2753
, _NpcZone(npcZone)
2752
, _Social(false)
2753 2754
{
2754 2755
	PROFILE_LOG("group", "wander", "ctor", "");
2755 2756
	_BotStandProfileType = BOT_STAND_AT_POS;
......
3043 3044
}
3044 3045

3045 3046
CGrpProfileStandAtStartPoint::CBotPositionner::CBotPositionner(TVerticalPos verticalPos, CAIPos position, RYAI_MAP_CRUNCH::TAStarFlag	flag) 
3046
: _BotAtDest(false)
3047
: _PathCont(flag)
3047 3048
, _Position(position)
3048 3049
, _VerticalPos(verticalPos)
3049
, _PathCont(flag)
3050
, _BotAtDest(false)
3050 3051
{
3051 3052
	_PathCont.setDestination(verticalPos, position);
3052 3053
}
......
4019 4020
: CAIBaseProfile()
4020 4021
, _VerticalPos(verticalPos)
4021 4022
, _Dest(dest)
4023
, _PathCont(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->getAStarFlag())
4024
, _PathPos(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->theta())
4022 4025
, _Bot(NLMISC::safe_cast<CSpawnBotNpc*>(owner))
4023
, _PathPos(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->theta())
4024
, _PathCont(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->getAStarFlag())
4025 4026
{
4026 4027
	PROFILE_LOG("bot", "move_to", "ctor", "");
4027 4028
#ifdef NL_DEBUG_PTR
......
4095 4096

4096 4097
CBotProfileFollowPos::CBotProfileFollowPos(CBotProfileFollowPos const& other)
4097 4098
: CAIBaseProfile()
4099
, _PathPos(const_cast<CBotProfileFollowPos&>(other)._PathPos._Angle) // Just to debug...
4100
, _Bot(const_cast<CBotProfileFollowPos&>(other)._Bot)
4098 4101
, _PathCont(const_cast<CBotProfileFollowPos&>(other)._PathCont)
4099
, _Bot(const_cast<CBotProfileFollowPos&>(other)._Bot)
4100 4102
, _MaxWalkSpeed(FLT_MAX)
4101 4103
, _MaxRunSpeed(FLT_MAX)
4102
, _PathPos(const_cast<CBotProfileFollowPos&>(other)._PathPos._Angle) // Just to debug...
4103 4104
, _Stop(false)
4104 4105
{
4105 4106
	PROFILE_LOG("bot", "follow_pos", "ctor", "");
......
4110 4111

4111 4112
CBotProfileFollowPos::CBotProfileFollowPos(CPathCont* pathCont, CProfileOwner* owner)
4112 4113
: CAIBaseProfile()
4114
, _PathPos(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->theta())
4115
, _Bot(NLMISC::safe_cast<CSpawnBotNpc*>(owner))
4113 4116
, _PathCont(pathCont)
4114
, _Bot(NLMISC::safe_cast<CSpawnBotNpc*>(owner))
4115 4117
, _MaxWalkSpeed(FLT_MAX)
4116 4118
, _MaxRunSpeed(FLT_MAX)
4117
, _PathPos(NLMISC::safe_cast<CSpawnBotNpc*>(owner)->theta())
4118 4119
, _Stop(false)
4119 4120
{
4120 4121
	PROFILE_LOG("bot", "follow_pos", "ctor", "");
......
4530 4531
}
4531 4532

4532 4533
CGrpProfileStandOnVertices::CBotPositionner::CBotPositionner(uint32 geomIndex, RYAI_MAP_CRUNCH::TAStarFlag flags)
4533
: _BotAtDest(false)
4534
: _PathCont(flags)
4534 4535
, _GeomIndex(geomIndex)
4535
, _PathCont(flags)
4536
, _BotAtDest(false)
4536 4537
{
4537 4538
}
4538 4539

b/code/ryzom/server/src/ai_service/alias_tree_owner.h Wed Sep 22 11:00:19 2010 +0200
143 143

144 144
inline
145 145
CAliasTreeOwner::CAliasTreeOwner(CAIAliasDescriptionNode* aliasTree)
146
: _AliasTree(aliasTree)
147
, _Alias(0)
146
: _Alias(0)
148 147
, _Name(std::string())
148
, _AliasTree(aliasTree)
149 149
{
150 150
	if (aliasTree)
151 151
	{
......
159 159

160 160
inline
161 161
CAliasTreeOwner::CAliasTreeOwner(uint32	alias, std::string const& name)
162
: _AliasTree(NULL)
163
, _Alias(alias)
162
: _Alias(alias)
164 163
, _Name(name)
164
, _AliasTree(NULL)
165 165
{
166 166
	CAliasTreeOwnerLocator::getInstance()->addEntity(_Alias, _Name, this);
167 167
}
... This diff was truncated because it exceeds the maximum size that can be displayed.