Skip to content

Commit

Permalink
GLK: ALAN3: Proper indentation & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jul 6, 2019
1 parent aebf256 commit dc40211
Show file tree
Hide file tree
Showing 68 changed files with 8,085 additions and 8,192 deletions.
946 changes: 473 additions & 473 deletions engines/glk/alan3/acode.h

Large diffs are not rendered by default.

138 changes: 68 additions & 70 deletions engines/glk/alan3/act.cpp
Expand Up @@ -32,93 +32,91 @@ namespace Glk {
namespace Alan3 {

/*----------------------------------------------------------------------*/
static void executeCommand(int verb, Parameter parameters[])
{
static AltInfo *altInfos = NULL; /* Need to survive lots of different exits...*/
int altIndex;

/* Did we leave anything behind last time... */
if (altInfos != NULL)
free(altInfos);

altInfos = findAllAlternatives(verb, parameters);

if (anyCheckFailed(altInfos, EXECUTE_CHECK_BODY_ON_FAIL))
return;

/* Check for anything to execute... */
if (!anythingToExecute(altInfos))
error(M_CANT0);

/* Now perform actions! First try any BEFORE or ONLY from inside out */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
if (altInfos[altIndex].alt != 0) // TODO Can this ever be NULL? Why?
if (altInfos[altIndex].alt->qual == (Aword)Q_BEFORE
|| altInfos[altIndex].alt->qual == (Aword)Q_ONLY) {
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
if (altInfos[altIndex].alt->qual == (Aword)Q_ONLY)
return;
}
}

/* Then execute any not declared as AFTER, i.e. the default */
for (altIndex = 0; !altInfos[altIndex].end; altIndex++) {
if (altInfos[altIndex].alt != 0)
if (altInfos[altIndex].alt->qual != (Aword)Q_AFTER)
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
}

/* Finally, the ones declared as AFTER */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
if (altInfos[altIndex].alt != 0)
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
}
static void executeCommand(int verb, Parameter parameters[]) {
static AltInfo *altInfos = NULL; /* Need to survive lots of different exits...*/
int altIndex;

/* Did we leave anything behind last time... */
if (altInfos != NULL)
free(altInfos);

altInfos = findAllAlternatives(verb, parameters);

if (anyCheckFailed(altInfos, EXECUTE_CHECK_BODY_ON_FAIL))
return;

/* Check for anything to execute... */
if (!anythingToExecute(altInfos))
error(M_CANT0);

/* Now perform actions! First try any BEFORE or ONLY from inside out */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
if (altInfos[altIndex].alt != 0) // TODO Can this ever be NULL? Why?
if (altInfos[altIndex].alt->qual == (Aword)Q_BEFORE
|| altInfos[altIndex].alt->qual == (Aword)Q_ONLY) {
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
if (altInfos[altIndex].alt->qual == (Aword)Q_ONLY)
return;
}
}

/* Then execute any not declared as AFTER, i.e. the default */
for (altIndex = 0; !altInfos[altIndex].end; altIndex++) {
if (altInfos[altIndex].alt != 0)
if (altInfos[altIndex].alt->qual != (Aword)Q_AFTER)
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
}

/* Finally, the ones declared as AFTER */
for (altIndex = lastAltInfoIndex(altInfos); altIndex >= 0; altIndex--) {
if (altInfos[altIndex].alt != 0)
if (!executedOk(&altInfos[altIndex]))
abortPlayerCommand();
}
}


