Exemple #1
0
void print(const char *str, int len, int row, int col) {
	if (valid_pos(row, col)) {
		int i;
		int pos = row * WIDTH + col;
		for (i = 0; i < len && valid_pos(ROW(pos), COL(pos)); i++, pos++)
			print_char(str[i], ROW(pos), COL(pos));
	}
}
Exemple #2
0
void CPhysicsShellHolder::correct_spawn_pos()
{
	VERIFY								(PPhysicsShell());
	
	if( H_Parent() )
	{
		CPhysicsShellHolder	* P = smart_cast<CPhysicsShellHolder*>(H_Parent());
		if( P && P->has_shell_collision_place(this) )
			return;
	}

	Fvector								size;
	Fvector								c;
	get_box								(PPhysicsShell(),XFORM(),size,c);

	R_ASSERT2( _valid( c ), make_string( "object: %s model: %s ", cName().c_str(), cNameVisual().c_str() ) );
	R_ASSERT2( _valid( size ), make_string( "object: %s model: %s ", cName().c_str(), cNameVisual().c_str() ) );
	R_ASSERT2( _valid( XFORM() ), make_string( "object: %s model: %s ", cName().c_str(), cNameVisual().c_str() ) );

	CPHActivationShape					activation_shape;
	activation_shape.Create				(c,size,this);
	activation_shape.set_rotation		(XFORM());
	PPhysicsShell()->DisableCollision	();
	activation_shape.Activate			(size,1,1.f,M_PI/8.f);
////	VERIFY								(valid_pos(activation_shape.Position(),phBoundaries));
//	if (!valid_pos(activation_shape.Position(),phBoundaries)) {
//		CPHActivationShape				activation_shape;
//		activation_shape.Create			(c,size,this);
//		activation_shape.set_rotation	(XFORM());
//		activation_shape.Activate		(size,1,1.f,M_PI/8.f);
////		VERIFY							(valid_pos(activation_shape.Position(),phBoundaries));
//	}
	
	PPhysicsShell()->EnableCollision	();

	Fvector								ap = activation_shape.Position();
#ifdef DEBUG
	if (!valid_pos(ap,phBoundaries)) {
		Msg("not valid position	%f,%f,%f",ap.x,ap.y,ap.z);
		Msg("size	%f,%f,%f",size.x,size.y,size.z);
		Msg("Object: %s",Name());
		Msg("Visual: %s",*(cNameVisual()));
		Msg("Object	pos	%f,%f,%f",Position().x,Position().y,Position().z);
	}
#endif // DEBUG
	VERIFY								(valid_pos(activation_shape.Position(),phBoundaries));
	
	Fmatrix								trans;
	trans.identity						();
	trans.c.sub							(ap,c);
	PPhysicsShell()->TransformPosition	(trans);
	PPhysicsShell()->GetGlobalTransformDynamic(&XFORM());
	activation_shape.Destroy			();
}
Exemple #3
0
void print_char(char c, int row, int col) {
	if (valid_pos(row, col)) {
		int position = (WIDTH*row + col)*2; /* duplica debido a los colores */
		video[position] = c;
		video[position+1] = color;
	}
}
void CActorMP::postprocess_packet	(net_update_A &N_A)
{

	if (!NET.empty())
		N_A.dwTimeStamp		= NET.back().dwTimeStamp;
	else
		N_A.dwTimeStamp		= Level().timeServer();

	N_A.State.previous_position	= N_A.State.position;
	N_A.State.previous_quaternion = N_A.State.quaternion;

	if (Local() && OnClient() || !g_Alive()) return;

	{
		//-----------------------------------------------
		if (!NET_A.empty() && N_A.dwTimeStamp < NET_A.back().dwTimeStamp) return;
		if (!NET_A.empty() && N_A.dwTimeStamp == NET_A.back().dwTimeStamp)
		{
			NET_A.back() = N_A;
		}
		else
		{
			VERIFY(valid_pos(N_A.State.position));
			NET_A.push_back			(N_A);
			if (NET_A.size()>5) NET_A.pop_front();
		};

		if (!NET_A.empty()) m_bInterpolate = true;
	};

	Level().AddObject_To_Objects4CrPr	(this);
	CrPr_SetActivated					(false);
	CrPr_SetActivationStep				(0);
}
Exemple #5
0
bool can_move(int r, int c, int dir)
{
    int r2 = r + dd[dir][0];
    int c2 = c + dd[dir][1];

    return valid_pos(r2, c2) && maze[r2][c2] == '0';
}
void remove_char_at( char* cstr, size_t pos ) // invariant: valid pos
{
    if( cstr != NULL )
    {
        assert( valid_pos( cstr, pos ) ) ; // nop if NDEBUG is defined
        for( ; cstr[pos] != 0 ; ++pos ) cstr[pos] = cstr[pos+1] ;
    }
}
Exemple #7
0
	/**
	* Reads a char form the array
	* @return The read char (between 0 and 255)
	*/
	unsigned char Storage::readChar() throw(std::invalid_argument)
	{
		if ( !valid_pos() )
		{
			throw std::invalid_argument("Storage::readChar(): invalid position");
		}
		return readCharUnsafe();
	}
