Skip to content

Commit

Permalink
Refactored verses parser.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.renegadeprojects.com/yrpp/trunk@284 bbc44d77-a14d-0410-bbfb-905795908d03
  • Loading branch information
DCoderLT committed Mar 28, 2010
1 parent bed12f4 commit 92fd3a8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
46 changes: 20 additions & 26 deletions Conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,46 @@

#include <Helpers/Macro.h>
#include <YRPP.h>
#include <WarheadTypeClass.h>

// converters
class Conversions
{
public:
static double Str2Armor(char *buf, DWORD *specialFX) {
static double Str2Armor(const char *buf, WarheadFlags *whFlags) {
if(!buf) { return 0.0; }

bool ForceFire = true;
bool Retaliate = true;
bool PassiveAcquire = true;

if(strchr(buf, '%')) {
bool specialed = false;

if(strlen(buf) == 2) {
switch(*buf) {
case '0':
*specialFX &= ~verses_ForceFire;
ForceFire = false;
case '1':
*specialFX &= ~verses_Retaliate;
Retaliate = false;
case '2':
*specialFX &= ~verses_PassiveAcquire;
specialed = true;
PassiveAcquire = false;
break;
}
}
if(!specialed) {
*specialFX |= verses_ForceFire;
*specialFX |= verses_Retaliate;
*specialFX |= verses_PassiveAcquire;
}
whFlags->ForceFire = ForceFire;
whFlags->Retaliate = Retaliate;
whFlags->PassiveAcquire = PassiveAcquire;
return atoi(buf) * 0.01;
} else {
double vs = atof(buf);
bool specialed = false;
if(CLOSE_ENOUGH(vs, 0.02)) {
*specialFX &= ~verses_PassiveAcquire;
specialed = true;
}
if(CLOSE_ENOUGH(vs, 0.01)) {
*specialFX &= ~verses_Retaliate;
specialed = true;
if(LESS_EQUAL(vs, 0.02)) {
whFlags->PassiveAcquire = PassiveAcquire;
}
if(CLOSE_ENOUGH(vs, 0.00)) {
*specialFX &= ~verses_ForceFire;
specialed = true;
if(LESS_EQUAL(vs, 0.01)) {
whFlags->Retaliate = Retaliate;
}
if(!specialed) {
*specialFX |= verses_ForceFire;
*specialFX |= verses_Retaliate;
*specialFX |= verses_PassiveAcquire;
if(LESS_EQUAL(vs, 0.00)) {
whFlags->ForceFire = ForceFire;
}
return vs;
}
Expand Down
8 changes: 0 additions & 8 deletions GeneralDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,6 @@ typedef int eTargetFlags;
#define ttf_Occupiable 0x8000
#define ttf_TechCapture 0x10000


typedef int eWarheadFlags;

#define verses_ForceFire 0x1
#define verses_Retaliate 0x2
#define verses_PassiveAcquire 0x4


typedef int eBlitterFlags;

#define bf_001 0x1
Expand Down
3 changes: 3 additions & 0 deletions Helpers/Macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@
#define CLOSE_ENOUGH(x, y) \
(fabs(x - y) < 0.001)

#define LESS_EQUAL(x, y) \
((x - y) <= 0.001)

#endif
8 changes: 8 additions & 0 deletions WarheadTypeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class AnimTypeClass;
class ParticleTypeClass;
class VoxelAnimTypeClass;

struct WarheadFlags {
bool ForceFire : 1;
bool Retaliate : 1;
bool PassiveAcquire : 1;

WarheadFlags(bool FF = true, bool Retal = true, bool Acquire = true) : ForceFire(FF), Retaliate(Retal), PassiveAcquire(Acquire) {};
};

class WarheadTypeClass : public AbstractTypeClass
{
public:
Expand Down

0 comments on commit 92fd3a8

Please sign in to comment.