Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- //Comparison function for bsearch
- int cmpfunc(const void * a,
- const void * b) {
- // return ( *(int*)a - *(int*)b );
- return strcmp((char * ) a, (char * ) b);
- }
- //SPECIAL is your character's base stats that affect your initial skill points, weapon handling, and other gameplay elements.
- struct Special {
- int strength;
- int perception;
- int endurance;
- int charisma;
- int intelligence;
- int agility;
- int luck;
- };
- //Skills affect weapon handling and gameplay elements.
- struct Skills {
- int barter;
- int enerWeap;
- int explosives;
- int guns;
- int lockpick;
- int medicine;
- int meleeWeap;
- int repair;
- int science;
- int sneak;
- int speech;
- int survival;
- int unarmed;
- };
- struct Special c1;
- struct Skills s1;
- //Skill list names in string
- char skillList[13][30] = {
- "barter",
- "energy weapons",
- "explosives",
- "guns",
- "lockpick",
- "medicine",
- "melee weapons",
- "repair",
- "science",
- "sneak",
- "speech",
- "survival",
- "unarmed"
- };
- int main() {
- //Initialize SPECIAL
- c1.strength = 1;
- c1.perception = 1;
- c1.endurance = 1;
- c1.charisma = 1;
- c1.intelligence = 1;
- c1.agility = 1;
- c1.luck = 1;
- int totSpec = 61; //Max possible SPECIAL for FNV
- int minSpec = 40; //Min possible SPECIAL for FNV
- int charSpec = 0; //Your character's SPECIAL
- while ((charSpec > totSpec) || (charSpec < minSpec)) {
- //Get SPECIAL
- //Note SPECIAL values are between 1 and 10
- //Strength
- printf("Strength: ");
- scanf("%d", & (c1.strength));
- while ((c1.strength < 1) || (c1.strength > 10)) { //Boundary checker; repeat until within boundaries. Same for all SPECIAL values
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nStrength: ");
- scanf("%d", & (c1.strength));
- }
- charSpec += c1.strength;
- //Perception
- printf("\nPerception: ");
- scanf("%d", & (c1.perception));
- while ((c1.perception < 1) || (c1.perception > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nPerception: ");
- scanf("%d", & (c1.perception));
- }
- charSpec += c1.perception;
- //Endurance
- printf("\nEndurance: ");
- scanf("%d", & (c1.endurance));
- while ((c1.endurance < 1) || (c1.endurance > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nEndurance: ");
- scanf("%d", & (c1.endurance));
- }
- charSpec += c1.endurance;
- //Charisma
- printf("\nCharisma: ");
- scanf("%d", & (c1.charisma));
- while ((c1.charisma < 1) || (c1.charisma > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nCharisma: ");
- scanf("%d", & (c1.charisma));
- }
- charSpec += c1.charisma;
- //Intelligence
- printf("\nIntelligence: ");
- scanf("%d", & (c1.intelligence));
- while ((c1.intelligence < 1) || (c1.intelligence > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nIntelligence: ");
- scanf("%d", & (c1.intelligence));
- }
- charSpec += c1.intelligence;
- //Agility
- printf("\nAgility: ");
- scanf("%d", & (c1.agility));
- while ((c1.agility < 1) || (c1.agility > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nAgility: ");
- scanf("%d", & (c1.agility));
- }
- charSpec += c1.agility;
- //Luck
- printf("\nLuck: ");
- scanf("%d", & (c1.luck));
- while ((c1.luck < 1) || (c1.luck > 10)) {
- printf("\nInvalid entry. Please enter a number between 1 and 10.\nPerception: ");
- scanf("%d", & (c1.luck));
- }
- charSpec += c1.luck;
- while ((charSpec > totSpec) || (charSpec < minSpec)) { //If your character SPECIAL is out of bounds
- char stat = 'S';
- printf("Please change one of the following so that the total is less than %d and greater than %d.\n\n", totSpec, minSpec);
- printf("Strength: %d\nPerception: %d\nEndurance: %d\nCharisma: %d\nIntelligence: %d\nAgility: %d\nLuck %d\n\n", c1.strength, c1.perception, c1.endurance, c1.charisma, c1.intelligence, c1.agility, c1.luck);
- if (charSpec < minSpec) {
- printf("Total: %d, please add %d point(s) to the stats.\n", charSpec, minSpec - charSpec); //If under
- }
- if (charSpec > totSpec) {
- printf("Total: %d, please remove %d point(s) to the stats.\n", charSpec, charSpec - totSpec); //If over
- }
- getchar(); //Absorbs newline
- printf("Enter the stat you wish to change. (S, P, E, C, I, A, L): "); //Enter SPECIAL char to change it
- stat = getchar();
- while ((stat != 'S') && (stat != 'P') && (stat != 'E') && (stat != 'C') && (stat != 'I') && (stat != 'A') && (stat != 'L')) { //If not one of the letters shown; should add lowercase.
- printf("\nInvalid entry. Please enter one of the following letters: S, P, E, C, I, A, L\n");
- getchar();
- stat = getchar();
- }
- if (stat == 'S') {
- charSpec -= c1.strength; //Removes existing stat from total
- printf("Strength: ");
- scanf("%d", & (c1.strength));
- charSpec += c1.strength; //Adds new stat value to total
- printf("\n");
- } else if (stat == 'P') {
- charSpec -= c1.perception;
- printf("Perception: ");
- scanf("%d", & (c1.perception));
- charSpec += c1.perception;
- printf("\n");
- } else if (stat == 'E') {
- charSpec -= c1.endurance;
- printf("Endurance: ");
- scanf("%d", & (c1.endurance));
- charSpec += c1.endurance;
- printf("\n");
- } else if (stat == 'C') {
- charSpec -= c1.charisma;
- printf("Charisma: ");
- scanf("%d", & (c1.charisma));
- charSpec += c1.charisma;
- printf("\n");
- } else if (stat == 'I') {
- charSpec -= c1.intelligence;
- printf("Intelligence: ");
- scanf("%d", & (c1.intelligence));
- charSpec += c1.intelligence;
- printf("\n");
- } else if (stat == 'A') {
- charSpec -= c1.agility;
- printf("Agility: ");
- scanf("%d", & (c1.agility));
- charSpec += c1.agility;
- printf("\n");
- } else if (stat == 'L') {
- charSpec -= c1.luck;
- printf("Luck: ");
- scanf("%d", & (c1.luck));
- charSpec += c1.luck;
- printf("\n");
- }
- if ((charSpec >= minSpec) && (charSpec <= totSpec)) {
- break; //If within bounds, break.
- }
- }
- }
- printf("\n");
- int minLevel = 1 + (charSpec - 20) / 2; //Mostly unused code snippet, may reuse.
- int tagSkills = 3; //Tag skills are initial skills you have that raise those skills by 15 points. You can have 3-4 Tag skills, 4 starting at level 5.
- printf("Skills: Barter, Energy Weapons, Explosives, Guns, Lockpick, Medicine, Melee Weapons, Repair, Science, Sneak, Speech, Survival.\n\n");
- if (minLevel >= 5) {
- int response;
- printf("Please choose whether you want 3 or 4 tag skills (as in, if your character has the Tag! perk or not).\n");
- scanf("%d", & response);
- while ((response != 3) && (response != 4)) {
- printf("Invalid response. Please enter either 3 or 4. \n");
- scanf("%d", & response);
- }
- if (response == 4) {
- tagSkills++; //If your character DOES decide to take on the 4th tag skill, this adds one to the number of tag skills.
- }
- }
- //Initializes skill points.
- s1.barter = skillPoints(c1.charisma);
- s1.enerWeap = skillPoints(c1.perception);
- s1.explosives = skillPoints(c1.perception);
- s1.guns = skillPoints(c1.agility);
- s1.lockpick = skillPoints(c1.perception);
- s1.medicine = skillPoints(c1.intelligence);
- s1.meleeWeap = skillPoints(c1.strength);
- s1.repair = skillPoints(c1.intelligence);
- s1.science = skillPoints(c1.intelligence);
- s1.sneak = skillPoints(c1.agility);
- s1.speech = skillPoints(c1.charisma);
- s1.survival = skillPoints(c1.endurance);
- s1.unarmed = skillPoints(c1.endurance);
- getchar();
- char ts1[30]; //Holders
- char ts2[30];
- char ts3[30];
- char ts4[30];
- int skill = 0;
- while (skill != 1) {
- printf("\nEnter first tag skill: ");
- char skillName[30];
- gets(skillName);
- strcpy(ts1, skillName);
- skill = cmpskill(skillName); //Checks to see if the typed skill is valid. If it isn't, it is set to 0, if it is, it's set to 1.
- tagSkillInc(skillName, 15);
- if (skill == 0) {
- printf("Invalid response.");
- }
- if (skill == 1) {
- break;
- }
- }
- skill = 0;
- while (skill != 1) {
- printf("\nEnter second tag skill: ");
- char skillName[30];
- gets(skillName);
- int cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 2); //Checks to see if it was already typed before it.
- while (cmp == 0) { //It's 0 because one out of one will match before it.
- printf("\nYou've already entered that skill. Please enter a different skill: ");
- gets(skillName);
- cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 2);
- }
- strcpy(ts2, skillName);
- skill = cmpskill(skillName);
- tagSkillInc(skillName, 15); //Adds 15 to the tag skill.
- if (skill == 0) {
- printf("Invalid response.");
- }
- if (skill == 1) {
- break;
- }
- }
- skill = 0;
- while (skill != 1) {
- printf("\nEnter third tag skill: ");
- char skillName[30];
- gets(skillName);
- int cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 3);
- while (cmp == 1) {
- printf("\nYou've already entered that skill. Please enter a different skill: ");
- gets(skillName);
- cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 3);
- }
- strcpy(ts3, skillName);
- skill = cmpskill(skillName);
- tagSkillInc(skillName, 15);
- if (skill == 0) {
- printf("Invalid response.");
- }
- if (skill == 1) {
- break;
- }
- }
- if (tagSkills == 4) { //If 4 tag skills.
- skill = 0;
- while (skill != 1) {
- printf("\nEnter fourth tag skill: ");
- char skillName[30];
- gets(skillName);
- int cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 4);
- while (cmp == 2) {
- printf("\nYou've already entered that skill. Please enter a different skill: ");
- gets(skillName);
- cmp = cmptag(skillName, ts1, ts2, ts3, ts4, 4);
- }
- strcpy(ts4, skillName);
- skill = cmpskill(skillName);
- tagSkillInc(skillName, 15);
- if (skill == 0) {
- printf("Invalid response.");
- }
- if (skill == 1) {
- break;
- }
- }
- }
- printf("\nEnter character level (make it make sense for your given SPECIAL): "); //Character level has to make sense for a given SPECIAL
- int lvl;
- scanf("%d", & lvl); //What level you want your character to be
- int minLvl = minLvlCalc(lvl);
- while ((lvl < 1) || (lvl > 50)) {
- printf("Invalid entry. Please enter a number between 1 and 50."); //50 is the level cap in the game.
- printf("\nLevel: ");
- scanf("%d", & lvl);
- }
- while (minLvl > lvl) {
- printf("Your SPECIAL doesn't make sense for your character level. Please enter something more realistic.");
- printf("\nLevel: ");
- scanf("%d", & lvl);
- }
- int educ = 0;
- if (minLvl >= 4) {
- char yn;
- while ((yn != 'Y') && (yn != 'y') && (yn != 'N') && (yn != 'n')) {
- printf("\nWould you like to take the Educated perk? (Y/N) "); //Educated perk gives two extra skill points per level. May have minimum intelligence requirement I have to add in.
- getchar();
- scanf("%c", & yn);
- getchar();
- if ((yn == 'Y') || (yn == 'y')) {
- educ = 2;
- } else if ((yn == 'N') || (yn == 'n')) {
- educ = 0;
- } else {
- printf("\nInvalid response.\n");
- }
- }
- }
- printSkills(); //Prints your skills.
- int totPoint = totPoints(educ, lvl); //Available skill points given your intelligence, luck, and level.
- while (totPoint > 0) { //Until total points hit 0, keep looping this section
- printf("\nYou have %d points remaining", totPoint);
- printf("\nSelect how many points you want to add to a skill: "); //Backwards because it makes the code easier. This part breaks if you type a char in here on accident.
- int pointSelect;
- scanf("%d", & pointSelect);
- while ((totPoint - pointSelect < 0) || (pointSelect < 0) || (pointSelect > 100)) { //Don't drop below 0, type a number above 100, or a negative number
- printf("\nInvalid entry.\n");
- printf("\nSelect how many points you want to add to a skill: ");
- scanf("%d", & pointSelect);
- }
- char selectSkill[30];
- printf("To which skill would you like to add this to? "); //Which skill do you want to add that many points to?
- getchar();
- gets(selectSkill);
- while (cmpskill(selectSkill) != 1) {
- printf("\nInvalid response.\n");
- printf("To which skill would you like to add this to? ");
- gets(selectSkill);
- }
- int inc = tagSkillInc(selectSkill, pointSelect);
- totPoint -= pointSelect;
- totPoint += inc;
- printSkills();
- }
- printf("\n\n YOUR SPECIAL \n"); //Prints your SPECIAL
- printf("_________________________\n");
- printf("STR: %d\n", c1.strength);
- printf("PER: %d\n", c1.perception);
- printf("END: %d\n", c1.endurance);
- printf("CHA: %d\n", c1.charisma);
- printf("INT: %d\n", c1.intelligence);
- printf("AGL: %d\n", c1.agility);
- printf("LCK: %d\n", c1.luck);
- printSkills();
- }
- void printSkills(void) { //Prints your skills
- printf("\n YOUR SKILLS \n");
- printf("____________________________\n");
- printf("Barter | %d\n", s1.barter);
- printf("Energy Weapons | %d\n", s1.enerWeap);
- printf("Explosives | %d\n", s1.explosives);
- printf("Guns | %d\n", s1.guns);
- printf("Lockpick | %d\n", s1.lockpick);
- printf("Medicine | %d\n", s1.medicine);
- printf("Melee Weapons | %d\n", s1.meleeWeap);
- printf("Repair | %d\n", s1.repair);
- printf("Science | %d\n", s1.science);
- printf("Sneak | %d\n", s1.sneak);
- printf("Speech | %d\n", s1.speech);
- printf("Survival | %d\n", s1.survival);
- printf("Unarmed | %d\n\n", s1.unarmed);
- }
- int skillPoints(int stat) { //Skill equation
- int skill = 2 + (2 * stat) + ceil((float) c1.luck / 2); //Each skill has an associated stat that determines its initial value.
- return skill;
- }
- int cmpskill(char skillName[30]) { //Checks to see if the typed skill is valid
- char * item;
- for (int i = 0; i < 30; i++) {
- skillName[i] = tolower(skillName[i]);
- }
- item = (char * ) bsearch(skillName, skillList, 13, sizeof(char) * 30, cmpfunc); //bsearch must be in ascending order bsearch(&key,values,sizeoflist,bytesperelement,comparisonfunction)
- if (item != NULL) { //bsearch returns nullptr if it didn't find anything, and something if it does.
- return 1;
- }
- if (item == NULL) {
- return 0;
- }
- }
- int cmptag(char comparison[30], char ts1[30], char ts2[30], char ts3[30], char ts4[30], int index) {
- int cmp = 0;
- for (int i = 0; i < 30; i++) { //Checks to see if element has been typed before through strcmps.
- comparison[i] = tolower(comparison[i]);
- }
- if (index == 2) {
- cmp += abs(strcmp(comparison, ts1));
- }
- if (index == 3) {
- cmp += abs(strcmp(comparison, ts1));
- cmp += abs(strcmp(comparison, ts2));
- }
- if (index == 4) {
- cmp += abs(strcmp(comparison, ts1));
- cmp += abs(strcmp(comparison, ts2));
- cmp += abs(strcmp(comparison, ts3));
- }
- return cmp;
- }
- int tagSkillInc(char skillName[30], int inc) { //Adds values to skills.
- for (int i = 0; i < 30; i++) {
- skillName[i] = tolower(skillName[i]);
- }
- int placeHolder; //Placeholder, as name suggests.
- if (strcmp(skillName, "barter") == 0) {
- s1.barter += inc;
- if (s1.barter > 100) { //If your value is over 100, return the difference and set it equal to 100.
- placeHolder = s1.barter;
- s1.barter = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "energy weapons") == 0) {
- s1.enerWeap += inc;
- if (s1.enerWeap > 100) {
- placeHolder = s1.enerWeap;
- s1.enerWeap = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "explosives") == 0) {
- s1.explosives += inc;
- if (s1.explosives > 100) {
- placeHolder = s1.explosives;
- s1.explosives = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "guns") == 0) {
- s1.guns += inc;
- if (s1.guns > 100) {
- placeHolder = s1.guns;
- s1.guns = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "lockpick") == 0) {
- s1.lockpick += inc;
- if (s1.lockpick > 100) {
- placeHolder = s1.lockpick;
- s1.lockpick = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "medicine") == 0) {
- s1.medicine += inc;
- if (s1.medicine > 100) {
- placeHolder = s1.medicine;
- s1.medicine = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "melee weapons") == 0) {
- s1.meleeWeap += inc;
- if (s1.meleeWeap > 100) {
- placeHolder = s1.meleeWeap;
- s1.meleeWeap = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "repair") == 0) {
- s1.repair += inc;
- if (s1.repair > 100) {
- placeHolder = s1.repair;
- s1.repair = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "science") == 0) {
- s1.science += inc;
- if (s1.science > 100) {
- placeHolder = s1.science;
- s1.science = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "sneak") == 0) {
- s1.sneak += inc;
- if (s1.sneak > 100) {
- placeHolder = s1.sneak;
- s1.sneak = 100;
- return s1.sneak - 100;
- }
- }
- if (strcmp(skillName, "speech") == 0) {
- s1.speech += inc;
- if (s1.speech > 100) {
- placeHolder = s1.sneak;
- s1.speech = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "survival") == 0) {
- s1.survival += inc;
- if (s1.survival > 100) {
- placeHolder = s1.survival;
- s1.survival = 100;
- return placeHolder - 100;
- }
- }
- if (strcmp(skillName, "unarmed") == 0) {
- s1.unarmed += inc;
- if (s1.unarmed > 100) {
- placeHolder = s1.unarmed;
- s1.unarmed = 100;
- return placeHolder - 100;
- }
- }
- }
- int minLvlCalc(int lvl) {
- int spec = c1.strength + c1.perception + c1.endurance + c1.charisma + c1.intelligence + c1.agility + c1.luck;
- int minLvl;
- if ((spec > 40) && (spec < 45)) { //Sensible level amounts for a given SPECIAL total.
- minLvl = 10;
- }
- if ((spec >= 45) && (spec < 50)) {
- minLvl = 20;
- }
- if ((spec >= 50) && (spec < 55)) {
- minLvl = 30;
- }
- if ((spec >= 55) && (spec <= 61)) {
- minLvl = 40;
- }
- return minLvl;
- }
- int totPoints(int educ, int lvl) { //Total available skill points to add given your level and intelligence and whether or not you have the Educated perk.
- int pointTotal = 0;
- if (c1.intelligence % 2 == 0) {
- pointTotal = lvl * (10 + c1.intelligence / 2 + educ);
- }
- if (c1.intelligence % 2 == 1) {
- if (lvl % 2 == 0) {
- pointTotal = (lvl / 2) * (10 + c1.intelligence / 2 + educ) + (lvl / 2) * (10 + c1.intelligence / 2 + 1 + educ);
- }
- if (lvl % 2 == 1) {
- pointTotal = (lvl / 2) * (10 + c1.intelligence / 2 + educ) + (lvl / 2) * (10 + c1.intelligence / 2 + 1 + educ) + (10 + c1.intelligence / 2 + educ);
- }
- }
- return pointTotal;
- }
- //Add option for skill books (increases by 3 or 4, based on perks you take). Change SPECIAL mechancics to manually enter perks to manipulate.
Add Comment
Please, Sign In to add comment