Commit dfda4357 authored by Colomban Wendling's avatar Colomban Wendling

Brand new OVCC tile implementation

parent c2fb9dd3
......@@ -9,7 +9,7 @@ libovcc_la_SOURCES = enumtypes.c \
pawn.c \
player.c \
stack.c \
tile.c \
tile.vala \
tileobject.vala \
tileset.c \
tilesdef.c \
......@@ -20,7 +20,6 @@ ovccinclude_HEADERS = ovcc.h \
game.h \
player.h \
stack.h \
tile.h \
tileset.h \
tilesdef.h
......
This diff is collapsed.
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCC_TILE
#define H_OVCC_TILE
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
/**
* OVCCTileContentType:
* @OVCC_TILE_CONTENT_TYPE_NONE: None type, no content
* @OVCC_TILE_CONTENT_TYPE_FIELD: Contains a field
* @OVCC_TILE_CONTENT_TYPE_PATH: Contains a path
* @OVCC_TILE_CONTENT_TYPE_CITY: Contains a city
* @OVCC_TILE_CONTENT_TYPE_MONASTERY: Contains a monastery
*
* Content of a side or tile's centre
*
* Type of a tile content.
* It is used for the types at a tile side and center.
*/
typedef enum
{
OVCC_TILE_CONTENT_TYPE_NONE,
OVCC_TILE_CONTENT_TYPE_FIELD,
OVCC_TILE_CONTENT_TYPE_PATH,
OVCC_TILE_CONTENT_TYPE_CITY,
OVCC_TILE_CONTENT_TYPE_MONASTERY
} OVCCTileContentType;
/**
* OVCCTileSideRelation:
* @OVCC_TILE_SIDE_REL_NONE: No relations at all
* @OVCC_TILE_SIDE_REL_LEFT: Relation to the left side
* @OVCC_TILE_SIDE_REL_TOP: Relation to the top side
* @OVCC_TILE_SIDE_REL_RIGHT: Relation to the right side
* @OVCC_TILE_SIDE_REL_BOTTOM: Relation to the bottom side
*
* Relations between sides.
*
* Flags saying whether a side content is linked over the tile to other side(s).
* A relation of course says that its members are of the same type.
*/
typedef enum /*< flags >*/
{
OVCC_TILE_SIDE_REL_NONE = 0,
OVCC_TILE_SIDE_REL_LEFT = 1 << 0,
OVCC_TILE_SIDE_REL_TOP = 1 << 2,
OVCC_TILE_SIDE_REL_RIGHT = 1 << 3,
OVCC_TILE_SIDE_REL_BOTTOM = 1 << 4
} OVCCTileSideRelation;
/**
* OVCCTileSidePosition:
* @OVCC_TILE_SIDE_POS_LEFT: The side is on the left
* @OVCC_TILE_SIDE_POS_TOP: The side is on the top
* @OVCC_TILE_SIDE_POS_RIGHT: The side is on the right
* @OVCC_TILE_SIDE_POS_BOTTOM: The side is on the bottom
* @OVCC_TILE_SIDE_NUM: The tile's side count (not a position)
*
* Positions of sides.
*
* List of valid positions for a side in regard of a tile.
*/
typedef enum
{
OVCC_TILE_SIDE_POS_LEFT,
OVCC_TILE_SIDE_POS_TOP,
OVCC_TILE_SIDE_POS_RIGHT,
OVCC_TILE_SIDE_POS_BOTTOM,
OVCC_TILE_SIDE_NUM
} OVCCTileSidePosition;
/**
* OVCCTileSideAttribute:
* @OVCC_TILE_SIDE_ATTR_NONE: No attribute at all.
* @OVCC_TILE_SIDE_ATTR_BONUS: This side has a bonus.
*
* Attributes mask. This is used to represent special caracterizations present
* in the different extensions and in the original version.
*/
typedef enum /*< flags >*/
{
OVCC_TILE_SIDE_ATTR_NONE = 0,
OVCC_TILE_SIDE_ATTR_BONUS = 1<<0
} OVCCTileSideAttribute;
/**
* OVCCTileDumpLine:
* @OVCC_TILE_DUMP_TOP: Display the top line
* @OVCC_TILE_DUMP_MIDDLE_TOP: Display the middle top line
* @OVCC_TILE_DUMP_MIDDLE: Display the middle line
* @OVCC_TILE_DUMP_MIDDLE_BOTTOM: Display the middle bottom line
* @OVCC_TILE_DUMP_BOTTOM: Display the bottom line
* @OVCC_TILE_DUMP_ALL: Display the whole tile
*
* Mask saying which line(s) to write from the dump of a tile.
*
*/
typedef enum /*< flags >*/
{
OVCC_TILE_DUMP_TOP = 1<<0,
OVCC_TILE_DUMP_MIDDLE_TOP = 1<<1,
OVCC_TILE_DUMP_MIDDLE = 1<<2,
OVCC_TILE_DUMP_MIDDLE_BOTTOM = 1<<3,
OVCC_TILE_DUMP_BOTTOM = 1<<4,
OVCC_TILE_DUMP_ALL = 0x7fff /* 2^15 -1, 16 bits signed mask */
} OVCCTileDumpLine;
#define OVCC_TYPE_TILE_ID G_TYPE_UINT
#define OVCC_TYPE_TILE (ovcc_tile_get_type ())
#define OVCC_TILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OVCC_TYPE_TILE, OVCCTile))
#define OVCC_IS_TILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OVCC_TYPE_TILE))
#define OVCC_TILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), OVCC_TYPE_TILE, OVCCTileClass))
#define OVCC_IS_TILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OVCC_TYPE_TILE))
#define OVCC_TILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OVCC_TYPE_TILE), OVCCTileClass)
#define OVCC_TYPE_TILE_SIDE (ovcc_tile_side_get_type ())
#define OVCC_TILE_SIDE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OVCC_TYPE_TILE_SIDE, OVCCTileSide))
#define OVCC_IS_TILE_SIDE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OVCC_TYPE_TILE_SIDE))
/**
* OVCCTileID:
*
* Type representing a Tile ID.
*
* A tile ID is unique, and therefore two tiles sharing the same ID
* must be identical.
*/
typedef guint OVCCTileID;
typedef struct _OVCCTile OVCCTile;
typedef struct _OVCCTilePrivate OVCCTilePrivate;
typedef struct _OVCCTileClass OVCCTileClass;
/* @brief Opaque structure representing a tile's side object */
typedef struct _OVCCTileSide OVCCTileSide;
/**
* OVCCTile:
*
* The object representing a tile.
*/
struct _OVCCTile
{
GObject parent_instance;
/*< private >*/
OVCCTilePrivate *priv;
};
struct _OVCCTileClass
{
GObjectClass parent_class;
};
const gchar *ovcc_tile_content_type_to_string (OVCCTileContentType type);
OVCCTileContentType ovcc_tile_content_type_from_string (const gchar *name);
GType ovcc_tile_get_type (void) G_GNUC_CONST;
OVCCTile *ovcc_tile_new_v (OVCCTileID id,
OVCCTileSide *sides[OVCC_TILE_SIDE_NUM],
OVCCTileContentType center);
OVCCTile *ovcc_tile_new (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center);
OVCCTile *ovcc_tile_new_auto_v(OVCCTileID id,
OVCCTileSide *sides[OVCC_TILE_SIDE_NUM],
OVCCTileContentType center,
GError **error);
OVCCTile *ovcc_tile_new_auto (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center,
GError **error);
OVCCTile *ovcc_tile_dup (const OVCCTile *tile);
void ovcc_tile_dump (const OVCCTile *tile,
guint mask);
void ovcc_tile_rotate (OVCCTile *tile,
gint wise);
OVCCTileID ovcc_tile_get_id (const OVCCTile *tile);
gint ovcc_tile_get_rotation (const OVCCTile *tile);
OVCCTileContentType ovcc_tile_get_center_type (const OVCCTile *tile);
OVCCTileSide *ovcc_tile_get_side (const OVCCTile *tile,
OVCCTileSidePosition side);
/**
* ovcc_tile_get_side_content_type:
* @tile: A tile
* @side: A side identifier
*
* Gets the type of a one side of a tile.
*
* This is actually a macro, hence you can use it same as it was a function but
* getting its address.
*
* Returns: the type of the side @side of the given tile.
*/
#define ovcc_tile_get_side_content_type(tile, side) \
(ovcc_tile_side_get_content_type (ovcc_tile_get_side (tile, side)))
GType ovcc_tile_side_get_type (void) G_GNUC_CONST;
OVCCTileSide *ovcc_tile_side_new (OVCCTileContentType side_type,
OVCCTileSideRelation rel_bits,
OVCCTileSideAttribute attr_bits);
OVCCTileSide *ovcc_tile_side_dup (const OVCCTileSide *side);
OVCCTileSide *ovcc_tile_side_ref (OVCCTileSide *side);
void ovcc_tile_side_unref (OVCCTileSide *side);
OVCCTileContentType ovcc_tile_side_get_content_type (const OVCCTileSide *side);
OVCCTileSideRelation ovcc_tile_side_get_relations (const OVCCTileSide *side);
OVCCTileSideAttribute ovcc_tile_side_get_attributes (const OVCCTileSide *side);
G_END_DECLS
#endif /* guard */
/*
*
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OVCC
{
public errordomain TileError
{
INVALID_TILE_ID
}
public struct TileID: uint {}
/**
* Represents a tile
*
* @see TileObject
*/
public class Tile : Object
{
/* private data */
private SList<TileObject> _objects;
/* properties */
public TileID id { get; construct; }
public SList<TileObject> objects {
get {
return this._objects;
}
construct {
this._objects = value.copy ();
}
}
/* methods */
public Tile (TileID id,
SList<TileObject> objects)
{
Object (id: id, objects: objects);
}
public Tile dup ()
{
return new Tile (this.id, this._objects);
}
/**
* Rotates the tile
*
* @param wise how much to rotate the object
*/
public void rotate (int wise)
{
wise = (int)Utils.clock_mod (wise, 4);
foreach (var o in this._objects) {
o.rotate (wise);
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment