2012-01-05 16:32:41 +00:00
|
|
|
#include "modifiers.h"
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-01-29 17:39:56 +00:00
|
|
|
#include "shared/types.h"
|
|
|
|
#include "tools.h"
|
|
|
|
|
|
|
|
#define MODE_NULL 0
|
|
|
|
#define MODE_ADD_VALUE 1
|
|
|
|
#define MODE_FIX_VALUE 2
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
struct HeightModifier
|
|
|
|
{
|
|
|
|
Zone* zone;
|
2012-01-29 17:39:56 +00:00
|
|
|
int mode;
|
2012-06-15 09:31:11 +00:00
|
|
|
float value;
|
2011-12-10 13:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HeightModifier* modifierCreate()
|
|
|
|
{
|
|
|
|
HeightModifier* modifier;
|
|
|
|
|
|
|
|
modifier = (HeightModifier*)malloc(sizeof(HeightModifier));
|
|
|
|
modifier->zone = zoneCreate();
|
|
|
|
modifier->mode = MODE_NULL;
|
|
|
|
|
|
|
|
return modifier;
|
|
|
|
}
|
|
|
|
|
2012-01-05 11:32:14 +00:00
|
|
|
HeightModifier* modifierCreateCopy(HeightModifier* source)
|
|
|
|
{
|
|
|
|
HeightModifier* result;
|
|
|
|
|
|
|
|
result = (HeightModifier*)malloc(sizeof(HeightModifier));
|
|
|
|
result->zone = zoneCreate();
|
|
|
|
zoneCopy(source->zone, result->zone);
|
|
|
|
result->mode = source->mode;
|
|
|
|
result->value = source->value;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
void modifierDelete(HeightModifier* modifier)
|
|
|
|
{
|
|
|
|
zoneDelete(modifier->zone);
|
|
|
|
free(modifier);
|
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void modifierSave(PackStream* stream, HeightModifier* modifier)
|
2012-01-05 11:32:14 +00:00
|
|
|
{
|
2012-04-22 17:12:39 +00:00
|
|
|
packWriteInt(stream, &modifier->mode);
|
2012-06-15 09:31:11 +00:00
|
|
|
packWriteFloat(stream, &modifier->value);
|
2012-04-22 17:12:39 +00:00
|
|
|
zoneSave(stream, modifier->zone);
|
2012-01-05 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void modifierLoad(PackStream* stream, HeightModifier* modifier)
|
2012-01-05 11:32:14 +00:00
|
|
|
{
|
2012-04-22 17:12:39 +00:00
|
|
|
packReadInt(stream, &modifier->mode);
|
2012-06-15 09:31:11 +00:00
|
|
|
packReadFloat(stream, &modifier->value);
|
2012-04-22 17:12:39 +00:00
|
|
|
zoneLoad(stream, modifier->zone);
|
2012-01-05 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
Zone* modifierGetZone(HeightModifier* modifier)
|
|
|
|
{
|
|
|
|
return modifier->zone;
|
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
void modifierActionAddValue(HeightModifier* modifier, float value)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
modifier->mode = MODE_ADD_VALUE;
|
|
|
|
modifier->value = value;
|
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
void modifierActionFixValue(HeightModifier* modifier, float value)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
modifier->mode = MODE_FIX_VALUE;
|
|
|
|
modifier->value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 modifierApply(HeightModifier* modifier, Vector3 location)
|
|
|
|
{
|
2012-06-15 09:31:11 +00:00
|
|
|
float influence, diff;
|
2011-12-10 13:25:22 +00:00
|
|
|
Vector3 normal;
|
|
|
|
|
|
|
|
switch (modifier->mode)
|
|
|
|
{
|
|
|
|
case MODE_ADD_VALUE:
|
|
|
|
influence = zoneGetValue(modifier->zone, location, normal);
|
|
|
|
location.y += modifier->value * influence;
|
|
|
|
break;
|
|
|
|
case MODE_FIX_VALUE:
|
|
|
|
influence = zoneGetValue(modifier->zone, location, normal);
|
|
|
|
diff = modifier->value - location.y;
|
|
|
|
location.y += diff * influence;
|
|
|
|
break;
|
|
|
|
case MODE_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return location;
|
|
|
|
}
|