Esempio n. 1
0
int32_t lasso_bigmem(FILE* bedfile, uintptr_t bed_offset, uintptr_t* marker_exclude, uintptr_t marker_ct, uintptr_t* marker_reverse, Chrom_info* chrom_info_ptr, uintptr_t unfiltered_sample_ct, uintptr_t* pheno_nm2, double lasso_h2, double lasso_minlambda, uint32_t select_covars, uintptr_t* select_covars_bitfield, double* pheno_d_collapsed, uintptr_t covar_ct, char* covar_names, uintptr_t max_covar_name_len, uintptr_t* covar_nm, double* covar_d, uint32_t hh_or_mt_exists, uintptr_t sample_valid_ct, uintptr_t* sample_include2, uintptr_t* sample_male_include2, uintptr_t* loadbuf_raw, uintptr_t* loadbuf_collapsed, double* rand_matrix, double* misc_arr, double* residuals, uintptr_t* polymorphic_markers, uintptr_t* polymorphic_marker_ct_ptr, uint64_t* iter_tot_ptr, double** xhat_ptr) {
  uintptr_t unfiltered_sample_ct4 = (unfiltered_sample_ct + 3) / 4;
  double* data_arr = (double*)g_bigstack_base; // marker-major
  double sqrt_n_recip = sqrt(1.0 / ((double)((intptr_t)sample_valid_ct)));
  double lambda_max = 0.0;
  double err_cur = 0.0;
  uint64_t iter_tot = 0;
  uintptr_t sample_valid_ctl2 = QUATERCT_TO_WORDCT(sample_valid_ct);
  uintptr_t polymorphic_marker_ct = 0;
  uintptr_t unselected_covar_ct = 0;
  uintptr_t final_mask = get_final_mask(sample_valid_ct);
  double lambda_min = lasso_minlambda;
  uint32_t chrom_fo_idx = 0xffffffffU; // exploit overflow
  uint32_t chrom_end = 0;
  uint32_t is_x = 0;
  uint32_t is_y = 0;
  uint32_t min_ploidy_1 = 0;
  int32_t retval = 0;
  double cur_mapping[4];
  double* xhat;
  double* prod_matrix;
  double* dptr;
  double* dptr2;
  uintptr_t* ulptr_end_init;
  uintptr_t* ulptr_end;
  uintptr_t* active_set;
  uintptr_t* ulptr;
  double sige;
  double loghi;
  double loglo;
  double logdelta;
  double lambda;
  double xjold;
  double err_last;
  double dxx;
  double dyy;
  double zz;
  uintptr_t cur_word;
  uintptr_t cur_genotype;
  uintptr_t ulii;
  uintptr_t iter;
  uintptr_t col_ct;
  uintptr_t col_ctl;
  uintptr_t col_idx;
  uintptr_t col_nz_ct;
  uintptr_t col_to_z;
  uintptr_t col_uidx;
  uintptr_t covar_idx;
  uintptr_t sample_idx;
  uintptr_t sample_idx_stop;
  uintptr_t marker_idx;
  uint32_t lambi;
  uint32_t marker_uidx;
  uint32_t homrar_ct;
  uint32_t missing_ct;
  uint32_t het_ct;
  uint32_t homset_ct;
  uint32_t uii;

  cur_mapping[1] = 0; // missing
  if (fseeko(bedfile, bed_offset, SEEK_SET)) {
    goto lasso_bigmem_ret_READ_FAIL;
  }
  ulptr_end_init = &(loadbuf_collapsed[sample_valid_ct / BITCT2]);
  fputs("--lasso: Populating data matrix...", stdout);
  fflush(stdout);
  if (covar_ct) {
    dxx = 1.0 / ((double)((intptr_t)sample_valid_ct));
    dyy = (double)((intptr_t)(sample_valid_ct - 1));
    if (!select_covars_bitfield) {
      for (covar_idx = 0; covar_idx < covar_ct; covar_idx++) {
	if (transpose_covar(sample_valid_ct, covar_ct, covar_nm, &(covar_d[covar_idx]), &(data_arr[covar_idx * sample_valid_ct]), sqrt_n_recip, dxx, dyy)) {
	  goto lasso_bigmem_ret_CONST_COVAR;
	}
      }
      if (!select_covars) {
        unselected_covar_ct = covar_ct;
      }
    } else {
      ulii = 0;
      for (covar_idx = 0; covar_idx < covar_ct; covar_idx++) {
	if (IS_SET(select_covars_bitfield, covar_idx)) {
	  continue;
	}
	if (transpose_covar(sample_valid_ct, covar_ct, covar_nm, &(covar_d[covar_idx]), &(data_arr[ulii * sample_valid_ct]), sqrt_n_recip, dxx, dyy)) {
          goto lasso_bigmem_ret_CONST_COVAR;
	}
	ulii++;
      }
      unselected_covar_ct = ulii;
      for (covar_idx = 0; covar_idx < covar_ct; covar_idx++) {
	if (!IS_SET(select_covars_bitfield, covar_idx)) {
	  continue;
	}
	if (transpose_covar(sample_valid_ct, covar_ct, covar_nm, &(covar_d[covar_idx]), &(data_arr[ulii * sample_valid_ct]), sqrt_n_recip, dxx, dyy)) {
          goto lasso_bigmem_ret_CONST_COVAR;
	}
	ulii++;
      }
    }
  }
  dptr = &(data_arr[covar_ct * sample_valid_ct]);
  for (marker_uidx = 0, marker_idx = 0; marker_idx < marker_ct; marker_uidx++, marker_idx++) {
    if (IS_SET(marker_exclude, marker_uidx)) {
      marker_uidx = next_unset_unsafe(marker_exclude, marker_uidx);
      if (fseeko(bedfile, bed_offset + ((uint64_t)marker_uidx) * unfiltered_sample_ct4, SEEK_SET)) {
	goto lasso_bigmem_ret_READ_FAIL;
      }
    }
    if (marker_uidx >= chrom_end) {
      chrom_fo_idx++;
      refresh_chrom_info(chrom_info_ptr, marker_uidx, &chrom_end, &chrom_fo_idx, &is_x, &is_y, &uii, &min_ploidy_1);
    }
    min_ploidy_1 |= uii;
    if (load_and_collapse_incl(bedfile, loadbuf_raw, unfiltered_sample_ct, loadbuf_collapsed, sample_valid_ct, pheno_nm2, final_mask, IS_SET(marker_reverse, marker_uidx))) {
      goto lasso_bigmem_ret_READ_FAIL;
    }
    if (min_ploidy_1) {
      haploid_fix(hh_or_mt_exists, sample_include2, sample_male_include2, sample_valid_ct, is_x, is_y, (unsigned char*)loadbuf_collapsed);
    }
    vec_3freq(sample_valid_ctl2, loadbuf_collapsed, sample_include2, &missing_ct, &het_ct, &homset_ct);
    uii = sample_valid_ct - missing_ct;
    homrar_ct = uii - het_ct - homset_ct;
    if (!(((!homrar_ct) && ((!het_ct) || (!homset_ct))) || ((!het_ct) && (!homset_ct)))) {
      // ok, not monomorphic.  standardize to zero mean, unit variance
      SET_BIT(polymorphic_markers, marker_uidx);
      dyy = (double)(2 * homrar_ct + het_ct); // sum
      dxx = dyy / ((double)((int32_t)uii)); // mean
      dyy = sqrt_n_recip * sqrt(((double)((int32_t)(uii - 1))) / (4 * ((double)((int32_t)homrar_ct)) + ((double)((int32_t)het_ct)) - dyy * dxx)); // 1/(stdev * sqrt(n))
      cur_mapping[0] = (2 - dxx) * dyy; // 2x minor allele
      cur_mapping[2] = (1 - dxx) * dyy; // 1x minor allele
      cur_mapping[3] = (-dxx) * dyy; // no copies of minor allele
      sample_idx = 0;
      sample_idx_stop = BITCT2;
      ulptr = loadbuf_collapsed;
      ulptr_end = ulptr_end_init;
      while (1) {
        while (ulptr < ulptr_end) {
          cur_word = *ulptr++;
          for (; sample_idx < sample_idx_stop; sample_idx++, cur_word >>= 2) {
            cur_genotype = cur_word & 3;
            *dptr++ = cur_mapping[cur_genotype];
	  }
          sample_idx_stop += BITCT2;
	}
        if (sample_idx == sample_valid_ct) {
	  break;
	}
        ulptr_end++;
        sample_idx_stop = sample_valid_ct;
      }
      polymorphic_marker_ct++;
    }
  }
Esempio n. 2
0
int
slap_set_filter( SLAP_SET_GATHER gatherer,
	SetCookie *cp, struct berval *fbv,
	struct berval *user, struct berval *target, BerVarray *results )
{
#define STACK_SIZE	64
#define IS_SET(x)	( (unsigned long)(x) >= 256 )
#define IS_OP(x)	( (unsigned long)(x) < 256 )
#define SF_ERROR(x)	do { rc = -1; goto _error; } while ( 0 )
#define SF_TOP()	( (BerVarray)( ( stp < 0 ) ? 0 : stack[ stp ] ) )
#define SF_POP()	( (BerVarray)( ( stp < 0 ) ? 0 : stack[ stp-- ] ) )
#define SF_PUSH(x)	do { \
		if ( stp >= ( STACK_SIZE - 1 ) ) SF_ERROR( overflow ); \
		stack[ ++stp ] = (BerVarray)(long)(x); \
	} while ( 0 )

	BerVarray	set, lset;
	BerVarray	stack[ STACK_SIZE ] = { 0 };
	int		len, rc, stp;
	unsigned long	op;
	char		c, *filter = fbv->bv_val;

	if ( results ) {
		*results = NULL;
	}

	stp = -1;
	while ( ( c = *filter++ ) ) {
		set = NULL;
		switch ( c ) {
		case ' ':
		case '\t':
		case '\x0A':
		case '\x0D':
			break;

		case '(' /* ) */ :
			if ( IS_SET( SF_TOP() ) ) {
				SF_ERROR( syntax );
			}
			SF_PUSH( c );
			break;

		case /* ( */ ')':
			set = SF_POP();
			if ( IS_OP( set ) ) {
				SF_ERROR( syntax );
			}
			if ( SF_TOP() == (void *)'(' /* ) */ ) {
				SF_POP();
				SF_PUSH( set );
				set = NULL;

			} else if ( IS_OP( SF_TOP() ) ) {
				op = (unsigned long)SF_POP();
				lset = SF_POP();
				SF_POP();
				set = slap_set_join( cp, lset, op, set );
				if ( set == NULL ) {
					SF_ERROR( memory );
				}
				SF_PUSH( set );
				set = NULL;

			} else {
				SF_ERROR( syntax );
			}
			break;

		case '|':	/* union */
		case '&':	/* intersection */
		case '+':	/* string concatenation */
			set = SF_POP();
			if ( IS_OP( set ) ) {
				SF_ERROR( syntax );
			}
			if ( SF_TOP() == 0 || SF_TOP() == (void *)'(' /* ) */ ) {
				SF_PUSH( set );
				set = NULL;

			} else if ( IS_OP( SF_TOP() ) ) {
				op = (unsigned long)SF_POP();
				lset = SF_POP();
				set = slap_set_join( cp, lset, op, set );
				if ( set == NULL ) {
					SF_ERROR( memory );
				}
				SF_PUSH( set );
				set = NULL;
				
			} else {
				SF_ERROR( syntax );
			}
			SF_PUSH( c );
			break;

		case '[' /* ] */:
			if ( ( SF_TOP() == (void *)'/' ) || IS_SET( SF_TOP() ) ) {
				SF_ERROR( syntax );
			}
			for ( len = 0; ( c = *filter++ ) && ( c != /* [ */ ']' ); len++ )
				;
			if ( c == 0 ) {
				SF_ERROR( syntax );
			}
			
			set = cp->set_op->o_tmpcalloc( 2, sizeof( struct berval ),
					cp->set_op->o_tmpmemctx );
			if ( set == NULL ) {
				SF_ERROR( memory );
			}
			set->bv_val = cp->set_op->o_tmpcalloc( len + 1, sizeof( char ),
					cp->set_op->o_tmpmemctx );
			if ( BER_BVISNULL( set ) ) {
				SF_ERROR( memory );
			}
			AC_MEMCPY( set->bv_val, &filter[ - len - 1 ], len );
			set->bv_len = len;
			SF_PUSH( set );
			set = NULL;
			break;

		case '-':
			if ( ( SF_TOP() == (void *)'/' )
				&& ( *filter == '*' || ASCII_DIGIT( *filter ) ) )
			{
				SF_POP();

				if ( *filter == '*' ) {
					set = set_parents( cp, SF_POP() );
					filter++;

				} else {
					char *next = NULL;
					long parent = strtol( filter, &next, 10 );

					if ( next == filter ) {
						SF_ERROR( syntax );
					}

					set = SF_POP();
					if ( parent != 0 ) {
						set = set_parent( cp, set, parent );
					}
					filter = next;
				}

				if ( set == NULL ) {
					SF_ERROR( memory );
				}

				SF_PUSH( set );
				set = NULL;
				break;
			} else {
				c = *filter++;
				if ( c != '>' ) {
					SF_ERROR( syntax );
				}
				/* fall through to next case */
			}

		case '/':
			if ( IS_OP( SF_TOP() ) ) {
				SF_ERROR( syntax );
			}
			SF_PUSH( '/' );
			break;

		default:
			if ( !AD_LEADCHAR( c ) ) {
				SF_ERROR( syntax );
			}
			filter--;
			for ( len = 1;
				( c = filter[ len ] ) && AD_CHAR( c );
				len++ )
			{
				/* count */
				if ( c == '-' && !AD_CHAR( filter[ len + 1 ] ) ) {
					break;
				}
			}
			if ( len == 4
				&& memcmp( "this", filter, len ) == 0 )
			{
				assert( !BER_BVISNULL( target ) );
				if ( ( SF_TOP() == (void *)'/' ) || IS_SET( SF_TOP() ) ) {
					SF_ERROR( syntax );
				}
				set = cp->set_op->o_tmpcalloc( 2, sizeof( struct berval ),
						cp->set_op->o_tmpmemctx );
				if ( set == NULL ) {
					SF_ERROR( memory );
				}
				ber_dupbv_x( set, target, cp->set_op->o_tmpmemctx );
				if ( BER_BVISNULL( set ) ) {
					SF_ERROR( memory );
				}
				BER_BVZERO( &set[ 1 ] );
				
			} else if ( len == 4
				&& memcmp( "user", filter, len ) == 0 ) 
			{
				if ( ( SF_TOP() == (void *)'/' ) || IS_SET( SF_TOP() ) ) {
					SF_ERROR( syntax );
				}
				if ( BER_BVISNULL( user ) ) {
					SF_ERROR( memory );
				}
				set = cp->set_op->o_tmpcalloc( 2, sizeof( struct berval ),
						cp->set_op->o_tmpmemctx );
				if ( set == NULL ) {
					SF_ERROR( memory );
				}
				ber_dupbv_x( set, user, cp->set_op->o_tmpmemctx );
				BER_BVZERO( &set[ 1 ] );
				
			} else if ( SF_TOP() != (void *)'/' ) {
				SF_ERROR( syntax );

			} else {
				struct berval		fb2;
				AttributeDescription	*ad = NULL;
				const char		*text = NULL;

				SF_POP();
				fb2.bv_val = filter;
				fb2.bv_len = len;

				if ( slap_bv2ad( &fb2, &ad, &text ) != LDAP_SUCCESS ) {
					SF_ERROR( syntax );
				}

				/* NOTE: ad must have distinguishedName syntax
				 * or expand in an LDAP URI if c == '*'
				 */
				
				set = set_chase( gatherer,
					cp, SF_POP(), ad, c == '*' );
				if ( set == NULL ) {
					SF_ERROR( memory );
				}
				if ( c == '*' ) {
					len++;
				}
			}
			filter += len;
			SF_PUSH( set );
			set = NULL;
			break;
		}
	}

	set = SF_POP();
	if ( IS_OP( set ) ) {
		SF_ERROR( syntax );
	}
	if ( SF_TOP() == 0 ) {
		/* FIXME: ok ? */ ;

	} else if ( IS_OP( SF_TOP() ) ) {
		op = (unsigned long)SF_POP();
		lset = SF_POP();
		set = slap_set_join( cp, lset, op, set );
		if ( set == NULL ) {
			SF_ERROR( memory );
		}
		
	} else {
		SF_ERROR( syntax );
	}

	rc = slap_set_isempty( set ) ? 0 : 1;
	if ( results ) {
		*results = set;
		set = NULL;
	}

_error:
	if ( IS_SET( set ) ) {
		ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
	}
	while ( ( set = SF_POP() ) ) {
		if ( IS_SET( set ) ) {
			ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
		}
	}
	return rc;
}
Esempio n. 3
0
/* syntax : objectgate <object>
 * ex. objectgate 2.bells
 */
void do_objectgate (CHAR_DATA *ch, char *argument)
{
  OBJ_DATA *obj;
  char arg1[MAX_INPUT_LENGTH];

  argument = one_argument(argument, arg1);

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_MAGE) && !IS_CLASS(ch, CLASS_LICH))
  {
    send_to_char("Huh?\n\r", ch );
    return;
  }
  if (IS_CLASS(ch, CLASS_LICH) && ch->pcdata->powers[CON_LORE] < 1)
  {
    send_to_char("But you don't know how to do that silly.\n\r",ch);
    return;
  }
  if (arg1[0] == '\0')
  {
    send_to_char("What object do you want to attempt to gate?\n\r",ch);
    return;
  }
  if ((obj = get_obj_world(ch, arg1)) == NULL)
  {
    send_to_char("No such object.\n\r",ch);
    return;
  }
  if (IS_SET(obj->quest, QUEST_ARTIFACT) || IS_SET(obj->quest, QUEST_RELIC))
  {
    send_to_char("You cannot grab artifacts or relics.\n\r",ch);
    return;
  }
  if (obj->carried_by != NULL)
  {
    send_to_char("Someone is holding the item.\n\r",ch);
    return;
  }
  if (obj->in_room == NULL)
  {
    send_to_char("It seems to be inside something.\n\r",ch);
    return;
  }
  if (!IS_SET(obj->wear_flags, ITEM_TAKE))
  {
    send_to_char("This item is too big.\n\r",ch);
    return;
  }
  if( IS_SET(obj->in_room->room_flags, ROOM_ASTRAL))
  {
    send_to_char( "You can't find it's room.\n\r",ch);
    return;
  }
  if(IS_SET(ch->in_room->room_flags, ROOM_ASTRAL))
  {
    send_to_char( "Your room is not connected to the astral plane.\n\r",ch);
    return;
  }
  obj_from_room( obj );
  obj_to_char( obj, ch );
  send_to_char("The item appears in your hand.\n\r",ch);
  return;
}
Esempio n. 4
0
/*
 * This function is the very heart of the entire magic system.  All
 * invocations of all types of magic -- objects, spoken and unspoken PC
 * and NPC spells, the works -- all come through this function eventually.
 * This is also the entry point for non-spoken or unrestricted spells.
 * Spellnum 0 is legal but silently ignored here, to make callers simpler.
 */
int	call_magic(struct char_data *caster, struct char_data *cvict,
               struct obj_data *ovict, struct spell_info_type *sptr,
               int level, int casttype, char *tar_str)
{
    int savetype;

    if (!magic_enabled)
        return (0);

    if (caster->nr != real_mobile(DG_CASTER_PROXY)) {
        if (ROOM_FLAGGED(IN_ROOM(caster), ROOM_NOMAGIC)) {
            send_to_char("Your magic fizzles out and dies.\r\n", caster);
            act("$n's magic fizzles out and dies.", FALSE, caster, 0, 0, TO_ROOM);
            return (0);
        }
        if (ROOM_FLAGGED(IN_ROOM(caster), ROOM_PEACEFUL) &&
                (sptr->violent || IS_SET(sptr->routines, MAG_DAMAGE))) {
            send_to_char("A flash of white light fills the room, dispelling your "
                         "violent magic!\r\n", caster);
            act("White light from no particular source suddenly fills the room, "
                "then vanishes.", FALSE, caster, 0, 0, TO_ROOM);
            return (0);
        }
    }
    /* determine the type of saving throw */
    switch (casttype) {
    case CAST_STAFF:
    case CAST_SCROLL:
    case CAST_POTION:
    case CAST_WAND:
        savetype = SAVING_ROD;
        break;
    case CAST_SPELL:
        savetype = SAVING_SPELL;
        break;
    default:
        savetype = SAVING_BREATH;
        break;
    }

    if (IS_SET(sptr->routines, MAG_DAMAGE))
        if (mag_damage(level, caster, cvict, sptr, savetype) == -1)
            return (-1);        /* Successful and target died, don't cast again. */

    if (IS_SET(sptr->routines, MAG_AFFECTS))
        mag_affects(level, caster, cvict, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_UNAFFECTS))
        mag_unaffects(level, caster, cvict, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_POINTS))
        mag_points(level, caster, cvict, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_ALTER_OBJS))
        mag_alter_objs(level, caster, ovict, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_GROUPS))
        mag_groups(level, caster, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_MASSES))
        mag_masses(level, caster, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_AREAS))
        mag_areas(level, caster, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_SUMMONS))
        mag_summons(level, caster, ovict, sptr, savetype);

    if (IS_SET(sptr->routines, MAG_CREATIONS))
        mag_creations(level, caster, sptr);

    if (IS_SET(sptr->routines, MAG_MANUAL))
        switch (sptr->number) {
        case SPELL_CHARM:
            MANUAL_SPELL(spell_charm);
            break;
        case SPELL_CREATE_WATER:
            MANUAL_SPELL(spell_create_water);
            break;
        case SPELL_DETECT_POISON:
            MANUAL_SPELL(spell_detect_poison);
            break;
        case SPELL_ENCHANT_WEAPON:
            MANUAL_SPELL(spell_enchant_weapon);
            break;
        case SPELL_IDENTIFY:
            MANUAL_SPELL(spell_identify);
            break;
        case SPELL_LOCATE_OBJECT:
            MANUAL_SPELL(spell_locate_object);
            break;
        case SPELL_SUMMON:
            MANUAL_SPELL(spell_summon);
            break;
        case SPELL_WORD_OF_RECALL:
            MANUAL_SPELL(spell_recall);
            break;
        case SPELL_TELEPORT:
            MANUAL_SPELL(spell_teleport);
            break;
        case SPELL_MINOR_IDENTIFY:
            MANUAL_SPELL(spell_minor_identify);
            break;
        case SPELL_PORTAL:
            MANUAL_SPELL(spell_portal);
            break;
        case SPELL_ARCANE_WORD:
            MANUAL_SPELL(spell_arcane_word);
            break;
        case SPELL_ARCANE_PORTAL:
            MANUAL_SPELL(spell_arcane_portal);
            break;
        }

    return (1);
}
Esempio n. 5
0
int	cast_spell(struct char_data *ch, struct char_data *tch,
               struct obj_data *tobj, struct spell_info_type *sptr,
               char *tar_str)
{

    if (!magic_enabled)
        return (0);

    if (!sptr) {
        extended_mudlog(NRM, SYSL_BUGS, TRUE, "cast_spell() called without a valid sptr: ch: %s, tch: %s",
                        GET_NAME(ch), GET_NAME(tch));
        return (0);
    }

    if (GET_POS(ch) < sptr->min_position) {
        switch (GET_POS(ch)) {
        case POS_SLEEPING:
            send_to_char("You dream about great magical powers.\r\n", ch);
            break;
        case POS_RESTING:
            send_to_char("You cannot concentrate while resting.\r\n", ch);
            break;
        case POS_SITTING:
            send_to_char("You can't do this sitting!\r\n", ch);
            break;
        case POS_FIGHTING:
            send_to_char("Impossible!  You can't concentrate enough!\r\n", ch);
            break;
        default:
            send_to_char("You can't do much of anything like this!\r\n", ch);
            break;
        }
        return (0);
    }
    if (AFF_FLAGGED(ch, AFF_CHARM) && (ch->master == tch)) {
        send_to_char("You are afraid you might hurt your master!\r\n", ch);
        return (0);
    }
    if ((tch != ch) && IS_SET(sptr->targets, TAR_SELF_ONLY)) {
        send_to_char("You can only cast this spell upon yourself!\r\n", ch);
        return (0);
    }
    if ((tch == ch) && IS_SET(sptr->targets, TAR_NOT_SELF)) {
        send_to_char("You cannot cast this spell upon yourself!\r\n", ch);
        return (0);
    }
    if (IS_SET(sptr->routines, MAG_GROUPS) && !AFF_FLAGGED(ch, AFF_GROUP)) {
        send_to_char("You can't cast this spell if you're not in a group!\r\n",ch);
        return (0);
    }

    if (cast_mtrigger(tch, ch, tar_str, sptr) == 0)
        return (0);
    if (cast_otrigger(tobj, ch, tar_str, sptr) == 0)
        return (0);
    if (cast_wtrigger(ch, tch, tobj, tar_str, sptr) == 0)
        return (0);

    send_to_char(OK, ch);
    say_spell(ch, sptr, tch, tobj);

    return (call_magic(ch, tch, tobj, sptr, (GET_SKILL(ch, sptr->skill)/100), CAST_SPELL,
                       tar_str));
}
Esempio n. 6
0
File: clan.c Progetto: verias/SRMud
bool is_leader(CHAR_DATA * ch)
{
    /* update by: Zak Johnson ([email protected]) Thanks Zak! */
    return IS_SET(ch->act, PLR_MORTAL_LEADER) ? 1 : 0;
} /* end: is_leader */
Esempio n. 7
0
File: clan.c Progetto: verias/SRMud
void do_clanadd(CHAR_DATA * ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *victim;
    int clan;

    argument = one_argument(argument, arg1);
    argument = one_argument(argument, arg2);

    if (!can_clan(ch))
    {
	send_to_char("huh?\n\r", ch);
	return;
    }
    if (arg1[0] == '\0' || arg2[0] == '\0')
    {
	send_to_char("Syntax: guild <char> <cln name>\n\r", ch);
	return;
    }
    if ((victim = get_char_world(ch, arg1)) == NULL)
    {
	send_to_char("They aren't playing.\n\r", ch);
	return;
    }

    /** thanks to Zanthras for the bug fix here...*/
    if (is_clan(victim) && !is_same_clan(ch, victim) &&
	((ch->level < SUPREME) & (ch->trust < SUPREME)))
    {
	send_to_char("They are a member of a clan other than your own.\n\r", ch);
	return;
    }

    if (!str_prefix(arg2, "none"))
    {
	send_to_char("They are no longer a member of any clan.\n\r", ch);
	send_to_char("You are no longer a member of any clan!\n\r", victim);
	victim->clan = 0;
	victim->rank = 0;

	/* add by: Zak Jonhson ([email protected]) */
	if (IS_SET(victim->act, PLR_MORTAL_LEADER))
	    REMOVE_BIT(victim->act, PLR_MORTAL_LEADER);

	return;
    }
    if ((clan = clan_lookup(arg2)) == 0)
    {
	send_to_char("No such clan exists.\n\r", ch);
	return;
    }
    sprintf(buf, "They are now a %s of the %s.\n\r",
	    clan_table[clan].rank[0].rankname, clan_table[clan].name);
    send_to_char(buf, ch);

    sprintf(buf, "You are now a %s of the %s.\n\r",
	    clan_table[clan].rank[0].rankname, clan_table[clan].name);
    send_to_char(buf, victim);

    victim->clan = clan;
    victim->rank = 0;		/* lowest, default */
} /* end: do_guild */
Esempio n. 8
0
/* ---------------------------------------------------------------------
 * CMD_EVAL
 * This monster evaluates an if/or/and statement
 * There are five kinds of statement:
 * 1) keyword and value (no $-code)	    if random 30
 * 2) keyword, comparison and value	    if people > 2
 * 3) keyword and actor		    	    if isnpc $n
 * 4) keyword, actor and value		    if carries $n sword
 * 5) keyword, actor, comparison and value  if level $n >= 10
 *
 *----------------------------------------------------------------------
 */
int
cmd_eval (sh_int vnum, char *line, int check,
	  CHAR_DATA * mob, CHAR_DATA * ch,
	  const void *arg1, const void *arg2, CHAR_DATA * rch)
{
  CHAR_DATA *lval_char = mob;
  CHAR_DATA *vch = (CHAR_DATA *) arg2;
  OBJ_DATA *obj1 = (OBJ_DATA *) arg1;
  OBJ_DATA *obj2 = (OBJ_DATA *) arg2;
  OBJ_DATA *lval_obj = NULL;

  char *original, buf[MAX_INPUT_LENGTH], code;
  int lval = 0, oper = 0, rval = -1;

  original = line;
  line = one_argument (line, buf);
  if (buf[0] == '\0' || mob == NULL)
    return FALSE;

  /*
   * If this mobile has no target, let's assume our victim is the one
   */
  if (mob->mprog_target == NULL)
    mob->mprog_target = ch;

  switch (check)
    {
      /*
       * Case 1: keyword and value
       */
    case CHK_RAND:
      return (atoi (buf) < number_percent ());
    case CHK_MOBHERE:
      if (is_number (buf))
	return (get_mob_vnum_room (mob, atoi (buf)));
      else
	return ((bool) (get_char_room (mob, buf) != NULL));
    case CHK_OBJHERE:
      if (is_number (buf))
	return (get_obj_vnum_room (mob, atoi (buf)));
      else
	return ((bool) (get_obj_here (mob, buf) != NULL));
    case CHK_MOBEXISTS:
      return ((bool) (get_char_world (mob, buf) != NULL));
    case CHK_OBJEXISTS:
      return ((bool) (get_obj_world (mob, buf) != NULL));
      /*
       * Case 2 begins here: We sneakily use rval to indicate need
       *                     for numeric eval...
       */
    case CHK_PEOPLE:
      rval = count_people_room (mob, 0);
      break;
    case CHK_PLAYERS:
      rval = count_people_room (mob, 1);
      break;
    case CHK_MOBS:
      rval = count_people_room (mob, 2);
      break;
    case CHK_CLONES:
      rval = count_people_room (mob, 3);
      break;
    case CHK_ORDER:
      rval = get_order (mob);
      break;
    case CHK_HOUR:
      rval = time_info.hour;
      break;
    default:;
    }

  /*
   * Case 2 continued: evaluate expression
   */
  if (rval >= 0)
    {
      if ((oper = keyword_lookup (fn_evals, buf)) < 0)
	{
	  sprintf (buf, "Cmd_eval: prog %d syntax error(2) '%s'",
		   vnum, original);
	  bug (buf, 0);
	  return FALSE;
	}
      one_argument (line, buf);
      lval = rval;
      rval = atoi (buf);
      return (num_eval (lval, oper, rval));
    }

  /*
   * Case 3,4,5: Grab actors from $* codes
   */
  if (buf[0] != '$' || buf[1] == '\0')
    {
      sprintf (buf, "Cmd_eval: prog %d syntax error(3) '%s'", vnum, original);
      bug (buf, 0);
      return FALSE;
    }
  else
    code = buf[1];
  switch (code)
    {
    case 'i':
      lval_char = mob;
      break;
    case 'n':
      lval_char = ch;
      break;
    case 't':
      lval_char = vch;
      break;
    case 'r':
      lval_char = rch == NULL ? get_random_char (mob) : rch;
      break;
    case 'o':
      lval_obj = obj1;
      break;
    case 'p':
      lval_obj = obj2;
      break;
    case 'q':
      lval_char = mob->mprog_target;
      break;
    default:
      sprintf (buf, "Cmd_eval: prog %d syntax error(4) '%s'", vnum, original);
      bug (buf, 0);
      return FALSE;
    }
  /*
   * From now on, we need an actor, so if none was found, bail out
   */
  if (lval_char == NULL && lval_obj == NULL)
    return FALSE;

  /*
   * Case 3: Keyword, comparison and value
   */
  switch (check)
    {
    case CHK_ISPC:
      return (lval_char != NULL && !IS_NPC (lval_char));
    case CHK_ISNPC:
      return (lval_char != NULL && IS_NPC (lval_char));
    case CHK_ISGOOD:
      return (lval_char != NULL && IS_GOOD (lval_char));
    case CHK_ISEVIL:
      return (lval_char != NULL && IS_EVIL (lval_char));
    case CHK_ISNEUTRAL:
      return (lval_char != NULL && IS_NEUTRAL (lval_char));
    case CHK_ISIMMORT:
      return (lval_char != NULL && IS_IMMORTAL (lval_char));
    case CHK_ISCHARM:		/* A relic from MERC 2.2 MOBprograms */
      return (lval_char != NULL && IS_AFFECTED (lval_char, AFF_CHARM));
    case CHK_ISFOLLOW:
      return (lval_char != NULL && lval_char->master != NULL
	      && lval_char->master->in_room == lval_char->in_room);
    case CHK_ISACTIVE:
      return (lval_char != NULL && lval_char->position > POS_SLEEPING);
    case CHK_ISDELAY:
      return (lval_char != NULL && lval_char->mprog_delay > 0);
    case CHK_ISVISIBLE:
      switch (code)
	{
	default:
	case 'i':
	case 'n':
	case 't':
	case 'r':
	case 'q':
	  return (lval_char != NULL && can_see (mob, lval_char));
	case 'o':
	case 'p':
	  return (lval_obj != NULL && can_see_obj (mob, lval_obj));
	}
    case CHK_HASTARGET:
      return (lval_char != NULL && lval_char->mprog_target != NULL
	      && lval_char->in_room == lval_char->mprog_target->in_room);
    case CHK_ISTARGET:
      return (lval_char != NULL && mob->mprog_target == lval_char);
    default:;
    }

  /* 
   * Case 4: Keyword, actor and value
   */
  line = one_argument (line, buf);
  switch (check)
    {
    case CHK_AFFECTED:
      return (lval_char != NULL
	      && IS_SET (lval_char->affected_by,
			 flag_lookup (buf, affect_flags)));
    case CHK_ACT:
      return (lval_char != NULL
	      && IS_SET (lval_char->act, flag_lookup (buf, act_flags)));
    case CHK_IMM:
      return (lval_char != NULL
	      && IS_SET (lval_char->imm_flags, flag_lookup (buf, imm_flags)));
    case CHK_OFF:
      return (lval_char != NULL
	      && IS_SET (lval_char->off_flags, flag_lookup (buf, off_flags)));
    case CHK_CARRIES:
      if (is_number (buf))
	return (lval_char != NULL
		&& has_item (lval_char, atoi (buf), -1, FALSE));
      else
	return (lval_char != NULL
		&& (get_obj_carry (lval_char, buf) != NULL));
    case CHK_WEARS:
      if (is_number (buf))
	return (lval_char != NULL
		&& has_item (lval_char, atoi (buf), -1, TRUE));
      else
	return (lval_char != NULL && (get_obj_wear (lval_char, buf) != NULL));
    case CHK_HAS:
      return (lval_char != NULL
	      && has_item (lval_char, -1, item_lookup (buf), FALSE));
    case CHK_USES:
      return (lval_char != NULL
	      && has_item (lval_char, -1, item_lookup (buf), TRUE));
    case CHK_NAME:
      switch (code)
	{
	default:
	case 'i':
	case 'n':
	case 't':
	case 'r':
	case 'q':
	  return (lval_char != NULL && is_name (buf, lval_char->name));
	case 'o':
	case 'p':
	  return (lval_obj != NULL && is_name (buf, lval_obj->name));
	}
    case CHK_POS:
      return (lval_char != NULL
	      && lval_char->position == position_lookup (buf));
    case CHK_CLAN:
      return (lval_char != NULL && lval_char->clan == clan_lookup (buf));
    case CHK_RACE:
      return (lval_char != NULL && lval_char->race == race_lookup (buf));
    case CHK_OBJTYPE:
      return (lval_obj != NULL && lval_obj->item_type == item_lookup (buf));
    default:;
    }

  /*
   * Case 5: Keyword, actor, comparison and value
   */
  if ((oper = keyword_lookup (fn_evals, buf)) < 0)
    {
      sprintf (buf, "Cmd_eval: prog %d syntax error(5): '%s'",
	       vnum, original);
      bug (buf, 0);
      return FALSE;
    }
  one_argument (line, buf);
  rval = atoi (buf);

  switch (check)
    {
    case CHK_VNUM:
      switch (code)
	{
	default:
	case 'i':
	case 'n':
	case 't':
	case 'r':
	case 'q':
	  if (lval_char != NULL && IS_NPC (lval_char))
	    lval = lval_char->pIndexData->vnum;
	  break;
	case 'o':
	case 'p':
	  if (lval_obj != NULL)
	    lval = lval_obj->pIndexData->vnum;
	}
      break;
    case CHK_HPCNT:
      if (lval_char != NULL)
	lval = (lval_char->hit * 100) / (UMAX (1, lval_char->max_hit));
      break;
    case CHK_ROOM:
      if (lval_char != NULL && lval_char->in_room != NULL)
	lval = lval_char->in_room->vnum;
      break;
    case CHK_SEX:
      if (lval_char != NULL)
	lval = lval_char->sex;
      break;
    case CHK_LEVEL:
      if (lval_char != NULL)
	lval = lval_char->level;
      break;
    case CHK_ALIGN:
      if (lval_char != NULL)
	lval = lval_char->alignment;
      break;
    case CHK_MONEY:		/* Money is converted to silver... */
      if (lval_char != NULL)
	lval = lval_char->gold + (lval_char->silver * 100);
      break;
    case CHK_OBJVAL0:
      if (lval_obj != NULL)
	lval = lval_obj->value[0];
      break;
    case CHK_OBJVAL1:
      if (lval_obj != NULL)
	lval = lval_obj->value[1];
      break;
    case CHK_OBJVAL2:
      if (lval_obj != NULL)
	lval = lval_obj->value[2];
      break;
    case CHK_OBJVAL3:
      if (lval_obj != NULL)
	lval = lval_obj->value[3];
      break;
    case CHK_OBJVAL4:
      if (lval_obj != NULL)
	lval = lval_obj->value[4];
      break;
    case CHK_GRPSIZE:
      if (lval_char != NULL)
	lval = count_people_room (lval_char, 4);
      break;
    default:
      return FALSE;
    }
  return (num_eval (lval, oper, rval));
}
Esempio n. 9
0
void damage(struct char_data *ch, struct char_data *victim,
            int dam, int attacktype)
{
	char buf[MAX_STRING_LENGTH];
	struct message_type *messages;
	int i,j,nr,max_hit,exp;

	int hit_limit(struct char_data *ch);

	assert(GET_POS(victim) > POSITION_DEAD);

	if ((GET_LEVEL(victim)>20) && !IS_NPC(victim)) /* You can't damage an immortal! */
		dam=0;
		
	if (victim != ch) {
		if (GET_POS(victim) > POSITION_STUNNED) {
			if (!(victim->specials.fighting))
				set_fighting(victim, ch);
			GET_POS(victim) = POSITION_FIGHTING;
		}

		if (GET_POS(ch) > POSITION_STUNNED) {
			if (!(ch->specials.fighting))
				set_fighting(ch, victim);

			if (IS_NPC(ch) && IS_NPC(victim) &&
          victim->master &&
			    !number(0,10) && IS_AFFECTED(victim, AFF_CHARM) &&
			    (victim->master->in_room == ch->in_room)) {
				if (ch->specials.fighting)
					stop_fighting(ch);
				hit(ch, victim->master, TYPE_UNDEFINED);
				return;
			}
		}
	}

	if (victim->master == ch)
		stop_follower(victim);
			
	if (IS_AFFECTED(ch, AFF_INVISIBLE))
		appear(ch);

	if (IS_AFFECTED(victim, AFF_SANCTUARY))
		dam = MIN(dam, 18);  /* Max 18 damage when sanctuary */

	dam=MIN(dam,100);

	dam=MAX(dam,0);

	GET_HIT(victim)-=dam;

	if (ch != victim)
		gain_exp(ch,GET_LEVEL(victim)*dam);

	update_pos(victim);


	if ((attacktype >= TYPE_HIT) && (attacktype <= TYPE_SLASH)) {
		if (!ch->equipment[WIELD]) {
			dam_message(dam, ch, victim, TYPE_HIT);
		} else {
			dam_message(dam, ch, victim, attacktype);
		}
	} else {

	for(i = 0; i < MAX_MESSAGES; i++) {
		if (fight_messages[i].a_type == attacktype) {
			nr=dice(1,fight_messages[i].number_of_attacks);
			for(j=1,messages=fight_messages[i].msg;(j<nr)&&(messages);j++)
				messages=messages->next;

			if (!IS_NPC(victim) && (GET_LEVEL(victim) > 20)) {
				act(messages->god_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR);
				act(messages->god_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT);
				act(messages->god_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT);
			} else if (dam != 0) {
				if (GET_POS(victim) == POSITION_DEAD) {
					act(messages->die_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR);
					act(messages->die_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT);
					act(messages->die_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT);
				} else {
					act(messages->hit_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR);
					act(messages->hit_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT);
					act(messages->hit_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT);
				}
			} else { /* Dam == 0 */
				act(messages->miss_msg.attacker_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_CHAR);
				act(messages->miss_msg.victim_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_VICT);
				act(messages->miss_msg.room_msg, FALSE, ch, ch->equipment[WIELD], victim, TO_NOTVICT);
			}
		}
	}
	}
	switch (GET_POS(victim)) {
		case POSITION_MORTALLYW:
			act("$n is mortally wounded, and will die soon, if not aided.", TRUE, victim, 0, 0, TO_ROOM);
			act("You are mortally wounded, and will die soon, if not aided.", FALSE, victim, 0, 0, TO_CHAR);
			break;
		case POSITION_INCAP:
			act("$n is incapacitated and will slowly die, if not aided.", TRUE, victim, 0, 0, TO_ROOM);
			act("You are incapacitated an will slowly die, if not aided.", FALSE, victim, 0, 0, TO_CHAR);
			break;
		case POSITION_STUNNED:
			act("$n is stunned, but will probably regain conscience again.", TRUE, victim, 0, 0, TO_ROOM);
			act("You're stunned, but will probably regain conscience again.", FALSE, victim, 0, 0, TO_CHAR);
			break;
		case POSITION_DEAD:
			act("$n is dead! R.I.P.", TRUE, victim, 0, 0, TO_ROOM);
			act("You are dead!  Sorry...", FALSE, victim, 0, 0, TO_CHAR);
			break;

		default:  /* >= POSITION SLEEPING */

			max_hit=hit_limit(victim);

			if (dam > (max_hit/5))
				act("That Really did HURT!",FALSE, victim, 0, 0, TO_CHAR);

			if (GET_HIT(victim) < (max_hit/5)) {

				act("You wish that your wounds would stop BLEEDING that much!",FALSE,victim,0,0,TO_CHAR);
				if (IS_NPC(victim))
					if (IS_SET(victim->specials.act, ACT_WIMPY))
						do_flee(victim, "", 0);
			}
			break;		
	}

	if (!IS_NPC(victim) && !(victim->desc)) {
		do_flee(victim, "", 0);
		if (!victim->specials.fighting) {
			act("$n is rescued by divine forces.", FALSE, victim, 0, 0, TO_ROOM);
			victim->specials.was_in_room = victim->in_room;
			char_from_room(victim);
			char_to_room(victim, 0);
		}
	}

	if (GET_POS(victim) < POSITION_STUNNED)
		if (ch->specials.fighting == victim)
			stop_fighting(ch);

	if (!AWAKE(victim))
		if (victim->specials.fighting)
			stop_fighting(victim);

	if (GET_POS(victim) == POSITION_DEAD) {
		if (IS_NPC(victim) || victim->desc)
			if (IS_AFFECTED(ch, AFF_GROUP)) {
					group_gain(ch, victim);
			} else {
				/* Calculate level-difference bonus */
				exp = GET_EXP(victim)/3;
				if (IS_NPC(ch))
					exp += (exp*MIN(4, (GET_LEVEL(victim) - GET_LEVEL(ch))))>>3;
				else
					exp += (exp*MIN(8, (GET_LEVEL(victim) - GET_LEVEL(ch))))>>3;
				exp = MAX(exp, 1);
				gain_exp(ch, exp);
				change_alignment(ch, victim);
			}
		if (!IS_NPC(victim)) {
			sprintf(buf, "%s killed by %s at %s",
				GET_NAME(victim),
				(IS_NPC(ch) ? ch->player.short_descr : GET_NAME(ch)),
				world[victim->in_room].name);
			log(buf);
		}
		die(victim);
	}
Esempio n. 10
0
void do_makejetpack( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    int level, chance, strength;
    bool checktool, checkbatt, checkchem, checkcirc, checkmetal;
    OBJ_DATA *obj;
    OBJ_INDEX_DATA *pObjIndex;
    int vnum;

    strcpy( arg , argument );

    switch( ch->substate )
    {
    	default:
    	        if ( arg[0] == '\0' )
                {
                  send_to_char( "&RUsage: Makejetpack <Name>\n\r&w", ch);
                  return;
                }

                checktool  = FALSE;
                checkbatt  = FALSE;
                checkchem  = FALSE;
                checkcirc  = FALSE;
                checkmetal = FALSE;

                if ( !IS_SET( ch->in_room->room_flags, ROOM_FACTORY ) )
                {
                   send_to_char( "&RYou need to be in a factory or workshop to do that.\n\r", ch);
                   return;
                }

                for ( obj = ch->last_carrying; obj; obj = obj->prev_content )
                {
                  if (obj->item_type == ITEM_TOOLKIT)
                    checktool = TRUE;
                  if (obj->item_type == ITEM_BATTERY)
                    checkbatt = TRUE;
                  if (obj->item_type == ITEM_CIRCUIT)
                    checkcirc = TRUE;
                  if (obj->item_type == ITEM_CHEMICAL)
                    checkchem = TRUE;
                  if (obj->item_type == ITEM_RARE_METAL)
                    checkmetal = TRUE;
                }

                if ( !checktool )
                {
                   send_to_char( "&RYou need toolkit to make the Jetpack\n\r", ch);
                   return;
                }

                if ( !checkmetal )
                {
                   send_to_char( "&RYou need a piece metal to craft the Jetpack.\n\r", ch);
                   return;
                }

                if ( !checkbatt )
                {
                   send_to_char( "&RYou need a battery for the mechanism to work.\n\r", ch);
                   return;
                }

                if ( !checkcirc )
                {
                   send_to_char( "&RYou need a small circuit.\n\r", ch);
                   return;
                }

                if ( !checkchem )
                {
                   send_to_char( "&RSome chemicals for the combustion.\n\r", ch);
                   return;
                }

                chance = IS_NPC(ch) ? ch->top_level : (int) (ch->pcdata->learned[gsn_makejetpack]);
                if ( number_percent( ) < chance )
                {
                   send_to_char( "&GYou begin the long process of crafting a Jetpack\n\r", ch);
                   act( AT_PLAIN, "$n takes $s tools and begins to work on something.", ch, NULL, argument , TO_ROOM );
                   add_timer ( ch , TIMER_DO_FUN , 15 , do_makejetpack , 1 );
                   ch->dest_buf   = str_dup(arg);
                   return;
                }
                send_to_char("&RYou can't figure out how to fit the parts together.\n\r",ch);
                learn_from_failure( ch, gsn_makejetpack );
                return;

        case 1:
                if ( !ch->dest_buf )
                 return;
                strcpy(arg, ch->dest_buf);
                DISPOSE( ch->dest_buf);
                break;

        case SUB_TIMER_DO_ABORT:
                DISPOSE( ch->dest_buf );
                ch->substate = SUB_NONE;
                send_to_char("&RYou are interupted and fail to finish your work.\n\r", ch);
                return;
    }

    ch->substate = SUB_NONE;

    level = IS_NPC(ch) ? ch->top_level : (int) (ch->pcdata->learned[gsn_makejetpack]);
    vnum = 88;

    if ( ( pObjIndex = get_obj_index( vnum ) ) == NULL )
    {
         send_to_char( "&RThe item you are trying to create is missing from the database.\n\rPlease inform the administration of this error.\n\r", ch );
         return;
    }

    checktool = FALSE;
    checkmetal = FALSE;
    checkbatt = FALSE;
    checkchem = FALSE;
    checkcirc = FALSE;

    for ( obj = ch->last_carrying; obj; obj = obj->prev_content )
    {
       if (obj->item_type == ITEM_TOOLKIT)
          checktool = TRUE;
       if (obj->item_type == ITEM_BATTERY && checkbatt == FALSE)
       {
          strength = obj->value[0];
          separate_obj( obj );
          obj_from_char( obj );
          extract_obj( obj );
          checkbatt = TRUE;
       }
       if (obj->item_type == ITEM_CHEMICAL)
       {
          separate_obj( obj );
          obj_from_char( obj );
          extract_obj( obj );
          checkchem = TRUE;
       }
       if (obj->item_type == ITEM_CIRCUIT && checkcirc == FALSE)
       {
          separate_obj( obj );
          obj_from_char( obj );
          extract_obj( obj );
          checkcirc = TRUE;
       }
       if (obj->item_type == ITEM_RARE_METAL && checkmetal == FALSE)
       {
          separate_obj( obj );
          obj_from_char( obj );
          extract_obj( obj );
          checkmetal = TRUE;
       }
    }

    chance = IS_NPC(ch) ? ch->top_level : (int) (ch->pcdata->learned[gsn_makejetpack]) ;

    if ( number_percent( ) > chance*2  || ( !checktool ) || ( !checkmetal )
         || ( !checkbatt ) || ( !checkchem ) || ( !checkcirc) )
    {
       send_to_char( "You hit the 'on' switch and watch the Jetpack explode into pieces.", ch);
       learn_from_failure( ch, gsn_makejetpack );
       return;
    }

    obj = create_object( pObjIndex, level );

    obj->item_type = ITEM_ARMOR;
    SET_BIT( obj->wear_flags, ITEM_TAKE );
    SET_BIT( obj->wear_flags, ITEM_WEAR_BACK );
    obj->level = level;
    obj->weight = 1;
    STRFREE( obj->name );
    strcpy( buf , arg );
    obj->name = STRALLOC( buf );
    strcpy( buf, arg );
    STRFREE( obj->short_descr );
    obj->short_descr = STRALLOC( buf );
    STRFREE( obj->description );
    strcat( buf, " was left behind here." );
    obj->description = STRALLOC( buf );

    obj->value[0] = 0;
    obj->value[0] = 0;
    obj->value[0] = 0;
    obj->cost = 5000;

    obj = obj_to_char( obj, ch );

    send_to_char( "&GYou finish your work and hold up your newly created Jetpack.&w\n\r", ch);
    act( AT_PLAIN, "$n finishes making $s new Jetpack.", ch,
         NULL, argument , TO_ROOM );

    {
         long xpgain;

         xpgain = UMIN( obj->cost*100 ,
            ( exp_level(ch->skill_level[ENGINEERING_ABILITY]+1) -
              exp_level(ch->skill_level[ENGINEERING_ABILITY]) ) );
         gain_exp(ch, xpgain, ENGINEERING_ABILITY);
         ch_printf( ch , "You gain %d engineering experience.", xpgain );
    }
        learn_from_success( ch, gsn_makejetpack );
}
Esempio n. 11
0
char *get_exits( CHAR_DATA * ch )
{
   static char buf[MAX_STRING_LENGTH];
   EXIT_DATA *pexit;
   bool found = FALSE;

   buf[0] = '\0';

   if( !check_blind( ch ) )
      return buf;

   set_char_color( AT_EXITS, ch );

   mudstrlcpy( buf, "[Exits:", MAX_STRING_LENGTH );

   for( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
   {
      if( IS_IMMORTAL( ch ) )
         /*
          * Immortals see all exits, even secret ones 
          */
      {
         if( pexit->to_room )
         {
            found = TRUE;
            mudstrlcat( buf, " ", MAX_STRING_LENGTH );

            mudstrlcat( buf, capitalize( dir_name[pexit->vdir] ), MAX_STRING_LENGTH );

            /*
             * New code added to display closed, or otherwise invisible exits to immortals 
             * Installed by Samson 1-25-98 
             */
            if( IS_SET( pexit->exit_info, EX_CLOSED ) )
               mudstrlcat( buf, "->(Closed)", MAX_STRING_LENGTH );
            if( IS_SET( pexit->exit_info, EX_DIG ) )
               mudstrlcat( buf, "->(Dig)", MAX_STRING_LENGTH );
            if( IS_SET( pexit->exit_info, EX_WINDOW ) )
               mudstrlcat( buf, "->(Window)", MAX_STRING_LENGTH );
            if( IS_SET( pexit->exit_info, EX_HIDDEN ) )
               mudstrlcat( buf, "->(Hidden)", MAX_STRING_LENGTH );
            if( xIS_SET( pexit->to_room->room_flags, ROOM_DEATH ) )
               mudstrlcat( buf, "->(Deathtrap)", MAX_STRING_LENGTH );
         }
      }
      else
      {
         if( pexit->to_room
             && !IS_SET( pexit->exit_info, EX_SECRET )
             && ( !IS_SET( pexit->exit_info, EX_WINDOW ) || IS_SET( pexit->exit_info, EX_ISDOOR ) )
             && !IS_SET( pexit->exit_info, EX_HIDDEN ) )
         {
            found = TRUE;
            mudstrlcat( buf, " ", MAX_STRING_LENGTH );

            mudstrlcat( buf, capitalize( dir_name[pexit->vdir] ), MAX_STRING_LENGTH );

            if( IS_SET( pexit->exit_info, EX_CLOSED ) )
               mudstrlcat( buf, "->(Closed)", MAX_STRING_LENGTH );
            if( IS_AFFECTED( ch, AFF_DETECTTRAPS ) && xIS_SET( pexit->to_room->room_flags, ROOM_DEATH ) )
               mudstrlcat( buf, "->(Deathtrap)", MAX_STRING_LENGTH );
         }
      }
   }

   if( !found )
      mudstrlcat( buf, " none]", MAX_STRING_LENGTH );
   else
      mudstrlcat( buf, "]", MAX_STRING_LENGTH );
   mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
   return buf;
}
Esempio n. 12
0
/* The effectiveness of the modules can vary depending on the level of the technitian's makemodule skill */
void do_makemodule( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    int affecttype, affectammount;
    char name[MAX_STRING_LENGTH];
    int level, chance;
    bool checklens, checkbat, checksuper, checkcircuit, checktool; 
    OBJ_DATA *obj;
    OBJ_INDEX_DATA *pObjIndex;
            
    argument = one_argument( argument, arg );


    switch( ch->substate )
    { 
    	default:
    	        
     		if(str_cmp(arg, "hull") && str_cmp( arg, "slave") && str_cmp( arg, "tractor") && str_cmp(arg, "torpedo") && str_cmp(arg, "rocket") && str_cmp(arg, "missile") && str_cmp(arg, "primary") && str_cmp(arg, "secondary") && str_cmp(arg, "shield") && str_cmp(arg, "speed") && str_cmp(arg, "hyperspeed") && str_cmp(arg, "energy") && str_cmp(arg, "manuever") && str_cmp(arg, "chaff") && str_cmp(arg, "alarm")){
    		  send_to_char("Modules may affect the following aspects of the ship:\n\rPrimary, Secondary, Missile, Rocket, Torpedo, Hull, Shield, Speed, Hyperspeed, Energy, Manuever, Slave, Tractor, Chaff, and Alarm.\n\r", ch);
    		  return;
    		}
                checklens = FALSE;
                checkbat = FALSE;
                checksuper = FALSE;
                checkcircuit = FALSE;
                checktool = FALSE;
                if ( !IS_SET( ch->in_room->room_flags, ROOM_FACTORY ) )
                {
                   send_to_char( "&RYou need to be in a factory or workshop to do that.\n\r", ch);
                   return;
                }
                
                for ( obj = ch->last_carrying; obj; obj = obj->prev_content )     
                {
                  if (obj->item_type == ITEM_LENS)
                    checklens = TRUE;
                  if (obj->item_type == ITEM_BATTERY)
          	    checkbat = TRUE;
                  if (obj->item_type == ITEM_SUPERCONDUCTOR)
                    checksuper = TRUE;
                  if (obj->item_type == ITEM_CIRCUIT)
                    checkcircuit = TRUE;
                  if (obj->item_type == ITEM_TOOLKIT)
                    checktool = TRUE;
          	    
                }
                
                if ( !checklens )
                {
                   send_to_char( "&RYou need a lens to control the energy.\n\r", ch);
                   return;
                }
 
                if ( !checkbat )
                {
                   send_to_char( "&RYou need a battery to power the module.\n\r", ch);
                   return;
                }

                if ( !checksuper )
                {
                   send_to_char( "&RYou need a superconductor to focus the energy.\n\r", ch);
                   return;
                }

                if ( !checkcircuit )
                {
                   send_to_char( "&RYou need a circuit board to control the module.\n\r", ch);
                   return;
                }

                if ( !checktool )
                {
                   send_to_char( "&RYou need a toolkit to build the module.\n\r", ch);
                   return;
                }
                
                
                

    	        chance = IS_NPC(ch) ? ch->top_level
	                 : (int) (ch->pcdata->learned[gsn_makemodule]);
                if ( number_percent( ) < chance )
    		{
    		   send_to_char( "&GYou begin the long process of creating a module.\n\r", ch);
    		   act( AT_PLAIN, "$n takes $s tools and begins to work.", ch,
		        NULL, argument , TO_ROOM );
		   add_timer ( ch , TIMER_DO_FUN , 10 , do_makemodule , 1 );
    		   ch->dest_buf = str_dup(arg);
    		   return;
	        }
	        send_to_char("&RYou can't figure out what to do.\n\r",ch);
	        learn_from_failure( ch, gsn_makemodule );
    	   	return;	
    	
    	case 1: 
    		if ( !ch->dest_buf )
    		     return;
    		strcpy(arg, ch->dest_buf);
    		DISPOSE( ch->dest_buf);
    		break;
    		
    	case SUB_TIMER_DO_ABORT:
    		DISPOSE( ch->dest_buf );
    		ch->substate = SUB_NONE;    		                                   
    	        send_to_char("&RYou are interupted and fail to finish your work.\n\r", ch);
    	        return;
    }
    
    ch->substate = SUB_NONE;
    
    level = IS_NPC(ch) ? ch->top_level : (int) (ch->pcdata->learned[gsn_makemodule]);



    if ( ( pObjIndex = get_obj_index( MODULE_VNUM ) ) == NULL )
    {
         send_to_char( "&RThe item you are trying to create is missing from the database.\n\rPlease inform the administration of this error.\n\r", ch );
         return;
    }    
    
    checklens = FALSE;
    checkbat = FALSE;
    checksuper = FALSE;
    checkcircuit = FALSE;
    checktool = FALSE;
    
    for ( obj = ch->last_carrying; obj; obj = obj->prev_content )     
    {
       if (obj->item_type == ITEM_TOOLKIT)
          checktool = TRUE;
       if (obj->item_type == ITEM_LENS && checklens == FALSE)
       {
          checklens = TRUE;
          separate_obj( obj );
          obj_from_char( obj );
       }
       if (obj->item_type == ITEM_BATTERY && checkbat == FALSE)
       {
          checkbat = TRUE;
          separate_obj( obj );
          obj_from_char( obj );
       }
       if (obj->item_type == ITEM_SUPERCONDUCTOR && checksuper == FALSE)
       {
          checksuper = TRUE;
          separate_obj( obj );
          obj_from_char( obj );
       }
       if (obj->item_type == ITEM_CIRCUIT && checkcircuit == FALSE)
       {
          checkcircuit = TRUE;
          separate_obj( obj );
          obj_from_char( obj );
       }
       
    }                            
    
    chance = IS_NPC(ch) ? ch->top_level
                : (int) (ch->pcdata->learned[gsn_makemodule]) ;            
                
    if ( number_percent( ) > chance*2  || ( !checklens ) || ( !checktool ) || ( !checkbat ) || ( !checksuper ) || ( !checkcircuit ) )
    {
       send_to_char( "&RYou hold up your newly created module.\n\r", ch);
       send_to_char( "&RThe module begins to shake violently turning red hot!\n\r", ch);
       send_to_char( "&RYou drop it as it begins to burn your hand and then.. It disintigrates!\n\r", ch);
       learn_from_failure( ch, gsn_makemodule );
       return;
    }

    if(!str_cmp(arg, "primary")){
      affecttype = AFFECT_PRIMARY;
      affectammount = 1;
      strcpy(name, "A Primary Weapons Module");
    }

    if(!str_cmp(arg, "secondary")){
      affecttype = AFFECT_SECONDARY;
      affectammount = 1;
      strcpy(name, "A Secondary Weapons Module");
    }

    if(!str_cmp(arg, "slave"))
    {
      affecttype = AFFECT_SLAVE;
      affectammount = (level / 4);
      strcpy(name, "A Slave Module");
    }

    if(!str_cmp(arg, "tractor"))
    {
      affecttype = AFFECT_TRACTOR;
      affectammount = 1;
      strcpy(name, "A Tractor Beam Module");
    }

    if(!str_cmp(arg, "missile")){
      affecttype = AFFECT_MISSILE;
      affectammount = (level / 20);
      strcpy(name, "A Missile Module");
    }

    if(!str_cmp(arg, "rocket")){
      affecttype = AFFECT_ROCKET;
      affectammount = (level / 20);
      strcpy(name, "A Rocket Module");
    }

    if(!str_cmp(arg, "torpedo")){
      affecttype = AFFECT_TORPEDO;
      affectammount = (level / 20);
      strcpy(name, "A Torpedo Module");
    }

    if(!str_cmp(arg, "hull")){
      affecttype = AFFECT_HULL;
      affectammount = (level / 2);
      strcpy(name, "A Hull Module");
    }

    if(!str_cmp(arg, "shield")){
      affecttype = AFFECT_SHIELD;
      affectammount = (level/5);
      strcpy(name, "A Shield Module");
    }
    if(!str_cmp(arg, "speed")){
      affecttype = AFFECT_SPEED;
      affectammount = (level / 10);
      strcpy(name, "A Speed Module");
    }
    if(!str_cmp(arg, "hyperspeed")){
      affecttype = AFFECT_HYPER;
      affectammount = 1;
      strcpy(name, "A Hyperspeed Module");
    }
    if(!str_cmp(arg, "energy")){
      affecttype = AFFECT_ENERGY;
      affectammount = (level * 5);
      strcpy(name, "An Energy Module");
    }
    if(!str_cmp(arg, "manuever")){
      affecttype = AFFECT_MANUEVER;
      affectammount = (level / 10);
      strcpy(name, "A Manuever Module");
    }
    if(!str_cmp(arg, "alarm"))
    {
      affecttype = AFFECT_ALARM;
      affectammount = 1;
      strcpy(name, "An Alarm Module");
    }
    if(!str_cmp(arg, "chaff"))
    {
      affecttype = AFFECT_CHAFF;
      affectammount = URANGE(1,(level / 33), 3);
      strcpy(name, "A Chaff Module");
    }


    
    obj = create_object( pObjIndex, level );
    obj->item_type = ITEM_MODULE;
    SET_BIT( obj->wear_flags, ITEM_TAKE );
    obj->level = level;
    STRFREE( obj->name );
    obj->name = STRALLOC( name );
    STRFREE( obj->short_descr );
    obj->short_descr = STRALLOC( name );        
    STRFREE( obj->description );
    strcat( name, " was dropped here." );
    obj->description = STRALLOC( name );
    
    obj->value[0] = affecttype;
    obj->value[1] = affectammount;
    obj->value[2] = 0;      
    obj->cost = (level * affecttype * affectammount);
                                                                    
    obj = obj_to_char( obj, ch );
                                                            
    send_to_char( "&GYou finish your work and hold up your newly created module.&w\n\r", ch);
    act( AT_PLAIN, "$n finishes creating a new module.", ch,
         NULL, argument , TO_ROOM );
    
    {
         long xpgain;
         
         xpgain = ((ch->skill_level[TECHNICIAN_ABILITY]+1) * 200);
         gain_exp(ch, xpgain, TECHNICIAN_ABILITY);
         ch_printf( ch , "You gain %d technician experience.", xpgain );
    }
        learn_from_success( ch, gsn_makemodule );
}
Esempio n. 13
0
void check_psionic_talents (CHAR_DATA *ch)
{
    ACCOUNT_DATA	*account;
    int		chance = 0, roll = 0;
    int		cur_talents = 0, i = 0, j = 1;
    int		talents [8] = { SKILL_CLAIRVOYANCE,
                            SKILL_DANGER_SENSE,
                            SKILL_EMPATHIC_HEAL,
                            SKILL_HEX,
                            SKILL_MENTAL_BOLT,
                            SKILL_PRESCIENCE,
                            SKILL_SENSITIVITY,
                            SKILL_TELEPATHY
                       };
    bool		check = TRUE, again = TRUE, awarded = FALSE, block = FALSE;
    char		buf [MAX_STRING_LENGTH] = {'\0'};
    char		*date = NULL;

    if ( is_newbie (ch) || ch->aur <= 15 )
        return;

    if ( ch->pc && ch->pc->account ) {
        if ( !(account = load_account (ch->pc->account)) )
            return;
        if ( IS_SET (account->flags, ACCOUNT_NOPSI) )
            block = TRUE;
        if ( account->roleplay_points < 2 )
            block = TRUE;
        free_account (account);
    }
    else return;

    if ( block )
        return;

    if ( ch->aur < 16 )
        return;
    else if ( ch->aur == 16 )
        chance = 5;
    else if ( ch->aur == 17 )
        chance = 10;
    else if ( ch->aur == 18 )
        chance = 20;
    else if ( ch->aur == 19 )
        chance = 30;
    else if ( ch->aur == 20 )
        chance = 45;
    else if ( ch->aur == 21 )
        chance = 50;
    else if ( ch->aur == 22 )
        chance = 60;
    else if ( ch->aur == 23 )
        chance = 70;
    else if ( ch->aur == 24 )
        chance = 80;
    else
        chance = 95;

    chance += number(1,10);
    chance = MIN(chance, 95);

    for ( i = 0; i <= 7; i++ )
        if ( ch->skills[talents[i]] )
            cur_talents++;

    while ( check && cur_talents <= 4 ) {
        if ( number(1,100) <= chance ) {
            again = TRUE;
            while ( again ) {
                roll = talents[number(0,7)];
                if ( !ch->skills [roll] ) {
                    ch->skills [roll] = 1;
                    cur_talents++;
                    again = FALSE;
                    awarded = TRUE;
                }
                chance /= 2;
            }
            if ( cur_talents >= 4 )
                check = FALSE;
        }
        else check = FALSE;
    }

    if ( !awarded )
        return;

    snprintf (buf, MAX_STRING_LENGTH,  "This character rolled positive for the following talents:\n\n");

    for ( i = 0; i <= 7; i++ )
        if ( ch->skills [talents[i]] )
            snprintf (buf + strlen(buf), MAX_STRING_LENGTH,  "   %d. %s\n", j++, skill_data[talents[i]].skill_name);

    date = timestr(date);

    add_message ("Psi_talents", 2, "Server", date, ch->tname, "", buf, 0);
    add_message (ch->tname, 3, "Server", date, "Psionic Talents.", "", buf, 0);

    mem_free (date);
}
Esempio n. 14
0
int generic_find(char *arg, int bitvector, struct char_data *ch,
		   struct char_data **tar_ch, struct obj_data **tar_obj)
{
    static char *ignore[] = {
	"the",
	"in",
	"on",
	"at",
	"\n" };

    int i;
    char name[256];
    bool found;

    found = FALSE;


    /* Eliminate spaces and "ignore" words */
    while (*arg && !found) {

	for(; *arg == ' '; arg++)   ;

	for(i=0; (name[i] = *(arg+i)) && (name[i]!=' '); i++)   ;
	name[i] = 0;
	arg+=i;
	if (search_block(name, ignore, TRUE) > -1)
	    found = TRUE;

    }

    if (!name[0])
	return(0);

    *tar_ch  = 0;
    *tar_obj = 0;

    if (IS_SET(bitvector, FIND_CHAR_ROOM)) {      /* Find person in room */
	if ( ( *tar_ch = get_char_room_vis(ch, name) ) != NULL ) {
	    return(FIND_CHAR_ROOM);
	}
    }

    if (IS_SET(bitvector, FIND_CHAR_WORLD)) {
	if ( ( *tar_ch = get_char_vis(ch, name) ) != NULL ) {
	    return(FIND_CHAR_WORLD);
	}
    }

    if (IS_SET(bitvector, FIND_OBJ_EQUIP)) {
	for(found=FALSE, i=0; i<MAX_WEAR && !found; i++)
	    if (ch->equipment[i] && str_cmp(name, ch->equipment[i]->name) == 0) {
		*tar_obj = ch->equipment[i];
		found = TRUE;
	    }
	    if (found) {
		return(FIND_OBJ_EQUIP);
	    }
    }

    if (IS_SET(bitvector, FIND_OBJ_INV)) {
	if ( ( *tar_obj = get_obj_in_list_vis(ch, name, ch->carrying) )
	!= NULL ) {
	    return(FIND_OBJ_INV);
	}
    }

    if (IS_SET(bitvector, FIND_OBJ_ROOM)) {
	*tar_obj = get_obj_in_list_vis(ch, name, world[ch->in_room].contents);
	if ( *tar_obj != NULL ) {
	    return(FIND_OBJ_ROOM);
	}
    }

    if (IS_SET(bitvector, FIND_OBJ_WORLD)) {
	if ( ( *tar_obj = get_obj_vis(ch, name) ) != NULL ) {
	    return(FIND_OBJ_WORLD);
	}
    }

    return(0);
}
Esempio n. 15
0
uint8_t sw_mcp2515_check_message(void) {
	return (!IS_SET(MCP2515_INT));
}
Esempio n. 16
0
void nanny(DESCRIPTOR_DATA *d, char *input)
{
  int i;
  char buf[MAX_STRING_LENGTH];
  DESCRIPTOR_DATA *dt;

  switch(d->state)
  {
    case STATE_GET_NAME:
      if (input[0] == 0)
      {
        sckoutput(d->socket, "Fine, then.\n");
        wipe_descriptor(d);
        return;
      }
      i = check_string(input, 4, 12, 0);
      if (i == 1)
        send_to_descriptor(d, "Your name must have at least 4 letters.\n");
      else if (i == 2)
        send_to_descriptor(d, "Your name can contain at most 12 letters.\n");
      else if (i == 4 || i == 3)
        send_to_descriptor(d, "Your name can contain only letters.\n");
      else
      {
        input[0] = UPPER(input[0]);
        load_account(input, d->acc);
        d->acc->d = d;

        if (d->acc->name[0] == 0)
        {
          check_address(d->ip, d->acc->name);
          if (d->acc->name[0] != 0 && stricmp(input, d->acc->name))
            send_to_descriptor(d, "#RWARNING:#n Your IP is linked to an existing account. It is against the rules to have multiple accounts.\n\n");

          strlcpy(d->acc->name, input, 32);
          snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want the name %s? ", input);
          send_to_descriptor(d, buf);
          d->state = STATE_CONFIRM_NAME;
          return;
        }

        send_to_descriptor(d, "Password? ");
        send_to_descriptor(d, password_on);
        d->state = STATE_GET_PASS;
        return;
      }
      send_to_descriptor(d, "What do you want your account name to be? ");
    break;


    case STATE_GET_PASS:
      send_to_descriptor(d, password_off);

      if (!strcmp(d->acc->password, input))
      {
        /* check to see if someone else is logged in under this account */
        for (dt = dhead; dt; dt = dt->next)
        {
          if (dt == d || dt->acc == NULL)
            continue;

          if (!stricmp(d->acc->name, dt->acc->name))
          {
            /* d = new connection, dt = old */
            if (dt->socket > 0 && dt->state != STATE_LINKDEAD)
            {
              sckoutput(dt->socket, "\n\nYou have been kicked off.\n");
              close(dt->socket);
            }

            dt->socket = d->socket;
            d->socket = -1; /* this is mandatory because wipe_descriptor closes d->socket */
            wipe_descriptor(d);
            d = dt;

            if (d->state != STATE_PLAYING && d->state != STATE_LINKDEAD)
              send_to_descriptor(d, "\nYou have kicked someone off while they were logging in. Sending you to the account menu.\n");
            else
            {
              destroy_all_events(d->acc->ch, EVENT_LINKDEAD);
              setup_char_events(d->acc->ch);
              d->acc->ch->idle = 0;
              syslog("RECONNECT", "%s (on %s@%s) has reconnected.", d->acc->ch->name, d->acc->name, d->ip);
              d->state = STATE_PLAYING;
              send_to_descriptor(d, "\n#RReconnected.#n\n");
              return;
            }
          }
        }

        syslog("LOGIN", "%s@%s has logged in.", d->acc->name, d->ip);
        d->state = STATE_ACCT_MENU;
        d->acc->logins++;
        save_account(d->acc);
        show_account_menu(d, 0);
        snprintf(buf, MAX_STRING_LENGTH, "#1[#2Last connection from #R%s#2 at #R%s#2.#1]\n", d->acc->lasthost, d->acc->lasttime);
        save_address(d);
        send_to_descriptor(d, buf);
        if (d->acc->failed == 1)
          snprintf(buf, MAX_STRING_LENGTH, "#1[#RWARNING:#2 1 failed login attempt since your last connection.#1]\n");
        else if (d->acc->failed > 1)
          snprintf(buf, MAX_STRING_LENGTH, "#1[#RWARNING:#2 %d failed login attempts since your last connection.#1]\n", d->acc->failed);
        if (d->acc->failed > 0)
        {
          send_to_descriptor(d, buf);
          d->acc->failed = 0;
          save_account(d->acc);
        }
        send_to_descriptor(d, "#nWhat is your choice? ");
        return;
      }

      sckoutput(d->socket, "Incorrect password. Logging you off...\n");
      syslog("PASSWORD", "%s@%s -- incorrect password! Logged off.", d->acc->name, d->ip);
      d->acc->failed++;
      save_account(d->acc);
      wipe_descriptor(d);
    break;

    case STATE_CONFIRM_NAME:
      if (input[0] == 'y' || input[0] == 'Y')
      {
        send_to_descriptor(d, "What do you want your password to be? ");
        syslog("NEW", "New account %s is being created.", d->acc->name);
        d->state = STATE_NEW_PASS;
        send_to_descriptor(d, password_on);
        return;
      }

      send_to_descriptor(d, "Okay. What do you want your name to be? ");
      d->state = STATE_GET_NAME;
    break;

    case STATE_NEW_PASS:
      send_to_descriptor(d, password_off);
      if (input[0] == 0)
      {
        send_to_descriptor(d, "\nWhat do you want your password to be? ");
        send_to_descriptor(d, password_on);
        return;
      }
      i = check_string(input, 4, 12, 1);
      if (i == 1)
        send_to_descriptor(d, "\nYour password must have at least 4 characters.\n");
      else if (i == 2)
        send_to_descriptor(d, "\nYour password can contain at most 12 characters.\n");
      else if (i == 4)
        send_to_descriptor(d, "\nYour password can contain only letters and numbers.\n");
      else
      {
        strlcpy(d->acc->password, input, 32);
        send_to_descriptor(d, "\nPlease retype your password for confirmation. ");
        send_to_descriptor(d, password_on);
        d->state = STATE_CONFIRM_PASS;
        return;
      }
      send_to_descriptor(d, "\nWhat do you want your password to be? ");
      send_to_descriptor(d, password_on);
    break;

    case STATE_CONFIRM_PASS:
      send_to_descriptor(d, password_off);
      if (strcmp(d->acc->password, input))
      {
        send_to_descriptor(d, "\nYour passwords must match exactly.\nWhat do you want your password to be? ");
        d->state = STATE_NEW_PASS;
        d->acc->password[0] = 0;
        send_to_descriptor(d, password_on);
        return;
      }

      send_to_descriptor(d, "\nDo you want ANSI color? ");
      d->state = STATE_GET_ANSI;
    break;

    case STATE_GET_ANSI:
      d->acc->aflags = 0;
      if (input[0] == 'y' || input[0] == 'Y')
        SET_BIT(d->acc->aflags, AFLAG_ANSI);
      else if (input[0] == 'n' || input[0] == 'N')
        ;
      else
      {
        send_to_descriptor(d, "Please type yes or no.\nDo you want ANSI color? ");
        return;
      }

      for (dt = dhead; dt; dt = dt->next)
      {
        if (dt == d)
          continue;

        if (!stricmp(d->acc->name, dt->acc->name) && (dt->state > STATE_GET_PASS || dt->state < STATE_CONFIRM_NAME))
        {
          sckoutput(d->socket, "You have been kicked off.\n");
          wipe_descriptor(d);
          return;
        }
      }

      d->acc->logins = 1;
      d->acc->changes = time(NULL);
      strlcpy(d->acc->email, "Unset", 128);
      d->state = STATE_ACCT_MENU;
      log_time(d->acc->firsttime);
      save_address(d);
      show_account_menu(d, 1);
      save_account(d->acc);
    break;

    case STATE_ACCT_MENU:
      switch (input[0])
      {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          i = atoi(input);
          if (i > d->acc->charcount)
          {
            send_to_descriptor(d, "Unknown option.\nWhat is your choice? ");
            return;
          }
          if (d->acc->status[i - 1] == CHSTATUS_DELETED)
          {
            send_to_descriptor(d, "You are unable to log onto that player.\nWhat is your choice? ");
            return;
          }

          {
            d->acc->ch = load_character(d->acc, d->acc->character[i - 1]);
            d->acc->ch->acc = d->acc;
            d->acc->ch->d = d;
            setup_char_events(d->acc->ch);
            d->state = STATE_PLAYING;
            d->acc->cur_char = i - 1;
            ++d->acc->chlogins[i - 1];
            destroy_d_events(d, EVENT_LOGINIDLE);

            if (d->acc->ch->level >= LEVEL_IMMORTAL)
              d->acc->status[i - 1] = CHSTATUS_IMMORTAL;

            if (!IS_SET(d->acc->ch->cflags, CFLAG_OLDPLAYER))
            {
              syslog("LOGIN", "%s (on %s@%s) is now playing for the first time!", d->acc->ch->name, d->acc->name, d->ip);
              login_msg_new(d->acc->ch);
              SET_BIT(d->acc->ch->cflags, CFLAG_OLDPLAYER);
              if (IS_SET(d->acc->ch->cflags, CFLAG_HARDCORE))
                d->acc->ch->plane = PLANE_HNEWBIE;
              else
                d->acc->ch->plane = PLANE_NEWBIE;
              d->acc->ch->maxhp = 1000;
              d->acc->ch->maxmove = 1000;
              d->acc->ch->maxmana = 1000;
              d->acc->ch->hp = d->acc->ch->maxhp;
              d->acc->ch->move = d->acc->ch->maxmove;
              d->acc->ch->mana = d->acc->ch->maxmana;
              d->acc->ch->level = LEVEL_MORTAL;
              d->acc->ch->sightradius = 5; /* pwipe: increase this to 50 */
              strlcpy(d->acc->ch->prompt, "#1[#2%pP#1] #1[#2%h#1/#2%HH %m#1/#2%MM %v#1/#2%VV#1]#n> ", 256);
              send_to_char(d->acc->ch, "\nWelcome to Undertow. This is a completely custom MUD. We recommend that you read #RHELP NEWBIE#n.\n");
            }
            else
            {
              syslog("LOGIN", "%s (on %s@%s) is now playing.", d->acc->ch->name, d->acc->name, d->ip);
              login_msg(d->acc->ch);
              do_look(d->acc->ch, "");
            }

            save_account(d->acc);
          }
        break;

        case 'r':
        case 'R':
          if (new_changes(d->acc) == 0)
          {
            send_to_descriptor(d, "There are no new changes.\nWhat is your choice? ");
            return;
          }
          show_changes(d->acc, -1);
          send_to_descriptor(d, "\n#nWhat is your choice? ");
        break;

        case 'c':
        case 'C':
          d->state = STATE_CONFIG_MENU;
          show_account_settings(d);
        break;

        case 's':
        case 'S':
          send_who(d);
          send_to_descriptor(d, "#nWhat is your choice? ");
        break;

        case 'n':
        case 'N':
          if (d->acc->charcount >= MAX_CHARS_PER_ACCOUNT)
          {
            send_to_descriptor(d, "You have met your maximum amount of characters for this account.\nWhat is your choice?");
            return;
          }

          d->state = STATE_NEW_CHAR;
          send_to_descriptor(d, "What do you want your name to be? ");
        break;

        case 'd':
        case 'D':
          if (d->acc->charcount == 0)
          {
            send_to_descriptor(d, "You have no characters to delete.\nWhat is your choice? ");
            return;
          }

          show_delete_menu(d);
          d->state = STATE_DELETE_CHAR;
        break;

        case 'q':
        case 'Q':
          save_account(d->acc);
          syslog("QUIT", "%s@%s quit at the login screen.", d->acc->name, d->ip);
          sckoutput(d->socket, "Goodbye.\n");

          wipe_descriptor(d);
        break;

        case '\0':
          show_account_menu(d, 1);
        break;

        default:
          send_to_descriptor(d, "Unknown option.\nWhat is your choice? ");
        break;
      }
    break;

    case STATE_CONFIG_MENU:
      switch (input[0])
      {
        case 'r':
        case 'R':
          d->state = STATE_ACCT_MENU;
          show_account_menu(d, 1);
        break;

        case 'a':
        case 'A':
          TOGGLE_BIT(d->acc->aflags, AFLAG_ANSI);
          if (IS_SET(d->acc->aflags, AFLAG_ANSI))
          {
            if (IS_SET(d->acc->aflags, AFLAG_ANSI_SPARSE))
              send_to_descriptor(d, "Your prompts will now be colored. If you want full color, turn Full ANSI Color on.\nWhat is your choice? ");
            else
              send_to_descriptor(d, "Welcome to the wonderful world of #Rc#Yo#Gl#Co#Mr#n!\nWhat is your choice? ");
          }
          else
            send_to_descriptor(d, "ANSI color turned off.\nWhat is your choice? ");
        break;

        case 'f':
        case 'F':
          TOGGLE_BIT(d->acc->aflags, AFLAG_ANSI_SPARSE);
          if (!IS_SET(d->acc->aflags, AFLAG_ANSI))
            send_to_descriptor(d, "You would probably notice a subsequent color level change if you had color on.\nWhat is your choice? ");
          else if (IS_SET(d->acc->aflags, AFLAG_ANSI_SPARSE))
            send_to_descriptor(d, "You will now only see colored prompts.\nWhat is your choice? ");
          else
            send_to_descriptor(d, "You will now see full color.\nWhat is your choice? ");
        break;

        case 'l':
        case 'L':
          TOGGLE_BIT(d->acc->aflags, AFLAG_REPLYLOCK);
          if (IS_SET(d->acc->aflags, AFLAG_REPLYLOCK))
            send_to_descriptor(d, "You will now reply only to the last person to whom you sent a tell.\nWhat is your choice? ");
          else
            send_to_descriptor(d, "You will now reply to the person who most recently sent you a tell.\nWhat is your choice? ");
        break;

        case 'p':
        case 'P':
          TOGGLE_BIT(d->acc->aflags, AFLAG_PUBLIC_EMAIL);
          if (IS_SET(d->acc->aflags, AFLAG_PUBLIC_EMAIL))
            send_to_descriptor(d, "Your email address is now public.\nWhat is your choice? ");
          else
            send_to_descriptor(d, "Your email address is now private.\nWhat is your choice? ");
        break;

        case 'c':
        case 'C':
          d->state = STATE_CHANGE_PASS1;
          send_to_descriptor(d, "What is your current password? ");
        send_to_descriptor(d, password_on);
        break;

        case 'e':
        case 'E':
          d->state = STATE_SET_EMAIL;
          send_to_descriptor(d, "What is your email address? ");
        break;

        case '\0':
          show_account_settings(d);
        break;

        case 'd':
        case 'D':
          SET_BIT(d->acc->aflags, AFLAG_ANSI);
          REMOVE_BIT(d->acc->aflags, AFLAG_ANSI_SPARSE);
          REMOVE_BIT(d->acc->aflags, AFLAG_PUBLIC_EMAIL);
          strlcpy(d->acc->email, "Unset", 128);
          send_to_descriptor(d, "Reverted to default settings.\nWhat is your choice?");
        break;

        default:
          send_to_descriptor(d, "Unknown option.\nWhat is your choice? ");
        break;
      }
    break;

    case STATE_CHANGE_PASS1:
      send_to_descriptor(d, password_off);
      if (input[0] == 0)
      {
        d->state = STATE_CONFIG_MENU;
        send_to_descriptor(d, "\nWhat is your choice? ");
        return;
      }

      if (strcmp(d->acc->password, input))
      {
        send_to_descriptor(d, "\nIncorrect password.\nWhat is your choice? ");
        d->state = STATE_CONFIG_MENU;
        return;
      }

      d->state = STATE_CHANGE_PASS2;
      d->acc->temp[0] = 0;
      send_to_descriptor(d, "\nWhat do you want your new password to be? ");
      send_to_descriptor(d, password_on);
    break;

    case STATE_CHANGE_PASS2:
      send_to_descriptor(d, password_off);
      if (input[0] == 0)
      {
        d->state = STATE_CONFIG_MENU;
        send_to_descriptor(d, "\nWhat is your choice? ");
        return;
      }

      i = check_string(input, 4, 12, 1);
      if (i == 1)
        send_to_descriptor(d, "\nYour password must have at least 4 characters.\n");
      else if (i == 2)
        send_to_descriptor(d, "\nYour password can contain at most 12 characters.\n");
      else if (i == 4)
        send_to_descriptor(d, "\nYour password can contain only letters and numbers.\n");
      else
      {
        strlcpy(d->acc->temp, input, 128);
        send_to_descriptor(d, "\nPlease retype your password for confirmation. ");
        d->state = STATE_CHANGE_PASS3;
        send_to_descriptor(d, password_on);
        return;
      }
      send_to_descriptor(d, "\nWhat do you want your password to be? ");
      send_to_descriptor(d, password_on);
    break;

    case STATE_CHANGE_PASS3:
      send_to_descriptor(d, password_off);
      if (input[0] == 0)
      {
        d->state = STATE_CONFIG_MENU;
        send_to_descriptor(d, "\nWhat is your choice? ");
        return;
      }

      if (strcmp(d->acc->temp, input))
      {
        send_to_descriptor(d, "\nPasswords must match exactly.\nWhat is your choice? ");
        d->state = STATE_CONFIG_MENU;
        return;
      }

      strlcpy(d->acc->password, input, 32);
      send_to_descriptor(d, "\nYour password is now changed.\nWhat is your choice? ");
      d->state = STATE_CONFIG_MENU;
      save_account(d->acc);
    break;

    case STATE_SET_EMAIL:
      i = check_string(input, -1, 47, 0);
      if (i == 2)
        send_to_descriptor(d, "Your email can contain at most 47 characters.\n");
      else if (strlen(input) == 0)
      {
        strlcpy(d->acc->email, "Unset", 128);
        d->state = STATE_CONFIG_MENU;
        send_to_descriptor(d, "Your email address is now unset.\nWhat is your choice? ");
      }
      else
      {
        replace(input, buf, "%", "", MAX_STRING_LENGTH);
        replace(buf, input, "~", "-", MAX_STRING_LENGTH);
        strlcpy(d->acc->email, input, 128);
        d->state = STATE_CONFIG_MENU;
        snprintf(buf, MAX_STRING_LENGTH, "Your email address is now %s.\nWhat is your choice? ", input);
        send_to_descriptor(d, buf);
        return;
      }
      send_to_descriptor(d, "What is your email address? ");
    break;

    case STATE_DELETE_CHAR:
      if (input[0] == 'r' || input[0] == 'R')
      {
        d->state = STATE_ACCT_MENU;
        show_account_menu(d, 1);
        return;
      }
      if (input[0] == 0)
      {
        show_delete_menu(d);
        return;
      }

      i = atoi(input);
      if (i < 1 || i > d->acc->charcount)
        send_to_descriptor(d, "Out of bounds.\nWhich character do you want to delete? ");
      else
      {
        d->acc->name[15] = --i;
        snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want to delete %s?", d->acc->character[i]);
        send_to_descriptor(d, buf);
        d->state = STATE_CONFIRM_DEL;
      }
    break;

    case STATE_CONFIRM_DEL:
      if (input[0] == 'y' || input[0] == 'Y')
      {
        i = d->acc->name[15];
        d->acc->name[15] = 0;
        snprintf(buf, MAX_STRING_LENGTH, "%s has been deleted.\nWhat is your choice? ", d->acc->character[i]);
        send_to_descriptor(d, buf);
        syslog("DELETION", "%s (on %s@%s) has selfdeleted.", d->acc->character[i], d->acc->name, d->ip);
        d->state = STATE_ACCT_MENU;
        d->acc->chtime[i] = 0;
        snprintf(buf, MAX_STRING_LENGTH, "rm -f account/%s.chr", d->acc->character[i]);
        to_lower(buf);
        system(buf);

        d->acc->charcount--;
        while (i < d->acc->charcount)
        {
          strlcpy(d->acc->character[i], d->acc->character[i + 1], 32);
          i++;
        }
        save_account(d->acc);
        return;
      }
      d->state = STATE_ACCT_MENU;
      show_account_menu(d, 1);
    break;

    case STATE_NEW_CHAR:
      i = 0;
      if (input[0] == 0)
      {
        d->state = STATE_ACCT_MENU;
        show_account_menu(d, 1);
        return;
      }

      i = check_string(input, 4, 12, 0);
      if (i == 1)
        send_to_descriptor(d, "Your name must have atleast 4 letters.\n");
      else if (i == 2)
        send_to_descriptor(d, "Your name can contain at most 12 letters.\n");
      else if (i == 4 || i == 3)
        send_to_descriptor(d, "Your name can contain only letters.\n");
      else
      {
        input[0] = UPPER(input[0]);
        for (dt = dhead; dt; dt = dt->next)
          if ((d != dt) && !stricmp(input, dt->acc->character[dt->acc->charcount]))
            i = 1;
        if (i == 0 && char_exists(input))
          i = 1;
        if (i)
        {
          snprintf(buf, MAX_STRING_LENGTH, "The name %s is already taken.\nWhat do you want your name to be? ", input);
          send_to_descriptor(d, buf);
          return;
        }
        strlcpy(d->acc->character[d->acc->charcount], input, 32);
        snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want the name %s? ", input);
        send_to_descriptor(d, buf);
        d->state = STATE_CONFIRM_CHAR;
        return;
      }
      send_to_descriptor(d, "What do you want your name to be? ");
    break;

    case STATE_CONFIRM_CHAR:
      if (input[0] == 'y' || input[0] == 'Y')
      {
        if (d->acc->logins == 1)
        {
          d->state = STATE_ACCT_MENU;
          finish_creation(d, 0);
          return;
        }
        d->state = STATE_GET_HARDCORE;
        send_to_descriptor(d, "Do you want this character to be hardcore (death = deletion)? ");
      }
      else
      {
        d->state = STATE_ACCT_MENU;
        show_account_menu(d, 1);
      }
    break;

    case STATE_GET_HARDCORE:
      finish_creation(d, input[0] == 'y' || input[0] == 'Y');
    break;
  }
}
Esempio n. 17
0
void tcpdemux::process_tcp(const struct timeval &ts,const u_char *data, uint32_t length,
                           const ipaddr &src, const ipaddr &dst,int32_t vlan,sa_family_t family)
{
    if (length < sizeof(struct tcphdr)) {
        DEBUG(6) ("received truncated TCP segment!");
        return;
    }

    struct tcphdr *tcp_header = (struct tcphdr *) data;

    /* calculate the total length of the TCP header including options */
    u_int tcp_header_len = tcp_header->th_off * 4;

    /* fill in the flow_addr structure with info that identifies this flow */
    flow_addr this_flow(src,dst,ntohs(tcp_header->th_sport),ntohs(tcp_header->th_dport),family);

    tcp_seq seq  = ntohl(tcp_header->th_seq);
    bool syn_set = IS_SET(tcp_header->th_flags, TH_SYN);
    bool ack_set = IS_SET(tcp_header->th_flags, TH_ACK);

    //std::cerr << "\n*** process_tcp seq=" << seq << " \n";

    /* recalculate the beginning of data and its length, moving past the
     * TCP header
     */
    data   += tcp_header_len;
    length -= tcp_header_len;

    /* see if we have state about this flow; if not, create it */
    uint64_t connection_count = 0;
    int32_t  delta = 0;			// from current position in tcp connection; must be SIGNED 32 bit!
    tcpip   *tcp = find_tcpip(this_flow);

    /* If this_flow is not in the database and the start_new_connections flag is false, just return */
    if(tcp==0 && start_new_connections==false) return;

    /* flow is in the database; find it */
    if(tcp) {
        /* Compute delta based on next expected sequence number.
         * If delta will be too much, start a new flow.
         */
        delta = seq - tcp->nsn;		// notice that signed offset is calculated

        if(abs(delta) > opt.max_seek) {
            connection_count = tcp->myflow.connection_count+1;
            remove_flow(this_flow);
            tcp = 0;
        }
    }

    /* At this point, tcp may be NULL because:
     * case 1 - a connection wasn't found or because
     * case 2 - a new connections should be started (jump is too much)
     *
     * THIS IS THE ONLY PLACE THAT create_tcpip() is called.
     */

    if (tcp==NULL) {
        /* Create a new connection.
         * delta will be 0, because it's a new connection!
         */
        tcp_seq isn = syn_set ? seq : seq-1;
        tcp = create_tcpip(this_flow, vlan, isn, ts,connection_count);
    }

    /* Now tcp is valid */
    tcp->myflow.tlast = ts;		// most recently seen packet
    tcp->myflow.packet_count++;

    /*
     * 2012-10-24 slg - the first byte is sent at SEQ==ISN+1.
     * The first byte in POSIX files have an LSEEK of 0.
     * The original code overcame this issue by introducing an intentional off-by-one
     * error with the statement tcp->isn++.
     *
     * With the new TCP state-machine we simply follow the spec.
     *
     * The new state machine works by examining the SYN and ACK packets
     * in accordance with the TCP spec.
     */
    if(syn_set) {
        if(tcp->syn_count>1) {
            DEBUG(1)("Multiple SYNs (%d) seen on a single connection.",tcp->syn_count);
        }
        tcp->syn_count++;
        if( ack_set ) {
            DEBUG(50) ("packet is handshake SYN"); /* First packet of three-way handshake */
            tcp->dir = tcpip::dir_cs;	// client->server
        } else {
            DEBUG(50) ("packet is handshake SYN/ACK"); /* second packet of three-way handshake  */
            tcp->dir = tcpip::dir_sc;	// server->client
        }
        if(length>0) {
            tcp->violations++;
            DEBUG(1) ("TCP PROTOCOL VIOLATION: SYN with data! (length=%d)",length);
        }
    }
    if(length==0) DEBUG(50) ("got TCP segment with no data"); // seems pointless to notify

    /* process any data.
     * Notice that this typically won't be called for the SYN or SYN/ACK,
     * since they both have no data by definition.
     */
    if (length>0) {
        if (opt.console_output) {
            tcp->print_packet(data, length);
        } else {
            if (opt.opt_output_enabled) {
                tcp->store_packet(data, length, delta);
            }
        }
    }

    /* Finally, if there is a FIN, then kill this TCP connection*/
    if (IS_SET(tcp_header->th_flags, TH_FIN)) {
        if(opt.opt_no_purge==false) {
            DEBUG(50)("packet is FIN; closing connection");
            remove_flow(this_flow);	// take it out of the map
        }
    }
}
Esempio n. 18
0
void do_heal(CHAR_DATA *ch, char *argument)
{
    CHAR_DATA *mob;
    char arg[MAX_INPUT_LENGTH];
    int cost,sn;
    SPELL_FUN *spell;
    char *words;	

    /* check for healer */
    for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
    {
        if ( IS_NPC(mob) && IS_SET(mob->act, ACT_IS_HEALER) )
            break;
    }
 
    if ( mob == NULL )
    {
        send_to_char( "You can't do that here.\n\r", ch );
        return;
    }

    one_argument(argument,arg);

    if (arg[0] == '\0')
    {
        /* display price list */
	act("$N says '{aI offer the following spells:{x'",ch,NULL,mob,TO_CHAR);
	send_to_char("  light:   cure light wounds     10 gold\n\r",ch);
	send_to_char("  serious: cure serious wounds   15 gold\n\r",ch);
	send_to_char("  critic:  cure critical wounds  25 gold\n\r",ch);
	send_to_char("  heal:    healing spell         50 gold\n\r",ch);
	send_to_char("  blind:   cure blindness        20 gold\n\r",ch);
	send_to_char("  disease: cure disease          15 gold\n\r",ch);
	send_to_char("  poison:  cure poison           25 gold\n\r",ch); 
	send_to_char("  uncurse: remove curse          50 gold\n\r",ch);
	send_to_char("  refresh: restore movement      5 gold\n\r",ch);
	send_to_char("  mana:    restore mana          10 gold\n\r",ch);
	send_to_char(" Type heal <type> to be healed.\n\r",ch);
	return;
    }

    if (!str_prefix(arg,"light"))
    {
        spell = spell_cure_light;
	sn    = skill_lookup("cure light");
	words = "judicandus dies";
	 cost  = 1000;
    }

    else if (!str_prefix(arg,"serious"))
    {
	spell = spell_cure_serious;
	sn    = skill_lookup("cure serious");
	words = "judicandus gzfuajg";
	cost  = 1600;
    }

    else if (!str_prefix(arg,"critical"))
    {
	spell = spell_cure_critical;
	sn    = skill_lookup("cure critical");
	words = "judicandus qfuhuqar";
	cost  = 2500;
    }

    else if (!str_prefix(arg,"heal"))
    {
	spell = spell_heal;
	sn = skill_lookup("heal");
	words = "pzar";
	cost  = 5000;
    }

    else if (!str_prefix(arg,"blindness"))
    {
	spell = spell_cure_blindness;
	sn    = skill_lookup("cure blindness");
      	words = "judicandus noselacri";		
        cost  = 2000;
    }

    else if (!str_prefix(arg,"disease"))
    {
	spell = spell_cure_disease;
	sn    = skill_lookup("cure disease");
	words = "judicandus eugzagz";
	cost = 1500;
    }

    else if (!str_prefix(arg,"poison"))
    {
	spell = spell_cure_poison;
	sn    = skill_lookup("cure poison");
	words = "judicandus sausabru";
	cost  = 2500;
    }
	
    else if (!str_prefix(arg,"uncurse") || !str_prefix(arg,"curse"))
    {
	spell = spell_remove_curse; 
	sn    = skill_lookup("remove curse");
	words = "candussido judifgz";
	cost  = 5000;
    }

    else if (!str_prefix(arg,"mana") || !str_prefix(arg,"energize"))
    {
        spell = NULL;
        sn = -1;
        words = "energizer";
        cost = 1000;
    }

	
    else if (!str_prefix(arg,"refresh") || !str_prefix(arg,"moves"))
    {
	spell =  spell_refresh;
	sn    = skill_lookup("refresh");
	words = "candusima"; 
	cost  = 500;
    }

    else 
    {
	act("$N says '{aType 'heal' for a list of spells.{x'",
	    ch,NULL,mob,TO_CHAR);
	return;
    }

    if (cost > ((ch->platinum * 10000) + (ch->gold * 100) + ch->silver))
    {
	act("$N says '{aYou do not have enough gold for my services.{x'",
	    ch,NULL,mob,TO_CHAR);
	return;
    }

    WAIT_STATE(ch,PULSE_VIOLENCE);

    deduct_cost(ch,cost,VALUE_SILVER);
    act("$n utters the words '{a$T{x'.",mob,NULL,words,TO_ROOM);
  
    if (spell == NULL)  /* restore mana trap...kinda hackish */
    {
	ch->mana += dice(2,8) + mob->level / 3;
	ch->mana = UMIN(ch->mana,ch->max_mana);
	send_to_char("A warm {Yglow{x passes through you.\n\r",ch);
	return;
     }

     if (sn == -1)
	return;
    
     spell(sn,mob->level,mob,ch,TARGET_CHAR);
}
Esempio n. 19
0
File: clan.c Progetto: verias/SRMud
void do_clanpmote(CHAR_DATA * ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *victim;
    int cnt;
    int sn = 0;

    argument = one_argument(argument, arg1);

    if (!can_promote(ch))
    {
	send_to_char("huh?\n\r", ch);
	return;
    }

    if (arg1[0] == '\0' || argument[0] == '\0')
    {
	/*
	 * --------------------------------------------------------------
	 * Keep in mind that we are displaying the ranks as 1 - MAX_RANK,
	 * so, since the structure is actually 0 - MAX_RANK-1, we need to
	 * set "cnt" to cnt-1.
	 * -------------------------------------------------------------- 
	 */

	send_to_char("Syntax: promote <who> <rank #>\n\r", ch);
	send_to_char("where rank is one of the following:\n\r", ch);

	for (cnt = 0; cnt < MAX_RANK; cnt++)
	{
	  sprintf(buf, "%2d] %s\n\r", cnt + 1,
 	    is_clan(ch) ? clan_table[ch->clan].rank[cnt].rankname : "(None)");
	  send_to_char(buf, ch);
	}
	send_to_char("\n\r", ch);
	return;
    }				/* end syntax */

    if ((victim = get_char_world(ch, arg1)) == NULL)
    {
	send_to_char("They aren't playing.\n\r", ch);
	return;
    }

    if (!is_clan(victim))
    {
        send_to_char("They are not a member of any guilds!\n\r", ch);
        return;
    }

    if (!is_same_clan(ch, victim) &&
	(ch->level < SUPREME))
    {
	send_to_char("They are a member of a guild different than yours!\n\r", ch);
	return;
    }

    if (!str_prefix(argument, "leader") && ch != victim)
    {
	SET_BIT(victim->act, PLR_MORTAL_LEADER);
	send_to_char("They are now a mortal leader.\n\r", ch);
	send_to_char("You have just been promoted to a leader of your guild!\n\r", victim);
	return;
    }

    cnt = atoi(argument) - 1;
    if (cnt < 0 ||
	cnt > MAX_RANK -1 ||
	clan_table[victim->clan].rank[cnt].rankname == NULL)
    {
	send_to_char("That rank does not exist!", ch);
	return;
    }
    if (cnt > victim->rank && ((ch == victim) & (!IS_IMMORTAL(ch))))
    {
	send_to_char("Heh. I dont think so...", ch);
	return;
    }

  /** bug report by: Zak Jonhnson ([email protected])
    * we were checking ch->rank here..*sigh* Thanks Zak!
    */
    if (cnt > victim->rank)
    {
	int i;

	sprintf(buf, "You have been promoted to %s!\n\r",
		clan_table[victim->clan].rank[cnt].rankname);
	send_to_char(buf, victim);

	sprintf(buf, "%s has been promoted to %s!\n\r",
	      victim->name, clan_table[victim->clan].rank[cnt].rankname);
	send_to_char(buf, ch);

	for (i = victim->rank; i < cnt; i++)
	    if (clan_table[victim->clan].rank[i].skillname != NULL)
	    {
		sn = skill_lookup(clan_table[victim->clan].rank[i].skillname);
		if (sn < 0)
		{
		    sprintf(buf, "Bug: Add skill [%s] is not a valid skill",
			    clan_table[victim->clan].rank[cnt].skillname);
		    log_string(buf);
		} else if (!victim->pcdata->learned[sn])
		    victim->pcdata->learned[sn] = 20 + (victim->level / 4);
	    }
    } 
    
    else if (cnt < victim->rank)
    {
	if (IS_SET(victim->act, PLR_MORTAL_LEADER))
	    REMOVE_BIT(victim->act, PLR_MORTAL_LEADER);

	sprintf(buf, "You have been demoted to %s!\n\r",
		clan_table[victim->clan].rank[cnt].rankname);

	send_to_char(buf, victim);
	sprintf(buf, "%s has been demoted to %s!\n\r",
	      victim->name, clan_table[victim->clan].rank[cnt].rankname);

	send_to_char(buf, ch);
	/*
	 * ---------------------------------------------------------------
	 * Note: I dont think it would be fair here to take away any skills
	 * the victim may have earned at a higher rank. It makes no RP sense
	 * to do so and only hurts the player (loss of practices etc). Imms
	 * may want to keep an eye on this, as we dont want players jumping
	 * guilds just to gain new skills.
	 * -------------------------------------------------------------- 
	 */
    }				/* else no change */
    victim->rank = cnt;
    return;
} /* end: do_promote */
Esempio n. 20
0
void do_buy( CHAR_DATA * ch, char *argument )
{
  char arg[MAX_INPUT_LENGTH];
  int maxgold = 0;

  argument = one_argument( argument, arg );

  if( arg[0] == '\0' )
  {
    send_to_char( "Buy what?\r\n", ch );
    return;
  }

  /* in case of different shop types */
  {
    CHAR_DATA *keeper = NULL;
    OBJ_DATA *obj = NULL;
    int cost = 0;
    int noi = 1;		/* Number of items */
    short mnoi = 20;		/* Max number of items to be bought at once */

    if( ( keeper = find_keeper( ch ) ) == NULL )
      return;

    maxgold = keeper->top_level * 10;

    if( is_number( arg ) )
    {
      noi = atoi( arg );
      argument = one_argument( argument, arg );

      if( noi > mnoi )
      {
	act( AT_TELL, "$n tells you 'I don't sell that many items at"
	    " once.'", keeper, NULL, ch, TO_VICT );
	ch->reply = keeper;
	return;
      }
    }

    obj = get_obj_carry( keeper, arg );

    if( !obj && arg[0] == '#' )
    {
      int onum = 0, oref = atoi( arg + 1 );
      bool ofound = FALSE;

      for( obj = keeper->last_carrying; obj; obj = obj->prev_content )
      {
	if( obj->wear_loc == WEAR_NONE && can_see_obj( ch, obj ) )
	  onum++;

	if( onum == oref )
	{
	  ofound = TRUE;
	  break;
	}
	else if( onum > oref )
	  break;
      }
      if( !ofound )
	obj = NULL;
    }

    cost = ( get_cost( ch, keeper, obj, TRUE ) * noi );
    if( cost <= 0 || !can_see_obj( ch, obj ) )
    {
      act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'",
	  keeper, NULL, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) )
    {
      char buf[MAX_STRING_LENGTH];
      snprintf( buf, MAX_STRING_LENGTH, "%s", "laugh" );
      interpret( keeper, buf );
      act( AT_TELL, "$n tells you 'I don't have enough of those in stock"
	  " to sell more than one at a time.'", keeper, NULL, ch,
	  TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( ch->gold < cost )
    {
      act( AT_TELL, "$n tells you 'You can't afford to buy $p.'",
	  keeper, obj, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( IS_SET( obj->extra_flags, ITEM_PROTOTYPE ) && IS_IMMORTAL( ch ) )
    {
      act( AT_TELL,
	  "$n tells you 'This is a only a prototype!  I can't sell you that...'",
	  keeper, NULL, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) )
    {
      send_to_char( "You can't carry that many items.\r\n", ch );
      return;
    }

    if( ch->carry_weight + ( get_obj_weight( obj ) * noi )
	+ ( noi > 1 ? 2 : 0 ) > can_carry_w( ch ) )
    {
      send_to_char( "You can't carry that much weight.\r\n", ch );
      return;
    }

    if( noi == 1 )
    {
      if( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
	separate_obj( obj );
      act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM );
      act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR );
    }
    else
    {
      sprintf( arg, "$n buys %d $p%s.", noi,
	  ( obj->short_descr[strlen( obj->short_descr ) - 1] == 's'
	    ? "" : "s" ) );
      act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM );
      sprintf( arg, "You buy %d $p%s.", noi,
	  ( obj->short_descr[strlen( obj->short_descr ) - 1] == 's'
	    ? "" : "s" ) );
      act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR );
      act( AT_ACTION, "$N puts them into a bag and hands it to you.",
	  ch, NULL, keeper, TO_CHAR );
    }

    ch->gold -= cost;
    keeper->gold += cost;

    if( keeper->gold > maxgold )
    {
      keeper->gold = maxgold / 2;
      act( AT_ACTION, "$n puts some credits into a large safe.", keeper,
	  NULL, NULL, TO_ROOM );
    }

    if( IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
    {
      OBJ_DATA *buy_obj = create_object( obj->pIndexData );
      OBJ_DATA *bag = NULL;

      /*
       * Due to grouped objects and carry limitations in SMAUG
       * The shopkeeper gives you a bag with multiple-buy,
       * and also, only one object needs be created with a count
       * set to the number bought.                -Thoric
       */
      if( noi > 1 )
      {
	bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ) );
	/* perfect size bag ;) */
	bag->value[0] = bag->weight + ( buy_obj->weight * noi );
	buy_obj->count = noi;
	obj->pIndexData->count += ( noi - 1 );
	numobjsloaded += ( noi - 1 );
	obj_to_obj( buy_obj, bag );
	obj_to_char( bag, ch );
      }
      else
	obj_to_char( buy_obj, ch );
    }
    else
    {
      obj_from_char( obj );
      obj_to_char( obj, ch );
    }

    return;
  }
}
Esempio n. 21
0
void fread_pfile( FILE * fp, time_t tdiff, char *fname, bool count )
{
   char *word;
   char *name = NULL;
   char *clan = NULL;
   short level = 0;
   short file_ver = 0;
   int pact2;
   bool fMatch;
   ROOM_INDEX_DATA *plr_home;
   char homebuf[MSL];

   for( ;; )
   {
      word = feof( fp ) ? "End" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol( fp );
            break;

         case 'A':
            KEY( "Act2", pact2, fread_number( fp ) );
            break;

         case 'C':
            KEY( "Clan", clan, fread_string( fp ) );
            break;

         case 'E':
            if( !strcmp( word, "End" ) )
               goto timecheck;
            break;

         case 'T':
            KEY( "Toplevel", level, fread_number( fp ) );
            break;

         case 'N':
            KEY( "Name", name, fread_string( fp ) );
            break;

		 case 'P':
            if ( !str_cmp( word, "PlrHome" ) )
            {
                plr_home = get_room_index( fread_number( fp ) );
                break;
            }
			break;

         case 'V':
            KEY( "Version", file_ver, fread_number( fp ) );
            break;
      }

      if( !fMatch )
         fread_to_eol( fp );
   }

 timecheck:

   if( count == FALSE && !IS_SET( pact2, ACT_EXEMPT ) )
   {
      if( (level < 10) && (tdiff > sysdata.newbie_purge) )
      {
         if( unlink( fname ) == -1 )
            perror( "Unlink" );
         else
         {
           sprintf( homebuf, "%s%c/%s.home", PLAYER_DIR, tolower(name[0]), name);

			if ( !remove(homebuf) )
			{
			   STRFREE( plr_home->name );
			   plr_home->name = STRALLOC( "An Empty Apartment" );
			   REMOVE_BIT( plr_home->room_flags , ROOM_PLR_HOME );
			   SET_BIT( plr_home->room_flags , ROOM_EMPTY_HOME );
			   fold_area( plr_home->area, plr_home->area->filename, FALSE );
			}

			 days = sysdata.newbie_purge;
            sprintf( log_buf, "Player %s was deleted. Exceeded time limit of %d days.", name, days );
            log_string( log_buf );
#ifdef AUTO_AUTH
            remove_from_auth( name );
#endif
            deleted++;
         }
      }

     if( (level < LEVEL_IMMORTAL) && (tdiff > sysdata.regular_purge) )
      {
         if( level < LEVEL_IMMORTAL )
         {
            if( unlink( fname ) == -1 )
               perror( "Unlink" );
            else
            {
              sprintf( homebuf, "%s%c/%s.home", PLAYER_DIR, tolower(name[0]), name);

			  if ( !remove(homebuf) )
			  {
			    STRFREE( plr_home->name );
			    plr_home->name = STRALLOC( "An Empty Apartment" );
			    REMOVE_BIT( plr_home->room_flags , ROOM_PLR_HOME );
			    SET_BIT( plr_home->room_flags , ROOM_EMPTY_HOME );
			    fold_area( plr_home->area, plr_home->area->filename, FALSE );
			  }
               days = sysdata.regular_purge;
               sprintf( log_buf, "Player %s was deleted. Exceeded time limit of %d days.", name, days );
               log_string( log_buf );
#ifdef AUTO_AUTH
               remove_from_auth( name );
#endif
               deleted++;
            }
         }
      }
   }

   if( clan != NULL )
   {
      CLAN_DATA *guild = get_clan( clan );

      if( guild )
         guild->members++;
   }

   if( name )
     STRFREE(name);
   if( clan )
     STRFREE(clan);

   return;
}
Esempio n. 22
0
void apply_spell( CHAR_DATA *ch, int mod )
{
    if ( mod > 0 )
    {
	if ( slot_lookup(mod) == gsn_haste )
	{
	    if ( !IS_SET(ch->affected_by, AFF_HASTE) )
	    {
		SET_BIT( ch->affected_by, AFF_HASTE );
		act("$n begins moving more quickly.",ch,NULL,NULL,TO_ROOM);
		send_to_char( "You begins moving more quickly.\n\r", ch );
	    }
	}
	else if ( slot_lookup(mod) == gsn_invis )
	{
	    if ( !IS_SET( ch->affected_by, AFF_INVISIBLE) )
	    {
		SET_BIT( ch->affected_by, AFF_INVISIBLE );
   		act( "$n snaps out of existence.", ch, NULL,NULL, TO_ROOM );
    		send_to_char( "You snap out of existence.\n\r", ch );
	    }
	}
	else if ( slot_lookup(mod) == gsn_air_armor )
	{
	    if ( !IS_SET(ch->affected_by, AFF_AIR_ARMOR) )
	    {
		SET_BIT( ch->affected_by, AFF_AIR_ARMOR );
    		send_to_char( "Flows of air harden around you, forming armor.\n\r", ch );
	    }
	}
	else if ( slot_lookup(mod) == gsn_ward_person )
	{
	    if ( !IS_SET(ch->affected_by, AFF_WARDED) )
	    {
		SET_BIT( ch->affected_by, AFF_WARDED );
		send_to_char( "Blue fills your vision for a moment.\n\r",ch );
	    }
	}
	else
	    bug("Apply_spell: unusable slot number %d.", mod );
    }
    else
    {
	if ( slot_lookup(abs( mod )) == gsn_haste )
	{
	    if ( IS_SET(ch->affected_by, AFF_HASTE) )
	    {
		REMOVE_BIT( ch->affected_by, AFF_HASTE );
		act("$n slows down and moves more normally.",ch,NULL,NULL,TO_ROOM);
		send_to_char( "You feel yourself slowing down.\n\r", ch );
	    }
	}
	else if ( slot_lookup(abs( mod )) == gsn_invis )
	{
	    if ( IS_SET(ch->affected_by, AFF_INVISIBLE) )
	    {
	    	REMOVE_BIT( ch->affected_by, AFF_INVISIBLE );
	    	act( "$n snaps into view.", ch, NULL, NULL, TO_ROOM );
	    	send_to_char( "You snap into view.\n\r", ch );
	    }
	}
	else if ( slot_lookup(abs( mod )) == gsn_air_armor )
	{
	    if ( IS_SET(ch->affected_by, AFF_AIR_ARMOR) )
	    {
		REMOVE_BIT( ch->affected_by, AFF_AIR_ARMOR );
	    	send_to_char( "Your armor of air dissipates.\n\r", ch );
	    }
	}
	else if ( slot_lookup(abs( mod )) == gsn_ward_person )
	{
	    if ( IS_SET(ch->affected_by, AFF_WARDED) )
	    {
		REMOVE_BIT( ch->affected_by, AFF_WARDED );
		send_to_char( "You suddenly feel less safe.\n\r", ch );
	    }
	}
	else
	    bug("Reset_char: unusable slot number %d.", mod );
    }
    return;
}
Esempio n. 23
0
void mag_objectmagic(struct char_data *ch, struct obj_data *obj,
                     char *argument)
{
    int i, k;
    struct char_data *tch = NULL, *next_tch;
    struct obj_data *tobj = NULL;

    if (!magic_enabled)
        return;

    one_argument(argument, arg);

    k = generic_find(arg, FIND_CHAR_ROOM | FIND_OBJ_INV | FIND_OBJ_ROOM |
                     FIND_OBJ_EQUIP, ch, &tch, &tobj);

    switch (GET_OBJ_TYPE(obj)) {
    case ITEM_STAFF:
        act("You tap $p three times on the ground.", FALSE, ch, obj, 0, TO_CHAR);
        if (obj->action_description)
            act(obj->action_description, FALSE, ch, obj, 0, TO_ROOM);
        else
            act("$n taps $p three times on the ground.", FALSE, ch, obj, 0, TO_ROOM);

        if (GET_OBJ_VAL(obj, 2) <= 0) {
            send_to_char("It seems powerless.\r\n", ch);
            act("Nothing seems to happen.", FALSE, ch, obj, 0, TO_ROOM);
        } else {
            GET_OBJ_VAL(obj, 2)--;
            WAIT_STATE(ch, PULSE_VIOLENCE);
            /* Level to cast spell at. */
            k = GET_OBJ_VAL(obj, 0) ? GET_OBJ_VAL(obj, 0) : DEFAULT_STAFF_LVL;

            /*
             * Problem : Area/mass spells on staves can cause crashes.
             * Solution: Remove the special nature of area/mass spells on staves.
             * Problem : People like that behavior.
             * Solution: We special case the area/mass spells here.
             */
            if (HAS_SPELL_ROUTINE(get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__), MAG_MASSES | MAG_AREAS)) {
                for (i = 0, tch = world[IN_ROOM(ch)].people; tch; tch = tch->next_in_room)
                    i++;
                while (i-- > 0)
                    call_magic(ch, NULL, NULL, get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__), k, CAST_STAFF, 0);
            } else {
                for (tch = world[IN_ROOM(ch)].people; tch; tch = next_tch) {
                    next_tch = tch->next_in_room;
                    if (ch != tch)
                        call_magic(ch, tch, NULL, get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__), k, CAST_STAFF, 0);
                }
            }
        }
        break;
    case ITEM_WAND:
        if (k == FIND_CHAR_ROOM) {
            if (tch == ch) {
                act("You point $p at yourself.", FALSE, ch, obj, 0, TO_CHAR);
                act("$n points $p at $mself.", FALSE, ch, obj, 0, TO_ROOM);
            } else {
                act("You point $p at $N.", FALSE, ch, obj, tch, TO_CHAR);
                if (obj->action_description)
                    act(obj->action_description, FALSE, ch, obj, tch, TO_ROOM);
                else
                    act("$n points $p at $N.", TRUE, ch, obj, tch, TO_ROOM);
            }
        } else if (tobj != NULL) {
            act("You point $p at $P.", FALSE, ch, obj, tobj, TO_CHAR);
            if (obj->action_description)
                act(obj->action_description, FALSE, ch, obj, tobj, TO_ROOM);
            else
                act("$n points $p at $P.", TRUE, ch, obj, tobj, TO_ROOM);
        } else if (IS_SET(get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__)->routines, MAG_AREAS | MAG_MASSES)) {
            /* Wands with area spells don't need to be pointed. */
            act("You point $p outward.", FALSE, ch, obj, NULL, TO_CHAR);
            act("$n points $p outward.", TRUE, ch, obj, NULL, TO_ROOM);
        } else {
            act("At what should $p be pointed?", FALSE, ch, obj, NULL, TO_CHAR);
            return;
        }

        if (GET_OBJ_VAL(obj, 2) <= 0) {
            send_to_char("It seems powerless.\r\n", ch);
            act("Nothing seems to happen.", FALSE, ch, obj, 0, TO_ROOM);
            return;
        }
        GET_OBJ_VAL(obj, 2)--;
        WAIT_STATE(ch, PULSE_VIOLENCE);
        if (GET_OBJ_VAL(obj, 0))
            call_magic(ch, tch, tobj, get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__),
                       GET_OBJ_VAL(obj, 0), CAST_WAND, 0);
        else
            call_magic(ch, tch, tobj, get_spell(GET_OBJ_VAL(obj, 3), __FILE__, __FUNCTION__),
                       DEFAULT_WAND_LVL, CAST_WAND, 0);
        break;
    case ITEM_SCROLL:
        if (*arg) {
            if (!k) {
                act("There is nothing to here to affect with $p.", FALSE,
                    ch, obj, NULL, TO_CHAR);
                return;
            }
        } else
            tch = ch;

        act("You recite $p which dissolves.", TRUE, ch, obj, 0, TO_CHAR);
        if (obj->action_description)
            act(obj->action_description, FALSE, ch, obj, NULL, TO_ROOM);
        else
            act("$n recites $p.", FALSE, ch, obj, NULL, TO_ROOM);

        WAIT_STATE(ch, PULSE_VIOLENCE);
        for (i = 1; i <= 3; i++)
            if (call_magic(ch, tch, tobj, get_spell(GET_OBJ_VAL(obj, i), __FILE__, __FUNCTION__),
                           GET_OBJ_VAL(obj, 0), CAST_SCROLL, 0) <= 0)
                break;

        if (obj != NULL)
            extract_obj(obj);
        break;
    case ITEM_POTION:
        tch = ch;
        act("You quaff $p.", FALSE, ch, obj, NULL, TO_CHAR);
        if (obj->action_description)
            act(obj->action_description, FALSE, ch, obj, NULL, TO_ROOM);
        else
            act("$n quaffs $p.", TRUE, ch, obj, NULL, TO_ROOM);

        WAIT_STATE(ch, PULSE_VIOLENCE);
        for (i = 1; i <= 3; i++)
            if (call_magic(ch, ch, NULL, get_spell(GET_OBJ_VAL(obj, i), __FILE__, __FUNCTION__),
                           GET_OBJ_VAL(obj, 0), CAST_POTION, 0) <= 0)
                break;

        if (obj != NULL)
            extract_obj(obj);
        break;
    case ITEM_SPELLBOOK:
        tch = ch;
        act("You study $p.", FALSE, ch, obj, NULL, TO_CHAR);
        if (obj->action_description)
            act(obj->action_description, FALSE, ch, obj, NULL, TO_ROOM);
        else
            act("$n studies $p.", TRUE, ch, obj, NULL, TO_ROOM);

        WAIT_STATE(ch, PULSE_VIOLENCE);
        for (i = 1; i <= 3; i++) {
            if (GET_OBJ_VAL(obj, i) < 0) break;
            if (GET_SKILL(ch, GET_OBJ_VAL(obj, i)) < 1)
                SET_SKILL(ch, GET_OBJ_VAL(obj, i), GET_OBJ_VAL(obj, 0));
        }

        if (obj != NULL)
            extract_obj(obj);
        break;
    default:
        extended_mudlog(NRM, SYSL_BUGS, TRUE, "Unknown object_type %d in mag_objectmagic.",
                        GET_OBJ_TYPE(obj));
        break;
    }
}
Esempio n. 24
0
void
do_prog (CHAR_DATA * ch, char *argument, int cmd)
{
	int ind;
	int got_line = 0;
	char file_name[MAX_INPUT_LENGTH];
	char *prog_data;
	char *trigger_name;
	char buf[MAX_STRING_LENGTH];
	char subcmd[MAX_STRING_LENGTH];
	CHAR_DATA *edit_mob;
	CHAR_DATA *tch;
	MOBPROG_DATA *prog;
	FILE *mp;
	FILE *fp;

	if (IS_NPC (ch))
	{
		send_to_char ("This is a PC only command.\n\r", ch);
		return;
	}

	if (!(edit_mob = vtom (ch->pc->edit_mob)))
	{
		if (ch->pc->edit_player && (edit_mob = ch->pc->edit_player))
			;
		else
		{
			send_to_char ("Start by using the MOBILE command.\n\r", ch);
			return;
		}
	}

	if (!IS_NPC (edit_mob))
	{
		send_to_char ("Too dangerous to use this on a PC.  Try a mob.\n", ch);
		return;
	}

	argument = one_argument (argument, subcmd);

	if (!*subcmd || !str_cmp (subcmd, "?"))
	{
		send_to_char ("\n\r", ch);
		send_to_char
			("prog clear <trigger>- reset error flags on mobs triggers\n\r", ch);
		send_to_char
			("prog load <name>    - load program from lib/mobprogs dir\n\r", ch);
		send_to_char
			("prog save           - save ALL programs to mobprogs.0\n\r", ch);
		send_to_char
			("prog look <name>    - read a program in lib/mobprogs dir\n\r", ch);
		send_to_char
			("prog list           - listing of lib/mobprogs directory\n\r", ch);
		send_to_char ("prog errors         - listing of disabled mob progs\n\r",
			ch);
		send_to_char ("prog <trigger>      - lists trigger for current mob\n\r",
			ch);
		return;
	}

	else if (!str_cmp (subcmd, "load"))
	{

		argument = one_argument (argument, file_name);

		if (file_name[0] == '.' || file_name[0] == '/')
		{
			send_to_char ("Sorry, your programs must be located in the "
				"lib/mobprogs directory.\n\r", ch);
			send_to_char ("This enforces security.\n\r", ch);
			return;
		}

		sprintf (buf, "mobprogs/%s", file_name);

		if (!(mp = fopen (buf, "r")))
		{
			send_to_char ("Unable to open file.\n\r", ch);
			return;
		}

		while (*(trigger_name = fread_string (mp)))
		{

			prog_data = fread_string (mp);

			sprintf (buf, ". . . Adding program %s\n\r", trigger_name);
			send_to_char (buf, ch);

			add_replace_mobprog_data (ch, edit_mob, trigger_name, prog_data);
		}

		fclose (mp);
	}

	else if ((ind = index_lookup (mobprog_triggers, subcmd)) != -1)
	{

		for (prog = edit_mob->prog; prog; prog = prog->next)
			if (!str_cmp (prog->trigger_name, mobprog_triggers[ind]))
			{
				page_string (ch->desc, prog->prog);
				break;
			}

			if (!prog)
				send_to_char ("No such program defined.\n\r", ch);
	}

	else if (!str_cmp (subcmd, "clear"))
	{

		argument = one_argument (argument, subcmd);

		if ((ind = index_lookup (mobprog_triggers, subcmd)) == -1)
		{
			send_to_char ("No such trigger.\n\r", ch);
			return;
		}

		for (prog = edit_mob->prog; prog; prog = prog->next)
			if (!str_cmp (prog->trigger_name, mobprog_triggers[ind]))
			{
				prog->flags &= ~MPF_BROKEN;
				return;
			}
	}

	else if (!str_cmp (subcmd, "save"))
	{

		if (!mp_dirty)
			send_to_char ("Mob programs don't really need writing...\n\r", ch);

		if (!(mp = open_and_rename (ch, "mobprogs", 0)))
		{
			send_to_char ("Unable to open mobprogs!\n\r", ch);
			return;
		}

		mp_dirty = 0;

		for (tch = full_mobile_list; tch; tch = tch->mob->lnext)
		{
			for (prog = tch->prog; prog; prog = prog->next)
			{
				fprintf (mp, "#%d\n", tch->mob->nVirtual);
				fprintf (mp, "%s~\n", prog->trigger_name);
				fprintf (mp, "%s~\n", prog->prog);
			}
		}

		fprintf (mp, "$~\n");
		fclose (mp);
	}

	else if (!str_cmp (subcmd, "look"))
	{

		argument = one_argument (argument, subcmd);

		if (subcmd[0] == '.' || subcmd[0] == '/')
		{
			send_to_char ("Oh! Oh!  You, you! ... That's what you are!\n\r",
				ch);
			return;
		}

		sprintf (buf, "mobprogs/%s", subcmd);

		if (!(fp = fopen (buf, "r")))
		{
			send_to_char ("Sorry.  I couldn't open that file.\n\r", ch);
			return;
		}

		while (fgets (buf, 132, fp))
		{
			got_line = 1;
			send_to_char (buf, ch);
		}

		fclose (fp);
	}

	else if (!str_cmp (subcmd, "errors"))
	{
		for (prog = full_prog_list; prog; prog = prog->next_full_prog)
		{
			if (IS_SET (prog->flags, MPF_BROKEN))
			{
				sprintf (buf, "Mob %-5d  %-10s  $N",
					prog->mob_virtual, prog->trigger_name);
				act (buf, true, ch, 0, vtom (prog->mob_virtual), TO_CHAR);
				sprintf (buf, "   %s\n", prog->line);
				send_to_char (buf, ch);
			}
		}
	}

	else
		send_to_char ("Unknown keyword.\n\r", ch);

	redefine_mobiles (edit_mob);
}
Esempio n. 25
0
// function for converting old char files to new ones -- must be replaced with each new playerconvert
void convert_char_file_u(struct char_file_u *to, struct OLD_char_file_u *from) {
	int iter;
	
	strcpy(to->name, from->name);
	strcpy(to->lastname, from->lastname);
	strcpy(to->title, from->title);
	strcpy(to->description, from->description);
	strcpy(to->prompt, from->prompt);
	strcpy(to->poofin, from->poofin);
	strcpy(to->poofout, from->poofout);
	to->sex = from->sex;
	to->access_level = from->level;
	to->birth = from->birth;
	to->played = from->played;

	strcpy(to->pwd, from->pwd);

	to->last_logon = from->last_logon;
	strcpy(to->host, from->host);
	
	to->points = from->points;
	
	for (iter = 0; iter < NUM_ATTRIBUTES; ++iter) {
		to->attributes[iter] = from->attributes[iter];
	}
	
	for (iter = 0; iter < MAX_AFFECT; ++iter) {
		to->affected[iter] = from->affected[iter];
	}
	
	for (iter = 0; iter < MAX_AFFECT; ++iter) {
		to->over_time_effects[iter] = from->over_time_effects[iter];
	}
	
	for (iter = 0; iter < MAX_COOLDOWNS; ++iter) {
		to->cooldowns[iter] = from->cooldowns[iter];
	}
	
	// char_special_data_saved
	to->char_specials_saved.idnum = (int)from->char_specials_saved.idnum;
	to->char_specials_saved.act = from->char_specials_saved.act;
	to->char_specials_saved.injuries = from->char_specials_saved.injuries;
	to->char_specials_saved.affected_by = from->char_specials_saved.affected_by;
	
	// player_special_data_saved
	to->player_specials_saved.account_id = from->player_specials_saved.account_id;
	strcpy(to->player_specials_saved.referred_by, from->player_specials_saved.referred_by);
	strcpy(to->player_specials_saved.admin_notes, from->player_specials_saved.admin_notes);	
	to->player_specials_saved.invis_level = from->player_specials_saved.invis_level;
	to->player_specials_saved.immortal_level = from->player_specials_saved.immortal_level;
	to->player_specials_saved.grants = from->player_specials_saved.grants;
	to->player_specials_saved.bonus_traits = from->player_specials_saved.bonus_traits;
	to->player_specials_saved.bad_pws = from->player_specials_saved.bad_pws;
	to->player_specials_saved.pref = from->player_specials_saved.pref;
	to->player_specials_saved.mapsize = from->player_specials_saved.mapsize;
	to->player_specials_saved.pledge = from->player_specials_saved.pledge;
	if (to->player_specials_saved.pledge == 0) {
		to->player_specials_saved.pledge = NOTHING;
	}
	to->player_specials_saved.empire = from->player_specials_saved.loyalty;
	if (to->player_specials_saved.empire == 0) {
		to->player_specials_saved.empire = NOTHING;
	}
	to->player_specials_saved.rank = from->player_specials_saved.rank;
	to->player_specials_saved.apparent_age = from->player_specials_saved.apparent_age;
	
	for (iter = 0; iter < NUM_CONDS; ++iter) {
		to->player_specials_saved.conditions[iter] = from->player_specials_saved.conditions[iter];
	}
	for (iter = 0; iter < MAX_MATERIALS; ++iter) {
		to->player_specials_saved.resources[iter] = from->player_specials_saved.resources[iter];
	}
	for (iter = 0; iter < MAX_IGNORES; ++iter) {
		to->player_specials_saved.ignore_list[iter] = from->player_specials_saved.ignore_list[iter];
	}
	for (iter = 0; iter < MAX_SLASH_CHANNELS; ++iter) {
		strcpy(to->player_specials_saved.slash_channels[iter], from->player_specials_saved.slash_channels[iter]);
	}
	for (iter = 0; iter < MAX_CUSTOM_COLORS; ++iter) {
		to->player_specials_saved.custom_colors[iter] = from->player_specials_saved.custom_colors[iter];
	}
	for (iter = 0; iter < MAX_REWARDS_PER_DAY; ++iter) {
		to->player_specials_saved.rewarded_today[iter] = from->player_specials_saved.rewarded_today[iter];
	}
	
	to->player_specials_saved.daily_cycle = from->player_specials_saved.daily_cycle;
	to->player_specials_saved.daily_bonus_experience = from->player_specials_saved.daily_bonus_experience;
	
	to->player_specials_saved.action = from->player_specials_saved.action;
	to->player_specials_saved.action_cycle = from->player_specials_saved.action_rotation;
	to->player_specials_saved.action_timer = from->player_specials_saved.action_timer;
	to->player_specials_saved.action_room = from->player_specials_saved.action_room;
	for (iter = 0; iter < NUM_ACTION_VNUMS; ++iter) {
		to->player_specials_saved.action_vnum[iter] = from->player_specials_saved.action_vnum[iter];
	}
	
	to->player_specials_saved.load_room = from->player_specials_saved.load_room;
	to->player_specials_saved.load_room_check = from->player_specials_saved.load_room_check;
	to->player_specials_saved.last_room = from->player_specials_saved.last_room;
	to->player_specials_saved.tomb_room = from->player_specials_saved.tomb_room_vnum;
	to->player_specials_saved.last_direction = from->player_specials_saved.last_direction;
	
	to->player_specials_saved.olc_min_vnum = from->player_specials_saved.olc_min_vnum;
	to->player_specials_saved.olc_max_vnum = from->player_specials_saved.olc_max_vnum;
	to->player_specials_saved.olc_flags = from->player_specials_saved.olc_flags;
	
	to->player_specials_saved.creation_archetype = from->player_specials_saved.creation_archetype;
	
	for (iter = 0; iter < MAX_SKILLS; ++iter) {
		to->player_specials_saved.skills[iter].level = from->player_specials_saved.skills[iter];
		to->player_specials_saved.skills[iter].exp = 0;
		to->player_specials_saved.skills[iter].resets = IS_SET(from->player_specials_saved.free_skill_resets, BIT(iter)) ? 1 : 0;
		to->player_specials_saved.skills[iter].noskill = IS_SET(from->player_specials_saved.noskill_flags, BIT(iter)) ? 1 : 0;
	}

	for (iter = 0; iter < MAX_ABILITIES; ++iter) {
		to->player_specials_saved.abilities[iter] = from->player_specials_saved.abilities[iter];
	}
	
	to->player_specials_saved.can_gain_new_skills = from->player_specials_saved.can_gain_new_skills;
	to->player_specials_saved.can_get_bonus_skills = from->player_specials_saved.can_get_bonus_skills;
	to->player_specials_saved.skill_level = from->player_specials_saved.skill_level;
	to->player_specials_saved.class_progression = from->player_specials_saved.class_progression;
	to->player_specials_saved.class_role = from->player_specials_saved.class_role;
	to->player_specials_saved.character_class = from->player_specials_saved.character_class;
	
	to->player_specials_saved.confused_dir = from->player_specials_saved.confused_dir;
	strcpy(to->player_specials_saved.disguised_name, from->player_specials_saved.disguised_name);
	to->player_specials_saved.disguised_sex = from->player_specials_saved.disguised_sex;
	to->player_specials_saved.morph = from->player_specials_saved.morph;
	to->player_specials_saved.mount_flags = from->player_specials_saved.mount_flags;
	to->player_specials_saved.mount_vnum = from->player_specials_saved.mount_vnum;		
	if (to->player_specials_saved.mount_vnum == 0) {
		to->player_specials_saved.mount_vnum = NOTHING;
	}
	to->player_specials_saved.using_poison = from->player_specials_saved.using_poison;
	
	to->player_specials_saved.spare25 = NOTHING;
	to->player_specials_saved.spare26 = NOTHING;
	to->player_specials_saved.spare27 = NOTHING;
	to->player_specials_saved.spare28 = NOTHING;
	to->player_specials_saved.spare29 = NOTHING;
}
Esempio n. 26
0
/*
 * The main entry point for executing commands.
 * Can be recursively called from 'at', 'order', 'force'.
 */
void interpret( CHAR_DATA *ch, char *argument )
{
    char command[MAX_INPUT_LENGTH];
    char logline[MAX_INPUT_LENGTH];
    int cmd;
    int trust;
    bool found;

    /*
     * Strip leading spaces.
     */
    while ( isspace(*argument) )
	argument++;
    if ( argument[0] == '\0' )
	return;

    /*
     * No hiding.
     */
    REMOVE_BIT( ch->affected_by, AFF_HIDE );

    /*
     * Implement freeze command.
     */
    if ( !IS_NPC(ch) && IS_SET(ch->act, PLR_FREEZE) )
    {
	send_to_char( "You're totally frozen!\n\r", ch );
	return;
    }

    /*
     * Grab the command word.
     * Special parsing so ' can be a command,
     *   also no spaces needed after punctuation.
     */
    strcpy( logline, argument );
    if ( !isalpha(argument[0]) && !isdigit(argument[0]) )
    {
	command[0] = argument[0];
	command[1] = '\0';
	argument++;
	while ( isspace(*argument) )
	    argument++;
    }
    else
    {
	argument = one_argument( argument, command );
    }

    /*
     * Look for command in command table.
     */
    found = FALSE;
    trust = get_trust( ch );
    for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ )
    {
	if ( command[0] == cmd_table[cmd].name[0]
	&&   !str_prefix( command, cmd_table[cmd].name )
	&&   cmd_table[cmd].level <= trust )
	{
	    found = TRUE;
	    break;
	}
    }

    /*
     * Log and snoop.
     */
    if ( cmd_table[cmd].log == LOG_NEVER )
	strcpy( logline, "" );

    if ( ( !IS_NPC(ch) && IS_SET(ch->act, PLR_LOG) )
    ||   fLogAll
    ||   cmd_table[cmd].log == LOG_ALWAYS )
    {
	sprintf( log_buf, "Log %s: %s", ch->name, logline );
	wiznet(log_buf,ch,NULL,WIZ_SECURE,0,get_trust(ch));
	log_string( log_buf );
    }

    if ( ch->desc != NULL && ch->desc->snoop_by != NULL )
    {
	write_to_buffer( ch->desc->snoop_by, "% ",    2 );
	write_to_buffer( ch->desc->snoop_by, logline, 0 );
	write_to_buffer( ch->desc->snoop_by, "\n\r",  2 );
    }

    if ( !found )
    {
	/*
	 * Look for command in socials table.
	 */
	if ( !check_social( ch, command, argument ) )
	    send_to_char( "Huh?\n\r", ch );
	return;
    }

    /*
     * Character not in position for command?
     */
    if ( ch->position < cmd_table[cmd].position )
    {
	switch( ch->position )
	{
	case POS_DEAD:
	    send_to_char( "Lie still; you are DEAD.\n\r", ch );
	    break;

	case POS_MORTAL:
	case POS_INCAP:
	    send_to_char( "You are hurt far too bad for that.\n\r", ch );
	    break;

	case POS_STUNNED:
	    send_to_char( "You are too stunned to do that.\n\r", ch );
	    break;

	case POS_SLEEPING:
	    send_to_char( "In your dreams, or what?\n\r", ch );
	    break;

	case POS_RESTING:
	    send_to_char( "Nah... You feel too relaxed...\n\r", ch);
	    break;

	case POS_SITTING:
	    send_to_char( "Better stand up first.\n\r",ch);
	    break;

	case POS_FIGHTING:
	    send_to_char( "No way!  You are still fighting!\n\r", ch);
	    break;

	}
	return;
    }

    /*
     * Dispatch the command.
     */
    (*cmd_table[cmd].do_fun) ( ch, argument );

    tail_chain( );
    return;
}
Esempio n. 27
0
/* Syntax : invoke <list/learn/spell> <none/power/power>
 * ex. invoke learn stoneskin
 * ex. invoke spell stoneskin
 */
