void signon( ANSI(void) ) { /* Print the sign-on message. Since the console is opened explicitly, the * message is printed even if both stdout and stderr are redirected. */ FILE *screen; UNIX( if( !(screen = fopen("/dev/tty", "w")) ) ) MS ( if( !(screen = fopen("con:", "w")) ) ) screen = stderr; /* The ANSI __DATE__ macro yields a string of the form: "Sep 01 1989". * The __DATE__+7 gets the year portion of that string. * * The UNIX __DATE__ is created from the makefile with this command: * echo \#define __DATE__ \"`date`\" >> date.h * which evaluates to: * #define __DATE__ "Sun Apr 29 12:51:50 PDT 1990" * The year is at __DATE__+24 */ fprintf(screen,"LeX %s [%s]. (c) %s, Allen I. Holub.", VERSION, __DATE__, ANSI( __DATE__+7 ) KnR ( __DATE__+24) ); fprintf(screen," All rights reserved.\n"); if( screen != stderr ) fclose(screen); }
static void _init(void) { fcode_env_t *env = initial_env; mac_addr = MALLOC(MAC_ADDR_SIZE); ASSERT(env); NOTICE; ANSI(0x06e, 0, "l@", fcd_lfetch); ANSI(0x06f, 0, "w@", fcd_wfetch); ANSI(0x071, 0, "c@", fcd_cfetch); ANSI(0x073, 0, "l!", fcd_lstore); ANSI(0x074, 0, "w!", fcd_wstore); ANSI(0x075, 0, "c!", fcd_cstore); ANSI(0x078, 0, "move", fcd_move); ANSI(0x07a, 0, "comp", fcd_comp); ANSI(0x120, 0, "diagnostic-mode?", diagnostic_mode); ANSI(0x1a4, 0, "mac-address", mac_address); P1275(0x220, 0, "cpeek", cpeek); P1275(0x221, 0, "wpeek", wpeek); P1275(0x222, 0, "lpeek", lpeek); P1275(0x223, 0, "cpoke", cpoke); P1275(0x224, 0, "wpoke", wpoke); P1275(0x225, 0, "lpoke", lpoke); P1275(0x230, 0, "rb@", rbfetch); P1275(0x231, 0, "rb!", rbstore); P1275(0x232, 0, "rw@", rwfetch); P1275(0x233, 0, "rw!", rwstore); P1275(0x234, 0, "rl@", rlfetch); P1275(0x235, 0, "rl!", rlstore); P1275(0x246, 0, "x@", fcd_xfetch); P1275(0x247, 0, "x!", fcd_xstore); P1275(0x22e, 0, "rx@", rxfetch); P1275(0x22f, 0, "rx!", rxstore); FORTH(0, "set-diagnostic-mode", set_diagnostic_mode); FORTH(0, "local-mac-address?", local_mac_address); FORTH(0, "local-ether-addr", local_ether_addr); }
void bench(char *name, benchfn fn, void *ctx, ...) { phdouble t = 0; phint n = 0; va_list args; va_start(args, ctx); while (name != NULL) { while (t < 0.1) { if (n == 0) { n = 1; } else { n *= 10; } printf("\r%s%s%s: run %s%d%s iterations", ANSI(green), name, ANSI(clear), ANSI(cyan), n, ANSI(clear) ); fflush(stdout); t = runiterations(n, fn, ctx); } printf("\r%s%s%s: %s%.3g%s iterations in %s%.3g%s second.\n", ANSI(green), name, ANSI(clear), ANSI(cyan), n / t, ANSI(clear), ANSI(cyan), t / t, ANSI(clear) ); fflush(stdout); n = 0; t = 0; name = va_arg(args, char *); if (name == NULL) {break;} fn = va_arg(args, benchfn); if (fn == NULL) {break;} ctx = va_arg(args, void *); } va_end(args); }
int update_combat( creature *crt_ptr ) { creature *att_ptr; room *rom_ptr; etag *ep; char *enemy; int n = 0,rtn = 0,p = 0,fd,t = 0; int victim_is_monster = 0, circled=0, tried_circle=0; ASSERTLOG( crt_ptr ); rom_ptr = crt_ptr->parent_rom; ep = crt_ptr->first_enm; while(1) { enemy = ep->enemy; if(!enemy) ep = ep->next_tag; if(!ep) return 0; if(enemy) break; } /* keep looking till we find one that is an exact match */ /* and is not the monster itself */ n = 1; do { att_ptr = find_exact_crt(crt_ptr, rom_ptr->first_ply,enemy, n); if(!att_ptr) att_ptr = find_exact_crt(crt_ptr, rom_ptr->first_mon,enemy, n); if(!att_ptr) { #ifdef OLD_CODE /* with this code commented out, a monster will remember it is attacking a player even if he logs out and logs back in unlike now where he can get someone else to stadn there and attack, disconnect, login attack again etc. */ if(!find_who(enemy)) del_enm_crt(enemy, crt_ptr); else #endif end_enm_crt(enemy, crt_ptr); return 0; } n++; } while ( att_ptr != NULL && att_ptr == crt_ptr ); if ( att_ptr->type == MONSTER) { victim_is_monster = 1; } /* I think this check is redundanct now */ if(att_ptr != crt_ptr) { if(is_charm_crt(crt_ptr->name, att_ptr)&& F_ISSET(crt_ptr, MCHARM)) p = 1; crt_ptr->NUMHITS++; n=20; if(F_ISSET(crt_ptr, MMAGIO)) n=crt_ptr->proficiency[0]; if(F_ISSET(crt_ptr, MMAGIC) && mrand(1, 100) <= n && !p) { rtn = crt_spell(crt_ptr, att_ptr ); if(rtn == 2) { /* spell killed the victim */ return 1; } else if(rtn == 1) { /* spell hurt the victim but did not kill */ n = 21; if ( !victim_is_monster ) { if ( check_for_ply_flee( att_ptr )) { return(1); } } } else { /* spell was not cast or did not hurt the victim */ n = crt_ptr->thaco - att_ptr->armor/10; } } else { n = crt_ptr->thaco - att_ptr->armor/10; n = MAX(n, 1); } if(mrand(1,20) >= n && !p) { if ( !victim_is_monster ) { fd = att_ptr->fd; ANSI(fd, ATTACKCOLOR); } else { fd = -1; } if((crt_ptr->class==BARBARIAN||crt_ptr->class==FIGHTER) && (mrand(1,30)<20 && crt_ptr->level > (att_ptr->level - 3))) { circled = (crt_ptr->level - att_ptr->level) + mrand(1,4); if(circled>1) { mprint(fd, "%M circles you.\n", m1arg(crt_ptr)); if(F_ISSET(crt_ptr, MNOPRE)) { if(F_ISSET(att_ptr, MNOPRE)) { sprintf(g_buffer, "%s circles %s.", crt_ptr->name, att_ptr->name); } else { sprintf(g_buffer, "%s circles the %s.", crt_ptr->name, att_ptr->name); } } else { /* !F_ISSET(crt_ptr,MNOPRE) */ if(F_ISSET(att_ptr, MNOPRE)) { sprintf(g_buffer, "The %s circles %s.", crt_ptr->name, att_ptr->name); } else { sprintf(g_buffer, "The %s circles the %s.", crt_ptr->name, att_ptr->name); } } broadcast_dam(fd, crt_ptr->fd, att_ptr->rom_num, g_buffer, NULL); att_ptr->lasttime[LT_ATTCK].ltime = time(0); att_ptr->lasttime[LT_ATTCK].interval = mrand(5,8) - bonus[(int)att_ptr->dexterity]; circled=1; } else { mprint(fd, "%M tried to circle you.\n", m1arg(crt_ptr)); if(F_ISSET(crt_ptr, MNOPRE)) { if(F_ISSET(att_ptr,MNOPRE)) { sprintf(g_buffer, "%s tried to circle %s.", crt_ptr->name, att_ptr->name); } else { sprintf(g_buffer, "%s tried to circle the %s.", crt_ptr->name, att_ptr->name); } } else { /*!F_ISSET(crt_ptr, MNOPRE) */ if(F_ISSET(att_ptr,MNOPRE)) { sprintf(g_buffer, "The %s tried to circle %s.", crt_ptr->name, att_ptr->name); } else { sprintf(g_buffer, "The %s tried to circle the %s.", crt_ptr->name, att_ptr->name); } } broadcast_dam(fd, crt_ptr->fd, att_ptr->rom_num, g_buffer, NULL); circled=0; tried_circle=1; } } if(F_ISSET(crt_ptr, MBRETH) && mrand(1,30)<5) { if (F_ISSET(crt_ptr, MBRWP1) && !F_ISSET(crt_ptr, MBRWP2)) n = bw_spit_acid(crt_ptr,att_ptr); else if (F_ISSET(crt_ptr, MBRWP1) && F_ISSET(crt_ptr, MBRWP2)) n = bw_poison(crt_ptr,att_ptr); else if (!F_ISSET(crt_ptr, MBRWP1) && F_ISSET(crt_ptr, MBRWP2)) n = bw_cone_frost(crt_ptr,att_ptr); else n = bw_cone_fire(crt_ptr,att_ptr); } else if(F_ISSET(crt_ptr, MENEDR) && mrand(1,100)< 25) n = power_energy_drain(crt_ptr,att_ptr); else { if(circled==0) { n = mdice(crt_ptr); } } if(circled==0 && tried_circle==0) { att_ptr->hpcur -= n; if ( !victim_is_monster ) { sprintf(g_buffer, "%%M hit you for %d damage.\n", n); mprint(fd, g_buffer, m1arg(crt_ptr)); add_enm_dmg(att_ptr->name, crt_ptr,n); // added for damage descriptions if(F_ISSET(crt_ptr, MNOPRE)) sprintf(g_buffer, "%s %s %s!",crt_ptr->name , hit_description(n), att_ptr->name); else sprintf(g_buffer,"The %s %s %s!", crt_ptr->name, hit_description(n), att_ptr->name); broadcast_dam(crt_ptr->fd, att_ptr->fd, att_ptr->rom_num, g_buffer, NULL); } else { /* Output only when monster v. monster */ broadcast_rom(-1,crt_ptr->rom_num, "%M hits %m.", m2args(crt_ptr, att_ptr)); add_enm_crt(crt_ptr->name, att_ptr); } } if(F_ISSET(crt_ptr, MPOISS) && mrand(1,100) <= 15) { if ( victim_is_monster ) { broadcast_rom(-1, att_ptr->rom_num,"%M poisoned %m.", m2args(crt_ptr, att_ptr)); } else { ANSI(fd, POISONCOLOR); mprint(fd, "%M poisoned you.\n", m1arg(crt_ptr)); } F_SET(att_ptr, PPOISN); } if(F_ISSET(crt_ptr, MDISEA) && mrand(1,100) <= 15) { if ( victim_is_monster ) { broadcast_rom(-1, att_ptr->rom_num,"%M infects %m.", m2args(crt_ptr, att_ptr)); } else { ANSI(fd, DISEASECOLOR); mprint(fd, "%M infects you.\n", m1arg(crt_ptr)); } F_SET(att_ptr, PDISEA); } if(F_ISSET(crt_ptr, MBLNDR) && mrand(1,100) <= 15) { if ( victim_is_monster ) { broadcast_rom(-1, att_ptr->rom_num,"%M blinds %m.", m2args(crt_ptr, att_ptr)); } else { ANSI(fd, BLINDCOLOR); mprint(fd, "%M blinds your eyes.\n", m1arg(crt_ptr)); } F_SET(att_ptr, PBLIND); } if(F_ISSET(crt_ptr, MDISIT) && mrand(1,100) <= 15) dissolve_item(att_ptr,crt_ptr); if ( !victim_is_monster ) { ANSI(fd, MAINTEXTCOLOR); n = choose_item(att_ptr); if(n) { if(--att_ptr->ready[n-1]->shotscur<1) { sprintf(g_buffer,"Your %s fell apart.\n",att_ptr->ready[n-1]->name); output(fd, g_buffer); sprintf(g_buffer, "%%M's %s fell apart.", att_ptr->ready[n-1]->name); broadcast_rom(fd,att_ptr->rom_num, g_buffer, m1arg(att_ptr)); add_obj_crt(att_ptr->ready[n-1],att_ptr); dequip(att_ptr,att_ptr->ready[n-1]); att_ptr->ready[n-1] = 0; compute_ac(att_ptr); } } } if(!victim_is_monster && !F_ISSET(att_ptr, PNOAAT) && !p) { rtn = attack_crt(att_ptr, crt_ptr); if(rtn) return 1; } else { if(LT(att_ptr,LT_ATTCK) < t) { rtn = attack_crt(att_ptr, crt_ptr); att_ptr->lasttime[LT_ATTCK].ltime = t; if(rtn) return 1; } } if(att_ptr->hpcur < 1) { if ( !victim_is_monster ) { msprint(att_ptr, g_buffer, "%M killed you.\n", m1arg(crt_ptr)); output_wc(att_ptr->fd, g_buffer, ATTACKCOLOR); } else { broadcast_rom(-1,att_ptr->rom_num,"%M killed %m.", m2args(crt_ptr, att_ptr)); } die(att_ptr, crt_ptr); return 1; } else if ( !victim_is_monster ) { if ( check_for_ply_flee( att_ptr )) { return(1); } } } else if(n <= 20 && !p) { if ( !victim_is_monster ) { msprint(att_ptr, g_buffer, "%M missed you.\n", m1arg(crt_ptr)); output_wc(att_ptr->fd, g_buffer, MISSEDCOLOR); } else { /* Output only when monster v. monster */ broadcast_rom(-1, att_ptr->rom_num, "%M misses %m.", m2args(crt_ptr, att_ptr)); add_enm_crt(crt_ptr->name, att_ptr); } if(!victim_is_monster && !F_ISSET(att_ptr, PNOAAT)) { rtn = attack_crt(att_ptr, crt_ptr); if(rtn) return 1; } else { if(LT(att_ptr,LT_ATTCK) < t) { rtn = attack_crt(att_ptr, crt_ptr); att_ptr->lasttime[LT_ATTCK].ltime = t; if(rtn) return 1; } } } }