CleverRaven/Cataclysm-DDA — pull request #7646 by BevapDin (2014-05-15 09:58:35+00:00)
Title: Fix artifact creation

Added a search for the item type in `itypes` in `Item_factory::find_template` so it can find the newly created artifact type. New artifact types are only inserted in `itypes` as of now. Therefor the new artifact types could not be found and no new artifact items could be instantiated.

This fixes #7643

Note: Loading artifact types from disk happens before the other item types get loaded and the artifact types are put in `itypes` during that step. But than `Item_factory::init_old` adds the content of `itypes` to the `Item_factory`, so old artifacts should already be loaded just fine.

----

Semi-related request for comment:

I might be totally blind and inconsiderate, but I see no need to pass the artifact type property through the item class to `Item_factory`. It's a property of the type, not of the item. It also makes the function name `find_template` incorrect, currently `find_template_or_create_artifact` would be more accurate. And this kind of defeats the purpose of a find-existing-something function. Creating a pseudo item type in case the requested type id was not found is fine, its only purpose is to avoid returning `NULL`.

I think it would be better to create the artifact type separately in `map::spawn_artifact`/`mdeath::amigara` (where it currently instantiates an item of type "artifact") and uses the id of the new artifact to create the item:

```
item art( new_artifact()->id, calendar::turn );
// instead of:
item art("artifact", calendar::turn);
```

```
void map::spawn_artifact(const int x, const int y, artifact_natural_property prop)
const itype *type;
if( prop ) {
type = new_natural_artifact( prop );
} else {
type = new_artifact();
}
item newart( type->id, 0, true );
// instead of:
item newart("artifact", 0, true, prop);
```
Or even better: make two `spawn_artifact` functions, with and without the `prop` parameter to avoid the if clause.