+ //TODO: wat
+ if(player[i].aitype!=playercontrolled&&
+ (player[i].isIdle()||
+ player[i].isCrouch()||
+ player[i].isRun())){
+ int target=-2;
+ for(int j=0;j<numplayers;j++)
+ if(j!=i&&!player[j].skeleton.free&&
+ player[j].hasvictim&&
+ (tutoriallevel==1&&reversaltrain||
+ Random()%2==0&&difficulty==2||
+ Random()%4==0&&difficulty==1||
+ Random()%8==0&&difficulty==0||
+ player[j].lastattack2==player[j].targetanimation&&
+ player[j].lastattack3==player[j].targetanimation&&
+ (Random()%2==0||difficulty==2)||
+ (player[i].isIdle()||player[i].isRun())&&
+ player[j].weaponactive!=-1||
+ player[j].targetanimation==swordslashanim&&
+ player[i].weaponactive!=-1||
+ player[j].targetanimation==staffhitanim||
+ player[j].targetanimation==staffspinhitanim))
+ if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
+ player[j].victim==&player[i]&&
+ (player[j].targetanimation==sweepanim||
+ player[j].targetanimation==spinkickanim||
+ player[j].targetanimation==staffhitanim||
+ player[j].targetanimation==staffspinhitanim||
+ player[j].targetanimation==winduppunchanim||
+ player[j].targetanimation==upunchanim||
+ player[j].targetanimation==wolfslapanim||
+ player[j].targetanimation==knifeslashstartanim||
+ player[j].targetanimation==swordslashanim&&
+ (findDistancefast(&player[j].coords,&player[i].coords)<2||
+ player[i].weaponactive!=-1))){
+ if(target>=0)
+ target=-1;
+ else
+ target=j;
+ }
+ if(target>=0)
+ player[target].Reverse();
+ }
+
+ if(player[i].collided<1)
+ player[i].jumpkeydown=0;
+ if(player[i].collided>.8&&player[i].jumppower>=5||
+ findDistancefast(&player[i].coords,&player[0].coords)>400&&
+ player[i].onterrain&&
+ player[i].creature==rabbittype)
+ player[i].jumpkeydown=1;
+ //TODO: why are we controlling the human?
+ if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
+ player[0].jumpkeydown=0;
+ if(player[0].targetanimation==jumpdownanim&&
+ findDistancefast(&player[0].coords,&player[i].coords)<40)
+ player[i].crouchkeydown=1;
+ if(player[i].jumpkeydown)
+ player[i].attackkeydown=0;
+
+ if(tutoriallevel==1)
+ if(!canattack)
+ player[i].attackkeydown=0;
+
+
+ XYZ facing=player[i].coords;
+ XYZ flatfacing=player[0].coords;
+ facing.y+=playerJoint(i,head).position.y*player[i].scale;
+ flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
+ if(player[i].occluded>=2)
+ if(-1!=checkcollide(facing,flatfacing)){
+ if(!player[i].pause)
+ player[i].lastseentime-=.2;
+ if(player[i].lastseentime<=0&&
+ (player[i].creature!=wolftype||
+ player[i].weaponstuck==-1)){
+ player[i].aitype=searchtype;
+ player[i].lastchecktime=12;
+ player[i].lastseen=player[0].coords;
+ player[i].lastseentime=12;
+ }
+ }else
+ player[i].lastseentime=1;
+ }
+ }
+ if(animation[player[0].targetanimation].height==highheight&&
+ (player[i].aitype==attacktypecutoff||
+ player[i].aitype==searchtype))
+ if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
+ XYZ test=player[0].coords;
+ test.y-=40;
+ if(-1==checkcollide(player[0].coords,test))
+ player[i].stunned=1;
+ }
+ //stunned
+ if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
+ player[i].stunned>0||
+ player[i].pause&&player[i].damage>player[i].superpermanentdamage){
+ if(player[i].pause)
+ player[i].lastseentime=1;
+ player[i].targetrotation=player[i].rotation;
+ player[i].forwardkeydown=0;
+ player[i].leftkeydown=0;
+ player[i].backkeydown=0;
+ player[i].rightkeydown=0;
+ player[i].jumpkeydown=0;
+ player[i].attackkeydown=0;
+ player[i].crouchkeydown=0;
+ player[i].throwkeydown=0;
+ }
+
+
+ XYZ facing;
+ facing=0;
+ facing.z=-1;
+
+ XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
+ facing=flatfacing;
+
+ if(player[i].aitype==attacktypecutoff){
+ player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
+ player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
+ }else if(player[i].howactive>=typesleeping){
+ player[i].targetheadrotation=player[i].targetrotation;
+ player[i].targetheadrotation2=0;
+ }else{
+ if(player[i].interestdelay<=0){
+ player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
+ player[i].headtarget=player[i].coords;
+ player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
+ player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
+ player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
+ player[i].headtarget+=player[i].facing*1.5;
+ }
+ player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
+ player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
+ }
+ }
+}
+
+/*
+Values of mainmenu :
+1 Main menu
+2 Menu pause (resume/end game)
+3 Option menu
+4 Controls configuration menu
+5 Main game menu (choose level or challenge)
+6 Deleting user menu
+7 User managment menu (select/add)
+8 Choose difficulty menu
+9 Challenge level selection menu
+10 End of the campaign congratulation (is that really a menu?)
+11 Same that 9 ??? => unused
+18 stereo configuration
+*/
+
+void Game::MenuTick(){
+ //menu buttons
+
+ // some specific case where we do something even if the left mouse button is not pressed.
+ if((mainmenu==5) && (endgame==2)) {
+ accountactive->endGame();
+ endgame=0;
+ }
+ if(mainmenu==10)
+ endgame=2;
+ if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
+ stereoseparation-=0.001;
+
+ if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
+ switch(mainmenu) {
+ case 1:
+ case 2:
+ switch(selected) {
+ case 1:
+ if(gameon) { //resume
+ mainmenu=0;
+ pause_sound(stream_menutheme);
+ resume_stream(leveltheme);
+ } else { //new game
+ fireSound(firestartsound);
+ flash();
+ mainmenu=(accountactive?5:7);
+ selected=-1;
+ }
+ break;
+ case 2: //options
+ fireSound();
+ flash();
+ mainmenu=3;
+ if(newdetail>2) newdetail=detail;
+ if(newdetail<0) newdetail=detail;
+ if(newscreenwidth>3000) newscreenwidth=screenwidth;
+ if(newscreenwidth<0) newscreenwidth=screenwidth;
+ if(newscreenheight>3000) newscreenheight=screenheight;
+ if(newscreenheight<0) newscreenheight=screenheight;
+ break;
+ case 3:
+ fireSound();
+ flash();
+ if(gameon){ //end game
+ gameon=0;
+ mainmenu=1;
+ } else { //quit
+ tryquit=1;
+ pause_sound(stream_menutheme);
+ }
+ break;
+ }
+ break;
+ case 3:
+ fireSound();
+ bool isCustomResolution,found;
+ switch(selected){
+ case 0:
+ extern SDL_Rect **resolutions;
+ isCustomResolution = true;
+ found = false;
+ for(int i = 0; (!found) && (resolutions[i]); i++) {
+ if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
+ isCustomResolution = false;
+
+ if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
+ i++;
+ if(resolutions[i] != NULL) {
+ newscreenwidth = (int) resolutions[i]->w;
+ newscreenheight = (int) resolutions[i]->h;
+ } else if(isCustomResolution){
+ if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
+ newscreenwidth = (int) resolutions[0]->w;
+ newscreenheight = (int) resolutions[0]->h;
+ } else {
+ newscreenwidth = screenwidth;
+ newscreenheight = screenheight;
+ }
+ } else {
+ newscreenwidth = (int) resolutions[0]->w;
+ newscreenheight = (int) resolutions[0]->h;
+ }
+ found = true;
+ }
+ }
+
+ if(!found) {
+ newscreenwidth = (int) resolutions[0]->w;
+ newscreenheight = (int) resolutions[0]->h;
+ }
+ break;
+ case 1:
+ newdetail++;
+ if(newdetail>2) newdetail=0;
+ break;
+ case 2:
+ bloodtoggle++;
+ if(bloodtoggle>2) bloodtoggle=0;
+ break;
+ case 3:
+ difficulty++;
+ if(difficulty>2) difficulty=0;
+ break;
+ case 4:
+ ismotionblur = !ismotionblur;
+ break;
+ case 5:
+ decals = !decals;
+ break;
+ case 6:
+ musictoggle = !musictoggle;
+
+ if(musictoggle) {
+ emit_stream_np(stream_menutheme);
+ } else {
+ pause_sound(leveltheme);
+ pause_sound(stream_fighttheme);
+ pause_sound(stream_menutheme);
+
+ for(int i=0;i<4;i++){
+ oldmusicvolume[i]=0;
+ musicvolume[i]=0;
+ }
+ }
+
+ break;
+ case 7: // controls
+ flash();
+ mainmenu=4;
+ selected=-1;
+ keyselect=-1;
+ break;
+ case 8:
+ flash();
+
+ SaveSettings(*this);
+ mainmenu=gameon?2:1;
+ break;
+ case 9:
+ invertmouse = !invertmouse;
+ break;
+ case 10:
+ usermousesensitivity+=.2;
+ if(usermousesensitivity>2) usermousesensitivity=.2;
+ break;
+ case 11:
+ volume+=.1f;
+ if(volume>1.0001f) volume=0;
+ OPENAL_SetSFXMasterVolume((int)(volume*255));
+ break;
+ case 12:
+ flash();
+
+ newstereomode = stereomode;
+ mainmenu=18;
+ keyselect=-1;
+ break;
+ case 13:
+ showdamagebar = !showdamagebar;
+ break;
+ }
+ break;
+ case 4:
+ if(!waiting) {
+ fireSound();
+ if(selected<9 && keyselect==-1)
+ keyselect=selected;
+ if(keyselect!=-1)
+ setKeySelected();
+ if(selected==9){
+ flash();
+
+ mainmenu=3;
+ }
+ }
+ break;
+ case 5:
+ fireSound();
+ flash();
+ if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
+ startbonustotal=0;
+
+ loading=2;
+ loadtime=0;
+ targetlevel=7;
+ if(firstload)
+ TickOnceAfter();
+ else
+ LoadStuff();
+ whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
+ actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
+ visibleloading=1;
+ stillloading=1;
+ Loadlevel(campaignlevels[actuallevel].mapname.c_str());
+ campaign=1;
+ mainmenu=0;
+ gameon=1;
+ pause_sound(stream_menutheme);
+ }
+ switch(selected){
+ case 1:
+ startbonustotal=0;
+
+ loading=2;
+ loadtime=0;
+ targetlevel=-1;
+ if(firstload) {
+ TickOnceAfter();
+ } else
+ LoadStuff();
+ Loadlevel(-1);
+
+ mainmenu=0;
+ gameon=1;
+ pause_sound(stream_menutheme);
+ break;
+ case 2:
+ mainmenu=9;
+ break;
+ case 3:
+ mainmenu=6;
+ break;
+ case 4:
+ mainmenu=(gameon?2:1);
+ break;
+ case 5:
+ mainmenu=7;
+ break;
+ case 6:
+ vector<string> campaigns = ListCampaigns();
+ vector<string>::iterator c;
+ if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
+ if(!campaigns.empty())
+ accountactive->setCurrentCampaign(campaigns.front());
+ } else {
+ c++;
+ if(c==campaigns.end())
+ c=campaigns.begin();
+ accountactive->setCurrentCampaign(*c);
+ }
+ LoadCampaign();
+ break;
+ }
+ break;
+ case 6:
+ fireSound();
+ if(selected==1) {
+ flash();
+ accountactive = Account::destroy(accountactive);
+ mainmenu=7;
+ } else if(selected==2) {
+ flash();
+ mainmenu=5;
+ }
+ break;
+ case 7:
+ fireSound();
+ if(selected==0 && Account::getNbAccounts()<8){
+ entername=1;
+ } else if (selected < Account::getNbAccounts()+1) {
+ flash();
+ mainmenu=5;
+ accountactive=Account::get(selected-1);
+ } else if (selected == Account::getNbAccounts()+1) {
+ flash();
+ mainmenu=5;
+ for(int j=0;j<255;j++){
+ displaytext[0][j]=0;
+ }
+ displaychars[0]=0;
+ displayselected=0;
+ entername=0;
+ }
+ break;
+ case 8:
+ fireSound();
+ flash();
+ if(selected<=2)
+ accountactive->setDifficulty(selected);
+ mainmenu=5;
+ break;
+ case 9:
+ if(selected<numchallengelevels && selected<=accountactive->getProgress()){
+ fireSound();
+ flash();
+
+ startbonustotal=0;