Bool function help.

No code help today but I am designing a turn based rpg game and have some effects where the effects only last until the start of their next turn or upon "being used up." an example of this is preparing a block action where the character gains extra armor until his next turn starts. I did a little messing with boolean functions but it didnt work. My main problem is that I want this to be a function. I'll show some examples of my code for help.

runcombat()
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
bool Combat::runCombat()
{
	introduceCharacters();

	const int entities = 7;

	Combatant combatants[entities];
	combatants[0] = fighter;
	combatants[1] = mage;
	combatants[2] = marksman;
	combatants[3] = assassin;
	combatants[4] = support;
	combatants[5] = tank;
	combatants[6] = blank;

	bool cbat = true;

	while (cbat == true)
	{
		int swapHolder;
		Combatant swapper;
		int end = entities;
		int length = entities;

		int position[entities] = { combatants[0]._speed, combatants[1]._speed, combatants[2]._speed, combatants[3]._speed, combatants[4]._speed, combatants[5]._speed, combatants[6]._speed };

		for (int counter = length - 1; counter > 0; counter--) {
			for (int index = 0; index < end; index++) {
				if (position[index] < position[index + 1]) {
					swapHolder = position[index + 1];
					swapper = combatants[index + 1];
					position[index + 1] = position[index];
					combatants[index + 1] = combatants[index];
					position[index] = swapHolder;
					combatants[index] = swapper;
				}
			}
		}

		cout << "Turn Order" << endl;
		cout << combatants[0]._name << endl;
		cout << combatants[1]._name << endl;
		cout << combatants[2]._name << endl;
		cout << combatants[3]._name << endl;
		cout << combatants[4]._name << endl;
		cout << combatants[5]._name << endl;

		for (int counter = 0; counter < 6; counter++) {
			cout << endl;
			cout << combatants[counter]._name << endl;
			switch (combatants[counter].pickAction())
			{
			case 1:
				combatants[counter].printStats();
				break;
			case 2:
				cout << "Please pick a target:" << endl;
				for (int target = 0; target < 6; target++) {
					cout << target << ")." << combatants[target]._name << "   " << combatants[target]._currentHealth << "/" << combatants[target]._health << endl;
				}
				int x;
				cin >> x;

				cout << "Please pick a weapon:" << endl;
				cout << "1)." << combatants[counter].wName1 << endl;
				cout << "2)." << combatants[counter].wName2 << endl;
				cout << "3)." << combatants[counter].wName3 << endl;

				int weaponSlot;
				cin >> weaponSlot;

				combatants[x]._currentHealth -= combatants[counter].attack(weaponSlot, combatants[x]);
				
				cout << combatants[x]._name << " has " << combatants[x]._currentHealth << " Health left!" << endl;
				break;
			case 3:
				combatants[counter].block();
				combatants[counter].printStats();
				break;
			}
		}

		return false;
	}
}


attack action
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
unsigned int Combatant::attack(int slot, Combatant target)
{
	bool MELEE;
	float ACCURACY;
	float RDAMAGE;
	float CRITICAL;
	float FIRESPEED;
	float STAMINACOST;
	float MANACOST;

	if (slot == 1) {
		MELEE = _melee1;
		if (MELEE == true) {
			ACCURACY = _mAccuracyDie1;
			RDAMAGE = _mDamageDie1;
			CRITICAL = _mCritChanceMod1;
			STAMINACOST = _mStaminaCost1;
		}
		else {
			ACCURACY = _rAccuracyDie1;
			RDAMAGE = _rDamageDie1;
			FIRESPEED = _rFireSpeed1;
			STAMINACOST = _rStaminaCost1;
			MANACOST = _rManaCost1;
		}
	}
	else if (slot == 2) {
		MELEE = _melee2;
		if (MELEE == true) {
			ACCURACY = _mAccuracyDie2;
			RDAMAGE = _mDamageDie2;
			CRITICAL = _mCritChanceMod2;
			STAMINACOST = _mStaminaCost2;
		}
		else {
			ACCURACY = _rAccuracyDie2;
			RDAMAGE = _rDamageDie2;
			FIRESPEED = _rFireSpeed2;
			STAMINACOST = _rStaminaCost2;
			MANACOST = _rManaCost2;
		}
	}
	else if (slot == 3) {
		MELEE = _melee3;
		if (MELEE == true) {
			ACCURACY = _mAccuracyDie3;
			RDAMAGE = _mDamageDie3;
			CRITICAL = _mCritChanceMod3;
			STAMINACOST = _mStaminaCost3;
		}
		else {
			ACCURACY = _rAccuracyDie3;
			RDAMAGE = _rDamageDie3;
			FIRESPEED = _rFireSpeed3;
			STAMINACOST = _rStaminaCost3;
			MANACOST = _rManaCost3;
		}
	} 
	else {
		cout << "Your attack has missed" << endl;
		return 0;
	}

	int aTotal;
	float dTotal;
	int iTotal;
	float cTotal;
	Dice ATTACK;
	Dice DAMAGE;
	Dice CRIT;

	int attackDiceResults = ATTACK.diceRoller(ACCURACY);
	

	aTotal = _mAccuracy + attackDiceResults;
	
	if (MELEE == true) {
		if (aTotal >= target._defense) {
			float damageDiceResults = DAMAGE.diceRoller(RDAMAGE);
			dTotal = _power + damageDiceResults;

			cTotal = _critChance + CRITICAL;
			float criticalConfirm = CRIT.diceRoller(100);
			if (criticalConfirm <= cTotal) {
				dTotal = dTotal * 2;
			}
			iTotal = dTotal - target._aArmor;
			cout << "This attack dealt" << iTotal << " damage!" << endl;
			return iTotal;
		}
		else {
			cout << "Your attack missed!" << endl;
			return 0;
		}
		
	}
	else {
		float ciTotal = 0;
		float holder[15];
		for (int counter = 0; counter < 15; counter++) {
			holder[counter] = 0;
		}

		for (int shots = 0; shots < FIRESPEED; shots++) {
			if (aTotal >= target._defense) {
				float damageDiceResults = DAMAGE.diceRoller(RDAMAGE);
				dTotal = damageDiceResults;

				cTotal = _critChance;
				float criticalConfirm = CRIT.diceRoller(100);
				if (criticalConfirm <= cTotal) {
					dTotal = dTotal * 2;
				}
				iTotal = dTotal - target._aArmor;

				if (iTotal > 0) {
					cout << "Shot " << shots << " dealt " << iTotal << " damage!" << endl;
					holder[shots] = iTotal;
				}
				else {
					cout << "Shot " << shots << " dealt 0 damage!" << endl;
				}
			}
			else {
				cout << "Shot " << shots << " has missed!" << endl;
			}
		}  
		return (holder[0] + holder[1] + holder[2] + holder[3] + holder[4] + holder[5] + holder[6] + holder[7] + holder[8] + holder[9] + holder[10] + holder[11] + holder[12] + holder[13] + holder[14]);
		int x = 0;
	}
}



the way i have it set up, the actions combatants make are an extension of the combatant class.
Topic archived. No new replies allowed.