Rant

Pages: 1234
like I said already, only make the class and its methods(functions) don't do anything inside of
int main()
because then our code will likely be incompatible. Keep in mind the weapon class will be part of a bigger class so don't include things that isn't about the weapon.

How did you learn c++ so fast if you get so easily distracted?
Don't be distracted :P

When you work on the project don't get too easily distracted, keep the code solid :) You don't have to use much time on the class, but when you do make it count.
Last edited on
Because then I had set my mind to it, I wouldn't associate with anyone until my tutorials were complete and I knew what they meant.

After that, everything was just... "meh,".

Anywho I did not put anything in main. I didn't event write the main function...

The weapon class is actually no more than a C struct with a constructor that isn't really needed. Lol. It's just a safety check so I don't make a weapon object with uninitialized variables.

I'm sure I finished the weapon class so I'm going to work on the warrior class.
Last edited on by Fredbill30
no... Don't start working on warrior class. I am not done with armor. Post the code you have for weapon.
You need a constructor by the way. Also you need functions to change and access the variables. I'll show you the armor class when I have what I need. Remember though that this is all work in progress so it doesn't have to be all that complicated.
FredBill why are you so scared of showing some actual code? I have a feeling you haven't done anything...
Well seems as though it's too long to fit on here. Well that was a waste of time.

I'll just upload it to file dropper


EDIT: Here ya go. http://www.filedropper.com/mostlethalwarrior
Last edited on by Fredbill30
Omg. Use github for sources and don't include every file in archive. If you would delete debug information and object files, archive would be less that 1MB.

Also there is some very bad practice here: in sim.cpp Sim::input() is just too large.
And its content just asking to use factory pattern like that:
1
2
3
4
5
	cout << "	*Warrior 1 Long Range Weapon*\n";
	wr_LR[0] = WeaponFactory.createFromUserInput();
	cout << "	*Warrior 1 Medium Range Weapon*\n";
	wr_MR[0] = WeaponFactory.createFromUserInput();
	//etc... 


wr_name[0] is a char* and memory for it was not allocated before:
cin >> wr_Name[0]; cout << "\n";

warrior.cpp:
type.c_str() == "long" /facepalm
Also "else if" would work better in this case.

