1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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.
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/>.
19 #ifndef NL_HARVEST_SOURCE_H
20 #define NL_HARVEST_SOURCE_H
22 #include "nel/misc/vector_2f.h"
23 #include "game_share/base_types.h"
24 #include "egs_mirror.h"
26 #include "phrase_manager/simple_entity_manager.h"
27 #include "phrase_manager/toxic_cloud.h"
29 class CStaticDepositRawMaterial
;
30 class CRecentForageSite
;
35 namespace VISIBILITY_RIGHTS
46 /// Convert a numeric value to TVisGroup
47 inline TVisGroup
fromInt( uint8 i
)
54 #define _S _RTProps[S]
55 #define _A _RTProps[A]
56 #define _Q _RTProps[Q]
57 #define _D _RTProps[D]
58 #define _E _RTProps[E]
59 #define _C _RTProps[C]
64 * \author Olivier Cado
65 * \author Nevrax France
70 NL_INSTANCE_COUNTER_DECL(CHarvestSource
);
75 S
, NoDrop
=S
, // Source speed (in steps per tick (<1)). Not droppable.
76 A
=1, // Source aperture (RM quantity delivered per step). Request 0 or "care".
77 Q
=2, ReduceDmg
=Q
, // Average quality of the delivered RM
79 D
= NbPosRTProps
, // Level before source is destroyed / deposit is disabled. Request a negative value for "life absorption by player".
80 E
, // Level before damaging events
81 //C, // Level before creature spawn
85 enum TTargetRTProp
// Subset of TRealTimeProp
108 /*enum TStatClassForage
110 BasicPlainAverage, FinePrime, ChoiceSelect, ExcellentSuperb, SupremeMagnificient, NbStatQualities
113 struct CReduceDamageEvent
115 NLMISC::TGameCycle Time
;
119 typedef std::vector
<CReduceDamageEvent
> CRDEvents
;
121 typedef std::vector
<TDataSetRow
> CForagers
;
123 /// Constructor (a source does not need init() if it's only a template source passed to init())
129 // Change the properties (for a template source)
130 void setLifetime( NLMISC::TGameCycle t
) { _LifeTime
= t
; }
131 void setProspectionExtraExtractionTime( NLMISC::TGameCycle t
) { _ExtraExtractionTime
= t
+ _IncludedBonusExtractionTime
; } // Locked is forbidden
132 void setBonusExtraExtractionTime( NLMISC::TGameCycle t
) { _ExtraExtractionTime
+= t
- _IncludedBonusExtractionTime
; _IncludedBonusExtractionTime
= t
; }
133 void setS( float p
) { _S
= p
; }
134 void setA( float p
) { _A
= p
; }
135 void setQ( float p
) { _Q
= p
; }
136 void setD( float p
) { _D
= p
; }
137 void setE( float p
) { _E
= p
; }
138 //void setC( float p ) { _C = p; }
139 void setN( float p
) { _N
= p
; }
140 //void setDistVis( sint32 p ) { _DistanceVisibility = p; }
141 //void setStealthVis( VISIBILITY_RIGHTS::TVisGroup r ) { _StealthVisibility = r; }
143 /// Init the source. All pointers must be valid (but forageSite may be NULL). Return false if the current quantity in the deposit is 0.
144 bool init( const CHarvestSource
& ini
,
145 const NLMISC::CVector2f
& pos
,
146 CRecentForageSite
*forageSite
,
147 CDeposit
*depositForK
,
148 const CStaticDepositRawMaterial
*rmInfo
, float quantityRatio
);
150 /// Set the deposit that has auto-spawned this source (if any). NULL to unlink the curent (if any)
151 void setDepositAutoSpawn(CDeposit
*deposit
);
153 /// Set bonus for quantity ratio
154 void setBonusForA( uint8 percent
) { _BonusForAPct
= percent
; }
157 * Prepare the source as an unpublished entity in mirror. Return false in case of failure.
158 * Must be called *after* init().
159 * prospectorDataSetRow must be either null (isNull()) or an accessible row (isAccessible()).
161 bool spawnBegin( uint8 knowledgePrecision
, const TDataSetRow
& prospectorDataSetRow
, bool isAutoSpawned
);
164 * Complete the source spawn: publish the entity in mirror or delete it
165 * Caution: if authorized, the source object is deleted!
167 void spawnEnd( bool authorized
);
169 /// Tick update. Return false if the source's life is ended.
173 * Begin an extraction action. Once the extraction process is started, the source remains in
174 * extraction mode until the extraction time is elapsed (even if players stop/restart
175 * extracting). Set isNewbie to true if the extractor should have low risks.
176 * Return true if the forager is the extractor (the first one on the source)
178 bool beginExtraction( const TDataSetRow
& forager
, bool isNewbie
=false );
181 * Update the source state with an extraction.
182 * Warning: this can lead to the death of the player (e.g. kami wrath threshold reached)
183 * => player->forageProgress() can become NULL and therefore must be tested.
185 * \param reqPosProps [in/out] Requested positive props (rS, rA, rQ). Can be lowered in output if a drop occurs.
186 * \param absPosProps [in] Absorption ratio (<=1.0f) of positive props (aS, aA, aQ): a higher value reduces the negative impact of the extraction.
187 * \param qualityCeilingFactor [in] Factor for quality target value (relative to reqPosProps[Q])
188 * \param qualitySlowFactor [in] Quality increase speed factor
189 * \param results [in/out] Resulting positive values (S, A, Q). In input, please provide the previous results.
190 * \param successFactor [in] The success factor ratio to be used.
191 * \param lifeAbsorberRatio [in] In not zero, extractingEntityRow will get some damage, converting lifeAbsorberRatio percent of the decrease of D.
192 * \param extractingEntityRow [in] See lifeAbsorberRatio.
193 * negative impact on the source life (D).
194 * \param propDrop [out] NoDrop=all ok; A=quantity drop; Q=quality drop.
196 void extractMaterial( float *reqPosProps
, float *absPosProps
, float qualityCeilingFactor
, float qualitySlowFactor
, float *results
, float successFactor
, uint8 lifeAbsorberRatio
, const TDataSetRow
& extractingEntityRow
, CHarvestSource::TRealTimeProp
& propDrop
);
198 /// Update the source state with a care (DeltaD, DeltaE, DeltaC). Output: isUseful if the care is not from the "begin zone"
199 void takeCare( float *deltas
, bool *isUseful
);
201 /// Reduce the damage of the next blowing up (will work if between ForageReduceDamageTimeWindow and blowing up time)
202 void reduceBlowingUpDmg( float ratio
);
205 static void hitEntity( RYZOMID::TTypeId aggressorType
, CEntityBase
*entity
, sint32 hpDamageAmount
, sint32 hpDamageAmountWithoutArmour
, bool isIntentional
, sint32 hpAvoided
=0 );
207 /// Recalculate the remaining extraction time depending on the requested quality
208 void recalcExtractionTime( float requestedQuality
);
211 * Return the prospector or a null datasetrow if there was no prospection (auto-spawn)
212 * The accessibility of this datasetrow must be checked before use.
214 const TDataSetRow
& getProspectorDataSetRow() const;
217 const NLMISC::CSheetId
& materialSheet() const { return _MaterialSheet
; }
218 const TDataSetRow
& rowId() const { return _DataSetRow
; }
219 const NLMISC::CVector2f
& pos() const { return _Pos
; }
220 float quantity() const { return _N
; }
221 //NLMISC::TGameCycle extractionTime() const { return _ExtractionTime + _ExtraExtractionTime; }
222 const NLMISC::TGameCycle
& timeToLive() const { return _T
; }
223 bool wasProspected() const { return _ExtraExtractionTime
!= 0; }
224 NLMISC::TGameCycle
deliveryPeriod() const { return (NLMISC::TGameCycle
)(1.0f
/ _S
); }
225 float speed() const { return _S
; }
226 float aperture() const { return _A
; }
227 float quality() const { return _Q
; }
228 float maxQuality() const { return _MaxQuality
; }
229 const CRecentForageSite
*forageSite() const { return _ForageSite
; }
230 CDeposit
*depositForK() const { return _DepositForK
; }
231 bool isExtractionInProgress() const { return _IsExtractionInProgress
; }
232 uint8
nbEventTriggered() const { return _NbEventTriggered
; }
233 const CForagers
& foragers() const { return _Foragers
; }
235 /// Return the stat quality of the raw material [0..100]
236 uint16
getStatQuality() const;
238 // Accessors for testing
239 float getD() const { return _D
; }
240 float getE() const { return _E
; }
241 //float getC() const { return _C; }
242 uint
getImpactScheme() const { return _IImpactMappingScheme
; }
243 void resetSource( const CHarvestSource
& ini
) { _NbExtractions
= 0; initFrom( ini
); }
245 void setSafeSource(bool value
) { _SafeSource
= value
; }
249 /// Init dynamic props from template source (except pos, _N and _MaxQuality... see other methods below, and others such as _IImpactMappingScheme).
250 void initFrom( const CHarvestSource
& ini
)
251 { _LifeTime
=ini
._LifeTime
; _ExtractionTime
=ini
._ExtractionTime
; _ExtraExtractionTime
=ini
._ExtraExtractionTime
; _S
=ini
._S
; _A
=ini
._A
; _Q
=ini
._Q
; _D
=ini
._D
; _E
=ini
._E
; /*_C=ini._C;*/ /*_DistanceVisibility=ini._DistanceVisibility; _StealthVisibility=ini._StealthVisibility;*/ }
254 void setPos( const NLMISC::CVector2f
& pos
) { _Pos
= pos
; }
256 /// Set the link to the forage site
257 void setForageSite( CRecentForageSite
*forageSite
) { _ForageSite
= forageSite
; }
259 /// Set the raw material, the initial amount and the max quality, or return false if the current quantity in the deposit is 0.
260 bool setRawMaterial( const CStaticDepositRawMaterial
*rmInfo
, float quantityRatio
);
262 /// Update visual properties & related stuff
263 void updateVisuals();
265 /// Send a message to all the players extracting on the source
266 void sendMessageToExtractors( const char *msg
);
268 /// Send a message with a parameter to all the players extracting on the source
269 void sendMessageToExtractors( const char *msg
, sint32 param
);
271 /// When the threshold of E is reached
272 void makeDamagingEvent();
274 /// A continuous damaging event
275 void spawnToxicCloud();
277 /// A one-time damaging event
280 /// Despawn the source in mirror, and exit from forage site
283 /// Get the damage factor of a source [0..1] (for explosion or toxic cloud)
284 float getDamageFactor() const;
286 /// Inc the number of event triggered
287 void setEventTriggered() { if ( _NbEventTriggered
< 255 ) ++_NbEventTriggered
; }
289 /// Set a new mapping scheme of property impact
290 void setNewImpactScheme();
292 /// Impact a realtime prop
293 void impactRTProp( TTargetRTProp iProp
, float targetValue
)
295 _TargetRTProps
[iProp
] = targetValue
;
301 NLMISC::CSheetId _MaterialSheet
;
303 /// Entity representing the source, valid after spawn()
304 TDataSetRow _DataSetRow
;
306 /// Source position (coordinates in meters)
307 NLMISC::CVector2f _Pos
;
309 /// Link to forage site (they can't move in memory or be deleted while the source is present). Can be NULL (usually for tests)
310 CRecentForageSite
*_ForageSite
;
312 /// Link to deposit used for kami anger level (they can't move or deleted after init)
313 CDeposit
*_DepositForK
;
315 /// Link to deposit used for auto spawned sources? Should be NULL or same as _DepositForK. Yoyo: I use a CRefPtr for security...
316 NLMISC::CRefPtr
<CDeposit
> _DepositAutoSpawn
;
318 /// Source remaining Time To Live in ticks (decremented every update when !_IsExtractionInProgress)
319 NLMISC::TGameCycle _LifeTime
;
321 /// The total time for extraction (_T initial value before it decreases). Locked is forbidden.
322 NLMISC::TGameCycle _ExtractionTime
;
324 /// Extra time for extraction
325 NLMISC::TGameCycle _ExtraExtractionTime
;
327 /// Amount of extra time (included in _ExtraExtractionTime) that comes from the extractor's bonus passive bricks
328 NLMISC::TGameCycle _IncludedBonusExtractionTime
;
330 // Time remaining for extraction (starts to decrease when the 1st extraction begins). Locked until the source is fully spawned.
331 NLMISC::TGameCycle _T
;
333 /// Quantity of raw material in the source
336 /// Real-time properties
337 float _RTProps
[NbRTProps
];
339 /// Target value for D, E
340 float _TargetRTProps
[NbTargetRTProps
];
342 /// Max quality of the raw material
345 /// Mapping of property impact
346 uint16 _IImpactMappingScheme
;
348 /// Number of extractions done
349 uint16 _NbExtractions
;
351 /// True if the impact scheme must be a friendly one
352 bool _IsInNewbieMode
;
354 /// Bonus for quantity rate (aperture)
357 /// Distance of visibility
358 //sint32 _DistanceVisibility;
360 /// Stealth mode (visibility priviledges)
361 //VISIBILITY_RIGHTS::TVisGroup _StealthVisibility;
366 /// List of 'reduce damage' events
369 /// True if one or more extractions are in progress
370 bool _IsExtractionInProgress
;
372 /// Trigger reset of explosion visual fx
373 sint8 _ExplosionResetCounter
;
375 /// True if the source was auto-spawned
378 /// True if the source is safe (cannot explode)
381 /// Number of source risk events triggered
382 uint8 _NbEventTriggered
;
386 * Harvest source manager class
388 class CHarvestSourceManager
: public CSimpleEntityManager
<CHarvestSource
>
390 NL_INSTANCE_COUNTER_DECL(CHarvestSourceManager
);
394 static CHarvestSourceManager
*getInstance();
397 void init( TDataSetIndex baseRowIndex
, TDataSetIndex size
);
400 static void release();
404 #endif // NL_HARVEST_SOURCE_H
406 /* End of harvest_source.h */