-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabil.cc
More file actions
448 lines (368 loc) · 11.2 KB
/
abil.cc
File metadata and controls
448 lines (368 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#include <ctype.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "define.h"
#include "struct.h"
const char *skill_cat_name [ MAX_SKILL_CAT ] = {
"physical",
"language",
"spell",
"trade",
"weapon"
};
const int skill_table_number[ MAX_SKILL_CAT ] = {
TABLE_SKILL_PHYSICAL,
TABLE_SKILL_LANGUAGE,
TABLE_SKILL_SPELL,
TABLE_SKILL_TRADE,
TABLE_SKILL_WEAPON
};
/*
* CURRENTLY UNUSED
*/
/*
char* abil_name( int i )
{
if( i < 0 ) return " (unknown) ";
if( i < 1 ) return "(appalling)";
if( i < 5 ) return "(dreadful) ";
if( i < 10 ) return " (awful) ";
if( i < 20 ) return " (bad) ";
if( i < 30 ) return " (poor) ";
if( i < 50 ) return " (fair) ";
if( i < 60 ) return " (capable) ";
if( i < 70 ) return " (good) ";
if( i < 80 ) return "(very good)";
if( i < 90 ) return " (superb) ";
return " (wicked) ";
}
*/
/*
* ABILITY ROUTINE
*/
/* Outputs the current players skills */
static void sort_skills( int clss, Array<int>& skills, bool level_sort )
{
for( int i = 0; i < skills.size-1; ++i ) {
bool done = true;
for( int j = 0; j < skills.size-1-i; ++j ) {
bool test = false;
Skill_Type *skill1 = skill_entry( skills[j] );
Skill_Type *skill2 = skill_entry( skills[j+1] );
if( level_sort ) {
test = ( ( skill1->level[clss] > skill2->level[clss] )
|| ( skill1->level[clss] == skill2->level[clss]
&& strcasecmp( skill1->name, skill2->name ) > 0 ) );
} else {
test = ( strcasecmp( skill1->name, skill2->name ) > 0 );
}
if( test ) {
swap( skills[j], skills[j+1] );
done = false;
}
}
if( done )
break;
}
}
void do_abilities( char_data* ch, const char *argument )
{
if( not_player( ch ) )
return;
int flags;
if( !get_flags( ch, argument, &flags, "l", "abilities" ) )
return;
if( !*argument ) {
send( ch, "Syntax: abilities [-l] <category> (optional class)\n\r" );
send( ch, "Where <category> is Physical, Weapon, Spell, Language, Trade, or All.\n\r" );
send( ch, "See help abilities for more detail.\n\r" );
return;
}
char arg [ MAX_STRING_LENGTH ];
argument = one_argument( argument, arg );
char buf [ FOUR_LINES ];
int i, j;
int ps1, ps2;
int length;
/* What class is the player? */
int clss = ch->pcdata->clss;
Array<int> skills;
/* If not looking for the skills available
* for a specific class then print current player's skills
*/
if( !*argument ) {
length = strlen( arg );
bool all = !strncasecmp( "all", arg, length );
for( j = 0; j < MAX_SKILL_CAT; ++j ) {
if( all || !strncasecmp( skill_cat_name[j], arg, length ) ) {
const int m = table_max[ skill_table_number[ j ] ];
for( i = 0; i < m; ++i ) {
const int id = skill_ident( j, i );
const Skill_Type *skill = skill_entry( j, i );
if( ( prac_cost( ch, id ) < 0
|| skill->level[clss] > ch->Level() )
&& ch->Level() < LEVEL_APPRENTICE )
continue;
skills.append( id );
}
if( !all ) {
if( skills.is_empty( ) ) {
send( ch, "You have no %s skills.\n\r", skill_cat_name[j] );
return;
}
break;
}
} else if( j+1 == MAX_SKILL_CAT ) {
send( ch, "Unknown skill category.\n\r" );
return;
}
}
if( skills.is_empty( ) ) {
send( ch, "You have no skills.\n\r" );
return;
}
sort_skills( clss, skills, false );
page_underlined( ch,
"Skill Level Cost Pracs Prerequistes\n\r" );
for( int k = 0; k < skills; ++k ) {
const int i = skills[k];
const int skill = ch->get_skill(i);
if( skill == UNLEARNT )
sprintf( arg, " unk" );
else
sprintf( arg, "%d ", skill );
Skill_Type *entry = skill_entry( i );
int b = sprintf( buf,"%-22s%4s",
entry->name, arg );
ps1 = entry->pre_skill[0];
ps2 = entry->pre_skill[1];
int cost = prac_cost( ch, i );
if( skill != 10 && cost >= 0 )
b += sprintf( buf+b, "%7d%5d%4s",
cost, entry->prac_cost[clss], "" );
else
b += sprintf( buf+b, "%16s", "" );
if( ps1 != SKILL_NONE )
b += sprintf( buf+b, "%s [%d]", skill_entry(ps1)->name,
entry->pre_level[0] );
if( ps2 != SKILL_NONE ) {
if( b + 8 + strlen( skill_entry(ps2)->name ) >= ch->pcdata->columns ) {
sprintf( buf+b, "\n\r" );
page( ch, buf );
b = sprintf( buf, "%41s", "" );
}
b += sprintf( buf+b, " & %s [%d]", skill_entry(ps2)->name,
entry->pre_level[1] );
}
sprintf( buf+b, "\n\r" );
page( ch, buf );
}
return;
}
/* Something was after abil <type> in the command line.
* Looking for skills for a specific class...
* i.e. abil <type> <class>
*/
length = strlen( argument );
/* Select the correct table for that class. */
for( clss = 0; clss < MAX_CLSS; ++clss )
if( !strncasecmp( argument, clss_table[clss].name, length ) )
break;
if( clss == MAX_CLSS ) {
send( ch, "Unknown class.\n\r" );
return;
}
/* Get the correct skill tables for that type.
* spell, physical, weapons, language.
*/
length = strlen( arg );
const bool all = !strncasecmp( "all", arg, length );
for( j = 0; j < MAX_SKILL_CAT; j++ ) {
if( all || !strncasecmp ( skill_cat_name[j], arg, length ) ) {
int m = table_max[ skill_table_number[ j ] ];
for( i = 0; i < m; ++i ) {
if( skill_entry( j, i )->prac_cost[clss] < 0 )
continue;
skills.append( skill_ident( j, i ) );
}
if( !all ) {
if( skills.is_empty( ) ) {
send( ch, "The %s class has no %s skills.\n\r",
clss_table[clss].name, skill_cat_name[j] );
return;
}
break;
}
} else if( j+1 == MAX_SKILL_CAT ) {
send( ch, "Unknown skill category.\n\r" );
return;
}
}
if( skills.is_empty( ) ) {
send( ch, "The %s class has no skills.\n\r",
clss_table[clss].name );
return;
}
sort_skills( clss, skills, is_set( flags, 0 ) );
page_underlined( ch,
"Skill Pracs Level Prerequistes\n\r" );
for( int k = 0; k < skills; ++k ) {
int i = skills[k];
Skill_Type *entry = skill_entry( i );
int b;
if( entry->level[clss] > LEVEL_HERO ) {
b = snprintf( buf, FOUR_LINES, "%-24s<Unfinished> ",
entry->name );
} else {
int cost = entry->prac_cost[clss];
b = snprintf( buf, FOUR_LINES, "%-22s%5d%7d ",
entry->name, cost,
entry->level[clss] );
}
ps1 = entry->pre_skill[0];
ps2 = entry->pre_skill[1];
if( ps1 != SKILL_NONE )
b += sprintf( buf+b, "%s [%d]", skill_entry( ps1 )->name,
entry->pre_level[0] );
if( ps2 != SKILL_NONE ) {
if( b + 8 + strlen( skill_entry( ps2 )->name ) >= ch->pcdata->columns ) {
sprintf( buf+b, "\n\r" );
page( ch, buf );
b = sprintf( buf, "%37s", "" );
}
b += sprintf( buf+b, " & %s [%d]", skill_entry( ps2 )->name,
entry->pre_level[1] );
}
if( !entry->religions.is_empty( ) ) {
if( ps1 != SKILL_NONE || ps2 != SKILL_NONE ) {
sprintf( buf+b, "\n\r" );
page( ch, buf );
b = sprintf( buf, "%38s", "" );
}
b += sprintf( buf+b, "(religion-specific)" );
}
sprintf( buf+b, "\n\r" );
page( ch, buf );
}
}
/*
* PRACTICE POINTS
*/
int total_pracs( char_data* ch )
{
const int clss = ch->pcdata->clss;
int total = 0;
int cost = 0;
for( int j = 0; j < MAX_SKILL_CAT; ++j ) {
const int m = table_max[ skill_table_number[ j ] ];
for( int i = 0; i < m; ++i ) {
skill_type *entry = skill_entry( j, i );
const int skill = ch->shdata->skills[j][i];
if( skill != UNLEARNT
&& ( cost = entry->prac_cost[clss] ) >= 0
&& entry->religion( ch->pcdata->religion ) )
total += cost*skill;
}
}
total -= 10*skill_entry( LANG_PRIMAL )->prac_cost[clss];
if( ch->shdata->race < MAX_PLYR_RACE )
total -= 10*skill_entry( LANG_HUMANIC+ch->shdata->race )->prac_cost[clss];
total += ch->pcdata->practice;
return total;
}
/* Does the calcs to see if you have improved at the skill you are using.
* Uses total pracs to date, expected pracs to date, a prac_timer and
* weights Intellegence and Wisdom equally. Also takes into account
* your level. If the skill is already at 10 then award a practise point.
*/
// Some physical skills improve like spells, since they don't get automatically
// used ad nauseum.
static bool sparse( int i )
{
return( i == SKILL_INSPECT
|| i == SKILL_UNTRAP
|| i == SKILL_FORAGE
|| i == SKILL_CAMPING
|| i == SKILL_BANDAGE
|| i == SKILL_GARROTE
|| i == SKILL_BUTCHER
|| i == SKILL_STEAL
|| i == SKILL_HEIST );
}
void char_data :: improve_skill( int i )
{
if( species
|| pcdata->prac_timer > 0
|| Level( ) >= LEVEL_APPRENTICE
|| i == LANG_PRIMAL )
return;
/* i is a valid skill, the players prac_timer has counted out, and the
* player has the skill at least at 1.
*/
const int l = get_skill( i );
if( l == UNLEARNT )
return;
/* Weapon, language or a skill that is being considered
* for an improve. If the timer just now counted below 0
* or the timer IS 0 then return. If the timer is 0 then
* set it to a random number between -20 and -2.
*/
const unsigned cat = skill_table( i );
if( cat != SKILL_CAT_SPELL && cat != SKILL_CAT_TRADE && !sparse( i ) ) {
if( pcdata->prac_timer < 0 && ++pcdata->prac_timer != -1 )
return;
if( pcdata->prac_timer == 0 ) {
pcdata->prac_timer = number_range( -20, -2 );
return;
}
}
/* nums for calculating if you get an improve.
* norm --> find expected pracs.
* total --> total number of pracs that a player has, including skill levels*pracs.
*/
const int norm = expected_pracs( this );
const int total = total_pracs( this );
const int j = max( 0, 2*(total-norm) );
/* reset the prac timer.*/
pcdata->prac_timer = 5;
/* Using random numbers between 0 and 30+the above j,
* comparisons to Intelligence and Wisdom are made. Must be less
* than both.
* Random between 0 and 200 must be greater than Level()...Dunno
*/
const skill_type *entry = skill_entry( i );
if( number_range( 0, 30+j ) < Intelligence( )
&& number_range( 0, 30+j ) < Wisdom( )
&& number_range( 0, 200 ) > Level() ) {
/* if the skill is already at 10 give a prac point. */
send( this, "\n\r" );
if( l == 10 || number_range( 0, 2 ) != 0 ) {
++pcdata->practice;
send_color( this, COLOR_SKILL,
"** You gain a practice point from %s. **",
entry->name );
} else {
/* otherwise improve. */
++shdata->skills[cat][skill_number(i)];
send_color( this, COLOR_SKILL, "** You improve at %s. **",
entry->name );
}
send( this, "\n\r\n\r" );
}
}
int prac_cost( char_data *ch, int skill )
{
if( skill < 0
|| ch->species ) {
return -1;
}
const skill_type *entry = skill_entry( skill );;
const int pracs = entry->prac_cost[ch->pcdata->clss];
if( pracs < 1 || !entry->religion( ch->pcdata->religion ) ) {
return -1;
}
const int class_level = entry->level[ch->pcdata->clss];
const int skill_level = ch->get_skill( skill );
return max( 5, (pracs * pracs * class_level * (skill_level + 2))/3 );
}