#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include"adjust.h"

extern charinfo Player;
extern HWND hWnd;

void SpellsFunc(void)
{
	pSpells pSpellist;
	char lovlig, c, n = 3, spell[4];

	Player.spells = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, sizeof(Spells));
	if(Player.spells == NULL)
	{
		MessageBox(hWnd, "Memory Error in SpellsFunc", NULL, MB_OK);
		return;
	}

	for(c=0; c<n; c++)
	{
		do
		{
			spell[c] = FALSE;
			lovlig = DICE(12);

			switch (lovlig)
			{
				case 1:
					if(strcmp(Player.class,"Abjurer") != 0)
					{
						spell[c] = 1;
					}
				break;

				case 2:
					if(c == 0 || c == 2)
					{
						if(strcmp(Player.class,"Invoker") != 0 &&
							 strcmp(Player.class,"Necromancer") != 0)
						{
							spell[c] = 2;
						}
						else if(c == 1)
						{
							if(strcmp(Player.class,"Illusionist") != 0 &&
								 strcmp(Player.class,"Transmuter") != 0)
							{
								spell[c] = 2;
							}
							else if(strcmp(Player.class,"Conjurer") != 0 &&
											strcmp(Player.class,"Necromancer") != 0)
							{
								spell[c] = 2;
							}
						}
					}
				break;

				case 3:
					if(strcmp(Player.class,"Abjurer") != 0)
					{
						spell[c] = 3;
					}
				break;

				case 4:
					if(c != 2)
					{
						if(strcmp(Player.class,"Invoker") != 0 &&
								strcmp(Player.class,"Necromancer") != 0)
						{
							spell[c] = 4;
						}
						else
						{
							if(strcmp(Player.class,"Illusionist") != 0)
							{
								spell[c] = 4;
							}
							else
							{
								if(c == 3)
								{
									spell[c] = 4;
								}
							}
						}
					}
				break;

				case 5:
					if(strcmp(Player.class,"Diviner") != 0 &&
						 strcmp(Player.class,"Invoker") != 0)
					{
						spell[c] = 5;
					}
				break;

				case 6:
					if(strcmp(Player.class,"Abjurer") != 0)
					{
						spell[c] = 6;
					}
				break;

				case 7:
					if(c == 0 || c == 1)
					{
						if(strcmp(Player.class,"Enchanter") != 0 &&
							 strcmp(Player.class,"Transmuter") != 0 &&
							 strcmp(Player.class,"Illusionist") != 0)
						{
							spell[c] = 7;
						}
						else
						{
							if(strcmp(Player.class,"Conjurer") != 0)
							{
								spell[c] = 7;
							}
						}
					}
				break;

				case 8:
					if(strcmp(Player.class,"Enchanter") != 0 &&
						 strcmp(Player.class,"Illusionist") != 0)
					{
						spell[c] = 8;
					}
					if(c == 3)
					{
						spell[c] = 8;
					}
				break;

				case 9:
					if(strcmp(Player.class,"Abjurer") != 0)
					{
						spell[c] = 9;
					}
				break;

				case 10:
					if(c == 0)
					{
						if(strcmp(Player.class,"Invoker") != 0 &&
							 strcmp(Player.class,"Necromancer") != 0)
						{
							spell[c] = 10;
						}
						if(c == 1)
						{
							if(strcmp(Player.class,"Enchanter") != 0 &&
								 strcmp(Player.class,"Illusionist") != 0)
							{
								spell[c] = 10;
							}
							if(c == 2)
							{
								if(strcmp(Player.class,"Abjurer") != 0)
								{
									spell[c] = 10;
								}
								if(c == 3)
								{
									if(strcmp(Player.class,"Abjurer") != 0 &&
										 strcmp(Player.class,"Necromancer") != 0)
									{
										spell[c] = 10;
									}
								}
							}
						}
					}
				break;

				case 11:
					if(strcmp(Player.class,"Conjurer") != 0 &&
						 strcmp(Player.class,"Necromancer") != 0)
					{
						spell[c] = 11;
					}
				break;

				case 12:
					n = 4;
				break;
			}
		}
		while(spell[c] == FALSE);
	}

	pSpellist = (pSpells) LocalLock(Player.spells);
	if(pSpellist == NULL)
	{
		MessageBox(hWnd, "Error in SpellsFunc", NULL, MB_OK);
		return;
	}


	switch (spell[0])
	{
		case  1:
			strcpy(pSpellist->Offensive, "Burning hands");
		break;

		case  2:
			strcpy(pSpellist->Offensive, "Charm person");
		break;

		case  3:
			strcpy(pSpellist->Offensive, "Enlarge");
		break;

		case  4:
			strcpy(pSpellist->Offensive, "Hypnotism");
		break;

		case  5:
			strcpy(pSpellist->Offensive, "Grease");
		break;

		case  6:
			strcpy(pSpellist->Offensive, "Color spray");
		break;

		case  7:
			strcpy(pSpellist->Offensive, "Chill touch");
		break;

		case  8:
			strcpy(pSpellist->Offensive, "Magic missile");
		break;

		case  9:
			strcpy(pSpellist->Offensive, "Shocking grasp");
		break;

		case 10:
			strcpy(pSpellist->Offensive, "Sleep");
		break;

		case 11:
			strcpy(pSpellist->Offensive, "Spook");
		break;

	}

	switch (spell[1])
	{
		case 1:
			strcpy(pSpellist->Defensive, "Gaze Reflection");
		break;

		case 2:
			strcpy(pSpellist->Defensive, "Protection/evil");
		break;

		case 3:
			strcpy(pSpellist->Defensive, "Light");
		break;

		case 4:
			strcpy(pSpellist->Defensive, "Alarm");
		break;

		case 5:
			strcpy(pSpellist->Defensive, "Armor");
		break;

		case 6:
			strcpy(pSpellist->Defensive, "Hold portal");
		break;

		case 7:
			strcpy(pSpellist->Defensive, "Detect undead");
		break;

		case 8:
			strcpy(pSpellist->Defensive, "Shield");
		break;

		case 9:
			strcpy(pSpellist->Defensive, "Featherfall");
		break;

		case 10:
			strcpy(pSpellist->Defensive, "Wall of fog");
		break;

		case 11:
			strcpy(pSpellist->Defensive, "Phantasmal force");
		break;
	}

	switch (spell[2])
	{
		case 1:
			strcpy(pSpellist->Miscelleanous, "Affect normal fires");
		break;

		case 2:
			strcpy(pSpellist->Miscelleanous, "Taunt");
		break;

		case 3:
			strcpy(pSpellist->Miscelleanous, "Spider climb");
		break;

		case 4:
			strcpy(pSpellist->Miscelleanous, "Friends");
		break;

		case 5:
			strcpy(pSpellist->Miscelleanous, "Unseen servant");
		break;

		case 6:
			strcpy(pSpellist->Miscelleanous, "Mending");
		break;

		case 7:
			strcpy(pSpellist->Miscelleanous, "Detect magic");
		break;

		case 8:
			strcpy(pSpellist->Miscelleanous, "T. floating disc");
		break;

		case 9:
			strcpy(pSpellist->Miscelleanous, "Dancing lights");
		break;

		case 10:
			strcpy(pSpellist->Miscelleanous, "Comprehend languages");
		break;

		case 11:
			strcpy(pSpellist->Miscelleanous, "Change self");
		break;
	}

	if (n == 4)
	{
		switch (spell[3])
		{
			case 1:
				strcpy(pSpellist->Bonus, "Jump");
			break;

			case 2:
				strcpy(pSpellist->Bonus, "Audible glamer");
			break;

			case 3:
				strcpy(pSpellist->Bonus, "Erase");
			break;

			case 4:
				strcpy(pSpellist->Bonus, "Free choise");
			break;

			case 5:
				strcpy(pSpellist->Bonus, "Mount");
			break;

			case 6:
				strcpy(pSpellist->Bonus, "Wizard mark");
			break;

			case 7:
				strcpy(pSpellist->Bonus, "Identify");
			break;

			case 8:
				strcpy(pSpellist->Bonus, "Free choise");
			break;

			case 9:
				strcpy(pSpellist->Bonus, "Message");
			break;

			case 10:
				strcpy(pSpellist->Bonus, "Ventriloquism");
			break;

			case 11:
				strcpy(pSpellist->Bonus, "Nystuls magic aura");
			break;
		}
	}
	else
	{
		strcpy(pSpellist->Bonus, "None");
	}
	LocalUnlock(Player.spells);
}