// Card.m
// Part of Risk by Mike Ferris

#import "Card.h"
#import <appkit/NXImage.h>
#import <appkit/Panel.h>

@implementation Card

+ initialize
{
	if (self == [Card class])  {
		[self setVersion:1];
	}
	return self;
}

- init
{
	[self initCountry:-1 type:NIL_TYPE imageFile:NULL];
	return self;
}

- initCountry:(int)c type:(int)t imageFile:(const char *)imageName
{
	[super init];
	countryNum=c;
	type=t;
	if (imageName!=NULL)  {
		image=[[NXImage allocFromZone:[self zone]] initFromSection:imageName];
		if (image==nil)  {
			NXRunAlertPanel("Debug", "Didn't get bmap", "OK", NULL, NULL);
		}
	}  else  {
		image=nil;
	}
	return self;
}

- free
{
	[image free];
	return [super free];
}

- (int)countryNum
{
	return countryNum;
}

- (int)type
{
	return type;
}

- image
{
	return image;
}

- setCountryNum:(int)c
{
	countryNum=c;
	return self;
}

- setType:(int)t
{
	type=t;
	return self;
}

- setImageName:(const char *)imageName
{
	if (imageName!=NULL)  {
		image=[[NXImage allocFromZone:[self zone]] initFromFile:imageName];
	}  else  {
		image=nil;
	}
	return self;
}

- write:(NXTypedStream *)typedStream
{
	[super write:typedStream];
	NXWriteType(typedStream, "i", &countryNum);
	NXWriteType(typedStream, "i", &type);
	NXWriteObject(typedStream, image);
	
	return self;
}

- read:(NXTypedStream *)typedStream
{
	[super read:typedStream];
	NXReadType(typedStream, "i", &countryNum);
	NXReadType(typedStream, "i", &type);
	image=NXReadObject(typedStream);

	return self;
}

@end
