From 6bfa76ca29b1e3c0eafefd82746d614386aea0ad Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Sun, 16 May 2010 14:54:48 +0400 Subject: [PATCH] Cleanup handling of console commands --- .hgignore | 8 +- Source/ConsoleCmds.h | 70 + Source/Constants.h | 20 +- Source/GameTick.cpp | 2932 +++++++++++++----------------------------- Source/Models.cpp | 6 +- Source/Models.h | 6 +- Source/Skeleton.cpp | 12 +- Source/Skeleton.h | 2 +- 8 files changed, 1022 insertions(+), 2034 deletions(-) create mode 100644 Source/ConsoleCmds.h diff --git a/.hgignore b/.hgignore index 795dbe1..21373a1 100644 --- a/.hgignore +++ b/.hgignore @@ -7,5 +7,11 @@ Xcode/*.xcodeproj/*.pbxuser build *~ .*.swp -lugaru-* +lugaru* +cmake_install.cmake cmake-build +CMakeFiles +CMakeCache.txt +Makefile +cscope.* +tags diff --git a/Source/ConsoleCmds.h b/Source/ConsoleCmds.h new file mode 100644 index 0000000..0e6c0ef --- /dev/null +++ b/Source/ConsoleCmds.h @@ -0,0 +1,70 @@ +DECLARE_COMMAND(quit) +DECLARE_COMMAND(map) +DECLARE_COMMAND(save) + +DECLARE_COMMAND(cellar) +DECLARE_COMMAND(tint) +DECLARE_COMMAND(tintr) +DECLARE_COMMAND(tintg) +DECLARE_COMMAND(tintb) +DECLARE_COMMAND(speed) +DECLARE_COMMAND(strength) +DECLARE_COMMAND(power) +DECLARE_COMMAND(size) +DECLARE_COMMAND(sizenear) +DECLARE_COMMAND(proportion) +DECLARE_COMMAND(proportionnear) +DECLARE_COMMAND(protection) +DECLARE_COMMAND(protectionnear) +DECLARE_COMMAND(protectionreset) +DECLARE_COMMAND(armor) +DECLARE_COMMAND(armornear) +DECLARE_COMMAND(metal) +DECLARE_COMMAND(clothes) +DECLARE_COMMAND(clothesnear) +DECLARE_COMMAND(noclothes) +DECLARE_COMMAND(noclothesnear) +DECLARE_COMMAND(belt) +DECLARE_COMMAND(cellophane) +DECLARE_COMMAND(funnybunny) +DECLARE_COMMAND(wolfie) +DECLARE_COMMAND(wolf) +DECLARE_COMMAND(snowwolf) +DECLARE_COMMAND(darkwolf) +DECLARE_COMMAND(white) +DECLARE_COMMAND(brown) +DECLARE_COMMAND(black) + +DECLARE_COMMAND(sizemin) +DECLARE_COMMAND(viewdistance) +DECLARE_COMMAND(fadestart) +DECLARE_COMMAND(slomo) +DECLARE_COMMAND(slofreq) + +DECLARE_COMMAND(tutorial) +DECLARE_COMMAND(hostile) +DECLARE_COMMAND(indemo) +DECLARE_COMMAND(notindemo) +DECLARE_COMMAND(type) +DECLARE_COMMAND(path) +DECLARE_COMMAND(hs) +DECLARE_COMMAND(dhs) +DECLARE_COMMAND(dialogue) +DECLARE_COMMAND(fixdialogue) +DECLARE_COMMAND(ddialogue) +DECLARE_COMMAND(fixtype) +DECLARE_COMMAND(fixrotation) +DECLARE_COMMAND(immobile) +DECLARE_COMMAND(allimmobile) +DECLARE_COMMAND(mobile) +DECLARE_COMMAND(default) +DECLARE_COMMAND(play) + +DECLARE_COMMAND(mapkilleveryone) +DECLARE_COMMAND(mapkillmost) +DECLARE_COMMAND(mapkillsomeone) +DECLARE_COMMAND(mapgosomewhere) + +DECLARE_COMMAND(skytint) +DECLARE_COMMAND(skylight) +DECLARE_COMMAND(skybox) diff --git a/Source/Constants.h b/Source/Constants.h index d921eb8..6769328 100644 --- a/Source/Constants.h +++ b/Source/Constants.h @@ -52,17 +52,17 @@ const int mapgosomewhere = 1; const int mapkillsomeone = 2; const int mapkillmost = 3; -const int wpkeepwalking = 0; -const int wppause = 1; +enum pathtypes {wpkeepwalking, wppause}; -const int typeactive = 0; -const int typesitting = 1; -const int typesittingwall = 2; -const int typesleeping = 3; -const int typedead1 = 4; -const int typedead2 = 5; -const int typedead3 = 6; -const int typedead4 = 7; +static const char *pathtypenames[] = {"keepwalking", "pause"}; + +enum editortypes {typeactive, typesitting, typesittingwall, typesleeping, + typedead1, typedead2, typedead3, typedead4}; + +static const char *editortypenames[] = { + "active", "sitting", "sitting wall", "sleeping", + "dead1", "dead2", "dead3", "dead4" +}; const int tracheotomy = 1; const int backstab = 2; diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 19876ad..1d2fea2 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -253,11 +253,931 @@ static bool stripfx(const char *str, const char *pfx) return !strncasecmp(str, pfx, strlen(pfx)); } -/********************> Tick() <*****/ extern OPENAL_STREAM * strm[20]; extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); + +static const char *cmd_names[] = { +#define DECLARE_COMMAND(cmd) #cmd " ", +#include "ConsoleCmds.h" +#undef DECLARE_COMMAND +}; + +typedef void (*console_handler)(Game *game, const char *args); + +#define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args); +#include "ConsoleCmds.h" +#undef DECLARE_COMMAND + +static console_handler cmd_handlers[] = { +#define DECLARE_COMMAND(cmd) ch_##cmd, +#include "ConsoleCmds.h" +#undef DECLARE_COMMAND +}; + +static void ch_quit(Game *game, const char *args) +{ + game->tryquit = 1; +} + +static void ch_map(Game *game, const char *args) +{ + char buf[64]; + snprintf(buf, 63, ":Data:Maps:%s", args); + game->Loadlevel(buf); + 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(j=0;j1&&numplayers0&&player[j].num_weapons<5) + for(k=0;knumpathpoints); + if(game->numpathpoints) + for(j=0;jnumpathpoints;j++){ + fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); + for(k=0;knumpathpointconnect[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; + } + + 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(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize); + 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_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_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) +{ + int i; + for (i = 1; i < numplayers; i++) + if (player[i].scale < 0.8 * 0.2) + player[i].scale = 0.8 * 0.2; +} + +static void ch_tutorial(Game *game, const char *args) +{ + tutoriallevel = atoi(args); +} + +static void ch_hostile(Game *game, const char *args) +{ + hostile = atoi(args); +} + +static void ch_indemo(Game *game, const char *args) +{ + game->indemo=1; + hotspot[numhotspots]=player[0].coords; + hotspotsize[numhotspots]=0; + hotspottype[numhotspots]=-111; + strcpy(hotspottext[numhotspots],"mapname"); + numhotspots++; +} + +static void ch_notindemo(Game *game, const char *args) +{ + game->indemo=0; + numhotspots--; +} + +static void ch_type(Game *game, const char *args) +{ + int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]); + for (i = 0; i < n; i++) + if (stripfx(args, editortypenames[i])) + { + editoractive = i; + break; + } +} + +static void ch_path(Game *game, const char *args) +{ + int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); + for (i = 0; i < n; i++) + if (stripfx(args, pathtypenames[i])) + { + editorpathtype = i; + break; + } +} + +static void ch_hs(Game *game, const char *args) +{ + hotspot[numhotspots]=player[0].coords; + + float size; + int type, shift; + sscanf(args, "%f%d %n", &size, &type, &shift); + + hotspotsize[numhotspots] = size; + hotspottype[numhotspots] = type; + + strcpy(hotspottext[numhotspots], args + shift); + strcat(hotspottext[numhotspots], "\n"); + + numhotspots++; +} + +static void ch_dialogue(Game *game, const char *args) +{ + int dlg, i, j; + char buf1[32], buf2[64]; + + sscanf(args, "%d %31s", &dlg, buf1); + snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1); + + dialoguetype[numdialogues] = dlg; + + memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues])); + memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues])); + + ifstream ipstream(ConvertFileName(buf2)); + ipstream.ignore(256,':'); + ipstream >> numdialogueboxes[numdialogues]; + for(i=0;i> dialogueboxlocation[numdialogues][i]; + ipstream.ignore(256,':'); + ipstream >> dialogueboxcolor[numdialogues][i][0]; + ipstream >> dialogueboxcolor[numdialogues][i][1]; + ipstream >> dialogueboxcolor[numdialogues][i][2]; + ipstream.ignore(256,':'); + ipstream.getline(dialoguename[numdialogues][i],64); + ipstream.ignore(256,':'); + ipstream.ignore(256,' '); + ipstream.getline(dialoguetext[numdialogues][i],128); + for(j=0;j<128;j++){ + if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n'; + } + ipstream.ignore(256,':'); + ipstream >> dialogueboxsound[numdialogues][i]; + } + + for(i=0;i> numdialogueboxes[whichdi]; + for(i=0;i> dialogueboxlocation[whichdi][i]; + ipstream.ignore(256,':'); + ipstream >> dialogueboxcolor[whichdi][i][0]; + ipstream >> dialogueboxcolor[whichdi][i][1]; + ipstream >> dialogueboxcolor[whichdi][i][2]; + ipstream.ignore(256,':'); + ipstream.getline(dialoguename[whichdi][i],64); + ipstream.ignore(256,':'); + ipstream.ignore(256,' '); + ipstream.getline(dialoguetext[whichdi][i],128); + for(j=0;j<128;j++){ + if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n'; + } + ipstream.ignore(256,':'); + ipstream >> dialogueboxsound[whichdi][i]; + } + + ipstream.close(); +} + +static void ch_fixtype(Game *game, const char *args) +{ + int dlg; + sscanf(args, "%d", &dlg); + dialoguetype[0] = dlg; +} + +static void ch_fixrotation(Game *game, const char *args) +{ + participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation; +} + +static void ch_ddialogue(Game *game, const char *args) +{ + if (numdialogues) + numdialogues--; +} + +static void ch_dhs(Game *game, const char *args) +{ + if (numhotspots) + numhotspots--; +} + +static void ch_immobile(Game *game, const char *args) +{ + player[0].immobile = 1; +} + +static void ch_allimmobile(Game *game, const char *args) +{ + for (int i = 1; i < numplayers; i++) + player[i].immobile = 1; +} + +static void ch_mobile(Game *game, const char *args) +{ + player[0].immobile = 0; +} + +static void ch_default(Game *game, const char *args) +{ + player[0].armorhead=1; + player[0].armorhigh=1; + player[0].armorlow=1; + player[0].protectionhead=1; + player[0].protectionhigh=1; + player[0].protectionlow=1; + player[0].metalhead=1; + player[0].metalhigh=1; + player[0].metallow=1; + player[0].power=1; + player[0].speedmult=1; + player[0].scale=1; + + if(player[0].creature==wolftype){ + player[0].proportionhead=1.1; + player[0].proportionbody=1.1; + player[0].proportionarms=1.1; + player[0].proportionlegs=1.1; + } + + if(player[0].creature==rabbittype){ + player[0].proportionhead=1.2; + player[0].proportionbody=1.05; + player[0].proportionarms=1.00; + player[0].proportionlegs=1.1; + player[0].proportionlegs.y=1.05; + } + + player[0].numclothes=0; + game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin], + &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0], + &player[0].skeleton.skinsize); + + editoractive=typeactive; + player[0].immobile=0; +} + +static void ch_play(Game *game, const char *args) +{ + int dlg, i; + sscanf(args, "%d", &dlg); + whichdialogue = dlg; + + if (whichdialogue >= numdialogues) + return; + + for(i=0;iSetUpLighting(); + + 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])); + break; + } + if (i < n_cmds) + { + PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true); + OPENAL_SetVolume(channels[consolesuccesssound], 256); + OPENAL_SetPaused(channels[consolesuccesssound], false); + } + else + { + PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true); + OPENAL_SetVolume(channels[consolefailsound], 256); + OPENAL_SetPaused(channels[consolefailsound], false); + } +} + + + +/********************> Tick() <*****/ extern void ScreenShot(const char * fname); void Screenshot (void) { @@ -1671,7 +2591,6 @@ void Game::Tick() static XYZ test2; static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2; static int whichhit; - static bool donesomething; static bool oldjumpkeydown; int templength; @@ -3249,2009 +4168,8 @@ void Game::Tick() } if(i==MAC_RETURN_KEY){ archiveselected=0; - donesomething=0; - if(stripfx(consoletext[0], "quit ")||stripfx(consoletext[0], "exit ")){ - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); - donesomething=1; - tryquit=1; - } - /*if(stripfx(consoletext[0], "send ")){ - for(j=5;j32)numchars=32; - for(j=5;j0){ - for(k=14;k>=1;k--){ - for(j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(j=0;j<255;j++){ - consoletext[0][j]=' '; - } - if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v); - else sprintf (consoletext[0], "Could not open connection"); - - consolechars[0]=255; - consoleselected=0; - } - } - else - { - donesomething=1; - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); - - if(consolechars[0]>0){ - for(k=14;k>=1;k--){ - for(j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(j=0;j<255;j++){ - consoletext[0][j]=' '; - } - sprintf (consoletext[0], "Connected to %s",theIPAddress); - - consolechars[0]=255; - consoleselected=0; - } - } - } - - if(stripfx(consoletext[0], "host ")){ - unsigned char gameNameStr[32], playerNameStr[32]; - char gameName[32];//, playerName[32]; - NMUInt32 port; - int players; - int v; - - port = 25710; - players =4; - - strcpy(gameName, "Host's game"); - strcpy(playerName, "Host"); - GameC2PStr( gameName, gameNameStr ); - GameC2PStr( playerName, playerNameStr ); - - v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr ); - if(v) - { - if(consolechars[0]>0){ - for(k=14;k>=1;k--){ - for(j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(j=0;j<255;j++){ - consoletext[0][j]=' '; - } - sprintf (consoletext[0], "Error #%d!!!",v); - - consolechars[0]=255; - consoleselected=0; - } - } - else - { - donesomething=1; - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); - - if(consolechars[0]>0){ - for(k=14;k>=1;k--){ - for(j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(j=0;j<255;j++){ - consoletext[0][j]=' '; - } - sprintf (consoletext[0], "Game hosted"); - - consolechars[0]=255; - consoleselected=0; - } - } - } - */ - if(stripfx(consoletext[0], "save ")){ - mapname[0]=':'; - mapname[1]='D'; - mapname[2]='a'; - mapname[3]='t'; - mapname[4]='a'; - mapname[5]=':'; - mapname[6]='M'; - mapname[7]='a'; - mapname[8]='p'; - mapname[9]='s'; - mapname[10]=':'; - for(j=5;j0&&player[0].num_weapons<5) - for(j=0;j1&&numplayers0&&player[j].num_weapons<5) - for(k=0;k0&&player[0].num_weapons<5) - for(j=0;j1&&numplayers0&&player[j].num_weapons<5) - for(k=0;k0&&player[0].num_weapons<5) - for(j=0;j1&&numplayers0&&player[j].num_weapons<5) - for(k=0;k1) - for(i=1;i1) - for(i=1;i> numdialogueboxes[numdialogues]; - for(i=0;i> dialogueboxlocation[numdialogues][i]; - ipstream.ignore(256,':'); - ipstream >> dialogueboxcolor[numdialogues][i][0]; - ipstream >> dialogueboxcolor[numdialogues][i][1]; - ipstream >> dialogueboxcolor[numdialogues][i][2]; - ipstream.ignore(256,':'); - ipstream.getline(dialoguename[numdialogues][i],64); - ipstream.ignore(256,':'); - ipstream.ignore(256,' '); - ipstream.getline(dialoguetext[numdialogues][i],128); - for(j=0;j<128;j++){ - if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n'; - } - ipstream.ignore(256,':'); - ipstream >> dialogueboxsound[numdialogues][i]; - } - - for(i=0;i> numdialogueboxes[whichdi]; - for(i=0;i> dialogueboxlocation[whichdi][i]; - ipstream.ignore(256,':'); - ipstream >> dialogueboxcolor[whichdi][i][0]; - ipstream >> dialogueboxcolor[whichdi][i][1]; - ipstream >> dialogueboxcolor[whichdi][i][2]; - ipstream.ignore(256,':'); - ipstream.getline(dialoguename[whichdi][i],64); - ipstream.ignore(256,':'); - ipstream.ignore(256,' '); - ipstream.getline(dialoguetext[whichdi][i],128); - for(j=0;j<128;j++){ - if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n'; - } - ipstream.ignore(256,':'); - ipstream >> dialogueboxsound[whichdi][i]; - } - - ipstream.close(); - - donesomething=1; - } - - if(stripfx(consoletext[0], "fixtype ")){ - int startpoint; - int alldone; - int whichdi; - - alldone=0; - startpoint=8; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - dialoguetype[0]=atoi(mapname); - - startpoint=j+1; - - donesomething=1; - } - - - if(stripfx(consoletext[0], "fixrotation ")){ - participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation; - - donesomething=1; - } - - if(stripfx(consoletext[0], "ddialogue ")){ - numdialogues--; - if(numdialogues<0)numdialogues=0; - - donesomething=1; - } - - if(stripfx(consoletext[0], "immobile ")){ - player[0].immobile=1; - donesomething=1; - } - - if(stripfx(consoletext[0], "mobile ")){ - player[0].immobile=0; - donesomething=1; - } - - if(stripfx(consoletext[0], "play ")){ - int startpoint; - int alldone; - - alldone=0; - startpoint=5; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - startpoint=j+1; - - whichdialogue=atoi(mapname); - - if(numdialogues>whichdialogue){ - for(i=0;i0)player[i].immobile=1; - } - donesomething=1; - } - - - if(stripfx(consoletext[0], "default ")||stripfx(consoletext[0], "Default ")){ - player[0].armorhead=1; - player[0].armorhigh=1; - player[0].armorlow=1; - player[0].protectionhead=1; - player[0].protectionhigh=1; - player[0].protectionlow=1; - player[0].metalhead=1; - player[0].metalhigh=1; - player[0].metallow=1; - player[0].power=1; - player[0].speedmult=1; - player[0].scale=1; - - if(player[0].creature==wolftype){ - player[0].proportionhead=1.1; - player[0].proportionbody=1.1; - player[0].proportionarms=1.1; - player[0].proportionlegs=1.1; - } - - if(player[0].creature==rabbittype){ - player[0].proportionhead=1.2; - player[0].proportionbody=1.05; - player[0].proportionarms=1.00; - player[0].proportionlegs=1.1; - player[0].proportionlegs.y=1.05; - } - - player[0].numclothes=0; - LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin], - &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize); - - editoractive=typeactive; - player[0].immobile=0; - - - - donesomething=1; - } - - if(stripfx(consoletext[0], "tint ")||stripfx(consoletext[0], "Tint ")){ - int startpoint; - int alldone; - alldone=0; - startpoint=5; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - tintr=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - tintg=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - tintb=atof(mapname); - - donesomething=1; - } - - if(stripfx(consoletext[0], "sky tint ")||stripfx(consoletext[0], "Sky Tint ")){ - int startpoint; - int alldone; - alldone=0; - startpoint=9; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxr=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxg=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxb=atof(mapname); - - skyboxlightr=skyboxr; - skyboxlightg=skyboxg; - skyboxlightb=skyboxb; - - SetUpLighting(); - - //if(skyboxtexture){ - terrain.DoShadows(); - objects.DoShadows(); - /*} - else terrain.DoLighting(); - */ - donesomething=1; - } - - if(stripfx(consoletext[0], "sky light ")||stripfx(consoletext[0], "Sky Light ")){ - int startpoint; - int alldone; - alldone=0; - startpoint=10; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxlightr=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxlightg=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - skyboxlightb=atof(mapname); - - SetUpLighting(); - - //if(skyboxtexture){ - terrain.DoShadows(); - objects.DoShadows(); - /*} - else terrain.DoLighting(); - */ - donesomething=1; - } - - if(stripfx(consoletext[0], "skybox ")||stripfx(consoletext[0], "Skybox ")){ - skyboxtexture=1-skyboxtexture; - - SetUpLighting(); - //if(skyboxtexture){ - terrain.DoShadows(); - objects.DoShadows(); - /*} - else terrain.DoLighting(); - */ - donesomething=1; - } - - if(stripfx(consoletext[0], "protection ")||stripfx(consoletext[0], "Protection ")){ - int startpoint; - int alldone; - alldone=0; - startpoint=11; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - player[0].protectionhead=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - player[0].protectionhigh=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - player[0].protectionlow=atof(mapname); - - donesomething=1; - } - - if(stripfx(consoletext[0], "armor ")||stripfx(consoletext[0], "Armor ")){ - int startpoint; - int alldone; - alldone=0; - startpoint=6; - j=startpoint; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - player[0].armorhead=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; + cmd_dispatch(this, consoletext[0]); - player[0].armorhigh=atof(mapname); - - j++; - startpoint=j; - while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){ - mapname[j-startpoint]=consoletext[0][j]; - j++; - if(consoletext[0][j]=='\0')alldone=1; - } - mapname[j-startpoint]='\0'; - - player[0].armorlow=atof(mapname); - - donesomething=1; - } - - if(stripfx(consoletext[0], "protectionreset ")||stripfx(consoletext[0], "Protectionreset ")){ - for(i=0;i1) - for(i=1;i1) - for(i=1;i1) - for(i=1;i1) - for(i=1;i0){ for(k=14;k>=1;k--){ for(j=0;j<255;j++){ @@ -5264,12 +4182,6 @@ void Game::Tick() } consolechars[0]=0; consoleselected=0; - - if(!donesomething){ - PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true); - OPENAL_SetVolume(channels[consolefailsound], 256); - OPENAL_SetPaused(channels[consolefailsound], false); - } } } } diff --git a/Source/Models.cpp b/Source/Models.cpp index 5c09c61..e573423 100644 --- a/Source/Models.cpp +++ b/Source/Models.cpp @@ -424,7 +424,7 @@ void Model::UpdateVertexArrayNoTexNoNorm(){ } } -bool Model::loadnotex(char *filename ) +bool Model::loadnotex(const char *filename ) { FILE *tfile; long i; @@ -499,7 +499,7 @@ bool Model::loadnotex(char *filename ) } -bool Model::load(char *filename,bool texture ) +bool Model::load(const char *filename,bool texture ) { FILE *tfile; long i; @@ -587,7 +587,7 @@ bool Model::load(char *filename,bool texture ) return 1; } -bool Model::loaddecal(char *filename,bool texture ) +bool Model::loaddecal(const char *filename,bool texture ) { FILE *tfile; long i,j; diff --git a/Source/Models.h b/Source/Models.h index 02f319f..297b6e1 100644 --- a/Source/Models.h +++ b/Source/Models.h @@ -127,10 +127,10 @@ public: void UpdateVertexArray(); void UpdateVertexArrayNoTex(); void UpdateVertexArrayNoTexNoNorm(); - bool loadnotex(char *filename); + bool loadnotex(const char *filename); bool loadraw(char *filename); - bool load(char *filename,bool texture); - bool loaddecal(char *filename,bool texture); + bool load(const char *filename,bool texture); + bool loaddecal(const char *filename,bool texture); void Scale(float xscale,float yscale,float zscale); void FlipTexCoords(); void UniformTexCoords(); diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp index 18806a8..9bdd4ce 100644 --- a/Source/Skeleton.cpp +++ b/Source/Skeleton.cpp @@ -1136,12 +1136,12 @@ void Animation::Move(XYZ how) } } -void Skeleton::Load(char *filename, char *lowfilename, char *clothesfilename, - char *modelfilename, char *model2filename, - char *model3filename, char *model4filename, - char *model5filename, char *model6filename, - char *model7filename, char *modellowfilename, - char *modelclothesfilename, bool aclothes) +void Skeleton::Load(const char *filename, const char *lowfilename, const char *clothesfilename, + const char *modelfilename, const char *model2filename, + const char *model3filename, const char *model4filename, + const char *model5filename, const char *model6filename, + const char *model7filename, const char *modellowfilename, + const char *modelclothesfilename, bool aclothes) { static GLfloat M[16]; static int parentID; diff --git a/Source/Skeleton.h b/Source/Skeleton.h index 2948b1f..2e5085e 100644 --- a/Source/Skeleton.h +++ b/Source/Skeleton.h @@ -216,7 +216,7 @@ public: void FindRotationJoint(int which); void FindRotationJointSameTwist(int which); void FindRotationMuscle(int which, int animation); - void Load(char *fileName,char *lowfileName,char *clothesfileName,char *modelfileName,char *model2fileName,char *model3fileName,char *model4fileName,char *model5fileNamee,char *model6fileName,char *model7fileName,char *modellowfileName,char *modelclothesfileName, bool aclothes); + void Load(const char *fileName,const char *lowfileName,const char *clothesfileName,const char *modelfileName,const char *model2fileName,const char *model3fileName,const char *model4fileName,const char *model5fileNamee,const char *model6fileName,const char *model7fileName,const char *modellowfileName,const char *modelclothesfileName, bool aclothes); Skeleton(); -- 2.39.5