IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> linux bot_script.cpp problem
bir3yk
post Sep 21 2009, 06:58 PM
Post #1


RCBot Fan
****

Group: Members
Posts: 107
Joined: 4-June 09
Member No.: 1,566



Cheeseh Hi.
After adding bot_script on my linux stopped working maps that use scripts. I could not understand what the problem. Today, it finally solved the problem, do not know how many correct, but the bots began to use scripts;) see whether I wrote.

bot_script.cpp



CODE
void CPoints :: loadMapScript ( )
{
    char filename[1024];

    vector < CResetPoint* > points;
    CResetPoint *currentpoint = NULL;

    freeMemory();
    
    //CBotGlobals::buildFileName(filename,CBotGlobals::getMapName(),BOT_SCRIPT_FOLDER,BOT_SCRIPT_EXTENSION);

    CBotGlobals::buildFileName(filename,CBotGlobals::getMapName(),BOT_WAYPOINT_FOLDER,BOT_SCRIPT_EXTENSION,true);

    FILE *fp = CBotGlobals::openFile(filename,"r");

    int state = STATE_NONE;

    if ( fp )
    {
        char line[256];
        int len;

        int linenum = 0;

        while ( fgets(line,255,fp) != NULL )
        {
            line[255] = 0;

            linenum++;

            if ( line[0] == '#' )
                continue;

            len = strlen(line);

            if ( line[len-1] == '\n' )
                line[--len] = 0;
//============================
#ifndef __linux__
            if ( line[len-1] == '\r' )
                line[--len] = 0;
#endif
//============================
            if ( len < 1 )
                continue;

            // control character
            if ( line[0] == ':' )
            {
                if ( strncmp(&line[1],"setup_time:",11) == 0 )
                {
                    CTeamFortress2Mod::setSetupTime(atoi(&line[12]));
                }
                else if ( strncmp(&line[1],"on_blue_cap:",12) == 0 )
                {
                    currentpoint = getPoint(&line[13]);
                    state = STATE_BLUE_CAP;
                }
                else if ( strncmp(&line[1],"on_red_cap:",11) == 0 )
                {
                    currentpoint = getPoint(&line[12]);
                    state = STATE_RED_CAP;
                }
                else if ( strncmp(&line[1],"on_reset:",9) == 0 )
                {
                    currentpoint = getPoint(NULL);
                    state = STATE_RESET;
                }
            }
            else if ( state != STATE_NONE )
            {
                int iTeam = 0;
                ePointStyle style;
            
                int i,n;
                char num[4];

                num[0] = 0;

                if ( strncmp("areas:",&line[0],6) == 0 )
                {
                    // get areas
                    i = 6;
                    n = 0;

                    while ( i < len )
                    {
                        if (line[i] == ' ')
                        {
                            i++;
                            continue;
                        }

                        if ( n < 3 )
                            num[n++] = line[i];

                        if ( ((i+1) >= len) || (line[i+1]==',') )
                        {
                            num[n]=0;
                            n = 0;

                            currentpoint->addValidArea(atoi(num));

                            i++;//skip ,
                        }

                        i++;
                    }

                    continue;
                }
                else if ( strncmp("red_",&line[0],4) == 0 )
                {
                    iTeam = TF2_TEAM_RED;
                    i = 4;
                }
                else if ( strncmp("blue_",&line[0],5) == 0 )
                {
                    iTeam = TF2_TEAM_BLUE;
                    i = 5;
                }
                else
                {
                    CBotGlobals::botMessage(NULL,0,"SCRIPT Syntax Error line : %d, missing team name",linenum);
                    // Syntax Error : missing team name
                    continue;
                }

                if ( strncmp("attack:",&line[i],7) == 0)
                    style = POINT_ATTACK;
                else if ( strncmp("defend:",&line[i],7) == 0 )
                    style = POINT_DEFEND;
                else
                {
                    CBotGlobals::botMessage(NULL,0,"SCRIPT Syntax Error line : %d, missing attack/defend",linenum);
                    // Syntax Error : missing attack/defend
                    continue;
                }

                // get points

                i = i + 7;
                n = 0;

                while ( i < len )
                {
                    if (line[i] == ' ')
                    {
                        i++;
                        continue;
                    }

                    if ( n < 3 )
                        num[n++] = line[i];

                    if ( ((i+1) >= len) || (line[i+1]==',') )
                    {
                        num[n]=0;
                        n = 0;

                        if ( state == STATE_RESET )
                            currentpoint->addPointStyle(0,iTeam,CPointStyle(atoi(num),style));
                        else if ( state == STATE_BLUE_CAP )
                            currentpoint->addPointStyle(TF2_TEAM_BLUE,iTeam,CPointStyle(atoi(num),style));
                        else if ( state == STATE_RED_CAP )
                            currentpoint->addPointStyle(TF2_TEAM_RED,iTeam,CPointStyle(atoi(num),style));

                        i++;//skip ,
                    }

                    i++;
                }
                
            }
        }
    }
    else
        return;
}
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th April 2024 - 02:28 PM