Text rewriter in the works (I18N on the table)

#3
Pretty nifty... I was able to make my project do everything I wanted it to do with the text output (being the control freak that I am) with just the following code:

Code:
    ? //Mauntstraut 09 HACKING///////////////////////

        LPTSTR out = (LPTSTR)txt; //hack
        
        if(len<5)
        {
            static int percents = 0;

            if(*out=='x') //inventory: x1
            {
                for(LPTSTR p=out+1;*p&&*p==' ';p++);

                if(*p=='1'&&!p[1])
                {
                    *p = ' '; *out = ' ';
                }
            }
            else if(out[len-1]!='%')
            {                
                for(LPTSTR p=out;*p&&*p==' ';p++);

                if(*p>='0'&&*p<='9')
                {
                    for(LPCTSTR q=p;*q&&*q!='.';q++);
                    
                    if(!*q) //without decimal point
                    if(!percents)
                    {
                        for(char carry=' ';p[1];p++) //memmove()
                        {
                            int swap = *p; *p = carry; //easier to do...
                            
                            carry = p[1]; p[1] = swap; //in reverse
                        }
                    }
                    else percents--;
                }
            }
            else percents++;
        }
        else if(len==5) //spell cost maybe...
        {
            for(LPTSTR p=out;*p&&*p==' ';p++);

            if(*p>='0'&&*p<='9')
            {
                for(LPCTSTR q=p;*q&&*q!='.';q++);

                if(!*q) //without decimal point
                while(*p)
                {
                    p[-1] = *p; if(!*++p) p[-1] = '%';
                }
            }
        }

    ? ///////////////////////////////////////////////

Of course the eventual goal is to make rebuilding the "injection" dll as unnecessary as possible. At the least I can make it modular, so you can just rebuild a module just for your game. But making sense of the SOM text stream can be a bit difficult to automate.

In this case for example, I pretty much divided all of the 3 character wide/whole numbers by 10 so to keep the numbers simpler for players (because the 1s place was always 0 anyway)

But the Magic/Strength numbers are also 3 wide/whole, and I didn't want those divided. So the only way I could recognize them was to watch for the HP/MP fields which are pretty flexible, count them by their percent signs (added for this project) and count down from the the number of such occurrences before treating numbers as divisible by 10 (because the two HP/MP fields always come before the Strength/Magic fields)

Still that is automatable (script-able) enough I think, but just an example of the cleverness required.

I stripped out the x1 counters from the inventories. But I think I might rearrange them to be like 2x instead of "x?? 2" ...still not sure what I prefer.

I was even able to add % to the magic cost numbers, which were thankfully not embroiled into the 3 wide formats for some reason.


I think this sort of flexibility is a must for my involvement in a project, so it's good to see these sorts of possibilities opening up.
Reply



Messages In This Thread
Re: Text rewriter in the works (I18N on the table) - by HolyDiver - 2009-10-14, 03:49 AM



Users browsing this thread:
1 Guest(s)