Exemple #1
0
char *monType::getName(mType type) {
    // do bounds checking
    ASSERTLOG( type >= PLAYER );
    ASSERTLOG( type < MAX_MOB_TYPES );

    return(mobtype_name[(int)type]);
}
Exemple #2
0
void logn(char *filename, char *str)
{
	char	buffer[4196];
	char    path[256];
    int     fd;

	ASSERTLOG( filename );
	ASSERTLOG( str );

    sprintf(path, "%s/%s", get_log_path(), filename);
    fd = open(path, O_RDWR | O_APPEND | O_BINARY );
    if(fd < 0) 
	{
        fd = open(path, O_RDWR | O_CREAT | O_BINARY, ACC);
        if(fd < 0) 
			return;
    }
    lseek(fd, 0L, 2);

	/* put a time stamp on everything */
	sprintf(buffer, "%s: %s\n", get_time_str(), str );
    write(fd, buffer, strlen(buffer));

    close(fd);

	return;
}
Exemple #3
0
/* the last argument */
void log_dm_command(char *ply_name, char *fullstr)
{
	char	buffer[2048];

	ASSERTLOG( ply_name );
	ASSERTLOG( fullstr );

	sprintf(buffer, "%s executed: %s", ply_name, fullstr );
	ilog( buffer );
	
	return;
}
Exemple #4
0
int find_crt_num( creature *crt_ptr )
{
	int i;
    creature  crt_src;

	ASSERTLOG( crt_ptr );


    for (i=0;i<CMAX;i++) 
	{
		/* call load_ctr_struct_from_file() to avoid any memory */
		/* allocations, thus no frees.  It should be the fastest */
		/* way to loop through the creature database */
	    if(load_crt_struct_from_file(i, &crt_src) < 0)
		    continue;
        if(!strcmp(crt_ptr->name, crt_src.name) && crt_ptr->experience == crt_src.experience) {
			break;
		}
    }

    if(i >= CMAX)
		i = 0;

	return(i);

}
Exemple #5
0
int get_config_file(char *filename)
{

	char	szBuffer[256];

	ASSERTLOG( filename );

	/* check for file existance */
	/* try the bin dir first */
	sprintf(filename, "%s/mordor.cf", BINPATH);

	/* check for file existance */
	if ( !file_exists( filename ) )
	{
		/* look in the current directory */
		strcpy( filename, "mordor.cf" );
		if ( !file_exists( filename ) )
		{
			if(loaded_paths_yet) {
				sprintf(szBuffer, "Missing \'%s\' file.\n", filename);
				elog(szBuffer);
			} 
			/* don't call elog if we can't find the ini, because that
			 * tries to load the paths again, which tries to load the ini, etc */
			else { 
				printf("Couldn't find mordor.cf file.  Exiting.\n");
				exit(0);
			}

			return(0);
		}
	}

	return(1);
}
Exemple #6
0
int Player::delCharm(Creature* creature) {
    etag    *cp, *prev;

    ASSERTLOG( creature );

    if(!hasCharm(creature->getName()))
        return(0);

    cp = first_charm;

    if(!strcmp(cp->enemy, creature->getCName())) {
        first_charm = cp->next_tag;
        delete cp;
        return(1);
    } else
        while(cp) {
            if(!strcmp(cp->enemy, creature->getCName())) {
                prev->next_tag = cp->next_tag;
                delete cp;
                return(1);
            }
            prev = cp;
            cp = cp->next_tag;
        }
    return(0);
}
Exemple #7
0
void new_merror(char *str, char errtype, char *file, const int line )
{
	long t;
	char bugstr[512];

	ASSERTLOG( file != NULL);

	t = time(0);
	sprintf(bugstr, "Error occured in %s in file %s line %d", str, 
		file, line);
	elog(bugstr);
	if(errtype == FATAL)
		exit(-1);
}
Exemple #8
0
int Player::addCharm(Creature* creature) {
    etag    *cp=0;

    ASSERTLOG( creature );

    if(hasCharm(creature->getName()))
        return(0);

    if(creature && !creature->isDm()) {
        cp = new etag;
        if(!cp)
            merror("add_charm_crt", FATAL);

        strcpy(cp->enemy, creature->getCName());
        cp->next_tag = first_charm;
        first_charm = cp;
    }
    return(0);
}
Exemple #9
0
int find_obj_num(object *obj_ptr )
{
    int i;
    object  obj_src;

	ASSERTLOG( obj_ptr );

    for (i=0;i<OMAX;i++) 
	{
		/* call load_obj_struct_from_file() to avoid any memory */
		/* allocations.  This no frees.  It shoudl be the fastest */
		/* way to loop through the greature database */
        if(load_obj_struct_from_file(i, &obj_src) < 0)
	        continue;
        if(!strcmp(obj_ptr->name, obj_src.name) && obj_ptr->ndice == obj_src.ndice) 
            break;
	}
	
    if(i >= OMAX)
		i = 0;

	return(i);

}
Exemple #10
0
int fixup_room(int fd, room *rom_ptr )
{
	/* assume the worst */
	int nReturn = 0;
	int	num;
	int	size;
	int	fd_bad;

	char	filename[256];
	char	filebad[256];
	char	str[128];
	char	*buffer;
	int		ndx;

	ASSERTLOG( rom_ptr );

	num = rom_ptr->rom_num;
	get_room_filename( num, filename );
	
	sprintf(str, "Attempting to fix corrupt room number %d", num );
	elog( str );

	/* find a name that doesn't exist */
	sprintf( filebad, "%s.bad", filename );

	ndx = 0;
	while ( file_exists( filebad ) )
	{
		sprintf( filebad, "%s.ba%d", filename, ndx );
		ndx++;
	}

	sprintf(str, "Copying file %s to %s", filename, filebad);
	elog( str );

	size = lseek(fd, 0, SEEK_END);
	buffer = malloc( size );
	if ( buffer )
	{
		/* rewind */
		if ( lseek( fd, 0, SEEK_SET ) == 0)
		{
			if ( size != read(fd, buffer, size ) )
			{
				elog("Unable to read room to make a backup of room" );
				free(buffer );
				return(0);
			}

			fd_bad = open(filebad, O_CREAT | O_RDWR | O_BINARY );
			if(fd_bad < 0)
			{
				elog("Unable to open backup of room" );
				free(buffer );
				return(0);
			}

			if ( size != write(fd_bad, buffer, size ) )
			{
				elog("Unable to write backup of room" );
				free(buffer );
				close( fd_bad );
				return(0);
			}

			/* done with backup */
			close( fd_bad );
		}
		else
		{
			elog("Unable to rewind file.");
			free(buffer);
			return(0);
		}

		free(buffer);
	}


	/* now write out a good copy to the original file handle */
	
	/* start back at the beginning */
	if ( lseek(fd, 0, SEEK_SET) == 0 )
	{
		if ( write_rom(fd, rom_ptr, 1 ) >= 0 )
		{
			/* it worked */
			nReturn = 1;
			sprintf(str, "Saved a good copy of file %s.", filename);
			elog( str );
		}
	}
	else
	{
		elog("Unable to rewind file.");
		return(0);
	}



	return(nReturn);
}
Exemple #11
0
int update_combat( creature *crt_ptr )
{
   creature *att_ptr;
   room     *rom_ptr;
   etag     *ep;
   char     *enemy;
   int      n = 0,rtn = 0,p = 0,fd,t = 0;
   int		victim_is_monster = 0, circled=0, tried_circle=0;
   
	ASSERTLOG( crt_ptr );

	rom_ptr = crt_ptr->parent_rom;
	ep = crt_ptr->first_enm;
	while(1)
	{
		enemy = ep->enemy;
		if(!enemy)
			ep = ep->next_tag;
		if(!ep)
			return 0;
		if(enemy)
			break;
	}


	/* keep looking till we find one that is an exact match */
	/* and is not the monster itself */
	n = 1;
	do 
	{

		att_ptr = find_exact_crt(crt_ptr, rom_ptr->first_ply,enemy, n);
		if(!att_ptr)
			att_ptr = find_exact_crt(crt_ptr, rom_ptr->first_mon,enemy, n);
		if(!att_ptr)
		{	
#ifdef OLD_CODE
			/* with this code commented out, a monster will remember it is
			attacking a player even if he logs out and logs back in unlike
			now where he can get someone else to stadn there and attack,
			disconnect, login attack again etc. */
			if(!find_who(enemy))
				del_enm_crt(enemy, crt_ptr);
			else
#endif
				end_enm_crt(enemy, crt_ptr);
			return 0;
		}

		n++;

	} while ( att_ptr != NULL && att_ptr == crt_ptr );

  
	if ( att_ptr->type == MONSTER)
	{
		victim_is_monster = 1;
	}
 
	/* I think this check is redundanct now */
	if(att_ptr != crt_ptr) 
	{
       if(is_charm_crt(crt_ptr->name, att_ptr)&& F_ISSET(crt_ptr, MCHARM))
	       p = 1;
		crt_ptr->NUMHITS++;
		n=20;
		if(F_ISSET(crt_ptr, MMAGIO))
			n=crt_ptr->proficiency[0];
	         
		if(F_ISSET(crt_ptr, MMAGIC) && mrand(1, 100) <= n && !p) 
		{
			rtn = crt_spell(crt_ptr, att_ptr );
			if(rtn == 2) 
			{
				/* spell killed the victim */
				return 1; 
			}
			else if(rtn == 1)
			{
				/* spell hurt the victim but did not kill */
				n = 21;
				if ( !victim_is_monster )
				{
					if ( check_for_ply_flee( att_ptr ))
					{
						return(1);
					}
				}
			}
			else 
			{
				/* spell was not cast or did not hurt the victim */
      			n = crt_ptr->thaco - att_ptr->armor/10;
			}
		}
		else 
		{
			n = crt_ptr->thaco - att_ptr->armor/10;
			n = MAX(n, 1);
		}
   
   
		if(mrand(1,20) >= n && !p) 
		{
			if ( !victim_is_monster )
			{
				fd = att_ptr->fd;
				ANSI(fd, ATTACKCOLOR); 
			}
			else
			{
				fd = -1;
			}
			
			if((crt_ptr->class==BARBARIAN||crt_ptr->class==FIGHTER)
				&& (mrand(1,30)<20 &&
				crt_ptr->level > (att_ptr->level - 3))) {
			   circled = (crt_ptr->level - att_ptr->level) +
				mrand(1,4);
			   if(circled>1) {
				mprint(fd, "%M circles you.\n", m1arg(crt_ptr));
			
				if(F_ISSET(crt_ptr, MNOPRE)) { 
				  if(F_ISSET(att_ptr, MNOPRE)) {
					sprintf(g_buffer, "%s circles %s.", crt_ptr->name, att_ptr->name);
				  } else {
					sprintf(g_buffer, "%s circles the %s.", crt_ptr->name, att_ptr->name);
				  }
				} 
				else { /* !F_ISSET(crt_ptr,MNOPRE) */
				  if(F_ISSET(att_ptr, MNOPRE)) {
					sprintf(g_buffer, "The %s circles %s.", crt_ptr->name, att_ptr->name);
				  } else {
					sprintf(g_buffer, "The %s circles the %s.", crt_ptr->name, att_ptr->name);
				  }
				}
				broadcast_dam(fd, crt_ptr->fd, att_ptr->rom_num, 
					g_buffer, NULL);

				att_ptr->lasttime[LT_ATTCK].ltime = time(0);
				att_ptr->lasttime[LT_ATTCK].interval = mrand(5,8) - 
					bonus[(int)att_ptr->dexterity];
				circled=1;
			   }
			   else {
				mprint(fd, "%M tried to circle you.\n", m1arg(crt_ptr));
				if(F_ISSET(crt_ptr, MNOPRE)) {
				   if(F_ISSET(att_ptr,MNOPRE)) {
					sprintf(g_buffer, "%s tried to circle %s.", crt_ptr->name, att_ptr->name);
				   } else {
					sprintf(g_buffer, "%s tried to circle the %s.", crt_ptr->name, att_ptr->name);
				   }
				}
				else { /*!F_ISSET(crt_ptr, MNOPRE) */
				   if(F_ISSET(att_ptr,MNOPRE)) {
					sprintf(g_buffer, "The %s tried to circle %s.", crt_ptr->name, att_ptr->name);
				   } else {
					sprintf(g_buffer, "The %s tried to circle the %s.", crt_ptr->name, att_ptr->name);
				   }
				}
				broadcast_dam(fd, crt_ptr->fd, att_ptr->rom_num, 
					g_buffer, NULL);

				circled=0;
				tried_circle=1;
			   }
				
			}
		
			if(F_ISSET(crt_ptr, MBRETH) && mrand(1,30)<5)
			{
				if (F_ISSET(crt_ptr, MBRWP1) && !F_ISSET(crt_ptr, MBRWP2))
					n = bw_spit_acid(crt_ptr,att_ptr);
				else if (F_ISSET(crt_ptr, MBRWP1) && F_ISSET(crt_ptr, MBRWP2))
					n = bw_poison(crt_ptr,att_ptr);
				else if (!F_ISSET(crt_ptr, MBRWP1) && F_ISSET(crt_ptr, MBRWP2))
					n = bw_cone_frost(crt_ptr,att_ptr);
				else
					n = bw_cone_fire(crt_ptr,att_ptr);
			}
			
			else if(F_ISSET(crt_ptr, MENEDR) && mrand(1,100)< 25) 
				n = power_energy_drain(crt_ptr,att_ptr);
			else {
			    if(circled==0) {
				n = mdice(crt_ptr);		     
			    }
			}
    
            
		if(circled==0 && tried_circle==0) {
			att_ptr->hpcur -= n;

			if ( !victim_is_monster )
			{
				sprintf(g_buffer, "%%M hit you for %d damage.\n", n);
				mprint(fd, g_buffer, m1arg(crt_ptr));
				add_enm_dmg(att_ptr->name, crt_ptr,n);
			
				// added for damage descriptions 
				if(F_ISSET(crt_ptr, MNOPRE))
					sprintf(g_buffer, "%s %s %s!",crt_ptr->name , 
						hit_description(n), att_ptr->name);
				else
					sprintf(g_buffer,"The %s %s %s!", crt_ptr->name,
						hit_description(n), att_ptr->name);
				
				broadcast_dam(crt_ptr->fd, att_ptr->fd, att_ptr->rom_num, g_buffer, NULL);


			}
			
			else
			{ 
				/* Output only when monster v. monster */

				broadcast_rom(-1,crt_ptr->rom_num, "%M hits %m.", m2args(crt_ptr, att_ptr));
				
				add_enm_crt(crt_ptr->name, att_ptr);
			}
		}

			if(F_ISSET(crt_ptr, MPOISS) && mrand(1,100) <= 15) 
			{
				if ( victim_is_monster )
				{
        			broadcast_rom(-1, att_ptr->rom_num,"%M poisoned %m.", 
						m2args(crt_ptr, att_ptr));
				}
				else
				{
					ANSI(fd, POISONCOLOR);
					mprint(fd, "%M poisoned you.\n", m1arg(crt_ptr));
				}
				F_SET(att_ptr, PPOISN);
			}

			if(F_ISSET(crt_ptr, MDISEA) && mrand(1,100) <= 15) 
			{

				if ( victim_is_monster )
				{
        			broadcast_rom(-1, att_ptr->rom_num,"%M infects %m.", 
						m2args(crt_ptr, att_ptr));
				}
				else
				{
					ANSI(fd, DISEASECOLOR);
					mprint(fd, "%M infects you.\n", m1arg(crt_ptr));
				}
				F_SET(att_ptr, PDISEA);
			}
		
			if(F_ISSET(crt_ptr, MBLNDR) && mrand(1,100) <= 15) 
			{
				if ( victim_is_monster )
				{
        			broadcast_rom(-1, att_ptr->rom_num,"%M blinds %m.", 
						m2args(crt_ptr, att_ptr));
				}
				else
				{
					ANSI(fd, BLINDCOLOR);
					mprint(fd, "%M  blinds your eyes.\n", m1arg(crt_ptr));
				}
				F_SET(att_ptr, PBLIND);
			}
  
			if(F_ISSET(crt_ptr, MDISIT) && mrand(1,100) <= 15) 
				dissolve_item(att_ptr,crt_ptr);
                
			if ( !victim_is_monster )
			{
				ANSI(fd, MAINTEXTCOLOR);

				n = choose_item(att_ptr);

				if(n) 
				{
					if(--att_ptr->ready[n-1]->shotscur<1) 
					{
						sprintf(g_buffer,"Your %s fell apart.\n",att_ptr->ready[n-1]->name);
						output(fd, g_buffer);
						sprintf(g_buffer, "%%M's %s fell apart.", att_ptr->ready[n-1]->name);
						broadcast_rom(fd,att_ptr->rom_num, g_buffer,
							  m1arg(att_ptr));
						add_obj_crt(att_ptr->ready[n-1],att_ptr);
						dequip(att_ptr,att_ptr->ready[n-1]);
						att_ptr->ready[n-1] = 0;
						compute_ac(att_ptr);
					}
				}
			}
        
			if(!victim_is_monster && !F_ISSET(att_ptr, PNOAAT) && !p)
			{      
				rtn = attack_crt(att_ptr, crt_ptr);
				if(rtn) 
					return 1;
			}
			else 
			{      
				if(LT(att_ptr,LT_ATTCK) < t)
				{				   
					rtn = attack_crt(att_ptr, crt_ptr);
					att_ptr->lasttime[LT_ATTCK].ltime = t;
					if(rtn) 
						return 1;
				}
			}
                
			if(att_ptr->hpcur < 1) 
			{
				if ( !victim_is_monster )
				{
					msprint(att_ptr, g_buffer, "%M killed you.\n", m1arg(crt_ptr));
					output_wc(att_ptr->fd, g_buffer, ATTACKCOLOR); 
				}
				else
				{
					broadcast_rom(-1,att_ptr->rom_num,"%M killed %m.",
                       				m2args(crt_ptr, att_ptr));
				}
				die(att_ptr, crt_ptr);
				return 1;
			}
			else if ( !victim_is_monster )
			{
				if ( check_for_ply_flee( att_ptr ))
				{
					return(1);
				}
			}
		}
		else if(n <= 20 && !p) 
		{
			if ( !victim_is_monster )
			{
				msprint(att_ptr, g_buffer, "%M missed you.\n", 
					m1arg(crt_ptr));
				output_wc(att_ptr->fd, g_buffer, MISSEDCOLOR);
			}
			else
			{
				/* Output only when monster v. monster */
				broadcast_rom(-1, att_ptr->rom_num, "%M misses %m.", 
					m2args(crt_ptr, att_ptr));
				add_enm_crt(crt_ptr->name, att_ptr);
			}
			if(!victim_is_monster && !F_ISSET(att_ptr, PNOAAT))
			{      
				rtn = attack_crt(att_ptr, crt_ptr);
				if(rtn) 
					return 1;
			}
			else 
			{      
				if(LT(att_ptr,LT_ATTCK) < t)
				{			
					rtn = attack_crt(att_ptr, crt_ptr);
					att_ptr->lasttime[LT_ATTCK].ltime = t;
					if(rtn) 
						return 1;
				}
			}
		}
	}
Exemple #12
0
int monType::getHitdice(mType type) {
    ASSERTLOG( type >= PLAYER );
    ASSERTLOG( type < MAX_MOB_TYPES );

    return(mob_hitdice[(int)type]);
}