Exemplo n.º 1
0
    relation_union_fn * sieve_relation_plugin::mk_union_fn(const relation_base & tgt, const relation_base & src, 
            const relation_base * delta) {
        if(&tgt.get_plugin()!=this && &src.get_plugin()!=this && (delta && &delta->get_plugin()!=this)) {
            //we create the operation only if it involves this plugin
            return 0;
        }

        bool tgt_sieved = tgt.get_plugin().is_sieve_relation();
        bool src_sieved = src.get_plugin().is_sieve_relation();
        bool delta_sieved = delta && delta->get_plugin().is_sieve_relation();
        const sieve_relation * stgt = tgt_sieved ? static_cast<const sieve_relation *>(&tgt) : 0;
        const sieve_relation * ssrc = src_sieved ? static_cast<const sieve_relation *>(&src) : 0;
        const sieve_relation * sdelta = delta_sieved ? static_cast<const sieve_relation *>(delta) : 0;
        const relation_base & itgt = tgt_sieved ? stgt->get_inner() : tgt;
        const relation_base & isrc = src_sieved ? ssrc->get_inner() : src;
        const relation_base * idelta = delta_sieved ? &sdelta->get_inner() : delta;

        //Now we require that the sieved and inner columns must match on all relations.
        //We may want to allow for some cases of misalignment even though it could introcude imprecision
        if( tgt_sieved && src_sieved && (!delta || delta_sieved) ) {
            if( !vectors_equal(stgt->m_inner_cols, ssrc->m_inner_cols)
                || (delta && !vectors_equal(stgt->m_inner_cols, sdelta->m_inner_cols)) ) {
                return 0;
            }
        }
        else {
            if( (stgt && !stgt->no_sieved_columns()) 
                  || (ssrc && !ssrc->no_sieved_columns())
                  || (sdelta && !sdelta->no_sieved_columns()) ) {
                //We have an unsieved relation and then some relation with some sieved columns,
                //which means there is an misalignment.
                return 0;
            }
        }

        relation_union_fn * union_fun = get_manager().mk_union_fn(itgt, isrc, idelta);
        if(!union_fun) {
            return 0;
        }

        return alloc(union_fn, union_fun);
    }
Exemplo n.º 2
0
    bool table_base::contains_fact(const table_fact & f) const {
        iterator it = begin();
        iterator iend = end();

        table_fact row;

        for(; it!=iend; ++it) {
            it->get_fact(row);
            if(vectors_equal(row, f)) {
                return true;
            }
        }
        return false;
    }
Exemplo n.º 3
0
/*
 * detect_and_handle_collisions
 *
 * Polls all of the players to determine whether they have arrived at their
 * location yet. If they have then it throws an event to the player so that the
 * AI can handle.
 *
 * Parameters: automaton - Required to have access to the events.
 *             teams - All the players.
 *             players_per_team - Numbers of players in each team.
 *             ms_per_frame - Used to find how far each player will travel in
 *                            the next frame.
 */
void detect_players_arrived_at_location(AUTOMATON *automaton,
                                        TEAM **teams,
                                        int players_per_team,
                                        Uint32 ms_per_frame)
{
  /*
   * Local Variables.
   */
  PLAYER *player;
  float dist_per_frame;
  float s_per_frame = ((float) ms_per_frame) / MILLISECONDS_PER_SECOND;
  int ii;
  int jj;

  for (ii = 0; ii < players_per_team; ii++)
  {
    for (jj = 0; jj < 2; jj++)
    {
      player = teams[jj]->players[ii];

      if (vectors_equal(&(player->position), &(player->desired_position)))
      {
        /*
         * Calculate the distance that the player travels per update based on
         * their current speed.
         */
        dist_per_frame = s_per_frame *
            (player->current_speed_percent / 100.0f) * player->max_speed;

        /*
         * If the player is within one frame of reaching the desired position
         * then throw a new event to inform the ai and let it decide what to do
         * next.
         *
         * TODO: If the AI doesn't handle an arrived at desired position event
         * then it could get thrown multiple times. How should this be handled?
         */
        if (dist_between_vectors_2d(&(player->desired_position),
                                    &(player->position)) < dist_per_frame)
        {
          throw_single_player_ai_event_by_name(player,
                                       automaton,
                                       AUTOMATON_EVENT_ARRIVED_AT_LOCATION);
        }
      }
    }
  }
}