/* BWSideView */

#import "Variables.h"

#define DOLMEN	0x04
#define PIT		0x08

@interface BWSideView : NSMatrix
{
	IBOutlet id objMain;
	IBOutlet id objOverWorld;
	IBOutlet id objGameData;
	
	IBOutlet id menuWorlds;
	IBOutlet id fieldArea;
	IBOutlet id fieldData;
	IBOutlet id fieldEnemySet;
	IBOutlet id fieldObjects;
	IBOutlet id fieldObjectPosition;
	IBOutlet id fieldObjectType;
	IBOutlet id fieldObjectItem;
	IBOutlet id fieldEnemies;
	IBOutlet id fieldEnemyPosition;
	IBOutlet id fieldEnemyScreen;
	IBOutlet id fieldEnemyType;
	IBOutlet id radioObjectSet;
	
	IBOutlet id fieldDestinationLeft;
	IBOutlet id fieldDestinationDown;
	IBOutlet id fieldDestinationUp;
	IBOutlet id fieldDestinationRight;
	IBOutlet id fieldEnterCodeLeft;
	IBOutlet id fieldEnterCodeDown;
	IBOutlet id fieldEnterCodeUp;
	IBOutlet id fieldEnterCodeRight;
	
	IBOutlet id checkNoCeiling;
	IBOutlet id fieldExtraLayer;
	IBOutlet id fieldInitialCF;
	IBOutlet id fieldAreaWidth;
	IBOutlet id fieldEnterCode;
	IBOutlet id fieldTileSet;
	IBOutlet id fieldPalette;
	IBOutlet id fieldBGMap;
	
	IBOutlet id tabOptions;
	IBOutlet id matrixDoorDestinations;
	//IBOutlet id matrixDoorButtons;
	IBOutlet id fieldRegionCode;
	IBOutlet id fieldPalaceCode;
	
	IBOutlet id matrixEnemySets;
	IBOutlet id matrixEnemies;
	
	IBOutlet id matrixPalettes;
	
	IBOutlet id matrixTiles;
	IBOutlet id matrixTileCodes;
	IBOutlet id matrixTiles01;
	IBOutlet id matrixAllTiles;
	IBOutlet id matrixEditorPalettes;
	IBOutlet id matrixVerticalSingle;
	IBOutlet id matrixVerticalTwo;
	IBOutlet id matrixHorizontalSingle;
	IBOutlet id matrixHorizontalDouble;
	
	IBOutlet id buttonTileCodesArrow;
	
	NSMutableData *rom;
	NSMutableArray *tiles;
	NSMutableArray *tilesItems;
	NSMutableArray *tilesEnemies;
	NSMutableArray *tilesBosses;
	NSMutableArray *tilesLink;
	NSMutableArray *tilesNumbers;
	NSMutableArray *tilesEditor;
	NSMutableArray *tiles8x8;
	NSMutableArray *tiles32x32;
	
	unsigned char currentTool;
	unsigned char mapScale;
	unsigned char cw;		// Current World (0-7)
	unsigned char ca;		// Current Area
	unsigned char cd;		// Current Area Data
	unsigned char co;		// Current Object
	unsigned char ceg;		// Current Enemy Group
	unsigned char ce;		// Current Enemy
	unsigned char objSet;   // Object Set (0-1)
	
	unsigned char selectedEnemySet;
	unsigned char selectedEnemyInSet;
	
	unsigned char teo;			// Tile Editor Object
	unsigned char tep;			// Tile Editor Palette
	unsigned char teTSA;		// Tile 0 or 1, Top-Left Top-Right Bottom-Left Bottom-Right
	unsigned char tePalette;	// Tile Editor Selected Palette
	
	unsigned char areaWidth;		// Width of the area, in screens (0-3)
	unsigned char enterCode;
	unsigned char objx,objy,length,type;
	unsigned char cfCode;
	unsigned char cfOffset;
	unsigned char cfLimit;
	unsigned char layerGroup;
	unsigned char regionCode;
	unsigned char palaceCode;
	unsigned char worldCode;
	
	unsigned char skip[4];
	unsigned char item[4][3];
	unsigned char elevatorSlot;
	unsigned char lockedDoorSlot;
	
	unsigned char objectBoxWidth;
	unsigned char objectBoxHeight;
	
	unsigned char areaData[8][0x40][0x80];
	unsigned char bgAreaData[8][8][0x80];
	unsigned char enemyData[8][0x80][0x40];
	unsigned char enemyAttributes[8][4][0x24];
	// enemy attributes 2
	// enemy attributes 3
	unsigned char connectivity[8][0x40][4];
	unsigned char doorDestinations[0x40][4];
	unsigned char itemBits[7][0x20];
	
	unsigned char areaAssoc[8][0x3F];
	unsigned char enemyAssoc[8][0x3F];
	
