Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////
- /// Debug Shell for ZC Quests ///
- /// Alpha Version 1.6.2 ///
- /// 31st October, 2018 ///
- /// By: ZoriaRPG ///
- /// Requires: ZC Necromancer ///
- /////////////////////////////////
- //
- // v1.2 : Finished working code. now it all functions as I intend.
- // v1.2.1 : Added a code comment block with examples on how to add more instructions to match_instruction().
- // v1.2.1 : Added a sanity check to setting Link->Item[]. It now only works on inventory items.
- // v1.3.0 : Added the SAVE instruction.
- // v1.4.0 : Added CREATEITEM ( cri,id,x,y )
- // v1.4.0 : Added CREATENPC ( crn,id,x,y )
- // v1.4.0 : Fixed bug where buffer persists through saves.
- // v1.5.0 : Added LX and LY as literal args for Link's X and Y positions.
- // v1.6.0 : Added LX and LY tracing.
- // v1.6.0 : Added PALETTE as pal,n1,n2 -- POS now requires more than 'p' -- to change DMap Palette. -1 for current DMap.
- // v1.6.0 : This sets Game->DmapPalette[n1] = n2
- // v1.6.0 : Added MONOCHROME as mon,n to set Graphics->Monochrome(n1)
- // v1.6.1 : Added break instructiosn to fix invalid rval and other invalid returns in switch statements.
- // v1.6.2 : Added clear instructions to case for NONE in switch(instr).
- import "std.zh"
- /*
- DEFINED INSTRUCTION VALUES
- w WARP: return 2; //dmap,screen
- p POS: return 2; //x,y
- mx MOVEX: return 1; //pixels (+/-)
- my MOVEY: return 1; //pixels (+/-)
- rh REFILLHP: return 0; //aNONE
- rm REFILLMP: return 0; //NONE
- rc REFILLCTR: return 1; //counter
- mh MAXHP: return 1; //amount
- mm MAXMP: return 1; //amount
- mc MAXCTR: return 2; //counter, amount
- save SAVE: return 0;
- cri CREATEITEM: return 3; //id, x, y
- crn CREATENPC: return 3; //id, x, y
- inv INVINCIBLE: return 1; //(BOOL) on / off
- itm LINKITEM: return 2; //item, (BOOL), on / off
- pal PALETTE return 2
- mon MONOCHROME return 1
- //COMMAND LIST
- w: Warp Link to a specific dmap and screen
- p: Reposition Link on the screen.
- mx: Move link by +/-n pixels on the X axis.
- my: Move link by +/-n pixels on the Y axis.
- rh: Refill Link's HP to Max.
- rm: Refill Link's HP to Max.
- rc: Refill a specific counter to Max.
- mh: Set Link's Max HP.
- mm: Set Link's Max MP
- mc: Set the maximum value of a specific counter.
- inv: Set Link's Invisible state.
- itm: Set the state of a specific item in Link's inventory.
- save: Save the game.
- cri: Create an item.
- crn: Create an npc.
- pal: Change a DMap palette; -1 for current dmap.
- mono: Set monochrome effect.
- //SYNTAX
- //command,args
- w,1,2
- p,1,2
- mx,1
- mx,-1
- my,1
- my,-1
- rh
- rm
- rc,1
- mh,1
- mm,1
- mc,1,2
- inv,true
- inv,false
- itm,1,true
- itm,1,false
- save
- cri,1,2,3 //id,x,y
- crn,1,2,3 //id,x,y
- pal,1,2 //dmap (-1 for current), palette
- mono,1 : mono,type
- */
- script typedef ffc namespace;
- typedef const int define;
- typedef const int CFG;
- namespace script debugshell
- {
- define INSTRUCTION_SIZE = 1; //The number of stack registers that any given *instruction* requires.
- define MAX_INSTR_QUEUE = 1; //The number of instructions that can be enqueued.
- define MAX_ARGS = 3; //The maximum number of args that any instruction can use/require.
- define STACK_SIZE = 1 + ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE);
- define MAX_TOKEN_LENGTH = 16;
- define BUFFER_LENGTH = 42;
- int stack[STACK_SIZE];
- int SP;
- int debug_buffer[BUFFER_LENGTH];
- define YES = 1;
- define NO = 0;
- CFG log_actions = YES;
- CFG WINDOW_F_KEY = 7; //We use F7 to open the debug window.
- define FONT = FONT_APPLE2; //Apple II
- define F_COLOUR = 0x01; //font colour, white
- define F_BCOLOUR = -1; //font background colour, translucent
- define W_COLOUR = 0x03; //window colour (background), black
- define W_S_COLOUR = 0xC5; //window colour (background), black
- define CHAR_WIDTH = 6; //5 + one space
- define CHAR_HEIGHT = 9; //8 + one space
- define WINDOW_X = 15; //window indent over screen
- define WINDOW_Y = 19; //window indent over screen
- define WINDOW_H = 50;//CHAR_WIDTH * BUFFER_LENGTH;
- define WINDOW_W = 180; //CHAR_HEIGHT * 3;
- define WINDOW_S_X = 12; //window indent over screen
- define WINDOW_S_Y = 16; //window indent over screen
- define WINDOW_S_H = 50; //CHAR_WIDTH * BUFFER_LENGTH;
- define WINDOW_S_W = 180; //CHAR_HEIGHT * 3;
- define CHAR_X = 2; //Initial x indent
- define CHAR_Y = 2; //Initial y indent
- define W_OPACITY = OP_OPAQUE; //Window translucency.
- define F_OPACITY = OP_OPAQUE; //Font translucency.
- define W_LAYER = 6; //window draw layer
- define F_LAYER = 6; //font draw layer
- CFG KEY_DELAY = 6; //frames between keystrokes
- define TYPESFX = 63;
- void process()
- {
- if ( Input->Key[51] ) //46+WINDOW_F_KEY] )
- {
- TraceS("Enabled Deb ug Shell");
- if ( type() )
- {
- TraceS("process() evaluated type() true");
- int r = read(debug_buffer);
- if ( r ) execute();
- }
- }
- }
- //if ( type() execute() )
- //returns true if the user presses enter
- bool type()
- {
- int frame = 0;
- if ( !frame ) TraceS("Starting type()");
- ++frame;
- Game->TypingMode = true;
- int key_timer; int buffer_pos = 0;
- bool typing = true;
- //while(!Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD])
- while(typing)
- {
- if ( key_timer <= 0 )
- {
- if ( Input->ReadKey[KEY_BACKSPACE] ) //backspace
- {
- if ( buffer_pos > 0 )
- {
- debug_buffer[buffer_pos] = 0;
- --buffer_pos;
- debug_buffer[buffer_pos] = 0;
- }
- key_timer = KEY_DELAY;
- continue;
- }
- else if ( Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD] )
- {
- Game->TypingMode = false;
- TraceNL(); TraceS("Read enter key, and buffer position is: "); Trace(buffer_pos); TraceNL();
- if ( !buffer_pos ) return false; //do not execute if there are no commands
- return true;
- }
- else if ( EscKey() )
- {
- for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
- Game->TypingMode = false;
- return false; //exit and do not process.
- }
- else
- {
- //else normal key
- int k;
- int LegalKeys[]=
- {
- KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H,
- KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P,
- KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
- KEY_Y, KEY_Z, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
- KEY_6, KEY_7, KEY_8, KEY_9, KEY_0_PAD, KEY_1_PAD, KEY_2_PAD,
- KEY_3_PAD, KEY_4_PAD, KEY_5_PAD,
- KEY_6_PAD, KEY_7_PAD, KEY_8_PAD, KEY_9_PAD,
- //KEY_TILDE,
- KEY_MINUS,
- //KEY_EQUALS, KEY_OPENBRACE, KEY_CLOSEBRACE,
- //KEY_COLON, KEY_QUOTE, KEY_BACKSLASH, KEY_BACKSLASH2,
- KEY_COMMA,
- //KEY_SEMICOLON, KEY_SLASH, KEY_SPACE, KEY_SLASH_PAD,
- //KEY_ASTERISK,
- KEY_MINUS_PAD
- //KEY_PLUS_PAD, KEY_CIRCUMFLEX, KEY_COLON2, KEY_EQUALS_PAD, KEY_STOP
- };
- for ( int kk = SizeOfArray(LegalKeys)-1; kk >= 0; --kk )
- {
- k = LegalKeys[kk];
- if ( Input->ReadKey[k] )
- {
- TraceS("Read a key: "); Trace(k); TraceNL();
- debug_buffer[buffer_pos] = KeyToChar(k,(Input->ReadKey[KEY_LSHIFT])||(Input->ReadKey[KEY_RSHIFT])); //Warning!: Some masking may occur. :P
- TraceNL(); TraceS(debug_buffer); TraceNL();
- ++buffer_pos;
- key_timer = KEY_DELAY;
- break;
- }
- }
- //continue;
- }
- }
- else { --key_timer; }
- draw();
- Waitframe();
- }
- }
- void draw()
- {
- Screen->Rectangle(W_LAYER, WINDOW_S_X, WINDOW_S_Y, WINDOW_S_X+WINDOW_W, WINDOW_S_Y+WINDOW_H, W_S_COLOUR, 1, 0,0,0,true,W_OPACITY);
- Screen->Rectangle(W_LAYER, WINDOW_X, WINDOW_Y, WINDOW_X+WINDOW_W, WINDOW_Y+WINDOW_H, W_COLOUR, 1, 0,0,0,true,W_OPACITY);
- Screen->DrawString(F_LAYER,WINDOW_X+CHAR_X,WINDOW_Y+CHAR_Y,FONT,F_COLOUR,F_BCOLOUR,0,debug_buffer,F_OPACITY);
- }
- void TraceErrorS(int s, int s2)
- {
- TraceS(s); TraceS(": "); TraceS(s2); TraceNL();
- }
- void TraceError(int s, float v, float v2)
- {
- int buf[12]; int buf2[12];
- ftoa(buf,v);
- ftoa(buf2,v2);
- TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(buf2); TraceNL();
- }
- void TraceErrorVS(int s, float v, int s2)
- {
- int buf[12];
- ftoa(buf,v);
- TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(s2); TraceNL();
- }
- //instruction //variables
- define NONE = 0; //NONE
- define WARP = 1; //dmap,screen
- define POS = 2; //x,y
- define MOVEX = 3; //pixels (+/-)
- define MOVEY = 4; //pixels (+/-)
- define REFILLHP = 5; //aNONE
- define REFILLMP = 6; //NONE
- define REFILLCTR = 7; //counter
- define MAXHP = 8; //amount
- define MAXMP = 9; //amount
- define MAXCTR = 10; //counter, amount
- define INVINCIBLE = 11; //(BOOL) on / off
- define LINKITEM = 12; //item, (BOOL), on / off
- define SAVE = 13; //item, (BOOL), on / off
- define CREATEITEM = 14; //item, (BOOL), on / off
- define CREATENPC = 15; //item, (BOOL), on / off
- define PALETTE = 16; //item, (BOOL), on / off
- define MONOCHROME = 17; //item, (BOOL), on / off
- int num_instruction_params(int instr)
- {
- switch(instr)
- {
- //instruction //variables
- case NONE: return 0;
- case WARP: return 2; //dmap,screen
- case POS: return 2; //x,y
- case MOVEX: return 1; //pixels (+/-)
- case MOVEY: return 1; //pixels (+/-)
- case REFILLHP: return 0; //aNONE
- case REFILLMP: return 0; //NONE
- case REFILLCTR: return 1; //counter
- case MAXHP: return 1; //amount
- case MAXMP: return 1; //amount
- case MAXCTR: return 2; //counter, amount
- case INVINCIBLE: return 1; //(BOOL) on / off
- case LINKITEM: return 2; //item, (BOOL), on / off
- case SAVE: return 0; //item, (BOOL), on / off
- case CREATEITEM: return 3; //item, (BOOL), on / off
- case CREATENPC: return 3; //item, (BOOL), on / off
- case PALETTE: return 2; //item, (BOOL), on / off
- case MONOCHROME: return 1; //item, (BOOL), on / off
- default:
- {
- TraceError("Invalid instruction passed to stack",instr);
- clearbuffer();
- return 0;
- }
- }
- }
- int match_instruction(int token)
- {
- TraceNL(); TraceS("Input token into match_instruction is: "); TraceS(token); TraceNL();
- TraceNL(); TraceErrorS("match_instruction() token is: ",token); TraceNL();
- TraceNL(); TraceError("Matching string with strcmp to 'w': ", strcmp(token,"w")); TraceNL();
- /* ONE WAY TO DO THIS. I did this with individual characters, and switches, to minimise the checks down
- to the absolute minimum. -Z
- You could add specific instructions this way, if you wish.
- if ( !(strcmp(token,"w") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
- if ( !(strcmp(token,"W") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
- if ( !(strcmp(token,"p") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
- if ( !(strcmp(token,"P") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
- if ( !(strcmp(token,"rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
- if ( !(strcmp(token,"RH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
- if ( !(strcmp(token,"Rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
- if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
- */
- switch(token[0])
- {
- case 'c':
- case 'C':
- {
- switch(token[1])
- {
- case 'r':
- case 'R':
- {
- switch(token[2])
- {
- case 'i':
- case 'I':
- {
- TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATEITEM;
- }
- case 'n':
- case 'N':
- {
- TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATENPC;
- }
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- }
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- case 'p':
- case 'P':
- {
- switch(token[1])
- {
- case 'o':
- case 'O':
- TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return POS;
- case 'a':
- case 'A':
- TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return PALETTE;
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- case 'w':
- case 'W':
- TraceNL(); TraceS("instr() found token 'w'"); TraceNL(); return WARP;
- case 'r':
- case 'R':
- {
- switch(token[1])
- {
- case 'h':
- case 'H':
- return REFILLHP;
- case 'm':
- case 'M':
- return REFILLMP;
- case 'c':
- case 'C':
- return REFILLCTR;
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- case 'i':
- case 'I':
- {
- switch(token[1])
- {
- case 'n':
- case 'N':
- return INVINCIBLE;
- case 't':
- case 'T':
- return LINKITEM;
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- case 'm':
- case 'M':
- {
- switch(token[1])
- {
- case 'x':
- case 'X':
- TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX;
- case 'y':
- case 'Y':
- TraceNL(); TraceS("instr() found token 'my'"); return MOVEY;
- case 'h':
- case 'H':
- return MAXHP;
- case 'm':
- case 'M':
- return MAXMP;
- case 'c':
- case 'C':
- return MAXCTR;
- case 'o':
- case 'O':
- return MONOCHROME;
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- case 's':
- case 'S':
- {
- switch(token[1])
- {
- case 'a':
- case 'A':
- case 'V':
- case 'v':
- {
- TraceNL(); TraceS("instr() found token 'save'"); return SAVE;
- }
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- break;
- }
- default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
- }
- //if ( strcmp(token,"w") == 0) { TraceNL(); TraceS("instr() found token 'w'"); return WARP; }
- //else if ( strcmp(token,"p") == 0) { TraceNL(); TraceS("instr() found token 'p'"); return POS; }
- //else if ( strcmp(token,"mx") == 0) { TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX; }
- //else if ( strcmp(token,"my") == 0) return MOVEY;
- //else if ( strcmp(token,"rh") == 0) return REFILLHP;
- //else if ( strcmp(token,"rm") == 0) return REFILLMP;
- //else if ( strcmp(token,"rc") == 0) return REFILLCTR;
- //else if ( strcmp(token,"mh") == 0) return MAXHP;
- //else if ( strcmp(token,"mm") == 0) return MAXMP;
- //else if ( strcmp(token,"mc") == 0) return MAXCTR;
- //else if ( strcmp(token,"inv") == 0) return INVINCIBLE;
- //else// if ( strcmp(token,"itm") == 0) return LINKITEM;
- //else
- //{
- // TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token);
- // return 0;
- //}
- }
- void clearbuffer()
- {
- for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
- }
- int read(int str)
- {
- //debug
- TraceNL(); TraceS("Starting read() with an initial buffer of: "); TraceS(str); TraceNL();
- int token[16]; int input_string_pos;
- int e; int token_pos = 0; int current_param;
- for ( input_string_pos = 0; input_string_pos < MAX_TOKEN_LENGTH; ++input_string_pos )
- {
- if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
- if (str[input_string_pos] == NULL ) break;
- token[token_pos] = str[input_string_pos];
- ++token_pos;
- //debug
- //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
- }
- //debug
- TraceNL(); TraceS("read() token: "); TraceS(token); TraceNL();
- //put the instruction onto the stack.
- //Right now, we are only allowing one instruction at a time.
- //This allows for future expansion.
- stack[SP] = match_instruction(token);
- TraceNL(); TraceS("SP is: "); Trace(stack[SP]); TraceNL();
- int num_params = num_instruction_params(stack[SP]);
- TraceNL(); TraceS("Number of expected params "); Trace(num_params); TraceNL();
- if ( num_params )
- {
- if ( str[input_string_pos] == NULL )
- {
- //no params.
- TraceErrorS("Input string is missing params. Token was:", token);
- return 0;
- }
- }
- ++SP; //get the stack ready for the next instruction.
- //push the variables onto the stack.
- while ( current_param < num_params ) //repeat this until we are out of params
- //NOT a Do loop, because some instructions have no params!
- {
- for ( token_pos = MAX_TOKEN_LENGTH-1; token_pos >= 0; --token_pos ) token[token_pos] = 0; //clear the token
- //copy over new token
- token_pos = 0;
- TraceNL(); TraceS("read() is seeking for params."); TraceNL();
- int temp_max = input_string_pos+MAX_TOKEN_LENGTH;
- for ( ; input_string_pos < temp_max; ++input_string_pos )
- {
- if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
- if (str[input_string_pos] == NULL ) break;
- token[token_pos] = str[input_string_pos];
- ++token_pos;
- //debug
- //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
- }
- /*
- while( str[input_string_pos] != ',' || str[input_string_pos] != NULL ) //|| current_param >= num_params ) //token terminates on a comma, or the end of the string
- {
- token[token_pos] = str[input_string_pos]; //store the variable into a new token
- ++token_pos;
- }
- */
- TraceNL(); TraceS("read() is getting tval"); TraceNL();
- int tval; //value of the param
- //first check the boolean types:
- TraceNL(); TraceS("The arg token is: "); TraceS(token); TraceNL();
- if ( !isNumber(token[0]) )
- {
- switch(token[0])
- {
- case '-': tval = atof(token); break;
- case 't':
- case 'T':
- tval = 1; break;
- case 'f':
- case 'F':
- tval = 0; break;
- case 'l':
- case 'L':
- {
- switch(token[1])
- {
- case 'x':
- case 'X':
- {
- TraceError("tval set to Link->X: ", Link->X);
- tval = Link->X; break;
- }
- case 'y':
- case 'Y':
- {
- TraceError("tval set to Link->Y: ", Link->Y);
- tval = Link->Y; break;
- }
- default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
- }
- break;
- }
- default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
- }
- //if ( strcmp(token,"true") ) tval = 1;
- //else if ( strcmp(token,"T") ) tval = 1;
- //else if ( strcmp(token,"false") ) tval = 0;
- //else if ( strcmp(token,"F") ) tval = 0;
- }
- else //literals
- {
- tval = atof(token);
- TraceNL(); TraceS("found a literal var of: "); Trace(tval); TraceNL();
- }
- //push the token value onto the stack
- stack[SP] = tval;
- //now out stack looks like:
- //: PARAMn where n is the loop iteration
- //: PARAMn where n is the loop iteration
- //: PARAMn where n is the loop iteration
- //: INSTRUCTION
- ++SP; //this is why the stack size must be +1 larger than the3 total number of instructions and
- //params that it can hold.
- ++current_param;
- } //repeat this until we are out of params
- return 1;
- }
- //void getVarValue(int str)
- //{
- // variables[VP] = atof(str);
- // ++VP;
- //}
- void execute()
- {
- TraceNL(); TraceS("Stack Trace");
- for ( int q = SizeOfArray(stack)-1; q >= 0; --q )
- {
- TraceNL(); Trace(stack[q]);
- }
- TraceNL(); TraceS("Running execute()"); TraceNL();
- int reg_ptr = 0; //read the stack starting here, until we reach TOP.
- int args[MAX_ARGS];
- //evaluate the instruction:
- int instr = stack[reg_ptr];
- ++reg_ptr;
- int current_arg = 0;
- int num_of_params = num_instruction_params(instr);
- TraceNL(); TraceS("execute() expects number of args to be: "); Trace(num_of_params); TraceNL();
- for ( ; num_of_params > 0; --num_of_params )
- {
- args[current_arg] = stack[reg_ptr];
- TraceNL(); TraceS("Putting an arg on the heap. Arg value: "); Trace(args[current_arg]); TraceNL();
- ++current_arg;
- ++reg_ptr;
- }
- TraceNL(); TraceS("execute believes that the present instruction is: "); Trace(instr); TraceNL();
- TraceNL(); TraceS("args[0] is: "); Trace(args[0]); TraceNL();
- TraceNL(); TraceS("args[1] is: "); Trace(args[1]); TraceNL();
- switch(instr)
- {
- case NONE:
- TraceError("STACK INSTRUCTION IS INVALID: ", instr);
- Game->TypingMode = false;
- clearbuffer();
- break;
- case WARP:
- {
- Link->Warp(args[0],args[1]);
- if ( log_actions ) TraceError("Cheat System Warped Link to dmap,screen:",args[0],args[1]);
- break;
- }
- case POS:
- {
- Link->X = args[0];
- Link->Y = args[1];
- if ( log_actions ) TraceError("Cheat System repositioned Link to X,Y:",args[0],args[1]);
- break;
- }
- case MOVEX:
- {
- Link->X += args[0];
- if ( log_actions ) TraceError("Cheat system moved Link on his X axis by: ", args[0]);
- break;
- }
- case MOVEY:
- {
- Link->Y += args[0];
- if ( log_actions ) TraceError("Cheat system moved Link on his Y axis by", args[0]);
- break;
- }
- case REFILLHP:
- {
- Link->HP = Link->MaxHP;
- if ( log_actions ) TraceError("Cheat system refilled Link's HP to", Link->MaxHP);
- break;
- }
- case REFILLMP:
- {
- Link->MP = Link->MaxMP;
- if ( log_actions ) TraceError("Cheat system refilled Link's MP to", Link->MaxHP);
- break;
- }
- case REFILLCTR:
- {
- Game->Counter[args[0]] = Game->MCounter[args[0]];
- if ( log_actions ) TraceError("Cheat system refilled Counter", args[0]);
- break;
- }
- case MAXHP:
- {
- Game->MCounter[CR_LIFE] = args[0];
- if ( log_actions ) TraceError("Cheat system set Link's Max HP to:",args[0]);
- break;
- }
- case MAXMP:
- {
- Game->MCounter[CR_MAGIC] = args[0];
- if ( log_actions ) TraceError("Cheat system set Link's Max MP to:",args[0]);
- break;
- }
- case MAXCTR:
- {
- Game->Counter[args[0]] = args[1];
- if ( log_actions ) TraceError("Cheat system refilled Counter (id, amount):",args[0],args[1]);
- break;
- }
- case INVINCIBLE:
- {
- if ( args[0] )
- {
- Link->Invisible = true;
- if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","true");
- break;
- }
- else
- {
- Link->Invisible = false;
- if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","false");
- break;
- }
- }
- case LINKITEM:
- {
- itemdata id = Game->LoadItemData(args[0]);
- if ( id->Keep )
- {
- if ( args[1] )
- {
- Link->Item[args[0]] = true;
- if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","true");
- break;
- }
- else
- {
- Link->Item[args[0]] = false;
- if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","false");
- break;
- }
- }
- else break;
- }
- case SAVE:
- {
- TraceNL(); TraceS("Cheat system is saving the game.");
- clearbuffer();
- Game->Save();
- break;
- }
- case CREATEITEM:
- {
- if ( log_actions ) TraceError("Cheat system is creating item ID: ", args[0]);
- if ( log_actions ) TraceError("Cheat system is creating item at X Position: ", args[1]);
- if ( log_actions ) TraceError("Cheat system is creating item at Y Position: ", args[2]);
- item cci = Screen->CreateItem(args[0]);
- cci->X = args[1];
- cci->Y = args[2];
- break;
- }
- case CREATENPC:
- {
- if ( log_actions ) TraceError("Cheat system is creating npc ID: ", args[0]);
- if ( log_actions ) TraceError("Cheat system is creating npc at X Position: ", args[1]);
- if ( log_actions ) TraceError("Cheat system is creating npc at Y Position: ", args[2]);
- npc ccn = Screen->CreateNPC(args[0]);
- ccn->X = args[1];
- ccn->Y = args[2];
- break;
- }
- case PALETTE:
- {
- if ( args[0] < 0 )
- {
- Game->DMapPalette[Game->GetCurDMap()] = args[1];
- }
- else Game->DMapPalette[args[0]] = args[1];
- break;
- }
- case MONOCHROME:
- {
- Graphics->Monochrome(args[0]);
- }
- default:
- {
- TraceError("Invalid instruction passed to stack",instr);
- break;
- }
- }
- ///-----later, we'll add this: //pop everything off of the stack
- //just wipe the stack for now, as we only support one command at this time
- for ( int q = 0; q < 3; ++q ) stack[q] = 0;
- SP = 0;
- //clear the main buffer, too!
- for ( int cl = 0; cl < BUFFER_LENGTH; ++cl ) debug_buffer[cl] = 0;
- Game->TypingMode = false; //insurance clear
- Link->PressStart = false;
- Link->InputStart = false;
- }
- void run()
- {
- }
- }
- global script test
- {
- void run()
- {
- debugshell.SP = 0;
- debugshell.clearbuffer();
- while(1)
- {
- debugshell.process();
- Waitdraw();
- Waitframe();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement