Esempio n. 1
0
int is_solvable()
{
	// consider some row and column and num (which runs from 1 to 9)
	int row, col, num;
	
	// if there is any unassigned cell, fetch the co-ordinates and store in row and column
	// else puzzle is done
	if(!find_next_unassigned(&row, &col))
		return 1;
	
	// start with num = 1 for any cell
	for(num = 1; num <= N; num++)
	{
		if(is_safe(row, col, num))
		{
			// if num can be assigned to this cell store it assuming it to be true
			sudoku[row][col] = num;
			
			// if storing num in that cell leads to solution continue
			if(is_solvable())
				return 1;
			
			// else remove the num from that cell and backtrack
			sudoku[row][col] = UNASSIGNED;
		}
	}
	
	return 0;
}
Esempio n. 2
0
void
got_dir (str *out, vec<str> s, str loc, bool *errp)
{
  strip_comments (&s);
  if (s.size () != 2) {
    warn << loc << ": usage: " << s[0] << " <path>\n";
    *errp = true;
    return;
  }
  str res = s[1];
  if (res.len() > 1 && res[0] == '$') {
    str env_val = getenv(res.cstr() + 1);
    if (!env_val) {
      warn << loc << ": directory env variable not set (" << res << ")\n";
      *errp = true;
      return;
    }
    res = env_val;
  }
  if (!is_safe(res)) {
    warn << loc << ": directory (" << res << ") contains unsafe substrings\n";
    *errp = true;
    return;
  }
  *out = dir_standardize(res);
}
queen_list n_queen(int n)
{
  if(n == 0)
    return NULL;
  queen_list l =  n_queen(n-1);
  for(int i = 0;i < n;++i){
    if(is_safe(l,i,n))
      join_queen_list(l,i,n);
  }
}
Esempio n. 4
0
bool spec_ogre_member( CHAR_DATA *ch )
{
    CHAR_DATA * vch, *victim = NULL;
    int count = 0;
    char *message;

    if ( !IS_AWAKE( ch ) || IS_AFFECTED( ch, AFF_CALM ) || ch->in_room == NULL
         || IS_AFFECTED( ch, AFF_CHARM ) || ch->fighting != NULL )
        return FALSE;

    /* find an troll to beat up */
    for ( vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room )
    {
        if ( !IS_NPC( vch ) || ch == vch )
            continue;

        if ( !str_cmp( race_table[ GET_RACE(vch) ].name, "troll" )
             && ch->level > vch->level - 2 && !is_safe( ch, vch, TRUE ) )
        {
            if ( number_range( 0, count ) == 0 )
                victim = vch;

            count++;
        }
    }

    if ( victim == NULL )
        return FALSE;

    /* say something, then raise hell */
    switch ( number_range( 0, 6 ) )
    {
        default: message = NULL;	break;
        case 0: message = "$n wrzeszczy 'Szuka³em ciê, ¶mieciu!'";
            break;
        case 1: message = "$n atakuje $C z szaleñczym wrzaskiem.";
            break;
        case 2: message =
                "$n mówi 'Co taki ¶mierdz±cy, trollowaty pomiot jak ty tu w ogóle robi?'";
            break;
        case 3: message = "$n wy³amuje palce a¿ trzeszcz± i mówi 'My¶lisz, ¿e masz szczê¶cie?'";
            break;
        case 4: message = "$n mówi 'Nie widzê tu stra¿ników którzy mogliby ciê ochroniæ tym razem!'";
            break;
        case 5: message = "$n mówi 'Czas do³±czyæ do swoich durnych braci w za¶wiatach.'";
            break;
        case 6: message = "$n mówi 'I niech gra muzyka...'";
            break;
    }

    if ( message != NULL )
        act( message, ch, NULL, victim, TO_ALL );
    multi_hit( ch, victim, TYPE_UNDEFINED );
    return TRUE;
}
Esempio n. 5
0
void do_chaossurge(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *victim;
  char buf[MAX_STRING_LENGTH];
  char arg[MAX_INPUT_LENGTH];
  int dam;

  argument = one_argument( argument, arg );

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_TANARRI) && !IS_CLASS(ch, CLASS_LICH))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (IS_CLASS(ch, CLASS_LICH) && ch->pcdata->powers[CHAOS_MAGIC] < 3)
  {
    send_to_char("Yes Master.\n\r",ch);
    return;
  }
  if ((victim = get_char_room(ch, arg)) == NULL)
  {
    send_to_char("They are not here.\n\r", ch);
    return;
  }
  if (IS_NPC(victim))
  {
    send_to_char("Not on mobiles.\n\r",ch);
    return;
  }
  if (is_safe(ch,victim)) return;
  if (victim == ch)
  {
    send_to_char("That doesn't seem like a good idea.\n\r",ch);
    return;
  }
  if (victim->alignment < -500)
  {
    send_to_char("They are too evil, you cannot affect them.\n\r",ch);
    return;
  }
  if (victim->alignment > 500) dam = 1500;
  else if (victim->alignment > 0) dam = 1000;
  else dam = 500;
  sprintf(buf,"Your let chaos envelope $N and $S is hurt [%d]",dam);
  act(buf,ch,NULL,victim,TO_CHAR);
  sprintf(buf,"$n points a wicked finger at you and chaos strikes your mind! [%d]",dam);
  act(buf,ch,NULL,victim,TO_VICT);
  sprintf(buf,"$n strikes $N down with a burst of pure #RCHAOS!#n.");
  act(buf,ch,NULL,victim,TO_NOTVICT);
  hurt_person(ch,victim,dam);
  WAIT_STATE(ch,12);
  return;
}
Esempio n. 6
0
/* syntax : discharge
 * (drops all elementalshields in one BIG blast)
 */
