int study_cost(struct unit *u, skill_t sk) { if (sk == SK_MAGIC) { static int config; static int cost; /* Die Magiekosten betragen 50+Summe(50*Stufe) */ /* 'Stufe' ist dabei die naechste zu erreichende Stufe */ if (config_changed(&config)) { cost = config_get_int("skills.cost.magic", 50); } if (cost > 0) { int next_level = 1 + (u ? get_level(u, sk) : 0); return cost * (1 + ((next_level + next_level * next_level) / 2)); } return cost; } return skill_cost(sk); }
/* * Increase your skills by spending experience points */ extern bool gain_skills(void) { int i; int row = 7; int col = 42; int skill = 0; int old_base[S_MAX]; int skill_gain[S_MAX]; int old_new_exp = p_ptr->new_exp; int total_cost = 0; //int old_csp = p_ptr->csp; //int old_msp = p_ptr->msp; char ch; char buf[80]; bool accepted; int tab = 0; // hack global variable skill_gain_in_progress = TRUE; /* save the old skills */ for (i = 0; i < S_MAX; i++) old_base[i] = p_ptr->skill_base[i]; /* initialise the skill gains */ for (i = 0; i < S_MAX; i++) skill_gain[i] = 0; /* Interact */ while (1) { // reset the total cost total_cost = 0; /* Process skills */ for (i = 0; i < S_MAX; i++) { /* Total cost */ total_cost += skill_cost(old_base[i], skill_gain[i]); } // set the new experience pool total p_ptr->new_exp = old_new_exp - total_cost; /* Restrict cost */ if (p_ptr->new_exp < 0) { /* Warning */ bell("Excessive skills!"); /* Reduce stat */ skill_gain[skill]--; /* Recompute costs */ continue; } /* Calculate the bonuses */ p_ptr->update |= (PU_BONUS); /* Set the redraw flag for everything */ p_ptr->redraw |= (PR_EXP | PR_BASIC); /* update the skills */ for (i = 0; i < S_MAX; i++) { p_ptr->skill_base[i] = old_base[i] + skill_gain[i]; } /* Update stuff */ update_stuff(); /* Update voice level */ //if (p_ptr->msp == 0) p_ptr->csp = 0; //else p_ptr->csp = (old_csp * p_ptr->msp) / old_msp; /* Display the player */ display_player(0); /* Display the costs header */ if (!character_dungeon) { if (p_ptr->new_exp >= 10000) tab = 0; else if (p_ptr->new_exp >= 1000) tab = 1; else if (p_ptr->new_exp >= 100) tab = 2; else if (p_ptr->new_exp >= 10) tab = 3; else tab = 4; strnfmt(buf, sizeof(buf), "%6d", p_ptr->new_exp); c_put_str(TERM_L_GREEN, buf, row - 2, col + 30); c_put_str(TERM_WHITE, "Points Left:", row - 2, col + 17 + tab); } /* Display the costs */ for (i = 0; i < S_MAX; i++) { byte attr = (i == skill) ? TERM_L_BLUE : TERM_L_WHITE; /* Display cost */ strnfmt(buf, sizeof(buf), "%6d", skill_cost(old_base[i], skill_gain[i])); c_put_str(attr, buf, row + i, col + 30); } /* Special Prompt? */ if (character_dungeon) { Term_putstr(QUESTION_COL + 38 + 2, INSTRUCT_ROW + 1, -1, TERM_SLATE, "ESC abort skill increases "); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL + 38 + 2, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "ESC"); } /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Arrow keys allocate points to skills"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, " Enter accept current values"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Arrow keys"); Term_putstr(QUESTION_COL + 5, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Enter"); /* Get key */ hide_cursor = TRUE; ch = inkey(); hide_cursor = FALSE; /* Quit (only if haven't begun game yet) */ if (((ch == 'Q') || (ch == 'q')) && (turn == 0)) quit(NULL); /* Done */ if ((ch == '\r') || (ch == '\n')) { accepted = TRUE; break; } /* Abort */ if (ch == ESCAPE) { p_ptr->new_exp = old_new_exp; for (i=0; i<S_MAX; i++) p_ptr->skill_base[i] = old_base[i]; //p_ptr->csp = old_csp; accepted = FALSE; break; } /* Prev skill */ if (ch == '8') { skill = (skill + S_MAX - 1) % S_MAX; } /* Next skill */ if (ch == '2') { skill = (skill + 1) % S_MAX; } /* Decrease skill */ if ((ch == '4') && (skill_gain[skill] > 0)) { skill_gain[skill]--; } /* Increase stat */ if (ch == '6') { skill_gain[skill]++; } } // reset hack global variable skill_gain_in_progress = FALSE; /* Calculate the bonuses */ p_ptr->update |= (PU_BONUS); /* Update stuff */ update_stuff(); /* Done */ return (accepted); }