Ejemplo n.º 1
0
/* -------------------------------------------------------------------- */
void doCR(void)
{
    static numLines = 0;

	do_idle(0);					/* clear idle display */
	
    crtColumn = 1;
    setio(whichIO, echo, outFlag);

    domcr();
    doccr();

    if (printing)
        fprintf(printfile, "\n");

    prevChar = ' ';

    /* pause on full screen */
    if (logBuf.linesScreen) {
        if (outFlag == OUTOK) {
            numLines++;
            if (numLines == logBuf.linesScreen) {
                outFlag = OUTPAUSE;
                mAbort();
                numLines = 0;
            }
        } else {
            numLines = 0;
        }
    } else {
        numLines = 0;
    }
}
Ejemplo n.º 2
0
void lab5_daemon_driver(int cn, int ret, int lastact)
{
	struct msg *msg,*next;
        int in,co,imm=-1;
        struct lab5_daemon_data *dat;

        dat=set_data(cn,DRD_LAB5_DAEMON,sizeof(struct lab5_daemon_data));
        if (!dat) return;

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        lab5_daemon_driver_parse(cn,dat);
                }

		if (msg->type==NT_TEXT) {
			co=msg->dat3;
			tabunga(cn,co,(char*)msg->dat2);
		}

                if (msg->type==NT_CHAR) {
                        co=msg->dat1;
                        if (dat->type==1) { // master
                                if (ch[co].flags&CF_PLAYER && char_see_char(cn,co)) {
                                        if ((in=ch[co].item[WN_RHAND])==0 || it[in].ID!=IID_LAB5_WEAPON) imm=1; else if (imm==-1) imm=0;
                                }
                        }
                        else imm=0;

                        if (dat->type==2) { // gunned
                                if (ch[co].flags&CF_PLAYER && ch[co].y<namecoordy[0]+25 && char_see_char(cn,co)) fight_driver_add_enemy(cn,co,1,1); // dat->aggressive=1;
                        }
                }

                standard_message_driver(cn,msg,dat->aggressive,1);
                remove_message(cn,msg);
	}

        // switch to attack
        if (dat->aggressive==0 && ticker>dat->attackstart) dat->aggressive=1;

        // immortal switch
        if (imm==1) ch[cn].flags|=CF_IMMORTAL; else if (imm==0) ch[cn].flags&=~CF_IMMORTAL;

        // fighting
        fight_driver_update(cn);
        if (fight_driver_attack_visible(cn,0)) return;
        if (fight_driver_follow_invisible(cn)) return;

        // rest of standard action
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;
        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;

        // nothing left to do
        do_idle(cn,TICKS/2);
}
Ejemplo n.º 3
0
 void main (void) 
{ 
   filltblout(); 
   // Pas d'entr?e analogique 
   // No analogue inputs
   ANSEL = 0; 
   ANSELH = 0; 
   
   // Configuration des Entr?es/Sorties 
   // Input / Output configuration
   TRISA = 0x0C; 
   TRISB = 0b11111111;     // 0xFF; 
   #ifdef avecnpn 
      TRISC = 0b11011110;  // 5E 
   #else 
      TRISC = 0b11011111;  // 5E 
   #endif 
   
   // Initialisation du Timer0 qui servira de timeout 
   // Initialise Timer0 to deliver a timeout
   // OPTION_REG : 
   // Bit 7 = 1 -- Pull-up disabled 
   // Bit 6 = 0 -- Interruption sur front descendant de Int 
   //              Interrupt on falling edge
   // Bit 5 = 0 -- Timer sur clock Interne 
   //              Timer delivered from internal clock
   // Bit 4 = 0 -- N/A 
   // Bit 3 = 0 -- Prescaler sur timer 0 
   //              Prescaler for Timer0
   // Bits 2-0 = 011 -- Prescaler ? 16 
   //                   Prescaler is 16
   // Soit un timer egal ? 16*255us = 4ms 
   //                                 4ms
   OPTION = 0b00000011;  //Bit7 = 1 pull-ups disabled 
   
   WPUA  = 0;  // Pas de pull-ups sur port A
               // No pull up at port A   
   WPUB  = 0;  // Pas de pull-ups sur port B 
               // No pull up at port B
   WPUA2 = 1;  // Pull-up sur RA2 (RWIN) 
               // Pull up for RA2 (RWIN)
   
   enable_interrupts(); 
   PEIE  = 1;  // autoriser l'autorisation du SPI; 
               // Enable SPI
   
   LED1 = LEDOFF; 
   LED2 = LEDOFF; 
   LED3 = LEDOFF; 
   
   do_idle();   // se mettre en position d'attente du boitier 
                // Wait for body
   while (1) 
   { 
   
   
   } 
} 
Ejemplo n.º 4
0
int carrier(void)
{
    unsigned char c;

    if (            /* (whichIO==MODEM) && */
        (c = (uchar) gotCarrier()) != modStat
        && (!detectflag)
    ) {
    /* carrier changed   */
        if (c) {        /* carrier present   */
            switch (cfg.dumbmodem) {
                case 0:     /* numeric */
        /* do not use this routine for carrier detect */
                    return (1);

                case 1:     /* returns */
                    if (!findbaud()) {
                        Initport();
                        return TRUE;
                    }
                    break;

                case 2:     /* HS on RI */
                    ringdetectbaud();
                    break;

                case 3:     /* verbose */
                    verbosebaud();
                    break;

                default:
                case 4:     /* forced */
                    baud(cfg.initbaud);
                    break;
            }

            if (!onConsole) {
                carrdetect();
                detectflag = FALSE;
                return (0);
            } else {
                detectflag = TRUE;
                /* update25();	*/
				do_idle(0);
                return (1);
            }
        } else {
            delay(2000);    /* confirm it's not a glitch */
            if (!gotCarrier()) {/* check again */
                carrloss();

                return (0);
            }
        }
    }
    return (1);
}
Ejemplo n.º 5
0
void jzfb_lcdc_wait_dma_end(struct jzfb *jzfb) {
	unsigned int count = 1000;
	unsigned int count2 = 1000;

#ifdef CONFIG_M200
	struct save_intc_mask save;

	if ((reg_read(jzfb, LCDC_STATE) & LCDC_STATE_EOF))
		goto wait_slcd;

#if 1
	jz4775_intc_clear_lcd();
#else
	jz4775_intc_clear();
#endif
	jz4775_intc_mask_all_save(&save);
	jz4775_intc_irq_unmask(1 << 17);
	jz4775_intc_irq_unmask(1 << 31);
	jz4775_intc_irq_dma_unmask(1 << 31);

//	ddr_start_cycle_count();

	cpu_clk_switch_to_extclk();
	do_idle();
	cpu_clk_switch_back_to_appll();

//	ddr_end_cycle_count();

	jz4775_intc_clear_lcd();
	jz4775_intc_irq_mask(1 << 31);
	jz4775_intc_irq_dma_mask(1 << 31);
	jz4775_intc_mask_restore(&save);
	while (count-- && !(reg_read(jzfb, LCDC_STATE) & LCDC_STATE_EOF)) {
		udelay(10);
	}

wait_slcd:
	while (count2-- && (reg_read(jzfb, SLCDC_STATE) & SLCDC_STATE_BUSY)) {
		udelay(10);
	}
#else
	/* mdelay(1); */

	while (count-- && !(reg_read(jzfb, LCDC_STATE) & LCDC_STATE_EOF)) {
		udelay(10);
	}
	while (count2-- && (reg_read(jzfb, SLCDC_STATE) & SLCDC_STATE_BUSY)) {
		udelay(10);
	}
#endif

	pr_debug("count: %u count2: %u\n", count, count2);
}
Ejemplo n.º 6
0
static int recv_ack(void)
{
	unsigned int	ack;

	ack = (unsigned int)recv_bit();
	scl_lo;

	if (ack) {
		do_idle();
		printk(KERN_ERR "Error reading the Atmel 24C32/24C64 EEPROM \n");
		return -1;
	}

	return ack;
}
Ejemplo n.º 7
0
void doLogin(char moreYet)	/* TRUE to accept following parameters  */
{
    char InitPw[NAMESIZE*2+2];
    char passWord[NAMESIZE*2+2];
    char Initials[NAMESIZE*2+2];
    char *semicolon;

    if (justLostCarrier || ExitToMsdos)
        return;

    if (moreYet == 2)
        moreYet = FALSE;
    else
        mPrintf("\bLogin");

    /* we want to be in console mode when we log in from local */
    if (!gotCarrier() && !loggedIn) {
        whichIO = CONSOLE;
        onConsole = (char) (whichIO == CONSOLE);
        /* update25();	*/
		do_idle(0);
        if (cfg.offhook)
            offhook();
    }
    if (loggedIn) {
        mPrintf("\n Already logged in!\n ");
        return;
    }
    getNormStr((moreYet) ? "" : "your initials", InitPw, NAMESIZE*2+2, NO_ECHO);
    dospCR();

    semicolon = strchr(InitPw, ';');

    if (!semicolon) {
        strncpy(Initials, InitPw,NAMESIZE);
		Initials[NAMESIZE] = '\0';
        getNormStr("password", passWord, NAMESIZE, NO_ECHO);
        dospCR();
    } else
        normalizepw(InitPw, Initials, passWord, semicolon);

    /* don't allow anything over NAMESIZE characters */
    Initials[NAMESIZE] = '\0';

    login(Initials, passWord);
}
Ejemplo n.º 8
0
void keyhold_fight_driver(int cn,int ret,int lastact)
{
        struct gate_fight_driver_data *dat;
	struct msg *msg,*next;

	dat=set_data(cn,DRD_GATE_FIGHT,sizeof(struct gate_fight_driver_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        dat->creation_time=ticker;
                        fight_driver_set_dist(cn,10,0,20);
                }

                standard_message_driver(cn,msg,1,0);
                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	// self destruct eventually
	if (ticker-dat->creation_time>TICKS*60*5) {
		say(cn,"Thats all folks!");
		remove_destroy_char(cn);
		return;
	}

        fight_driver_update(cn);

        if (fight_driver_attack_visible(cn,0)) return;
	if (fight_driver_follow_invisible(cn)) return;
			
	if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;

	if (regenerate_driver(cn)) return;

	if (spell_self_driver(cn)) return;

        do_idle(cn,TICKS);
}
Ejemplo n.º 9
0
/* -------------------------------------------------------------------- */
void carrdetect(void)
{
    char temp[30];

    haveCarrier = TRUE;
    modStat = TRUE;
    newCarrier = TRUE;
    justLostCarrier = FALSE;

    conntimestamp = cit_time();

    connectcls();
    /* update25();	*/
	do_idle(0);

    sprintf(temp, "Carrier-Detect (%d)", bauds[speed]);
    trap(temp, T_CARRIER);

    logBuf.credits = cfg.unlogbal;
}
Ejemplo n.º 10
0
void monk_worker_driver(int cn, int ret, int lastact)
{
        struct saltmine_worker_data *workerdat;
        struct saltmine_ppd *ppd;
        struct msg *msg,*next;
        int co,dir;
        char *str;

        // get data
        if (!(workerdat=set_data(cn,DRD_SALTMINE_WORKER,sizeof(struct saltmine_worker_data)))) return;
        if (!(ppd=get_saltmine_ppd(workerdat->follow_cn))) return;

        // kill monk
        if ((!ch[workerdat->follow_cn].flags) || (ch[workerdat->follow_cn].serial!=workerdat->follow_serial)) {
                remove_destroy_char(cn);
                return;
        }

        if (char_dist(cn,workerdat->follow_cn)>90) {
                log_char(workerdat->follow_cn,LOG_SYSTEM,0,"°c3One of thine monks vanished!°c0");
                remove_destroy_char(cn);
                return;
        }

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        fight_driver_set_dist(cn,0,20,0);
                }

                if (msg->type==NT_GIVE) {
                        if (!ch[cn].citem) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source
                        co=msg->dat1;

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_TEXT) {

                        co=msg->dat3;
                        str=(char *)msg->dat2;

                        tabunga(cn,co,(char*)msg->dat2);

                        if (co==cn) { remove_message(cn,msg); continue; }
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
			// if (!char_see_char(cn,co)) { remove_message(cn,msg); continue; }

                        if (co==workerdat->follow_cn) {
                                if (strcasestr(str,"COME")) { workerdat->waituntil=0; }
                                else if (strcasestr(str,"WAIT")) { workerdat->waituntil=ticker+20*TICKS; }
                                else if (strcasestr(str,"SALT")) {  log_area(ch[cn].x,ch[cn].y,LOG_SYSTEM,0,10,"%s %s his head.",ch[cn].name,workerdat->hassalt?"nods":"shakes");  }
                        }
                }

                if (msg->type==NT_CHAR) {
                        co=msg->dat1;

                        if (co==workerdat->follow_cn && !(ch[cn].flags&CF_INVISIBLE)) {
                                if (ch[co].x<216)  {
                                        ch[cn].tmpx=ch[co].x;
                                        ch[cn].tmpy=ch[co].y;
                                } else workerdat->useitem=map[door_itemx+door_itemy*MAXMAP].it;
                        }
                }

                if (msg->type==NT_NPC && msg->dat1==NTID_SALTMINE_USEITEM) {
                        if (msg->dat2==workerdat->follow_cn && !workerdat->hassalt && !workerdat->useitem && ppd->useitemflag) {
                                workerdat->useitem=msg->dat3;
                                ppd->useitemflag=0;
                        }
                }

                standard_message_driver(cn,msg,1,1);
                remove_message(cn,msg);
	}

        // monastery action of worker
        if (workerdat->leftmonastery && workerdat->leftmonastery+10*TICKS<ticker) {
                if (in_monastery(ch[cn].x,ch[cn].y)) {
                        if (workerdat->hassalt && !workerdat->useitem) workerdat->useitem=map[saltbag_itemx+saltbag_itemy*MAXMAP].it;
                        if (!workerdat->hassalt && !workerdat->useitem) workerdat->useitem=map[door_itemx+door_itemy*MAXMAP].it;
                }
        }
        else {
                if (!workerdat->leftmonastery && !in_monastery(ch[cn].x,ch[cn].y)) workerdat->leftmonastery=ticker;
        }

        if (workerdat->hassalt && ch[cn].speed_mode!=SM_STEALTH) ch[cn].speed_mode=SM_STEALTH;
        if (!workerdat->hassalt && ch[cn].speed_mode!=SM_NORMAL) ch[cn].speed_mode=SM_NORMAL;
        if (workerdat->hassalt && ch[cn].hp<ch[cn].value[1][V_HP]*POWERSCALE && ch[cn].speed_mode!=SM_NORMAL) ch[cn].speed_mode=SM_NORMAL;

        // fighting
        fight_driver_update(cn);
        if (ch[cn].hp>20*POWERSCALE) { if (fight_driver_attack_visible(cn,0)) return; }
        else {  if (fight_driver_flee(cn)) return; }
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;

        if ((ch[cn].flags&CF_INVISIBLE)) {
                if (ticker>workerdat->turnvisible) {
                        ch[cn].flags&=~CF_INVISIBLE;
                }
                else if (move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,0)) return;
        }
        else if (workerdat->useitem) {
                if (use_driver(cn,workerdat->useitem,0)) return;
        }
        else if (ticker>workerdat->waituntil) {
                if (move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,3)) return;
        }

        // turn to owner
        dir=offset2dx(ch[cn].x,ch[cn].y,ch[workerdat->follow_cn].x,ch[workerdat->follow_cn].y);
        if (ch[cn].dir!=dir) turn(cn,dir);

        do_idle(cn,TICKS/8); // they need to be fast, otherwise they act a bit stupid (easy solution. swap driver cause some deadlocks)
}
Ejemplo n.º 11
0
void monk_govida_driver(int cn, int ret, int lastact)
{
        do_idle(cn,TICKS/2);
}
Ejemplo n.º 12
0
char doRegular(char expand, char c)
{
    char toReturn;
    int i;
    int done = 0;
    label doorinfo;

    toReturn = FALSE;

    for (i = 0; !expand && i < MAXEXTERN && extCmd[i].name[0]; ++i) {
        if (c == toupper(extCmd[i].name[0]) && (onConsole || !extCmd[i].local)) {
            done = 1;
            mPrintf("\b%s", extCmd[i].name);
            doCR();
            if (changedir(cfg.aplpath) == ERROR) {
                mPrintf("  -- Can't find application directory.\n\n");
                changedir(cfg.homepath);
            }
        /* apsystem(extCmd[i].command); */
            sprintf(doorinfo, "DORINFO%d.DEF", onConsole ? 0 : userdat.apl_com);
            extFmtRun(extCmd[i].command, doorinfo);
        }
    }
    if (!done) {
        switch (c) {

            case 'S':
                if (gl_user.sysop && expand) {
                    mPrintf("\b\bSysop Menu");
                    doCR();
                    doSysop();
                } else {
                    toReturn = TRUE;
                }
                break;

            case 'A':
                if (gl_user.aide) {
                    doAide(expand, 'E');
                } else {
                    toReturn = TRUE;
                }
                break;

            case 'C':
                doChat(expand, '\0');
                break;
            case 'D':
                doDownload(expand);
                break;
            case 'E':
                doEnter(expand, 'm');
                break;
            case 'F':
                doRead(expand, 'f');
                break;
            case 'G':
                doGoto(expand, FALSE);
                break;
            case 'H':
                doHelp(expand);
                break;
            case 'I':
                doIntro();
                break;
            case 'J':
                mPrintf("\bJump back to ");
                unGotoRoom();
                break;
            case 'K':
                doKnown(expand, 'r');
                break;
            case 'L':
                if (!loggedIn) {
                    doLogin(expand);
                } else {
                    if (!getYesNo(confirm, 0))
                        break;
                    doLogout(expand, 's');
                    doLogin(expand);
                }
                break;
            case 'N':
            case 'O':
            case 'R':
                doRead(expand, tolower(c));
                break;

            case 'B':
                doGoto(expand, TRUE);
                break;
            case 'T':
                doLogout(expand, 'q');
                break;
            case 'U':
                doUpload(expand);
                break;
            case 'X':
                if (!expand) {
                    doEnter(expand, 'x');
                } else {
                    doXpert();
                }
                break;

            case '=':
            case '+':
                doNext();
                break;
            case '\b':
                mPrintf("  ");
            case '-':
                doPrevious();
                break;

            case ']':
            case '>':
                doNextHall();
                break;
            case '[':
            case '<':
                doPreviousHall();
                break;
            case '~':
                mPrintf("\bAnsi %s\n ", gl_term.ansiOn ?
					gl_str.off : gl_str.on);
                gl_term.ansiOn = !gl_term.ansiOn;
                break;

            case '!':
                mPrintf("\bIBM Graphics %s\n ", gl_term.IBMOn ?
					gl_str.off:gl_str.on);
                gl_term.IBMOn = !gl_term.IBMOn;
                break;

            case '?':
                nextmenu("mainopt", &(cfg.cnt.mainopttut), 1);
				listExterns();
                break;

            case 0:     /* never gets here in shell mode... */
                if (newCarrier) {
                    greeting();

                    if (cfg.forcelogin) {
                        doCR();
                        doCR();
                        i = 0;
                        while (!loggedIn && gotCarrier()) {
                            doLogin(2);
                            if (++i > 3) {
                                Initport();
                                toReturn = TRUE;
                                break;
                            }
                        }
                    }
                    newCarrier = FALSE;
                }
                if (logBuf.lbflags.NODE && loggedIn) {
                    net_slave();

                    haveCarrier = FALSE;
                    modStat = FALSE;
                    newCarrier = FALSE;
                    justLostCarrier = FALSE;
                    onConsole = FALSE;
                    disabled = FALSE;
                    callout = FALSE;

                    delay(2000);

                    Initport();

                    cfg.callno++;
                    terminate(FALSE, FALSE);
                }
                if (justLostCarrier || ExitToMsdos) {
                    justLostCarrier = FALSE;
                    if (loggedIn)
                        terminate(FALSE, FALSE);
                }
                break;      /* irrelevant value */

            default:
                toReturn = TRUE;
                break;
        }
    }
    /* if they get unverified online */
    if (logBuf.VERIFIED)
        terminate(FALSE, FALSE);

    /* update25();	*/
	do_idle(0);
    return toReturn;
}
Ejemplo n.º 13
0
void lostdwarf_driver(int cn,int ret,int lastact)
{
	struct lostdwarf_data *dat;
	struct staffer_ppd *ppd;
        int co,in;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_LOSTDWARFDRIVER,sizeof(struct lostdwarf_data));
	if (!dat) return;	// oops...

	if ((ch[cn].flags&CF_INVISIBLE) && dat->invis_tick<ticker) {
		ch[cn].flags&=~CF_INVISIBLE;
		set_sector(ch[cn].x,ch[cn].y);
	}

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CREATE) {
                        if (ch[cn].arg) {
				dat->nr=atoi(ch[cn].arg);
			}
		}

		// did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*60) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			quiet_say(cn,"I hope you have a dwarven recall scroll for me! If not, be off with you!");
			dat->last_talk=ticker;

		}

                // got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;
                        if ((in=ch[cn].citem)) {	// we still have it
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
				
				if (ppd && ppd->dwarfchief_state<=3 && dat->nr==1 && it[in].ID==IID_DWARFRECALL1) {
					ppd->dwarfchief_state=4;
					say(cn,"Thank you for saving me, %s. I got so hungry I almost ate my beard.",ch[co].name);
					log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s uses a scroll of recall and vanishes.",ch[cn].name);
					ch[cn].flags|=CF_INVISIBLE;
					dat->invis_tick=ticker+TICKS*30;
					set_sector(ch[cn].x,ch[cn].y);
				}

				if (ppd && ppd->dwarfchief_state>=5 && ppd->dwarfchief_state<=6 && dat->nr==2 && it[in].ID==IID_DWARFRECALL2) {
					ppd->dwarfchief_state=7;
					say(cn,"Thank you for saving me, %s. I got so hungry I almost ate my boots.",ch[co].name);
					log_char(co,LOG_SYSTEM,0,"You notice that the dwarf's beard looks somewhat thin.");
					log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s uses a scroll of recall and vanishes.",ch[cn].name);
					ch[cn].flags|=CF_INVISIBLE;
					dat->invis_tick=ticker+TICKS*30;
					set_sector(ch[cn].x,ch[cn].y);
				}

				if (ppd && ppd->dwarfchief_state>=8 && ppd->dwarfchief_state<=9 && dat->nr==3 && it[in].ID==IID_DWARFRECALL3) {
					ppd->dwarfchief_state=10;
					say(cn,"Thank you for saving me, %s. I got so hungry I almost ate my pick-axe.",ch[co].name);
					log_char(co,LOG_SYSTEM,0,"You notice that the dwarf is barefoot.");
					log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s uses a scroll of recall and vanishes.",ch[cn].name);
					ch[cn].flags|=CF_INVISIBLE;
					dat->invis_tick=ticker+TICKS*30;
					set_sector(ch[cn].x,ch[cn].y);
				}

				if (ppd && ppd->dwarfchief_state>=11 && ppd->dwarfchief_state<=12 && dat->nr==4 && it[in].ID==IID_DWARFRECALL4) {
					ppd->dwarfchief_state=13;
					say(cn,"Thank you for saving me, %s. I got so hungry I did eat my pick-axe.",ch[co].name);
                                        log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s uses a scroll of recall and vanishes.",ch[cn].name);
					ch[cn].flags|=CF_INVISIBLE;
					dat->invis_tick=ticker+TICKS*30;
					set_sector(ch[cn].x,ch[cn].y);
				}
			
				// let it vanish, then
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;

        do_idle(cn,TICKS);

}
Ejemplo n.º 14
0
void dwarfshaman_driver(int cn,int ret,int lastact)
{
	struct dwarfshaman_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_DWARFSHAMANDRIVER,sizeof(struct dwarfshaman_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->dwarfshaman_state) {
					case 0:         quiet_say(cn,"Welcome to Grimroot stranger. To make it here you must have battled some strong foes, though they're nothing compared to what you're about to face, should you accept the quest I am about to give you.");
							questlog_open(co,51);
							ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 1:		quiet_say(cn,"But before I give you the quest, I want to see if you can fight the lizards you will be facing. Bring me back 9 lizard's teeth, and I will see that as proof of your strength.");
                                                        ppd->dwarfshaman_state++; didsay=1;
							break;
                                        case 2:         break;	// waiting for teeth
					
					case 3:		if (questlog_isdone(co,52)) { ppd->dwarfshaman_state=6; break; }
							quiet_say(cn,"Ah! I see you've come back with all your teeth, and those of the lizards. I guess you are strong enough after all to do the quest I am about to give you. You see, I've seen the lizards come out with brown berries out of the water.");
							questlog_open(co,52);
                                                        ppd->dwarfshaman_state++; didsay=1;
                                                        break;
                                        case 4:		quiet_say(cn,"Since I hate water, I need others like you to grab them for me. If you want to breath underwater, you will have to combine 3 flowers. I'll leave it up to you to figure out which ones. Now go get me 9 brown berries!");
                                                        ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 5:		break; // waiting for berries
					
					case 6:		if (questlog_isdone(co,53)) { ppd->dwarfshaman_state=10; break; }
							quiet_say(cn,"It's good that you can swim, you have no idea how much I hate water. Thanks for the berries. As I suspected, they seem to have magic properties, which I may be able to use.");
							questlog_open(co,53);
							ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 7:		quiet_say(cn,"Also, I managed to learn some of the lizard's tongue, and overheard them talking in fear of an 'elite lizard'... If you can find it and bring it's head to me, I can learn more about these lizards, and why they're so varied.");
                                                        ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 8:		break; // waiting for elite head
					
					case 9:		quiet_say(cn,"This is quite amazing! The reason these lizards are so varied is due to them being able to somehow absorb magical energy. To much of it seems to affect their mind however, as was the case with this elite lizard.");
							ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 10:	quiet_say(cn,"Thank you for helping out! I guess you are sturdier than you look, even though your kind looks skinnier than a dwarven skeleton!");
                                                        ppd->dwarfshaman_state++; didsay=1;
                                                        break;
					case 11:	break; // all done

				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->dwarfshaman_state<=2) { dat->last_talk=0; ppd->dwarfshaman_state=0; }
                                                        if (ppd && ppd->dwarfshaman_state>=3 && ppd->dwarfshaman_state<=5) { dat->last_talk=0; ppd->dwarfshaman_state=3; }
							if (ppd && ppd->dwarfshaman_state>=6 && ppd->dwarfshaman_state<=8) { dat->last_talk=0; ppd->dwarfshaman_state=6; }
							if (ppd && ppd->dwarfshaman_state>=9 && ppd->dwarfshaman_state<=11) { dat->last_talk=0; ppd->dwarfshaman_state=9; }
                                                        break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->dwarfshaman_state=0; ppd->dwarfshaman_count=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;
			
			ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if ((in=ch[cn].citem)) {	// we still have it
				if (it[in].ID==IID_LIZARDTOOTH && ppd && ppd->dwarfshaman_state<3) {
					ppd->dwarfshaman_count++;
					if (ppd->dwarfshaman_count>=9) {
						ppd->dwarfshaman_state=3;
						ppd->dwarfshaman_count=0;
						dat->last_talk=0;
						questlog_done(co,51);						
					} else {
						quiet_say(cn,"%d done, %d to go.",ppd->dwarfshaman_count,9-ppd->dwarfshaman_count);
					}
				} else if (it[in].ID==IID_BROWNBERRY && ppd && ppd->dwarfshaman_state>=3 && ppd->dwarfshaman_state<=5) {
					ppd->dwarfshaman_count++;
					if (ppd->dwarfshaman_count>=9) {
						ppd->dwarfshaman_state=6;
						ppd->dwarfshaman_count=0;
						dat->last_talk=0;
						questlog_done(co,52);
					} else {
						quiet_say(cn,"%d done, %d to go.",ppd->dwarfshaman_count,9-ppd->dwarfshaman_count);
					}
				} else if (it[in].ID==IID_LIZARDHEAD && ppd && ppd->dwarfshaman_state>=6 && ppd->dwarfshaman_state<=8) {
                                        ppd->dwarfshaman_state=9;
					dat->last_talk=0;
					questlog_done(co,53);
					destroy_item_byID(co,IID_LIZARDHEAD);
				} else if (give_char_item(co,in)) {
					quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
					ch[cn].citem=0;
				}
			
				// let it vanish, then
				if (ch[cn].citem) destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Ejemplo n.º 15
0
/************************************************************************
 *      main() Initialize & start citadel
 ************************************************************************/
void main(int argc, char *argv[])
{
    int i, cfg_ctdl = FALSE;
    long b;
    char init_baud;
    static char prompt[92];
    char *envprompt;

    cfg.bios = 1;
	cit_init_timer();			/* initialize cit_time() and cit_timer()	*/
    cfg.attr = 7;       		/* logo gets white letters                  */
    setscreen();				/* initialize screen system					*/
	memset(&parm,0,sizeof(parm));
    for (i = 1; i < argc; i++) {
        if (argv[i][0] == '/'
        || argv[i][0] == '-') {
            switch (tolower(argv[i][1])) {
#ifndef ATARI_ST
                case 'd':       /* DesqView/TopView     */
                    parm.dv = 1;
                    cPrintf("DesqView/TopView mode\n");
                    break;

                case 'b':       /* baud rate (for shell) */
                    if (argv[i + 1]) {
						b = atol(argv[++i]);
                        for (init_baud = 0; bauds[init_baud]; ++init_baud)
                            if (bauds[init_baud] == b) {
                                parm.baud = init_baud;
                                cPrintf("Initial baud rate fixed at %ld\n", b);
                                break;
							}
                    }
                    break;
				case 'm':
					parm.memcheck = !parm.memcheck;
					break;
#endif
                case 'c':       /* Configure system     */
                    cfg_ctdl = TRUE;
                    break;

                case 'p':       /* pace output          */
                    if (argv[i + 1]) {
                        parm.pace = atoi(argv[++i]);
                        cPrintf("Output pacing %d\n", parm.pace);
                    }
                    break;

                case 's':       /* run in shell from another BBS (door).        */
                    cPrintf("Shell mode\n");
                    parm.door = TRUE;
                    break;
/*#ifndef ATARI_ST*/
#ifndef FLOPPY
                case 'e':       /* use EMS                      */
                    if (_OvrInitEms(0, 0, 0)) {
                        cPrintf("EMS memory initialization failed!\n");
                        parm.ems = 1;
                    }
                    break;
#endif
/*#endif*/
				case 'v':       /* just do events       */
                    parm.events = 1;
                    break;
/*#ifndef ATARI_ST*/
#ifndef FLOPPY
                case 'x':       /* use exteneded memory */
					if (_OvrInitExt(0, 0))
                        cPrintf("Extended memory initialization failed!\n");
                    parm.ext = 1;
                    break;
#endif
/*#endif*/
				case 'l':		/* log in user */
                    if (argv[i + 1]) {
						parm.login = argv[++i];
						cPrintf("Auto-login\n");
					}
					break;

				case 'u':		/* log in user */
                    if (argv[i + 1]) {
						parm.user = argv[++i];
						cPrintf("Auto-login %s\n", parm.user);
					}
					break;
					
                default:
                    cPrintf("\nUnknown commandline switch '%s'.\n", argv[i]);
                    cPrintf("Valid DOS command line switches:\n");
                    cPrintf("    -b baud   Starting baud rate (300-19200)\n");
                    cPrintf("    -c        Read configuration files\n");
                    cPrintf("    -d        DesqView/TopView\n");
#ifndef FLOPPY
                    cPrintf("    -e        Use EMS memory for overlays\n");
#endif
					cPrintf("    -l str    Log in using initials;password in str\n");
					cPrintf("    -m        Memory check during idle time, start\n");
                    cPrintf("    -p num    Set output pacing to num\n");
                    cPrintf("    -s        Run as a shell from another BBS\n");
					cPrintf("    -u 'name' Log in using specifed user name");
                    cPrintf("    -v        Just run cron events\n");
#ifndef FLOPPY
					cPrintf("    -x        Use extended memory for overlays (386/486 only!)\n");
#endif
                    exit(1);
            }
        }
    }

    if (cfg_ctdl)				/* force reconfigure?						*/
        unlink("etc.tab");

    logo();						/* prints out system logo                   */

    if (cit_time() < 607415813L) {
        cPrintf("\n\nPlease set your time and date!\n");
        exit(1);
    }
	/* set prompt for shells */
    envprompt = getenv("PROMPT");
	if (!envprompt)
		envprompt = "$p$g";
    sprintf(prompt, "PROMPT=\r\nType EXIT to return to FredCit\r\n%s", envprompt);
    if (putenv(prompt)) {
        cPrintf("\n\nCan not set DOS prompt!\n");
		delay (5000);
	}
	/* initialize citadel */
    initCitadel();

    if (parm.baud) {
        cfg.initbaud = parm.baud;
        baud(cfg.initbaud);
    }
	if (parm.door) {
		detectflag = 1;
//		carrier();
//		if (haveCarrier) {
//			carrdetect();
//			newCarrier = 1;		/* make hello blurb show up */
//		}
	}
    greeting();

	sysReq = FALSE;

	if (cfg.f6pass[0])
		ConLock = TRUE;

	if (parm.dv) {
		cfg.bios = 1;
		directvideo = 0;
	}

	if (parm.login) {
		normalizeString(parm.login);	/* normalize string in environment */
		login(parm.login,NULL);
	} else if (parm.user && !loggedIn) {
		normalizeString(parm.user);	/* normalize string in environment */
		if (findPerson(parm.user, &lBuf) != ERROR)
			login(lBuf.lbin,lBuf.lbpw);
	}

		/* read in door interface files */
	if (parm.door) {
		readDoorFiles(0);
	}
	/* update25();	*/
	do_idle(0);

	/* install critical error handler */
	harderr(cit_herror_handler);
	
	/* execute main command loop */
    if (!parm.events)
        command_loop();
    else {
        do_cron_loop();
    }

    exitcitadel();
}
Ejemplo n.º 16
0
void yoatin_driver(int cn,int ret,int lastact)
{
	struct yoatin_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_YOATINDRIVER,sizeof(struct yoatin_data));
	if (!dat) return;	// oops...

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->yoatin_state) {					
					case 0:         quiet_say(cn,"Greetings stranger!");
							questlog_open(co,39);
							ppd->yoatin_state++; didsay=1;
                                                        break;
                                        case 1:		quiet_say(cn,"Wait...I recognize you from the description my brother gave - you must be %s!",ch[co].name);
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 2:		quiet_say(cn,"My brother's name is Yoakin. It seems you did him a great service slaying the bears of Cameron.");
                                                        ppd->yoatin_state++; didsay=1;
                                                        break;
					case 3:		quiet_say(cn,"Mayhap you could assist me with a problem I have?");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 4:		quiet_say(cn,"A family from the town beyond this forest has asked me to hunt down the bear that killed their son.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 5:		quiet_say(cn,"I am not quite the hunter my brother is and well... to be frank, bears scare the living daylights out of me.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 6:		quiet_say(cn,"If you could fetch me proof of the bear being slain, I would reward thee greatly.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 7:		quiet_say(cn,"Take care as you travel! The whole forest is full of bears and bear caves.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 8:		break; // waiting for bear to die
					case 9:		break; // all done
					
					
				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->yoatin_state<=8) { dat->last_talk=0; ppd->yoatin_state=0; }
                                                        break;				
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->yoatin_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it

				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

				if (it[in].ID==IID_STAFF_BEARHEAD && ppd && ppd->yoatin_state<=8) {
					quiet_say(cn,"Thank you %s! This will be perfect proof. Here, take my belt, you are clearly the greater hunter!",ch[co].name);
					questlog_done(co,39);
					destroy_item_byID(co,IID_STAFF_BEARHEAD);
                                        if ((in=create_item("WS_Hunter_Belt"))) {
						if (!give_char_item(co,in)) destroy_item(in);						
					}
                                        ppd->yoatin_state=9;
				} else {
					say(cn,"Thou hast better use for this than I do. Well, if there is a use for it at all.");
                                        if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
                                        ch[cn].citem=0;
				}
				
				// let it vanish, then
				if (ch[cn].citem) {
					destroy_item(ch[cn].citem);
					ch[cn].citem=0;
				}
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	dat->amgivingback=0;

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Ejemplo n.º 17
0
void aristocrat_driver(int cn,int ret,int lastact)
{
	struct aristocrat_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_ARISTOCRATDRIVER,sizeof(struct aristocrat_data));
	if (!dat) return;	// oops...

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->aristocrat_state) {
					case 0:         quiet_say(cn,"Greetings stranger!");
							questlog_open(co,38);
							ppd->aristocrat_state++; didsay=1;
                                                        break;
                                        case 1:		quiet_say(cn,"Say! You look like quite a buoyant adventurer.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 2:		quiet_say(cn,"Oh no, I didn't mean it that way! Please don't growl at me!");
                                                        ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 3:		quiet_say(cn,"I was watching the local wildlife at a large lake north of here...");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
                                        case 4:		quiet_say(cn,"When one of the larger natives suddenly lurched out of the water and attacked me.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 5:		quiet_say(cn,"I managed to escape with my life, but alas my Amulet was lost.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 6:		quiet_say(cn,"I would reward you well if you could retrieve this family heirloom for me.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 7:		break; // waiting for amulet
					case 8:		break; // all done
				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->aristocrat_state<=7) { dat->last_talk=0; ppd->aristocrat_state=0; }
                                                        break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->aristocrat_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it

				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

				if (it[in].ID==IID_STAFF_ARIAMULET && ppd && ppd->aristocrat_state<=7) {
					int tmp;
                                        quiet_say(cn,"Yes! Many thanks adventurer! Please accept this reward.");
					tmp=questlog_done(co,38);
					destroy_item_byID(co,IID_STAFF_ARIAMULET);
					destroy_item_byID(co,IID_STAFF_ARIKEY);
                                        ppd->aristocrat_state=8;
					if (tmp==1 && (in=create_money_item(1000*100))) {
						if (!give_char_item(co,in)) destroy_item(in);						
					}
				} else {
					say(cn,"Thou hast better use for this than I do. Well, if there is a use for it at all.");
                                        if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
                                        ch[cn].citem=0;
				}
				
				// let it vanish, then
				if (ch[cn].citem) {
					destroy_item(ch[cn].citem);
					ch[cn].citem=0;
				}
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	dat->amgivingback=0;

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Ejemplo n.º 18
0
void professor_driver(int cn,int ret,int lastact)
{
	struct professor_driver_data *dat;
        int co,in;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_PROFDRIVER,sizeof(struct professor_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
                professor_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont offer to teach anyone not having the profession skill
			if (!ch[co].value[1][V_PROFESSION]) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			say(cn,"Hello %s! I am a professor at Aston University, and I °c4teach°c0 °c4%s°c0.",ch[co].name,prof[dat->nr].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;
                        ret=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co);
			switch(ret) {
				case 2:		switch(dat->quest) {
							case 0:		say(cn,"If thou wishest to learn the art of the %s, thou must pay %d gold coins and %d profession points. Say °c4learn°c0 if this is thy wish. Thou canst also °c4improve°c0 thy knowledge of this art for the fee of %d gold coins and %d profession points.",prof[dat->nr].name,dat->quest_option,prof[dat->nr].base,dat->improve_cost*prof[dat->nr].step,prof[dat->nr].step); break;
							default:	say(cn,"You've found bug #418a"); break;
						}
						break;
				case 3:		switch(dat->nr) {
							case P_ATHLETE:		say(cn,"The art of the athlete are fast, precise movements. Skilled athletes make better use of their endurance and move faster than untrained humans."); break;
							case P_ALCHEMIST:	say(cn,"The alchemist can create better potions, calling on the powers of the moons and the seasons at any time."); break;
							case P_MINER:		say(cn,"A skilled miner will make better use of every vein of precious metal he finds. He will also not exhaust as fast as an unskilled miner."); break;
							case P_ASSASSIN:	say(cn,"The assassin is especially skilled at attacking an enemy from the side or behind, and he can backstab an unware opponent from behind."); break;
							case P_THIEF:		say(cn,"A skilled thief can remain unseen even when next to another person. But when he uses this skill of stealth he cannot do anything but wait or walk, and the effort of remaining unseen will drain his endurance."); break;
							case P_LIGHT:		say(cn,"A master of light will receive a bonus to his basic abilities during the day. If he masters this skill he will also be able to see all undead creatures in the dark."); break;
							case P_DARK:		say(cn,"A master of dark will receive a bonus to his basic abilities during the night. If he masters this skill he will also be able to see all living creatures in the dark."); break;
							case P_TRADER:		say(cn,"A skilled trader will get better prices when dealing with merchants."); break;
							case P_MERCENARY:	say(cn,"Those skilled in the art of the mercenary will advance in military rank faster. They will also collect pay for their missions."); break;
							case P_CLAN:		say(cn,"A clan master has received special training in the art of clan warfare. He will be at an advantage in any fight in the clan catacombs."); break;
							case P_HERBALIST:	say(cn,"A herbalist knows the art of making plants ripe faster. Any flower, berry or mushroom he picks will grow back in less time."); break;

							default: 		say(cn,"You've found bug #418b"); break;
						}
						break;
				case 4:		switch(dat->quest) {
							case 0:		if (ch[co].gold<dat->quest_option*100) { say(cn,"But thou cannot afford my fee of %dG.",dat->quest_option); break; }
									if (!learn_prof(cn,co,dat->nr)) break;
									ch[co].gold-=dat->quest_option*100;
									ch[co].flags|=CF_ITEMS;
									break;
							default:	say(cn,"You've found bug #418a"); break;
						}
						break;
				case 5:		if (ch[co].gold<dat->improve_cost*prof[dat->nr].step*100) { say(cn,"But thou cannot afford my fee of %dG.",dat->improve_cost*prof[dat->nr].step); break; }
						if (!improve_prof(cn,co,dat->nr)) break;
						ch[co].gold-=dat->improve_cost*prof[dat->nr].step*100;
						ch[co].flags|=CF_ITEMS;
                                                break;
			}

		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		

        do_idle(cn,TICKS);
}
Ejemplo n.º 19
0
void merchant_driver(int cn,int ret,int lastact)
{
	struct merchant_driver_data *dat;
        int co,in,n;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_MERCHANTDRIVER,sizeof(struct merchant_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
		dat->open=6; dat->close=23;
		merchant_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}
	if (!ch[cn].store) {
		if (dat->pricemulti) create_store(cn,dat->ignore,dat->pricemulti);
		else create_store(cn,dat->ignore,400);
		if (dat->special) {
			for (n=0; n<5; n++) add_special_store(cn);
		}
	}
	
	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			quiet_say(cn,"Hello %s! If you'd like to trade, say: '°c4%s, trade°c0!",ch[co].name,ch[cn].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

			if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk
				if (strcasestr((char*)msg->dat2,ch[cn].name) &&
				    strcasestr((char*)msg->dat2,"trade")) {
					/*if (abuser(ch[co].ID)) {
						switch(RANDOM(3)) {
                                                        case 0:		murmur(cn,"I hate cheaters."); break;
							case 1:		emote(cn,"clenches his fists and stares at %s.",ch[co].name); break;
							case 2:		murmur(cn,"I wish the cheaters would leave me alone."); break;
						}
					}*/
					ch[co].merchant=cn;
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (dat->dayx) {	// we have day / night positions
		if (!opening_time(dat->open,dat->close)) {	// we're closed
                        if (dat->doorx && !is_closed(dat->doorx,dat->doory)) {	// door is still open
				if (!is_room_empty(dat->storefx,dat->storefy,dat->storetx,dat->storety)) {	// store is not empty
					quiet_say(cn,"We're closing, please leave now!");
					do_idle(cn,TICKS);
					return;
				} else {
					if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
					do_idle(cn,TICKS);
					return;
				}
			}
			if (secure_move_driver(cn,dat->nightx,dat->nighty,dat->nightdir,ret,lastact)) return;
		} else {	// we're open
                        if (dat->doorx && is_closed(dat->doorx,dat->doory)) {	// door is still closed
                                if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
				do_idle(cn,TICKS);
				return;			
			}

			if (secure_move_driver(cn,dat->dayx,dat->dayy,dat->daydir,ret,lastact)) return;			
		}
	} else {		// just one position
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		
	}

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(11)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
			case 5:		murmur(cn,"Beware of the fire snails!"); break;	
			case 6:		murmur(cn,"Ishtar! Oh, what has become of us!"); break;
			case 7:		murmur(cn,"The demons will get you."); break;
			case 8:		emote(cn,"scratches %s back",hisname(cn)); break;
			case 9:		if (map[ch[cn].x+ch[cn].y*MAXMAP].flags&MF_INDOORS) emote(cn,"stares at the ceiling");
					else emote(cn,"stares at the sky");
					break;
			case 10:	emote(cn,"twiddles %s thumbs",hisname(cn)); break;

			default:	break;
		}
		
		dat->last_talk=ticker;
	}
	if (dat->special && ticker>dat->lastadd+TICKS*60*60*12) {
		add_special_store(cn);
		dat->lastadd=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
Ejemplo n.º 20
0
//
// Read a line of input from the user
// Return:
//        _GETS_OK: 'n' valid characters received
//       _GETS_GDB: '$' (GDB lead-in)
//   _GETS_TIMEOUT: No input before timeout
//     _GETS_CTRLC: ^C typed
//
// if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
//   Command line history support
//    ^P - Select previous line from history
//    ^N - Select next line from history
//    ^A - Move insertion [cursor] to start of line
//    ^E - Move cursor to end of line
//    ^B - Move cursor back [previous character]
//    ^F - Move cursor forward [next character]
// "standard" arrow keys work as well
//   left  ^[[D      == ^B
//   right ^[[C      == ^F
//   up    ^[[A      == ^P
//   down  ^[[B      == ^N
//   home  ^[[H/^[1~ == ^A
//   end   ^[[F/^[OF == ^E
//   del   ^[3~      == ^D
//
int
_rb_gets_preloaded(char *buf, int buflen, int timeout)
{
    char *ip = buf;   // Insertion point
    char *eol = buf;  // End of line
    char c;
    bool res = false;
    static char last_ch = '\0';
    int _timeout;
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
    int   _index = _cl_index;  // Last saved line
    char *xp;
#ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
    int   ansi_state = 0;      // Used to drive ANSI parser
    char  ansi_char = '\0';
#endif
#endif

    // Display current buffer data
    while (*eol) {
        mon_write_char(*eol++);
    }
    ip = eol;

    while (true) {
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
        if (getc_script(&c))
            do_idle(false);
        else
#endif
        if ((timeout > 0) && (eol == buf)) {
#define MIN_TIMEOUT 50
            _timeout = timeout > MIN_TIMEOUT ? MIN_TIMEOUT : timeout;
            mon_set_read_char_timeout(_timeout);
            while (timeout > 0) {
                res = mon_read_char_with_timeout(&c);
                if (res) {
                    // Got a character
                    do_idle(false);
                    break;
                }
                timeout -= _timeout;
            }
            if (res == false) {
                do_idle(true);
                return _GETS_TIMEOUT;  // Input timed out
            }
        } else {
            mon_read_char(&c);
        }
        *eol = '\0';
#define CTRL(c) ((c)&0x1F)
#ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
        // Special handling of ANSI keyboard sequences (arrows, etc)
        if (c == '\x1B') {
            // Leadin for ANSI keyboard sequence
            ansi_state = 1;
            continue;
        }
        switch (ansi_state) {
        case 0:
            // No ANSI sequence in progress
            break;
        case 1:
            // ESC seen, look for '['
            if (c == '[') {
                ansi_state = 2;
            } else if (c == 'O') {
                ansi_state = 4;
            } else {
                // Handle bad sequences?
                ansi_state = 0;
            }
            continue;
        case 2:
            // ESC+[ seen, process key
            ansi_state = 0;
            switch (c) {
            case 'A':
                c = CTRL('P');
                break;
            case 'B':
                c = CTRL('N');
                break;
            case 'C':
                c = CTRL('F');
                break;
            case 'D':
                c = CTRL('B');
                break;
            case 'F':
                c = CTRL('E');
                break;
            case 'H':
                c = CTRL('A');
                break;
            case '1':
                ansi_char = CTRL('A');
                ansi_state = 3;
                continue;
            case '3':
                ansi_char = CTRL('D');
                ansi_state = 3;
                continue;
            default:
                // Handle bad sequences?
                continue;
            }
            break;
        case 3:
            // Sequences like ^[[1~ == ^H
            ansi_state = 0;
            if (c == '~') {
                c = ansi_char;
            } else {
                // Handle bad sequences?
                continue;
            }
            break;
        case 4:
            // Sequences like ^[OF == ^E
            ansi_state = 0;
            if (c == 'F') {
                c = CTRL('E');
            } else {
                // Handle bad sequences?
                continue;
            }
            break;
        }
#endif
        switch (c) {
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
        case CTRL('P'):
            // Fetch the previous line into the buffer
            if (_index >= 0) {
                // Erase the previous line [crude]
                while (ip != buf) {
                    mon_write_char('\b');
                    mon_write_char(' ');
                    mon_write_char('\b');
                    ip--;
                }
                strcpy(buf, _cl_lines[_index]);
                while (*ip) {
                    mon_write_char(*ip++);
                }
                eol = ip;
                // Move to previous line
                _index--;
                if (_index < 0) {
                    _index = _cl_max_index;
                }
            } else {
                mon_write_char(0x07);  // Audible bell on most devices
            }
            break;
        case CTRL('N'):
            // Fetch the next line into the buffer
            if (_index >= 0) {
                if (++_index > _cl_max_index) _index = 0;
                // Erase the previous line [crude]
                while (ip != buf) {
                    mon_write_char('\b');
                    mon_write_char(' ');
                    mon_write_char('\b');
                    ip--;
                }
                strcpy(buf, _cl_lines[_index]);
                while (*ip) {
                    mon_write_char(*ip++);
                }
                eol = ip;
            } else {
                mon_write_char(0x07);  // Audible bell on most devices
            }
            break;
        case CTRL('B'): 
            // Move insertion point backwards
            if (ip != buf) {
                mon_write_char('\b');
                ip--;
            }
            break;
        case CTRL('F'):
            // Move insertion point forwards
            if (ip != eol) {
                mon_write_char(*ip++);
            }
            break;
        case CTRL('E'):
            // Move insertion point to end of line
            while (ip != eol) {
                mon_write_char(*ip++);
            }
            break;
        case CTRL('A'):
            // Move insertion point to beginning of line
            if (ip != buf) {
                xp = ip;
                while (xp-- != buf) {
                    mon_write_char('\b');
                }
            }
            ip = buf;
            break;
        case CTRL('K'):
            // Kill to the end of line
            if (ip != eol) {
                xp = ip;
                while (xp++ != eol) {
                    mon_write_char(' ');
                }
                while (--xp != ip) {
                    mon_write_char('\b');
                }
                eol = ip;
            }
            break;
        case CTRL('D'):
            // Erase the character under the cursor
            if (ip != eol) {
                xp = ip;
                eol--;
                while (xp != eol) {
                    *xp = *(xp+1);
                    mon_write_char(*xp++);
                }
                mon_write_char(' ');  // Erases last character
                mon_write_char('\b');
                while (xp-- != ip) {
                    mon_write_char('\b');
                }
            }
            break;
#endif // CYGNUM_REDBOOT_CMD_LINE_EDITING
        case CTRL('C'): // ^C
            // Abort current input
            diag_printf("^C\n");
            *buf = '\0';  // Nothing useful in buffer
            return _GETS_CTRLC;
        case '\n':
        case '\r':
            // If previous character was the "other" end-of-line, ignore this one
            if (((c == '\n') && (last_ch == '\r')) ||
                ((c == '\r') && (last_ch == '\n'))) {
                c = '\0';
                break;
            }
            // End of line
	    if (console_echo) {
                mon_write_char('\r');
                mon_write_char('\n');
	    }
            last_ch = c;
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
            if (cmd_history) {
                // History handling - only when enabled
#ifdef CYGBLD_REDBOOT_CMD_LINE_HISTORY
		expand_history(buf);
#endif
		if (*buf != '\0') {
		    if (++_cl_index == _CL_NUM_LINES) {
                        _cl_index = 0;
                    }
		    if (_cl_index > _cl_max_index) _cl_max_index = _cl_index;
		    strcpy(_cl_lines[_cl_index], buf);
                    _cl_real_index++;
		}
            }
#endif
            return _GETS_OK;
        case '\b':
        case 0x7F:  // DEL
            if (ip != buf) {
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
                if (ip != eol) {
                    ip--;
                    mon_write_char('\b');
                    xp = ip;
                    while (xp != (eol-1)) {
                        *xp = *(xp+1);
                        mon_write_char(*xp++);
                    }
                    mon_write_char(' ');  // Erases last character
                    mon_write_char('\b');
                    while (xp-- != ip) {
                        mon_write_char('\b');
                    }
                } else {
                    if (console_echo) {
                        mon_write_char('\b');
                        mon_write_char(' ');
                        mon_write_char('\b');
                    }
                    ip--;
                }
                eol--;
#else
                if (console_echo) {
                    mon_write_char('\b');
                    mon_write_char(' ');
                    mon_write_char('\b');
                }
                ip--;
                eol--;
#endif
            }
            break;
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
        case '+': // fall through
        case '$':
            if (ip == buf || last_ch != '\\')
            {
                // Give up and try GDB protocol
                ungetDebugChar(c);  // Push back character so stubs will see it
                return _GETS_GDB;
            }
            if (last_ch == '\\') {
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
                if (ip == eol) {
                    // Just save \$ as $
                    eol = --ip;
                } else {
                    mon_write_char('\b');
                    *--ip = c;
                    mon_write_char(c);
                    break;
                }
#else
                ip--;  // Save \$ as $
#endif
            }
            // else fall through
#endif
        default:
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
            // If the insertion point is not at the end of line, make space for it
            if (ip != eol) {
                xp = eol;
                *++eol = '\0';
                while (xp != ip) {
                    *xp = *(xp-1);
                    xp--;
                }
            }
#endif
            if (console_echo) {
                mon_write_char((unsigned char)c);
            }
            if (ip == eol) {
                // Advance both pointers
                *ip++ = c;
                eol = ip;
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
            } else {
                // Just insert the character
                *ip++ = c;
                xp = ip;
                while (xp != eol) {
                    mon_write_char(*xp++);
                }
                while (xp-- != ip) {
                    mon_write_char('\b');
                }
#endif
            }
        }
        last_ch = c;
        if (ip == buf + buflen - 1) { // Buffer full
            *ip = '\0';
            return buflen;
        }
    }
}
Ejemplo n.º 21
0
void dwarfchief_driver(int cn,int ret,int lastact)
{
	struct dwarfchief_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_DWARFCHIEFDRIVER,sizeof(struct dwarfchief_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->dwarfchief_state) {
					case 0:         quiet_say(cn,"Welcome, stranger, to Grimroot, home of the dwarves. I would introduce you to our town further, but I have urgent matters to attend to.");
							questlog_open(co,47);
							ppd->dwarfchief_state++; didsay=1;
                                                        break;
					case 1:		quiet_say(cn,"Four of our miners have gone missing, one each in one of the 4 mine areas, and we can only think it's because of those bothersome golems...");
                                                        ppd->dwarfchief_state++; didsay=1;
							break;
                                        case 2:         quiet_say(cn,"If you wish, here's a scroll so you can help one of them. Give this one to the miner in the first section, then come back for another scroll for the next miner.");
                                                        ppd->dwarfchief_state++; didsay=1;
							if (!has_item(co,IID_DWARFRECALL1)) {
								in=create_item("dwarf_recall90");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 3:		break; // waiting for player to save first miner
					
					case 4:		questlog_done(co,47);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 5:		if (questlog_isdone(co,48)) { ppd->dwarfchief_state=8; break; }
							quiet_say(cn,"Not too bad for a human, you people are sturdier than I thought... Don't cheer up though, the miner in the next section is surrounded by stronger golems. Don't let them hurt your precious nails!");
							questlog_open(co,48);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall100");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 6:		break; // waiting for player to save second miner
					
					case 7:		questlog_done(co,48);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 8:		if (questlog_isdone(co,49)) { ppd->dwarfchief_state=11; break; }
							quiet_say(cn,"A job well done! It's that we have enough hands already, otherwise I'd ask you to go out there and mine for us. Anyway, back to business. Go and find the next miner, and you will be rewarded again.");
							questlog_open(co,49);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall110");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 9:		break; // waiting for player to save third miner
					
					case 10:	questlog_done(co,49);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 11:	if (questlog_isdone(co,50)) { ppd->dwarfchief_state=14; break; }
							quiet_say(cn,"Just in time! If you had been any later, he wouldn't have had his dinner, and trust me, you don't want to see a dwarf hungry, it's not a pretty sight. The fourth miner should be ok, he always packs more than the others, but do hurry and find him.");
							questlog_open(co,50);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall120");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 12:	break; // waiting for player to save fourth miner

					case 13:	questlog_done(co,50);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 14:	quiet_say(cn,"Thank you for saving the last one! You have been of great help to us. Now let's hope they can stay out of the hands of those golems once and for all. Those recall scrolls aren't cheap you know!");
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        break;
					case 15:	break; // all done

				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->dwarfchief_state<=3) { dat->last_talk=0; ppd->dwarfchief_state=0; }
                                                        if (ppd && ppd->dwarfchief_state>=5 && ppd->dwarfchief_state<=6) { dat->last_talk=0; ppd->dwarfchief_state=5; }
							if (ppd && ppd->dwarfchief_state>=8 && ppd->dwarfchief_state<=9) { dat->last_talk=0; ppd->dwarfchief_state=8; }
							if (ppd && ppd->dwarfchief_state>=11 && ppd->dwarfchief_state<=12) { dat->last_talk=0; ppd->dwarfchief_state=11; }
							if (ppd && ppd->dwarfchief_state>=14 && ppd->dwarfchief_state<=15) { dat->last_talk=0; ppd->dwarfchief_state=14; }
                                                        break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->dwarfchief_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
				if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
				ch[cn].citem=0;				
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Ejemplo n.º 22
0
/* -------------------------------------------------------------------- */
void fkey(void)
{
    char key;
    int oldIO, i;
    label string;
    unsigned space;

    key = (char) getch();
    while (kbhit())     /* flush keyboard buffer */
        getch();
    if (strcmpi(cfg.f6pass, "f6disabled") != SAMESTRING)
        if (ConLock == TRUE && key == K_A_L &&
        strcmpi(cfg.f6pass, "disabled") != SAMESTRING) {
            ConLock = FALSE;

            oldIO = whichIO;
            whichIO = CONSOLE;
            onConsole = TRUE;
            /* update25();	*/
			do_idle(0);
            string[0] = 0;
            getNormStr("System Password", string, NAMESIZE, NO_ECHO);
            if (strcmpi(string, cfg.f6pass) != SAMESTRING)
                ConLock = TRUE;
            whichIO = (BOOL) oldIO;
            onConsole = (BOOL) (whichIO == CONSOLE);
            /* update25();	*/
			do_idle(0);
            givePrompt();
            return;
        }
    if (ConLock && !gl_user.sysop && strcmpi(cfg.f6pass, "f6disabled") != SAMESTRING)
        return;

    switch (key) {
        case K_F1:
            drop_dtr();
            detectflag = FALSE;
            break;

        case K_F2:
            if (parm.door)
                ExitToMsdos = 1;
            else
                Initport();
            detectflag = FALSE;
            break;

        case K_F3:
            sysReq = (BOOL) (!sysReq);
            break;

        case K_F4:
            anyEcho = (BOOL) (!anyEcho);
            break;

        case K_F5:
            if (whichIO == CONSOLE)
                whichIO = MODEM;
            else
                whichIO = CONSOLE;

            onConsole = (BOOL) (whichIO == CONSOLE);
            break;

        case K_S_F6:
            if (!ConLock)
                gl_user.aide = (BOOL) (!gl_user.aide);
            break;

        case K_A_F6:
            if (!ConLock)
                gl_user.sysop = (BOOL) (!gl_user.sysop);
            break;

        case K_F6:
            if (gl_user.sysop || !ConLock)
                sysopkey = TRUE;
            break;

        case K_F7:
            cfg.noBells = !cfg.noBells;
            break;

        case K_A_C:
        case K_F8:
            chatkey = !chatkey;    /* will go into chat from main() */
            break;

        case K_F9:
            cfg.noChat = !cfg.noChat;
            chatReq = FALSE;
            break;

        case K_F10:
            help();
            break;

        case K_A_B:
            backout = !backout;
            break;

        case K_A_D:
            debug = !debug;
            break;

        case K_A_E:
            eventkey = TRUE;
            break;

        case K_A_L:
            if (cfg.f6pass[0] && strcmpi(cfg.f6pass, "f6disabled") != SAMESTRING)
                ConLock = (BOOL) (!ConLock);
            break;

        case K_A_M:
#ifndef ATARI_ST
            cPrintf("Free heap    %lXh (%lu.)\n", farcoreleft(), farcoreleft());
            space = _stklen - ((unsigned) 0xffff - _SP);
            cPrintf("Free stack   %Xh (%u.)\n", space, space);
#endif
            break;

        case K_A_P:
            if (printing) {
                printing = FALSE;
                fclose(printfile);
            } else {
                printfile = fopen(cfg.printer, "a");
                if (printfile) {
                    printing = TRUE;
                } else {
                    printing = FALSE;
                }
            }
            break;

        case K_A_T:
            gl_user.twit = (BOOL) (!gl_user.twit);
            break;

        case K_A_X:
            if (dowhat == MAINMENU || dowhat == SYSOPMENU) {
                if (loggedIn) {
                    i = getYesNo("Exit to MS-DOS", 0);
                } else {
                    doCR();
                    doCR();
                    mPrintf("Exit to MS-DOS");
                    doCR();
                    i = TRUE;
                }

                if (!i) {
                    if (dowhat == MAINMENU) {
                        givePrompt();
                    } else {
                        doCR();
                        mPrintf("Privileged function: ");
                    }
                    break;
                }
                ExitToMsdos = TRUE;
            }
            break;

		case K_PgDn:
			logBuf.credits -= 10;
            break;
			
		case K_PgUp:
			logBuf.credits += 10;
            break;
			
		case K_Lft:
            ungetch('-');
			getkey = 1;
            break;
			
		case K_Rgt:
            ungetch('=');
			getkey = 1;
            break;
			
		case K_Up:
            ungetch(']');
			getkey = 1;
            break;
			
		case K_Dwn:
            ungetch('[');
			getkey = 1;
            break;
			
        default:
            break;
    }

    /* update25();	*/
	do_idle(0);
}
Ejemplo n.º 23
0
void dwarfsmith_driver(int cn,int ret,int lastact)
{
	struct dwarfsmith_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0,in2;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_DWARFSMITHDRIVER,sizeof(struct dwarfsmith_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->dwarfsmith_state) {
					case 0:         quiet_say(cn,"Welcome to my smithy! If you are in need of my services, come to me and I will see what I can do for you. For now though, I'm afraid I can't do a whole lot.");
							ppd->dwarfsmith_state++; didsay=1;
                                                        break;
					case 1:         break;	// waiting for mold
					case 2:		break;	// waiting for silver
				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					//case 2:         if (ppd && ppd->dwarfsmith_state<=3) { dat->last_talk=0; ppd->dwarfsmith_state=0; }
                                                        //break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->dwarfsmith_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;
			
			ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if ((in=ch[cn].citem)) {	// we still have it
				if (it[in].ID==IID_LIZARDMOLD && ppd && ppd->dwarfsmith_state<=1) {
					ppd->dwarfsmith_state=2;
					ppd->dwarfsmith_type=it[in].drdata[0];
					quiet_say(cn,"What's this? A mold from the lizards? I guess I can make a key out of this, but I will need 5,000 silver to make it. You can't expect me to sacrifice my own ore for your adventuring!");
				} else if (it[in].driver==IDR_ENHANCE && it[in].drdata[0]==1 && *(unsigned int*)(it[in].drdata+1)==5000 && ppd && ppd->dwarfsmith_state==2) {
                                        quiet_say(cn,"There you go, one key for the adventurer.");
					switch(ppd->dwarfsmith_type) {
						case 1:		in2=create_item("lizard_elite_key1"); break;
						case 2:		in2=create_item("lizard_elite_key2"); break;
						case 3:		in2=create_item("lizard_elite_key3"); break;
						default:	in2=0; quiet_say(cn,"oops. bug # 3266/%d",ppd->dwarfsmith_type); break;
					}
					if (in2) {
						if (!give_char_item(co,in2)) destroy_item(in2);						
                                        }
					ppd->dwarfsmith_state=1;
					ppd->dwarfsmith_type=0;
					
				} else if (give_char_item(co,in)) {
					if (it[in].driver==IDR_ENHANCE) {
						if (it[in].drdata[0]!=1) quiet_say(cn,"I'll need silver, not any other material.");
						else if (*(unsigned int*)(it[in].drdata+1)!=5000) quiet_say(cn,"I'll need exactly 5000 units of silver.");
						else quiet_say(cn,"I'll need a mold first.");
					} else quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
					ch[cn].citem=0;
				}
			
				// let it vanish, then
				if (ch[cn].citem) destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Ejemplo n.º 24
0
void lab4_seyan_driver(int cn, int ret, int lastact)
{
	struct lab4_player_data *pd;
        static struct lab4_seyan_data datbuf;   // we only have one, so there is no need to use the memory system (?)
        struct lab4_seyan_data *dat=&datbuf;
        struct msg *msg,*next;
        int co;
        int talkdir=0,didsay=0;
        char *str;


        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_GIVE) {
                        if (!ch[cn].citem) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source
                        co=msg->dat1;

                        // players only
                        if (ch[co].flags&CF_PLAYER) {

                                // get lab ppd
                                pd=set_data(co,DRD_LAB4_PLAYER,sizeof(struct lab4_player_data));
                                if (!pd) { remove_message(cn,msg); continue; }

                                // check item
                                if (it[ch[cn].citem].ID==IID_LAB4_CROWN) {
                                        pd->seyan4got|=(1<<0);
                                        set_seyan_state(pd);
                                        if (dat->cv_co && (dat->cv_co!=co || ch[dat->cv_co].serial!=dat->cv_serial)) { say(cn,"%s, please be patient while i'm talking to others.",ch[co].name); }
                                }
                                if (it[ch[cn].citem].ID==IID_LAB4_SZEPTER) {
                                        pd->seyan4got|=(1<<1);
                                        set_seyan_state(pd);
                                        if (dat->cv_co && (dat->cv_co!=co || ch[dat->cv_co].serial!=dat->cv_serial)) { say(cn,"%s, please be patient while i'm talking to others.",ch[co].name); }
                                }
                        }

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_CHAR) {

                        co=msg->dat1;

                        // dont talk
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }            // dont talk to other NPCs
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }           // dont talk to players without connection
			if (ticker<dat->lasttalk+5*TICKS) { remove_message(cn,msg); continue; }              // only talk when the old sentence is read
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }      // dont talk to someone we cant see, and dont talk to ourself
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }                  // dont talk to someone far away

                        // remove cv
                        if (dat->cv_co) {
                                if (!ch[dat->cv_co].flags || ch[dat->cv_co].serial!=dat->cv_serial || char_dist(cn,dat->cv_co)>10 || !char_see_char(cn,dat->cv_co)) {
                                        dat->cv_co=0;
                                }
                        }

                        // only talk to cv
                        if (dat->cv_co && dat->cv_co!=co) { remove_message(cn,msg); continue; }

                        // set new cv
                        if (!dat->cv_co) {
                                dat->cv_co=co;
                                dat->cv_serial=ch[co].serial;
                        }

                        // get lab ppd
                        pd=set_data(co,DRD_LAB4_PLAYER,sizeof(struct lab4_player_data));
                        if (!pd) { remove_message(cn,msg); continue; }

			switch(pd->seyan4state) {
                                // INTRO
                                case 0: say(cn,"Hello %s. This is thy first mission in the Labyrinth.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 1: say(cn,"Listen, %s. To the east is an entrance to the Gnalbs winter residence.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 2: say(cn,"The Gnalbs are peaceful creatures, but their King and their Mage and the Guards are not."); didsay=1; pd->seyan4state++; break;
                                case 3: say(cn,"Bring me the King's Crown, and the Mage's Szepter to prove thou art worthy to enter the next Gate."); didsay=1; pd->seyan4state++; break;
                                case 4: say(cn,"Go ahead now, %s, and fulfil thine destiny.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 5: dat->cv_co=0; break;

                                // received crown (szepter missing)
                                case 10: say(cn,"Thou broughtst me the Kings Crown. Now, %s, seek for the Mage's Szepter.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 11: dat->cv_co=0; break;
			
                                // received szepter (corwn missing)
                                case 20: say(cn,"Thou broughtst me the Mages Szepter. Now, %s, seek for the King's Crown.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 21: dat->cv_co=0; break;

                                // received both, opening gate
                                case 30: say(cn,"%s, thou broughtst me the King's Crown and the Mage's Szepter.",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 31: say(cn,"Now I will open a magic gate for thee. Use it, and thou wilt be able to travel to the next part of the Labyrinth."); didsay=1; pd->seyan4state++; break;
                                case 32: create_lab_exit(co,10); say(cn,"Mayest Thou Past The Last Gate, %s",ch[co].name); didsay=1; pd->seyan4state++; break;
                                case 33: dat->cv_co=0; break;
                        }

                        if (didsay) {
                                dat->lasttalk=ticker;
                                talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
                        }

		}

                if (msg->type==NT_TEXT) {

                        co=msg->dat3;
                        str=(char *)msg->dat2;

                        tabunga(cn,co,(char*)msg->dat2);

                        if (co==cn) { remove_message(cn,msg); continue; }
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
			if (!char_see_char(cn,co)) { remove_message(cn,msg); continue; }

                        // get lab ppd
                        pd=set_data(co,DRD_LAB4_PLAYER,sizeof(struct lab4_player_data));
                        if (!pd) { remove_message(cn,msg); continue; }

                        if (strcasestr(str,"REPEAT")) { say(cn,"I will repeat, %s",ch[co].name); set_seyan_state(pd); }
                }

                standard_message_driver(cn,msg,0,0);
                remove_message(cn,msg);
	}

        if (talkdir) turn(cn,talkdir);

        if (dat->lasttalk+TICKS*30<ticker) {
                if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHTDOWN,ret,lastact)) return;		
        }

        do_idle(cn,TICKS);
}
Ejemplo n.º 25
0
int
main(int argc,char **argv)
{
	GR_EVENT	event;		/* current event */
	GR_BITMAP	bitmap1fg[7];	/* bitmaps for first cursor */
	GR_BITMAP	bitmap1bg[7];
	GR_BITMAP	bitmap2fg[7];	/* bitmaps for second cursor */
	GR_BITMAP	bitmap2bg[7];

	if (GrOpen() < 0) {
		fprintf(stderr, "cannot open graphics\n");
		exit(1);
	}

	GrReqShmCmds(655360);
	
	GrGetScreenInfo(&si);
COLS = si.cols - 40;
ROWS = si.rows - 80;

	/* print error, but don't exit*/
	GrSetErrorHandler(errorcatcher);

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 100, 50, COLS - 120,
		ROWS - 60, 1, BROWN, WHITE);
	w2 = GrNewWindow(GR_ROOT_WINDOW_ID, 6, 6, W2_WIDTH, W2_HEIGHT, 2, GREEN,
		WHITE);
	w3 = GrNewWindow(GR_ROOT_WINDOW_ID, 250, 30, 80, 100, 1, LTGRAY,
		GREEN);
	w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE);
	w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN);

	GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN |
		GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE |
		GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT |
		GR_EVENT_MASK_CLOSE_REQ);
	/* must select down and up for w2 to get implicit grab when
	 * running window manager, otherwise the wm-created parent
	 * window will get the grab, and we won't get the button up...
	 */
	GrSelectEvents(w2, GR_EVENT_MASK_BUTTON_DOWN |
			GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(w3, GR_EVENT_MASK_BUTTON_DOWN |
		GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(w4, GR_EVENT_MASK_BUTTON_DOWN |
		GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION |
		GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(w5, GR_EVENT_MASK_MOUSE_ENTER |
		GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_BUTTON_DOWN |
			GR_EVENT_MASK_CLOSE_REQ);

	GrMapWindow(w1);
	GrMapWindow(w2);
	GrMapWindow(w3);
	GrMapWindow(w4);
	GrMapWindow(w5);

	gc1 = GrNewGC();
	gc2 = GrNewGC();
	gc3 = GrNewGC();
	gc4 = GrNewGC();

	GrSetGCForeground(gc1, RED);
	GrSetGCBackground(gc1, BROWN);
	GrSetGCForeground(gc2, MAGENTA);
	GrSetGCMode(gc4, GR_MODE_XOR);

	bitmap1fg[0] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[2] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[3] = MASK(X,X,X,X,X,X,X);
	bitmap1fg[4] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[5] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[6] = MASK(_,_,_,X,_,_,_);

	bitmap1bg[0] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[1] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[2] = MASK(X,X,X,X,X,X,X);
	bitmap1bg[3] = MASK(X,X,X,X,X,X,X);
	bitmap1bg[4] = MASK(X,X,X,X,X,X,X);
	bitmap1bg[5] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[6] = MASK(_,_,X,X,X,_,_);

	bitmap2fg[0] = MASK(_,_,X,X,X,_,_);
	bitmap2fg[1] = MASK(_,X,_,_,_,X,_);
	bitmap2fg[2] = MASK(X,_,_,_,_,_,X);
	bitmap2fg[3] = MASK(X,_,_,_,_,_,X);
	bitmap2fg[4] = MASK(_,X,_,_,_,X,_);
	bitmap2fg[5] = MASK(_,_,X,X,X,_,_);

	bitmap2bg[0] = MASK(_,_,X,X,X,_,_);
	bitmap2bg[1] = MASK(_,X,X,X,X,X,_);
	bitmap2bg[2] = MASK(X,X,X,X,X,X,X);
	bitmap2bg[3] = MASK(X,X,X,X,X,X,X);
	bitmap2bg[4] = MASK(_,X,X,X,X,X,_);
	bitmap2bg[5] = MASK(_,_,X,X,X,_,_);

	GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
	GrSetCursor(w2, 7, 7, 3, 3, WHITE, BLACK, bitmap2fg, bitmap2bg);

	while (1) {
		GrCheckNextEvent(&event);

		switch (event.type) {
			case GR_EVENT_TYPE_BUTTON_DOWN:
				do_buttondown(&event.button);
				break;

			case GR_EVENT_TYPE_BUTTON_UP:
				do_buttonup(&event.button);
				break;

			case GR_EVENT_TYPE_MOUSE_POSITION:
			case GR_EVENT_TYPE_MOUSE_MOTION:
				do_motion(&event.mouse);
				break;

			case GR_EVENT_TYPE_KEY_DOWN:
				do_keystroke(&event.keystroke);
				break;

			case GR_EVENT_TYPE_EXPOSURE:
				do_exposure(&event.exposure);
				break;

			case GR_EVENT_TYPE_FOCUS_IN:
				do_focusin(&event.general);
				break;

			case GR_EVENT_TYPE_FOCUS_OUT:
				do_focusout(&event.general);
				break;

			case GR_EVENT_TYPE_MOUSE_ENTER:
				do_enter(&event.general);
				break;

			case GR_EVENT_TYPE_MOUSE_EXIT:
				do_exit(&event.general);
				break;

			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				exit(0);

			case GR_EVENT_TYPE_NONE:
				do_idle();
				break;
		}
	}
}
Ejemplo n.º 26
0
void monk_gatama_driver(int cn, int ret, int lastact)
{
        static struct talk_data talkbuf;   // we only have one, so there is no need to use the memory system (?)
        struct talk_data *talkdat=&talkbuf;
        struct saltmine_ppd *ppd;
        struct msg *msg,*next;
        int co;
        int talkdir=0,didsay=0,noturn=0;
        char *str;

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        fight_driver_set_dist(cn,20,0,30);
                }

                if (msg->type==NT_GIVE) {
                        if (!ch[cn].citem) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source
                        co=msg->dat1;

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_CHAR) {

                        co=msg->dat1;

                        // dont talk
                        if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }             // dont talk to other NPCs
                        if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }            // dont talk to players without connection
                        if (ticker<talkdat->lasttalk+5*TICKS) { remove_message(cn,msg); continue; }      // only talk when the old sentence is read
                        if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }       // dont talk to someone we cant see, and dont talk to ourself

                        // get ppd
                        if (!(ppd=get_saltmine_ppd(co))) { remove_message(cn,msg); continue; }

                        if (char_dist(cn,co)>7) { ppd->gatamastate=0; remove_message(cn,msg); continue; } // dont talk to someone far away

                        // remove cv
                        if (talkdat->cv_co) {
                                if (!ch[talkdat->cv_co].flags || ch[talkdat->cv_co].serial!=talkdat->cv_serial || char_dist(cn,talkdat->cv_co)>7 || !char_see_char(cn,talkdat->cv_co)) {
                                        talkdat->cv_co=0;
                                }
                        }

                        // only talk to cv
                        if (talkdat->cv_co && talkdat->cv_co!=co) { remove_message(cn,msg); continue; }

                        // set new cv
                        if (!talkdat->cv_co) {
                                talkdat->cv_co=co;
                                talkdat->cv_serial=ch[co].serial;
                        }

                        switch(ppd->gatamastate) {
                                case 0: if (ppd->salt) ppd->gatamastate=50; else ppd->gatamastate=10;
                                        break;

                                // Intro
                                case 10: say(cn,"Welcome %s. The Monastery of Kir Laka needs thine help. We live from the salt we get from the saltmine thou can find to the west. But now many golems appeared in the mine and we had to run for our lives, and all the salt we had already mined is lost there.",ch[co].name); didsay=1; ppd->gatamastate++; break;
                                case 11: say(cn,"Thou might want to know more °c4details°c0 of what thee can do for the monastery. After this, thou might °c4begin°c0 helping us, or not."); didsay=1; ppd->gatamastate++; break;
                                case 12: talkdat->cv_co=0; break;

                                // Details
                                case 20: say(cn,"Thou will have to lead group of monks safely to certain ladders in the saltmine. Once reached, thou \"use\" the ladder, and one of the monks will get the salt out of that place. Every ladder can be used only once every 12 astonian days, and every monk can only carry one bag of salt."); didsay=1; ppd->gatamastate++; break;
                                case 21: say(cn,"The monks will follow thee, and help thee against the golems. Once left, thou canst return to the monastery any time you like, the monks will then deposit their salt, if they have any, and will rest then. Thou can give some commands to the monks by simply speaking to them. Those commands are:");
                                         say(cn,"wait - and they will wait a short while.");
                                         say(cn,"come - and they will come to thee.");
                                         say(cn,"salt - and they will show thee if they carry salt, or not.");
                                         didsay=1; ppd->gatamastate++; break;
                                case 22: say(cn,"Hopefully thou now decide to °c4begin°c0 helping us."); didsay=1; ppd->gatamastate++; break;
                                case 23: talkdat->cv_co=0; break;

                                // Begin (check)
                                case 30: if (monksout(co,ppd)) ppd->gatamastate=40; else ppd->gatamastate++; break;
                                case 31: say(cn,"Come here, Monks. The mighty %s offers %s help. I want to see and hear quick feet now!",ch[co].name,hisname(co)); didsay=1; ppd->gatamastate++;
                                         create_worker(co,ppd);
                                         create_worker(co,ppd);
                                         create_worker(co,ppd);
                                         break;
                                case 32: say(cn,"Lead them wise and carfully, %s. Mayest thou all return safe.",ch[co].name); didsay=1; ppd->gatamastate++;
                                case 33: talkdat->cv_co=0; break;

                                // ...
                                case 40: say(cn,"Let us wait until all thine Monks are resting. Either in the rest room, or in peace."); didsay=1; ppd->gatamastate++;
                                case 41: talkdat->cv_co=0; break;

                                // Reward
                                case 50: say(cn,"Thanks thee %s for thine help. Thou canst use the saltbag in the store room, to take thee thine reward. I trust thee, that thou wilt take the right amount.",ch[co].name); ppd->gatamastate++;
                                case 51: talkdat->cv_co=0; break;
                        }

                        if (didsay) {
                                talkdat->lasttalk=ticker;
                                talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
                        }

		}

                if (msg->type==NT_TEXT) {

                        co=msg->dat3;
                        str=(char *)msg->dat2;

                        tabunga(cn,co,(char*)msg->dat2);

                        if (co==cn) { remove_message(cn,msg); continue; }
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
			if (!char_see_char(cn,co)) { remove_message(cn,msg); continue; }
                        if (char_dist(cn,co)>7) { remove_message(cn,msg); continue; }

                        // get ppd
                        if (!(ppd=get_saltmine_ppd(co))) { remove_message(cn,msg); continue; }

                        if (strcasestr(str,"REPEAT")) { say(cn,"I will repeat, %s",ch[co].name); ppd->gatamastate=0; }
                        else if (strcasestr(str,"DETAILS")) { ppd->gatamastate=20; }
                        else if (strcasestr(str,"BEGIN")) { ppd->gatamastate=30; }
                }

                standard_message_driver(cn,msg,1,1);
                remove_message(cn,msg);
	}

        if (talkdir) turn(cn,talkdir);

        // fighting
        fight_driver_update(cn);
        if (fight_driver_attack_visible(cn,0)) return;
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;

        if (talkdat->lasttalk+TICKS*30<ticker || noturn) {
                if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
                if (!noturn && (ticker/TICKS)%5==0) whisper(cn,"Auaaauuuuuuummmmmmmmmmm");
        }

        do_idle(cn,TICKS);
}
Ejemplo n.º 27
0
void ruby_driver(int cn,int retval,int lastact)
{
        struct ruby_driver_data *dat;
	struct sidestory_ppd *ppd;
	struct msg *msg,*next;
	int co,ret,in;
	char *ptr;

        dat=set_data(cn,DRD_RUBYDRIVER,sizeof(struct ruby_driver_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        ;
                }

		if (msg->type==NT_CHAR) {
                        co=msg->dat1;

			if ((ch[co].flags&CF_PLAYER) &&
			    ch[co].driver!=CDR_LOSTCON &&
			    char_dist(cn,co)<16 &&
			    char_see_char(cn,co) &&
			    (ticker-dat->last_time>TICKS*30 || dat->last_char==co) &&
			    (ppd=set_data(co,DRD_SIDESTORY_PPD,sizeof(struct sidestory_ppd)))) {
				switch(areaID) {
					case 2:		ret=do_story(cn,co,ppd,&ppd->ruby2,ruby2_story); break;
					case 3:		ret=ruby_aston_char(cn,co,ppd); break;
					case 5:		ret=do_story(cn,co,ppd,&ppd->ruby5,ruby5_story); break;
					case 6:		ret=do_story(cn,co,ppd,&ppd->ruby6,ruby6_story); break;
					case 8:		ret=do_story(cn,co,ppd,&ppd->ruby8,ruby8_story); break;
					case 10:	ret=do_story(cn,co,ppd,&ppd->ruby10,ruby10_story); break;
					case 11:	ret=do_story(cn,co,ppd,&ppd->ruby11,ruby11_story); break;
					case 12:	ret=do_story(cn,co,ppd,&ppd->ruby12,ruby12_story); break;
					case 15:	ret=do_story(cn,co,ppd,&ppd->ruby15,ruby15_story); break;
					case 16:	ret=do_story(cn,co,ppd,&ppd->ruby16,ruby16_story); break;
					case 17:	ret=do_story(cn,co,ppd,&ppd->ruby17,ruby17_story); break;

					default:	ret=0; break;
				}
				if (ret==1) {
					dat->last_char=co;
					dat->last_time=ticker;
				} else if (ret==2) {
					dat->last_char=dat->last_time=0;
				}
                        }
		}

		if (msg->type==NT_TEXT) {
			ptr=(char*)msg->dat2;
			co=msg->dat3;

			if ((ch[co].flags&CF_PLAYER) &&
			    ch[co].driver!=CDR_LOSTCON &&
			    char_dist(cn,co)<16 &&
			    char_see_char(cn,co) &&
			    (ppd=set_data(co,DRD_SIDESTORY_PPD,sizeof(struct sidestory_ppd)))) {
				switch(areaID) {
					case 2:		hear_story(cn,co,ppd,&ppd->ruby2,ruby2_story,ptr); break;
					case 3:		ruby_aston_text(cn,co,ppd,ptr); break;
					case 5:		hear_story(cn,co,ppd,&ppd->ruby5,ruby5_story,ptr); break;
					case 6:		hear_story(cn,co,ppd,&ppd->ruby6,ruby6_story,ptr); break;
					case 8:		hear_story(cn,co,ppd,&ppd->ruby8,ruby8_story,ptr); break;
					case 10:	hear_story(cn,co,ppd,&ppd->ruby10,ruby10_story,ptr); break;
					case 11:	hear_story(cn,co,ppd,&ppd->ruby11,ruby11_story,ptr); break;
					case 12:	hear_story(cn,co,ppd,&ppd->ruby12,ruby12_story,ptr); break;
					case 15:	hear_story(cn,co,ppd,&ppd->ruby15,ruby15_story,ptr); break;
					case 16:	hear_story(cn,co,ppd,&ppd->ruby16,ruby16_story,ptr); break;
					case 17:	hear_story(cn,co,ppd,&ppd->ruby17,ruby17_story,ptr); break;

				}

                        }
			
		}
		
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {
				if ((ch[co].flags&CF_PLAYER) && (ppd=set_data(co,DRD_SIDESTORY_PPD,sizeof(struct sidestory_ppd)))) {
					switch(areaID) {
						case 2:		ret=give_story(cn,co,ppd,&ppd->ruby2,ruby2_story,in); break;
						case 5:		ret=give_story(cn,co,ppd,&ppd->ruby5,ruby5_story,in); break;
						case 6:		ret=give_story(cn,co,ppd,&ppd->ruby6,ruby6_story,in); break;
						case 8:		ret=give_story(cn,co,ppd,&ppd->ruby8,ruby8_story,in); break;
						case 10:	ret=give_story(cn,co,ppd,&ppd->ruby10,ruby10_story,in); break;
						case 11:	ret=give_story(cn,co,ppd,&ppd->ruby11,ruby11_story,in); break;
						case 12:	ret=give_story(cn,co,ppd,&ppd->ruby12,ruby12_story,in); break;
						case 15:	ret=give_story(cn,co,ppd,&ppd->ruby15,ruby15_story,in); break;
						case 16:	ret=give_story(cn,co,ppd,&ppd->ruby16,ruby16_story,in); break;
						case 17:	ret=give_story(cn,co,ppd,&ppd->ruby17,ruby17_story,in); break;


						default:	ret=0; break;
					}
				} else ret=0;
				
				ch[cn].citem=0;
				if (ret || !give_char_item(co,in)) {
					destroy_item(in);
				}
			}
		}

                standard_message_driver(cn,msg,0,0);
                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

        fight_driver_update(cn);

        if (fight_driver_attack_visible(cn,0)) return;
	if (fight_driver_follow_invisible(cn)) return;

	if (spell_self_driver(cn)) return;
	if (regenerate_driver(cn)) return;

	if (dat->last_time && map_dist(ch[cn].x,ch[cn].y,ch[cn].tmpx,ch[cn].tmpy)>16) dat->last_time=0;

	if (dat->last_char && !char_see_char(cn,dat->last_char)) dat->last_char=dat->last_time=0;

	if (ticker-dat->last_time<TICKS*60) {
		int dir;

		co=dat->last_char;

                dir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
	
		if (tile_char_dist(cn,co)>2 && move_driver(cn,ch[co].x,ch[co].y,2)) return;
		turn(cn,dir);		
	} else if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,retval,lastact)) return;

        do_idle(cn,TICKS/2);
}
Ejemplo n.º 28
0
 void interrupt tc_int(void) 
 { 
    // recu int du timer0 : c'est grave (timeout) 
    // On se remet en attente 
	// Interrupt received from timer0; This is serious! Resetting to waiting state
    if (T0IE && T0IF) 
	{ 
       T0IF=0; 
       LED1 = LEDOFF; 
       LED2 = LEDOFF; 
       LED3 = LEDOFF; 
       if ((inwaitingstate==0) && (waitforstart)) 
	   { 
          #ifdef avecnpn 
             RWOUT = 1; // pour indiquer au boitier que l'on a un truc a lui dire
                        // To indicate the body that something has arisen			 
          #else 
             TRISC = TRISC & 0b11111110; 
             RWOUT = 0; // pour indiquer au boitier que l'on a un truc a lui dire 
                        // To indicate the body that something has arisen			 
          #endif 
          waitforstart = 0; 
       } 
       else 
	   {
	      do_idle(); 
	   }
    } 
    
    // recu front descendant sur RW : le boitier veut 
    // savoir ? qui il a ? faire 
	// Falling edge received from RW1; The Body wants know what it is connected to
    if (INTE && INTF) 
	{ 
       INTF  = 0; 
       #ifdef avecnpn 
          RWOUT = 1 ;   // on met la ligne rw à 0 
		                // Set RW1 = 0
       #else 
          TRISC = TRISC & 0b11111110; 
          RWOUT = 0 ;   // on met la ligne rw à 0 
		                // Set RW1 = 0
       #endif 
       
       inbyte = SSPBUF; 
       
       INTE  = 0;    // 
       SSPIF = 0;    // on autorise les irqs sur port s?rie;
                     // Enable interrupts at the serial port	   
       SSPIE = 1; 
       
       LED2 = LEDON; 
       enable_T0(); 
    } 
    
    // nous venons de recevoir un caractere sur le port s?rie 
	// Now we have received a character from the serial port
    if (SSPIF && SSPIE) 
    { 
       SSPIF = 0; 
       TMR0  = 0; 
       inbyte = SSPBUF; 
       if (inwaitingstate==1) 
	   { 
         if (inbyte == 0x44) 
	     {
            // caractere d'initialisation venant du boitier 
            // Initialsation character from body
            numbytetosend = 0; 
            bytetosend = inverseoctet(tblout[numbytetosend]); // preparation du premier caractere ? envoyer
                                                              // Preparing first character to be send			
            SSPBUF = bytetosend; // on envoie le caractere 
			                     // Send character
            
            // passer en transmission 
			// Switch to transmission
            inwaitingstate = 0; 
            INTE = 0;  // Pas d'irq sur front du RW 
			           // No interrupt from RW1
            INTF = 0;  // par s?curit? 
			           // for security
            
            TRISC = TRISC & 0b01111111; 
            
            LED1 = LEDON; 
            #ifdef avecnpn 
               RWOUT = 0; // Liberation du RW 
			              // Release RW1
            #else 
               RWOUT = 1; // Liberation du RW 
			              // Release RW1
               TRISC = TRISC | 0b00000001; 
            #endif 
            enable_T0(); // initialisation du timeout 
			             // initialise the time out
            TMR0 = 252; 
            waitforstart = 1; 
         } 
         else
		 {
		   do_idle(); 
		 }
       } 
       else 
	   { 
          // Recu interruption alors que l'on est en emision 
		  // Interruption received in transmission
          LED3 = LEDON; 
          #ifdef avecnpn 
             RWOUT=0; // RW au niveau 1 
	                  // Set RW = 1
          #else 
             TRISC = TRISC | 0b00000001; 
             RWOUT=1; // RW au niveau 1 
 	                  // Set RW = 1
          #endif 
          numbytetosend++; 
          if (numbytetosend<nbbytetosend) 
          { 
             bytetosend = inverseoctet(tblout[numbytetosend]); // caractere ? envoyer 
			                                                   // charater to send....
             SSPBUF = bytetosend; // on envoie le caractere
                                  // Send buffer			 
             waitforstart = 1; 
             enable_T0(); // initialisation du timeout
                          // initialisation of the timeout			 
             TMR0 = 252; 
          } 
          else 
		  {
		     do_idle(); // on a plus rien à transmettre;
                        // Nothing left to transmit.			 
	      }
       } 
    } 
 } 
Ejemplo n.º 29
0
void lab4_gnalb_driver(int cn, int ret, int lastact)
{
        struct lab4_gnalb_driver_data *dat;
        struct msg *msg,*next;
        int co,cc,in;
        char *str;

        // get data
        dat=set_data(cn,DRD_LAB4_GNALB,sizeof(struct lab4_gnalb_driver_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        lab4_gnalb_driver_parse(cn,dat);
                        lab4_gnalb_driver_init(cn,dat);
                }

                if (msg->type==NT_GIVE) {

                        co=msg->dat1;
                        if (!(in=ch[cn].citem)) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_TEXT) {
                        co=msg->dat3;
                        str=(char *)msg->dat2;
                        tabunga(cn,co,str);
                        if (co==cn) { remove_message(cn,msg); continue; }
                }

                if (msg->type==NT_SEEHIT && dat->type==2) {

                        cc=msg->dat1;
                        co=msg->dat2;
                        if (!cc || !co) { remove_message(cn,msg); continue; }

                        // is the victim our friend? then help
                        if (co!=cn && ch[co].group==ch[cn].group) {
                                if (!is_valid_enemy(cn,cc,-1)) { remove_message(cn,msg); continue; }
                                if (char_dist(cn,cc)>10) { remove_message(cn,msg); continue; }
                                fight_driver_add_enemy(cn,cc,1,1);
                                remove_message(cn,msg);
                                continue;
                        }

                        // is the attacker our friend? then help
                        if (cc!=cn && ch[cc].group==ch[cn].group) {
                                if (!is_valid_enemy(cn,co,-1)) { remove_message(cn,msg); continue; }
                                if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }
                                fight_driver_add_enemy(cn,co,0,1);
                                remove_message(cn,msg);
                                continue;
                        }
                        remove_message(cn,msg);
                        continue;
                }

                standard_message_driver(cn,msg,dat->aggressive,dat->helper);
                remove_message(cn,msg);
	}

        // fighting
        fight_driver_update(cn);
        if (fight_driver_attack_visible(cn,0)) return;
        if (fight_driver_follow_invisible(cn)) return;

        // rest of standard action
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;

        // gnalb guards patroling
        if (dat->type==1 && dat->path) {

                fight_driver_set_home(cn,ch[cn].x,ch[cn].y);

                if (swap_move_driver(cn,gnalb_path[dat->path].x,gnalb_path[dat->path].y,1)) return;
                if (map_dist(ch[cn].x,ch[cn].y,gnalb_path[dat->path].x,gnalb_path[dat->path].y)<4) {
                        int p;

                        do p=RANDOM(4); while(gnalb_path[dat->path].next[p]==0 || (gnalb_path[dat->path].next[1]!=0 && gnalb_path[dat->path].next[p]==dat->lastpath));
                        dat->lastpath=dat->path;
                        dat->path=gnalb_path[dat->path].next[p];
                }
                else do_idle(cn,TICKS/2);

                return;
        }

        // crazy gnalb talking
        if (dat->type==3) {

                switch (RANDOM(50)) {
                        case 0: whisper(cn,"Me saw right in Fire."); break;
                        case 1: whisper(cn,"Me not crazy. In me house me saw in fire."); break;
                        case 2: whisper(cn,"Me will get it out."); break;
                        case 3: whisper(cn,"Fire hot, but me not crazy."); break;
                        case 4: whisper(cn,"Tell mage me saw in fire, me not crazy."); break;
                        case 10: case 11: case 12: case 13: case 14: if (do_use(cn,DX_RIGHT,0)) return;
                }

                if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
                // nothing left to do
                do_idle(cn,TICKS/2);
                return;
        }

        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;

        // nothing left to do
        do_idle(cn,TICKS/2);
}
Ejemplo n.º 30
0
void clubmaster_driver(int cn,int ret,int lastact)
{
	struct clubmaster_driver_data *dat;
        int co,in,n,rank,cc,val;
        struct msg *msg,*next;
	char *ptr,tmp[80],name[80];

        dat=set_data(cn,DRD_CLUBMASTERDRIVER,sizeof(struct clubmaster_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
                clubmaster_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

		// did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			if (!get_char_club(cn) && !get_char_clan(cn)) quiet_say(cn,"Hello %s! Would you like to found a °c4club°c0?",ch[co].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

                        if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk				
                                if ((ptr=strcasestr((char*)msg->dat2,"found:"))) {
					if (!(ch[co].flags&CF_PAID)) {
						quiet_say(cn,"I'm sorry, %s, but only paying players may found clubs.",ch[co].name);
					} else if (!get_char_clan(co) && !get_char_club(co)) {
						if (ch[co].gold>=10000*100) {
							ptr+=6;
							while (isspace(*ptr)) ptr++;
							for (n=0; n<79; n++) {
								if (!(isalpha(*ptr) || *ptr==' ')) break;
								name[n]=*ptr++;
							}
							name[n]=0;
							
							if ((n=create_club(name))) {
								take_money(co,10000*100);
								ch[co].clan=n+CLUBOFFSET;
								ch[co].clan_serial=club[n].serial;
								ch[co].clan_rank=2;
								quiet_say(cn,"Congratulations, %s, you are now the leader of the club %s.",ch[co].name,club[n].name);
								dlog(co,0,"created club %d %s",n,club[n].name);
							} else quiet_say(cn,"Something's wrong with the name.");
						} else quiet_say(cn,"You cannot pay the fee of 10,000 gold.");
					} else quiet_say(cn,"You are already a member of a clan or club. You cannot found a new one.");
				}
				if ((ptr=strcasestr((char*)msg->dat2,"accept:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=7;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							dat->accept[n]=*ptr++;
						}
						dat->accept[n]=0;
						strcpy(dat->join,ch[co].name);
						dat->accept_clan=get_char_club(co);
						dat->accept_cn=co;

						quiet_say(cn,"To join %s's club %s, say: 'join: %s'",dat->join,dat->accept,dat->join);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"join:"))) {
					if (get_char_clan(co) || get_char_club(co)) {
                                                quiet_say(cn,"You are already a clan or club member, %s.",ch[co].name);
					} else {
						ptr+=5;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
                                                if (strcasecmp(dat->accept,ch[co].name)) {
							quiet_say(cn,"You have not been invited, %s.",ch[co].name);
						} else if (strcasecmp(dat->join,tmp)) {
							quiet_say(cn,"%s has not invited you, %s.",tmp,ch[co].name);
						} else {
                                                        //add_member(co,dat->accept_clan,dat->join);
							ch[co].clan=dat->accept_clan+CLUBOFFSET;
							ch[co].clan_serial=club[dat->accept_clan].serial;
							ch[co].clan_rank=0;
							quiet_say(cn,"%s, you are now a member of %s's club.",ch[co].name,dat->join);
							dat->accept[0]=0;
							dat->accept_clan=0;
							dat->join[0]=0;
						}
						
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"leave!"))) {
					if (!get_char_club(co)) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						remove_member(co,co);
						quiet_say(cn,"You are no longer a member of any club, %s",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"rank:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
						rank=atoi(ptr);

						if (rank<0 || rank>1) {
							quiet_say(cn,"You must use a rank between 0 and 1.");
							remove_message(cn,msg);
							continue;
						}

						for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (!(ch[cc].flags&CF_PAID) && rank>0) {
                                                                quiet_say(cn,"%s is not a paying player, you cannot set the rank higher than 0.",ch[cc].name);
							} else if (ch[cc].clan_rank==2) {
								quiet_say(cn,"%s is the club's founder, cannot change rank.",ch[cc].name);
							} else if (get_char_club(cc)==get_char_club(co)) {
								ch[cc].clan_rank=rank;
								quiet_say(cn,"Set %s's rank to %d.",ch[cc].name,rank);
							} else quiet_say(cn,"You cannot change the rank of those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_set_clan_rank(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,rank,ch[co].name);
								quiet_say(cn,"Update scheduled (%s,%d).",tmp,rank);
							}
						}
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"fire:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
                                                for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (get_char_club(cc)==get_char_club(co)) {
								if (ch[cc].clan_rank<2) {
									remove_member(cc,co);
									quiet_say(cn,"Fired: %s.",ch[cc].name);
								} else quiet_say(cn,"You cannot fire the founder of the club.");
							} else quiet_say(cn,"You cannot fire those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_fire_from_clan(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,ch[co].name);
								quiet_say(cn,"Update scheduled (%s).",tmp);
							}
						}
					}
				}

				if ((ptr=strcasestr((char*)msg->dat2,"deposit:"))) {
					if (!(n=get_char_club(co))) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						val=atoi(ptr+8)*100;

						if (val>0 && ch[co].gold>=val) {
							club[n].money+=val;
							take_money(co,val);
							quiet_say(cn,"You have deposited %dG, for a total of %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Deposited %dG into club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"You do not have that much gold, %s.",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"withdraw:"))) {
					if (!(n=get_char_club(co)) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						val=atoi(ptr+9)*100;

						if (val>0 && club[n].money>=val) {
							club[n].money-=val;
							give_money(co,val,"club withdrawal");
							quiet_say(cn,"You have withdrawn %dG, money left in club %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Withdrew %dG from club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"The club does not have that much gold, %s.",ch[co].name);
					}
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// try to give it back
                                if (give_char_item(cn,co)) return;
				
				// didnt work, let it vanish, then
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}
                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(8)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
                        case 5:		murmur(cn,"Beware of the fire snails!"); break;
			case 6:         murmur(cn,"I love the clicking of coins."); break;
			case 7:		murmur(cn,"Gold and Silver, Silver and Gold."); break;
			default:	break;
		}
		
		dat->last_talk=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}