void do_discharge (CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *vch;
  CHAR_DATA *vch_next;
  CHAR_DATA *mount;
  char buf1[MAX_STRING_LENGTH];
  char buf2[MAX_STRING_LENGTH];
  char buf3[MAX_STRING_LENGTH];
  int magic_power = ch->spl[RED_MAGIC] + ch->spl[BLUE_MAGIC] + ch->spl[GREEN_MAGIC] + ch->spl[PURPLE_MAGIC] + ch->spl[YELLOW_MAGIC];
  int dam;

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_MAGE))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[PINVOKE] < 4) /* 4 is just a test */
  {
    send_to_char("You don't have that invoke yet.\n\r",ch);
    return;
  }
  if (IS_ITEMAFF(ch, ITEMA_AFFENTROPY)) 
    magic_power +=100;
  if (IS_ITEMAFF(ch, ITEMA_MAGESHIELD))
  {
    REMOVE_BIT(ch->itemaffect, ITEMA_MAGESHIELD);
    for (vch = ch->in_room->people; vch != NULL; vch = vch_next)
    {
      vch_next = vch->next_in_room;
      if (vch != ch)
      {
        if (is_safe(ch,vch)) continue;
        if ((mount = ch->mount) != NULL)
          if (mount == vch) continue;
        dam = number_range(magic_power*7/2, magic_power*9/2) + ch->damroll;
        if (IS_AFFECTED(vch, AFF_SANCTUARY)) dam *= 0.5;
        sprintf(buf1,"$n's mystical shields explodes in a shower of flames striking $N [#C%d#n]",dam);
        sprintf(buf2,"Your mystical shields explodes in a shower of flames striking $N [#C%d#n]",dam);
        sprintf(buf3,"$n's mystical shields explodes in a shower of flames striking you [#C%d#n]",dam);
        act(buf1,ch,NULL,vch, TO_NOTVICT);
        act(buf2,ch,NULL,vch, TO_CHAR);
        act(buf3,ch,NULL,vch, TO_VICT);
        hurt_person(ch,vch,dam);
        if (vch->position > POS_STUNNED)
        {
          if (vch->fighting == NULL) set_fighting(vch, ch);
          if (ch->fighting == NULL) set_fighting(ch, vch);
        }
      }
    }
  }
  return;
}
Esempio n. 7
0
void do_forgivness( CHAR_DATA *ch, char *argument )
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];

    argument = one_argument( argument, arg );

    if (IS_NPC(ch)) return;
    if (!IS_CLASS(ch, CLASS_ANGEL))
    {
        send_to_char("Huh?\n\r",ch);
        return;
    }
    if (ch->pcdata->powers[ANGEL_LOVE] < 3)
    {
        send_to_char("Your are not loving enough.\n\r",ch);
        return;
    }
    if ((victim = get_char_room(ch, arg)) == NULL)
    {
        send_to_char("They are not here.\n\r", ch);
        return;
    }
    if (IS_NPC(victim))
    {
        send_to_char("Not on mobiles.\n\r",ch);
        return;
    }
    if (is_safe(ch,victim)) return;
    if (victim == ch)
    {
        send_to_char("You haven't sinned, why seek forgivness ??\n\r",ch);
        return;
    }
    if (IS_CLASS(ch, CLASS_TANARRI))
    {
        send_to_char("You cannot forgive a creature of utter evil.\n\r",ch);
        return;
    }
    if (victim->alignment < 0)
    {
        send_to_char("They are not ready to seek forgivness, first they must repent.\n\r",ch);
        return;
    }
    victim->hit += number_range(1000,1500);
    if (victim->hit > victim->max_hit) victim->hit = victim->max_hit;
    act("You feel the cleansing love of God run through your veins, filling you with an inner peace.", victim, NULL, NULL, TO_CHAR);
    act("$n is struck by a ray of pure light, and a blissful smile crosses $s lips.", victim, NULL, NULL, TO_ROOM);
    send_to_char("You forgive them, and thus God forgives them for their sins.\n\r",ch);
    WAIT_STATE(ch, 16);
    return;
}
const char*
StateMachineHelperTest::is_safe_test()
{
	struct vehicle_status_s current_state;
	struct safety_s safety;
	struct actuator_armed_s armed;

	armed.armed = false;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = false;
	mu_assert("is safe: not armed", is_safe(&current_state, &safety, &armed));

	armed.armed = false;
	armed.lockdown = true;
	safety.safety_switch_available = true;
	safety.safety_off = true;
	mu_assert("is safe: software lockdown", is_safe(&current_state, &safety, &armed));

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = true;
	mu_assert("not safe: safety off", !is_safe(&current_state, &safety, &armed));

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = false;
	mu_assert("is safe: safety off", is_safe(&current_state, &safety, &armed));

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = false;
	safety.safety_off = false;
	mu_assert("not safe: no safety switch", !is_safe(&current_state, &safety, &armed));

	return 0;
}
Esempio n. 9
0
void do_touchofgod(CHAR_DATA *ch, char *argument )
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];
    int dam;

    argument = one_argument( argument, arg );
    dam = number_range(100,200);

    if (IS_NPC(ch)) return;
    if (!IS_CLASS(ch, CLASS_ANGEL))
    {
        send_to_char("Huh?\n\r",ch);
        return;
    }
    if (ch->pcdata->powers[ANGEL_JUSTICE] < 4)
    {
        send_to_char("You cannot channel the will of God yet.\n\r",ch);
        return;
    }
    if ((victim = get_char_room(ch, arg)) == NULL)
    {
        send_to_char("They are not here.\n\r", ch);
        return;
    }
    if (IS_NPC(victim))
    {
        send_to_char("Not on mobiles.\n\r",ch);
        return;
    }
    if (is_safe(ch,victim)) return;
    if (victim == ch)
    {
        send_to_char("That doesn't seem like a good idea.\n\r",ch);
        return;
    }
    WAIT_STATE(ch, 18);
    hurt_person(ch, victim, dam);
    act("You grab $N by the forehead and channel God's justice into $S body.",ch,NULL,victim,TO_CHAR);
    act("$n grabs you by your forehead and sends a prayer to God, DAMN THAT HURT.",ch,NULL,victim,TO_VICT);
    act("$n grabs $N by the forehead and sends a prayer to God.",ch,NULL,victim,TO_NOTVICT);
    if (number_range(1,3) == 1)
    {
        if (victim->position == POS_FIGHTING) stop_fighting(victim,TRUE);
        act("$N screams in pain and drops to the ground as God's justice wrecks $S body.",ch,NULL,victim,TO_CHAR);
        act("AARGH!!! The pain is to much, you drop to the ground.",ch,NULL,victim,TO_VICT);
        act("$N screams in agony and falls to the ground.",ch,NULL,victim,TO_NOTVICT);
        victim->position = POS_STUNNED;
    }
    return;
}
bool StateMachineHelperTest::isSafeTest(void)
{
	struct vehicle_status_s current_state;
	struct safety_s safety;
	struct actuator_armed_s armed;

	armed.armed = false;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = false;
	ut_compare("is safe: not armed", is_safe(&current_state, &safety, &armed), true);

	armed.armed = false;
	armed.lockdown = true;
	safety.safety_switch_available = true;
	safety.safety_off = true;
	ut_compare("is safe: software lockdown", is_safe(&current_state, &safety, &armed), true);

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = true;
	ut_compare("not safe: safety off", is_safe(&current_state, &safety, &armed), false);

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = true;
	safety.safety_off = false;
	ut_compare("is safe: safety off", is_safe(&current_state, &safety, &armed), true);

	armed.armed = true;
	armed.lockdown = false;
	safety.safety_switch_available = false;
	safety.safety_off = false;
	ut_compare("not safe: no safety switch", is_safe(&current_state, &safety, &armed), false);

	return true;
}
Esempio n. 11
0
/*
** method: string http_encode(string m)
**   Encode with HTTP specification the given string
** arg: string m
**   The string to encode.
** returns:
**   The encoded string
*/
static void f_http_encode(INT32 args) 
{
  char *o, *out, *in;
  unsigned char *i;
  int unsafe = 0;
  int out_len, in_len;
  struct pike_string *ret;
  struct pike_string *src;

  if(Pike_sp[-1].type != T_STRING)
    SIMPLE_BAD_ARG_ERROR("Caudium.http_encode", 1, "string");
  src = Pike_sp[-1].u.string;
  if(src->size_shift) {
    Pike_error("Caudium.http_encode(): Only 8-bit strings allowed.\n");
  }

  in = src->str;
  in_len = src->len-1;
	
  /* count unsafe characters */
  for(i=in; *i; i++) if(!is_safe((int )*i)) unsafe++;

  /* no need to convert	*/
  if(unsafe == 0) {
    pop_n_elems(args-1);
    return;
  }
	
  out_len = in_len + (unsafe * 2) + 1;
  ret = begin_shared_string(out_len);
  out = ret->str;

  for(o=out, i=in; *i; i++) {
    if (!is_safe(*i)) {
      *o++ = '%';
      *o++ = hex_chars[*i >> 4];
      *o++ = hex_chars[*i & 15];
    } else *o++ = *i;
Esempio n. 12
0
int test(int max_dist, int ntowns)
{
	int nsafe = 0;
	int i;
	for (i = 0; i < ntowns; i += 1) {
		if (is_safe(i, max_dist, ntowns) == 0)
			nsafe += 1;
	}

	if (nsafe < ntowns)
		return -1;
	else
		return 0;
}
Esempio n. 13
0
void do_sinsofthepast( CHAR_DATA *ch, char *argument )
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];

    argument = one_argument( argument, arg );

    if (IS_NPC(ch)) return;
    if (!IS_CLASS(ch, CLASS_ANGEL))
    {
        send_to_char("Huh?\n\r",ch);
        return;
    }
    if (ch->pcdata->powers[ANGEL_JUSTICE] < 3)
    {
        send_to_char("Your not ready to punish the sinners.\n\r",ch);
        return;
    }
    if ((victim = get_char_room(ch, arg)) == NULL)
    {
        send_to_char("They are not here.\n\r", ch);
        return;
    }
    if (IS_NPC(victim))
    {
        send_to_char("Not on mobiles.\n\r",ch);
        return;
    }
    if (is_safe(ch,victim)) return;
    if (victim == ch)
    {
        send_to_char("That doesn't seem like a good idea.\n\r",ch);
        return;
    }
    if (IS_CLASS(victim, CLASS_ANGEL))
    {
        send_to_char("Angels are born without sin, they are perfect creatures.\n\r",ch);
        return;
    }
    send_to_char("#RYou burn them with the fires of hell!#n\n\r",ch);
    if (!IS_AFFECTED(victim, AFF_FLAMING)) SET_BIT(victim->affected_by, AFF_FLAMING);
    send_to_char("#LTheir body is wrecked by poison!#n\n\r",ch);
    if (!IS_AFFECTED(victim, AFF_POISON)) SET_BIT(victim->affected_by, AFF_POISON);
    send_to_char("#CGod's fury upon them for they have truly sinned!!!#n\n\r",ch);
    one_hit(ch,victim, gsn_wrathofgod,1);
    WAIT_STATE(ch,12);
    return;
}
Esempio n. 14
0
void	eight_queens_solver(int rows[8], int y)
{
  int x;
  
  x = 0;
  while (x < 8) {
    if (is_safe(rows, x, y)) {
      rows[y] = x;
      if (y == 7)
	g_count++;
      else
	eight_queens_solver(rows, y+1);
    }
    ++x;
  }
}
Esempio n. 15
0
static int
bfs()
{
	int i, j;
	int max_j = -2147483648;

	q.init();
	q.enqueue(st);

	while (!q.is_empty())
	{
		struct Point x = q.front();
		q.dequeue();
		
		for (i = 0; i < M; i++)
		{
			// next move
			int ny = x.u + mrow[i];
			int nx = x.v + mcol[i];

			if ((is_safe(ny, nx))
				&& board[ny][nx] == -1
				&& MAP[ny][nx] == '.')
			{
				board[ny][nx] = board[x.u][x.v] + 1;
				struct Point next;
				next.u = ny, next.v = nx;
				q.enqueue(next);
			}
		}
	}

	//print_board();
	for (i = 0; i < H; i++)
	{
		for (j = 0; j < W; j++)
		{
			if (MAP[i][j] == '.'
				&& board[i][j] == -1)
				return -1;
			max_j = max(max_j, board[i][j]);
		}
	}

	return max_j;
}
Esempio n. 16
0
void do_infernal(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *ich;
  CHAR_DATA *ich_next;

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_TANARRI) && !IS_CLASS(ch, CLASS_LICH))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (!IS_SET(ch->pcdata->powers[TANARRI_POWER], TANARRI_FLAMES) && IS_CLASS(ch, CLASS_TANARRI))
  {
    send_to_char("You don't have that power yet.\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[CON_LORE] < 2 && IS_CLASS(ch, CLASS_LICH))
  {
    send_to_char("You don't have that power yet.\n\r",ch);
    return;
  }
  if (ch->mana < 2000)
  {
    if (IS_CLASS(ch, CLASS_TANARRI)) send_to_char("You need more mana to summon the infernal flames of the abyss.\n\r",ch);
    else send_to_char("Not enough mana.\n\r",ch);
    return;
  }
  if (IS_CLASS(ch, CLASS_TANARRI)) send_to_char("You summon the infernal flames of the abyss.\n\r",ch);
  else send_to_char("You mutter an incantation and a fireball flies from your hands.\n\r",ch);
  ich_next = ch->in_room->people;
  ich = ich_next;
  while (ich_next != NULL)
  {  
    ich_next = ich->next_in_room;
    if (ich != ch)
    {  
      if (is_safe(ch,ich)) break;
      one_hit(ch,ich,gsn_fireball,1);
      one_hit(ch,ich,gsn_fireball,1);
    }  
    ich = ich_next;
  }  
  ch->mana -= 2000;
  WAIT_STATE(ch, 12);
  return;
}  
Esempio n. 17
0
/* ciut przerobione */
void found_prey( CHAR_DATA *ch, CHAR_DATA *victim )
{
	OBJ_DATA *weapon;
	char * target;

	if ( !victim )
	{
	bug( "Found_prey: null victim", 0 );
	return;
	}

	if ( !victim->in_room )
	{
		bug( "Found_prey: null victim->in_room", 0 );
		return;
	}

	if ( !can_see( ch, victim ) )
	return;

	if ( is_safe( ch, victim ) )
	return;

	stop_hunting( ch );

	if( (weapon = get_eq_char(ch, WEAR_WIELD)) != NULL )
	{
		if( (target = get_target_by_name(ch,victim)) == NULL)
		target = victim->name;

	if(weapon->value[0] == WEAPON_DAGGER && get_skill(ch, gsn_backstab) > 0)
	{
		do_function(ch, &do_backstab, target );
	}
		else if ( get_skill(ch, gsn_charge) > 0 && IS_WEAPON_STAT( weapon, WEAPON_TWO_HANDS ) && weapon->value[0] != WEAPON_WHIP && weapon->value[0] != WEAPON_SHORTSWORD && weapon->value[0] != WEAPON_DAGGER )
	{
		do_function(ch, &do_charge, target );
	}
	else
		multi_hit( ch, victim, TYPE_UNDEFINED );
	return;
	}

	multi_hit( ch, victim, TYPE_UNDEFINED );
	return;
}
Esempio n. 18
0
void do_wyrmroar(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *victim;
  char arg[MAX_INPUT_LENGTH];
  one_argument (argument, arg);

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_SKYBLADE))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[SKYBLADE_SKILLS] < 9)
  {
    send_to_char("You have not mastered the skills ability enough yet.\n\r",ch);
    return;
  }
  if (!TIME_UP(ch, TIMER_WYRM_ROAR))
  {
    send_to_char("Your throat is still sore from the last time.\n\r",ch);
    return;
  }
  if (( victim = get_char_room(ch, NULL, arg)) == NULL)
  {
    if (ch->fighting == NULL)
    {
    send_to_char("Yes release the roar of the wyrm, but at who?\n\r",ch);
    return;
    }
    else victim = ch->fighting;
  }
  if (victim == ch)
  {
    send_to_char("Quit that stupid ass.\n\r",ch);
    return;
  }
  if (is_safe(ch, victim)) return;
  SET_TIMER(ch, TIMER_WYRM_ROAR, 6);
  WAIT_STATE(victim, 18);
  act("$n roars with the power of the wyrm, stunning you in place.",ch,NULL,victim,TO_VICT);
  act("$n roars with the power of the wyrm, stunning $N in place.", ch, NULL, victim, TO_NOTVICT);
  act("You roar with the power of the wyrm, stunning $N in place.", ch, NULL, victim, TO_CHAR);
  return;
}
Esempio n. 19
0
void queen(int k)
{
	int col;
	for (col = 0; col < N; ++col) 
	{
		if (is_safe(col, k)) // 유망한가 ?
		{
			rows[k] = col;

			if (k == N - 1) // 기저사례
			{ 
				cnt++;
				return;
			}
			
			queen(k + 1);
		}
	}
}
rtsp_error_t rtsp_phdr_session(rtsp_header_t *header, const char *msg, int32_t msg_len, const char **endptr){
	const char *scan = NULL;
	const char *scan_end = NULL;
	const char *temp = NULL;
	const char *end = msg + msg_len;
	rtsp_error_t err = RTSP_E_FAILURE;

	if(!header || !msg || msg_len <= 0){
		return (RTSP_E_INVALID_ARG);
	}

	scan = msg;
	header->session.id = scan;
	while (scan < end && (isalnum(*scan) || is_safe(*scan)))
		scan++;

	header->session.id_len = scan-msg;
	if(header->session.id_len > 0)
		err = RTSP_E_SUCCESS;
	if(*scan == ';'){
		scan++;	
		scan_end = find_char(scan, end, '\r');
		err = is_strncasematch(scan, scan_end, "timeout", STATIC_STR_LEN("timeout"));
		if(err==RTSP_E_SUCCESS){
			scan+=STATIC_STR_LEN("timeout");
			if(*scan == '='){
				scan++;
				header->session.timeout = strtoul(scan,(char **)&temp,10);
				if(temp > (scan_end+1)){
					ERR_LOG("Parsing Session timeout Error - Check Logic");
					err = RTSP_E_FAILURE;
				} else {
					scan = temp;
				}
			}
		}
	} 
	if(endptr)
		*endptr = scan;
	return (err);

}
Esempio n. 21
0
bool solveKTUtil(int x,int y,int movei,int sol[N][N],int x_move[], int y_move[]){
    if(movei==N*N)
    {
        return true;
    }
    int next_x,next_y;
    int i;
    for(i=0;i<N;i++){
        next_x=x+x_move[i];
        next_y=y+y_move[i];
        if(is_safe(next_x,next_y,sol)){
            sol[next_x][next_y]=movei;
            if(solveKTUtil(next_x,next_y,movei+1,sol,x_move,y_move)== true){
                return true;
            }else
            sol[next_x][next_y]=-1;
        }
    }
    return false;
}
Esempio n. 22
0
bool spec_thief( CHAR_DATA *ch )
{
    CHAR_DATA * victim;
    CHAR_DATA *v_next;

    if ( ch->position != POS_STANDING )
    {
        return FALSE;
    }

    for ( victim = ch->in_room->people; victim != NULL; victim = v_next )
    {
        v_next = victim->next_in_room;

        if ( IS_NPC( victim )
             || is_safe( ch, victim, TRUE )
             || victim->level >= LEVEL_IMMORTAL
             || number_bits( 5 ) != 0
             || !can_see( ch, victim )
	     || money_count_copper( victim ) == 0 )
        {
            continue;
        }

        if ( IS_AWAKE( victim ) && number_range( 0, ch->level ) == 0 )
        {
            act( "Odkrywasz rêke $z w swojej kieszeni!", ch, NULL, victim, TO_VICT );
            act( "$N odkrywa rêke $z w swojej kieszeni!", ch, NULL, victim, TO_NOTVICT );
            return TRUE;
        }
        else
        {
            money_steal( ch, victim );
            return TRUE;
        }
    }

    return FALSE;
}
Esempio n. 23
0
/**
 * Recursive function that searches for solutions to the nqueens problem.
 */
