LAB: Change the scene rule list to use a Common::List

This commit is contained in:
Filippos Karapetis 2015-10-12 13:53:00 +03:00 committed by Willem Jan Palenstijn
parent 9676165436
commit 93b2e413fd
5 changed files with 56 additions and 79 deletions

View file

@ -97,7 +97,14 @@ static void freeRoom(uint16 RMarker) {
Rooms[RoomNum].SouthView = NULL;
Rooms[RoomNum].EastView = NULL;
Rooms[RoomNum].WestView = NULL;
Rooms[RoomNum].RuleList = NULL;
RuleList *rules = Rooms[RoomNum].rules;
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++)
delete *rule;
Rooms[RoomNum].rules->clear();
delete Rooms[RoomNum].rules;
Rooms[RoomNum].rules = NULL;
Rooms[RoomNum].RoomMsg = NULL;
}

View file

@ -138,7 +138,7 @@ struct Rule {
Rule *NextRule;
};
typedef Rule *RulePtr;
typedef Common::List<Rule *> RuleList;
struct RoomData {
uint16 NorthDoor, SouthDoor, EastDoor, WestDoor;
@ -146,7 +146,7 @@ struct RoomData {
byte WipeType;
ViewDataPtr NorthView, SouthView, EastView, WestView;
RulePtr RuleList;
RuleList *rules;
char *RoomMsg;
};

View file

@ -615,34 +615,29 @@ static void doActions(ActionPtr APtr, CloseDataPtr *LCPtr) {
/* Does the work for doActionRule. */
/*****************************************************************************/
static bool doActionRuleSub(int16 action, int16 roomNum, CloseDataPtr LCPtr, CloseDataPtr *Set, bool AllowDefaults) {
RulePtr RPtr;
action++;
if (LCPtr) {
RPtr = Rooms[roomNum].RuleList;
RuleList *rules = Rooms[RoomNum].rules;
if ((RPtr == NULL) && (roomNum == 0)) {
if ((rules == NULL) && (roomNum == 0)) {
g_resource->readViews(roomNum);
RPtr = Rooms[roomNum].RuleList;
rules = Rooms[roomNum].rules;
}
while (RPtr) {
if ((RPtr->RuleType == ACTION) &&
((RPtr->Param1 == action) || ((RPtr->Param1 == 0) && AllowDefaults))) {
if (((RPtr->Param2 == LCPtr->CloseUpType) ||
((RPtr->Param2 == 0) && AllowDefaults))
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++) {
if (((*rule)->RuleType == ACTION) &&
(((*rule)->Param1 == action) || (((*rule)->Param1 == 0) && AllowDefaults))) {
if ((((*rule)->Param2 == LCPtr->CloseUpType) ||
(((*rule)->Param2 == 0) && AllowDefaults))
||
((action == 1) && (RPtr->Param2 == (-LCPtr->CloseUpType)))) {
if (checkConditions(RPtr->Condition)) {
doActions(RPtr->ActionList, Set);
((action == 1) && ((*rule)->Param2 == (-LCPtr->CloseUpType)))) {
if (checkConditions((*rule)->Condition)) {
doActions((*rule)->ActionList, Set);
return true;
}
}
}
RPtr = RPtr->NextRule;
}
}
@ -678,28 +673,24 @@ bool doActionRule(int16 x, int16 y, int16 action, int16 roomNum, CloseDataPtr *L
/* Does the work for doActionRule. */
/*****************************************************************************/
static bool doOperateRuleSub(int16 ItemNum, int16 roomNum, CloseDataPtr LCPtr, CloseDataPtr *Set, bool AllowDefaults) {
RulePtr RPtr;
if (LCPtr)
if (LCPtr->CloseUpType > 0) {
RPtr = Rooms[roomNum].RuleList;
RuleList *rules = Rooms[roomNum].rules;
if ((RPtr == NULL) && (roomNum == 0)) {
if ((rules == NULL) && (roomNum == 0)) {
g_resource->readViews(roomNum);
RPtr = Rooms[roomNum].RuleList;
rules = Rooms[roomNum].rules;
}
while (RPtr) {
if ((RPtr->RuleType == OPERATE) &&
((RPtr->Param1 == ItemNum) || ((RPtr->Param1 == 0) && AllowDefaults)) &&
((RPtr->Param2 == LCPtr->CloseUpType) || ((RPtr->Param2 == 0) && AllowDefaults))) {
if (checkConditions(RPtr->Condition)) {
doActions(RPtr->ActionList, Set);
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++) {
if (((*rule)->RuleType == OPERATE) &&
(((*rule)->Param1 == ItemNum) || (((*rule)->Param1 == 0) && AllowDefaults)) &&
(((*rule)->Param2 == LCPtr->CloseUpType) || (((*rule)->Param2 == 0) && AllowDefaults))) {
if (checkConditions((*rule)->Condition)) {
doActions((*rule)->ActionList, Set);
return true;
}
}
RPtr = RPtr->NextRule;
}
}
@ -744,19 +735,15 @@ bool doOperateRule(int16 x, int16 y, int16 ItemNum, CloseDataPtr *LCPtr) {
/* Goes thru the rules if the user tries to go forward. */
/*****************************************************************************/
bool doGoForward(CloseDataPtr *LCPtr) {
RulePtr RPtr;
RuleList *rules = Rooms[RoomNum].rules;
RPtr = Rooms[RoomNum].RuleList;
while (RPtr) {
if ((RPtr->RuleType == GOFORWARD) && (RPtr->Param1 == (Direction + 1))) {
if (checkConditions(RPtr->Condition)) {
doActions(RPtr->ActionList, LCPtr);
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++) {
if (((*rule)->RuleType == GOFORWARD) && ((*rule)->Param1 == (Direction + 1))) {
if (checkConditions((*rule)->Condition)) {
doActions((*rule)->ActionList, LCPtr);
return true;
}
}
RPtr = RPtr->NextRule;
}
return false;
@ -766,25 +753,20 @@ bool doGoForward(CloseDataPtr *LCPtr) {
/* Goes thru the rules if the user tries to turn. */
/*****************************************************************************/
bool doTurn(uint16 from, uint16 to, CloseDataPtr *LCPtr) {
RulePtr RPtr;
from++;
to++;
RPtr = Rooms[RoomNum].RuleList;
RuleList *rules = Rooms[RoomNum].rules;
while (RPtr) {
if ((RPtr->RuleType == TURN) ||
((RPtr->RuleType == TURNFROMTO) &&
(RPtr->Param1 == from) && (RPtr->Param2 == to))) {
if (checkConditions(RPtr->Condition)) {
doActions(RPtr->ActionList, LCPtr);
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++) {
if (((*rule)->RuleType == TURN) ||
(((*rule)->RuleType == TURNFROMTO) &&
((*rule)->Param1 == from) && ((*rule)->Param2 == to))) {
if (checkConditions((*rule)->Condition)) {
doActions((*rule)->ActionList, LCPtr);
return true;
}
}
RPtr = RPtr->NextRule;
}
return false;
@ -794,19 +776,14 @@ bool doTurn(uint16 from, uint16 to, CloseDataPtr *LCPtr) {
/* Goes thru the rules if the user tries to go to the main view */
/*****************************************************************************/
bool doMainView(CloseDataPtr *LCPtr) {
RulePtr RPtr;
RPtr = Rooms[RoomNum].RuleList;
while (RPtr) {
if (RPtr->RuleType == GOMAINVIEW) {
if (checkConditions(RPtr->Condition)) {
doActions(RPtr->ActionList, LCPtr);
RuleList *rules = Rooms[RoomNum].rules;
for (RuleList::iterator rule = rules->begin(); rule != rules->end(); rule++) {
if ((*rule)->RuleType == GOMAINVIEW) {
if (checkConditions((*rule)->Condition)) {
doActions((*rule)->ActionList, LCPtr);
return true;
}
}
RPtr = RPtr->NextRule;
}
return false;

View file

@ -101,7 +101,7 @@ bool Resource::readRoomData(const char *fileName) {
Rooms[i].SouthView = NULL;
Rooms[i].EastView = NULL;
Rooms[i].WestView = NULL;
Rooms[i].RuleList = NULL;
Rooms[i].rules = NULL;
Rooms[i].RoomMsg = NULL;
}
@ -140,7 +140,7 @@ bool Resource::readViews(uint16 roomNum) {
Rooms[roomNum].SouthView = readView(dataFile);
Rooms[roomNum].EastView = readView(dataFile);
Rooms[roomNum].WestView = readView(dataFile);
Rooms[roomNum].RuleList = readRule(dataFile);
Rooms[roomNum].rules = readRule(dataFile);
g_music->updateMusic();
@ -190,32 +190,25 @@ int16 *Resource::readConditions(Common::File *file) {
return list;
}
Rule *Resource::readRule(Common::File *file) {
RuleList *Resource::readRule(Common::File *file) {
char c;
Rule *rule = NULL;
Rule *prev = NULL;
Rule *head = NULL;
RuleList *rules = new Common::List<Rule *>();
do {
c = file->readByte();
if (c == 1) {
rule = (Rule *)malloc(sizeof(Rule));
if (!head)
head = rule;
if (prev)
prev->NextRule = rule;
Rule *rule = new Rule();;
rule->RuleType = file->readSint16LE();
rule->Param1 = file->readSint16LE();
rule->Param2 = file->readSint16LE();
rule->Condition = readConditions(file);
rule->ActionList = readAction(file);
rule->NextRule = NULL;
prev = rule;
rules->push_back(rule);
}
} while (c == 1);
return head;
return rules;
}
Action *Resource::readAction(Common::File *file) {

View file

@ -108,7 +108,7 @@ public:
private:
char *readString(Common::File *file);
int16 *readConditions(Common::File *file);
Rule *readRule(Common::File *file);
RuleList *readRule(Common::File *file);
Action *readAction(Common::File *file);
CloseData *readCloseUps(uint16 depth, Common::File *file);
viewData *readView(Common::File *file);