Exemple #8
0
bool wall_right(int r, int c, int dir)
{
    int d2 = move_right(dir);
    int r2 = r + dd[d2][0];
    int c2 = c + dd[d2][1];

    return (!valid_pos(r2, c2)) || maze[r2][c2] == '1';
}
void CPhysicsShellHolder::correct_spawn_pos()
{
	VERIFY								(PPhysicsShell());

	Fvector								size;
	Fvector								c;
	get_box								(PPhysicsShell(),XFORM(),size,c);

	CPHActivationShape					activation_shape;
	activation_shape.Create				(c,size,this);
	activation_shape.set_rotation		(XFORM());
	PPhysicsShell()->DisableCollision	();
	activation_shape.Activate			(size,1,1.f,M_PI/8.f);
////	VERIFY								(valid_pos(activation_shape.Position(),phBoundaries));
//	if (!valid_pos(activation_shape.Position(),phBoundaries)) {
//		CPHActivationShape				activation_shape;
//		activation_shape.Create			(c,size,this);
//		activation_shape.set_rotation	(XFORM());
//		activation_shape.Activate		(size,1,1.f,M_PI/8.f);
////		VERIFY							(valid_pos(activation_shape.Position(),phBoundaries));
//	}

	PPhysicsShell()->EnableCollision	();

	Fvector								ap = activation_shape.Position();
#ifdef DEBUG
	if (!valid_pos(ap,phBoundaries)) {
		Msg("not valid position	%f,%f,%f",ap.x,ap.y,ap.z);
		Msg("size	%f,%f,%f",size.x,size.y,size.z);
		Msg("Object: %s",Name());
		Msg("Visual: %s",*(cNameVisual()));
		Msg("Object	pos	%f,%f,%f",Position().x,Position().y,Position().z);
	}
#endif // DEBUG
	VERIFY								(valid_pos(activation_shape.Position(),phBoundaries));
	
	Fmatrix								trans;
	trans.identity						();
	trans.c.sub							(ap,c);
	PPhysicsShell()->TransformPosition	(trans);
	PPhysicsShell()->GetGlobalTransformDynamic(&XFORM());
	activation_shape.Destroy			();
}
Exemple #10
0
void	phys_shell_verify_object_model( CObject& O )	
{
	IRenderVisual	*V = O.Visual();
	VERIFY2( V, make_string( "Can not create physics shell for object %s it has no model", O.cName().c_str() )+ make_string("\n object dump: \n") + dbg_object_full_dump_string( &O ) );
	IKinematics		*K = V->dcast_PKinematics();
	VERIFY2( K, make_string( "Can not create physics shell for object %s, model %s is not skeleton", O.cName().c_str(), O.cNameVisual().c_str() ) );
	VERIFY2( has_physics_collision_shapes( *K ), make_string( "Can not create physics shell for object %s, model %s has no physics collision shapes set", O.cName().c_str(), O.cNameVisual().c_str() )+ make_string("\n object dump: \n") + dbg_object_full_dump_string( &O )  );
	VERIFY2( _valid( O.XFORM() ), make_string( "create physics shell: object matrix is not valide" ) + make_string("\n object dump: \n") + dbg_object_full_dump_string( &O ) );
	VERIFY2(valid_pos( O.XFORM().c ),  dbg_valide_pos_string( O.XFORM().c, &O, "create physics shell" ) );
}
void CActorMP::net_Export	(NET_Packet &packet)
{
	if (OnClient())
	{
		//Msg("net_Export: ID is: 0x%08x, is going to send health %2.04f", this->ID(), m_state_holder.state().health);
		//R_ASSERT						(g_Alive());
		//R_ASSERT						(PHGetSyncItemsNumber() == 1);
	}
	R_ASSERT2(valid_pos(m_state_holder.state().position,phBoundaries), "trying to export bad position");
	m_state_holder.write			(packet);
}
Exemple #12
0
int solve()
{
    for (int i = 0; i < len; ++i)
        for (int j = 0; j < len; ++j) {
            int d = abs(k - i) + abs(k - j);

            if (d > k) grid[i][j] = ' ';
            else grid[i][j] = word[k - d];
        }

    for (int i = 0; i < len; ++i)
        for (int j = 0; j < len; ++j)
            dp[i][j][0] = grid[i][j] == word[0] ? 1 : 0;

    for (int x = 1; x <= k; ++x)
        for (int i = 0; i < len; ++i)
            for (int j = 0; j < len; ++j) {
                dp[i][j][x] = 0;

                for (int di = i - 1; di <= i + 1; ++di)
                    for (int dj = j - 1; dj <= j + 1; ++dj) {
                        if ((di == i && dj == j) ||
                            ! valid_pos(di, dj)) continue;
                        if (grid[i][j] == word[x]) {
                            dp[i][j][x] += dp[di][dj][x - 1];
                            dp[i][j][x] %= MOD;
                        }
                    }
            }

    int ans = 0;

    for (int i = 0; i < len; ++i)
        for (int j = 0; j < len; ++j) {
            i64 n = dp[i][j][k];

            if (n > 0) {
                n *= n;
                n %= MOD;
                ans += n;
                ans %= MOD;
            }
        }

    return ans;
}
void CSE_ActorMP::UPDATE_Read	(NET_Packet &packet)
{
    flags						= 0;
    m_u16NumItems				= 1;
    velocity.set				(0.f,0.f,0.f);

    if (get_health() <= 0)
    {
        actor_mp_state_holder	tmp_state_holder;
        tmp_state_holder.read	(packet);
        return;
    }
    m_state_holder.read			(packet);
    R_ASSERT2(valid_pos(m_state_holder.state().position,phBoundaries), "read bad position");

    m_AliveState.quaternion		= m_state_holder.state().physics_quaternion;
    m_AliveState.angular_vel	= m_state_holder.state().physics_angular_velocity;
    m_AliveState.linear_vel		= m_state_holder.state().physics_linear_velocity;
    m_AliveState.force			= m_state_holder.state().physics_force;
    m_AliveState.torque			= m_state_holder.state().physics_torque;
    m_AliveState.position		= m_state_holder.state().physics_position;

    o_Position					= m_state_holder.state().position;

    accel						= m_state_holder.state().logic_acceleration;

    o_model						= m_state_holder.state().model_yaw;
    o_torso.yaw					= m_state_holder.state().camera_yaw;
    o_torso.pitch				= m_state_holder.state().camera_pitch;
    o_torso.roll				= m_state_holder.state().camera_roll;

    timestamp					= m_state_holder.state().time;

    weapon						= m_state_holder.state().inventory_active_slot;
    mstate						= m_state_holder.state().body_state_flags;
    set_health					( m_state_holder.state().health );
    fRadiation					= m_state_holder.state().radiation;
    m_AliveState.enabled		= m_state_holder.state().physics_state_enabled;

    m_ready_to_update			= true;
    //Msg("* Client 0x%08x UPDATE_Read, health is: %2.04f", this->ID, m_state_holder.state().health);
}
Exemple #14
0
t_vector		find_next_valid_pos(t_tetrimos form, char **map, t_vector index)
{
	int size;

	size = get_sizeof_map(map);
	index.y++;
	while (index.x < size)
	{
		while (index.y < size)
		{
			if (valid_pos(map, form, index))
				return (index);
			index.y++;
		}
		index.y = 0;
		index.x++;
	}
	index.x = -1;
	return (index);
}
Exemple #15
0
void prepare()
{
	for (int i = 0; i < 64; ++i)
		for (int j = 0; j < 64; ++j)
			g[i][j] = INF;

	for (int i = 0; i < 8; ++i)
		for (int j = 0; j < 8; ++j) {
			g[Pos(i, j)][Pos(i, j)] = 0;

			for (int k = 0; k < 8; ++k) {
				int ti = i + moves[k][0];
				int tj = j + moves[k][1];
				if (! valid_pos(ti, tj)) continue;

				g[Pos(i, j)][Pos(ti, tj)] = 1;
			}

		}

	floyd_warshall();
}
void CActorMP::net_Import	( NET_Packet &P)
{
	net_update			N;

	m_state_holder.read	(P);
	R_ASSERT2(valid_pos(m_state_holder.state().position), "imported bad position");

	
	/*if (m_i_am_dead)
		return;*/

	if (OnClient())
	{
/*#ifdef DEBUG
		if (GetfHealth() != m_state_holder.state().health)
			Msg("net_Import: [%d][%s], is going to set health to %2.04f", this->ID(), Name(), m_state_holder.state().health);
#endif*/
		
		game_PlayerState* ps = Game().GetPlayerByGameID(this->object_id());
		float new_health = m_state_holder.state().health;
		if (GetfHealth() < new_health)
		{
			SetfHealth(new_health);
		} else
		{
			if (!ps || !ps->testFlag(GAME_PLAYER_FLAG_INVINCIBLE))
			{
				SetfHealth(new_health);
			}
		}
	}

	if (PPhysicsShell() != NULL)
	{
		return;
	}
	

	if (OnClient())
		SetfRadiation	(m_state_holder.state().radiation*100.0f);

	u16		ActiveSlot = m_state_holder.state().inventory_active_slot;

	if (OnClient() && (inventory().GetActiveSlot()!=ActiveSlot) )
	{
#ifdef DEBUG
		Msg("Client-SetActiveSlot[%d][%d]",ActiveSlot, Device.dwFrame);
#endif // #ifdef DEBUG
		inventory().SetActiveSlot(ActiveSlot);
	}

	N.mstate			= m_state_holder.state().body_state_flags;

	N.dwTimeStamp		= m_state_holder.state().time;
	N.p_pos				= m_state_holder.state().position;

	N.o_model			= m_state_holder.state().model_yaw;
	N.o_torso.yaw		= m_state_holder.state().camera_yaw;
	N.o_torso.pitch		= m_state_holder.state().camera_pitch;
	N.o_torso.roll		= m_state_holder.state().camera_roll;

	if (N.o_torso.roll > PI)
		N.o_torso.roll	-= PI_MUL_2;

	{
		if (Level().IsDemoPlay() || OnServer() || Remote())
		{
			unaffected_r_torso.yaw		= N.o_torso.yaw;
			unaffected_r_torso.pitch	= N.o_torso.pitch;
			unaffected_r_torso.roll		= N.o_torso.roll;

			cam_Active()->yaw	= -N.o_torso.yaw;
			cam_Active()->pitch = N.o_torso.pitch;
		};
	};

	//CSE_ALifeCreatureActor
	N.p_accel				= m_state_holder.state().logic_acceleration;

	process_packet			(N);

	net_update_A			N_A;
	m_States.clear			();

	N_A.State.enabled		= m_state_holder.state().physics_state_enabled;
	N_A.State.angular_vel	= m_state_holder.state().physics_angular_velocity;
	N_A.State.linear_vel	= m_state_holder.state().physics_linear_velocity;
	N_A.State.force			= m_state_holder.state().physics_force;
	N_A.State.torque		= m_state_holder.state().physics_torque;
	N_A.State.position		= m_state_holder.state().physics_position;
	N_A.State.quaternion	= m_state_holder.state().physics_quaternion;

	// interpolcation
	postprocess_packet		(N_A);
}
Exemple #17
0
/* have 2 lines passing around a point ie
 _ _ _ _ x _ _
 _ _ x x o _ _
 _ _ x x o _ _
 _ x o o x _ _
 _ o o x o x _

*/
int arrow_attack(Game_state* state, int player, Pair** rmap, int s) {
  /*
  given all other points are filled:

  1 2
  3 4

  have an arrow if:
   if no 3 but 2 and 4 - op places 3, we place 1
   if no 4 but 1 and 3 - op places 4, we place 2

  more generally, looking for a 3 with one blank.
  above the blank should be a blank (obv) with 3.
  must be diagonal.
  */
  int to_connect = state->num_to_connect;
  int lines = num_of_win_places(state->width, state->height, to_connect);
  int i, j, k, l;
  int t_x, t_y, b_x = -1, b_y = -1;
  
  for(i = 0; i < lines; i++) {
    /* not a diagonal, don't care */
    if(!is_diagonal(state, rmap, i))
      continue;

    /* make sure we've got 3 on the row w/ one blank */
    if(!state->score_array[player][i] == to_connect-1 && 
          state->score_array[other(player)][i] == 0)
      continue;

    /* get the blank x,y */
    for(j = 0; j < state->num_to_connect; j++) {
      t_x = rmap[i][j].x;
      t_y = rmap[i][j].y;
      if(state->board[t_x][t_y] == C4_NONE) {
        b_x = t_x;
        b_y = t_y;
        break;
      }
    }

    /* diagonal above blank */
    if(valid_pos(state, b_x, b_y+1)) {
      k = 0;
      while((l = state->map[b_x][b_y+1][k]) != -1) {
        if(is_diagonal(state, rmap, l) && 
            state->score_array[player][l] == to_connect-s &&
              state->score_array[other(player)][l] == 0) {
          return 1;
        }
        k++;
      }
    }

    /* diagonal below blank */
    if(valid_pos(state, b_x, b_y-1)) {
      k = 0;
      while((l = state->map[b_x][b_y-1][k]) != -1) {
        if(is_diagonal(state, rmap, l) && 
            state->score_array[player][l] == to_connect-s &&
              state->score_array[other(player)][l] == 0) {
          return 1;
        }
        k++;
      }
    }

    if(valid_pos(state, b_x-1, b_y-2)) {
      k = 0;
      while((l = state->map[b_x-1][b_y-2][k]) != -1) {
        if(is_diagonal(state, rmap, l) && 
            state->score_array[player][l] == to_connect-s &&
              state->score_array[other(player)][l] == 0) {
          return 1;
        }
        k++;
      }
    }
  }
  return 0;
}
Exemple #18
0
bool valid_pos( const Fvector &P )
{
	return valid_pos( P, phBoundaries );
}
Exemple #19
0
/* return 1 if a three attack 
can occur on horizon OR diagonal lines.*/
int three_attack(Game_state* state, int player, Pair** rmap) {
  int i, j, t_x, t_y;
  int h_left, h_right, v_upper, v_lower;
  int to_connect = state->num_to_connect;
  int lines = num_of_win_places(state->width, state->height, to_connect);

  for(i = 0; i < lines; i++) {
    /* does opponent have n-1 in a row on a line ? */
    if(!state->score_array[player][i] == to_connect-1)
      continue;

    /* are those n-1 contiguous in a row? */
    if(!has_n_in_row(state, rmap, player, i, to_connect-1))
      continue;
    
    v_upper = v_lower = h_left = h_right = 0;

    /* is there a blank either side, two on one side? vulnerable! */
    if(is_diagonal(state, rmap, i)) {
      for(j = 0; j < state->num_to_connect; j++) {
        t_x = rmap[i][j].x;
        t_y = rmap[i][j].y;
        /* upper right vertical */
        if(valid_pos(state, t_x+1, t_y+1) && blank(state, t_x+1, t_y+1))
          v_upper = 1;
        /* upper left vertical */
        if(valid_pos(state, t_x-1, t_y+1) && blank(state, t_x-1, t_y+1))
          v_upper = 1;
        /* lower right vertical */
        if(valid_pos(state, t_x+1, t_y-1) && blank(state, t_x+1, t_y-1))
          v_lower = 1;
        /* lower left vertical */
        if(valid_pos(state, t_x-1, t_y-1) && blank(state, t_x-1, t_y-1))
          v_lower = 1;

        if(v_upper && v_lower)
          return 1;
      }
    } else { 
      for(j = 0; j < state->num_to_connect; j++) {
        t_x = rmap[i][j].x;
        t_y = rmap[i][j].y;

        /* check as we go for horizontal 3-attack */
        if(state->board[t_x][t_y] == player) {
          /* left (horizontal) side is blank */
          if(valid_pos(state, t_x-1, t_y) && blank(state, t_x-1, t_y)) {
            h_left = 1;
          }
          /* right (horizontal) side is blank */
          if(valid_pos(state, t_x+1, t_y) && blank(state, t_x+1, t_y)) {
            h_right = 1;
          }
        }
        if(h_left && h_right)
          return 1;
      }
    }
  }
  /* if both blank conditions are not met, not three attack */
  return 0;
}