Hi,
I've being battling to find a way to replace entities in a map at map loading time. After numerous attempts I've run out of ideas. I've worked my way all the way back to G_SpawnEntitiesFromString() trying to figure it out, alas, no luck! Here's my latest (quick) attempt to load ammo_bfg entities as ammo_cells:
g_items.c:
void G_SpawnItem (gentity_t *ent, gitem_t *item) {
	G_SpawnFloat( "random", "0", &ent->random );
	G_SpawnFloat( "wait", "0", &ent->wait );
	RegisterItem( item );
	if ( G_ItemDisabled(item) )
		return;
	ent->item = item;
	if ( !strcmp(ent->item->classname, "ammo_bfg" ) ) {
		strcpy(ent->item->classname, "ammo_cells" );
		strcpy(ent->item->pickup_name, "Cells" );
		strcpy(ent->item->world_model[0], va("models/powerups/ammo/plasmaam.md3") );
	}
...
}
It makes absolutely no difference. What am I doing wrong?
			
			
									
						
										
						Map entities
Re: Map entities
Hi,
I am not surprised that you have problems. The whole spawn module has been designed by a person who must be nuts. It is unnecessarily convoluted and very hard to understand.
I suspect that the cause of your problem is that you do not modify the 'giType' and 'giTag' fields of the item structure. Try to set them like this:
Hope this works (I have not tried it, to be honest).
EDIT:
I may have found a better solution. You could try to modify the function 'G_CallSpawn' in 'g_spawn.c'. There is a 'for' loop in which the function tries to find the item with the given classname. I have added the code I think is needed:
In this way the fully initialized item structure of the plasma ammo is found and used, no need for any further hacking (I think).
			
			
									
						
										
						I am not surprised that you have problems. The whole spawn module has been designed by a person who must be nuts. It is unnecessarily convoluted and very hard to understand.
I suspect that the cause of your problem is that you do not modify the 'giType' and 'giTag' fields of the item structure. Try to set them like this:
Code: Select all
ent->item->giType = IT_AMMO;
ent->item->giTag = WP_PLASMAGUN;
EDIT:
I may have found a better solution. You could try to modify the function 'G_CallSpawn' in 'g_spawn.c'. There is a 'for' loop in which the function tries to find the item with the given classname. I have added the code I think is needed:
Code: Select all
//_SP added
  if (strcmp(ent->classname, "ammo_bfg") == 0)
    strcpy(ent->classname, "ammo_plasma");
//_SP
  // check item spawn functions
  for (item = bg_itemlist + 1; item->classname; item++)
  {
    if (!strcmp(item->classname, ent->classname))
    {
      G_SpawnItem(ent, item);
      return qtrue;
    }
  }