Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/skill.c

Go to the documentation of this file.
00001 /* {{{
00002  * CalcRogue, a roguelike game for PCs, calculators and PDAs
00003  * Copyright (C) 2003 Jim Babcock
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * }}} */
00019 // skill.c
00022 
00023 #include "crogue.h"
00024 #define NUM_SKILL_LEVELS 10
00025 
00026 static int marks_to_advance(int skill_num);
00027 
00028 typedef struct skill_desc
00029 {
00030     const char *skill_name;
00031 } skill_desc;
00032 
00033 typedef struct skill_level_desc
00034 {
00035     schar hit_effect;
00036     schar damage_effect;
00037 } skill_level_desc;
00038 
00039 static skill_desc skill_descs[NUM_SKILLS+1] = {
00040         { ""                   },
00041         { gettext("bows")      },
00042         { gettext("crossbows") },
00043         { gettext("clubs")     },
00044         { gettext("daggers")   },
00045         { gettext("staves")    },
00046         { gettext("maces")     },
00047         { gettext("swords")    },
00048         { gettext("axes")      }
00049     };
00050 
00051 static skill_level_desc skill_levels[NUM_SKILL_LEVELS] = {
00052         { -3,  -3  },
00053         { -1,  -1, },
00054         { 0,   0,  },
00055         { 1,   0,  },
00056         { 2,   0,  },
00057         { 3,   1,  },
00058         { 5,   1,  },
00059         { 7,   2,  },
00060         { 9,   2,  },
00061         { 11,  3,  },
00062     };
00063 
00064 static int advancement_marks[NUM_SKILL_LEVELS] = {
00065         2,
00066         3,
00067         4,
00068         6,
00069         9,
00070         12,
00071         15,
00072         18,
00073         22,
00074         30
00075     };
00076 
00077 //{{{
00078 static int marks_to_advance(int skill_num)
00079 {
00080     int level = w->plr.skill[skill_num];
00081     
00082     return advancement_marks[level] * w->playerclasses[w->plr.class].weapon_skill_factor;
00083 }
00084 //}}}
00085 //{{{
00086 // Note: The currently-wielded weapon is special, so this must be called AFTER
00087 // inventory initialization
00088 void init_skills(void)
00089 {
00090     int i;
00091     for(i=0; i<=NUM_SKILLS; i++)
00092     {
00093         w->plr.skill_marks[i] = 0;
00094         w->plr.skill[i] = 0;
00095     }
00096     w->plr.skill[w->plr.extrinsic[STAT_WEAPON_TYPE]] = 2;
00097     for(i=0; i<=NUM_SKILLS; i++)
00098         w->plr.skill[i] += w->playerclasses[w->plr.class].weapon_skill_start;
00099 }
00100 //}}}
00101 //{{{
00102 void award_mark(void)
00103 {
00104     int skill_num = w->plr.extrinsic[STAT_WEAPON_TYPE];
00105     
00106     if(!skill_num) return;
00107     
00108     w->plr.skill_marks[skill_num]++;
00109     
00110     if(w->plr.skill_marks[skill_num] > marks_to_advance(skill_num) && w->plr.skill[skill_num] < NUM_SKILL_LEVELS)
00111     {
00112         message(gettext("You improve your skill with %s to level %i."), skill_descs[skill_num], ++w->plr.skill[skill_num]);
00113         w->plr.skill_marks[skill_num] = 0;
00114         update_player();
00115     }
00116 }
00117 //}}}
00118 //{{{
00119 sint weapon_skill_attack(void)
00120 {
00121     int skill_used = w->plr.extrinsic[STAT_WEAPON_TYPE];
00122     return skill_levels[w->plr.skill[skill_used]].hit_effect;
00123 }
00124 //}}}
00125 //{{{
00126 sint weapon_skill_damage(void)
00127 {
00128     int skill_used = w->plr.extrinsic[STAT_WEAPON_TYPE];
00129     return skill_levels[w->plr.skill[skill_used]].damage_effect;
00130 }
00131 //}}}
00132 //{{{
00133 void print_skills(char *buf)
00134 {
00135     int i;
00136     for(i=1; i<=NUM_SKILLS; i++)
00137         catprintf(buf, "%s\t%i\n", skill_descs[i].skill_name, w->plr.skill[i]);
00138 }
00139 //}}}
00140 

Generated on Thu May 20 13:12:11 2004 for CalcRogue by doxygen 1.3.6