/* FINAL DRAGON TEXT DISPLAY MODULE 4/25/05
JESSE HARRIS
SET UP BACKGROUND TO DISPLAY TEXT ON SCREEN FOR NPC
ALSO HAS A MAJORITY OF PLOT CODE FOR CRSYTALS AND SHOES
*/
#include <mygba.h>
#include <hel.h>
#include <iostream.h>
#include "stuff.hpp"
#include "drawtextbox.h"

extern u16 delay;
extern u8 sprites[127];
extern player watashi;
extern TCustomTextInfo g_TextInfo;
extern char * text[];
extern u16 textlength[];


void myTextInit()
{
    char tempy[30];
    delay = 20;  //global delay

    //hardcode HEAL IN TOWN
    if(watashi.textnum == 12)
    {
        watashi.hp = watashi.maxhp;
        watashi.mp = watashi.maxmp;
    }
    //endhardcode HEAL IN TOWN
    
    //hardcode SAVE IN TOWN
    if(watashi.textnum == 11)
    {
                int tempint;
        tempint = watashi.x;
        ham_SaveIntToRAM("X", tempint);
        tempint = watashi.y;
        ham_SaveIntToRAM("Y", tempint);
        tempint = watashi.map;
        ham_SaveIntToRAM("Map", tempint);
        tempint = watashi.textnum;
        ham_SaveIntToRAM("Textnum", tempint);
        tempint = watashi.musicnum;
        ham_SaveIntToRAM("Musicnum", tempint);
        tempint = watashi.dir;
        ham_SaveIntToRAM("Dir", tempint);
        tempint = watashi.hp;
        ham_SaveIntToRAM("Hp", tempint);
        tempint = watashi.maxhp;
        ham_SaveIntToRAM("Maxhp", tempint);
        tempint = watashi.mp;
        ham_SaveIntToRAM("Mp", tempint);
        tempint = watashi.maxmp;
        ham_SaveIntToRAM("Maxmp", tempint);
        tempint = watashi.exp;
        ham_SaveIntToRAM("Exp", tempint);
        tempint = watashi.level;
        ham_SaveIntToRAM("Level", tempint);
        tempint = watashi.playerstate;
        ham_SaveIntToRAM("Playerstate", tempint);
    }
    //endhardcode
    
    //hardcode KINGTALK PLOT
    if(watashi.textnum == 17 && (watashi.playerstate & PS_KINGTALK) )
    {
        watashi.textnum = 8;
    }
    if(watashi.textnum == 17)
    {
        watashi.playerstate = watashi.playerstate | PS_KINGTALK;
    }
    //endhardcode
    
    //hardcode CRYSTAL1 PLOT
    if(watashi.textnum == 21 && (watashi.map == 10) && (watashi.playerstate & PS_CRYSTAL1) )
    {
        watashi.textnum = 7;
    }
    if(watashi.textnum == 21 && (watashi.map == 10))
    {
        watashi.playerstate = watashi.playerstate | PS_CRYSTAL1;
    }
    //endhardcode

    //hardcode CRYSTAL2 PLOT
    if(watashi.textnum == 21 && (watashi.map == 11) && (watashi.playerstate & PS_CRYSTAL2) )
    {
        watashi.textnum = 7;
    }
    if(watashi.textnum == 21 && (watashi.map == 11))
    {
        watashi.playerstate = watashi.playerstate | PS_CRYSTAL2;
    }
    //endhardcode

    //hardcode CRYSTAL3 PLOT
    if(watashi.textnum == 21 && (watashi.map == 15) && (watashi.playerstate & PS_CRYSTAL3) )
    {
        watashi.textnum = 7;
    }
    if(watashi.textnum == 21 && (watashi.map == 15))
    {
        watashi.playerstate = watashi.playerstate | PS_CRYSTAL3;
    }
    //endhardcode
    
    //hardcode CRYSTAL4 PLOT
    if(watashi.textnum == 21 && (watashi.map == 16) && (watashi.playerstate & PS_CRYSTAL4) )
    {
        watashi.textnum = 7;
    }
    if(watashi.textnum == 21 && (watashi.map == 16))
    {
        watashi.playerstate = watashi.playerstate | PS_CRYSTAL4;
    }
    //endhardcode
    
    //hardcode CRYSTAL5 PLOT
    if(watashi.textnum == 21 && (watashi.map == 17) && (watashi.playerstate & PS_CRYSTAL5) )
    {
        watashi.textnum = 7;
    }
    if(watashi.textnum == 21 && (watashi.map == 17))
    {
        watashi.playerstate = watashi.playerstate | PS_CRYSTAL5;
    }
    //endhardcode

    //hardcode HIKINGBOOTS PLOT
    if(watashi.textnum == 9 && (watashi.playerstate & PS_CRYSTAL1) && (watashi.playerstate & PS_CRYSTAL2) && (watashi.playerstate & PS_CRYSTAL3) && (watashi.playerstate & PS_CRYSTAL4) && (watashi.playerstate & PS_CRYSTAL5) && (watashi.playerstate & PS_SWAMPBOOTS) && (watashi.playerstate & PS_HIKINGBOOTS) && (watashi.playerstate & PS_DESERTSHOES))
    {
        watashi.textnum = 24;
    }
    if(watashi.textnum == 9 && (watashi.playerstate & PS_CRYSTAL1) && (watashi.playerstate & PS_CRYSTAL2) && (watashi.playerstate & PS_CRYSTAL3) && (watashi.playerstate & PS_CRYSTAL4) && (watashi.playerstate & PS_CRYSTAL5) && (watashi.playerstate & PS_SWAMPBOOTS) && (watashi.playerstate & PS_HIKINGBOOTS) )
    {
        watashi.textnum = 23;
        watashi.playerstate = watashi.playerstate | PS_DESERTSHOES;
    }
    //endhardcode

    //hardcode HIKINGBOOTS PLOT
    if(watashi.textnum == 9 && (watashi.playerstate & PS_CRYSTAL1) && (watashi.playerstate & PS_CRYSTAL2) && (watashi.playerstate & PS_SWAMPBOOTS) && (watashi.playerstate & PS_HIKINGBOOTS))
    {
        watashi.textnum = 6;
    }
    if(watashi.textnum == 9 && (watashi.playerstate & PS_CRYSTAL1) && (watashi.playerstate & PS_CRYSTAL2) && (watashi.playerstate & PS_SWAMPBOOTS) )
    {
        watashi.textnum = 22;
        watashi.playerstate = watashi.playerstate | PS_HIKINGBOOTS;
    }
    //endhardcode
    
    //hardcode SWAMPBOOTS PLOT
    if(watashi.textnum == 9 && (watashi.playerstate & PS_SWAMPBOOTS))
    {
        watashi.textnum = 6;
    }
    if(watashi.textnum == 9)
    {
        watashi.playerstate = watashi.playerstate | PS_SWAMPBOOTS;
    }
    //endhardcode

    //visual functions
    for(int x = 0; x < 119; x++)
    {
        ham_SetObjVisible(sprites[x], 0);
    }
    hel_CustomTextClear(&g_TextInfo);
    ham_SetBgVisible(2,1);
    //actually write text on the screen
    //a more intelligent function will hopefully one day be created
    drawTextBox(g_TextInfo,0,0,29,19);
    int x;
    for(x=0; x <= (textlength[watashi.textnum] / 28);x++)
    {
        for(int y = 0; y < 28; y++)
        {
            tempy[y] = text[watashi.textnum][x * 28 + y];
        }
        tempy[28] = 0;
        hel_CustomTextPrint(&g_TextInfo, 1, x + 1, tempy);
    }
    return;
}


/* END OF FILE */
