// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x18e10
movl $0x2fe, %edi            # imm = 0x2FE
movq 0x36ba8(%rip), %rax     # 0x82600
callq *0x118(%rax)
movq 0x3733b(%rip), %rdi     # 0x82da0
xorl %esi, %esi
movl $0x158, %edx            # imm = 0x158
callq 0x188f0
movq 0x36ae0(%rip), %rax     # 0x82558
movq (%rax), %rdi
movq 0x372be(%rip), %rax     # 0x82d40
movslq 0x614(%rax), %rax
imulq $0x4a8, %rax, %rdx      # imm = 0x4A8
xorl %esi, %esi
callq 0x188f0
movq -0x8(%rbp), %rsi
movq 0x372fe(%rip), %rdi     # 0x82da0
addq $0x48, %rdi
movl $0x3f, %edx
callq 0x181e0
movq -0x18(%rbp), %rsi
movq 0x37285(%rip), %rdi     # 0x82d40
addq $0x410, %rdi            # imm = 0x410
movl $0x1ff, %edx            # imm = 0x1FF
callq 0x181e0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq 0x37263(%rip), %rcx     # 0x82d40
cmpl 0x610(%rcx), %eax
jge 0x4bb2d
movq 0x37254(%rip), %rax     # 0x82d40
movq 0x408(%rax), %rcx
movslq -0x34(%rbp), %rax
imulq $0x9140, %rax, %rax     # imm = 0x9140
addq %rax, %rcx
movq 0x36a50(%rip), %rax     # 0x82558
movq (%rax), %rax
movl -0x34(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq $0x4a8, %rdx, %rdx      # imm = 0x4A8
addq %rdx, %rax
movq %rcx, 0x58(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4bad3
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x184f0
movq %rax, -0x10(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x19360
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4bb6d
jmp 0x4bd88
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
je 0x4bb93
movq 0x36a80(%rip), %rax     # 0x82600
movq 0x38(%rax), %rcx
movq -0x30(%rbp), %rsi
leaq 0x298fb(%rip), %rdi     # 0x7548a
movb $0x0, %al
callq *%rcx
cmpq $0x0, -0x20(%rbp)
jne 0x4bbaa
movq 0x369b7(%rip), %rax     # 0x82558
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x4bbb3
callq 0x19950
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x19b70
movq %rax, -0x10(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq 0x371cc(%rip), %rdi     # 0x82da0
addq $0x48, %rdi
leaq 0x298d6(%rip), %rsi     # 0x754b5
callq 0x186f0
cmpl $0x0, %eax
jne 0x4bc37
movq -0x20(%rbp), %rax
movq 0x138(%rax), %rdi
leaq 0x29348(%rip), %rsi     # 0x74f43
callq 0x186f0
cmpl $0x0, %eax
jne 0x4bc37
movq -0x20(%rbp), %rax
movq 0x120(%rax), %rdi
leaq 0x298a6(%rip), %rsi     # 0x754bd
callq 0x186f0
cmpl $0x0, %eax
jne 0x4bc37
movq -0x20(%rbp), %rax
movl 0x140(%rax), %ecx
andl $0xfffffbff, %ecx       # imm = 0xFFFFFBFF
movl %ecx, 0x140(%rax)
movq -0x20(%rbp), %rax
movq 0x36916(%rip), %rcx     # 0x82558
cmpq (%rcx), %rax
je 0x4bd7a
movq 0x3726e(%rip), %rax     # 0x82ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4bc66
jp 0x4bc66
jmp 0x4bc96
movq -0x20(%rbp), %rax
movl 0x140(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x4bc91
movq -0x20(%rbp), %rdi
callq 0x19cd0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4bb54
jmp 0x4bd64
movq 0x36a9b(%rip), %rax     # 0x82738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4bcc7
jp 0x4bcc7
movq -0x20(%rbp), %rax
movl 0x140(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0x4bd4b
movq 0x36a6a(%rip), %rax     # 0x82738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
movss 0x2420e(%rip), %xmm1    # 0x6feec
ucomiss %xmm1, %xmm0
jne 0x4bcf9
jp 0x4bcf9
movq -0x20(%rbp), %rax
movl 0x140(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x4bd4b
movq 0x36a38(%rip), %rax     # 0x82738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
movss 0x241d8(%rip), %xmm1    # 0x6fee8
ucomiss %xmm1, %xmm0
jne 0x4bd19
jp 0x4bd19
jmp 0x4bd37
movq 0x36a18(%rip), %rax     # 0x82738
movq (%rax), %rax
movss 0x20(%rax), %xmm0
movss 0x241e0(%rip), %xmm1    # 0x6ff10
ucomiss %xmm1, %xmm0
jne 0x4bd62
jp 0x4bd62
movq -0x20(%rbp), %rax
movl 0x140(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x4bd62
movq -0x20(%rbp), %rdi
callq 0x19cd0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4bb54
jmp 0x4bd64
movq -0x20(%rbp), %rax
movl 0x140(%rax), %ecx
andl $0xffffe0ff, %ecx       # imm = 0xFFFFE0FF
movl %ecx, 0x140(%rax)
movq -0x20(%rbp), %rdi
callq 0x19520
jmp 0x4bb54
movq 0x37131(%rip), %rax     # 0x82ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4bda3
jp 0x4bda3
jmp 0x4bddb
movq 0x36a4e(%rip), %rax     # 0x827f8
movq $0x0, (%rax)
movq 0x36aa8(%rip), %rax     # 0x82860
movq $0x0, (%rax)
movb $0x0, %al
callq 0x185f0
movb $0x0, %al
callq 0x192e0
cmpl $0x0, %eax
je 0x4bdd9
movb $0x0, %al
callq 0x18a10
jmp 0x4bddb
movq 0x3667e(%rip), %rax     # 0x82460
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4bdfc
movl $0x1, %edi
callq 0x19ac0
movq 0x3665d(%rip), %rax     # 0x82460
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4be1d
movl $0x4, %edi
callq 0x19ac0
movq 0x3663c(%rip), %rax     # 0x82460
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x4be3e
movl $0x2, %edi
callq 0x19ac0
movq 0x3661b(%rip), %rax     # 0x82460
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x4be5f
movl $0x8, %edi
callq 0x19ac0
movq 0x365fa(%rip), %rax     # 0x82460
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4be80
movl $0x10, %edi
callq 0x19ac0
movb $0x0, %al
callq 0x19a10
movq 0x36772(%rip), %rax     # 0x82600
movq 0x8(%rax), %rcx
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
subl -0x24(%rbp), %edx
leaq 0x2961f(%rip), %rdi     # 0x754c1
movb $0x0, %al
callq *%rcx
callq 0x19190
callq 0x18bb0
movq 0x36ee9(%rip), %rsi     # 0x82da0
movq %rsp, %rdi
movl $0x2b, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq 0x36737(%rip), %rdi     # 0x82600
callq 0x19c10
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw (%rax,%rax)