____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

unit_draw.cpp File Reference

The draw routines for units. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include <vector>
#include "video.h"
#include "editor.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "unit_cache.h"
#include "map.h"
#include "construct.h"
#include "cursor.h"
#include "interface.h"
#include "font.h"
#include "ui.h"
#include "script.h"

Go to the source code of this file.

Classes

class  Decoration
class  DecoSpriteType

Functions

void DrawUnitSelection (const CUnit *unit)
void DrawSelection (Uint32 color, int x1, int y1, int x2, int y2)
int GetSpriteIndex (const std::string &spriteName)
static int CclDefineSprites (lua_State *l)
void DecorationCclRegister (void)
 < Register CCL decorations features
void LoadDecorations (void)
 Clean the decorations (health,mana) of units.
void CleanDecorations (void)
 Draw unit's shadow.
void UpdateUnitVariables (const CUnit *unit)
static void DrawDecoration (const CUnit *unit, const CUnitType *type, int x, int y)
void DrawShadow (const CUnit *unit, const CUnitType *type, int frame, int x, int y)
 Draw all units visible on map in viewport.
static void GetOrderPosition (const CUnit *unit, const COrder *order, int *x, int *y)
static void ShowSingleOrder (const CUnit *unit, int x1, int y1, const COrder *order)
void ShowOrder (const CUnit *unit)
static void DrawInformations (const CUnit *unit, const CUnitType *type, int x, int y)
static void DrawConstructionShadow (const CUnit *unit, const CConstructionFrame *cframe, int frame, int x, int y)
static void DrawConstruction (const CUnit *unit, const CConstructionFrame *cframe, const CUnitType *type, int frame, int x, int y)
static int DrawLevelCompare (const void *v1, const void *v2)
int FindAndSortUnits (const CViewport *vp, CUnit **table, int tablesize)
 Show a unit's orders.

Variables

static DecoSpriteType DecoSprite
 All sprite's infos.
unsigned long ShowOrdersCount
 Show orders for some time.
const CViewportCurrentViewport
 FIXME: quick hack for split screen.


Detailed Description

The draw routines for units.

Definition in file unit_draw.cpp.


Function Documentation

static int CclDefineSprites ( lua_State *  l  )  [static]

Define the sprite to show variables.

Parameters:
l Lua_state

Definition at line 215 of file unit_draw.cpp.

References _C_, Decoration::File, GetSpriteIndex(), Decoration::Height, Decoration::HotX, Decoration::HotY, LuaError, LuaToNumber(), LuaToString(), DecoSpriteType::Name, DecoSpriteType::SpriteArray, and Decoration::Width.

Referenced by DecorationCclRegister().

void CleanDecorations ( void   ) 

Draw unit's shadow.

Clean decorations.

Definition at line 300 of file unit_draw.cpp.

References CGraphic::Free(), DecoSpriteType::Name, and DecoSpriteType::SpriteArray.

Referenced by CleanModules().

void DecorationCclRegister ( void   ) 

< Register CCL decorations features

Register CCL features for decorations.

Definition at line 279 of file unit_draw.cpp.

References CclDefineSprites(), and Lua.

Referenced by InitCcl().

static void DrawConstruction ( const CUnit unit,
const CConstructionFrame cframe,
const CUnitType type,
int  frame,
int  x,
int  y 
) [static]

static void DrawConstructionShadow ( const CUnit unit,
const CConstructionFrame cframe,
int  frame,
int  x,
int  y 
) [static]

static void DrawDecoration ( const CUnit unit,
const CUnitType type,
int  x,
int  y 
) [static]

static void DrawInformations ( const CUnit unit,
const CUnitType type,
int  x,
int  y 
) [static]

static int DrawLevelCompare ( const void *  v1,
const void *  v2 
) [static]

Compare what order 2 units should be drawn on the map

Parameters:
v1 First Unit to compare (**Unit)
v2 Second Unit to compare (**Unit)
Returns:
-1 for v1 < v2, 1 for v2 < v1

Definition at line 892 of file unit_draw.cpp.

References CUnitType::CorpseType, CUnitType::DrawLevel, CUnitType::Height, CUnit::IY, CUnit::Orders, CUnit::Slot, TileSizeY, CUnit::Type, UnitActionDie, CUnit::X, and CUnit::Y.

Referenced by FindAndSortUnits().

void DrawSelection ( Uint32  color,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw selected corners around the unit.

Parameters:
color Color to draw corners.
x1,y1 Coordinates of the top left corner.
x2,y2 Coordinates of the bottom right corner.

Definition at line 172 of file unit_draw.cpp.

References CVideo::DrawHLineClip(), CVideo::DrawVLineClip(), and Video.

Referenced by DrawUnitSelection(), and ShowSingleOrder().

void DrawShadow ( const CUnit unit,
const CUnitType type,
int  frame,
int  x,
int  y 
)

Draw all units visible on map in viewport.

Draw unit's shadow.

Parameters:
unit Pointer to the unit.
type Pointer to the unit type.
frame Frame number
x Screen X position of the unit.
y Screen Y position of the unit.
Todo:
FIXME: combine new shadow code with old shadow code.

Definition at line 410 of file unit_draw.cpp.

References Assert, CGraphic::DrawFrameClip(), CGraphic::DrawFrameClipX(), CUnitType::Flip, CUnitType::NumDirections, CUnitType::OffsetX, CUnitType::OffsetY, CUnit::Orders, CUnitType::ShadowHeight, CUnitType::ShadowOffsetX, CUnitType::ShadowOffsetY, CUnitType::ShadowSprite, CUnitType::ShadowWidth, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, CUnit::Type, and UnitActionDie.

Referenced by CUnit::Draw(), and DrawBuildingCursor().

void DrawUnitSelection ( const CUnit unit  ) 

int FindAndSortUnits ( const CViewport vp,
CUnit **  table,
int  tablesize 
)

Show a unit's orders.

Find all units to draw in viewport.

Parameters:
vp Viewport to be drawn.
table Table of units to return in sorted order
tablesize Size of table array

Definition at line 930 of file unit_draw.cpp.

References DrawLevelCompare(), CUnit::IsVisibleInViewport(), CViewport::MapHeight, CViewport::MapWidth, CViewport::MapX, CViewport::MapY, CUnitCache::Select(), and UnitCache.

Referenced by CViewport::Draw().

static void GetOrderPosition ( const CUnit unit,
const COrder order,
int *  x,
int *  y 
) [static]

Get the location of a unit's order.

Parameters:
unit Pointer to unit.
order Pointer to order.
x Resulting screen X cordinate.
y Resulting screen Y cordinate.

Definition at line 458 of file unit_draw.cpp.

References COrder::Action, COrder::Goal, CUnit::IX, CUnit::IY, CViewport::Map2ViewportX(), CViewport::Map2ViewportY(), CUnit::Removed, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, COrder::Type, CUnit::Type, UnitActionBuild, COrder::X, CUnit::X, COrder::Y, and CUnit::Y.

Referenced by ShowOrder(), and ShowSingleOrder().

int GetSpriteIndex ( const std::string &  spriteName  ) 

Return the index of the sprite.

Parameters:
spriteName Name of the sprite.
Returns:
Index of the sprite. -1 if not found.

Definition at line 197 of file unit_draw.cpp.

References int(), and DecoSpriteType::Name.

Referenced by CclDefineDecorations(), and CclDefineSprites().

void LoadDecorations ( void   ) 

Clean the decorations (health,mana) of units.

Load decoration.

Definition at line 287 of file unit_draw.cpp.

References CGraphic::New(), ShowLoadProgress(), and DecoSpriteType::SpriteArray.

Referenced by CreateGame(), and LoadModules().

void ShowOrder ( const CUnit unit  ) 

static void ShowSingleOrder ( const CUnit unit,
int  x1,
int  y1,
const COrder order 
) [static]

void UpdateUnitVariables ( const CUnit unit  ) 


Variable Documentation

FIXME: quick hack for split screen.

CurrentViewport.

Definition at line 104 of file unit_draw.cpp.

Referenced by CViewport::Draw(), and Missile::DrawMissile().

All sprite's infos.

Definition at line 88 of file unit_draw.cpp.

unsigned long ShowOrdersCount

Show orders for some time.

Todo:
could be moved into the user interface ?
Show orders for some time

Definition at line 90 of file unit_draw.cpp.

Referenced by DoRightButton(), CViewport::Draw(), and SendCommand().


Generated on Sat Feb 21 00:28:22 2009 for Bos Wars by  doxygen 1.5.6