Exemple #1
0
Fichier : tech.c Projet : s0be/naev
/**
 * @Brief Removes a tech item.
 */
int tech_rmItem( const char *name, const char *value )
{
   int id, i, s;
   tech_group_t *tech;
   char *buf;

   /* Get ID. */
   id = tech_getID( name);
   if (id < 0) {
      WARN("Trying to remove item '%s' to non-existant tech '%s'.", value, name );
      return -1;
   }

   /* Comfort. */
   tech  = &tech_groups[id];

   /* Iterate over to find it. */
   s = array_size( tech->items );
   for (i=0; i<s; i++) {
      buf = tech_getItemName( &tech->items[i] );
      if (strcmp(buf, value)==0) {
         array_erase( &tech->items, &tech->items[i], &tech->items[i+1] );
         return 0;
      }
   }

   WARN("Item '%s' not found in tech group '%s'", value, name );
   return -1;
}
Exemple #2
0
/**
 * @brief Sets the weapon set as sane.
 *
 *    @param p Pilot to set weapons as sane.
 */
void pilot_weaponSane( Pilot *p )
{
   int i, j;
   int n, l;
   PilotWeaponSet *ws;

   for (j=0; j<PILOT_WEAPON_SETS; j++) {
      ws = &p->weapon_sets[j];
      if (ws->slots == NULL)
         continue;

      l = array_size(ws->slots);
      n = 0;
      for (i=0; i<l; i++) {
         if (ws->slots[i].slot->outfit != NULL)
            continue;

         /* Move down. */
         memmove( &ws->slots[i], &ws->slots[i+1], sizeof(PilotWeaponSetOutfit) * (l-i-1) );
         n++;
      }
      /* Remove surplus. */
      if (n > 0)
         array_erase( &ws->slots, &ws->slots[l-n], &ws->slots[l] );

      /* See if we must overwrite levels. */
      if ((ws->type == WEAPSET_TYPE_WEAPON) ||
            (ws->type == WEAPSET_TYPE_ACTIVE))
         for (i=0; i<array_size(ws->slots); i++)
            ws->slots[i].level = 0;
   }

   /* Update range. */
   pilot_weapSetUpdateRange( ws );
}
Exemple #3
0
/**
 * @brief Destroys an OSD.
 *
 *    @param osd ID of the OSD to destroy.
 */
int osd_destroy( unsigned int osd )
{
   int i;
   OSD_t *ll;

   for (i=0; i<array_size( osd_list ); i++) {
      ll = &osd_list[i];
      if (ll->id != osd)
         continue;

      /* Clean up. */
      osd_free( &osd_list[i] );

      /* Remove. */
      array_erase( &osd_list, &osd_list[i], &osd_list[i+1] );

      /* Recalculate dimensions. */
      osd_calcDimensions();

      /* Remove the OSD, if empty. */
      if (array_size(osd_list) == 0)
         osd_exit();

      /* Done here. */
      return 0;
   }

   WARN("OSD '%u' not found to destroy.", osd );
   return 0;
}
Exemple #4
0
/**
 * @brief Removes a slot from a weapon set.
 *
 *    @param p Pilot who owns the weapon set.
 *    @param id ID of the weapon set.
 *    @param o Outfit to remove.
 */
void pilot_weapSetRm( Pilot* p, int id, PilotOutfitSlot *o )
{
   PilotWeaponSet *ws;
   int i;

   /* Make sure it has slots. */
   ws = pilot_weapSet(p,id);
   if (ws->slots == NULL)
      return;

   /* Find the slot. */
   for (i=0; i<array_size(ws->slots); i++) {
      if (ws->slots[i].slot != o)
         continue;

      array_erase( &ws->slots, &ws->slots[i], &ws->slots[i+1] );

      /* Update range. */
      pilot_weapSetUpdateRange( ws );

      /* Update if needed. */
      if (id == p->active_set)
         pilot_weapSetUpdateOutfits( p, ws );
      return;
   }
}
Exemple #5
0
static int
blast_client_process_ack(blast_client_t* client, uint32_t* seq, tick_t timestamp) {
	int ipend, psize;
	int iack, asize;
	for (iack = 0, asize = PACKET_ACK_COUNT; iack < asize; ++iack) {
		for (ipend = 0, psize = array_size(client->pending); ipend < psize; ++ipend) {
			if (client->pending[ipend].seq == seq[iack]) {
				array_erase(client->pending, ipend);
				break;
			}
		}
	}
	FOUNDATION_UNUSED(timestamp);

	/*log_infof( HASH_BLAST, "ACK processed, %d pending packets remaining (ack seq %d)", array_size( client->pending ), seq[0] );
	if( array_size( client->pending ) )
	{
		char* buf = 0;
		for( ipend = 0, psize = array_size( client->pending ); ipend < psize; ++ipend )
		{
			buf = string_append( buf, string_from_uint_static( client->pending[ipend].seq, false, 0, 0 ) );
			buf = string_append( buf, " " );
		}
		log_infof( HASH_BLAST, "  %s", buf );
		string_deallocate( buf );
	}*/

	return 0;
}
Exemple #6
0
/**
 * @brief Approaches a mission giver guy.
 *
 *    @brief Returns 1 on destroyed, 0 on not destroyed.
 */