void queens_helper(int rows[], int y, int *solution_count)
{
	int x;

	for (x=0; x < num_queens; ++x) 
	{
		if (is_safe(rows, x, y)) 
		{
			rows[y] = x;
			if (y == num_queens-1)
			{
					(*solution_count)++;
					if (display_flag)
						putboard(stdout, rows);
			}
			else
			{
				queens_helper(rows, y+1, solution_count);
			}
		}
	}
}
Esempio n. 24
0
void do_tornado(CHAR_DATA *ch, char *argument)
{  
  CHAR_DATA *ich;
  CHAR_DATA *ich_next;

  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_TANARRI))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (!IS_SET(ch->pcdata->powers[TANARRI_POWER], TANARRI_TORNADO))
  {
    send_to_char("You don't have that power yet.\n\r",ch);
    return;
  }
  if (ch->mana < 1500)
  {
    send_to_char("You need more mana to summon a storm.\n\r",ch);
    return;
  }
  send_to_char("You summon a supernatural storm.\n\r",ch);
  ich_next = ch->in_room->people;
  ich = ich_next;
  while (ich_next != NULL)
  {
    ich_next = ich->next_in_room;
    if (ich != ch && IS_AFFECTED(ich, AFF_FLYING))
    {
      if (is_safe(ch,ich)) break;
      one_hit(ch,ich,gsn_lightning,1);
      one_hit(ch,ich,gsn_lightning,1);
    }
    ich = ich_next;
  }
  ch->mana -= 1500;
  WAIT_STATE(ch, 12);
  return;
}
Esempio n. 25
0
void do_earthquake(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *ich;
  CHAR_DATA *ich_next;
  
  if (IS_NPC(ch)) return;
  if (!IS_CLASS(ch, CLASS_TANARRI))
  {
    send_to_char("Huh?\n\r",ch);
    return;
  }
  if (!IS_SET(ch->pcdata->powers[TANARRI_POWER], TANARRI_EARTHQUAKE))
  {
    send_to_char("You don't have that power yet.\n\r",ch);
    return;
  }
  if (ch->mana < 1000)
  {
    send_to_char("You need more mana to summon an earthquake.\n\r",ch);
    return;
  }
  send_to_char("You summon an earthquake.\n\r",ch);
  ich_next = ch->in_room->people;
  ich = ich_next;
  while (ich_next != NULL)
  {
    ich_next = ich->next_in_room;
    if (ich != ch && !IS_AFFECTED(ich, AFF_FLYING))
    {
      if (is_safe(ch,ich)) break;
      one_hit(ch,ich,32,1);
    }
    ich = ich_next;
  }
  ch->mana -= 1000;
  WAIT_STATE(ch, 12);
  return;
}
Esempio n. 26
0
static int 
bfs()
{
	q.init();
	q.enqueue(st);

	// mark visited
	visited[st.u][st.v] = 1;
	// depth of Maze
	DEP[st.u][st.v] = 0;

	while (!q.is_empty())
	{
		struct Point x = q.front();
		if (x.u == end.u && x.v == end.v) 
			break;
		q.dequeue();

		for (int i = 0; i < 4; i++)
		{
			int ny = x.u + dy[i];
			int nx = x.v + dx[i];
			if ((is_safe(ny, nx)) 
				&& !visited[ny][nx]
				&& MAP[ny][nx] == '.')
			{
				DEP[ny][nx] = DEP[x.u][x.v] + 1;
				struct Point next;
				next.u = ny, next.v = nx;
				q.enqueue(next);
			}
		}
	}

	return DEP[end.u][end.v];
}
Esempio n. 27
0
/*
 * Core procedure for dragons.
 */