/*======================================================================
action()
Execute the command. Handles acting on multiple items
such as ALL, THEM or lists of objects.
*/
void action(int verb, Parameter parameters[], Parameter multipleMatches[])
{
int multiplePosition;
void action(int verb, Parameter parameters[], Parameter multipleMatches[]) {
int multiplePosition;
#ifdef TODO
char marker[10];
#endif

multiplePosition = findMultiplePosition(parameters);
if (multiplePosition != -1) {
multiplePosition = findMultiplePosition(parameters);
if (multiplePosition != -1) {
#ifdef TODO
jmp_buf savedReturnLabel;
memcpy(savedReturnLabel, returnLabel, sizeof(returnLabel));
sprintf(marker, "($%d)", multiplePosition+1); /* Prepare a printout with $1/2/3 */
for (int i = 0; !isEndOfArray(&multipleMatches[i]); i++) {
copyParameter(&parameters[multiplePosition], &multipleMatches[i]);
setGlobalParameters(parameters); /* Need to do this here since the marker use them */
output(marker);
// TODO: if execution for one parameter aborts we should return here, not to top level
if (setjmp(returnLabel) == NO_JUMP_RETURN)
executeCommand(verb, parameters);
if (multipleMatches[i+1].instance != EOD)
para();
}
memcpy(returnLabel, savedReturnLabel, sizeof(returnLabel));
parameters[multiplePosition].instance = 0;
memcpy(savedReturnLabel, returnLabel, sizeof(returnLabel));
sprintf(marker, "($%d)", multiplePosition + 1); /* Prepare a printout with $1/2/3 */
for (int i = 0; !isEndOfArray(&multipleMatches[i]); i++) {
copyParameter(&parameters[multiplePosition], &multipleMatches[i]);
setGlobalParameters(parameters); /* Need to do this here since the marker use them */
output(marker);
// TODO: if execution for one parameter aborts we should return here, not to top level
if (setjmp(returnLabel) == NO_JUMP_RETURN)
executeCommand(verb, parameters);
if (multipleMatches[i + 1].instance != EOD)
para();
}
memcpy(returnLabel, savedReturnLabel, sizeof(returnLabel));
parameters[multiplePosition].instance = 0;
#else
::error("TODO: action");
#endif
} else {
setGlobalParameters(parameters);
executeCommand(verb, parameters);
}
} else {
setGlobalParameters(parameters);
executeCommand(verb, parameters);
}

}

Expand Down
57 changes: 28 additions & 29 deletions engines/glk/alan3/actor.cpp
Expand Up @@ -33,49 +33,48 @@ namespace Alan3 {

/*======================================================================*/
ScriptEntry *scriptOf(int actor) {
ScriptEntry *scr;
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;
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;
}


/*======================================================================*/
StepEntry *stepOf(int actor) {
StepEntry *step;
ScriptEntry *scr = scriptOf(actor);
StepEntry *step;
ScriptEntry *scr = scriptOf(actor);

if (scr == NULL) return NULL;
if (scr == NULL) return NULL;

step = (StepEntry*)pointerTo(scr->steps);
step = &step[admin[actor].step];
step = (StepEntry *)pointerTo(scr->steps);
step = &step[admin[actor].step];

return step;
return step;
}


/*======================================================================*/
void describeActor(int actor)
{
ScriptEntry *script = scriptOf(actor);
void describeActor(int actor) {
ScriptEntry *script = scriptOf(actor);

if (script != NULL && script->description != 0)
interpret(script->description);
else if (hasDescription(actor))
describeAnything(actor);
else {
printMessageWithInstanceParameter(M_SEE_START, actor);
printMessage(M_SEE_END);
if (instances[actor].container != 0)
describeContainer(actor);
}
admin[actor].alreadyDescribed = TRUE;
if (script != NULL && script->description != 0)
interpret(script->description);
else if (hasDescription(actor))
describeAnything(actor);
else {
printMessageWithInstanceParameter(M_SEE_START, actor);
printMessage(M_SEE_END);
if (instances[actor].container != 0)
describeContainer(actor);
}
admin[actor].alreadyDescribed = TRUE;
}

} // End of namespace Alan3
Expand Down
64 changes: 32 additions & 32 deletions engines/glk/alan3/alan3.cpp
Expand Up @@ -41,7 +41,7 @@ namespace Alan3 {
Alan3 *g_vm = nullptr;

Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
vm_exited_cleanly(false), _restartFlag(false), _saveSlot(-1), _pendingLook(false) {
vm_exited_cleanly(false), _restartFlag(false), _saveSlot(-1), _pendingLook(false) {
g_vm = this;
// txtfil = nullptr;
// logfil = nullptr;
Expand Down Expand Up @@ -86,42 +86,42 @@ bool Alan3::initialize() {
glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
winmethod_Fixed, 1, wintype_TextGrid, 0);
g_vm->glk_set_window(glkMainWin);
/*
// Set up the code file to point to the already opened game file
codfil = &_gameFile;
strncpy(codfnm, getFilename().c_str(), 255);
codfnm[255] = '\0';
if (_gameFile.size() < 8) {
GUIErrorMessage(_("This is too short to be a valid Alan3 file."));
return false;
}
if (_gameFile.readUint32BE() != MKTAG(2, 8, 1, 0)) {
GUIErrorMessage(_("This is not a valid Alan3 file."));
return false;
}
// Open up the text file
txtfil = new Common::File();
if (!txtfil->open(Common::String::format("%s.dat", _advName.c_str()))) {
GUIErrorMessage("Could not open adventure text data file");
delete txtfil;
return false;
}
// Check for a save being loaded directly from the launcher
_saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
*/
/*
// Set up the code file to point to the already opened game file
codfil = &_gameFile;
strncpy(codfnm, getFilename().c_str(), 255);
codfnm[255] = '\0';
if (_gameFile.size() < 8) {
GUIErrorMessage(_("This is too short to be a valid Alan3 file."));
return false;
}
if (_gameFile.readUint32BE() != MKTAG(2, 8, 1, 0)) {
GUIErrorMessage(_("This is not a valid Alan3 file."));
return false;
}
// Open up the text file
txtfil = new Common::File();
if (!txtfil->open(Common::String::format("%s.dat", _advName.c_str()))) {
GUIErrorMessage("Could not open adventure text data file");
delete txtfil;
return false;
}
// Check for a save being loaded directly from the launcher
_saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
*/
return true;
}

void Alan3::deinitialize() {
free(memory);
/*
delete txtfil;
delete logfil;
*/
/*
delete txtfil;
delete logfil;
*/
}

Common::Error Alan3::readSaveData(Common::SeekableReadStream *rs) {
Expand Down
8 changes: 6 additions & 2 deletions engines/glk/alan3/alan3.h
Expand Up @@ -68,12 +68,16 @@ class Alan3 : public GlkAPI {
/**
* Flag for the game to restart
*/
void setRestart(bool flag) { _restartFlag = flag; }
void setRestart(bool flag) {
_restartFlag = flag;
}

/**
* Returns whether the game should restart
*/
bool shouldRestart() const { return _restartFlag; }
bool shouldRestart() const {
return _restartFlag;
}

/**
* Returns the running interpreter type
Expand Down
20 changes: 10 additions & 10 deletions engines/glk/alan3/alan_version.cpp
Expand Up @@ -26,16 +26,16 @@ namespace Glk {
namespace Alan3 {

const Product alan = {
"Alan",
"Adventure Language System",
"Alan 3.0beta6",
"Alan 3.0beta6 -- Adventure Language System (2017-09-08 10:18)",
"2017-09-08",
"10:18:25",
"Thomas",
"thoni64",
"cygwin32",
{"3.0beta6", 3, 0, 6, 1504858705, "beta"}
"Alan",
"Adventure Language System",
"Alan 3.0beta6",
"Alan 3.0beta6 -- Adventure Language System (2017-09-08 10:18)",
"2017-09-08",
"10:18:25",
"Thomas",
"thoni64",
"cygwin32",
{"3.0beta6", 3, 0, 6, 1504858705, "beta"}
};

} // End of namespace Alan3
Expand Down

0 comments on commit dc40211

Please sign in to comment.