static int npc_approach_giver( NPC_t *npc )
{
   int i;
   int ret;
   Mission *misn;

   /* Make sure player can accept the mission. */
   for (i=0; i<MISSION_MAX; i++)
      if (player_missions[i].data == NULL)
         break;
   if (i >= MISSION_MAX) {
      dialogue_alert("You have too many active missions.");
      return -1;
   }

   /* Get mission. */
   misn = &npc->u.g;
   ret  = mission_accept( misn );
   if ((ret==0) || (ret==2) || (ret==-1)) { /* success in accepting the mission */
      if (ret==-1)
         mission_cleanup( misn );
      npc_free( npc );
      array_erase( &npc_array, &npc[0], &npc[1] );
      ret = 1;
   }
   else
      ret  = 0;

   return ret;
}
Exemple #7
0
/**
 * @brief Removes all the pilot global hooks.
 */
void pilots_clearGlobalHooks (void)
{
   /* Must exist pilot hook.s */
   if (pilot_globalHooks == NULL )
      return;

   array_erase( &pilot_globalHooks, pilot_globalHooks, &pilot_globalHooks[ array_size(pilot_globalHooks)-1 ] );
}
Exemple #8
0
/**
 * @brief Removes an npc from the spaceport bar.
 */
static int npc_rm( NPC_t *npc )
{
   npc_free(npc);

   array_erase( &npc_array, &npc[0], &npc[1] );

   return 0;
}
Exemple #9
0
/**
 * @brief Clears the current markers.
 */
void ovr_mrkClear (void)
{
   int i;
   if (ovr_markers == NULL)
      return;
   for (i=0; i<array_size(ovr_markers); i++)
      ovr_mrkCleanup( &ovr_markers[i] );
   array_erase( &ovr_markers, ovr_markers, &ovr_markers[ array_size(ovr_markers) ] );
}
Exemple #10
0
/**
 * @brief Clears the pilots weapon settings.
 *
 *    @param p Pilot whose weapons we're clearing.
 */
void pilot_weaponClear( Pilot *p )
{
   int i;
   PilotWeaponSet *ws;

   for (i=0; i<PILOT_WEAPON_SETS; i++) {
      ws = pilot_weapSet( p, i );
      if (ws->slots != NULL)
         array_erase( &ws->slots, &ws->slots[0], &ws->slots[ array_size(ws->slots) ] );
   }
}
Exemple #11
0
/**
 * @brief Removes an overlay message.
 *
 *    @param id ID of the message to remove.
 */
void omsg_rm( unsigned int id )
{
   omsg_t *omsg;

   omsg = omsg_get(id);
   if (omsg == NULL)
      return;

   /* Destroy. */
   omsg_free( omsg );
   array_erase( &omsg_array, &omsg[0], &omsg[1] );
}
Exemple #12
0
/**
 * @brief Removes a marker by id.
 *
 *    @param id ID of the marker to remove.
 */