bool dragon( CHAR_DATA *ch, int sn )
{
    CHAR_DATA *victim;

    if ( ch->position != POS_FIGHTING )
	return FALSE;

    for ( victim = ch->in_room->people; victim; victim = victim->next_in_room )
    {
	if ( victim->deleted )
	    continue;
	if ( is_safe( ch, victim, FALSE ) )
	    continue;
	if ( is_fighting( victim, ch ) && number_bits( 2 ) == 0 )
	    break;
    }

    if ( !victim )
	return FALSE;

    ( *skill_table[ sn ].spell_fun )( sn, SPELL_LEVEL( ch, ch->level ), ch, victim, USAGE_SPECIAL );

    return TRUE;
}
Esempio n. 28
0
bool check_social( CHAR_DATA * ch, const char *command, const char *argument )
{
   char arg[MAX_INPUT_LENGTH];
   CHAR_DATA *victim, *victim_next;
   SOCIALTYPE *social;
   CHAR_DATA *removed[128];   /* What are the chances of more than 128? */
   ROOM_INDEX_DATA *room;
   int i = 0, k = 0;

   if( ( social = find_social( command ) ) == NULL )
      return FALSE;

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

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

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

      case POS_STUNNED:
         send_to_char( "You are too stunned to do that.\r\n", 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->name, "snore" ) )
            break;
         send_to_char( "In your dreams, or what?\r\n", ch );
         return TRUE;
   }

   /*
    * Search room for chars ignoring social sender and 
    * remove them from the room until social has been  
    * completed              
    */
   room = ch->in_room;
   for( victim = ch->in_room->first_person; victim; victim = victim_next )
   {
      if( i == 127 )
         break;
      victim_next = victim->next_in_room;
      if( is_ignoring( victim, ch ) )
      {
         if( !IS_IMMORTAL( ch ) || get_trust( victim ) > get_trust( ch ) )
         {
            removed[i] = victim;
            i++;
            UNLINK( victim, room->first_person, room->last_person, next_in_room, prev_in_room );
         }
         else
         {
            set_char_color( AT_IGNORE, victim );
            ch_printf( victim, "You attempt to ignore %s," " but are unable to do so.\r\n", ch->name );
         }
      }
   }

   one_argument( argument, arg );
   victim = NULL;
   if( arg[0] == '\0' )
   {
      act( AT_SOCIAL, social->others_no_arg, ch, NULL, victim, TO_ROOM );
      act( AT_SOCIAL, social->char_no_arg, ch, NULL, victim, TO_CHAR );
   }
   else if( ( victim = get_char_room( ch, arg ) ) == NULL )
   {
      /*
       * If they aren't in the room, they may be in the list of 
       * people ignoring...                 
       */
      if( i != 0 )
      {
         for( k = 0, victim = removed[0]; k < i; k++, victim = removed[k] )
         {
            if( nifty_is_name( victim->name, arg ) || nifty_is_name_prefix( arg, victim->name ) )
            {
               set_char_color( AT_IGNORE, ch );
               ch_printf( ch, "%s is ignoring you.\r\n", victim->name );
               break;
            }
         }
      }

      if( !victim )
         send_to_char( "They aren't here.\r\n", ch );
   }
   else if( victim == ch )
   {
      act( AT_SOCIAL, social->others_auto, ch, NULL, victim, TO_ROOM );
      act( AT_SOCIAL, social->char_auto, ch, NULL, victim, TO_CHAR );
   }
   else
   {
      act( AT_SOCIAL, social->others_found, ch, NULL, victim, TO_NOTVICT );
      act( AT_SOCIAL, social->char_found, ch, NULL, victim, TO_CHAR );
      act( AT_SOCIAL, social->vict_found, ch, NULL, victim, TO_VICT );

      if( !IS_NPC( ch ) && IS_NPC( victim )
          && !IS_AFFECTED( victim, AFF_CHARM ) && IS_AWAKE( victim ) && !HAS_PROG( victim->pIndexData, ACT_PROG ) )
      {
         switch ( number_bits( 4 ) )
         {
            case 0:
               if( IS_EVIL( ch ) && !is_safe( victim, ch, TRUE ) )   /* was IS_EVIL(ch) ||.... didn't make sense to me - FB */
                     multi_hit( victim, ch, TYPE_UNDEFINED );
               else if( IS_NEUTRAL( ch ) )
               {
                  act( AT_ACTION, "$n slaps $N.", victim, NULL, ch, TO_NOTVICT );
                  act( AT_ACTION, "You slap $N.", victim, NULL, ch, TO_CHAR );
                  act( AT_ACTION, "$n slaps you.", victim, NULL, ch, TO_VICT );
               }
               else
               {
                  act( AT_ACTION, "$n acts like $N doesn't even exist.", victim, NULL, ch, TO_NOTVICT );
                  act( AT_ACTION, "You just ignore $N.", victim, NULL, ch, TO_CHAR );
                  act( AT_ACTION, "$n appears to be ignoring you.", victim, NULL, ch, TO_VICT );
               }
               break;

            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
               act( AT_SOCIAL, social->others_found, victim, NULL, ch, TO_NOTVICT );
               act( AT_SOCIAL, social->char_found, victim, NULL, ch, TO_CHAR );
               act( AT_SOCIAL, social->vict_found, victim, NULL, ch, TO_VICT );
               break;

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

   /*
    * Replace the chars in the ignoring list to the room 
    * note that the ordering of the players in the room  
    * might change                
    */
   if( i != 0 )
   {
      for( k = 0, victim = removed[0]; k < i; k++, victim = removed[k] )
      {
         LINK( victim, room->first_person, room->last_person, next_in_room, prev_in_room );
      }
   }

   return TRUE;
}
Esempio n. 29
0
void do_heavenlyrain(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *victim;
  char buf[MAX_STRING_LENGTH];
  char arg1[MAX_INPUT_LENGTH];
  int dam;

  argument = one_argument(argument, arg1);

  if (IS_NPC(ch)) return;

  if (!IS_CLASS(ch, CLASS_SKYBLADE))
  {
    stc("Huh?\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[SKYBLADE_MAGIC] < 3)
  {
    send_to_char("You haven't mastered that magic yet.\n\r",ch);
    return;
  }
  if (( victim = get_char_room(ch, NULL, arg1)) == NULL)
  {
    if (( victim = ch->fighting) == NULL)
    {
      send_to_char("Call heavenlyrain upon whom?\n\r",ch);
      return;
    }
    else victim = ch->fighting;
  }
  if (is_safe(ch, victim))
  {
    send_to_char("They are safe from such a hostile action.\n\r",ch);
    return;
  }
  if (ch->mana < 5000)
  {
    send_to_char("You do not have the 5000 mana required to call on the dragon.\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[SKYBLADE_MAGIC] >= 4) dam = number_range(5000, 7000);
  else dam = number_range(3000, 5000);
  if (!IS_NPC(victim) && victim->alignment == 1000) dam *= .5;
  if (IS_NPC(victim)) dam += victim->hit/10;
  xprintf(buf, "#CYou call upon a heavenly rain to harm your opponent!#W[%d]\n\r",dam);
  stc(buf,ch);
  xprintf(buf, "#C%s calls upon a heavenly rain to harm you!#W[%d]\n\r",ch->name,dam);
  stc(buf,victim);
  act("#C$n calls upon a heavenly rain to harm $N!#n\n\r",ch,NULL,victim,TO_NOTVICT);
  ch->mana -= 5000;
  if (number_range(1,4) == 4){
  if (ch->pcdata->powers[SKYBLADE_MAGIC] >= 4)
  ch->hit += dam;
  else
  ch->hit += dam/2;
  stc ("#LYour heavenly rain has healed you.#n\n\r",ch);}
  hurt_person(ch, victim, dam);
  if (victim->hit < -10) victim->hit = -10;
  WAIT_STATE(ch, 8);
  if (ch->fighting == NULL) ch->fighting = victim;
  return;
}
Esempio n. 30
0
void do_dragonx (CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *victim;
  char arg1[MAX_INPUT_LENGTH];
  char buf[MAX_STRING_LENGTH];
  int dam;

  argument = one_argument(argument, arg1);

  if (IS_NPC(ch)) return;

  if (!IS_CLASS(ch, CLASS_SKYBLADE))
  {
    stc("Huh?\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[SKYBLADE_SKILLS] < 8)
  {
    send_to_char("You haven't mastered that skill yet.\n\r",ch);
    return;
  }
  if (ch->pcdata->powers[SKYBLADE_DTIMER] != 10)
  {
    send_to_char("Your dragon power has not fully charged.\n\r",ch);
    return;
  }
  if (( victim = get_char_room(ch, NULL, arg1)) == NULL)
  {
    if (( victim = ch->fighting) == NULL)
    {
      send_to_char("Use the power of the dragon on whom?\n\r",ch);
      return;
    }
    else victim = ch->fighting;
  }
  if (is_safe(ch, victim))
  {
    send_to_char("They are safe from such a hostile action.\n\r",ch);
    return;
  }
  if (ch->mana < 10000)
  {
    send_to_char("You do not have the 10000 mana required to call on the dragon.\n\r",ch);
    return;
  }
  dam = victim->hit/3;
  if (IS_NPC(victim)) dam = victim->hit * .9;
  if (ch->pcdata->powers[SKYBLADE_MAGIC] >= 5) dam *= 1.5;
  if (IS_NPC(victim))
  {
    if (dam > 15000) dam = 5000 + (number_range(1,5) * number_range(1,7));
  }
  else
  {
    if (dam > 6000) dam = 6000 + (number_range(1,5) * number_range(1,7));
  }
  do_say(ch, "#LMighty dragon give me your POWER!!!!!!#n");
  act("#C$n #Lleaps high into the air.......#n\n\r",ch,NULL,victim,TO_ROOM);
  stc("#LYou leap high into the air!#n\n\r",ch);
  act("#0The #ylightning crackles#0 as a large dragon is seen in the horizon.#n\n\r",ch,NULL,victim,TO_ROOM);
  WAIT_STATE(ch, 6);
  WAIT_STATE(victim, 6);
  stc("#LYou charge down upon your victim riding a huge dragon!#n\n\r",ch);
  act("#C$n #0charges down upon you, riding a huge dragon!#n\n\r",ch,NULL,victim,TO_VICT);
  act("#C$n #0charges down upon $N, riding a huge dragon!#n\n\r",ch,NULL,victim,TO_NOTVICT);
  ch->mana -= 10000;
  ch->pcdata->powers[SKYBLADE_DTIMER] = 0;
  WAIT_STATE(ch, 12);
  WAIT_STATE(victim, 12);
  xprintf(buf, "#LYou return to the ground and your dragon fades away.#W[%d]\n\r",dam);
  stc(buf,ch);
  xprintf(buf, "#L%s returns to the ground and the dragon fades away.#W[%d]\n\r",ch->name,dam);
  stc(buf, victim);
  hurt_person(ch, victim, dam);
  WAIT_STATE(ch, 8);
  if (ch->fighting == NULL) ch->fighting = victim;
  return;
}