]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/spawn.qc
Merge branch 'master' into Mario/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / spawn.qc
1 entity spawnmonster (string monster, float monster_id, entity spawnedby, entity own, vector orig, float respwn, float invincible, float moveflag)
2 {
3         // ensure spawnfunc database is initialized
4         //initialize_field_db();
5
6         entity e = spawn();
7         float i;
8
9         e.spawnflags = MONSTERFLAG_SPAWNED;
10
11         if(!respwn)
12                 e.spawnflags |= MONSTERFLAG_NORESPAWN;
13
14         if(invincible)
15                 e.spawnflags |= MONSTERFLAG_INVINCIBLE;
16
17         setorigin(e, orig);
18
19         if(monster == "random")
20         {
21                 RandomSelection_Init();
22                 for(i = MON_FIRST; i <= MON_LAST; ++i)
23                         RandomSelection_Add(world, 0, (get_monsterinfo(i)).netname, 1, 1);
24
25                 monster = RandomSelection_chosen_string;
26         }
27
28         if(monster != "")
29         {
30                 float found = 0;
31                 entity mon;
32                 for(i = MON_FIRST; i <= MON_LAST; ++i)
33                 {
34                         mon = get_monsterinfo(i);
35                         if(mon.netname == monster)
36                         {
37                                 found = TRUE;
38                                 monster_id = mon.monsterid; // we have the monster, old monster id is no longer required
39                                 break;
40                         }
41                 }
42                 if(!found)
43                         monster = (get_monsterinfo(MON_FIRST)).netname;
44         }
45
46         if(monster == "")
47         if(monster_id)
48                 monster = (get_monsterinfo(monster_id)).netname;
49
50         e.realowner = spawnedby;
51
52         if(moveflag)
53                 e.monster_moveflags = moveflag;
54
55         if(IS_PLAYER(spawnedby))
56         {
57                 if(teamplay && autocvar_g_monsters_teams)
58                         e.team = spawnedby.team; // colors handled in spawn code
59
60                 if(autocvar_g_monsters_owners)
61                         e.monster_owner = own; // using .owner makes the monster non-solid for its master
62
63                 e.angles = spawnedby.angles;
64         }
65
66         //monster = strcat("$ spawnfunc_monster_", monster);
67         
68         entity oldself = self;
69         self = e;
70         monster_initialize(monster_id);
71         self = oldself;
72
73         //target_spawn_edit_entity(e, monster, world, world, world, world, world);
74
75         return e;
76 }