X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=8b519880e7da4f483bddcfe830334cc7db30cd72;hb=42bf932baf8cecf12b4daba00c4453093aa4971a;hp=047c5f133feb8077a0d790bb01e0c808740afb09;hpb=72621d52ae69fa4ecb4329437810d71860ae3ebc;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 047c5f1..8b51988 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -122,8 +122,6 @@ extern float hostiletime; extern bool gamestarted; extern int numhotspots; -extern int winhotspot; -extern int windialogue; extern int killhotspot; extern XYZ hotspot[40]; extern int hotspottype[40]; @@ -169,7 +167,7 @@ static bool stripfx(const char *str, const char *pfx) } static const char *cmd_names[] = { -#define DECLARE_COMMAND(cmd) #cmd " ", +#define DECLARE_COMMAND(cmd) #cmd, #include "ConsoleCmds.h" #undef DECLARE_COMMAND }; @@ -190,13 +188,6 @@ static console_handler cmd_handlers[] = { // added utility functions -sf17k ============================================================= -//TODO: try to hide these variables completely with a better interface -inline void setAnimation(int playerid,int animation){ - player[playerid].targetanimation=animation; - player[playerid].targetframe=0; - player[playerid].target=0; -} - //TODO: this is incorrect but I'm afraid to change it and break something, //probably causes quirky behavior that I might want to preserve inline float roughDirection(XYZ vec){ @@ -219,12 +210,6 @@ inline float pitchTo(XYZ start, XYZ end){ return pitch(end-start); } -//change these to a Person method -inline Joint& playerJoint(int playerid, int bodypart){ - return player[playerid].skeleton.joints[player[playerid].skeleton.jointlabels[bodypart]]; } -inline Joint& playerJoint(Person* pplayer, int bodypart){ - return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; } - inline float sq(float n) { return n*n; } inline float stepTowardf(float from, float to, float by){ @@ -1101,15 +1086,16 @@ static void ch_skybox(Game *game, const char *args) objects.DoShadows(); } -static void cmd_dispatch(Game *game, const char *cmd) +static void cmd_dispatch(Game *game, const string cmd) { int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]); for (i = 0; i < n_cmds; i++) - if (stripfx(cmd, cmd_names[i])) + if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i])) { - cmd_handlers[i](game, cmd + strlen(cmd_names[i])); - break; + cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl; + cmd_handlers[i](game, cmd.substr(cmd.find(' ')+1).c_str()); + break; } emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound); } @@ -1399,22 +1385,22 @@ void Game::Setenvironment(int which) texdetail=temptexdetail; } -void Game::Loadlevel(int which){ +void Game::Loadlevel(int which) { stealthloading=0; whichlevel=which; - if(which == -1){ + if(which == -1) { tutoriallevel = -1; Loadlevel("tutorial"); - }else if(which >= 0 && which <= 15){ + } else if(which >= 0 && which <= 15) { char buf[32]; snprintf(buf, 32, "map%d", which + 1); // challenges Loadlevel(buf); - }else + } else Loadlevel("mapsave"); } -void Game::Loadlevel(const char *name){ +void Game::Loadlevel(const char *name) { int templength; float lamefloat; static const char *pfx = ":Data:Maps:"; @@ -1425,7 +1411,6 @@ void Game::Loadlevel(const char *name){ LOGFUNC; LOG(std::string("Loading level...") + name); - cout << "Loading level..." << name << endl; if(!gameon) visibleloading=1; @@ -1459,15 +1444,14 @@ void Game::Loadlevel(const char *name){ int mapvers; FILE *tfile; - char* buff=getcwd(NULL,0); - cout << buff << " " << FixedFN << endl; - free(buff); + //~ char* buff=getcwd(NULL,0); + //~ cout << buff << " " << FixedFN << endl; + //~ free(buff); tfile=fopen( FixedFN, "rb" ); if(tfile) { - cout << "existe" << endl; pause_sound(stream_firesound); scoreadded=0; - windialogue=0; + windialogue=false; hostiletime=0; won=0; @@ -1532,7 +1516,6 @@ void Game::Loadlevel(const char *name){ emit_sound_np(consolesuccesssound); freeze=0; console=false; - cout << "console contente" << endl; } if(!stealthloading){ @@ -2093,7 +2076,7 @@ void Game::Loadlevel(const char *name){ if(!firstload) firstload=1; } else { - perror("Soucis"); + perror("Problem"); } leveltime=0; loadingstuff=0; @@ -2697,7 +2680,7 @@ void Game::doDebugKeys(){ if(closest!=-1){ XYZ headspurtdirection; //int i = player[closest].skeleton.jointlabels[head]; - Joint& headjoint=playerJoint(closest,head); + Joint& headjoint= player[closest].getJointFor(head); for(int k=0;k25){ - setAnimation(k,hanganim); + player[k].setAnimation(hanganim); player[k].jumppower=0; } } @@ -3685,7 +3668,7 @@ void Game::doAerialAcrobatics(){ //stagger off ledge (?) if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim) player[k].RagDoll(0); - setAnimation(k,jumpdownanim); + player[k].setAnimation(jumpdownanim); if(!k) emit_sound_at(whooshsound, player[k].coords, 128.); @@ -3760,14 +3743,14 @@ void Game::doAttacks(){ player[i].targetanimation==staffhitanim|| player[i].targetanimation==staffspinhitanim) if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){ - setAnimation(k,dodgebackanim); + player[k].setAnimation(dodgebackanim); player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords); player[k].targettilt2=pitchTo(player[k].coords,player[i].coords); } } if(player[k].targetanimation!=dodgebackanim){ if(k==0)numflipped++; - setAnimation(k,backhandspringanim); + player[k].setAnimation(backhandspringanim); player[k].targetrotation=-rotation+180; if(player[k].leftkeydown) player[k].targetrotation-=45; @@ -4158,8 +4141,8 @@ void Game::doAttacks(){ if(player[k].targetanimation==crouchstabanim|| player[k].targetanimation==swordgroundstabanim|| player[k].targetanimation==staffgroundsmashanim){ - targetpoint+=(playerJoint(i,abdomen).position+ - playerJoint(i,neck).position)/2* + targetpoint+=(player[i].getJointFor(abdomen).position+ + player[i].getJointFor(neck).position)/2* player[i].scale; } player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint); @@ -4215,7 +4198,7 @@ void Game::doAttacks(){ player[k].rabbitkickenabled)|| player[k].jumpkeydown)){ oldattackkey=1; - setAnimation(k,rabbitkickanim); + player[k].setAnimation(rabbitkickanim); } //update counts if(animation[player[k].targetanimation].attack&&k==0){ @@ -4279,9 +4262,9 @@ void Game::doPlayerCollisions(){ XYZ tempcoords1=player[i].coords; XYZ tempcoords2=player[k].coords; if(!player[i].skeleton.oldfree) - tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale; + tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale; if(!player[k].skeleton.oldfree) - tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale; + tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale; collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5); if(player[0].hasvictim) if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free) @@ -4375,18 +4358,18 @@ void Game::doPlayerCollisions(){ if(player[k].howactive==typeactive||hostile) if(player[k].isIdle()){ if(player[k].howactive0) if(player[j].coords.y0) if((-1==checkcollide( - DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)* + DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)* player[i].scale+player[i].coords, - DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)* + DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)* player[j].scale+player[j].coords)&& !player[j].isWallJump())|| (player[j].targetanimation==hanganim&& @@ -4802,7 +4785,7 @@ void Game::doAI(int i){ j=checkcollide(test2,test); if(j==-1){ player[i].velocity=0; - setAnimation(i,player[i].getStop()); + player[i].setAnimation(player[i].getStop()); player[i].targetrotation+=180; player[i].stunned=.5; //player[i].aitype=passivetype; @@ -4881,9 +4864,9 @@ void Game::doAI(int i){ if(findDistancefast(&player[i].coords,&player[0].coords)<400) if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0) if((checkcollide( - DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)* + DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)* player[i].scale+player[i].coords, - DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)* + DoRotation(player[0].getJointFor(head).position,0,player[0].rotation,0)* player[0].scale+player[0].coords)==-1)|| (player[0].targetanimation==hanganim&&normaldotproduct( player[0].facing,player[i].coords-player[0].coords)<0)){ @@ -4914,25 +4897,25 @@ void Game::doAI(int i){ player[i].runninghowlong=0; //get help from buddies - if(player[i].aitype==gethelptype){ + if(player[i].aitype==gethelptype) { player[i].runninghowlong+=multiplier; player[i].aiupdatedelay-=multiplier; - if(player[i].aiupdatedelay<0||player[i].ally==0){ + if(player[i].aiupdatedelay<0||player[i].ally==0) { player[i].aiupdatedelay=.2; //find closest ally //TODO: factor out closest search somehow - if(!player[i].ally){ + if(!player[i].ally) { int closest=-1; float closestdist=-1; - for(int k=0;k=2) if(-1!=checkcollide(facing,flatfacing)){ if(!player[i].pause) @@ -5591,13 +5574,12 @@ void Game::MenuTick(){ case 4: if(!waiting) { fireSound(); - if(selected<9 && keyselect==-1) + if(selected<(debugmode?10:9) && keyselect==-1) keyselect=selected; if(keyselect!=-1) setKeySelected(); - if(selected==9){ + if(selected==(debugmode?10:9)){ flash(); - mainmenu=3; } } @@ -5970,9 +5952,9 @@ void Game::Tick(){ if(chatting) keyboardfrozen=true; - if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){ + if(Input::isKeyPressed(consolekey)&&debugmode) { console=!console; - if(console){ + if(console) { OPENAL_SetFrequency(OPENAL_ALL, 0.001); } else { freeze=0; @@ -5982,14 +5964,14 @@ void Game::Tick(){ if(console) freeze=1; - if(console&&!Input::isKeyDown(SDLK_LMETA)){ + if(console&&!Input::isKeyDown(SDLK_LMETA)) { inputText(consoletext[0],&consoleselected,&consolechars[0]); if(!waiting) { archiveselected=0; - if(consolechars[0]>0){ - consoletext[0][consolechars[0]]=' '; + if(consolechars[0]>0) { + consoletext[0][consolechars[0]]='\0'; cmd_dispatch(this, consoletext[0]); - for(int k=14;k>=1;k--){ + for(int k=14;k>=1;k--) { for(int j=0;j<255;j++) consoletext[k][j]=consoletext[k-1][j]; consolechars[k]=consolechars[k-1]; @@ -6002,7 +5984,7 @@ void Game::Tick(){ } consoleblinkdelay-=multiplier; - if(consoleblinkdelay<=0){ + if(consoleblinkdelay<=0) { consoleblinkdelay=.3; consoleblink=1-consoleblink; } @@ -6380,7 +6362,7 @@ void Game::Tick(){ hostile=1; } if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){ - windialogue=1; + windialogue=true; } if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){ hostile=1; @@ -6645,7 +6627,7 @@ void Game::Tick(){ player[i].isIdle()|| player[i].aitype!=playercontrolled){ player[i].throwtogglekeydown=1; - setAnimation(i,crouchremoveknifeanim); + player[i].setAnimation(crouchremoveknifeanim); player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position); player[i].hasvictim=0; } @@ -6678,7 +6660,7 @@ void Game::Tick(){ player[i].coords.yweaponactive=-1; - playerJoint(player[i].victim,abdomen).velocity+=relative*6; - playerJoint(player[i].victim,neck).velocity+=relative*6; - playerJoint(player[i].victim,rightshoulder).velocity+=relative*6; - playerJoint(player[i].victim,leftshoulder).velocity+=relative*6; + player[i].victim->getJointFor(abdomen).velocity+=relative*6; + player[i].victim->getJointFor(neck).velocity+=relative*6; + player[i].victim->getJointFor(rightshoulder).velocity+=relative*6; + player[i].victim->getJointFor(leftshoulder).velocity+=relative*6; } weapons[k].owner=i; if(player[i].num_weapons>0){ @@ -6826,11 +6808,11 @@ void Game::Tick(){ findDistancefast(&player[i].coords,&player[j].coords)<100&& findDistancefast(&player[i].coords,&player[j].coords)>1.5&& !player[j].skeleton.free&& - -1==checkcollide(DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){ + -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){ if(!player[i].isFlip()){ player[i].throwtogglekeydown=1; player[i].victim=&player[j]; - setAnimation(i,knifethrowanim); + player[i].setAnimation(knifethrowanim); player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords); player[i].targettilt2=pitchTo(player[i].coords,player[j].coords); } @@ -6840,7 +6822,7 @@ void Game::Tick(){ player[i].victim=&player[j]; XYZ aim; weapons[player[i].weaponids[0]].owner=-1; - aim=player[i].victim->coords+DoRotation(playerJoint(player[i].victim,abdomen).position,0,player[i].victim->rotation,0)*player[i].victim->scale+player[i].victim->velocity*findDistance(&player[i].victim->coords,&player[i].coords)/50-(player[i].coords+DoRotation(playerJoint(i,righthand).position,0,player[i].rotation,0)*player[i].scale); + aim=player[i].victim->coords+DoRotation(player[i].victim->getJointFor(abdomen).position,0,player[i].victim->rotation,0)*player[i].victim->scale+player[i].victim->velocity*findDistance(&player[i].victim->coords,&player[i].coords)/50-(player[i].coords+DoRotation(player[i].getJointFor(righthand).position,0,player[i].rotation,0)*player[i].scale); Normalise(&aim); aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0); @@ -6903,7 +6885,7 @@ void Game::Tick(){ isgood=false; if(isgood&&player[i].creature!=wolftype){ if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){ - setAnimation(i,drawrightanim); + player[i].setAnimation(drawrightanim); player[i].drawtogglekeydown=1; } if((player[i].isIdle()|| @@ -6912,11 +6894,11 @@ void Game::Tick(){ player[i].isRun()))&& player[i].num_weapons&& weapons[player[i].weaponids[0]].getType()==sword){ - setAnimation(i,drawleftanim); + player[i].setAnimation(drawleftanim); player[i].drawtogglekeydown=1; } if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){ - setAnimation(i,crouchdrawrightanim); + player[i].setAnimation(crouchdrawrightanim); player[i].drawtogglekeydown=1; } } @@ -6933,9 +6915,9 @@ void Game::Tick(){ player[i].attackkeydown&& musictype!=stream_fighttheme) { if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife) - setAnimation(i,crouchstabanim); + player[i].setAnimation(crouchstabanim); if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword) - setAnimation(i,swordgroundstabanim); + player[i].setAnimation(swordgroundstabanim); player[i].hasvictim=0; } } @@ -7008,7 +6990,7 @@ void Game::Tick(){ player[i].lowreversaldelay=.5; if(player[i].isIdle()){ - setAnimation(i,player[i].getCrouch()); + player[i].setAnimation(player[i].getCrouch()); player[i].transspeed=10; } if(player[i].isRun()|| @@ -7017,7 +6999,7 @@ void Game::Tick(){ player[i].rightkeydown|| player[i].forwardkeydown|| player[i].backkeydown))){ - setAnimation(i,rollanim); + player[i].setAnimation(rollanim); player[i].transspeed=20; } } @@ -7052,12 +7034,12 @@ void Game::Tick(){ player[i].currentanimation=player[i].getCrouch(); player[i].currentframe=0; } - setAnimation(i,player[i].getIdle()); + player[i].setAnimation(player[i].getIdle()); player[i].transspeed=10; } } if(player[i].targetanimation==sneakanim){ - setAnimation(i,player[i].getIdle()); + player[i].setAnimation(player[i].getIdle()); player[i].transspeed=10; } } @@ -7073,9 +7055,9 @@ void Game::Tick(){ !player[i].jumpkeydown&& player[i].crouchkeydown)){ if(player[i].aitype==passivetype) - setAnimation(i,walkanim); + player[i].setAnimation(walkanim); else - setAnimation(i,player[i].getRun()); + player[i].setAnimation(player[i].getRun()); } if(player[i].isCrouch()){ player[i].targetanimation=sneakanim; @@ -7084,7 +7066,7 @@ void Game::Tick(){ player[i].targetframe=0; } if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){ - setAnimation(i,climbanim); + player[i].setAnimation(climbanim); player[i].targetframe=1; player[i].jumpclimb=1; } @@ -7105,7 +7087,7 @@ void Game::Tick(){ player[i].targetframe>0&& !player[i].jumpkeydown&& player[i].crouchkeydown)){ - setAnimation(i,player[i].getRun()); + player[i].setAnimation(player[i].getRun()); } if(player[i].isCrouch()){ player[i].targetanimation=sneakanim; @@ -7132,7 +7114,7 @@ void Game::Tick(){ player[i].targetframe>0&& !player[i].jumpkeydown&& player[i].crouchkeydown)){ - setAnimation(i,player[i].getRun()); + player[i].setAnimation(player[i].getRun()); } if(player[i].isCrouch()){ player[i].targetanimation=sneakanim; @@ -7159,7 +7141,7 @@ void Game::Tick(){ player[i].targetframe>0&& !player[i].jumpkeydown&& player[i].crouchkeydown)){ - setAnimation(i,player[i].getRun()); + player[i].setAnimation(player[i].getRun()); } if(player[i].isCrouch()){ player[i].targetanimation=sneakanim; @@ -7195,7 +7177,7 @@ void Game::Tick(){ ((player[i].targetanimation!=rabbitrunninganim&& player[i].targetanimation!=wolfrunninganim)||i!=0)){ player[i].jumpstart=0; - setAnimation(i,jumpupanim); + player[i].setAnimation(jumpupanim); player[i].rotation=player[i].targetrotation; player[i].transspeed=20; player[i].FootLand(0,1); @@ -7242,7 +7224,7 @@ void Game::Tick(){ emit_sound_at(jumpsound, player[i].coords, 128.); } if((player[i].isIdle())&&player[i].jumppower>1){ - setAnimation(i,player[i].getLanding()); + player[i].setAnimation(player[i].getLanding()); player[i].targetframe=2; player[i].landhard=0; player[i].jumpstart=1; @@ -7267,7 +7249,7 @@ void Game::Tick(){ if(!movekey){ if(player[i].isRun()||player[i].targetanimation==walkanim) - setAnimation(i,player[i].getStop()); + player[i].setAnimation(player[i].getStop()); if(player[i].targetanimation==sneakanim){ player[i].targetanimation=player[i].getCrouch(); if(player[i].currentanimation==sneakanim) @@ -7280,9 +7262,9 @@ void Game::Tick(){ player[i].aitype==searchtype|| (player[i].aitype==passivetype&& player[i].numwaypoints<=1))) - setAnimation(i,player[i].getStop()); + player[i].setAnimation(player[i].getStop()); if(player[i].isRun()&&(player[i].aitype==passivetype)) - setAnimation(i,player[i].getStop()); + player[i].setAnimation(player[i].getStop()); } } if(player[i].targetanimation==rollanim) @@ -7300,7 +7282,7 @@ void Game::Tick(){ //stop to turn in right direction if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)) - setAnimation(k,player[k].getStop()); + player[k].setAnimation(player[k].getStop()); if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim) player[k].targettilt=0; @@ -7611,11 +7593,11 @@ void Game::TickOnceAfter(){ killhotspot=0; - winhotspot=0; + winhotspot=false; for(int i=0;inumchallengelevels-1)targetlevel=0; } - if(winhotspot||windialogue){ + if(winhotspot||windialogue) { changedelay=0.1; targetlevel=whichlevel+1; if(targetlevel>numchallengelevels-1)targetlevel=0; @@ -7670,8 +7655,8 @@ void Game::TickOnceAfter(){ if(leveltime<1){ loading=0; changedelay=.1; - alldead=0; - winhotspot=0; + alldead=false; + winhotspot=false; killhotspot=0; } @@ -7758,9 +7743,7 @@ void Game::TickOnceAfter(){ if(!firstload) LoadStuff(); whichchoice=0; - cout << "from " << campaignlevels[actuallevel].mapname.c_str() << "(" << actuallevel << ")" << endl; actuallevel=campaignlevels[actuallevel].nextlevel.front(); - cout << "to " << campaignlevels[actuallevel].mapname.c_str() << "(" << actuallevel << ")" << endl; visibleloading=1; stillloading=1; Loadlevel(campaignlevels[actuallevel].mapname.c_str());