-static void ch_skytint(Game *game, const char *args)
-{
- sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
-
- skyboxlightr=skyboxr;
- skyboxlightg=skyboxg;
- skyboxlightb=skyboxb;
-
- game->SetUpLighting();
-
- terrain.DoShadows();
- objects.DoShadows();
-}
-
-static void ch_skylight(Game *game, const char *args)
-{
- sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
-
- game->SetUpLighting();
-
- terrain.DoShadows();
- objects.DoShadows();
-}
-
-static void ch_skybox(Game *game, const char *args)
-{
- skyboxtexture = !skyboxtexture;
-
- game->SetUpLighting();
-
- terrain.DoShadows();
- objects.DoShadows();
-}
-
-static void cmd_dispatch(Game *game, const char *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]))
- {
- cmd_handlers[i](game, cmd + strlen(cmd_names[i])+1);
- break;
- }
- emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
-}
-
-/********************> Tick() <*****/
-extern bool save_image(const char * fname);
-void Screenshot (void)
-{
- char temp[1024];
- time_t t = time(NULL);
- struct tm *tme = localtime(&t);
- sprintf(temp, "Screenshots/Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
-
- #if defined(_WIN32)
- mkdir("Screenshots");
- #else
- mkdir("Screenshots", S_IRWXU);
- #endif
-
- save_image(temp);
-}
-
-void Game::SetUpLighting(){
- if(environment==snowyenvironment)
- light.setColors(.65,.65,.7,.4,.4,.44);
- if(environment==desertenvironment)
- light.setColors(.95,.95,.95,.4,.35,.3);
- if(environment==grassyenvironment)
- light.setColors(.95,.95,1,.4,.4,.44);
- if(!skyboxtexture)
- light.setColors(1,1,1,.4,.4,.4);
- float average;
- average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
- light.color[0]*=(skyboxlightr+average)/2;
- light.color[1]*=(skyboxlightg+average)/2;
- light.color[2]*=(skyboxlightb+average)/2;
- light.ambient[0]*=(skyboxlightr+average)/2;
- light.ambient[1]*=(skyboxlightg+average)/2;
- light.ambient[2]*=(skyboxlightb+average)/2;
-}
-
-int Game::findPathDist(int start,int end){
- int smallestcount,count,connected;
- int last,last2,last3,last4;
- int closest;
-
- smallestcount=1000;
- for(int i=0;i<50;i++){
- count=0;
- last=start;
- last2=-1;
- last3=-1;
- last4=-1;
- while(last!=end&&count<30){
- closest=-1;
- for(int j=0;j<numpathpoints;j++){
- if(j!=last&&j!=last2&&j!=last3&&j!=last4)
- {
- connected=0;
- if(numpathpointconnect[j])
- for(int k=0;k<numpathpointconnect[j];k++){
- if(pathpointconnect[j][k]==last)connected=1;
- }
- if(!connected)
- if(numpathpointconnect[last])
- for(int k=0;k<numpathpointconnect[last];k++){
- if(pathpointconnect[last][k]==j)connected=1;
- }
- if(connected)
- if(closest==-1||Random()%2==0){
- closest=j;
- }
- }
- }
- last4=last3;
- last3=last2;
- last2=last;
- last=closest;
- count++;
- }
- if(count<smallestcount)smallestcount=count;
- }
- return smallestcount;
-}
-
-int Game::checkcollide(XYZ startpoint,XYZ endpoint){
- static XYZ colpoint,colviewer,coltarget;
- static float minx,minz,maxx,maxz,miny,maxy;
-
- minx=min(startpoint.x,endpoint.x)-1;
- miny=min(startpoint.y,endpoint.y)-1;
- minz=min(startpoint.z,endpoint.z)-1;
- maxx=max(startpoint.x,endpoint.x)+1;
- maxy=max(startpoint.y,endpoint.y)+1;
- maxz=max(startpoint.z,endpoint.z)+1;
-
- for(int i=0;i<objects.numobjects;i++){
- if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
- objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
- objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
- objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
- objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
- objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
- if( objects.type[i]!=treeleavestype&&
- objects.type[i]!=bushtype&&
- objects.type[i]!=firetype){
- colviewer=startpoint;
- coltarget=endpoint;
- if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
- }
- }
- }
-
- //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
-
- return -1;
-}
-
-int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
- static XYZ colpoint,colviewer,coltarget;
- static float minx,minz,maxx,maxz,miny,maxy;
- static int i; //FIXME: see below
-
- minx=min(startpoint.x,endpoint.x)-1;
- miny=min(startpoint.y,endpoint.y)-1;
- minz=min(startpoint.z,endpoint.z)-1;
- maxx=max(startpoint.x,endpoint.x)+1;
- maxy=max(startpoint.y,endpoint.y)+1;
- maxz=max(startpoint.z,endpoint.z)+1;
-
- if(what!=1000){
- if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
- objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
- objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
- objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
- objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
- objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
- if( objects.type[what]!=treeleavestype&&
- objects.type[what]!=bushtype&&
- objects.type[what]!=firetype){
- colviewer=startpoint;
- coltarget=endpoint;
- //FIXME: i/what
- if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
- }
- }
- }
-
- if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
-
- return -1;
-}
-
-void Game::Setenvironment(int which)
-{
- LOGFUNC;
-
- LOG(" Setting environment...");
-
- float temptexdetail;
- environment=which;
-
- pause_sound(stream_snowtheme);
- pause_sound(stream_grasstheme);
- pause_sound(stream_deserttheme);
- pause_sound(stream_wind);
- pause_sound(stream_desertambient);
-
-
- if(environment==snowyenvironment){
- windvector=0;
- windvector.z=3;
- if(ambientsound)
- emit_stream_np(stream_wind);
-
- LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
- LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
- LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
- LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
-
- footstepsound = footstepsn1;
- footstepsound2 = footstepsn2;
- footstepsound3 = footstepst1;
- footstepsound4 = footstepst2;
-
- LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
-
- LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
-
- //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
-
-
-
-
- temptexdetail=texdetail;
- if(texdetail>1)texdetail=4;
- skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
- ":Data:Textures:Skybox(snow):Left.jpg",
- ":Data:Textures:Skybox(snow):Back.jpg",
- ":Data:Textures:Skybox(snow):Right.jpg",
- ":Data:Textures:Skybox(snow):Up.jpg",
- ":Data:Textures:Skybox(snow):Down.jpg");
-
-
-
-
- texdetail=temptexdetail;
- } else if(environment==desertenvironment){
- windvector=0;
- windvector.z=2;
- LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
- LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
- LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
- LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
-
-
- if(ambientsound)
- emit_stream_np(stream_desertambient);
-
- footstepsound = footstepsn1;
- footstepsound2 = footstepsn2;
- footstepsound3 = footstepsn1;
- footstepsound4 = footstepsn2;
-
- LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
-
- LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
-
- //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
-
-
-
- temptexdetail=texdetail;
- if(texdetail>1)texdetail=4;
- skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
- ":Data:Textures:Skybox(sand):Left.jpg",
- ":Data:Textures:Skybox(sand):Back.jpg",
- ":Data:Textures:Skybox(sand):Right.jpg",
- ":Data:Textures:Skybox(sand):Up.jpg",
- ":Data:Textures:Skybox(sand):Down.jpg");
-
-
-
-
- texdetail=temptexdetail;
- } else if(environment==grassyenvironment){
- windvector=0;
- windvector.z=2;
- LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
- LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
- LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
- LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
-
- if(ambientsound)
- emit_stream_np(stream_wind, 100.);
-
- footstepsound = footstepgr1;
- footstepsound2 = footstepgr2;
- footstepsound3 = footstepst1;
- footstepsound4 = footstepst2;
-
- LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
-
- LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
-
- //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
-
-
-
- temptexdetail=texdetail;
- if(texdetail>1)texdetail=4;
- skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
- ":Data:Textures:Skybox(grass):Left.jpg",
- ":Data:Textures:Skybox(grass):Back.jpg",
- ":Data:Textures:Skybox(grass):Right.jpg",
- ":Data:Textures:Skybox(grass):Up.jpg",
- ":Data:Textures:Skybox(grass):Down.jpg");
-
-
-
- texdetail=temptexdetail;
- }
- temptexdetail=texdetail;
- texdetail=1;
- terrain.load(":Data:Textures:heightmap.png");
-
- texdetail=temptexdetail;
-}
-
-void Game::Loadlevel(int which) {
- stealthloading=0;
- whichlevel=which;
-
- if(which == -1) {
- tutoriallevel = -1;
- Loadlevel("tutorial");
- } else if(which >= 0 && which <= 15) {
- char buf[32];
- snprintf(buf, 32, "map%d", which + 1); // challenges
- Loadlevel(buf);
- } else
- Loadlevel("mapsave");
-}
-
-void Game::Loadlevel(const char *name) {
- int templength;
- float lamefloat;
- static const char *pfx = ":Data:Maps:";
- char *buf;
-
- float headprop,legprop,armprop,bodyprop;
-
- LOGFUNC;
-
- LOG(std::string("Loading level...") + name);
- cout << "Loading level..." << name << endl;
-
- if(!gameon)
- visibleloading=1;
- if(stealthloading)
- visibleloading=0;
- if(!stillloading)
- loadtime=0;
- gamestarted=1;
-
- numenvsounds=0;
-
- if(tutoriallevel!=-1)
- tutoriallevel=0;
- else
- tutoriallevel=1;
-
- if(tutoriallevel==1)
- tutorialstage=0;
- if(tutorialstage==0) {
- tutorialstagetime=0;
- tutorialmaxtime=1;
- }
- loadingstuff=1;
- pause_sound(whooshsound);
- pause_sound(stream_firesound);
-
- // Change the map filename into something that is os specific
- buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
- sprintf(buf, "%s%s", pfx, name);
- const char *FixedFN = ConvertFileName(buf);
-
- int mapvers;
- FILE *tfile;
- 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;
- hostiletime=0;
- won=0;
-
- animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
-
- numdialogues=0;
-
- for(int i=0;i<20;i++)
- dialoguegonethrough[i]=0;
-
- indialogue=-1;
- cameramode=0;
-
- damagedealt=0;
- damagetaken=0;
-
- if(accountactive)
- difficulty=accountactive->getDifficulty();
-
- if(difficulty!=2)
- minimap=1;
- else
- minimap=0;
-
- numhotspots=0;
- currenthotspot=-1;
- bonustime=1;
-
- skyboxtexture=1;
- skyboxr=1;
- skyboxg=1;
- skyboxb=1;
-
- freeze=0;
- winfreeze=0;
-
- for(int i=0;i<100;i++)
- bonusnum[i]=0;
-
- numfalls=0;
- numflipfail=0;
- numseen=0;
- numstaffattack=0;
- numswordattack=0;
- numknifeattack=0;
- numunarmedattack=0;
- numescaped=0;
- numflipped=0;
- numwallflipped=0;
- numthrowkill=0;
- numafterkill=0;
- numreversals=0;
- numattacks=0;
- maxalarmed=0;
- numresponded=0;
-
- bonustotal=startbonustotal;
- bonus=0;
- gameon=1;
- changedelay=0;
- if(console){
- emit_sound_np(consolesuccesssound);
- freeze=0;
- console=false;
- cout << "console contente" << endl;
- }
-
- if(!stealthloading){
- terrain.numdecals=0;
- Sprite::deleteSprites();
- for(int i=0;i<objects.numobjects;i++)
- objects.model[i].numdecals=0;
-
- int j=objects.numobjects;
- for(int i=0;i<j;i++){
- objects.DeleteObject(0);
- if(visibleloading)
- LoadingScreen();
- }
-
- for(int i=0;i<subdivision;i++)
- for(int j=0;j<subdivision;j++)
- terrain.patchobjectnum[i][j]=0;
- if(visibleloading)
- LoadingScreen();
- }
-
- weapons.clear();
-
- funpackf(tfile, "Bi", &mapvers);
- if(mapvers>=15)
- funpackf(tfile, "Bi", &indemo);
- else
- indemo=0;
- if(mapvers>=5)
- funpackf(tfile, "Bi", &maptype);
- else
- maptype=mapkilleveryone;
- if(mapvers>=6)
- funpackf(tfile, "Bi", &hostile);
- else
- hostile=1;
- if(mapvers>=4)
- funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
- else{
- viewdistance=100;
- fadestart=.6;
- }
- if(mapvers>=2)
- funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
- else{
- skyboxtexture=1;
- skyboxr=1;
- skyboxg=1;
- skyboxb=1;
- }
- if(mapvers>=10)
- funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
- else{
- skyboxlightr=skyboxr;
- skyboxlightg=skyboxg;
- skyboxlightb=skyboxb;
- }
- if(!stealthloading)
- funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
- if(stealthloading)
- funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
- player[0].originalcoords=player[0].coords;
- if(player[0].num_weapons>0&&player[0].num_weapons<5)
- for(int j=0;j<player[0].num_weapons;j++){
- player[0].weaponids[j]=weapons.size();
- int type;
- funpackf(tfile, "Bi", &type);
- weapons.push_back(Weapon(type,0));
- }
-
- if(visibleloading)
- LoadingScreen();
-
- funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
- funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
- funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
- funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
-
- funpackf(tfile, "Bi", &player[0].numclothes);
-
- if(mapvers>=9)
- funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
- else{
- player[0].whichskin=0;
- player[0].creature=rabbittype;
- }
-
- player[0].lastattack=-1;
- player[0].lastattack2=-1;
- player[0].lastattack3=-1;
-
- //dialogues
- if(mapvers>=8){
- funpackf(tfile, "Bi", &numdialogues);
- for(int k=0;k<numdialogues;k++){
- funpackf(tfile, "Bi", &numdialogueboxes[k]);
- funpackf(tfile, "Bi", &dialoguetype[k]);
- for(int l=0;l<10;l++){
- funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
- funpackf(tfile, "Bf", &participantrotation[k][l]);
- }
- for(int l=0;l<numdialogueboxes[k];l++){
- funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
- funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
- funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
- funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
- funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
-
- funpackf(tfile, "Bi",&templength);
- if(templength>128||templength<=0)
- templength=128;
- int m;
- for(m=0;m<templength;m++){
- funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
- if(dialoguetext[k][l][m]=='\0')
- break;
- }
- dialoguetext[k][l][m] = 0;
-
- funpackf(tfile, "Bi",&templength);
- if(templength>64||templength<=0)templength=64;
- for(m=0;m<templength;m++){
- funpackf(tfile, "Bb", &dialoguename[k][l][m]);
- if(dialoguename[k][l][m]=='\0')
- break;
- }
- dialoguename[k][l][m] = 0;
- funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
- funpackf(tfile, "Bi", &participantfocus[k][l]);
- funpackf(tfile, "Bi", &participantaction[k][l]);
-
- for(m=0;m<10;m++)
- funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
-
- funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
- }