along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
*/
-/**> HEADER FILES <**/
-#include "Animation/Animation.h"
-#include "Audio/openal_wrapper.h"
-#include "Audio/Sounds.h"
-#include "Level/Awards.h"
-#include "Objects/Weapons.h"
+#include "Objects/Weapons.hpp"
-#include "Game.h"
+#include "Animation/Animation.hpp"
+#include "Audio/openal_wrapper.hpp"
+#include "Audio/Sounds.hpp"
+#include "Game.hpp"
+#include "Level/Awards.hpp"
+#include "Tutorial.hpp"
extern float multiplier;
extern Terrain terrain;
extern float texdetail;
extern GLubyte bloodText[512 * 512 * 3];
extern int bloodtoggle;
-extern Objects objects;
extern bool autoslomo;
extern float camerashake;
extern float woozy;
extern float viewdistance;
extern float blackout;
extern bool freeze;
-extern int tutoriallevel;
extern int numthrowkill;
Model Weapon::throwingknifemodel;
}
}
-void Weapon::DoStuff(int i)
+/* Load weapons models and textures */
+void Weapon::Load()
+{
+ LOG("Loading weapon data...");
+
+ knifetextureptr.load("Textures/Knife.png", 0);
+ bloodknifetextureptr.load("Textures/BloodKnife.png", 0);
+ lightbloodknifetextureptr.load("Textures/BloodKnifeLight.png", 0);
+ swordtextureptr.load("Textures/Sword.jpg", 1);
+ bloodswordtextureptr.load("Textures/SwordBlood.jpg", 1);
+ lightbloodswordtextureptr.load("Textures/SwordBloodLight.jpg", 1);
+ stafftextureptr.load("Textures/Staff.jpg", 1);
+
+ throwingknifemodel.load("Models/ThrowingKnife.solid");
+ throwingknifemodel.Scale(.001, .001, .001);
+ throwingknifemodel.Rotate(90, 0, 0);
+ throwingknifemodel.Rotate(0, 90, 0);
+ throwingknifemodel.flat = 0;
+ throwingknifemodel.CalculateNormals(1);
+
+ swordmodel.load("Models/Sword.solid");
+ swordmodel.Scale(.001, .001, .001);
+ swordmodel.Rotate(90, 0, 0);
+ swordmodel.Rotate(0, 90, 0);
+ swordmodel.Rotate(0, 0, 90);
+ swordmodel.flat = 1;
+ swordmodel.CalculateNormals(1);
+
+ staffmodel.load("Models/Staff.solid");
+ staffmodel.Scale(.005, .005, .005);
+ staffmodel.Rotate(90, 0, 0);
+ staffmodel.Rotate(0, 90, 0);
+ staffmodel.Rotate(0, 0, 90);
+ staffmodel.flat = 1;
+ staffmodel.CalculateNormals(1);
+}
+
+void Weapon::doStuff(int i)
{
- //~ cout << position.x << "," << position.y << "," << position.z << "|" << tippoint.x << "," << tippoint.y << "," << tippoint.z << endl;
static int whichpatchx, whichpatchz, whichhit;
static XYZ start, end, colpoint, normalrot, footvel, footpoint;
static XYZ terrainnormal;
static XYZ closestswordpoint;
static float tempmult;
+ if (multiplier <= 0) {
+ return;
+ }
+
if (owner != -1) {
oldowner = owner;
}
whichpatchx = position.x / (terrain.size / subdivision * terrain.scale);
whichpatchz = position.z / (terrain.size / subdivision * terrain.scale);
if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
- if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are objects where the weapon is
+ if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are Object::objects where the weapon is
for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) { // check for collision
int k = terrain.patchobjects[whichpatchx][whichpatchz][j];
start = oldtippoint;
end = tippoint;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
- if (objects.type[k] == treetrunktype) {
- objects.model[k].MakeDecal(breakdecal, DoRotation(colpoint - objects.position[k], 0, -objects.yaw[k], 0), .1, 1, Random() % 360);
- normalrot = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0);
+ if (Object::objects[k]->type == treetrunktype) {
+ Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .1, 1, Random() % 360);
+ normalrot = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0);
velocity = 0;
if (type == knife)
position = colpoint - normalrot * .1;
Person::players[j]->jointVel(neck) += velocity * 2;
Person::players[j]->jointVel(rightshoulder) += velocity * 2;
Person::players[j]->jointVel(leftshoulder) += velocity * 2;
- if (bloodtoggle && tutoriallevel != 1)
+ if (bloodtoggle && !Tutorial::active)
Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
- if (tutoriallevel == 1)
+ if (Tutorial::active)
Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .8, .3);
footvel = tippoint - position;
Normalise(&footvel);
- if (bloodtoggle && tutoriallevel != 1)
+ if (bloodtoggle && !Tutorial::active)
Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * -1, 1, 0, 0, .6, 1);
- if (tutoriallevel != 1) {
+ if (!Tutorial::active) {
if (Person::players[j]->weaponstuckwhere == 0)
Person::players[j]->DoBloodBig(2, 205);
if (Person::players[j]->weaponstuckwhere == 1)
if (type == staff) {
start = tippoint - (position - tippoint) / 5;
end = position + (position - tippoint) / 30;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
XYZ diff;
diff = (colpoint - position);
} else {
start = position - (tippoint - position) / 5;
end = tippoint + (tippoint - position) / 30;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
XYZ diff;
diff = (colpoint - tippoint);
start = oldposition;
end = position;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
hitsomething = 1;
position = colpoint;
- terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+ terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
ReflectVector(&velocity, &terrainnormal);
position += terrainnormal * .002;
}
start = oldtippoint;
end = tippoint;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
hitsomething = 1;
tippoint = colpoint;
- terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+ terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
ReflectVector(&tipvelocity, &terrainnormal);
tippoint += terrainnormal * .002;
}
}
- if ((objects.type[k] != boxtype && objects.type[k] != platformtype && objects.type[k] != walltype && objects.type[k] != weirdtype) || objects.pitch[k] != 0)
+ if ((Object::objects[k]->type != boxtype && Object::objects[k]->type != platformtype && Object::objects[k]->type != walltype && Object::objects[k]->type != weirdtype) || Object::objects[k]->pitch != 0)
for (int m = 0; m < 2; m++) {
mid = (position * (21 + (float)m * 10) + tippoint * (19 - (float)m * 10)) / 40;
oldmid2 = mid;
start = oldmid;
end = mid;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
hitsomething = 1;
mid = colpoint;
- terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+ terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
ReflectVector(&velocity, &terrainnormal);
bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal)));
start = oldmid;
end = mid;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
hitsomething = 1;
mid = colpoint;
- terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+ terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
ReflectVector(&tipvelocity, &terrainnormal);
bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal)));
else {
start = position;
end = tippoint;
- whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
if (whichhit != -1) {
hitsomething = 1;
closestdistance = -1;
- closestswordpoint = colpoint; //(position+tippoint)/2;
- point[0] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]], 0, objects.yaw[k], 0) + objects.position[k];
- point[1] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]], 0, objects.yaw[k], 0) + objects.position[k];
- point[2] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]], 0, objects.yaw[k], 0) + objects.position[k];
+ closestswordpoint = colpoint;
+ point[0] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 0), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+ point[1] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 1), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+ point[2] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 2), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
if (DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance, &colpoint )) {
if (distance < closestdistance || closestdistance == -1) {
closestpoint = colpoint;
//Move
int i = 0;
for (std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
- weapon->DoStuff(i++);
+ weapon->doStuff(i++);
}
}
-void Weapon::Draw()
+void Weapon::draw()
{
static XYZ terrainlight;
static GLfloat M[16];
glDepthMask(1);
for (std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
- weapon->Draw();
+ weapon->draw();
}
return 0;
}
Weapons::Weapons()
{
}
-
-Weapons::~Weapons()
-{
- Weapon::stafftextureptr.destroy();
- Weapon::knifetextureptr.destroy();
- Weapon::lightbloodknifetextureptr.destroy();
- Weapon::bloodknifetextureptr.destroy();
- Weapon::swordtextureptr.destroy();
- Weapon::lightbloodswordtextureptr.destroy();
- Weapon::bloodswordtextureptr.destroy();
-}
-