ZoriaRPG icon

Random Encounter Template v0.1

ZoriaRPG | PRO | 02/07/18 02:26:26 PM UTC | 0 ⭐ | 681 👁️ | Never ⏰ | []
C++ |

3.21 KB

|

None

|

0 👍

/

0 👎

 
void RandomEncounter()
{
    mapdata m = Game->LoadMapDat(Game->GetCurMap(), Game->GetCurScreen());
    npcdata e = Game->LoadNPCData(m-Enemy[Rand(10]l
    ffc f = Screen->LoadFFC(32);
    f->Script = Game->GetFFCScript("Battle");
    f->InitD[0] = e;
    f->InitD[1] = m; //for drawing backdrops
}
 
 
ffc script Battle
{
   void run(npcdata e, mapdata m)
   {
        bool waiting; int mode; int action;
    while(1)
    {
        // Draw background using 'm'
                // draw npc using 'e'
            // determine e's attacks using it's attributes;
            // draw menus
            // determine who goes first
            mode = Rand(1); //if 1, enemy goes first
            while(mode)
            {
                //do enemy actions
                //Waitframe();
            }
            while(!mode)
            {
                //player actions
            waiting = true;
            while(waiting)
            {
                //do_menus();
                action = BattleMenu();
                    Waitframe();
                }
            
                //resolve stuff this round
            Waitframe();
        }
    }
}
 
 
// There are certainly other ways to handle these...
// Vars used by the Tango menu. 
int menuCommand;
int menuArg;
 
//Tango Menu Init
void SetUpWindow(int slot, int style, int x, int y, int size)
{
    SetStyleSize(style, size);
    Tango_ClearSlot(slot);
    Tango_SetSlotStyle(slot, style);
    Tango_SetSlotPosition(slot, x, y);
}
 
//Quick way to drop a string into a Tango dialogue box. 
void ShowString(int string, int slot, int style, int x, int y)
{
    SetUpWindow(slot, style, x, y, SIZE_LARGE);
    Tango_LoadString(slot, string);
    Tango_ActivateSlot(slot);
    while(Tango_SlotIsActive(slot))   
        Waitframe();
}
 
 
//The 'yes/no' menu called by the ffc. 
int BattleMenu() {
 
    int lineBreak[]="@26";
    int line1[]="@choice(1)Attack@tab(40)@choice(2)Spell@26";
    int line2[]="@choice(3)Item@tab(40)@choice(4)Item@domenu(1)@suspend()";
    
    
    SetUpWindow(WINDOW_SLOT_1, WINDOW_STYLE_3, 32, 32, SIZE_LARGE);
        Tango_LoadString(WINDOW_SLOT_1, line1);
    Tango_AppendString(WINDOW_SLOT_1, line2);
        Tango_ActivateSlot(WINDOW_SLOT_1);
 
    
    while(!Tango_MenuIsActive()){
        
        Waitframe();
    }
    
    // Save the state again...
    int slotState[278];
    int menuState[960];
    int cursorPos;
    Tango_SaveSlotState(WINDOW_SLOT_1, slotState);
    Tango_SaveMenuState(menuState);
    
    int done = 0;
    int choice;
    while(true){
    
        while( Tango_MenuIsActive() ) {
            cursorPos=Tango_GetMenuCursorPosition();
            Waitframe();
        }
        
        choice = Tango_GetLastMenuChoice();
        if ( choice == 1 ) { // Item Info
            int text[256];
            Game->GetMessage(msg,text); //Load msg into the buffer.
            ShowString(text, WINDOW_SLOT_2, WINDOW_STYLE_3, 48, 48);
        }
        else if ( choice == 2 ) { //Buy
            done = choice;
            menuArg = choice;
        }
        
        else if ( choice == 3 ) { //Cancel
            done = choice;
        }
        
        else if ( Link->PressEx1 ) {
            done = 1;
        }
        else done = 3;
 
        if ( done ) {
            break;
        //  return choice;
        }
        else {
            Tango_RestoreSlotState(WINDOW_SLOT_1, slotState);
            Tango_RestoreMenuState(menuState);
            Tango_SetMenuCursorPosition(cursorPos);
        }
    }
    
    Tango_ClearSlot(WINDOW_SLOT_1);
    return done;
}

Comments