D&D Power Calculator Source Code
I've only include the main .cpp and one of the header files here. There are a few other support files used for the calculations.
damage.h
//damage.h
/*
contains calculations for damage bonuses (die rolls will be
calculated in powers.h/powers.cpp). Copies vector from file.h
loadFile to use for bonus values as determined by stats.txt file.
*/
#ifndef DAMAGE_H_
#define DAMAGE_H_
#include "attacks.h"
class damage //class damage
{
public:
damage();
~damage();
//melee damage
int fullMain(); // strmod+weap_enhance+elad_sold+twf
int fullMainCrit();
int fullOffhand();
int fullOffhandCrit();
int twoFullMain(); // 2d[W] + strmod+weap_enhance+elad_sold+twf
int twoFullOffhand(); //2d[W] + strmod+weap2_enhance+elad_sold
int twoFullMainCrit();
int twoFullOffhandCrit();
int nomodMain(); // weap_enhance+elad_sold+twf
int nomodOffhand(); // weap_enhance2+elad_sold
int nomodMainCrit(); // weap_enhance+elad_sold+twf
int nomodOffhandCrit(); // weap_enhance2+elad_sold
int twoNomodMain(); // 2d[W] + weap_enhance+elad_sold+twf
int twoNomodOffhand(); //2d[W] + weap2_enhance+elad_sold
int twoNomodMainCrit();
int twoNomodOffhandCrit();
//ranged damage
int fullRanged(); // dexmod+bow_enhance
int nomodRanged(); // bow_enhance
int fullRangedCrit();
int nomodRangedCrit();
//extra damage
int huntersQuarry(); //1d8 if target is marked as quarry
int quickHit(); //1d6 if using 2 attacks and both hit
int wis();//grants access for powers to use wismod value
private:
//stat and weapon mods
int strmod;
int dexmod;
int wismod;
int weap_enhance;
int weap2_enhance;
int ranged_enhance;
int elad_sold;
int twf;
//weapon die values
int weap_die;
int weap2_die;
int ranged_die;
int bonus;
};
#endif
//accessors and mutators
damage::damage() //initialize attack variables from file vector
{
vector < int > v;
loadFile(v); //copy vector from loadFile
strmod = v[0];
dexmod = v[2];
wismod = v[4];
weap_enhance = v[10];
weap2_enhance = v[11];
ranged_enhance = v[12];
elad_sold = v[13];
twf = v[14];
weap_die = v[15];
weap2_die = v[16];
ranged_die = v[17];
bonus = 0;
}
damage::~damage()//destructor
{
}
int damage::wis()
{
int wisdom = wismod;
return wisdom;
}
int damage::huntersQuarry()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(8);
cout << "Hunter's Quarry Damage: " << die_val << endl;
return die_val;
}
int damage::quickHit()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(6);
cout <<"Quickhit Damage: " << die_val << endl;
return die_val;
}
int damage::fullMain()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap_die);
int total = 0;
bonus = strmod+elad_sold+weap_enhance+twf;
cout <<"Main Die Roll (1d" << weap_die <<"): " << die_val<< endl;
total = die_val+bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::fullOffhand()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap2_die);
int total = 0;
bonus = strmod+elad_sold+weap2_enhance;
cout <<"Offhand Die Roll (1d" << weap2_die <<"): " << die_val<< endl;
total = die_val+bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::fullMainCrit()
{
int total = weap_die;
bonus = strmod+elad_sold+weap_enhance+twf;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::fullOffhandCrit()
{
int total = weap2_die;
bonus = strmod+elad_sold+weap2_enhance;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::twoFullMain()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap_die);
int die2_val = newDice.die_Roller(weap_die);
int total = 0;
bonus = strmod+elad_sold+weap_enhance+twf;
cout <<"Main Die Roll (1d" << weap_die <<"): " << die_val<< endl;
cout <<"2nd Main Die Roll (1d" << weap_die <<"): " << die2_val<< endl;
total = die_val+die2_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::twoFullOffhand()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap2_die);
int die2_val = newDice.die_Roller(weap2_die);
int total = 0;
bonus = strmod+elad_sold+weap_enhance;
cout <<"Offhand Die Roll (1d" << weap2_die <<"): " << die_val<< endl;
cout <<"2nd Offhand Die Roll (1d" << weap2_die <<"): " << die2_val<< endl;
total = die_val+die2_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::twoFullMainCrit()
{
int total = (weap_die*2);
bonus = strmod+elad_sold+weap_enhance+twf;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::twoFullOffhandCrit()
{
int total = (weap2_die *2);
bonus = strmod+elad_sold+weap_enhance;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::nomodMain()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap_die);
int total = 0;
bonus = elad_sold+weap2_enhance+twf;
cout <<"Main Die Roll (1d" << weap_die <<"): " << die_val<< endl;
total = die_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::nomodOffhand()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap2_die);
int total = 0;
bonus = elad_sold+weap_enhance;
cout <<"Offhand Die Roll (1d" << weap2_die <<"): " << die_val<< endl;
total = die_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::nomodMainCrit()
{
int total = weap_die;
bonus = elad_sold+weap2_enhance+twf;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::nomodOffhandCrit()
{
int total = weap2_die;
bonus = elad_sold+weap_enhance;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::twoNomodMain()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap_die);
int die2_val = newDice.die_Roller(weap_die);
int total = 0;
bonus = elad_sold+weap_enhance+twf;
cout <<"Main Die Roll (1d" << weap_die <<"): " << die_val<< endl;
cout <<"2nd Main Die Roll (1d" << weap_die <<"): " << die2_val<< endl;
total = die_val+die2_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::twoNomodOffhand()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(weap2_die);
int die2_val = newDice.die_Roller(weap2_die);
int total = 0;
bonus = elad_sold+weap_enhance;
cout <<"Offhand Die Roll (1d" << weap2_die <<"): " << die_val<< endl;
cout <<"2nd Offhand Die Roll (1d" << weap2_die <<"): " << die2_val<< endl;
total = die_val+die2_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::twoNomodMainCrit()
{
int total = weap_die;
bonus = elad_sold+weap_enhance+twf;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::twoNomodOffhandCrit()
{
int total = (weap2_die*2);
bonus = elad_sold+weap_enhance;
total += bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::fullRanged()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(ranged_die);
int total = 0;
bonus = dexmod+ranged_enhance;
cout <<"Ranged Die Roll (1d" << ranged_die <<"): " << die_val << endl;
total = die_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::nomodRanged()
{
dice_roller newDice;//load dice object
int die_val = newDice.die_Roller(ranged_die);
int total = 0;
bonus = ranged_enhance;
cout <<"Ranged Die Roll (1d" << ranged_die <<"): " << die_val << endl;
total = die_val+bonus; //total attack value
cout <<"Total Damage: " << total << endl << endl;
return total;
}
int damage::fullRangedCrit()
{
int total = ranged_die;
bonus = dexmod+ranged_enhance;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
int damage::nomodRangedCrit()
{
int total = ranged_die;
bonus = ranged_enhance;
total += bonus; //total damage value
cout <<"Total Damage: " << total << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED
|BACKGROUND_INTENSITY);
cout <<"Add extra damage from weapon crit bonus" ;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
cout << endl;
return total;
}
main.cpp
//main.cpp
/*
Features needed:
-Graphical Interface
-Better Class implimentation
*/
#include iostream
#include ctime
#include "powers.h"
int main()
{
dice_roller newDie; //create object for dice roller
//these chars are initialized before there while loops so they
//reset when that option is chosen again
char mPower; //melee power
char rPower; //ranged power
char type; //attack type (melee or ranged)
//initialize chars used in if's and main option selection
char option = ' '; //main option choice (attack or roll die)
char mBasic = ' '; //melee basic
char rBasic = ' '; //ranged basic
//vars for die roller section
int value = 0;
int die = 0;
int num_die = 1;
//create seed for random numbers based off internal clock
srand(unsigned (time(NULL)));
while (option != 'q' && option != 'Q')//die roller or attack calculator
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN
|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
cout <<"Are you making a Die Roll or an Attack?" << endl;
cout <<"(D)ie roll, (A)ttack, (Q)uit: ";
cin >> option;
system("cls");
switch(option)
{
//make an attack
case 'a':
case 'A':
type = ' ';
while(type != 'q' && type != 'Q')//ranged or melee attacks
{
cout <<"Are you making a Ranged or Melee Attack?" << endl;
cout <<"(M)elee, (R)anged, or (Q)uit: ";
cin >> type;
system("cls");
switch(type)
{
//Melee Attack Options
case 'm':
case 'M':
mPower = ' ';
//choose melee power
while(mPower != 'q' && mPower != 'Q')
{
cout <<"What Melee Power would you like to use?"
<< endl;
cout <<"-(B)asic Attack\n-(T)win Strike\n-(H)it
and Run\n-Dire (W)olverine Strike\n-(J)aws of
the Wolf \n-(D)isruptive Strike\n-Two Wolf
(P)ounce\n-(C)laws of the Griffon\n-(Q)uit"
<< endl;
cout <<"Power: ";
cin >> mPower;
cout << endl;
switch(mPower)
{
//basic attack
case 'b':
case 'B': system ("cls");
cout <<"Using (M)ain Weapon or
(O)ffand Weapon? ";
cin >> mBasic;
if(mBasic == 'm' ||
mBasic == 'M')
basic_Main();
else if(mBasic == 'o' ||
mBasic == 'O')
basic_Offhand();
else
cout <<"Invalid Input"
<< endl;
break;
//Twin Strike
case 't':
case 'T': system ("cls");
twinStrikeMelee();
break;
//Hit and Run
case 'h':
case 'H': system ("cls");
Hit_Run();
break;
//Dire Wolverine Strike
case 'w':
case 'W': system ("cls");
direWolverine();
break;
//Jaws of the Wolf
case 'j':
case 'J': system ("cls");
JawsoftheWolf();
break;
//Disruptive Strike
case 'd':
case 'D': system ("cls");
disruptMelee();
break;
//Two-Wolf Pounce
case 'p':
case 'P': system ("cls");
TwoWolfPounce();
break;
//Claws of the Griffon
case 'c':
case 'C': system("cls");
GriffonClaw();
break;
//back to attack type selection
case 'q':
case 'Q': system ("cls");
mPower = 'q';
break;
default: system ("cls");
cout <<"Invalid Input"
<< endl;
}
}
break;
//Ranged attack options
case 'r':
case 'R':
rPower = ' ';
//choose ranged power
while(rPower != 'q' && rPower != 'Q')
{
cout <<"What Ranged Power would you like to
use?" << endl;
cout <<"-(B)asic Attack\n-(T)win
Strike \n-(D)isruptive Strike\n-(Q)uit"
<< endl;
cout <<"Power: ";
cin >> rPower;
cout << endl;
switch(rPower)
{
//Basic attack
case 'b':
case 'B': system ("cls");
basic_Ranged();
break;
//Twin Strike
case 't':
case 'T': system ("cls");
twinStrikeRanged();
break;
//Disruptive Strike
case 'd':
case 'D': system ("cls");
disruptRanged();
break;
//Back to attack type selection
case 'q':
case 'Q': system ("cls");
rPower = 'q';
break;
default: system ("cls");
cout <<"Invalid Input"
<< endl;
}
}
break;
//Back to attack or die roll selection
case 'q':
case 'Q':
break;
}
}
break;
//roll dice
case 'd':
case 'D':
cout <<"Choose your die:" << endl;
cout <<"d(4)\nd(6)\nd(8)\nd(10)\nd(12)\nd(20)" << endl;
cout <<"Die: ";
cin >> die;
cout <<"\nHow many dice?: ";
cin >> num_die;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY);
for(int i = 0; i < num_die; i++)
{
switch(die)
{
case 4: value = newDie.d4();
cout << value<< endl;
break;
case 6: value = newDie.d6();
cout << value<< endl;
break;
case 8: value = newDie.d8();
cout << value<< endl;
break;
case 10: value = newDie.d10();
cout << value<< endl;
break;
case 12: value = newDie.d12();
cout << value<< endl;
break;
case 20: value = newDie.d20();
cout << value<< endl;
break;
default: cout <<"Invalid Input" << endl;
break;
}
}
break;
//Quit program
case 'q':
case 'Q':
break;
}
}
return 0;
}