-inline float roughDirectionTo(XYZ start, XYZ end){
- return roughDirection(end-start);
-}
-
-//TODO: gotta be a better way
-inline float pitch(XYZ vec){
- Normalise(&vec);
- return -asin(vec.y)*180/M_PI;
-}
-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){
- if(fabs(from-to)<by) return to;
- else if(from>to) return from-by;
- else return from+by;
-}
-
-void playdialogueboxsound(){
- XYZ temppos;
- temppos=player[participantfocus[whichdialogue][indialogue]].coords;
- temppos=temppos-viewer;
- Normalise(&temppos);
- temppos+=viewer;
-
- int sound=-1;
- switch(dialogueboxsound[whichdialogue][indialogue]){
- case -6: sound=alarmsound; break;
- case -4: sound=consolefailsound; break;
- case -3: sound=consolesuccesssound; break;
- case -2: sound=firestartsound; break;
- case -1: sound=fireendsound; break;
- case 1: sound=rabbitchitter; break;
- case 2: sound=rabbitchitter2; break;
- case 3: sound=rabbitpainsound; break;
- case 4: sound=rabbitpain1sound; break;
- case 5: sound=rabbitattacksound; break;
- case 6: sound=rabbitattack2sound; break;
- case 7: sound=rabbitattack3sound; break;
- case 8: sound=rabbitattack4sound; break;
- case 9: sound=growlsound; break;
- case 10: sound=growl2sound; break;
- case 11: sound=snarlsound; break;
- case 12: sound=snarl2sound; break;
- case 13: sound=barksound; break;
- case 14: sound=bark2sound; break;
- case 15: sound=bark3sound; break;
- case 16: sound=barkgrowlsound; break;
- default: break;
- }
- if(sound!=-1)
- emit_sound_at(sound, temppos);
-}
-
-// end added utility functions ================================================================
-
-
-
-static void ch_quit(Game *game, const char *args)
-{
- game->tryquit = 1;
-}
-
-static void ch_map(Game *game, const char *args)
-{
- game->Loadlevel(args);
- game->whichlevel = -2;
- campaign = 0;
-}
-
-static void ch_save(Game *game, const char *args)
-{
- char buf[64];
- int i, j, k, l, m, templength;
- float headprop, bodyprop, armprop, legprop;
- snprintf(buf, 63, ":Data:Maps:%s", args);
-
-
- int mapvers = 12;;
-
- FILE *tfile;
- tfile=fopen( ConvertFileName(buf), "wb" );
- fpackf(tfile, "Bi", mapvers);
- fpackf(tfile, "Bi", maptype);
- fpackf(tfile, "Bi", hostile);
- fpackf(tfile, "Bf Bf", viewdistance, fadestart);
- fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
- fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
- fpackf(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(player[0].num_weapons>0&&player[0].num_weapons<5)
- for(int j=0;j<player[0].num_weapons;j++){
- fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
- }
-
- fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
- fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
- fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
- fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
-
- fpackf(tfile, "Bi", player[0].numclothes);
-
- fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
-
- fpackf(tfile, "Bi", numdialogues);
- for(int k=0;k<numdialogues;k++){
- fpackf(tfile, "Bi", numdialogueboxes[k]);
- fpackf(tfile, "Bi", dialoguetype[k]);
- for(int l=0;l<10;l++){
- fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
- fpackf(tfile, "Bf", participantrotation[k][l]);
- }
- for(int l=0;l<numdialogueboxes[k];l++){
- fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
- fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
- fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
- fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
- fpackf(tfile, "Bi", dialogueboxsound[k][l]);
-
- templength=strlen(dialoguetext[k][l]);
- fpackf(tfile, "Bi",(templength));
- for(int m=0;m<templength;m++){
- fpackf(tfile, "Bb", dialoguetext[k][l][m]);
- if(dialoguetext[k][l][m]=='\0')break;
- }
-
- templength=strlen(dialoguename[k][l]);
- fpackf(tfile, "Bi",templength);
- for(int m=0;m<templength;m++){
- fpackf(tfile, "Bb", dialoguename[k][l][m]);
- if(dialoguename[k][l][m]=='\0')break;
- }
-
- fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
- fpackf(tfile, "Bi", participantfocus[k][l]);
- fpackf(tfile, "Bi", participantaction[k][l]);
-
- for(int m=0;m<10;m++)
- fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
-
- fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
- }
- }
-
- for(int k=0;k<player[0].numclothes;k++){
- templength=strlen(player[0].clothes[k]);
- fpackf(tfile, "Bi", templength);
- for(int l=0;l<templength;l++)
- fpackf(tfile, "Bb", player[0].clothes[k][l]);
- fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
- }
-
- fpackf(tfile, "Bi", environment);
-
- fpackf(tfile, "Bi", objects.numobjects);
-
- for(int k=0;k<objects.numobjects;k++){
- fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k], objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
- }
-
- fpackf(tfile, "Bi", numhotspots);
- for(int i=0;i<numhotspots;i++){
- fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
- templength=strlen(hotspottext[i]);
- fpackf(tfile, "Bi",templength);
- for(int l=0;l<templength;l++)
- fpackf(tfile, "Bb", hotspottext[i][l]);
- }
-
- fpackf(tfile, "Bi", numplayers);
- if(numplayers<maxplayers)
- for(int j=1;j<numplayers;j++){
- fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
- if(player[j].num_weapons<5)
- for(int k=0;k<player[j].num_weapons;k++){
- fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
- }
- if(player[j].numwaypoints<30){
- fpackf(tfile, "Bi", player[j].numwaypoints);
- for(int k=0;k<player[j].numwaypoints;k++){
- fpackf(tfile, "Bf", player[j].waypoints[k].x);
- fpackf(tfile, "Bf", player[j].waypoints[k].y);
- fpackf(tfile, "Bf", player[j].waypoints[k].z);
- fpackf(tfile, "Bi", player[j].waypointtype[k]);
- }
- fpackf(tfile, "Bi", player[j].waypoint);
- } else {
- player[j].numwaypoints=0;
- player[j].waypoint=0;
- fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
- }
-
- fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
- fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
- fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
- fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
-
- if(player[j].creature==wolftype) {
- headprop=player[j].proportionhead.x/1.1;
- bodyprop=player[j].proportionbody.x/1.1;
- armprop=player[j].proportionarms.x/1.1;
- legprop=player[j].proportionlegs.x/1.1;
- } else if(player[j].creature==rabbittype){
- headprop=player[j].proportionhead.x/1.2;
- bodyprop=player[j].proportionbody.x/1.05;
- armprop=player[j].proportionarms.x/1.00;
- legprop=player[j].proportionlegs.x/1.1;
- }
-
- fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
-
- fpackf(tfile, "Bi", player[j].numclothes);
- if(player[j].numclothes)
- for(int k=0;k<player[j].numclothes;k++){
- int templength;
- templength=strlen(player[j].clothes[k]);
- fpackf(tfile, "Bi", templength);
- for(int l=0;l<templength;l++)
- fpackf(tfile, "Bb", player[j].clothes[k][l]);
- fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
- }
- }
-
- fpackf(tfile, "Bi", game->numpathpoints);
- for(int j=0;j<game->numpathpoints;j++){
- fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
- for(int k=0;k<game->numpathpointconnect[j];k++){
- fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
- }
- }
-
- fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
-
- fclose(tfile);
-}
-
-static void ch_cellar(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_tint(Game *game, const char *args)
-{
- sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
-}
-
-static void ch_tintr(Game *game, const char *args)
-{
- tintr = atof(args);
-}
-
-static void ch_tintg(Game *game, const char *args)
-{
- tintg = atof(args);
-}
-
-static void ch_tintb(Game *game, const char *args)
-{
- tintb = atof(args);
-}
-
-static void ch_speed(Game *game, const char *args)
-{
- player[0].speedmult = atof(args);
-}
-
-static void ch_strength(Game *game, const char *args)
-{
- player[0].power = atof(args);
-}
-
-static void ch_power(Game *game, const char *args)
-{
- player[0].power = atof(args);
-}
-
-static void ch_size(Game *game, const char *args)
-{
- player[0].scale = atof(args) * .2;
-}
-
-static int find_closest()
-{
- int closest = 0;
- float closestdist = 1.0/0.0;
-
- for (int i = 1; i < numplayers; i++) {
- float distance;
- distance = findDistancefast(&player[i].coords,&player[0].coords);
- if (distance < closestdist) {
- closestdist = distance;
- closest = i;
- }
- }
- return closest;
-}
-
-static void ch_sizenear(Game *game, const char *args)
-{
- int closest = find_closest();
-
- if (closest)
- player[closest].scale = atof(args) * .2;
-}
-
-static void set_proportion(int pnum, const char *args)
-{
- float headprop,bodyprop,armprop,legprop;
-
- sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
-
- if(player[pnum].creature==wolftype){
- player[pnum].proportionhead=1.1*headprop;
- player[pnum].proportionbody=1.1*bodyprop;
- player[pnum].proportionarms=1.1*armprop;
- player[pnum].proportionlegs=1.1*legprop;
- } else if(player[pnum].creature==rabbittype){
- player[pnum].proportionhead=1.2*headprop;
- player[pnum].proportionbody=1.05*bodyprop;
- player[pnum].proportionarms=1.00*armprop;
- player[pnum].proportionlegs=1.1*legprop;
- player[pnum].proportionlegs.y=1.05*legprop;
- }
-}
-
-static void ch_proportion(Game *game, const char *args)
-{
- set_proportion(0, args);
-}
-
-static void ch_proportionnear(Game *game, const char *args)
-{
- int closest = find_closest();
- if (closest)
- set_proportion(closest, args);
-}
-
-static void set_protection(int pnum, const char *args)
-{
- float head, high, low;
- sscanf(args, "%f%f%f", &head, &high, &low);
-
- player[pnum].protectionhead = head;
- player[pnum].protectionhigh = high;
- player[pnum].protectionlow = low;
-}
-
-static void ch_protection(Game *game, const char *args)
-{
- set_protection(0, args);
-}
-
-static void ch_protectionnear(Game *game, const char *args)
-{
- int closest = find_closest();
- if (closest)
- set_protection(closest, args);
-}
-
-static void set_armor(int pnum, const char *args)
-{
- float head, high, low;
- sscanf(args, "%f%f%f", &head, &high, &low);
-
- player[pnum].armorhead = head;
- player[pnum].armorhigh = high;
- player[pnum].armorlow = low;
-}
-
-static void ch_armor(Game *game, const char *args)
-{
- set_armor(0, args);
-}
-
-static void ch_armornear(Game *game, const char *args)
-{
- int closest = find_closest();
- if (closest)
- set_armor(closest, args);
-}
-
-static void ch_protectionreset(Game *game, const char *args)
-{
- set_protection(0, "1 1 1");
- set_armor(0, "1 1 1");
-}
-
-static void set_metal(int pnum, const char *args)
-{
- float head, high, low;
- sscanf(args, "%f%f%f", &head, &high, &low);
-
- player[pnum].metalhead = head;
- player[pnum].metalhigh = high;
- player[pnum].metallow = low;
-}
-
-static void ch_metal(Game *game, const char *args)
-{
- set_metal(0, args);
-}
-
-static void set_noclothes(int pnum, Game *game, const char *args)
-{
- player[pnum].numclothes = 0;
- game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
- &player[pnum].skeleton.drawmodel.textureptr,1,
- &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
-}
-
-static void ch_noclothes(Game *game, const char *args)
-{
- set_noclothes(0, game, args);
-}
-
-static void ch_noclothesnear(Game *game, const char *args)
-{
- int closest = find_closest();
- if (closest)
- set_noclothes(closest, game, args);
-}
-
-
-static void set_clothes(int pnum, Game *game, const char *args)
-{
- char buf[64];
- snprintf(buf, 63, ":Data:Textures:%s.png", args);
-
- if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
- return;
-
- player[pnum].DoMipmaps();
- strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
- player[pnum].clothestintr[player[pnum].numclothes]=tintr;
- player[pnum].clothestintg[player[pnum].numclothes]=tintg;
- player[pnum].clothestintb[player[pnum].numclothes]=tintb;
- player[pnum].numclothes++;
-}
-
-static void ch_clothes(Game *game, const char *args)
-{
- set_clothes(0, game, args);
-}
-
-static void ch_clothesnear(Game *game, const char *args)
-{
- int closest = find_closest();
- if (closest)
- set_clothes(closest, game, args);
-}
-
-static void ch_belt(Game *game, const char *args)
-{
- player[0].skeleton.clothes = !player[0].skeleton.clothes;
-}
-
-
-static void ch_cellophane(Game *game, const char *args)
-{
- cellophane = !cellophane;
- float mul = cellophane ? 0 : 1;
-
- for (int i = 0; i < numplayers; i++) {
- player[i].proportionhead.z = player[i].proportionhead.x * mul;
- player[i].proportionbody.z = player[i].proportionbody.x * mul;
- player[i].proportionarms.z = player[i].proportionarms.x * mul;
- player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
- }
-}
-
-static void ch_funnybunny(Game *game, const char *args)
-{
- player[0].skeleton.id=0;
- player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
- ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
- ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
- ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
- ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
- ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
- game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
- player[0].creature=rabbittype;
- player[0].scale=.2;
- player[0].headless=0;
- player[0].damagetolerance=200;
- set_proportion(0, "1 1 1 1");
-}
-
-static void ch_wolfie(Game *game, const char *args)
-{
- player[0].skeleton.id=0;
- player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
- ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
- ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
- ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
- ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
- ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
- game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
- player[0].creature=wolftype;
- player[0].damagetolerance=300;
- set_proportion(0, "1 1 1 1");
-}
-
-static void ch_wolfieisgod(Game *game, const char *args)
-{
- ch_wolfie(game, args);
-}
-
-static void ch_wolf(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_snowwolf(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_darkwolf(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_lizardwolf(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_white(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_brown(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_black(Game *game, const char *args)
-{
- game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
- &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
-}
-
-static void ch_sizemin(Game *game, const char *args)