//reptile functions
#include "animalsBase.h"
#include "reptile.h"
#include "tx_api.h"
#include <iostream>
using namespace std;


extern "C"
{
reptileBase::reptileBase() : animalBase()
{
	cout << "Creating a default reptile" << endl;
	this->isPoisionous = notPoisonous;
	this->changesColors = canNotChangeColors;
}
}

extern "C"
{
reptileBase::reptileBase(int isNocternal, int whatItEats, int isPoisonous, int canItChangeColors) : animalBase(isNocternal, whatItEats)
{
    unsigned int theuiStatus = 0;
	cout << "creating a reptile with params" << endl;
	this->isPoisionous = isPoisonous;
	this->changesColors = canItChangeColors;
	char theName[6] = "Harry";
	printf("Creating a reptile semaphore no memset\n");
	//memset(&this->theReptileSemaphore, '\0', sizeof(TX_SEMAPHORE));
	//theuiStatus = tx_semaphore_create(&this->theReptileSemaphore, theName, 1);
	theuiStatus = tx_semaphore_create(&theReptileSemaphore, theName, 1);

	if(theuiStatus != TX_SUCCESS)
	{
	    printf("create failed [%xl]\n", theuiStatus); 
	}
}
}

extern "C"
{
reptileBase::~reptileBase()
{
	cout << "destroying a reptile" << endl;
}
}


extern "C"
{
int reptileBase::attack()
{
	if(animalBase::checkSleepState() == asleep)
	{
		cout << "reptile can't attack, is asleep " << endl;
		return attackFailure;
	}
	else
	{
		cout << "reptile attacked" << endl;
		return attackSuccess;
	}
}
}


extern "C"
{
void reptileBase::print()
{
	cout << "reptile is poisonous " << this->isPoisionous << " reptile can change colors " << this->changesColors << endl;
	animalBase::print();
}
}


extern "C"
{
int reptileBase::changeColors(int whatColor)
{
	if(this->changesColors == canNotChangeColors)
	{
		cout << "this reptile is not equiped to change colors" << endl;
		return changeColorsFailure;
	}
	else
	{
		this->currentColor = whatColor;
		return changeColorsSuccess;
	}
}
}
