#include "stdafx.h"
#include "War3TypesAndConstants.h"
#include "War3StrID.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CWar3StrID::CWar3StrID()
{
	int i;
	for (i = 0; i <= WAR3STRID_MAXCHAR; i++)
	{
		strID[i] = '\0';
	}
	for (i = 0; i <= WAR3STRID_MAXCHAR2; i++)
	{
		strID2[i] = '\0';
	}
}

CWar3StrID::~CWar3StrID()
{

}


char* CWar3StrID::GetStrID()
{
	if (strID[0] != '\0')
		return strID;
	if (strID2[0] != '\0')
		return strID2;
	return strID;
}

void CWar3StrID::SetStrID(const char acNewID[])
{
	int i;
	if (strlen(acNewID) <= 4)
	{
		for (i = 0; i < WAR3STRID_MAXCHAR; i++)
		{
			strID[i] = acNewID[i];
		}
		strID[WAR3STRID_MAXCHAR] = '\0';
		strID2[0] = '\0';
	}
	else if(strlen(acNewID) > 4)
	{
		for (i = 0; i < strlen(acNewID); i++)
		{
			strID2[i] = acNewID[i];
		}
		strID[0] = '\0';
		strID2[strlen(acNewID)] = '\0';
	}
}

BOOL CWar3StrID::operator ==(const CWar3StrID &otherStrID) const
{
	BOOL ret = TRUE;
	int i = 0;
	if (strlen(otherStrID.strID) != 0)
	{
		while ((i < WAR3STRID_MAXCHAR) && (TRUE == ret))
		{
			if (strID[i] != otherStrID.strID[i])
			{
				ret = FALSE;
			}
			i++;
		}
	}
	else
	{
		if (strlen(otherStrID.strID2) != 0)
		{
			while ((i < strlen(otherStrID.strID2)) && (TRUE == ret))
			{
				if (strID2[i] != otherStrID.strID2[i])
				{
					ret = FALSE;
				}
				i++;
			}
		}
	}
	return ret;
}


BOOL CWar3StrID::operator ==(const char acStrID[]) const
{
	BOOL ret = TRUE;
	int i = 0;
	if (strID[0] == NULL && strID2[0] == NULL)
		return ret;
	if (strlen(acStrID) <= 4 && strID[0] != NULL)
	{
		while ((i < WAR3STRID_MAXCHAR) && (TRUE == ret))
		{
			if (strID[i] != acStrID[i])
			{
				ret = FALSE;
			}
			i++;
		}
	}
	else if(strlen(acStrID) > 4)
	{
		while ((i < strlen(acStrID)) && (TRUE == ret))
		{
			if (strID2[i] != acStrID[i])
			{
				ret = FALSE;
			}
			i++;
		}
	}
	else
	{
		ret = FALSE;
	}
	return ret;
}


BOOL CWar3StrID::operator !=(const CWar3StrID &otherStrID) const
{
	BOOL ret = FALSE;
	int i = 0;
	if (strlen(otherStrID.strID) <= 4)
	{
		while ((i < WAR3STRID_MAXCHAR) && (FALSE == ret))
		{
			if (strID[i] != otherStrID.strID[i])
			{
				ret = TRUE;
			}
			i++;
		}
	}
	else if(strlen(otherStrID.strID) > 4)
	{
		while ((i < strlen(otherStrID.strID)) && (FALSE == ret))
		{
			if (strID2[i] != otherStrID.strID2[i])
			{
				ret = TRUE;
			}
			i++;
		}
	}
	return ret;
}


BOOL CWar3StrID::operator !=(const char acStrID[]) const
{
	BOOL ret = FALSE;
	int i = 0;
	if (strID[i] == NULL && strID2[i] == NULL)
		return ret;
	if (strlen(acStrID) <= 4 && strID[i] != NULL)
	{
		while ((i < WAR3STRID_MAXCHAR) && (FALSE == ret))
		{
			if (strID[i] != acStrID[i])
			{
				ret = TRUE;
			}
			i++;
		}
	}
	else if(strlen(acStrID) > 4)
	{
		while ((i < strlen(acStrID)) && (FALSE == ret))
		{
			if (strID2[i] != acStrID[i])
			{
				ret = TRUE;
			}
			i++;
		}
	}
	else
	{
		ret = TRUE;
	}
	return ret;
}


void CWar3StrID::operator =(const char acStrID[])
{
	SetStrID(acStrID);
}

char CWar3StrID::operator [](int nIndex) const
{
	if ((nIndex < WAR3STRID_MAXCHAR) && (nIndex >= 0))
	{
		return strID[nIndex];
	}
	else
	{
		return '\0';
	}
}

CWar3StrID::CWar3StrID(const char acStrID[])
{
	SetStrID(acStrID);
}
