extern float usermousesensitivity;
extern bool ismotionblur;
extern bool showdamagebar; // (des)activate the damage bar
-extern bool decals;
+extern bool decalstoggle;
extern bool skyboxtexture;
extern float skyboxr;
extern float skyboxg;
void Game::playdialoguescenesound()
{
XYZ temppos;
- temppos = Person::players[Dialog::currentScene().participantfocus]->coords;
+ temppos = Person::players.at(Dialog::currentScene().participantfocus)->coords;
temppos = temppos - viewer;
Normalise(&temppos);
temppos += viewer;
texdetail = temptexdetail;
}
-void Game::Loadlevel(int which)
+bool Game::LoadLevel(int which)
{
stealthloading = 0;
whichlevel = which;
if (which == -1) {
- Loadlevel("tutorial", true);
+ return LoadLevel("tutorial", true);
} else if (which >= 0 && which <= 15) {
char buf[32];
snprintf(buf, 32, "map%d", which + 1); // challenges
- Loadlevel(buf);
- } else
- Loadlevel("mapsave");
+ return LoadLevel(buf);
+ } else {
+ return LoadLevel("mapsave");
+ }
}
-void Game::Loadlevel(const std::string& name, bool tutorial)
+bool Game::LoadLevel(const std::string& name, bool tutorial)
{
+ const std::string level_path = Folders::getResourcePath("Maps/" + name);
+ if (!Folders::file_exists(level_path)) {
+ perror(std::string("LoadLevel: Could not open file '" + level_path).c_str());
+ return false;
+ }
+
int indemo; // FIXME this should be removed
int templength;
float lamefloat;
int mapvers;
FILE *tfile;
errno = 0;
- tfile = Folders::openMandatoryFile( Folders::getResourcePath("Maps/"+name), "rb" );
+ tfile = Folders::openMandatoryFile(level_path, "rb");
pause_sound(stream_firesound);
scoreadded = 0;
}
if (!stealthloading) {
- terrain.numdecals = 0;
+ terrain.decals.clear();
Sprite::deleteSprites();
for (int i = 0; i < subdivision; i++) {
for (int j = 0; j < subdivision; j++) {
- terrain.patchobjectnum[i][j] = 0;
+ terrain.patchobjects[i][j].clear();
}
}
Game::LoadingScreen();
funpackf(tfile, "Bi", &environment);
+ if (environment != oldenvironment)
+ Setenvironment(environment);
+ oldenvironment = environment;
+
Object::LoadObjectsFromFile(tfile, stealthloading);
if (mapvers >= 7) {
funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x, &mapcenter.y, &mapcenter.z, &mapradius);
SetUpLighting();
- if (environment != oldenvironment)
- Setenvironment(environment);
- oldenvironment = environment;
if (!stealthloading) {
Object::AddObjectsToTerrain();
oldmusicvolume[2] = 0;
oldmusicvolume[3] = 0;
- if (!firstload)
- firstload = 1;
-
leveltime = 0;
wonleveltime = 0;
visibleloading = false;
+
+ return true;
}
void doDevKeys()
//clip to terrain
Person::players[k]->coords.y = max(Person::players[k]->coords.y, terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z));
- for (int l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
- int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
+ for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
+ unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
if (Object::objects[i]->type != rocktype ||
Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled ||
Object::objects[i]->position.y > Person::players[k]->coords.y) {
lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5;
XYZ tempcoords1 = lowpoint;
whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
- if (whichhit != -1 && fabs(Object::objects[i]->model.facenormals[whichhit].y) < .3) {
+ if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
Person::players[k]->setTargetAnimation(walljumpleftanim);
emit_sound_at(movewhooshsound, Person::players[k]->coords);
if (k == 0)
pause_sound(whooshsound);
- lowpointtarget = DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[i]->yaw, 0);
+ lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
if (lowpointtarget.z < 0)
Person::players[k]->yaw = 180 - Person::players[k]->yaw;
lowpoint = tempcoords1;
lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5;
whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
- if (whichhit != -1 && fabs(Object::objects[i]->model.facenormals[whichhit].y) < .3) {
+ if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
Person::players[k]->setTargetAnimation(walljumprightanim);
emit_sound_at(movewhooshsound, Person::players[k]->coords);
if (k == 0)
pause_sound(whooshsound);
- lowpointtarget = DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[i]->yaw, 0);
+ lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
if (lowpointtarget.z < 0)
Person::players[k]->yaw = 180 - Person::players[k]->yaw;
lowpoint = tempcoords1;
lowpointtarget = lowpoint + Person::players[k]->facing * 2;
whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
- if (whichhit != -1 && fabs(Object::objects[i]->model.facenormals[whichhit].y) < .3) {
+ if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
Person::players[k]->setTargetAnimation(walljumpbackanim);
emit_sound_at(movewhooshsound, Person::players[k]->coords);
if (k == 0)
pause_sound(whooshsound);
- lowpointtarget = DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[i]->yaw, 0);
+ lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
if (lowpointtarget.z < 0)
Person::players[k]->yaw = 180 - Person::players[k]->yaw;
lowpoint = tempcoords1;
lowpointtarget = lowpoint - Person::players[k]->facing * 2;
whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
- if (whichhit != -1 && fabs(Object::objects[i]->model.facenormals[whichhit].y) < .3) {
+ if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
Person::players[k]->setTargetAnimation(walljumpfrontanim);
emit_sound_at(movewhooshsound, Person::players[k]->coords);
if (k == 0)
pause_sound(whooshsound);
- lowpointtarget = DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[i]->yaw, 0);
+ lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
if (lowpointtarget.z < 0)
Person::players[k]->yaw = 180 - Person::players[k]->yaw;
}
if (tempcollide)
- for (int l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
+ for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
lowpoint = Person::players[k]->coords;
lowpoint.y += 1.35;
lowpoint.y += (float)j / 13;
lowpointtarget = lowpoint + facing * 1.3;
flatfacing = Person::players[k]->coords;
- Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[k]->yaw, 0) * .01;
+ Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * .01;
Person::players[k]->coords.y = lowpointtarget.y - .07;
Person::players[k]->currentoffset = (flatfacing - Person::players[k]->coords) / Person::players[k]->scale;
}
emit_sound_at(jumpsound, Person::players[k]->coords, 128.);
- lowpointtarget = DoRotation(Object::objects[i]->model.facenormals[whichhit], 0, Object::objects[i]->yaw, 0);
+ lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
if (lowpointtarget.z < 0)
Person::players[k]->yaw = 180 - Person::players[k]->yaw;
Person::players[i]->skeleton.free &&
Person::players[i]->skeleton.longdead > 1000) {
Person::players[k]->animTarget = killanim;
- //TODO: refactor this out, what does it do?
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2)
- terrain.DeleteDecal(j);
- }
+ terrain.deleteDeadDecals();
for (unsigned int l = 0; l < Object::objects.size(); l++) {
- if (Object::objects[l]->model.type == decalstype)
- for (int j = 0; j < Object::objects[l]->model.numdecals; j++) {
- if ((Object::objects[l]->model.decaltype[j] == blooddecal ||
- Object::objects[l]->model.decaltype[j] == blooddecalslow) &&
- Object::objects[l]->model.decalalivetime[j] < 2)
- Object::objects[l]->model.DeleteDecal(j);
- }
+ if (Object::objects[l]->model.type == decalstype) {
+ Object::objects[l]->model.deleteDeadDecals();
+ }
}
}
if (!Person::players[i]->dead || musictype != 2)
Person::players[i]->skeleton.free) &&
(!Person::players[i]->dead || musictype != stream_fighttheme)) {
Person::players[k]->animTarget = dropkickanim;
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2) {
- terrain.DeleteDecal(j);
- }
- }
+ terrain.deleteDeadDecals();
for (unsigned int l = 0; l < Object::objects.size(); l++) {
- if (Object::objects[l]->model.type == decalstype)
- for (int j = 0; j < Object::objects[l]->model.numdecals; j++) {
- if ((Object::objects[l]->model.decaltype[j] == blooddecal ||
- Object::objects[l]->model.decaltype[j] == blooddecalslow) &&
- Object::objects[l]->model.decalalivetime[j] < 2) {
- Object::objects[l]->model.DeleteDecal(j);
- }
- }
+ if (Object::objects[l]->model.type == decalstype) {
+ Object::objects[l]->model.deleteDeadDecals();
+ }
}
}
}
hostile = 1;
}
- if (Person::players[Dialog::currentScene().participantfocus]->dead) {
+ if (Person::players.at(Dialog::currentScene().participantfocus)->dead) {
Dialog::indialogue = -1;
Dialog::directing = false;
cameramode = 0;
Person::players[i]->aitype == getweapontype ||
Person::players[i]->aitype == gethelptype ||
Person::players[i]->aitype == searchtype) &&
- !Person::players[i]->dead/*&&Person::players[i]->surprised<=0*/ &&
+ !Person::players[i]->dead &&
(Person::players[i]->animTarget != sneakattackedanim &&
Person::players[i]->animTarget != knifesneakattackedanim &&
Person::players[i]->animTarget != swordsneakattackedanim)) {
if (!Person::players[0]->dead && targetlevel != whichlevel)
startbonustotal = bonustotal;
- if (Person::players[0]->dead)
- Loadlevel(whichlevel);
- else
- Loadlevel(targetlevel);
+ LoadLevel(targetlevel);
fireSound();
loading = 3;
fireSound(firestartsound);
- Loadlevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
+ LoadLevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
fireSound();
loading = 2;
loadtime = 0;
targetlevel = 7;
- if (!firstload)
+ if (!firstLoadDone) {
LoadStuff();
+ }
whichchoice = 0;
actuallevel = campaignlevels[actuallevel].nextlevel.front();
visibleloading = true;
stillloading = 1;
- Loadlevel(campaignlevels[actuallevel].mapname.c_str());
+ LoadLevel(campaignlevels[actuallevel].mapname.c_str());
campaign = 1;
mainmenu = 0;
gameon = 1;
colviewer = viewer;
coltarget = cameraloc;
Object::SphereCheckPossible(&colviewer, findDistance(&colviewer, &coltarget));
- if (terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz])
- for (int j = 0; j < terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz]; j++) {
- int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
- colviewer = viewer;
- coltarget = cameraloc;
- if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1)
- viewer = col;
+ for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
+ unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
+ colviewer = viewer;
+ coltarget = cameraloc;
+ if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
+ viewer = col;
}
- if (terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz])
- for (int j = 0; j < terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz]; j++) {
- int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
- colviewer = viewer;
- if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
- viewer = colviewer;
- }
+ }
+ for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
+ unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
+ colviewer = viewer;
+ if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
+ viewer = colviewer;
}
+ }
cameradist = findDistance(&viewer, &target);
viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .6);
if (cameraloc.y < terrain.getHeight(cameraloc.x, cameraloc.z)) {