// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_spawn.c
// Function: SpawnEntities
void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
{
	edict_t		*ent;
	int			inhibit;

	int total_ents;

	char		*com_token;
	int			i;

	SaveClientData ();

	gi.FreeTags (TAG_LEVEL);

	memset (&level, 0, sizeof(level));
	memset (g_edicts, 0, game.maxentities * sizeof (g_edicts[0]));

	strncpy (level.mapname, mapname, sizeof(level.mapname)-1);
	strncpy (game.spawnpoint, spawnpoint, sizeof(game.spawnpoint)-1);

	// set client fields on player ents
	for (i=0 ; i<game.maxclients ; i++)
		g_edicts[i+1].client = game.clients + i;

	ent = NULL;
	inhibit = 0;



	// LM_JORM
	//  Write Entities out to a file
	entities = ReadEntFile(mapname, entities);
	
	total_ents = 0; //surt
	// END LM_JORM

// parse ents
	while (1)
	{
		// parse the opening brace	
		com_token = COM_Parse (&entities);
		if (!entities)
			break;
		if (com_token[0] != '{')
			gi.error ("ED_LoadFromFile: found %s when expecting {",com_token);

		if (!ent)
			ent = g_edicts;
		else
			ent = G_Spawn ();
		entities = ED_ParseEdict (entities, ent);

		total_ents++;

		// yet another map hack
		if (!Q_stricmp(level.mapname, "command") && !Q_stricmp(ent->classname, "trigger_once") && !Q_stricmp(ent->model, "*27"))
			ent->spawnflags &= ~SPAWNFLAG_NOT_HARD;

		// remove things (except the world) from different skill levels or deathmatch
		if (ent != g_edicts)
		{
			if (deathmatch->value)
			{
				if ( ent->spawnflags & SPAWNFLAG_NOT_DEATHMATCH )
				{
					G_FreeEdict (ent);	
					inhibit++;
					continue;
				}
			}
			else
			{
				if ( /* ((coop->value) && (ent->spawnflags & SPAWNFLAG_NOT_COOP)) || */
					((skill->value == 0) && (ent->spawnflags & SPAWNFLAG_NOT_EASY)) ||
					((skill->value == 1) && (ent->spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
					(((skill->value == 2) || (skill->value == 3)) && (ent->spawnflags & SPAWNFLAG_NOT_HARD))
					)
					{
						G_FreeEdict (ent);	
						inhibit++;
						continue;
					}
			}

			ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY|SPAWNFLAG_NOT_MEDIUM|SPAWNFLAG_NOT_HARD|SPAWNFLAG_NOT_COOP|SPAWNFLAG_NOT_DEATHMATCH);
		}

		ED_CallSpawn (ent);
	}	
	
	// CTF CODE -- LM_JORM
	if (deathmatch->value)
	{
		redflag = NULL;
		blueflag = NULL;
		// Spawn our flags
		ctf_validateflags(); //this is the only function allowed to spawn flags
		
		if (Match_Mode())
			SpawnTourneyClock ();
		//else
		//	SpawnRegClock();

	}

	//in case you want to play single player runes
	if ((int)runes->value & RUNE_DAMAGE)
		SpawnRune(RUNE_DAMAGE);
	if ((int)runes->value & RUNE_HASTE)
		SpawnRune(RUNE_HASTE);
	if ((int)runes->value & RUNE_RESIST)
		SpawnRune(RUNE_RESIST);
	if ((int)runes->value & RUNE_REGEN)
		SpawnRune(RUNE_REGEN);
	if ((int)runes->value & RUNE_VAMP)  //added by Vampire
		SpawnRune(RUNE_VAMP);           


	Reset_MVP();

	// END CTF CODE

	gi.dprintf ("%i ents removed, %i ents used\n", inhibit,total_ents-inhibit);

	G_FindTeams ();

	PlayerTrail_Init ();

	sl_GameStart( &gi, level );	//	StdLog - Mark Davies
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdx, %r14
movq %rdi, %r13
movq %rsi, 0x168(%rsp)
callq 0x18db0
movq 0x2e623(%rip), %rax     # 0x66600
movl $0x2fe, %edi            # imm = 0x2FE
callq *0x118(%rax)
movq 0x2edb1(%rip), %r15     # 0x66da0
xorl %r12d, %r12d
movl $0x158, %edx            # imm = 0x158
movq %r15, %rdi
xorl %esi, %esi
callq 0x188e0
movq 0x2e550(%rip), %rbx     # 0x66558
movq (%rbx), %rdi
movq 0x2ed2e(%rip), %rbp     # 0x66d40
movslq 0x614(%rbp), %rax
imulq $0x4a8, %rax, %rdx      # imm = 0x4A8
xorl %esi, %esi
callq 0x188e0
addq $0x48, %r15
pushq $0x3f
popq %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x181e0
leaq 0x410(%rbp), %rdi
movl $0x1ff, %edx            # imm = 0x1FF
movq %r14, %rsi
callq 0x181e0
movl 0x610(%rbp), %ecx
movq 0x408(%rbp), %rax
testl %ecx, %ecx
cmovlel %r12d, %ecx
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
cmpq %r12, %rcx
je 0x38086
movq (%rbx), %rdx
movq %rax, 0x500(%rdx,%r12)
addq $0x4a8, %r12            # imm = 0x4A8
addq $0x9140, %rax           # imm = 0x9140
jmp 0x38067
leaq 0x168(%rsp), %r12
movq (%r12), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x184e0
movq %r14, (%r12)
xorl %eax, %eax
movl $0x0, 0x164(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rax, 0x170(%rsp)
leal (%rax,%r13), %r14d
incl %r13d
movq %r12, %rdi
callq 0x19300
cmpq $0x0, 0x168(%rsp)
je 0x3823c
cmpb $0x7b, (%rax)
je 0x380f4
leaq 0x1c685(%rip), %rdi     # 0x5476a
movq %rax, %rsi
xorl %eax, %eax
movq 0x2e50f(%rip), %rcx     # 0x66600
callq *0x38(%rcx)
testq %rbp, %rbp
je 0x38103
callq 0x198d0
movq %rax, %rbp
jmp 0x38106
movq (%rbx), %rbp
movq 0x168(%rsp), %rdi
movq %rbp, %rsi
callq 0x19ae0
movq %rax, 0x168(%rsp)
movq %r15, %rdi
leaq 0x1c66d(%rip), %rsi     # 0x54795
callq 0x186d0
testl %eax, %eax
jne 0x38166
movq 0x138(%rbp), %rdi
leaq 0x1c0e4(%rip), %rsi     # 0x54223
callq 0x186d0
testl %eax, %eax
jne 0x38166
movq 0x120(%rbp), %rdi
leaq 0x1c647(%rip), %rsi     # 0x5479d
callq 0x186d0
testl %eax, %eax
jne 0x38166
andb $-0x5, 0x141(%rbp)
cmpq (%rbx), %rbp
je 0x3820e
movq 0x2ed4a(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x38188
jnp 0x38199
movl 0x140(%rbp), %eax
btl $0xb, %eax
jae 0x38203
jmp 0x3821e
movq 0x2e598(%rip), %rax     # 0x66738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x381b8
jp 0x381b8
testb $0x1, 0x141(%rbp)
jne 0x3821e
ucomiss 0x16d69(%rip), %xmm0    # 0x4ef28
jne 0x381cc
jp 0x381cc
testb $0x2, 0x141(%rbp)
jne 0x3821e
movaps %xmm0, %xmm1
movss 0x16d35(%rip), %xmm2    # 0x4ef0c
cmpneqps %xmm2, %xmm1
movss 0x17289(%rip), %xmm2    # 0x4f46c
cmpneqps %xmm2, %xmm0
andps %xmm1, %xmm0
movd %xmm0, %ecx
movl 0x140(%rbp), %eax
testb $0x1, %cl
jne 0x38203
movl %eax, %ecx
andl $0x400, %ecx            # imm = 0x400
jne 0x3821e
andl $0xffffe0ff, %eax       # imm = 0xFFFFE0FF
movl %eax, 0x140(%rbp)
movq %rbp, %rdi
callq 0x194a0
incl %r14d
jmp 0x380bf
movq %rbp, %rdi
callq 0x19c50
incl 0x164(%rsp)
movq 0x170(%rsp), %rax
decl %eax
jmp 0x380b3
movq 0x2ec7d(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x38255
jnp 0x38284
movq 0x2e59c(%rip), %rax     # 0x667f8
andq $0x0, (%rax)
movq 0x2e5f9(%rip), %rax     # 0x66860
andq $0x0, (%rax)
xorl %eax, %eax
callq 0x185d0
xorl %eax, %eax
callq 0x19280
testl %eax, %eax
je 0x38284
xorl %eax, %eax
callq 0x189f0
movq 0x2e1d5(%rip), %rbx     # 0x66460
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x1, %al
je 0x382a7
pushq $0x1
popq %rdi
callq 0x19a30
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x382bb
pushq $0x4
popq %rdi
callq 0x19a30
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
je 0x382cf
pushq $0x2
popq %rdi
callq 0x19a30
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x8, %al
je 0x382e3
pushq $0x8
popq %rdi
callq 0x19a30
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x10, %al
je 0x382ef
pushq $0x10
popq %rdi
callq 0x19a30
xorl %eax, %eax
callq 0x19980
leaq 0x1c4a4(%rip), %rdi     # 0x547a1
movl 0x164(%rsp), %esi
movl %r14d, %edx
xorl %eax, %eax
movq 0x2e2f0(%rip), %rbx     # 0x66600
callq *0x8(%rbx)
callq 0x19120
callq 0x18b80
movq 0x2ea7c(%rip), %rsi     # 0x66da0
pushq $0x2b
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x19b80
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop