// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movq %rsi, 0x160(%rsp)
callq 0x18cd0
movq 0x2dae4(%rip), %rax     # 0x69600
movl $0x2fe, %edi            # imm = 0x2FE
callq *0x118(%rax)
movq 0x2e272(%rip), %r15     # 0x69da0
movl $0x0, 0x15c(%rsp)
movl $0x158, %edx            # imm = 0x158
movq %r15, %rdi
xorl %esi, %esi
callq 0x18880
movq 0x2da09(%rip), %rbp     # 0x69558
movq (%rbp), %rdi
movq 0x2e1e6(%rip), %r12     # 0x69d40
movslq 0x614(%r12), %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(%r12), %rdi
movl $0x1ff, %edx            # imm = 0x1FF
movq %r14, %rsi
callq 0x181c0
movslq 0x610(%r12), %rcx
testq %rcx, %rcx
jle 0x3bbd5
movq 0x408(%r12), %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 0x3bbb7
leaq 0x160(%rsp), %r14
movq (%r14), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x184b0
movq %r12, (%r14)
movq %r14, %rdi
callq 0x19190
cmpq $0x0, (%r14)
movl $0x0, %r14d
je 0x3bd94
leaq 0x1d994(%rip), %r12     # 0x595a1
leaq 0x160(%rsp), %rbx
xorl %r13d, %r13d
xorl %r14d, %r14d
movl $0x0, 0x15c(%rsp)
incl %r14d
movl %r14d, %ecx
movl %ecx, %r14d
cmpb $0x7b, (%rax)
je 0x3bc4a
leaq 0x1d93b(%rip), %rdi     # 0x59576
movq %rax, %rsi
xorl %eax, %eax
movq 0x2d9b9(%rip), %rcx     # 0x69600
callq *0x38(%rcx)
testq %r13, %r13
je 0x3bc59
callq 0x19710
movq %rax, %r13
jmp 0x3bc5d
movq (%rbp), %r13
movq 0x160(%rsp), %rdi
movq %r13, %rsi
callq 0x19910
movq %rax, 0x160(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18690
testl %eax, %eax
jne 0x3bcba
movq 0x138(%r13), %rdi
leaq 0x1d39d(%rip), %rsi     # 0x5902f
callq 0x18690
testl %eax, %eax
jne 0x3bcba
movq 0x120(%r13), %rdi
leaq 0x1d900(%rip), %rsi     # 0x595a9
callq 0x18690
testl %eax, %eax
jne 0x3bcba
andb $-0x5, 0x141(%r13)
cmpq (%rbp), %r13
je 0x3bd49
movq 0x2e1f5(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3bcdd
jnp 0x3bcec
testb $0x8, 0x141(%r13)
je 0x3bd41
jmp 0x3bd6e
movq 0x2da45(%rip), %rax     # 0x69738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x3bd0c
jp 0x3bd0c
testb $0x1, 0x141(%r13)
jne 0x3bd6e
ucomiss 0x18215(%rip), %xmm0    # 0x53f28
jne 0x3bd21
jp 0x3bd21
testb $0x2, 0x141(%r13)
jne 0x3bd6e
ucomiss 0x18730(%rip), %xmm0    # 0x54458
jne 0x3bd2c
jnp 0x3bd37
ucomiss 0x181d9(%rip), %xmm0    # 0x53f0c
jne 0x3bd41
jp 0x3bd41
testb $0x4, 0x141(%r13)
jne 0x3bd6e
andb $-0x20, 0x141(%r13)
movq %r13, %rdi
callq 0x19310
movq %rbx, %rdi
callq 0x19190
leal 0x1(%r14), %ecx
cmpq $0x0, 0x160(%rsp)
jne 0x3bc2c
jmp 0x3bd94
movq %r13, %rdi
callq 0x19a60
incl 0x15c(%rsp)
movq %rbx, %rdi
callq 0x19190
cmpq $0x0, 0x160(%rsp)
jne 0x3bc26
movq 0x2e125(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3bdad
jnp 0x3bddc
movq 0x2da44(%rip), %rax     # 0x697f8
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x2daa0(%rip), %rax     # 0x69860
movq %rcx, (%rax)
xorl %eax, %eax
callq 0x18590
xorl %eax, %eax
callq 0x19110
testl %eax, %eax
je 0x3bddc
xorl %eax, %eax
callq 0x18970
movq 0x2d67d(%rip), %rbx     # 0x69460
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x1, %al
je 0x3bdf9
movl $0x1, %edi
callq 0x19860
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x3be0f
movl $0x4, %edi
callq 0x19860
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
je 0x3be25
movl $0x2, %edi
callq 0x19860
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x8, %al
je 0x3be3b
movl $0x8, %edi
callq 0x19860
movq (%rbx), %rax
cvttss2si 0x20(%rax), %eax
testb $0x10, %al
je 0x3be51
movl $0x10, %edi
callq 0x19860
xorl %eax, %eax
callq 0x197b0
movl 0x15c(%rsp), %esi
subl %esi, %r14d
leaq 0x1d744(%rip), %rdi     # 0x595ad
movl %r14d, %edx
xorl %eax, %eax
movq 0x2d78b(%rip), %rbx     # 0x69600
callq *0x8(%rbx)
callq 0x18ff0
callq 0x18ae0
movq 0x2df17(%rip), %rsi     # 0x69da0
movl $0x2b, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x199b0
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop