// File: /workspace/github_c_makefile_star2_O3/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 $0x168, %rsp            # imm = 0x168
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x158(%rsp)
callq 0x18cd0
movq 0x2d40b(%rip), %rax     # 0x68600
movl $0x2fe, %edi            # imm = 0x2FE
callq *0x118(%rax)
movq 0x2db99(%rip), %r15     # 0x68da0
movl $0x0, 0x164(%rsp)
movl $0x158, %edx            # imm = 0x158
movq %r15, %rdi
xorl %esi, %esi
callq 0x18880
movq 0x2d330(%rip), %rbp     # 0x68558
movq (%rbp), %rdi
movq 0x2db0d(%rip), %r13     # 0x68d40
movslq 0x614(%r13), %rax
imulq $0x4a8, %rax, %rdx      # imm = 0x4A8
xorl %esi, %esi
callq 0x18880
addq $0x48, %r15
movl $0x3f, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x181c0
leaq 0x410(%r13), %rdi
movl $0x1ff, %edx            # imm = 0x1FF
movq %r12, %rsi
callq 0x181c0
movslq 0x610(%r13), %rcx
testq %rcx, %rcx
jle 0x3b2b2
movq 0x408(%r13), %rax
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
xorl %edx, %edx
movq (%rbp), %rsi
movq %rax, 0x500(%rsi,%rdx)
addq $0x9140, %rax           # imm = 0x9140
addq $0x4a8, %rdx            # imm = 0x4A8
cmpq %rdx, %rcx
jne 0x3b28c
movq 0x158(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x184b0
leaq 0x158(%rsp), %rbx
movq %r14, (%rbx)
movq %rbx, %rdi
callq 0x19190
cmpq $0x0, (%rbx)
movl $0x0, %r14d
je 0x3b48d
leaq 0x1d4ce(%rip), %r12     # 0x587b5
leaq 0x158(%rsp), %rbx
xorl %r13d, %r13d
xorl %r14d, %r14d
movl $0x0, 0x164(%rsp)
incl %r14d
movl %r14d, %ecx
movl %ecx, %r14d
cmpb $0x7b, (%rax)
je 0x3b324
leaq 0x1d475(%rip), %rdi     # 0x5878a
movq %rax, %rsi
xorl %eax, %eax
movq 0x2d2df(%rip), %rcx     # 0x68600
callq *0x38(%rcx)
testq %r13, %r13
je 0x3b333
callq 0x19700
movq %rax, %r13
jmp 0x3b337
movq (%rbp), %r13
movq 0x158(%rsp), %rdi
movq %r13, %rsi
callq 0x19900
movq %rax, 0x158(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18690
testl %eax, %eax
jne 0x3b394
movq 0x138(%r13), %rdi
leaq 0x1ced7(%rip), %rsi     # 0x58243
callq 0x18690
testl %eax, %eax
jne 0x3b394
movq 0x120(%r13), %rdi
leaq 0x1d43a(%rip), %rsi     # 0x587bd
callq 0x18690
testl %eax, %eax
jne 0x3b394
andb $-0x5, 0x141(%r13)
cmpq (%rbp), %r13
je 0x3b442
movq 0x2db1b(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3b3b7
jnp 0x3b3c9
movl 0x140(%r13), %eax
btl $0xb, %eax
jae 0x3b436
jmp 0x3b467
movq 0x2d368(%rip), %rax     # 0x68738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x3b3e9
jp 0x3b3e9
testb $0x1, 0x141(%r13)
jne 0x3b467
ucomiss 0x17b38(%rip), %xmm0    # 0x52f28
jne 0x3b3fe
jp 0x3b3fe
testb $0x2, 0x141(%r13)
jne 0x3b467
movaps %xmm0, %xmm1
movss 0x17b07(%rip), %xmm2    # 0x52f10
cmpneqps %xmm2, %xmm1
movss 0x18057(%rip), %xmm2    # 0x5346c
cmpneqps %xmm2, %xmm0
andps %xmm1, %xmm0
movd %xmm0, %ecx
movl 0x140(%r13), %eax
testb $0x1, %cl
jne 0x3b436
movl %eax, %ecx
andl $0x400, %ecx            # imm = 0x400
jne 0x3b467
andl $0xffffe0ff, %eax       # imm = 0xFFFFE0FF
movl %eax, 0x140(%r13)
movq %r13, %rdi
callq 0x19310
movq %rbx, %rdi
callq 0x19190
leal 0x1(%r14), %ecx
cmpq $0x0, 0x158(%rsp)
jne 0x3b306
jmp 0x3b48d
movq %r13, %rdi
callq 0x19a50
incl 0x164(%rsp)
movq %rbx, %rdi
callq 0x19190
cmpq $0x0, 0x158(%rsp)
jne 0x3b300
movq 0x2da2c(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3b4a6
jnp 0x3b4d5
movq 0x2d34b(%rip), %rax     # 0x687f8
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x2d3a7(%rip), %rax     # 0x68860
movq %rcx, (%rax)
xorl %eax, %eax
callq 0x18590
xorl %eax, %eax
callq 0x19110
testl %eax, %eax
je 0x3b4d5
xorl %eax, %eax
callq 0x18970
movq 0x2cf84(%rip), %rbx     # 0x68460
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x1, %al
je 0x3b4fa
movl $0x1, %edi
callq 0x19850
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x3b510
movl $0x4, %edi
callq 0x19850
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
je 0x3b526
movl $0x2, %edi
callq 0x19850
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x8, %al
je 0x3b53c
movl $0x8, %edi
callq 0x19850
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x10, %al
je 0x3b54a
movl $0x10, %edi
callq 0x19850
xorl %eax, %eax
callq 0x197a0
movl 0x164(%rsp), %esi
subl %esi, %r14d
leaq 0x1d25f(%rip), %rdi     # 0x587c1
movl %r14d, %edx
xorl %eax, %eax
movq 0x2d092(%rip), %rbx     # 0x68600
callq *0x8(%rbx)
callq 0x18ff0
callq 0x18ae0
movq 0x2d81e(%rip), %rsi     # 0x68da0
movl $0x2b, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x199a0
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop