ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/exp.C
(Generate patch)

Comparing deliantra/server/common/exp.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.2 by root, Tue Aug 29 08:01:35 2006 UTC

1/* 1/*
2 * static char *rcsid_arch_c = 2 * static char *rcsid_arch_c =
3 * "$Id: exp.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: exp.C,v 1.2 2006/08/29 08:01:35 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
33 33
34#define TRUE 1 34#define TRUE 1
35#define FALSE 0 35#define FALSE 0
36 36
37float exp_att_mult[NROFATTACKS+2] = { 37float exp_att_mult[NROFATTACKS+2] = {
38 0.0, /* AT_PHYSICAL */ 38 0.0, /* AT_PHYSICAL */
39 0.0, /* AT_MAGIC */ 39 0.0, /* AT_MAGIC */
40 0.0, /* AT_FIRE */ 40 0.0, /* AT_FIRE */
41 0.0, /* AT_ELECTRICITY */ 41 0.0, /* AT_ELECTRICITY */
42 0.0, /* AT_COLD */ 42 0.0, /* AT_COLD */
43 0.0, /* AT_WATER *//*AT_CONFUSION!*/ 43 0.0, /* AT_WATER *//*AT_CONFUSION!*/
44 0.4, /* AT_ACID */ 44 0.4, /* AT_ACID */
45 1.5, /* AT_DRAIN */ 45 1.5, /* AT_DRAIN */
46 0.0, /* AT_WEAPONMAGIC */ 46 0.0, /* AT_WEAPONMAGIC */
47 0.1, /* AT_GHOSTHIT */ 47 0.1, /* AT_GHOSTHIT */
48 0.3, /* AT_POISON */ 48 0.3, /* AT_POISON */
49 0.2, /* AT_DISEASE */ 49 0.2, /* AT_DISEASE */
50 0.3, /* AT_PARALYZE */ 50 0.3, /* AT_PARALYZE */
51 0.0, /* AT_TURN_UNDEAD */ 51 0.0, /* AT_TURN_UNDEAD */
52 0.0, /* AT_FEAR */ 52 0.0, /* AT_FEAR */
53 0.0, /* AT_CANCELLATION */ 53 0.0, /* AT_CANCELLATION */
54 0.0, /* AT_DEPLETE */ 54 0.0, /* AT_DEPLETE */
55 0.0, /* AT_DEATH */ 55 0.0, /* AT_DEATH */
56 0.0, /* AT_CHAOS */ 56 0.0, /* AT_CHAOS */
57 0.0 /* AT_COUNTERSPELL */ 57 0.0 /* AT_COUNTERSPELL */
58}; 58};
59 59
60float exp_prot_mult[NROFATTACKS+2] = { 60float exp_prot_mult[NROFATTACKS+2] = {
61 0.4, /* AT_PHYSICAL */ 61 0.4, /* AT_PHYSICAL */
62 0.5, /* AT_MAGIC */ 62 0.5, /* AT_MAGIC */
63 0.1, /* AT_FIRE */ 63 0.1, /* AT_FIRE */
64 0.1, /* AT_ELECTRICITY */ 64 0.1, /* AT_ELECTRICITY */
65 0.1, /* AT_COLD */ 65 0.1, /* AT_COLD */
66 0.1, /* AT_WATER */ 66 0.1, /* AT_WATER */
67 0.1, /* AT_ACID */ 67 0.1, /* AT_ACID */
68 0.1, /* AT_DRAIN */ 68 0.1, /* AT_DRAIN */
69 0.1, /* AT_WEAPONMAGIC */ 69 0.1, /* AT_WEAPONMAGIC */
70 0.1, /* AT_GHOSTHIT */ 70 0.1, /* AT_GHOSTHIT */
71 0.1, /* AT_POISON */ 71 0.1, /* AT_POISON */
72 0.1, /* AT_DISEASE */ 72 0.1, /* AT_DISEASE */
73 0.1, /* AT_PARALYZE */ 73 0.1, /* AT_PARALYZE */
74 0.1, /* AT_TURN_UNDEAD */ 74 0.1, /* AT_TURN_UNDEAD */
75 0.1, /* AT_FEAR */ 75 0.1, /* AT_FEAR */
76 0.0, /* AT_CANCELLATION */ 76 0.0, /* AT_CANCELLATION */
77 0.0, /* AT_DEPLETE */ 77 0.0, /* AT_DEPLETE */
78 0.0, /* AT_DEATH */ 78 0.0, /* AT_DEATH */
79 0.0, /* AT_CHAOS */ 79 0.0, /* AT_CHAOS */
80 0.0 /* AT_COUNTERSPELL */ 80 0.0 /* AT_COUNTERSPELL */
81 81
82}; 82};
83 83
84/* 84/*
85 * new_exp() is an alternative way to calculate experience based 85 * new_exp() is an alternative way to calculate experience based
87 * It's far from perfect, and doesn't consider everything which 87 * It's far from perfect, and doesn't consider everything which
88 * can be considered, thus it's only used in debugging. 88 * can be considered, thus it's only used in debugging.
89 * this is only used with one of the dumpflags, 89 * this is only used with one of the dumpflags,
90 * and not anyplace in the code. 90 * and not anyplace in the code.
91 */ 91 */
92 92
93int new_exp(const object *ob) { 93int new_exp(const object *ob) {
94 double att_mult, prot_mult, spec_mult; 94 double att_mult, prot_mult, spec_mult;
95 double exp; 95 double exp;
96 int i; 96 int i;
97 long mask = 1; 97 long mask = 1;
106 */ 106 */
107 prot_mult += (exp_prot_mult[i] * 200*ob->resist[i]) / 100.0; 107 prot_mult += (exp_prot_mult[i] * 200*ob->resist[i]) / 100.0;
108 } 108 }
109 spec_mult += (0.3*(QUERY_FLAG(ob,FLAG_SEE_INVISIBLE)!= FALSE)) + 109 spec_mult += (0.3*(QUERY_FLAG(ob,FLAG_SEE_INVISIBLE)!= FALSE)) +
110 (0.5*(QUERY_FLAG(ob,FLAG_SPLITTING)!= FALSE))+ 110 (0.5*(QUERY_FLAG(ob,FLAG_SPLITTING)!= FALSE))+
111 (0.3*(QUERY_FLAG(ob,FLAG_HITBACK)!= FALSE)) + 111 (0.3*(QUERY_FLAG(ob,FLAG_HITBACK)!= FALSE)) +
112 (0.1*(QUERY_FLAG(ob,FLAG_REFL_MISSILE)!= FALSE)) + 112 (0.1*(QUERY_FLAG(ob,FLAG_REFL_MISSILE)!= FALSE)) +
113 (0.3*(QUERY_FLAG(ob,FLAG_REFL_SPELL)!= FALSE)) + 113 (0.3*(QUERY_FLAG(ob,FLAG_REFL_SPELL)!= FALSE)) +
114 (1.0*(QUERY_FLAG(ob,FLAG_NO_MAGIC)!= FALSE)) + 114 (1.0*(QUERY_FLAG(ob,FLAG_NO_MAGIC)!= FALSE)) +
115 (0.1*(QUERY_FLAG(ob,FLAG_PICK_UP)!= FALSE)) + 115 (0.1*(QUERY_FLAG(ob,FLAG_PICK_UP)!= FALSE)) +
116 (0.1*(QUERY_FLAG(ob,FLAG_USE_SCROLL)!= FALSE)) + 116 (0.1*(QUERY_FLAG(ob,FLAG_USE_SCROLL)!= FALSE)) +
117 (0.2*(QUERY_FLAG(ob,FLAG_USE_RANGE)!= FALSE)) + 117 (0.2*(QUERY_FLAG(ob,FLAG_USE_RANGE)!= FALSE)) +
118 (0.1*(QUERY_FLAG(ob,FLAG_USE_BOW)!= FALSE)); 118 (0.1*(QUERY_FLAG(ob,FLAG_USE_BOW)!= FALSE));
119 119
120 exp = (ob->stats.maxhp<5) ? 5 : ob->stats.maxhp; 120 exp = (ob->stats.maxhp<5) ? 5 : ob->stats.maxhp;
121 exp *= (QUERY_FLAG(ob,FLAG_CAST_SPELL) && has_ability(ob)) 121 exp *= (QUERY_FLAG(ob,FLAG_CAST_SPELL) && has_ability(ob))
122 ? (40+(ob->stats.maxsp>80?80:ob->stats.maxsp))/40 : 1; 122 ? (40+(ob->stats.maxsp>80?80:ob->stats.maxsp))/40 : 1;
123 exp *= (80.0/(70.0+ob->stats.wc)) * (80.0/(70.0+ob->stats.ac)) * (50.0+ob->stats.dam)/50.0; 123 exp *= (80.0/(70.0+ob->stats.wc)) * (80.0/(70.0+ob->stats.ac)) * (50.0+ob->stats.dam)/50.0;
136 136
137int has_ability(const object *ob) { 137int has_ability(const object *ob) {
138 object *tmp; 138 object *tmp;
139 139
140 for(tmp=ob->inv;tmp!=NULL;tmp=tmp->below) 140 for(tmp=ob->inv;tmp!=NULL;tmp=tmp->below)
141 if(tmp->type==SPELL||tmp->type==SPELLBOOK) 141 if(tmp->type==SPELL||tmp->type==SPELLBOOK)
142 return TRUE; 142 return TRUE;
143 return FALSE; 143 return FALSE;
144} 144}
145 145
146/* This loads the experience table from the exp_table 146/* This loads the experience table from the exp_table
147 * file. This tends to exit on any errors, since it 147 * file. This tends to exit on any errors, since it
161 161
162 if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) { 162 if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) {
163 return; 163 return;
164 } 164 }
165 while (fgets(buf, MAX_BUF-1, fp) != NULL) { 165 while (fgets(buf, MAX_BUF-1, fp) != NULL) {
166 if (buf[0] == '#') continue; 166 if (buf[0] == '#') continue;
167 167
168 /* eliminate newline */ 168 /* eliminate newline */
169 if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0'; 169 if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0';
170 170
171 /* Skip over empty lines */ 171 /* Skip over empty lines */
172 if (buf[0] == 0) continue; 172 if (buf[0] == 0) continue;
173 cp = buf; 173 cp = buf;
174 while (isspace(*cp) && *cp!=0) cp++; 174 while (isspace(*cp) && *cp!=0) cp++;
175 if (!strncasecmp(cp, "max_level",9)) { 175 if (!strncasecmp(cp, "max_level",9)) {
176 if (settings.max_level) { 176 if (settings.max_level) {
177 LOG(llevDebug, "Got more than one max_level value from exp_table file?\n"); 177 LOG(llevDebug, "Got more than one max_level value from exp_table file?\n");
178 free(levels); 178 free(levels);
179 } 179 }
180 settings.max_level = atoi(cp+9); 180 settings.max_level = atoi(cp+9);
181 if (!settings.max_level) { 181 if (!settings.max_level) {
182 LOG(llevDebug, "Got invalid max_level from exp_table file? %s\n", buf); 182 LOG(llevDebug, "Got invalid max_level from exp_table file? %s\n", buf);
183 } else { 183 } else {
184 levels = (sint64 *) calloc(settings.max_level +1, sizeof(sint64)); 184 levels = (sint64 *) calloc(settings.max_level +1, sizeof(sint64));
185 } 185 }
186 } 186 }
187 while (isdigit(*cp) && *cp!=0) { 187 while (isdigit(*cp) && *cp!=0) {
188 if (!settings.max_level) { 188 if (!settings.max_level) {
189 LOG(llevError, "max_level is not set in exp_table file. Did you remember to update it?\n"); 189 LOG(llevError, "max_level is not set in exp_table file. Did you remember to update it?\n");
190 exit(1); 190 exit(1);
191 } 191 }
192 192
193 tmpexp = atoll(cp); 193 tmpexp = atoll(cp);
194 /* Do some sanity checking - if value is bogus, just exit because 194 /* Do some sanity checking - if value is bogus, just exit because
195 * the table otherwise is probably in an inconsistent state 195 * the table otherwise is probably in an inconsistent state
196 */ 196 */
197 if (tmpexp <= lastexp) { 197 if (tmpexp <= lastexp) {
198#ifndef WIN32 198#ifndef WIN32
199 LOG(llevError,"Experience for level %d is lower than previous level (%lld <= %lld)\n", 199 LOG(llevError,"Experience for level %d is lower than previous level (%lld <= %lld)\n",
200 lastlevel + 1, tmpexp, lastexp); 200 lastlevel + 1, tmpexp, lastexp);
201#else 201#else
202 LOG(llevError,"Experience for level %d is lower than previous level (%I64d <= %I64d)\n", 202 LOG(llevError,"Experience for level %d is lower than previous level (%I64d <= %I64d)\n",
203 lastlevel + 1, tmpexp, lastexp); 203 lastlevel + 1, tmpexp, lastexp);
204#endif 204#endif
205 exit(1); 205 exit(1);
206 } 206 }
207 lastlevel++; 207 lastlevel++;
208 if (lastlevel > settings.max_level) { 208 if (lastlevel > settings.max_level) {
209 LOG(llevError,"Too many levels specified in table (%d > %d)\n", 209 LOG(llevError,"Too many levels specified in table (%d > %d)\n",
210 lastlevel, settings.max_level); 210 lastlevel, settings.max_level);
211 exit(1); 211 exit(1);
212 } 212 }
213 levels[lastlevel] = tmpexp; 213 levels[lastlevel] = tmpexp;
214 lastexp = tmpexp; 214 lastexp = tmpexp;
215 /* First, skip over the number we just processed. Then skip over 215 /* First, skip over the number we just processed. Then skip over
216 * any spaces, commas, etc. 216 * any spaces, commas, etc.
217 */ 217 */
218 while (isdigit(*cp) && *cp!=0) cp++; 218 while (isdigit(*cp) && *cp!=0) cp++;
219 while (!isdigit(*cp) && *cp!=0) cp++; 219 while (!isdigit(*cp) && *cp!=0) cp++;
220 } 220 }
221 } 221 }
222 close_and_delete(fp, comp); 222 close_and_delete(fp, comp);
223 if (lastlevel != settings.max_level && lastlevel != 0) { 223 if (lastlevel != settings.max_level && lastlevel != 0) {
224 LOG(llevError,"Warning: exp_table does not have %d entries (%d)\n", 224 LOG(llevError,"Warning: exp_table does not have %d entries (%d)\n",
225 settings.max_level, lastlevel); 225 settings.max_level, lastlevel);
226 exit(1); 226 exit(1);
227 } 227 }
228} 228}
229 229
230/* Dump the table - useful in terms of debugging to make sure the 230/* Dump the table - useful in terms of debugging to make sure the
231 * format of the exp_table is correct. 231 * format of the exp_table is correct.
234void dump_experience() 234void dump_experience()
235{ 235{
236 int i; 236 int i;
237 237
238 for (i=1; i<= settings.max_level; i++) { 238 for (i=1; i<= settings.max_level; i++) {
239 fprintf(logfile,"%4d %20lld\n", i, levels[i]); 239 fprintf(logfile,"%4d %20lld\n", i, levels[i]);
240 } 240 }
241 exit(0); 241 exit(0);
242} 242}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines