| 1 |
#include "attribute.h" |
| 2 |
|
| 3 |
#include "syserr.h" |
| 4 |
#include "current.h" |
| 5 |
#include "lists.h" |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
static AttributeEntry *lookupAttribute(AttributeEntry *attributeTable, int attributeCode) |
| 10 |
{ |
| 11 |
AttributeEntry *attribute = attributeTable; |
| 12 |
while (attribute->code != attributeCode) { |
| 13 |
attribute++; |
| 14 |
if (isEndOfArray(attribute)) |
| 15 |
return NULL; |
| 16 |
} |
| 17 |
return attribute; |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
bool attributeExists(AttributeEntry *attributeTable, int attributeCode) |
| 23 |
{ |
| 24 |
AttributeEntry *attribute = lookupAttribute(attributeTable, attributeCode); |
| 25 |
|
| 26 |
return attribute != NULL; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
Aword getAttribute(AttributeEntry *attributeTable, int attributeCode) |
| 32 |
{ |
| 33 |
AttributeEntry *attribute = lookupAttribute(attributeTable, attributeCode); |
| 34 |
|
| 35 |
if (attribute == NULL) |
| 36 |
syserr("Attribute not found."); |
| 37 |
|
| 38 |
return attribute->value; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
void setAttribute(AttributeEntry *attributeTable, int attributeCode, Aptr newValue) |
| 44 |
{ |
| 45 |
AttributeEntry *attribute = lookupAttribute(attributeTable, attributeCode); |
| 46 |
|
| 47 |
if (attribute == NULL) |
| 48 |
syserr("Attribute not found."); |
| 49 |
|
| 50 |
attribute->value = newValue; |
| 51 |
gameStateChanged = true; |
| 52 |
} |