	unsigned char palettes[8][0xE0];
	unsigned char tileMappings[8][0x400];
	unsigned char tileCodes[8][2][0x20];
	unsigned char tileLayers[8][8][9];
	
	unsigned char fromDoor;
	
	NSRect tileCodesArrowBasePosition;
	
	unsigned const char *ptr;
}

- (void)open:(NSMutableData *)theRom;

- (void)loadTiles;
- (void)loadTilesItems;
- (void)loadEnemyAttributes;
- (void)loadTilesEnemies;
- (void)loadTilesBosses;
- (void)loadTilesLink;
- (void)loadTilesEditor;

- (NSImage *)graphicWithBlocks:(NSArray *)blocks type:(unsigned char)size;
- (NSImage *)tileBlockWithTiles:(NSArray *)tsa;
- (NSImage *)tileWithOffset:(int)os palette:(struct sCol *)pal;
- (NSImage *)graphicWithTiles:(NSArray *)tilesList type:(unsigned char)size;
- (NSImage *)emptyTile;
- (void)flipTile:(NSImage *)tile type:(int)flip;

- (void)loadPalettes;
- (void)loadTileMappings;
- (void)loadTileCodes;
- (void)loadTileLayers;

- (IBAction)changeWorld:(id)sender;

- (void)loadArea;
- (void)loadAreaData;
- (void)loadEnemyData;
- (void)loadAssociations;
- (void)loadConnectivity;
- (void)loadDoorDestinations;
- (void)loadItemBits;
- (void)loadNumbers;

- (IBAction)changeArea:(id)sender;
- (void)changeArea:(unsigned char)areaCode world:(unsigned char)worldCode enter:(unsigned char)enterCode;
- (IBAction)changeData:(id)sender;
- (IBAction)changeEnemySet:(id)sender;

- (IBAction)nextObject:(id)sender;
- (IBAction)prevObject:(id)sender;
- (void)changeObject;
- (IBAction)changeObjectPosition:(id)sender;
- (IBAction)changeObjectType:(id)sender;
- (IBAction)changeObjectItem:(id)sender;
- (unsigned char)totalObjects;
- (unsigned char)offsetForObject:(unsigned char)obj;

- (IBAction)nextEnemy:(id)sender;
- (IBAction)prevEnemy:(id)sender;
- (void)changeEnemy;
- (IBAction)changeEnemyPosition:(id)sender;
- (IBAction)changeEnemyType:(id)sender;
- (IBAction)changeEnemyScreen:(id)sender;

- (IBAction)changeExtraLayer:(id)sender;
- (IBAction)changeNoCeiling:(id)sender;
- (IBAction)changeInitialCF:(id)sender;
- (IBAction)changeAreaWidth:(id)sender;
- (IBAction)changeEnterCode:(id)sender;
- (IBAction)changeTileSet:(id)sender;
- (IBAction)changePaletteCode:(id)sender;
- (IBAction)changeBGMap:(id)sender;

- (IBAction)changeObjectSet:(id)sender;

- (IBAction)move:(id)sender;
- (IBAction)enterDoor:(id)sender;
- (IBAction)changeGraphicsCode:(id)sender;

- (IBAction)selectEnemySet:(id)sender;
- (IBAction)changeEnemyInSet:(id)sender;

- (NSString *)getObjectName:(unsigned char)objectCode position:(unsigned char)positionCode item:(unsigned char)itemCode world:(unsigned char)worldCode;
- (NSString *)getEnemyName:(unsigned char)enemyCode world:(unsigned char)worldCode;

- (IBAction)changeTileObject:(id)sender;
- (IBAction)changeSelectionTSA:(id)sender;
- (IBAction)changeTileTSA:(id)sender;

- (void)redraw;
- (void)redrawAreaData:(unsigned char)bgCode;
- (void)drawCF;

- (void)setSingle:(unsigned char)code;
- (void)setHorizontalTwo:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setHorizontalSingle:(unsigned char)code;
- (void)setHorizontalDouble:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setHorizontalTriple:(unsigned char)c1 secondCode:(unsigned char)c2 thirdCode:(unsigned char)c3;

//- (void)setVerticalUp:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setVerticalTwo:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setVerticalSingle:(unsigned char)code;
- (void)setVerticalSingle:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setVerticalDouble:(unsigned char)code;

- (void)setHouseFacade:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setWindow:(unsigned char)c1 secondCode:(unsigned char)c2;
- (void)setOther:(unsigned char)code;
- (void)setItem:(unsigned char)code;

- (unsigned char)currentWorld;
- (NSArray *)tilesEnemies;

- (unsigned int)stringToHex:(NSString *)str;
- (NSString *)hexToString:(unsigned int)hex;

- (void)outputAreaData;

@end