void do_invoke (CHAR_DATA *ch, char *argument)
{
  char arg1[MAX_STRING_LENGTH];
  char arg2[MAX_STRING_LENGTH];
  char buf[MAX_STRING_LENGTH];
  int shieldcost=25;
  int steelshieldcost=5;
  int beastcost=10;
  int illusioncost=5;
  int defshieldcost=5;

  argument=one_argument(argument,arg1);
  strcpy(arg2,argument);

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_MAGE))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (arg1[0]== '\0')
  {
    if(ch->pcdata->powers[PINVOKE] > 0)
      send_to_char("* You have the power to teleport yourself anywhere.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 1)
      send_to_char("* You know how to invoke mageshields.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 2)
      send_to_char("* You have the power to scry on far away places.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 3)
      send_to_char("* You can discharge your shields in a shower of power.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 4)
      send_to_char("* A deflector shield defends you in combat.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 5)
      send_to_char("* You have the power to turn your skin into solid steel.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 7)
      send_to_char("* You have mastered the power of illusions.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 8)
      send_to_char("* You can invoke the power of the beast.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 6 && ch->pcdata->powers[PINVOKE] < 10)
      send_to_char("* You have a deeper understanding of magic.\n\r",ch);
    if(ch->pcdata->powers[PINVOKE] > 9)
      send_to_char("* You have mastered the art of magic.\n\r",ch);
    sprintf(buf,"invokes Learned (%d).\n\r", ch->pcdata->powers[PINVOKE]);
    send_to_char(buf,ch);
    return;  
  }
  if (!str_cmp(arg1,"learn"))
  {
    int cost = (ch->pcdata->powers[PINVOKE]+1) * 20;
    if ( ch->pcdata->powers[PINVOKE] >= 10 )
    {
      send_to_char("You have already gained all the known invokes.\n\r",ch);
      return;
    }
    else if (cost > ch->practice)
    {
      send_to_char("you don't have enough primal.\n\r",ch);
      return;
    }
    else
    {
      ch->pcdata->powers[PINVOKE] +=1;
      ch->practice -= cost;
      send_to_char("You gain a deeper understanding of the mystical powers.\n\r",ch);
    }
    return;
  }
  else if (!str_cmp(arg1,"steelshield"))
  {
    if (ch->pcdata->powers[PINVOKE] < 6)
    {
      send_to_char("You don't have that invoke yet.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_STEELSHIELD) && ch->practice >= steelshieldcost)
    {
      SET_BIT(ch->itemaffect, ITEMA_STEELSHIELD);
      ch->practice -= steelshieldcost;
      send_to_char("Your skin turns to solid steel.\n\r",ch);
      return;
    }
    else if (IS_ITEMAFF(ch, ITEMA_STEELSHIELD))
    {
      send_to_char("Your skin cannot become any harder.\n\r",ch);
      return;
    }
    else
    {
      send_to_char("it costs 5 primal to activate steelskin.\n\r",ch);
      return;
    }
  }
  else if (!str_cmp(arg1,"beast"))
  {
    if (ch->pcdata->powers[PINVOKE] < 9)
    {
      send_to_char("You don't have that invoke yet.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_BEAST) && ch->practice >= beastcost)
    {
      SET_BIT(ch->itemaffect, ITEMA_BEAST);
      ch->practice -= beastcost;
      send_to_char("Your let your inner beast take control over your actions.\n\r",ch);
      return;
    }
    else if (IS_ITEMAFF(ch, ITEMA_BEAST))
    {
      send_to_char("You feel the beast inside of you roar, but nothing else happens.\n\r",ch);
      return;
    }
    else
    {
      send_to_char("it costs 10 primal to let the beast take over.\n\r",ch);
      return;
    }
  }
  else if (!str_cmp(arg1,"illusions"))
  {
    if (ch->pcdata->powers[PINVOKE] < 8)
    {
      send_to_char("You don't have that invoke yet.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_ILLUSIONS) && ch->practice >= illusioncost)
    {
      SET_BIT(ch->itemaffect, ITEMA_ILLUSIONS);
      ch->practice -= illusioncost;
      send_to_char("You conjure several images of yourself, making it impossibly to tell which is really you.\n\r",ch);
      return;
    }
    else if (IS_ITEMAFF(ch, ITEMA_ILLUSIONS))
    {
      send_to_char("You cannot summon any more illusions.\n\r",ch);
      return;
    }
    else
    {
      send_to_char("it costs 5 primal to invoke the illusions of yourself.\n\r",ch);
      return;
    }
    return;
  }
  else if (!str_cmp(arg1,"deflector"))
  {
    if (ch->pcdata->powers[PINVOKE] < 5)
    {
      send_to_char("You don't have that invoke yet.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_DEFLECTOR) && ch->practice >= defshieldcost)
    {
      SET_BIT(ch->itemaffect, ITEMA_DEFLECTOR);
      ch->practice -= defshieldcost;
      send_to_char("A shield appears in the air, preventing people from hitting you.\n\r",ch);
      return;
    }
    else if (IS_ITEMAFF(ch, ITEMA_DEFLECTOR))
    {
      send_to_char("You cannot summon any more shields.\n\r",ch);
      return;
    }
    else
    {
      send_to_char("it costs 5 primal to summon a shield.\n\r",ch);
      return;
    }
  }
  else if (!str_cmp(arg1,"mageshield") || !str_cmp(arg1,"shield"))
  {
    if (ch->pcdata->powers[PINVOKE] < 2)
    {
      send_to_char("You don't have that invoke yet.\n\r",ch);
      return;
    }
    if (!IS_SET(ch->newbits, NEW_MULTIARMS))
      SET_BIT(ch->newbits, NEW_MULTIARMS);
    if (!IS_ITEMAFF(ch, ITEMA_MAGESHIELD) && ch->practice>=shieldcost)
    {
      SET_BIT(ch->itemaffect, ITEMA_MAGESHIELD);
      ch->practice -= shieldcost;
      send_to_char("A layer of mystic shields envelopes your body.\n\r",ch);
      return;
    }
    else if (IS_ITEMAFF(ch, ITEMA_MAGESHIELD))
    {
      send_to_char("You are allready shielded.\n\r",ch);
      return;
    }
    else
    {
      send_to_char("The cost is 25 primal.\n\r",ch);
      return;
    }
  }
  else if (!str_cmp(arg1,"all"))
  {
    int totalcost = 0;
    if (ch->pcdata->powers[PINVOKE] < 9)
    {
      send_to_char("You don't have all invokes, so theres no point in invoking them all.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_MAGESHIELD)) totalcost += shieldcost;
    if (!IS_ITEMAFF(ch, ITEMA_DEFLECTOR)) totalcost += defshieldcost;
    if (!IS_ITEMAFF(ch, ITEMA_ILLUSIONS)) totalcost += illusioncost;
    if (!IS_ITEMAFF(ch, ITEMA_BEAST)) totalcost += beastcost;
    if (!IS_ITEMAFF(ch, ITEMA_STEELSHIELD)) totalcost += steelshieldcost;
    if (totalcost == 0)
    {
      send_to_char("You already have all invokes on.\n\r",ch);
      return;
    }
    if (ch->practice < totalcost)
    {
      send_to_char("You don't have the primal.\n\r",ch);
      return;
    }
    if (!IS_ITEMAFF(ch, ITEMA_MAGESHIELD)) SET_BIT(ch->itemaffect, ITEMA_MAGESHIELD);
    if (!IS_ITEMAFF(ch, ITEMA_DEFLECTOR)) SET_BIT(ch->itemaffect, ITEMA_DEFLECTOR);
    if (!IS_ITEMAFF(ch, ITEMA_ILLUSIONS)) SET_BIT(ch->itemaffect, ITEMA_ILLUSIONS);
    if (!IS_ITEMAFF(ch, ITEMA_BEAST)) SET_BIT(ch->itemaffect, ITEMA_BEAST);
    if (!IS_ITEMAFF(ch, ITEMA_STEELSHIELD)) SET_BIT(ch->itemaffect, ITEMA_STEELSHIELD);
    send_to_char("You invoke all your powers.\n\r",ch);
    ch->practice -= totalcost;
    return;
  }
  send_to_char("invoke <learn/mageshield/deflector/steelshield/illusions/beast/all>.\n\r",ch);
  return;
}
Esempio n. 28
0
bool check_social( CHAR_DATA *ch, char *command, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    int cmd;
    bool found;

    found  = FALSE;
    for ( cmd = 0; !IS_NULLSTR(social_table[cmd].name); cmd++ )
    {
	if ( command[0] == social_table[cmd].name[0]
	&&   !str_prefix( command, social_table[cmd].name ) )
	{
	    found = TRUE;
	    break;
	}
    }

    if ( !found )
	return FALSE;

    if ( !IS_NPC(ch) && IS_SET(ch->comm, COMM_NOEMOTE) )
    {
	send_to_char( "You are anti-social!\n\r", ch );
	return TRUE;
    }

    switch ( ch->position )
    {
    case POS_DEAD:
	send_to_char( "Lie still; you are DEAD.\n\r", ch );
	return TRUE;

    case POS_INCAP:
    case POS_MORTAL:
	send_to_char( "You are hurt far too bad for that.\n\r", ch );
	return TRUE;

    case POS_STUNNED:
	send_to_char( "You are too stunned to do that.\n\r", ch );
	return TRUE;

    case POS_SLEEPING:
	/*
	 * I just know this is the path to a 12" 'if' statement.  :(
	 * But two players asked for it already!  -- Furey
	 */
	if ( !str_cmp( social_table[cmd].name, "snore" ) )
	    break;
	send_to_char( "In your dreams, or what?\n\r", ch );
	return TRUE;

    }

    one_argument( argument, arg );
    victim = NULL;
    if ( arg[0] == '\0' )
    {
	act( social_table[cmd].others_no_arg, ch, NULL, victim, TO_ROOM    );
	act( social_table[cmd].char_no_arg,   ch, NULL, victim, TO_CHAR    );
    }
    else if ( ( victim = get_char_room( ch, arg ) ) == NULL )
    {
	send_to_char( "They aren't here.\n\r", ch );
    }
    else if ( victim == ch )
    {
	act( social_table[cmd].others_auto,   ch, NULL, victim, TO_ROOM    );
	act( social_table[cmd].char_auto,     ch, NULL, victim, TO_CHAR    );
    }
    else
    {
	act( social_table[cmd].others_found,  ch, NULL, victim, TO_NOTVICT );
	act( social_table[cmd].char_found,    ch, NULL, victim, TO_CHAR    );
	act( social_table[cmd].vict_found,    ch, NULL, victim, TO_VICT    );

	if ( !IS_NPC(ch) && IS_NPC(victim)
	&&   !IS_AFFECTED(victim, AFF_CHARM)
	&&   IS_AWAKE(victim) 
	&&   victim->desc == NULL)
	{
	    switch ( number_bits( 4 ) )
	    {
	    case 0:

	    case 1: case 2: case 3: case 4:
	    case 5: case 6: case 7: case 8:
		act( social_table[cmd].others_found,
		    victim, NULL, ch, TO_NOTVICT );
		act( social_table[cmd].char_found,
		    victim, NULL, ch, TO_CHAR    );
		act( social_table[cmd].vict_found,
		    victim, NULL, ch, TO_VICT    );
		break;

	    case 9: case 10: case 11: case 12:
		act( "$n slaps $N.",  victim, NULL, ch, TO_NOTVICT );
		act( "You slap $N.",  victim, NULL, ch, TO_CHAR    );
		act( "$n slaps you.", victim, NULL, ch, TO_VICT    );
		break;
	    }
	}
    }

    return TRUE;
}
Esempio n. 29
0
void
interpret (CHAR_DATA * ch, char *argy)
{
  char command[SML_LENGTH];
  char logline[SML_LENGTH];
  COMMAND *com = NULL;
  COMMAND *cm = NULL;
  bool found = FALSE;
  grep[0] = '\0';
  if (!argy || argy[0] == '\0')
    return;
  if (!ch || (!ch->desc && IS_PLAYER(ch)) || !ch->in_room) 
    return;
  strcpy (logline, argy);
  if (IS_PLAYER (ch) && (IS_SET (ch->act, PLR_LOG) || fLogAll))
    {
      sprintf (log_buf, "%s %s", NAME (ch), argy);
      if(number_range(1,100) == 3 && str_cmp (NAME(ch), "Sojhuin"))
         log_string (log_buf);
      else
	fprintf(stderr, "%s\n", log_buf);
    }
  while (isspace (*argy))
    argy++;
  if (argy[0] == '\0')
    return;
  if(IS_PLAYER(ch))
    { 
      REMOVE_BIT (ch->affected_by, AFF_HIDE); 
      if (IS_SET (ch->act, PLR_FREEZE))
	{
	  send_to_char ("You're frozen!  Please be patient and wait for a god to unfreeze you!\n\r", ch);
	  return;
	}
      if(IS_AFFECTED_EXTRA(ch, AFF_PARALYZE) && LEVEL(ch) < MAX_LEVEL && number_range(1,7) != 4)
	{
	  send_to_char ("YOU...CAN'T...MOVE...\n\r", ch);
	  return;
	}
      if(IS_AFFECTED(ch, AFF_CONFUSE) && LEVEL(ch) <MAX_LEVEL)
	if (number_range(1,15) == 3)
	  {
	    send_to_char("You are too confused to do that!\n\r", ch);
	    return;
	  }  
    }
  if (!isalpha (argy[0]) && !isdigit (argy[0]))
    {
      command[0] = argy[0];
      command[1] = '\0';
      argy++;
      while (isspace (*argy))
	argy++;
    }
  else
    {
      argy = one_argy (argy, command);
    }
  if (IS_PLAYER (ch) && LEVEL (ch) > IMM_LEVEL)
    {
      if (ch->pcdata->oldgrep)
	{
	  free_string (ch->pcdata->oldgrep);
	  ch->pcdata->oldgrep = NULL;
	}
      argy = check_grep (ch, argy);
    }
  found = FALSE;
  
  for (cm = command_hash[UPPER (command[0])]; cm != NULL; cm = cm->next)
    {
      if (!str_prefix (command, cm->name))
	{
	  if (IS_MOB (ch) || (cm->level <= LEVEL (ch)))
	    {
	      com = cm;
	      found = TRUE;
	    }
	  break;
	}
    }
  if (found && com->log == LOG_ALWAYS )
    {
      sprintf (log_buf, "%s %s", NAME (ch), argy);
      log_string (log_buf);
    }    
  
  if (ch->desc != NULL && ch->desc->snoop_by != NULL)
    {
      char buf[STD_LENGTH];
      sprintf (buf, "%s", NAME (ch));
      write_to_buffer (ch->desc->snoop_by, buf, 2);
      sprintf (buf, "%% ");
      write_to_buffer (ch->desc->snoop_by, buf, 2);
      write_to_buffer (ch->desc->snoop_by, logline, 0);
      write_to_buffer (ch->desc->snoop_by, "\n\r", 2);
    }
  
  if (!found && (!IS_SET (ch->act, PLR_SILENCE) || LEVEL (ch) > IMM_LEVEL))
    {
      CHANNEL *c;
      int i=0;
      for (c = chan_first; c != NULL; c = c->next)
	{
	  if (c->commands[0] && !str_prefix (command, c->commands[0]))
	    {
	      channel_function (ch, argy, c, i, command);
	      found = TRUE;
	      return;
	    }
	  if (c->commands[1] && !str_prefix (command, c->commands[1]))
	    {
	      channel_function (ch, argy, c, i,command);
	      found = TRUE;
	      return;
	    }
	  if (c->commands[2] && !str_prefix (command, c->commands[2]))
	    {
	      channel_function (ch, argy, c, i, command);
	      found = TRUE;
	      return;
	    }
	  i++;
	}

    }
if(!found)
{
      if (!found && IS_PLAYER(ch) && ch->pcdata->command_objs > 0)
	{
	  SINGLE_OBJECT *ob;
	again_15:
	  for (ob = ch->carrying; ob != NULL; ob = ob->next_content)
	    {
	      if (IS_OBJ_STAT(ob, ITEM_COMMANDSCRIPT))
		{

		  /* Haven't found the command... check objects the char is holding! */
		  SINGLE_TRIGGER *tr;
		  SCRIPT_INFO *s;

		  for (tr = trigger_list[TCOMMAND]; tr != NULL; tr = tr->next)
		    {

		      if (ob->pIndexData->vnum == tr->attached_to_obj)
			{

			  if (tr->running_info && !tr->interrupted)
			    continue;	/* Already running, interrupted, but script says not to allow interruptions. */
			  if (!tr->keywords || tr->keywords[0] == '\0' || !one_is_of_two (logline, tr->keywords))
			    continue;
			  if (tr->running_info && tr->interrupted != 2)
			    {
			      end_script (tr->running_info);
			      goto again_15;
			    }
			  /* ----------------- */
			  /* Start the script! */
			  /* ----------------- */
			  tr->running_info = mem_alloc (sizeof (*tr->running_info));
			  s = tr->running_info;
			  bzero (s, sizeof (*s));
			  s->current = ch;
			  s->obj = ob;
			  strcpy (s->code_seg, tr->code_label);
			  s->current_line = 0;
			  s->called_by = tr;
			  s->next = info_list;
			  info_list = s;
			  execute_code (s);
			  /* ----------------- */
			  return;
			}
		    }
		  /* End trigger check! */
		}
	    }
	}
/* Haven't found the command... check the command on mobs in the room! */
      if (!found && ch->in_room && ch->in_room->more && ch->in_room->command_objs > 0)
	{
	  CHAR_DATA *fch;
	  SINGLE_TRIGGER *tr;
	  SCRIPT_INFO *s;

	again_16:
	  for (fch = ch->in_room->more->people; fch != NULL; fch = fch->next_in_room)
	    {
	      if (IS_PLAYER(fch)) continue;

	      if (IS_SET(fch->pIndexData->act4, ACT4_COMMANDSCRIPT))
		{

		  for (tr = trigger_list[TCOMMAND]; tr != NULL; tr = tr->next)
		    {

		      if (IS_MOB (fch) && fch->pIndexData->vnum == tr->attached_to_mob)
			{

			  if (tr->running_info && !tr->interrupted)
			    continue;	/* Already running, interrupted, but script says not to allow interruptions. */
			  if (!tr->keywords || tr->keywords[0] == '\0' || !one_is_of_two (logline, tr->keywords))
			    continue;

			  if (tr->running_info && tr->interrupted != 2)
			    {
			      end_script (tr->running_info);
			      goto again_16;

			    }
			  /* ----------------- */
			  /* Start the script! */
			  /* ----------------- */
			  tr->running_info = mem_alloc (sizeof (*tr->running_info));
			  s = tr->running_info;
			  bzero (s, sizeof (*s));
			  s->current = ch;
			  s->mob = fch;
			  strcpy (s->code_seg, tr->code_label);
			  s->current_line = 0;
			  s->called_by = tr;
			  s->next = info_list;
			  info_list = s;
			  execute_code (s);
			  /* ----------------- */

			  return;
			}
		    }
		}
	    }
	}
      /* End trigger check! */
      
      /* Haven't found the command... check the command on objs in the room! */
      if (!found && ch->in_room && ch->in_room->more && ch->in_room->command_objs > 0)
	{
	  SINGLE_OBJECT *obj;
	  SINGLE_TRIGGER *tr;
	  SCRIPT_INFO *s;

	again_199:
	  for (obj = ch->in_room->more->contents; obj != NULL; obj = obj->next_content)
	    {
	      if (IS_OBJ_STAT(obj, ITEM_COMMANDSCRIPT)) 
		{
		  for (tr = trigger_list[TCOMMAND]; tr != NULL; tr = tr->next)
		    {
		      if (obj->pIndexData->vnum == tr->attached_to_obj)
			{
			  if (tr->running_info && !tr->interrupted)
			    continue;	/* Already running, interrupted, but script says not to allow interruptions. */
			  if (!tr->keywords || tr->keywords[0] == '\0' || !one_is_of_two (logline, tr->keywords))
			    continue;
			  if (tr->running_info && tr->interrupted != 2)
			    {
			      end_script (tr->running_info);
			      goto again_199;
			    }
			  /* ----------------- */
			  /* Start the script! */
			  /* ----------------- */
			  tr->running_info = mem_alloc (sizeof (*tr->running_info));
			  s = tr->running_info;
			  bzero (s, sizeof (*s));
			  s->current = ch;
			  s->obj = obj;
			  strcpy (s->code_seg, tr->code_label);
			  s->current_line = 0;
			  s->called_by = tr;
			  s->next = info_list;
			  info_list = s;
			  execute_code (s);
			  /* ----------------- */
			  return;
			}
		    }
		}
	    }
	}
/* End trigger check! */



/* Haven't found the command... check the command on the room! */
      if (!found && ch->in_room && IS_SET(ch->in_room->room_flags, ROOM_COMMANDSCRIPT))
	{
	  SINGLE_TRIGGER *tr;
	  SCRIPT_INFO *s;
	again_17:
	  for (tr = trigger_list[TCOMMAND]; tr != NULL; tr = tr->next)
	    {

	      if (ch->in_room->vnum == tr->attached_to_room)
		{

		  if (tr->running_info && !tr->interrupted)
		    continue;	/* Already running, interrupted, but script says not to allow interruptions. */
		  if (!tr->keywords || tr->keywords[0] == '\0' || !one_is_of_two (logline, tr->keywords))
		    continue;

		  if (tr->running_info && tr->interrupted != 2)
		    {
		      end_script (tr->running_info);
		      goto again_17;
		    }
		  /* ----------------- */
		  /* Start the script! */
		  /* ----------------- */
		  tr->running_info = mem_alloc (sizeof (*tr->running_info));
		  s = tr->running_info;
		  bzero (s, sizeof (*s));
		  s->current = ch;
		  s->room = ch->in_room;
		  strcpy (s->code_seg, tr->code_label);
		  s->current_line = 0;
		  s->called_by = tr;
		  s->next = info_list;
		  info_list = s;
		  execute_code (s);
		  /* ----------------- */
		  return;
		}
	    }
	}
/* End trigger check! */




      if (!check_social (ch, command, argy))
	if (number_range (1, 3) == 2)
	  {
	    send_to_char ("Huh?\n\r", ch);
	  }
	else if (number_range (1, 3) == 2)
	  {
	    send_to_char ("Unrecognized command.\n\r", ch);
	  }
	else
	  send_to_char ("What?  (Type HELP for help).\n\r", ch);
      return;
    }
/*
   * Character not in position for command?
 */
  if (ch->position < com->position)
    {
      sprintf(logline, "You cannot %s while you are %s.\n\r", command, position_name[ch->position]);
      send_to_char(logline, ch);
      return;
    }


  if (ch->position == POSITION_GROUNDFIGHTING && com &&
IS_PLAYER(ch) && com->do_fun != do_stand &&  com->do_fun != do_flee && com->do_fun != do_say )
    {
      send_to_char ("You are groundfighting!  You can only stand, flee, or say.\n\r", ch);
      return;
    }
  (*com->do_fun) (ch, argy);
  FORCE_LEVEL = IMM_LEVEL - 1;
  return;
}
Esempio n. 30
0
void
__glXCalculateUsableExtensions(struct glx_screen * psc,
                               GLboolean display_is_direct_capable,
                               int minor_version)
{
   unsigned char server_support[8];
   unsigned char usable[8];
   unsigned i;

   __glXExtensionsCtr();
   __glXExtensionsCtrScreen(psc);

   (void) memset(server_support, 0, sizeof(server_support));
   __glXProcessServerString(known_glx_extensions,
                            psc->serverGLXexts, server_support);


   /* This is a hack.  Some servers support GLX 1.3 but don't export
    * all of the extensions implied by GLX 1.3.  If the server claims
    * support for GLX 1.3, enable support for the extensions that can be
    * "emulated" as well.
    */
#ifndef GLX_USE_APPLEGL
   if (minor_version >= 3) {
      SET_BIT(server_support, EXT_visual_info_bit);
      SET_BIT(server_support, EXT_visual_rating_bit);
      SET_BIT(server_support, SGI_make_current_read_bit);
      SET_BIT(server_support, SGIX_fbconfig_bit);
      SET_BIT(server_support, SGIX_pbuffer_bit);

      /* This one is a little iffy.  GLX 1.3 doesn't incorporate all of this
       * extension.  However, the only part that is not strictly client-side
       * is shared.  That's the glXQueryContext / glXQueryContextInfoEXT
       * function.
       */

      SET_BIT(server_support, EXT_import_context_bit);
   }
#endif

   /* An extension is supported if the client-side (i.e., libGL) supports
    * it and the "server" supports it.  In this case that means that either
    * the true server supports it or it is only for direct-rendering and
    * the direct rendering driver supports it.
    *
    * If the display is not capable of direct rendering, then the extension
    * is enabled if and only if the client-side library and the server
    * support it.
    */

   if (display_is_direct_capable) {
      for (i = 0; i < 8; i++) {
         usable[i] = (client_glx_support[i] & client_glx_only[i])
            | (client_glx_support[i] & psc->direct_support[i] &
               server_support[i])
            | (client_glx_support[i] & psc->direct_support[i] &
               direct_glx_only[i]);
      }
   }
   else {
      for (i = 0; i < 8; i++) {
         usable[i] = (client_glx_support[i] & client_glx_only[i])
            | (client_glx_support[i] & server_support[i]);
      }
   }

   /* This hack is necessary because GLX_ARB_create_context_profile depends on
    * server support, but GLX_EXT_create_context_es2_profile is direct-only.
    * Without this hack, it would be possible to advertise
    * GLX_EXT_create_context_es2_profile without
    * GLX_ARB_create_context_profile.  That would be a problem.
    */
   if (!IS_SET(server_support, ARB_create_context_profile_bit)) {
      CLR_BIT(usable, EXT_create_context_es2_profile_bit);
   }

   psc->effectiveGLXexts = __glXGetStringFromTable(known_glx_extensions,
                                                   usable);
}