Ejemplo n.º 1
0
varbox::varbox()
{
    loopi(VARBOXMAXNODES) nodes[i] = NULL;
}
Ejemplo n.º 2
0
void purgetextures()
{
    loopi(256) loop(j,MAXFRAMES) mapping[i][j] = 0;
};
Ejemplo n.º 3
0
gui_options::gui_options(app_wiiradio* _theapp) :
    logo(0),
    media_free_space_desc("unknown"),
    last_time_ds(0)
{
    theapp = _theapp;
    fnts = theapp->GetFonts();
    guibuffer =  theapp->ui->guibuffer;

    logo = IMG_Load(make_path("data/imgs/def_logo.png"));

    loopi(O_MAX) b_option_item[i] = 0;
    loopi(OB_MAX) option_buts[i] = 0;

    //quit

    option_buts[OB_QUIT] = new gui_button(theapp, 20,425,0,0,false);
    option_buts[OB_QUIT]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_over.png",0,0);
    option_buts[OB_QUIT]->set_text(theapp->GetVariables()->search_var("$LANG_TXT_EXIT"));
    option_buts[OB_QUIT]->pad_y = 5;
    option_buts[OB_QUIT]->text_color = 0x000000;
    option_buts[OB_QUIT]->text_color_over = 0xff0044;
    option_buts[OB_QUIT]->font_sz = FS_SYSTEM;
    option_buts[OB_QUIT]->center_text = true;
    option_buts[OB_QUIT]->bind_screen = S_OPTIONS;
    option_buts[OB_QUIT]->parent = (gui_object*)this;

    //return
    option_buts[OB_RETURN] = new gui_button(theapp,150,425,0,0,false);
    option_buts[OB_RETURN]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_over.png",0,0);
    option_buts[OB_RETURN]->set_text(theapp->GetVariables()->search_var("$LANG_TXT_OK"));
    option_buts[OB_RETURN]->pad_y = 5;
    option_buts[OB_RETURN]->text_color = 0x000000;
    option_buts[OB_RETURN]->text_color_over = 0xff0044;
    option_buts[OB_RETURN]->font_sz = FS_SYSTEM;
    option_buts[OB_RETURN]->center_text = true;
    option_buts[OB_RETURN]->bind_screen = S_OPTIONS;
    option_buts[OB_RETURN]->parent = (gui_object*)this;

    //more
/*
    option_buts[OB_MORE] = new gui_button(theapp,500,425,0,0,false);
    option_buts[OB_MORE]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_over.png",0,0);
    option_buts[OB_MORE]->set_text("More >>>");//theapp->vars->search_var("$LANG_TXT_OK"));
    option_buts[OB_MORE]->pad_y = 5;
    option_buts[OB_MORE]->text_color = 0x000000;
    option_buts[OB_MORE]->text_color_over = 0xff0044;
    option_buts[OB_MORE]->font_sz = FS_SYSTEM;
    option_buts[OB_MORE]->center_text = true;
    option_buts[OB_MORE]->bind_screen = S_OPTIONS;
    option_buts[OB_MORE]->parent = (gui_object*)this;
*/
    int y = 90;

    service_group = new gui_group(theapp,2,220,y,41,26,143,NULL);
    service_group->set_on(theapp->GetSettings()->oservicetype);


    y += 35;
/*  Removed for now this is kinda annoying to most
    b_option_item[O_SCROLL_TEXT] = new gui_button(theapp,220,y,0,0,0);
    b_option_item[O_SCROLL_TEXT]->set_images((char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_on.png");
    b_option_item[O_SCROLL_TEXT]->bind_screen = S_OPTIONS;
    b_option_item[O_SCROLL_TEXT]->set_image_onout((char*)"data/imgs/toggle_on.png");
    b_option_item[O_SCROLL_TEXT]->parent = (gui_object*)this;
*/
    b_option_item[O_WIDESCREEN] = new gui_button(theapp,403,y,0,0,0);
    b_option_item[O_WIDESCREEN]->set_images((char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_on.png");
    b_option_item[O_WIDESCREEN]->bind_screen = S_OPTIONS;
    b_option_item[O_WIDESCREEN]->parent = (gui_object*)this;
    b_option_item[O_WIDESCREEN]->set_image_onout((char*)"data/imgs/toggle_on.png");
    y += 35;

    b_option_item[O_STARTFROMLAST] = new gui_button(theapp,220,y,0,0,0);
    b_option_item[O_STARTFROMLAST]->set_images((char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_on.png");
    b_option_item[O_STARTFROMLAST]->bind_screen = S_OPTIONS;
    b_option_item[O_STARTFROMLAST]->parent = (gui_object*)this;
    b_option_item[O_STARTFROMLAST]->set_image_onout((char*)"data/imgs/toggle_on.png");

    b_option_item[O_RIPMUSIC] = new gui_button(theapp,403,y,0,0,0);
    b_option_item[O_RIPMUSIC]->set_images((char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_out.png",(char*)"data/imgs/toggle_on.png");
    b_option_item[O_RIPMUSIC]->bind_screen = S_OPTIONS;
    b_option_item[O_RIPMUSIC]->parent = (gui_object*)this;
    b_option_item[O_RIPMUSIC]->set_image_onout((char*)"data/imgs/toggle_on.png");

    y += 50;

    saver_group = new gui_group(theapp,4,220,y,41,26,20,NULL);
    saver_group->set_on(theapp->GetSettings()->oscreensavetime);
    saver_group->bind_screen = S_OPTIONS;

    y += 45;

    sleep_timer_group = new gui_group(theapp,6,220,y,41,26,20,&sleep_timer_callback);
    sleep_timer_group->set_on(theapp->GetSettings()->osleep_timer_time);
    sleep_timer_group->bind_screen = S_OPTIONS;
    sleep_timer_group->parent = (gui_object*)this;

    y += 45;

    // visual type
    visuals_group = new gui_group(theapp,2,220,y,41,26,40,NULL);
    visuals_group->set_on(theapp->GetSettings()->ovisual_mode);
    visuals_group->bind_screen = S_OPTIONS;
    visuals_group->parent = (gui_object*)this;

    y += 35;

    // next skin
    option_buts[OB_NEXT_SKIN] = new gui_button(theapp, 420,y,0,0,false);
    option_buts[OB_NEXT_SKIN]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_out.png",0,0);
    option_buts[OB_NEXT_SKIN]->set_text(theapp->GetVariables()->search_var("$LANG_TXT_NEXT_SKIN"));
    option_buts[OB_NEXT_SKIN]->pad_y = 5;
    option_buts[OB_NEXT_SKIN]->text_color = 0x000000;
    option_buts[OB_NEXT_SKIN]->text_color_over = 0xff0044;
    option_buts[OB_NEXT_SKIN]->font_sz = FS_SYSTEM;
    option_buts[OB_NEXT_SKIN]->center_text = true;
    option_buts[OB_NEXT_SKIN]->bind_screen = S_OPTIONS;
    option_buts[OB_NEXT_SKIN]->parent = (gui_object*)this;

    y += 50;

    // next lang
    option_buts[OB_NEXT_LANG] = new gui_button(theapp,420,y,0,0,false);
    option_buts[OB_NEXT_LANG]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_out.png",0,0);
    option_buts[OB_NEXT_LANG]->set_text(theapp->GetVariables()->search_var("$LANG_TXT_NEXT_LANG"));
    option_buts[OB_NEXT_LANG]->pad_y = 5;
    option_buts[OB_NEXT_LANG]->text_color = 0x000000;
    option_buts[OB_NEXT_LANG]->text_color_over = 0xff0044;
    option_buts[OB_NEXT_LANG]->font_sz = FS_SYSTEM;
    option_buts[OB_NEXT_LANG]->center_text = true;
    option_buts[OB_NEXT_LANG]->bind_screen = S_OPTIONS;
    option_buts[OB_NEXT_LANG]->parent = (gui_object*)this;

//#ifdef _WII_
    // reinir network
    option_buts[OB_NET_REINIT] = new gui_button(theapp,280,425,0,0,false);
    option_buts[OB_NET_REINIT]->set_images((char*)"data/imgs/button_out.png",(char*)"data/imgs/button_out.png",0,0);
    option_buts[OB_NET_REINIT]->set_text(theapp->GetVariables()->search_var("$LANG_REINTNET"));
    option_buts[OB_NET_REINIT]->pad_y = 5;
    option_buts[OB_NET_REINIT]->text_color = 0x000000;
    option_buts[OB_NET_REINIT]->text_color_over = 0xff0044;
    option_buts[OB_NET_REINIT]->font_sz = FS_SYSTEM;
    option_buts[OB_NET_REINIT]->center_text = true;
    option_buts[OB_NET_REINIT]->bind_screen = S_OPTIONS;
    option_buts[OB_NET_REINIT]->parent = (gui_object*)this;
//#endif
    // set options
//    theapp->GetSettings()->oscrolltext ? b_option_item[O_SCROLL_TEXT]->obj_sub_state = B_ON : b_option_item[O_SCROLL_TEXT]->obj_sub_state = B_OFF;
    theapp->GetSettings()->owidescreen ? b_option_item[O_WIDESCREEN]->obj_sub_state = B_ON : b_option_item[O_WIDESCREEN]->obj_sub_state = B_OFF;
    theapp->GetSettings()->oripmusic ? b_option_item[O_RIPMUSIC]->obj_sub_state = B_ON : b_option_item[O_RIPMUSIC]->obj_sub_state = B_OFF;
//    GetSYSVariable(SYS_RIPPING) ? b_option_item[O_RIPMUSIC]->obj_sub_state = B_ON : b_option_item[O_RIPMUSIC]->obj_sub_state = B_OFF;
    theapp->GetSettings()->ostartfromlast ? b_option_item[O_STARTFROMLAST]->obj_sub_state = B_ON : b_option_item[O_STARTFROMLAST]->obj_sub_state = B_OFF;

    // Try calc. ds on construction
    media_free_space_desc = get_media_free_space_desc();
};
Ejemplo n.º 4
0
void gui_options::output_options()
{
    this->visible = true;

    int x = 0;
    ostringstream str;

    //logo
    SDL_Rect rc = {50,30,logo->w,logo->h};
    SDL_BlitSurface(logo,0,guibuffer,&rc);

    // Font setup
    fnts->change_color(100,100,100);
    fnts->set_size(FS_SYSTEM);

    // -- about
    str << theapp->GetVariables()->search_var("$LANG_ABOUT")
        << " v" << VERSION_NUMBER << " - " << theapp->GetVariables()->search_var("$LANG_AUTHOR")
        << " Scanff, TiMeBoMb " << theapp->GetVariables()->search_var("$LANG_AND") << " Knarrff";
    fnts->text(guibuffer, str.str().c_str(), 200, 50, 0, 0);

    int y = 90;

    // for service type
    fnts->text(guibuffer,"SHOUTcast :",200,y,0,1);
    fnts->text(guibuffer,"Icecast :",393,y,0,1);

    y += 35;
    // Scrolltext, Widescreen, Rip Music
    //fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_SCROLL_STATIONTEXT"),200,y,0,1);
    fnts->text(guibuffer,"Widescreen :",393,y,0,1); // -- TO DO Variable this

    y += 35;
    fnts->text(guibuffer,"Play last at start :", 200,y,0,1); // -- TO DO Variable this
    fnts->text(guibuffer,"Rip Music :",393,y,0,1); // -- TO DO Variable this

    /*
        Show the user how much free space they have left.
        Only run this every few seconds as it my lag
    */
/*    if((SDL_GetTicks() - last_time_ds > 1000*10) && GetSYSVariable(SYS_RIPPING))
    {
        last_time_ds = SDL_GetTicks();
        media_free_space_desc = get_media_free_space_desc();
    }
*/
    fnts->text(guibuffer,("(Free space: "+media_free_space_desc+")").c_str(),450,y,0,0);

    y += 50;
    // screen save
    fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_SCREEN_SAVE"),200,y,0,1);
    fnts->text(guibuffer,"  Off         1min       5min      10min",220,y-20,0,0);

    y += 45;
    // sleep timer
    fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_SLEEP_TIMER"),200,y,0,1);
    fnts->text(guibuffer,"  Off         5min      15min     30min        1h           3h",220,y-20,0,0);

    y += 45;
    // visual type/mode
    fnts->text(guibuffer,"Visual Mode:",190,y,0,1);
    fnts->text(guibuffer,"ProjectM     Classic(2D)",215,y-20,0,0);

    y += 35;
    // -- skin changer
    fnts->change_color(100,100,100);
    fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_CHANGE_SKIN"),200,y,0,1);
    fnts->change_color(40,40,100);

    fnts->text(guibuffer,theapp->GetVariables()->search_var("skinname"),220,y,0);
    x = fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_AUTHOR"),220,y+20,0);
    x += fnts->text(guibuffer,": ",220+x,y+20,0);
    fnts->text(guibuffer,theapp->GetVariables()->search_var("skinauthor"),220+x,y+20,0);

    y += 50;
    // -- language selection
    fnts->change_color(100,100,100);
    fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_CHANGE_LANG"),200,y,0,1);
    fnts->change_color(40,40,100);
    fnts->text(guibuffer,theapp->GetVariables()->search_var("$LANG_NAME"),220,y,0);

    // -- draw the butons ect...
    loopi(O_MAX) b_option_item[i]->draw();
    loopi(OB_MAX) option_buts[i]->draw();

    saver_group->draw();
    sleep_timer_group->draw();
    visuals_group->draw();
    service_group->draw();
}
Ejemplo n.º 5
0
 /// configure spawn settings (weapons, ammo, health...) depending on game mode
 void spawnstate(int gamemode)
 {
     if(m_demo)
     {
         gunselect = GUN_FIST;
         backupweapon = GUN_FIST;
     } else if(m_insta)
     {
         armour = 0;
         health = 1;
         gunselect = GUN_RIFLE;
         ammo[GUN_RIFLE] = 100;
         backupweapon = GUN_FIST;
     } else if(m_regencapture)
     {
         armourtype = A_BLUE;
         armour = 25;
         gunselect = GUN_PISTOL;
         ammo[GUN_PISTOL] = 40;
         ammo[GUN_GL] = 1;
         backupweapon = GUN_FIST;
     } else if(m_tactics)
     {
         armourtype = A_GREEN;
         armour = 100;
         ammo[GUN_PISTOL] = 40;
         backupweapon = GUN_FIST;
         int spawngun1 = inexor::util::random::rnd(5)+1, spawngun2;
         gunselect = spawngun1;
         baseammo(spawngun1, m_noitems ? 2 : 1);
         do spawngun2 = inexor::util::random::rnd(5)+1; while(spawngun1==spawngun2);
         baseammo(spawngun2, m_noitems ? 2 : 1);
         if(m_noitems) ammo[GUN_GL] += 1;
     } else if(m_efficiency)
     {
         armourtype = A_GREEN;
         armour = 100;
         loopi(5) baseammo(i+1);
         gunselect = GUN_CG;
         ammo[GUN_CG] /= 2;
         backupweapon = GUN_FIST;
     } else if(m_ctf || m_collect)
     {
         armourtype = A_BLUE;
         armour = 50;
         ammo[GUN_PISTOL] = 40;
         ammo[GUN_GL] = 1;
         backupweapon = GUN_FIST;
     } else if(m_bomb)
     {
         health = 1;
         armourtype = A_GREEN;
         armour = 0;
         gunselect = GUN_BOMB;
         backupweapon = GUN_BOMB;
     } else if(m_hideandseek)
     {
         health = 100;
         armour = 0;
         gunselect = GUN_RL;
         ammo[GUN_RL] = 10;
         ammo[GUN_PISTOL] = 0;
         ammo[GUN_GL] = 0;
         backupweapon = GUN_FIST;
     } else
     {
         armourtype = A_BLUE;
         armour = 25;
         ammo[GUN_PISTOL] = 40;
         ammo[GUN_GL] = 1;
         backupweapon = GUN_FIST;
     }
 }
Ejemplo n.º 6
0
skins::skins(app_wiiradio* _theapp) :  theapp(_theapp), total_skins(0), current_skin(0), current_objectid(0)
{
    loopi(MAX_SKINS) skin_list[i] = 0;
    find_skins();

}
Ejemplo n.º 7
0
void demoplaybackstep()
{
    while(demoplayback && lastmillis>=playbacktime)
    {
        int len = gzgeti();
        if(len<1 || len>MAXTRANS)
        {
            conoutf("error: huge packet during demo play (%d)", len);
            stopreset();
            return;
        };
        uchar buf[MAXTRANS];
        gzread(f, buf, len);
        localservertoclient(buf, len);  // update game state
        
        dynent *target = players[democlientnum];
        assert(target); 
        
		int extras;
        if(extras = gzget())     // read additional client side state not present in normal network stream
        {
            target->gunselect = gzget();
            target->lastattackgun = gzget();
            target->lastaction = scaletime(gzgeti());
            target->gunwait = gzgeti();
            target->health = gzgeti();
            target->armour = gzgeti();
            target->armourtype = gzget();
            loopi(NUMGUNS) target->ammo[i] = gzget();
            target->state = gzget();
            target->lastmove = playbacktime;
			if(bdamage = gzgeti()) damageblend(bdamage);
			if(ddamage = gzgeti()) { gzgetv(dorig); particle_splash(3, ddamage, 1000, dorig); };
            // FIXME: set more client state here
        };
        
        // insert latest copy of player into history
        if(extras && (playerhistory.empty() || playerhistory.last()->lastupdate!=playbacktime))
        {
            dynent *d = newdynent();
            *d = *target;
            d->lastupdate = playbacktime;
            playerhistory.add(d);
            if(playerhistory.length()>20)
            {
                zapdynent(playerhistory[0]);
                playerhistory.remove(0);
            };
        };
        
        readdemotime();
    };
    
    if(demoplayback)
    {
        int itime = lastmillis-demodelaymsec;
        loopvrev(playerhistory) if(playerhistory[i]->lastupdate<itime)      // find 2 positions in history that surround interpolation time point
        {
            dynent *a = playerhistory[i];
            dynent *b = a;
            if(i+1<playerhistory.length()) b = playerhistory[i+1];
            *player1 = *b;
            if(a!=b)                                // interpolate pos & angles
            {
				dynent *c = b;
				if(i+2<playerhistory.length()) c = playerhistory[i+2];
				dynent *z = a;
				if(i-1>=0) z = playerhistory[i-1];
				//if(a==z || b==c) printf("* %d\n", lastmillis);
				float bf = (itime-a->lastupdate)/(float)(b->lastupdate-a->lastupdate);
				fixwrap(a, player1);
				fixwrap(c, player1);
				fixwrap(z, player1);
				vdist(dist, v, z->o, c->o);
				if(dist<16)		// if teleport or spawn, dont't interpolate
				{
					catmulrom(z->o, a->o, b->o, c->o, bf, player1->o);
					catmulrom(*(vec *)&z->yaw, *(vec *)&a->yaw, *(vec *)&b->yaw, *(vec *)&c->yaw, bf, *(vec *)&player1->yaw);
				};
				fixplayer1range();
			};
            break;
        };
        //if(player1->state!=CS_DEAD) showscores(false);
    };
};
Ejemplo n.º 8
0
buffer& buffer::operator -= ( float v )
{
   loopi(width*height) data[i]-=v;
   return *this;
}
Ejemplo n.º 9
0
bool CslGameAssaultCube::ParseDefaultPong(ucharbuf& buf, CslServerInfo& info) const
{
    wxInt32 i, l, q;
    char text[MAXSTRLEN];
    bool wasfull=info.IsFull();

    if ((wxUint32)getint(buf)!=m_fourcc)
        return false;

    q=getint(buf);
    if (q==AC_EXTPING_SERVERINFO)
        loopi(2) getint(buf);

    info.Protocol=getint(buf);
    info.Version=GetVersionName(info.Protocol);
    wxInt32 mode=getint(buf);
    info.GameMode=GetModeName(mode);

    i=getint(buf);
    if (info.HasRegisteredEvent(CslServerEvents::EVENT_EMPTY) && info.Players>0 && !i)
        info.SetEvents(CslServerEvents::EVENT_EMPTY);
    else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_EMPTY) && !info.Players && i>0)
        info.SetEvents(CslServerEvents::EVENT_NOT_EMPTY);
    info.Players=i;

    info.TimeRemain=max(0, getint(buf));
    if (info.Protocol<1126) // <= 0.93
        info.TimeRemain++;
    if (info.Protocol>=1200) // <= 1.2.0.x
        info.TimeRemain*=60;
    getstring(text, buf);
    info.Map=C2U(FilterCubeString(text, 1));
    getstring(text, buf);
    info.SetDescription(C2U(FilterCubeString(text, 1)));

    info.PlayersMax=getint(buf);
    if (info.HasRegisteredEvent(CslServerEvents::EVENT_FULL) && !wasfull && info.IsFull())
        info.SetEvents(CslServerEvents::EVENT_FULL);
    else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_FULL) && wasfull && !info.IsFull())
        info.SetEvents(CslServerEvents::EVENT_NOT_FULL);

    l=info.MM;
    info.MMDescription.Empty();
    info.MM=CSL_SERVER_OPEN;

    if (info.Protocol>=1128 && buf.remaining()) // >=1.0.x
    {
        i = getint(buf);
        wxInt32 mm = i>>PONGFLAG_MASTERMODE;

        if (mm==1)
        {
            if (info.HasRegisteredEvent(CslServerEvents::EVENT_PRIVATE) &&
                CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_PRIVATE(l))
                info.SetEvents(CslServerEvents::EVENT_PRIVATE);
            info.MMDescription=wxT("P");
            info.MM=CSL_SERVER_PRIVATE;
        }
        else if (mm==2)
        {
            if (info.HasRegisteredEvent(CslServerEvents::EVENT_LOCKED) &&
                CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_LOCKED(l))
                info.SetEvents(CslServerEvents::EVENT_LOCKED);
            info.MMDescription=wxT("L");
            info.MM=CSL_SERVER_LOCKED;
        }
        else
            info.MMDescription=wxT("O");

        if (i&(1<<PONGFLAG_BANNED))
        {
            info.MMDescription<<wxT("/BAN");
            CSL_FLAG_SET(info.MM, CSL_SERVER_BAN);
        }
        if (i&(1<<PONGFLAG_BLACKLIST))
        {
            info.MMDescription<<wxT("/BLACK");
            CSL_FLAG_SET(info.MM, CSL_SERVER_BLACKLIST);
        }
        if (i&(1<<PONGFLAG_PASSWORD))
        {
            info.MMDescription<<wxT("/PASS");
            CSL_FLAG_SET(info.MM, CSL_SERVER_PASSWORD);
        }

        if (buf.remaining() && getint(buf)==q) // >=1.0.2
        {
            switch (q)
            {
                case AC_EXTPING_SERVERINFO:    // >=1.0.4
                {
                    if (getstring(text, buf)==2)
                    {
                        i=0;
                        info.InfoText.Empty();

                        while (buf.remaining())
                        {
                            getstring(text, buf);

                            if (!*text)
                                break;
                            if (i++)
                                info.InfoText<<CSL_NEWLINE_WX;
                            if (strcmp(text, "."))
                                info.InfoText<<C2U(FilterCubeString(text, 1, true, false, true));
                        }
                    }
                    break;
                }
                default:
                    break;
            }
        }
    }
Ejemplo n.º 10
0
/// Internal: Render an object to text.
static char *print_object(JSON *item, int depth, bool fmt)
{
    char **entries = 0, **names = 0;
    char *out = 0, *ptr, *ret, *str;
    int len=7, i=0;

    JSON *child = item->firstchild;
    int numentries=0, fail=0;
    // Count the number of entries.
    while (child) numentries++, child = child->next;

    if(!numentries) // Explicitly handle empty object case
    {
        out=new char[fmt?depth+4:3];
        if(!out)    return 0;
        ptr = out;
        *ptr++='{';
        if(fmt) { *ptr++='\n'; for (i=0; i<depth-1; i++) *ptr++='\t';}
        *ptr++='}'; *ptr++=0;
        return out;
    }
    // Allocate space for the names and the objects
    entries = new char *[numentries*sizeof(char*)];
    if(!entries) return 0;
    names = new char *[numentries*sizeof(char*)];

    memset(entries, 0, sizeof(char*)*numentries);
    memset(names, 0, sizeof(char*)*numentries);

    // Collect all the results into our arrays:
    child = item->firstchild;
    depth++;
    if(fmt) len+=depth;
    while (child)
    {
        names[i] = str = print_string_ptr(child->name);
        entries[i++]= ret = print_value(child, depth, fmt);
        if(str && ret) len+= strlen(ret) + strlen(str) + 2 + (fmt ? depth+2 : 0);
        else fail=1;
        child = child->next;
    }

    // Try to allocate the output string
    if(!fail) out = new char[len];

    // Handle failure
    if(fail)
    {
        loopi(numentries) { delete[] names[i]; delete[] entries[i];}
        delete[] names;
        delete[] entries;
        return 0;
    }

    // Compose the output:
    *out = '{'; ptr = out+1;
    if(fmt) *ptr++ = '\n'; *ptr = 0;
    loopi(numentries)
    {
        if(fmt) loopj(depth) *ptr++ = '\t';
        strcpy(ptr, names[i]);
        ptr += strlen(names[i]);
        *ptr++=':'; if(fmt) *ptr++ = '\t';

        strcpy(ptr, entries[i]); ptr += strlen(entries[i]);
        if(i != numentries-1) *ptr++ = ',';
        if(fmt) *ptr++='\n'; *ptr = 0;
        delete[] names[i];
        delete[] entries[i];
    }

    delete[] names;
    delete[] entries;
    if(fmt) loopi(depth-1) *ptr++='\t';
    *ptr++='}';*ptr++=0;
    return out;
}
Ejemplo n.º 11
0
void cleanupcaustics()
{
    loopi(NUMCAUSTICS) caustictex[i] = NULL;
}
Ejemplo n.º 12
0
bool CACBot::ChoosePreferredWeapon()
{
    if(lastmillis < m_iChangeWeaponDelay) return false;
    short bestWeapon = m_pMyEnt->gunselect;
    short bestWeaponScore = SHRT_MIN;

    short sWeaponScore;
    float flDist = GetDistance(m_pMyEnt->enemy->o);
    char bestWeap[NUMGUNS];
    loopi(NUMGUNS) bestWeap[i] = 0;
    // Choose a weapon
    for(int i=0; i<NUMGUNS; i++)
    {
        sWeaponScore = primary_weap(i) ? 5 : 0; // Primary are usually better

        if (!m_pMyEnt->mag[i] && WeaponInfoTable[i].eWeaponType != TYPE_MELEE) continue;

        sWeaponScore += 3*m_pMyEnt->weapstats[i].kills/(m_pMyEnt->weapstats[i].deaths ? m_pMyEnt->weapstats[i].deaths : 0.5f);
        sWeaponScore -= 2*m_pMyEnt->weapstats[i].deaths/(m_pMyEnt->weapstats[i].kills ? m_pMyEnt->weapstats[i].kills : 0.5f);

        if((flDist >= WeaponInfoTable[i].flMinDesiredDistance) &&
            (flDist <= WeaponInfoTable[i].flMaxDesiredDistance))
        { // In desired range for this weapon
            sWeaponScore += 5; // Increase score much

            if(i == GUN_PISTOL || WeaponInfoTable[i].eWeaponType == TYPE_MELEE)
            {
                if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SNIPER) sWeaponScore += 10; // At a close range, knife & pistol are strong with a sniper like primary weapon
                if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SHOTGUN) sWeaponScore -= 2; // Penalize a bit knife and pistol on close range with shotgun
            }
        }
        else if (((flDist < WeaponInfoTable[i].flMinFireDistance) ||
                (flDist > WeaponInfoTable[i].flMaxFireDistance)) && i != GUN_GRENADE && i != GUN_RPG)
            continue; // Wrong distance for this weapon

        if(i == GUN_GRENADE) sWeaponScore += 30; // Nades have high priority

        // Score on the distance to the ideal distance
        float flIdealDiff = fabs(flDist - WeaponInfoTable[i].flIdealDistance);

        if(flIdealDiff < 1.0f) sWeaponScore += 10;
        else if(flIdealDiff <= 5.0f) sWeaponScore += 4;
        else if(flIdealDiff <= 7.5f) sWeaponScore += 2;
        else if(flIdealDiff <= 10.0f) ++sWeaponScore;

        // Now rate the weapon on available ammo in magazine...
        if (WeaponInfoTable[i].sMinDesiredAmmo > 0)
        {
            // Calculate how much percent of the min desired ammo in mag the bot has
            float flDesiredPercent = (float(m_pMyEnt->mag[i])/float(WeaponInfoTable[i].sMinDesiredAmmo))*100.0f;

            if (flDesiredPercent >= 400.0f)
                sWeaponScore += 10;
            else if (flDesiredPercent >= 200.0f)
                sWeaponScore += 8;
            else if (flDesiredPercent >= 100.0f)
                sWeaponScore += 3;
            else if (flDesiredPercent >= 50.0f)
                sWeaponScore -= 2;
            else
                sWeaponScore -= 5;
        }
        else sWeaponScore += 15; // Not needing ammo is an advantage...

        if(sWeaponScore > bestWeaponScore)
        {
            bestWeaponScore = sWeaponScore;
            bestWeapon = i;
            loopi(bestWeapon) bestWeap[i] = 0;
            bestWeap[bestWeapon] = 1;
        }
        else if(sWeaponScore == bestWeaponScore) bestWeap[i] = 1;
    }
    int tie = 0;
    loopi(NUMGUNS) tie += bestWeap[i];
    if (tie)
    {
        if (tie > 1)
        {
            int select = rnd(tie), i = 0;
            while (select >= 0)
            {
                bestWeapon = i;
                select -= bestWeap[i++];
            }
        }
    }
    else bestWeapon = GUN_KNIFE;

    return SelectGun(bestWeapon);
};
Ejemplo n.º 13
0
buffer& buffer::operator = ( const buffer& b)
{
   loopi(width*height) data[i]=b.data[i];
   return *this;
}
Ejemplo n.º 14
0
static void animategrass()
{
    loopi(NUMGRASSOFFSETS) grassanimoffsets[i] = grassanimscale*sinf(2*M_PI*(grassoffsets[i] + lastmillis/float(grassanimmillis)));
    lastgrassanim = lastmillis;
}
Ejemplo n.º 15
0
// server side processing of updates: does very little and most state is tracked
// client only could be extended to move more gameplay to server (at expense of
// lag)
void process(ENetPacket * packet, int sender) { // sender may be -1
  const u16 len = *(u16*) packet->data;
  if (ENET_NET_TO_HOST_16(len)!=packet->dataLength) {
    disconnect_client(sender, "packet length");
    return;
  }

  u8 *end = packet->data+packet->dataLength;
  u8 *p = packet->data+2;
  char text[MAXTRANS];
  int cn = -1, type;

  while (p<end) switch (type = getint(p)) {
    case SV_TEXT:
      sgetstr();
    break;
    case SV_INITC2S:
      sgetstr();
      strcpy_s(clients[cn].name, text);
      sgetstr();
      getint(p);
    break;
    case SV_MAPCHANGE: {
      sgetstr();
      int reqmode = getint(p);
      if (reqmode<0) reqmode = 0;
      if (smapname[0] && !mapreload && !vote(text, reqmode, sender)) return;
      mapreload = false;
      mode = reqmode;
      minremain = mode&1 ? 15 : 10;
      mapend = lastsec+minremain*60;
      interm = 0;
      strcpy_s(smapname, text);
      resetitems();
      sender = -1;
    }
    break;
    case SV_ITEMLIST: {
      int n;
      while ((n = getint(p))!=-1) if (notgotitems) {
        server_entity se = { false, 0 };
        while (sents.length()<=n) sents.add(se);
        sents[n].spawned = true;
      }
      notgotitems = false;
    }
    break;
    case SV_ITEMPICKUP: {
      const int n = getint(p);
      pickup(n, getint(p), sender);
    }
    break;
    case SV_PING:
      send2(false, cn, SV_PONG, getint(p));
    break;
    case SV_POS: {
      cn = getint(p);
      if (cn<0 || cn>=clients.length() || clients[cn].type==ST_EMPTY) {
        disconnect_client(sender, "client num");
        return;
      }
      int size = msgsizelookup(type);
      assert(size!=-1);
      loopi(size-2) getint(p);
    }
    break;
    case SV_SENDMAP: {
      sgetstr();
      int mapsize = getint(p);
      sendmaps(sender, text, mapsize, p);
    }
    return;
    case SV_RECVMAP:
      send(sender, recvmap(sender));
    return;
    case SV_EXT:   // allows for new features that require no server updates 
      for (int n = getint(p); n; n--) getint(p);
    break;
    default: {
      const int size = msgsizelookup(type);
      if (size==-1) { disconnect_client(sender, "tag type"); return; };
      loopi(size-1) getint(p);
    }
  }

  if (p>end) { disconnect_client(sender, "end of packet"); return; };
  multicast(packet, sender);
}
Ejemplo n.º 16
0
void playbackstep(void) {
  while (demoplayback && game::lastmillis()>=playbacktime) {
    int len = gzgeti();
    if (len<1 || len>MAXTRANS) {
      con::out("error: huge packet during demo play (%d)", len);
      stopreset();
      return;
    }
    u8 buf[MAXTRANS];
    gzread(f, buf, len);
    client::localservertoclient(buf, len);  // update game state

    game::dynent *target = game::players[democlientnum];
    assert(target);

    int extras;
    if ((extras = gzget())) { // read additional client side state not present in normal network stream
      target->gunselect = gzget();
      target->lastattackgun = gzget();
      target->lastaction = scaletime(gzgeti());
      target->gunwait = gzgeti();
      target->health = gzgeti();
      target->armour = gzgeti();
      target->armourtype = gzget();
      loopi(game::NUMGUNS) target->ammo[i] = gzget();
      target->state = gzget();
      target->lastmove = playbacktime;
      // if ((bdamage = gzgeti()) != 0) rr::damageblend(bdamage);
      if ((ddamage = gzgeti()) != 0) {
        gzgetv(dorig);
        rr::particle_splash(rr::PT_BLOOD_SPATS, ddamage, 1000, dorig);
      }
      // FIXME: set more client state here
    }

    // insert latest copy of player into history
    if (extras && (playerhistory.empty() || playerhistory.last()->lastupdate!=playbacktime)) {
      game::dynent *d = game::newdynent();
      *d = *target;
      d->lastupdate = playbacktime;
      playerhistory.add(d);
      if (playerhistory.length()>20) {
        game::zapdynent(playerhistory[0]);
        playerhistory.remove(0);
      }
    }

    readdemotime();
  }

  if (demoplayback) {
    int itime = game::lastmillis()-demodelaymsec;
    loopvrev(playerhistory) if (playerhistory[i]->lastupdate<itime) { // find 2 positions in history that surround interpolation time point
      game::dynent *a = playerhistory[i];
      game::dynent *b = a;
      if (i+1<playerhistory.length()) b = playerhistory[i+1];
      *game::player1 = *b;
      if (a!=b) { // interpolate pos & angles
        game::dynent *c = b;
        if (i+2<playerhistory.length()) c = playerhistory[i+2];
        game::dynent *z = a;
        if (i-1>=0) z = playerhistory[i-1];
        float bf = (itime-a->lastupdate)/(float)(b->lastupdate-a->lastupdate);
        fixwrap(a, game::player1);
        fixwrap(c, game::player1);
        fixwrap(z, game::player1);
        const float dist = distance(z->o,c->o);
        if (dist<16.f) { // if teleport or spawn, dont't interpolate
          catmulrom(z->o, a->o, b->o, c->o, bf, game::player1->o);
          // catmulrom(*(vec3f*)&z->ypr.x, *(vec3f*)&a->ypr.x, *(vec3f*)&b->ypr.x, *(vec3f*)&c->ypr.x, bf, *(vec3f *)&game::player1->ypr.x);
          vec3f dstangle;
          catmulrom(z->ypr, a->ypr, b->ypr, c->ypr, bf, dstangle);
          game::player1->ypr.x = dstangle.x;
          game::player1->ypr.y = dstangle.y;
          game::player1->ypr.z = dstangle.z;
        }
        game::fixplayer1range();
      }
      break;
    }
  }
}
Ejemplo n.º 17
0
void projreset() { loopi(MAXPROJ) projs[i].inuse = false; };