-
Notifications
You must be signed in to change notification settings - Fork 5
/
arena.cpp
682 lines (596 loc) · 19.4 KB
/
arena.cpp
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/* ************************************************************************
* File: arena.c Addition to CircleMUD *
* Usage: Implementation of a event driven arena where players pay to kill*
* *
* Writen by: Kevin Hoogheem aka Goon *
* Modified by Billy H. Chan (STROM) *
* *
* Using this code without consent by Goon will make your guts spill *
* out or worse.. Maybe I will hire Lauraina Bobbet to come visit you *
************************************************************************ */
#include "config.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "screen.h"
#include "spells.h"
#include "handler.h"
#include "interpreter.h"
#include "db.h"
#include "arena.h"
#include "fight.h"
#include "descriptor.h"
/* external vars */
//extern int restrict;
int in_arena = ARENA_OFF;
int start_time;
int game_length;
int lo_lim;
int hi_lim;
int cost_per_lev;
int time_to_start;
int time_left_in_game;
long arena_pot;
long bet_pot;
struct hall_of_fame_element *fame_list = NULL;
ACMD ( do_bet )
{
gold_int newbet;
Character *bet_on;
char arg[MAX_INPUT_LENGTH];
char buf1[MAX_INPUT_LENGTH];
two_arguments ( argument, arg, buf1 );
if ( IS_NPC ( ch ) )
{
ch->Send ( "Mobs can't bet on the arena.\r\n" );
return;
}
if ( !*arg )
{
if ( in_arena == ARENA_OFF )
{
ch->Send ( "Sorry no arena is in going on.\r\n" );
return;
}
else if ( in_arena == ARENA_START )
{
ch->Send ( "Usage: wager <player> <amt>\r\n" );
return;
}
else if ( in_arena == ARENA_RUNNING )
{
ch->Send ( "Fighting has already begun - no more wagers.\r\n" );
return;
}
}
if ( in_arena == ARENA_OFF )
{
ch->Send ( "The arena is closed - wait until it opens to bet.\r\n" );
}
else if ( in_arena == ARENA_RUNNING )
{
ch->Send ( "Arena is in session, no more bets.\r\n" );
}
else if ( ! ( bet_on = get_char_vis ( ch, arg, NULL, FIND_CHAR_WORLD ) ) )
ch->Send ( "%s", CONFIG_NOPERSON );
else if ( ! ( bet_on->in_room->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( bet_on ), ROOM_ARENA ) ) )
ch->Send ( "Sorry that person is not in the arena.\r\n" );
else
{
if ( GET_AMT_BET ( ch ) > 0 )
{
ch->Send ( "Sorry you have already bet.\r\n" );
return;
}
GET_BETTED_ON ( ch ) = GET_IDNUM ( bet_on );
newbet = abs ( atoi ( buf1 ) );
if ( newbet == 0 )
{
ch->Send ( "Bet some gold why don't you!\r\n" );
return;
}
if ( newbet > ch->Gold ( 0, GOLD_ALL ) )
{
ch->Send ( "You don't have that much money!\r\n" );
return;
}
if ( newbet > MAX_BET * 10 )
{
ch->Send ( "Sorry the house will not accept that much.\r\n" );
return;
}
ch->Gold ( -newbet, GOLD_ALL ); /* substract the gold */
arena_pot += ( newbet / 2 );
bet_pot += ( newbet / 2 );
GET_AMT_BET ( ch ) = newbet;
ch->Send ( "You place %lld coins on %s.\r\n", newbet,
GET_NAME ( bet_on ) );
send_to_arena ( "## %s has placed %lld coins on %s.", GET_NAME ( ch ),
newbet, GET_NAME ( bet_on ) );
}
}
// x12Il.dj
ACMD ( do_arena )
{
if ( IS_NPC ( ch ) )
{
ch->Send ( "Mobs can't play in the arena.\r\n" );
return;
}
if ( in_arena == ARENA_OFF )
{
ch->Send ( "The killing fields are closed right now.\r\n" );
}
else if ( GET_LEVEL ( ch ) < lo_lim )
{
ch->Send (
"You must be at least level %d to enter this arena.\r\n",
lo_lim );
}
else if ( PLR_FLAGGED ( ch, PLR_KILLER ) || PLR_FLAGGED ( ch, PLR_THIEF ) )
{
ch->Send ( "Wanted criminals can not play in the arena.\r\n" );
}
else if ( GET_LEVEL ( ch ) > hi_lim )
{
ch->Send ( "Sorry the killing fields are not open to you.\r\n" );
}
else if ( ch->Gold ( 0, GOLD_ALL ) < ( unsigned ) ( cost_per_lev * GET_LEVEL ( ch ) ) )
{
ch->Send ( "Sorry but you need %d coins to enter the arena.\r\n",
( cost_per_lev * GET_LEVEL ( ch ) ) );
}
else if ( in_arena == ARENA_RUNNING )
{
ch->Send ( "The fighting has already begun.\r\n" );
}
else if ( ROOM_FLAGGED ( IN_ROOM ( ch ), ROOM_ARENA ) )
{
ch->Send ( "You are already in the arena.\r\n" );
}
else
{
act ( "$n has been taken to the killing fields.", FALSE, ch, 0, 0, TO_ROOM );
if ( !move_char_to ( ch,real_room ( number ( ARENA_PREP_START, ARENA_PREP_END ) ) ) ) return;
act ( "$n is dropped from the sky.", FALSE, ch, 0, 0, TO_ROOM );
ch->Send ( "You have been taken to the killing fields\r\n" );
look_at_room ( ch, 0 );
send_to_arena ( "%s has joined the blood bath.\r\n", GET_NAME ( ch ) );
ch->Gold ( - ( cost_per_lev * GET_LEVEL ( ch ) ), GOLD_ALL );
arena_pot += ( cost_per_lev * GET_LEVEL ( ch ) );
ch->Send ( "You pay %d coins to enter the arena\r\n",
( cost_per_lev * GET_LEVEL ( ch ) ) );
alter_hit ( ch, -GET_MAX_HIT ( ch ) );
alter_mana ( ch, -GET_MAX_MANA ( ch ) );
alter_move ( ch, -GET_MAX_MOVE ( ch ) );
remove_all_normal_affects ( ch );
}
}
ACMD ( do_chaos )
{
char cost[MAX_INPUT_LENGTH], lolimit[MAX_INPUT_LENGTH];
char hilimit[MAX_INPUT_LENGTH], start_delay[MAX_INPUT_LENGTH];
char length[MAX_INPUT_LENGTH];
char buf[MAX_INPUT_LENGTH];
/* Usage: chaos lo hi start_delay cost/lev length */
if (!(GET_LEVEL(ch) == LVL_IMPL)
&& !(GET_LEVEL(ch) >= LVL_IMMORT && WIZ_TRUSTED(ch, WIZ_IMM2_GRP))
&& !PLR_FLAGGED(ch, PLR_HERO)) {
ch->Send ( "Only heroes and immortals can do this.\r\n");
return;
}
if ( in_arena != ARENA_OFF )
{
ch->Send ( "There is an arena running already.\r\n" );
return;
}
half_chop ( argument, lolimit, buf );
lo_lim = atoi ( lolimit );
half_chop ( buf, hilimit, buf );
hi_lim = atoi ( hilimit );
half_chop ( buf, start_delay, buf );
start_time = atoi ( start_delay );
half_chop ( buf, cost, buf );
cost_per_lev = atoi ( cost );
strcpy ( length, buf );
game_length = atoi ( length );
if ( hi_lim > LVL_IMPL )
{
ch->Send ( "Please choose a hi_lim under the Imps level\r\n" );
return;
}
if ( lo_lim < 0 )
silent_end();
if ( !*lolimit || !*hilimit || !*start_delay || !*cost || !*length )
{
ch->Send ( "Usage: chaos lo hi start_delay cost/lev length\r\n" );
return;
}
if ( lo_lim > hi_lim )
{
ch->Send ( "Sorry, low limit must be lower than hi limit.\r\n" );
return;
}
if ( ( hi_lim < 0 ) || ( cost_per_lev < 0 ) || ( game_length < 0 ) )
{
ch->Send ( "I like positive numbers thank you.\r\n" );
return;
}
if ( start_time <= 0 )
{
ch->Send ( "Lets at least give them a chance to enter!\r\n" );
return;
}
if ( ( GET_LEVEL ( ch ) < LVL_IMPL ) && ( cost_per_lev < MIN_ARENA_COST ) )
{
ch->Send ( "The minimum cost per level is 100.\r\n" );
return;
}
in_arena = ARENA_START;
time_to_start = start_time;
time_left_in_game = 0;
arena_pot = 0;
bet_pot = 0;
start_arena();
}
void start_arena ( void )
{
if ( time_to_start == 0 )
{
show_jack_pot();
in_arena = ARENA_RUNNING; /* start the blood shed */
time_left_in_game = game_length;
start_game();
}
else
{
send_to_arena (
"The Killing Fields are open to levels %d thru %d, \r\n"
"%d coins/level to enter.\r\n%d hour%s to start.\r\n"
"Type arena to enter.",
lo_lim, hi_lim,cost_per_lev, time_to_start, time_to_start > 1 ? "s" : "" );
time_to_start--;
}
}
void show_jack_pot ( void )
{
send_to_arena ( "\007\007Lets get ready to RUMBLE!!!!!!!!\r\n"
"The jackpot for this arena is %ld coins.\r\n",
arena_pot );
send_to_arena ( "There are %ld coins in the betting pool.\r\n", bet_pot );
}
void start_game ( void )
{
Character *i;
Descriptor *d;
for ( d = descriptor_list; d; d = d->next )
{
if ( !d->connected )
{
i = d->character;
if ( i->in_room->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( i ), ROOM_ARENA ) &&
( i->in_room != NULL ) )
{
send_to_char
( "\r\nThe floor opens, droping you in the arena.\r\n",
i );
move_char_to ( i,
real_room ( number
( ARENA_START_ROOM,
ARENA_END_ROOM ) ) );
look_at_room ( i, 0 );
}
}
}
do_game();
}
void do_game ( void )
{
if ( num_in_arena() == 1 )
{
in_arena = ARENA_OFF;
find_game_winner();
}
else if ( time_left_in_game == 0 )
{
in_arena = ARENA_OFF;
do_end_game();
}
else if ( num_in_arena() == 0 )
{
in_arena = ARENA_OFF;
silent_end();
}
else if ( ( time_left_in_game % 5 ) || time_left_in_game <= 4 )
{
send_to_arena (
"With %d hours left in the game there are %d players left.\r\n",
time_left_in_game, num_in_arena() );
}
else if ( time_left_in_game == 1 )
{
send_to_arena (
"With 1 hour left in the game there are %d players left.\r\n",
num_in_arena() );
}
time_left_in_game--;
}
void find_game_winner ( void )
{
Character *i;
Descriptor *d;
struct hall_of_fame_element *fame_node;
for ( d = descriptor_list; d; d = d->next )
if ( !d->connected )
{
i = d->character;
if ( i->in_room->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( i ), ROOM_ARENA ) &&
( !IS_NPC ( i ) ) && ( i->in_room != NULL ) &&
GET_LEVEL ( i ) < LVL_HERO )
{
alter_hit ( i, -GET_MAX_HIT ( i ) );
alter_mana ( i, -GET_MAX_MANA ( i ) );
alter_move ( i, -GET_MAX_MOVE ( i ) );
remove_all_normal_affects ( i );
move_char_to ( i, real_room ( 3001 ) );
look_at_room ( i, 0 );
act ( "$n falls from the sky.", FALSE, i, 0, 0, TO_ROOM );
if ( game_length - time_left_in_game == 1 )
{
send_to_arena (
"After 1 brief hour, %s is declared the winner.\r\n",
GET_NAME ( i ) );
}
else
{
send_to_arena (
"After %d hours, %s is declared the winner.\r\n",
game_length - time_left_in_game, GET_NAME ( i ) );
}
i->Gold ( arena_pot / 2, GOLD_ALL );
i->Send ( "You have earned %ld coins for winning the arena.\r\n", ( arena_pot / 2 ) );
send_to_arena ( "%s has been awarded %ld coins for winning arena.\r\n", GET_NAME ( i ), ( arena_pot / 2 ) );
CREATE ( fame_node, struct hall_of_fame_element, 1 );
strncpy ( fame_node->name, GET_NAME ( i ), MAX_NAME_LENGTH );
fame_node->name[MAX_NAME_LENGTH] = '\0';
fame_node->date = time ( 0 );
fame_node->award = ( arena_pot / 2 );
fame_node->next = fame_list;
fame_list = fame_node;
write_fame_list();
find_bet_winners ( i );
}
}
}
void silent_end ( void )
{
in_arena = ARENA_OFF;
start_time = 0;
game_length = 0;
time_to_start = 0;
time_left_in_game = 0;
arena_pot = 0;
bet_pot = 0;
send_to_arena (
"It looks like no one was brave enough to enter the Arena." );
}
void do_end_game ( void )
{
Character *i;
Descriptor *d;
for ( d = descriptor_list; d; d = d->next )
if ( !d->connected )
{
i = d->character;
if ( ROOM_FLAGGED ( IN_ROOM ( i ), ROOM_ARENA ) &&
( i->in_room != NULL ) && ( !IS_NPC ( i ) ) )
{
alter_hit ( i, -GET_MAX_HIT ( i ) );
alter_mana ( i, -GET_MAX_MANA ( i ) );
alter_move ( i, -GET_MAX_MOVE ( i ) );
remove_all_normal_affects ( i );
if ( GET_RACE ( i ) == RACE_GLADIATOR )
move_char_to ( i, CONFIG_GLA_DEATH_ROOM );
else
move_char_to ( i, real_room ( 1205 ) );
look_at_room ( i, 0 );
act ( "$n falls from the sky.", FALSE, i, 0, 0, TO_ROOM );
}
}
send_to_arena ( "After %d hours of battle the Match is a draw.",
game_length );
time_left_in_game = 0;
}
int num_in_arena ( void )
{
Character *i;
Descriptor *d;
int num = 0;
for ( d = descriptor_list; d; d = d->next )
if ( !d->connected )
{
i = d->character;
if ( i->in_room->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( i ), ROOM_ARENA )
&& ( i->in_room != NULL ) )
{
if ( GET_LEVEL ( i ) < LVL_HERO )
num++;
}
}
return num;
}
ACMD ( do_awho )
{
Descriptor *d;
Character *tch;
int num = 0;
if ( in_arena == ARENA_OFF )
{
ch->Send ( "There is no Arena going on right now.\r\n" );
return;
}
ch->Send ( " Gladiators in the Arena\r\n"
"---------------------------------------\r\n"
"Game Length = %-3d Time To Start %-3d\r\n", game_length, time_to_start );
ch->Send ( "Level Limits %d to %d\r\n", lo_lim, hi_lim );
ch->Send ( " Jackpot = %ld\r\n", arena_pot );
ch->Send ( "---------------------------------------\r\n" );
for ( d = descriptor_list; d; d = d->next )
if ( !d->connected )
{
tch = d->character;
if ( IN_ROOM ( tch )->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( tch ), ROOM_ARENA ) &&
( IN_ROOM ( tch ) != NULL ) && GET_LEVEL ( tch ) < LVL_HERO )
{
ch->Send ( "%-20.20s%s",
GET_NAME ( tch ), ( ! ( ++num % 3 ) ? "\r\n" : "" ) );
}
}
ch->Send ( "\r\n\r\n" );
}
ACMD ( do_ahall )
{
char site[MAX_INPUT_LENGTH], *timestr;
struct hall_of_fame_element *fame_node;
if ( !fame_list )
{
ch->Send ( "No-one is in the Hall of Fame.\r\n" );
return;
}
ch->Send ( "%s|---------------------------------------|%s\r\n",
CCBLU ( ch, C_NRM ), CCNRM ( ch, C_NRM ) );
ch->Send (
"%s|%sPast Winners of Arena%s |%s\r\n",
CCBLU ( ch, C_NRM ), CCNRM ( ch, C_NRM ), CCBLU ( ch, C_NRM ),
CCNRM ( ch, C_NRM ) );
ch->Send (
"%s|---------------------------------------|%s\r\n\r\n",
CCBLU ( ch, C_NRM ), CCNRM ( ch, C_NRM ) );
ch->Send ( "%-10.10s %-15.15s %-40s\r\n", "Date", "Award Amt", "Name" );
ch->Send ( "%-10.10s %-15.15s %-40s\r\n",
"---------------------------------",
"--------------------------------",
"-------------------------------------------------" );
for ( fame_node = fame_list; fame_node; fame_node = fame_node->next )
{
if ( fame_node->date )
{
timestr = asctime ( localtime ( & ( fame_node->date ) ) );
* ( timestr + 10 ) = 0;
strcpy ( site, timestr );
}
else
strcpy ( site, "Unknown" );
ch->Send ( "%-10.10s %-16ld %s\r\n", site, fame_node->award,
CAP ( fame_node->name ) );
}
return;
}
void load_hall_of_fame ( void )
{
FILE *fl;
int date, award;
char name[MAX_NAME_LENGTH + 1];
struct hall_of_fame_element *next_node;
fame_list = 0;
if ( ! ( fl = fopen ( HALL_FAME_FILE, "r" ) ) )
{
perror ( "Unable to open hall of fame file" );
return;
}
while ( fscanf ( fl, "%s %d %d", name, &date, &award ) == 3 )
{
CREATE ( next_node, struct hall_of_fame_element, 1 );
strncpy ( next_node->name, name, MAX_NAME_LENGTH );
next_node->name[MAX_NAME_LENGTH] = '\0';
next_node->date = date;
next_node->award = award;
next_node->next = fame_list;
fame_list = next_node;
}
fclose ( fl );
}
void write_fame_list ( void )
{
FILE *fl;
if ( ! ( fl = fopen ( HALL_FAME_FILE, "w" ) ) )
{
/* syserrlog("Error writing _hall_of_fame_list", FALSE); */
log ( "Error writing _hall_of_fame_list" );
return;
}
write_one_fame_node ( fl, fame_list ); /* recursively write from end to start */
fclose ( fl );
return;
}
void write_one_fame_node ( FILE * fp, struct hall_of_fame_element *node )
{
if ( node )
{
write_one_fame_node ( fp, node->next );
fprintf ( fp, "%s %ld %ld\n", node->name, ( long ) node->date,
node->award );
}
}
void find_bet_winners ( Character *winner )
{
Character *i;
Descriptor *d;
for ( d = descriptor_list; d; d = d->next )
if ( !d->connected )
{
i = d->character;
if ( ( !IS_NPC ( i ) ) && ( i->in_room != NULL ) &&
( GET_BETTED_ON ( i ) == GET_IDNUM ( winner ) )
&& GET_AMT_BET ( i ) > 0 )
{
i->Send ( "You have won %d coins on your bet.\r\n", GET_AMT_BET ( i ) * 2 );
i->Gold ( GET_AMT_BET ( i ) * 2, GOLD_ALL );
GET_BETTED_ON ( i ) = 0;
GET_AMT_BET ( i ) = 0;
}
else /* they bet and did't win, or didn't bet at all */
GET_AMT_BET ( i ) = 0;
}
}
int arena_ok ( Character *ch, Character *victim )
{
if ( ROOM_FLAGGED ( IN_ROOM ( ch ), ROOM_ARENA ) &&
ROOM_FLAGGED ( victim->in_room, ROOM_ARENA ) )
return TRUE;
else if ( both_pk ( ch,victim ) )
return TRUE;
else
return FALSE;
}
void arena_kill ( Character *ch )
{
if ( FIGHTING ( ch ) )
stop_fighting ( ch );
remove_all_normal_affects ( ch );
if ( IN_ROOM ( ch )->zone == ARENA_ZONE &&
ROOM_FLAGGED ( IN_ROOM ( ch ), ROOM_ARENA ) )
{
GET_HIT ( ch ) = GET_MAX_HIT ( ch );
GET_MANA ( ch ) = GET_MAX_MANA ( ch );
GET_MOVE ( ch ) = GET_MAX_MOVE ( ch );
}
else
{
GET_HIT ( ch ) = GET_MAX_HIT ( ch );
}
ch->check_regen_rates();
update_pos ( ch );
if ( GET_RACE ( ch ) == RACE_GLADIATOR )
move_char_to ( ch, CONFIG_GLA_DEATH_ROOM );
else
move_char_to ( ch, real_room ( 1205 ) );
look_at_room ( ch, 0 );
act ( "$n is dropped from the sky.", FALSE, ch, 0, 0, TO_ROOM );
}