/*======================================================================*/ bool passesContainerLimits(Aint theContainer, Aint theAddedInstance) { LimitEntry *limit; Aword props; if (!isAContainer(theContainer)) syserr("Checking limits for a non-container."); /* Find the container properties */ props = instances[theContainer].container; if (containers[props].limits != 0) { /* Any limits at all? */ for (limit = (LimitEntry *) pointerTo(containers[props].limits); !isEndOfArray(limit); limit++) if (limit->atr == 1-I_COUNT) { /* TODO This is actually some encoding of the attribute number, right? */ if (countInContainer(theContainer) >= limit->val) { interpret(limit->stms); return(FALSE); } } else { if (sumAttributeInContainer(theContainer, limit->atr) + getInstanceAttribute(theAddedInstance, limit->atr) > limit->val) { interpret(limit->stms); return(FALSE); } } } return(TRUE); }
/*======================================================================*/ StepEntry *stepOf(int actor) { StepEntry *step; ScriptEntry *scr = scriptOf(actor); if (scr == NULL) return NULL; step = (StepEntry*)pointerTo(scr->steps); step = &step[admin[actor].step]; return step; }
/*----------------------------------------------------------------------*/ static void saveSets(AFILE saveFile) { SetInitEntry *initEntry; if (header->setInitTable != 0) for (initEntry = (SetInitEntry *)pointerTo(header->setInitTable); !isEndOfArray(initEntry); initEntry++) { Set *attr = (Set *)getInstanceSetAttribute(initEntry->instanceCode, initEntry->attributeCode); fwrite((void *)&attr->size, sizeof(attr->size), 1, saveFile); fwrite((void *)attr->members, sizeof(attr->members[0]), attr->size, saveFile); } }
/*======================================================================*/ ScriptEntry *scriptOf(int actor) { ScriptEntry *scr; if (admin[actor].script != 0) { for (scr = (ScriptEntry *) pointerTo(header->scriptTableAddress); !isEndOfArray(scr); scr++) if (scr->code == admin[actor].script) break; if (!isEndOfArray(scr)) return scr; } return NULL; }
/*----------------------------------------------------------------------*/ static int sourceFileNumber(char *fileName) { SourceFileEntry *entries = pointerTo(header->sourceFileTable); int n; for (n = 0; *(Aword*)&entries[n] != EOF; n++) { char *entryName; entryName = getStringFromFile(entries[n].fpos, entries[n].len); if (strcmp(entryName, fileName) == 0) return n; entryName = baseNameStart(entryName); if (strcmp(entryName, fileName) == 0) return n; } return -1; }
/*----------------------------------------------------------------------*/ static void saveStrings(AFILE saveFile) { StringInitEntry *initEntry; if (header->stringInitTable != 0) for (initEntry = (StringInitEntry *)pointerTo(header->stringInitTable); !isEndOfArray(initEntry); initEntry++) { char *attr = (char *)getInstanceStringAttribute(initEntry->instanceCode, initEntry->attributeCode); Aint length = strlen(attr) + 1; fwrite((void *)&length, sizeof(length), 1, saveFile); fwrite((void *)attr, 1, length, saveFile); } }
/*----------------------------------------------------------------------*/ static void restoreStrings(AFILE saveFile) { StringInitEntry *initEntry; if (header->stringInitTable != 0) for (initEntry = (StringInitEntry *)pointerTo(header->stringInitTable); !isEndOfArray(initEntry); initEntry++) { Aint length; char *string; fread((void *)&length, sizeof(Aint), 1, saveFile); string = allocate(length+1); fread((void *)string, 1, length, saveFile); setInstanceAttribute(initEntry->instanceCode, initEntry->attributeCode, (Aptr)string); } }
/*----------------------------------------------------------------------*/ static void showAttributes(AttributeEntry *attributes) { AttributeEntry *at; int i; char str[80]; if (attributes == 0) return; i = 1; for (at = attributes; !isEndOfArray(at); at++) { sprintf(str, "$i$t%s[%d] = %d", (char *) pointerTo(at->id), at->code, (int)at->value); #if ISO == 0 fromIso(str, str); #endif output(str); i++; } }
/*======================================================================*/ bool checksFailed(Aaddr adr, bool execute) { CheckEntry *chk = (CheckEntry *) pointerTo(adr); if (chk->exp == 0) { if (execute == EXECUTE_CHECK_BODY_ON_FAIL) interpret(chk->stms); return TRUE; } else { while (!isEndOfArray(chk)) { if (!evaluate(chk->exp)) { if (execute == EXECUTE_CHECK_BODY_ON_FAIL) interpret(chk->stms); return TRUE; } chk++; } return FALSE; } }
/*----------------------------------------------------------------------*/ static void restoreSets(AFILE saveFile) { SetInitEntry *initEntry; if (header->setInitTable != 0) for (initEntry = (SetInitEntry *)pointerTo(header->setInitTable); !isEndOfArray(initEntry); initEntry++) { Aint setSize; Set *set; int i; fread((void *)&setSize, sizeof(setSize), 1, saveFile); set = newSet(setSize); for (i = 0; i < setSize; i++) { Aword member; fread((void *)&member, sizeof(member), 1, saveFile); addToSet(set, member); } setInstanceAttribute(initEntry->instanceCode, initEntry->attributeCode, (Aptr)set); } }