logic checking takes too much space. It is rare special case, so it is better to hide it:
1
2
3
4
5
6
7
if(wep == NULL)
{
	std::cout << "Failure to set weapon. Argument \"Weapon* wep\" == NULL";
	exit(1);
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓
assert(wep && "Failure to set weapon. Argument \"Weapon* wep\" == NULL")

You do not need to check for null, delete does it itself:
1
2
3
4
5
6
if(extra != NULL)
{
	delete extra;
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓
delete extra;

Weapon.h
:
Better to use 0 to indicate that weapon is melee (if there would be difference between 1-shot ranged and melee that will save you from need to rewrite code)
1
2
int capacity;  // - How many rounds the weapon can hold before reloading.
               // set to 1 if the weapon is melee. 

Warrior.h:
I even would not comment that part:
void setName(char* Name) {name = Name;}

bool ExtraWep; — not actually needed. nullptr in extra weapon will tell enough.
Last edited on
Looks like you did make something after all :P It was actually quite impressive. Why does the program abort after I hit a key? You have made it way too general for a weapons class. I think you should make an exclusively weapons class and a warrior class contains a weapon and an armor. My code is a little different, it would work better as an object of annother class. That is why I also have made a struct to hold the info about the gear before it is assigned to a warrior making it easier to use the same armor twice.

What my program is is not an attempt at the final thing of course, just a test to see if the armor is working.

armor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef ARMOR_H_
#define ARMOR_H_

#include <iostream>
#include <string>
using namespace std;
enum armor { head, chest, arms, legs };

struct CraftArmor {
	int AVOIDED[4];
	int DURABILITY[4];
	double WEIGHT;
	int CAMO;
	string NAME;
};

class Armor
{
private:
	int defenseRating; // calculated after the other variables are
	                   // entered.
	double weight; // in kg
	int camouflage; // % from 0 - 100
	int armorPieces[4]; // how many % does the pieces protect
	int armorDurability[4]; // hp of each individual part
	                        // 100 is the best possible normal humans
	                        // will use. (a robot suit would be more)
	string name;
public:
	Armor(const CraftArmor & armor)
	{
		for(int i = 0; i < 4; i++)
			armorPieces[i] = armor.AVOIDED[i];
		for(int i = 0; i < 4; i++)
			armorDurability[i] = armor.DURABILITY[i];
		weight = armor.WEIGHT;
		camouflage = armor.CAMO;
		name = armor.NAME;
	}

	Armor(int a[], int b[], double w=0, int camo=0, string nm = "not specified")
	{
		for(int i = 0; i < 4; i++)
			armorPieces[i] = a[i];
		for(int i = 0; i < 4; i++)
			armorDurability[i] = b[i];
		weight = w;
		camouflage = camo;
		name = nm;
	}
	Armor() // no armor
	{
		int a[4] = { 0 };
		int b[4] = { 0 };
		double w=0;
		int camo=0;

		for(int i = 0; i < 4; i++)
			armorPieces[i] = a[i];
		for(int i = 0; i < 4; i++)
			armorDurability[i] = b[i];
		weight = w;
		camouflage = camo;
		name = "no armor";
	}

	Armor(bool manual)
	{
		cout << "What is the name of the armor?\nname: ";
		cin >> name;

		cout << "How heavy is the armor? (kilograms)\nweight: "; 
		cin >> weight;

		cout << "How good is the camouflage? 0% no camo, 100% invisible\ncamo: "; 
		cin >> camouflage;

		string pieces[4] = { "head", "chest", "arms", "legs" };
		cout << "What is the % of damage avoided each attack\n"
			<<  "and how good is the durability of the armor?\n";
		for(int i = 0; i < 4; i++)
		{
			cout << "avoided, " << pieces[i] << ": ";
			cin >> armorPieces[i];
			cout << "durability, " << pieces[i] << ": ";
			cin >> armorDurability[i];
		}

	}

	void updateDefenseRating() // this is an average of the pieces 
		                     // of armor. Its only use will be get
							 // the overall defense.
	{
		defenseRating = 0;
		if(noDefenseLeft())
			defenseRating = 0;
		else
		{
			for(int i = 0; i < 4; i++)
				defenseRating += armorPieces[i];
			for(int i = 0; i < 4; i++)
				defenseRating += armorDurability[i];
			defenseRating += camouflage;
			defenseRating /= 9; // find the overall average!
		}
	}

	void showDefenseRating()
	{
		updateDefenseRating();
		cout << "Defense rating of the warrior: " << defenseRating
		     << endl;
	}

	int returnDefenseRating() { return defenseRating; }

	void updateArmor()
	{
		updateDefenseRating();
		if(armorDurability[head] == 0 && armorDurability[chest] == 0
			&& armorDurability[arms] == 0 && armorDurability[legs] == 0) 
		{ weight = 0; camouflage = 0; updateDefenseRating(); } // armor is destroyed
	}

	int armorDamaged(int attackDamage, int part)
	{
		int damageAvoided = 0;
		if(armorDurability[part] > 0 && armorPieces[part] > 0)
		{
			damageAvoided += attackDamage * float(armorPieces[part])/100.0;
			armorDurability[part] -= damageAvoided;
			// the design could be better, the % of damage blocked doesn't decrease as 
			// the armor gets damaged. This is not that important to have now
			// and can be added in the future.
		}

		if(0 <= attackDamage - damageAvoided) // returns the attack damage left after 
			                                 // damage avoided is subtracted.
			return attackDamage - damageAvoided;
		else
			return 0;
	}

	void Show()
	{
		updateArmor();
		cout << "Name: " << name << endl;
		cout << "Defense rating: " << defenseRating << endl;
		cout << "Weight: " << weight << endl << endl;
		if(!noDefenseLeft())
		{
			cout << "(percent of damage avoided, durability):\n"; // head, chest, arms, legs
			cout << "Head: (" <<  armorPieces[head] << ", " << armorDurability[head] << ")\n";
			cout << "Chest: (" <<  armorPieces[chest] << ", " << armorDurability[chest] << ")\n";
			cout << "Arms: (" <<  armorPieces[arms] << ", " << armorDurability[arms] << ")\n";
			cout << "Legs: (" <<  armorPieces[legs] << ", " << armorDurability[legs] << ")\n";
		}
		else
			cout << "No armor\n";
	}

	bool noDefenseLeft()
	{
		return (armorDurability[head] == 0 && armorDurability[chest]  == 0
			&& armorDurability[arms] == 0 && armorDurability[legs] == 0);
	}
};

#endif 



And the main() is just to see if the armor works like it is supposed to :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// WarriorsSimulation.cpp : Defines the entry point for the console application.
//

#include "armor.h"
#include <windows.h>

void TestArmor(Armor & a,int n)
{
	cout << "\n\nArmor simulation\n\n"; // not really that much of a sim :P
	cout << "Damage done to head: " << a.armorDamaged(n, head) << endl;
	cout << "Damage done to chest: " << a.armorDamaged(n, chest) << endl;
	cout << "Damage done to arms: " << a.armorDamaged(n, arms) << endl;
	cout << "Damage done to legs: " << a.armorDamaged(n, legs) << endl;
}


int main()
{

	CraftArmor temporaryArmor = { 0, 15, 5, 5,
					  0, 15, 5, 10,
					  5.5, 25, 
					  "leather armor" };

	Armor leather(temporaryArmor);

	while(!leather.noDefenseLeft())
	{
		leather.Show();
		TestArmor(leather, 20);
	}
	leather.Show();
	cin.get();
	return 0;
}
Last edited on
don't forget about like shields, accuracy , dodging , someone falling off a cliff , vehicles , weather condition , wild animals coming from behind to eat them , sink holes, snake bites , twisting ankle on rocks , stepping on a trap( landmine) , tripping....ect
I'm currently in the process of making a simulation where people shoot at each other but I only have a couple of factors and it's still kind of a pain.
My factors are accuracy , position to shoot in , and position to get shot in.
Last edited on
wild animals coming from behind to eat them , sink holes, ... stepping on a trap( landmine) , tripping....ect

But it's a simulation... Not a death arena...

Also, am I correct in assuming that you guys are going for the medieval type, so the warriors won't be using as technology advanced weaponry and equipment as today?
Well on that show they have modern groups also. And simulations would take into consideration environmental factors I thought? The more factors the more accurate the simulation would be.
Last edited on
Are you simulating that the warriors are fighting in some field with tall grass or forest that happens to have brittle ground below fraught with deadly traps and mindless carnivores, all the while next to a cliff?

Even if you make the simulation change the environment for each test run, each environment is more suited to some bloody battle in some adrenaline-filled war and not a contest between warriors.

That is... If FredBill and Filiprei are simulating a duel among warriors instead of a death arena... I could be wrong, and those virtual beings are doomed.
My program and Fred's program aren't very compatible, he have already made his program it looks like. If any of you want to develop the program I am making along sided with me just say it. Like I already said many times we are just making something simple to start with. Adding a couple of extra factors shouldn't be a problem and if it is the program is not made very well. The program needs a weapon class, environment class, warrior class(to hold the weapon and armor class), etc.
don't forget about like shields, accuracy , dodging , someone falling off a cliff , vehicles , weather condition , wild animals coming from behind to eat them , sink holes, snake bites , twisting ankle on rocks , stepping on a trap( landmine) , tripping....ect


accuracy should be part of weapon. Only one that can potentially be part of the armor class is shield. Giblit if you want to you can make a class for something and we can combine them to make one big simulation. Just make sure you don't make something that is hard to implement as an object of the warrior class. The environment also needs to communicate with the warrior class in some way.
Is this an invitation for a collaboration? You could set up the project on github (cloud service for programs).


accuracy should be part of weapon. Only one that can potentially be part of the armor class is shield

Accuracy should be with the wielder, no? Unlike games, weapons do not increase accuracy (unless it has a scope).


The environment also needs to communicate with the warrior class in some way.

I would think an interface class or an event class could manage the interactions, so you don't couple two unrelated classes.

Also, you should make sure you and FredBill use the same measurement units. :3
My program and Fred's program aren't very compatible
That is because you didn't design interfaces and behaviors first. So each of you develop his own program right now.

he have already made his program it looks like
It have some severe bugs. And there is problems with architecture as whole.

Your program have less problems: only encapsulation and design problems.
Your program would benefit from factory pattern as well (it will remove dependensy of your class on std::cin and will lower amount of code in class)
BTW, define operator== for your armor class and do: std::cout << (Armor() == false);

accuracy should be part of weapon
Depends on simulation logic.
In D&D chance to hit depends on wielder, AC of defender and a litle from veapon bonus (does not matter in most cases)
Last edited on
My point was that I didn't leave out any variables. (or at least very few) I did set up a project on github but I have broblems understanding how it works. If anyone want to set up a project on github I will gladly join, I don't have any plans on finishing this program if no one wants to join.

It have some severe bugs. And there is problems with architecture as whole.

He has still tried to make his program so it is impossible to use my class in his program.

Anyways, my vision is making a sim that is easy to modify and add classes, which can include classes for realism elements and also classes with new features. There is a limit to how realistic a simulation can be so it is better not to add too many factors if it isn't crucial(to start with). If anyone is interested in making something similar to this we can join forces :P

EDIT:
MiiNiPaa, not sure what you meant with defining == operator so that I can compare to bool. If what you mean is to check if armor is destroyed or not this should do the job:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool operator==(bool x)
	{
		if(noDefenseLeft() == true)
		{
			return (x == false);
		}
		else
			return (x == true);
	}

	friend bool operator==(bool x, Armor a)
	{
		return (a == x);
	}
Last edited on
From the website:
-Next to repository name is a small page symbol for creating a new file
-Within each file on the top right corner there is an edit button
-All changes must be "commited" via the commit button at the bottom in order for the changes to occur

From gitub software:
-All files can be edited as usual, i.e. with an IDE or text-editor like notepad
-All changes must also be committed but with the additional syncing in order to match up files on the github database and the computer syncing

I can add Gilbit, FredBill, and others if they wish to join.
Last edited on
Daleth what do you want to make? Also is there some chat on the website? We really need a chat to figure things out.
Possibly tomorrow I'm watching movie then bed
Pages: 1234