//A6.60 c-script
/*
snippet from _helpyqz.wdl
(c)opyright dummy collective
may only be used without permission
*/
// TEXT used to show a question
TEXT qz_tQuestion {
red = 255;
green = 225;
blue = 255;
pos_x = 0;
pos_y = 0;
strings = 1;
flags = VISIBLE;
}
// contains a list of answers some of which are incorrect
TEXT qz_tAnswers {
red = 255;
green = 225;
blue = 255;
pos_x = 0;
pos_y = 50;
strings = 4;
flags = VISIBLE;
}
// contains a list of answers and questions in no particular order
// loaded from qz.txt
// see format file qz.txt
TEXT qz_tLoad {
strings = 60000;
}
var qz_nAnswer = 0; // the actual answer index in the questions TEXT
var qz_nLoad = 0; // number of lines loaded from qz.txt
var qz_bQuestionFound = 0; // result for qzf_getQuestion
var qz_bAnswerFound = 0; // result for qzf_getAnswer
STRING qz_sAnswer[1024]; // an answer temp string used with qzf_getAnswer
STRING qz_sQuestion[1024]; // a question temp string used with qzf_getQuestion
STRING qz_sNum[128]; // used to convert number to STRING in multiple functions
function random_int(_nLow, _nHigh) {
return(int(_nLow + ((_nHigh - _nLow) * random(1.001))));
}
// returns 1 if _sIn starts with _sFind
function str_starts(_sIn, _sFind) {
return(str_stri(_sIn, _sFind) == 1);
}
// loads qz_tAnswers with random answers, non of which are _nNotNumber (the correct answer)
function qzf_getRandomAnswers(_nAnswers, _nNotNumber) {
var n; n = random_int(0, qz_nLoad);
var nCalls; nCalls = 0;
var nAnswersFound; nAnswersFound = 0;
while(nCalls < qz_nLoad * 5) {
n = random_int(0, qz_nLoad - 1);
if (n != _nNotNumber) {
qzf_getAnswer(n);
if (qz_bAnswerFound) {
str_cpy(qz_tAnswers.string[nAnswersFound], qz_sAnswer);
nAnswersFound += 1;
if (nAnswersFound >= _nAnswers) { break; }
}
}
nCalls += 1;
}
}
// sets qz_sAnswer to answer in qz.txt
// modifies qz_bAnswerFound
function qzf_getAnswer(_nNumber) {
str_cpy(qz_sAnswer, "");
var n; n=0;
qz_bAnswerFound = 0;
while(n < qz_nLoad) {
str_for_num(qz_sNum, _nNumber);
str_cat(qz_sNum, "a");
if (str_starts(qz_tLoad.string[n], qz_sNum)) {
str_cpy(qz_sAnswer, qz_tLoad.string[n]);
str_clip(qz_sAnswer, str_len(qz_sNum));
qz_bAnswerFound = 1;
return(n);
}
n+=1;
}
}
// sets qz_sQuestion to question number _nNumber in qz.txt
// modifies qz_bQuestionFound
function qzf_getQuestion(_nNumber) {
str_cpy(qz_sQuestion, "");
var n; n=0;
qz_bQuestionFound = 0;
while(n < qz_nLoad) {
str_for_num(qz_sNum, _nNumber);
str_cat(qz_sNum, "q");
if (str_starts(qz_tLoad.string[n], qz_sNum)) {
str_cpy(qz_sQuestion, qz_tLoad.string[n]);
str_clip(qz_sQuestion, str_len(qz_sNum));
qz_bQuestionFound = 1;
return(n);
}
n+=1;
}
}
// loads all questions and answers from _sFileName into qz_tLoad
// modifies qz_nLoad (number of lines loaded)
function qzf_load(_sFileName) {
if (_sFileName == 0) { return(0); }
qz_nLoad = txt_load(qz_tLoad, _sFileName);
if (qz_nLoad == 0) { error("no questions loaded"); }
return(qz_nLoad);
}
// a test function
// call once from main
// press 1 , 2, or 3 key to select question 1, 2 or 3
// and generate 3 random answers plus one correct one
// note to fix: the 3 random answers might not be unique
function qzf_input() {
qzf_load("qz.txt");
while(1) {
wait(1);
var n; n = 0;
if (key_1) { n = 1; }
if (key_2) { n = 2; }
if (key_3) { n = 3; }
if (n != 0) {
qzf_getQuestion(n);
str_cpy(qz_tQuestion.string[0], qz_sQuestion);
qzf_getRandomAnswers(3, n);
qzf_getAnswer(n);
if (qz_bAnswerFound) {
qz_nAnswer = random_int(0, 3);
str_cpy(qz_tAnswers.string[3], qz_tAnswers.string[qz_nAnswer]);
str_cpy(qz_tAnswers.string[qz_nAnswer], qz_sAnswer);
}
}
}
}
/////////////////////////////////////////////////////////////////
// Desc: The main() function is started at game start
function main()
{
randomize();
// set some common flags and variables
// freeze all entity functions
freeze_mode = 1;
// no level has been loaded yet...
gid01_level_state = gid01_level_not_loaded;
// entry: Warning Level (0,1, or 2)
// entry_help: Sets sensitivity to warnings (0 = none, 1 = some, 2 = all).
warn_level = 2; // announce bad texture sizes and bad wdl code
// entry: Starting Mouse Mode (0, 1, or 2)
mouse_mode = 0;
// wait 3 frames (for triple buffering) until it is flipped to the foreground
wait(3);
qzf_input();
// now load the level
level_load(level_str);
wait(2); // let level load
// level should be loaded at this point...
gid01_level_state = gid01_level_loaded;
//+++ load starting values
// un-freeze the game
freeze_mode = 0;
// save start of game here
wait(6); // allow time for functions that wait for "gid01_level_loaded" to load
file_delete("start0.SAV"); // remove any old savefile
wait(1);
if( game_save("start",0,SV_ALL) <= 0)
{
diag("\nWARNING! main - Cannot save 'start' of level (ignore on restarts).");
}
else
{
diag("\nWDL: main - Game 'start' saved.");
}
// main game loop
while(1)
{
if(gid01_level_state != gid01_level_loaded)
{
freeze_mode = 1; // pause the game
while(gid01_level_state != gid01_level_loaded) { wait(1); }
freeze_mode = 0; // resume the game
}
wait(1);
}
}