void ovr_mrkRm( unsigned int id )
{
   int i;
   if (ovr_markers == NULL)
      return;
   for (i=0; i<array_size(ovr_markers); i++) {
      if (id!=ovr_markers[i].id)
         continue;
      ovr_mrkCleanup( &ovr_markers[i] );
      array_erase( &ovr_markers, &ovr_markers[i], &ovr_markers[i+1] );
      break;
   }
}
Exemple #13
0
void make_random_number(int res[])
{
    int num[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    int num_range = NUM_SIZE;
    int i;
    int pos;
    int j;
    for(i = 0; i < 3; i++){
        srand((unsigned)time(NULL));
        pos = rand() % num_range;
        res[i] = num[pos];
        array_erase(num, pos);
        num_range--;
    }
}
Exemple #14
0
/**
 * @brief Removes a pilot global hook.
 */
void pilots_rmGlobalHook( unsigned int hook )
{
   int i;

   /* Must exist pilot hook.s */
   if (pilot_globalHooks == NULL )
      return;

   for (i=0; i<array_size(pilot_globalHooks); i++) {
      if (pilot_globalHooks[i].id == hook) {
         array_erase( &pilot_globalHooks, &pilot_globalHooks[i], &pilot_globalHooks[i+1] );
         return;
      }
   }
}
Exemple #15
0
void*
hashmap_erase(hashmap_t* map, hash_t key) {
	/*lint --e{613} */
	size_t ibucket = GET_BUCKET(map, key);
	hashmap_node_t* bucket = map->bucket[ibucket];
	size_t inode, nsize;
	for (inode = 0, nsize = array_size(bucket); inode < nsize; ++inode) {
		if (bucket[inode].key == key) {
			void* prev = bucket[inode].value;
			array_erase(map->bucket[ibucket], inode);
			--map->num_nodes;
			return prev;
		}
	}
	return 0;
}
Exemple #16
0
/**
 * @brief Renders the overlays.
 */
void omsg_render( double dt )
{
   int i, j;
   double x, y;
   omsg_t *omsg;
   glFont *font;
   glColour col;

   /* Case nothing to do. */
   if (omsg_array == NULL)
      return;

   /* Center. */
   x  = omsg_center_x - omsg_center_w/2.;
   y  = omsg_center_y;

   /* Render. */
   for (i=0; i<array_size(omsg_array); i++) {
      omsg  = &omsg_array[i];

      /* Check if time to erase. */
      omsg->duration -= dt;
      if (omsg->duration < 0.) {
         omsg_free( omsg );
         array_erase( &omsg_array, &omsg[0], &omsg[1] );
         i--;
         continue;
      }

      /* Must have a message. */
      if (omsg->msg == NULL)
         continue;

      /* Render. */
      font = omsg_getFont( omsg->font );
      memcpy( &col, omsg->col, sizeof(glColour) );
      if (omsg->duration < 1.)
         col.a = omsg->duration;
      for (j=0; j<omsg->nlines; j++) {
         y -= font->h * 1.5;
         if (j>0)
            gl_printRestoreLast();
         gl_printMidRaw( font, omsg_center_w, x, y, &col, omsg->msg[j] );
      }
   }
}
void* hashmap_erase( hashmap_t* map, hash_t key )
{
	unsigned int ibucket = key % map->num_buckets;
	hashmap_bucket_t bucket = map->bucket[ibucket];
	unsigned int inode, nsize;
	for( inode = 0, nsize = array_size( bucket ); inode < nsize; ++inode )
	{
		if( bucket[inode].key == key )
		{
			void* prev = bucket[inode].value;
			array_erase( map->bucket[ibucket], inode );
			--map->num_nodes;
			return prev;
		}
	}
	return 0;
}
Exemple #18
0
/**
 * @brief Clears a background image array.
 *
 *    @param arr Array to clear.
 */
static void background_clearImgArr( background_image_t **arr )
{
   int i;
   background_image_t *bkg;

   /* Must have an image array created. */
   if (*arr == NULL)
      return;

   for (i=0; i<array_size(*arr); i++) {
      bkg = &((*arr)[i]);
      gl_freeTexture( bkg->image );
   }

   /* Erase it all. */
   array_erase( arr, &(*arr)[0], &(*arr)[ array_size(*arr) ] );
}
Exemple #19
0
/**
 * @brief Removes an item from a tech.
 */
int tech_rmItemTech( tech_group_t *tech, const char *value )
{
   int i, s;
   char *buf;

   /* Iterate over to find it. */
   s = array_size( tech->items );
   for (i=0; i<s; i++) {
      buf = tech_getItemName( &tech->items[i] );
      if (strcmp(buf, value)==0) {
         array_erase( &tech->items, &tech->items[i], &tech->items[i+1] );
         return 0;
      }
   }

   WARN("Item '%s' not found in tech group", value );
   return -1;
}
Exemple #20
0
/**
 * @brief Removes a mission system marker.
 *
 * @usage misn.markerRm( my_marker )
 *
 *    @luaparam id ID of the marker to remove.
 * @luafunc markerRm( id )
 */
static int misn_markerRm( lua_State *L )
{
   int id;
   int i, n;
   MissionMarker *marker;
   Mission *cur_mission;

   /* Handle parameters. */
   id    = luaL_checkinteger( L, 1 );

   cur_mission = misn_getFromLua(L);

   /* Mission must have markers. */
   if (cur_mission->markers == NULL) {
      /* Already removed. */
      return 0;
   }

   /* Check id. */
   marker = NULL;
   n = array_size( cur_mission->markers );
   for (i=0; i<n; i++) {
      if (id == cur_mission->markers[i].id) {
         marker = &cur_mission->markers[i];
         break;
      }
   }
   if (marker == NULL) {
      /* Already removed. */
      return 0;
   }

   /* Remove the marker. */
   array_erase( &cur_mission->markers, marker, &marker[1] );

   /* Update system markers. */
   mission_sysMark();
   return 0;
}
Exemple #21
0
/**
 * @brief Removes slots by type from the weapon set.
 */
void pilot_weapSetRmSlot( Pilot *p, int id, OutfitSlotType type )
{
   int i, n, l;
   PilotWeaponSet *ws;

   /* We must clean up the slots. */
   n  = 0; /* Number to remove. */
   ws = pilot_weapSet(p,id);
   if (ws->slots == NULL)
      return;
   l  = array_size(ws->slots);
   for (i=0; i<l; i++) {
      if (ws->slots->slot->sslot->slot.type != type)
         continue;

      /* Move down. */
      memmove( &ws->slots[i], &ws->slots[i+1], sizeof(PilotWeaponSetOutfit) * (l-i-1) );
      n++;
   }

   /* Remove surplus. */
   array_erase( &ws->slots, &ws->slots[l-n], &ws->slots[l] );
}
Exemple #22
0
static void removePlugin(PluginData* pluginData) {
    // Remove the plugin data

    for (int i = 0; i < PRODBG_PLUGIN_COUNT; ++i) {
        int count = array_size(s_plugins[i]);

        for (int t = 0; t < count; ++t) {
            PluginData* plugin = s_plugins[i][t];

            if (pluginData != plugin)
                continue;

            printf("removed plugin %s\n", plugin->fullFilename);

            library_unload(plugin->lib);
            free((void*)plugin->fullFilename);
            free(plugin);
            array_erase(s_plugins[i], t);

            return;
        }
    }
}
Exemple #23
0
/**
 * @brief Removes a slot from a weapon set.
 *
 *    @param p Pilot who owns the weapon set.
 *    @param id ID of the weapon set.
 *    @param o Outfit to remove.
 */
void pilot_weapSetRm( Pilot* p, int id, PilotOutfitSlot *o )
{
   PilotWeaponSet *ws;
   int i, j;

   /* Make sure it has slots. */
   ws = pilot_weapSet(p,id);
   if (ws->slots == NULL)
      return;

   /* Find the slot. */
   for (i=0; i<array_size(ws->slots); i++) {
      if (ws->slots[i].slot != o)
         continue;

      array_erase( &ws->slots, &ws->slots[i], &ws->slots[i+1] );

      /* Update range. */
      pilot_weapSetUpdateRange( ws );

      /* Update if needed. */
      if (id == p->active_set)
         pilot_weapSetUpdateOutfits( p, ws );

      /* Updated cached weapset. */
      o->weapset = -1;
      for (j=0; j<PILOT_WEAPON_SETS; j++) {
         if (pilot_weapSetCheck(p, j, o) != -1) {
            o->weapset = j;
            break;
         }
      }

      return;
   }
}
Exemple #24
0
void test_array(void)
{
  int i;
  double* d;
  void* A = array_create(0);
  fprintf(stdout, "call function : %s\n", __func__);
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_push_back ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_pop_back ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_pop_back(A);
    fprintf(stdout, "  the pop element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_erase ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_erase(A, array_begin(A));
    fprintf(stdout, "  the erased begin element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);
    d = (double*)array_erase(A, array_end(A));
    fprintf(stdout, "  the erased end element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_remove ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_remove(A, 3);
    fprintf(stdout, "  the removed [3] -> {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_copy ===>\n");
  {
    void* copy_A;
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    copy_A = array_copy(A, 10);
    array_object_show(copy_A);
    array_for_each(copy_A, array_element_display, NULL);
    array_release(&copy_A);

    array_for_each(A, array_element_destroy, NULL);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_resize ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_resize(A, 20);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_release ===>\n");
  array_release(&A);
  array_object_show(A);
}