Logo Search packages:      
Sourcecode: freecraft version File versions

unittype.h

//   ___________             _________                _____  __
//   \_       _____/______   ____   ____ \_   ___ \____________ _/ ____\/  |_
//    |    __) \_  __ \_/ __ \_/ __ \/    \  \/\_  __ \__  \\   __\\   __|
//    |     \   |  | \/\  ___/\  ___/\     \____|  | \// __ \|  |   |  |
//    \___  /   |__|    \___  >\___  >\______  /|__|  (____  /__|   |__|
//      \/            \/         \/      \/              \/
//  ______________________                           ______________________
//                  T H E   W A R   B E G I N S
//       FreeCraft - A free fantasy real time strategy game engine
//
/**@name unittype.h     -     The unit-types headerfile. */
//
//    (c) Copyright 1998-2002 by Lutz Sammer
//
//    FreeCraft 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; only version 2 of the License.
//
//    FreeCraft 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.
//
//    $Id: unittype.h,v 1.82 2003/01/22 06:32:54 jsalmon3 Exp $

#ifndef __UNITTYPE_H__
#define __UNITTYPE_H__

//@{

/*----------------------------------------------------------------------------
--    Documentation
----------------------------------------------------------------------------*/

/**
**    @struct _unit_type_ unittype.h
**
**    \#include "unittype.h"
**
**    typedef struct _unit_type_ UnitType;
**
**    This structure contains the informations that are shared between all
**    units of the same type and determins if an unit is a building,
**    a person, ...
**
**    The unit-type structure members:
**
**    UnitType::OType
**
**          Object type (future extensions).
**
**    UnitType::Ident
**
**          Unique identifier of the unit-type, used to reference it in
**          config files and during startup. As convention they start with
**          "unit-" fe. "unit-farm".
**          @note Don't use this member in game, use instead the pointer
**          to this structure. See UnitTypeByIdent().
**
**    UnitType::Name
**
**          Pretty name shown by the engine. The name should be shorter
**          than 17 characters and no word can be longer than 8 characters. 
**
**    UnitType::SameSprite
**
**          Identifier of an unit-type with this are the sprites shared.
**
**    UnitType::File[::TilesetMax]
**
**          Path file name of sprite files for the different tilesets.
**          @note It is planned to change this to support more and 
**          better tilesets.
**
**    UnitType::SpriteFile
**
**          Path file name of shadow sprite file for the different tilesets.
**
**    UnitType::Width UnitType::Height
**
**          Size of a sprite frame in pixels. All frames of a sprite have
**          the same size. Also all sprites (tilesets) must have the same
**          size.
**
**    UnitType::ShadowWidth UnitType::ShadowHeight
**
**          Size of a shadow sprite frame in pixels. All frames of a sprite
**          have the same size. Also all sprites (tilesets) must have the
**          same size.
**
**    UnitType::ShadowOffset
**
**          Vertical offset to draw the shadow in pixels.
**
**    UnitType::Animations
**
**          Animation scripts for the different actions. Currently the
**          animations still, move, attack and die are supported.
**          @see Animations @see _animations_
**          @see Animation @see _animation_
**
**    UnitType::Icon
**
**          Icon to display for this unit-type. Contains configuration and
**          run time variable.
**          @note This icon can be used for training, but isn't used.
**
**    UnitType::Missile
**
**          Configuration and run time variable of the missile weapon.
**          @note It is planned to support more than one weapons.
**          And the sound of the missile should be used as fire sound.
**
**    UnitType::CorpseName
**
**          Corpse unit-type name, should only be used during setup.
**
**    UnitType::CorpseType
**
**          Corpse unit-type pointer, only this should be used during run
**          time. Many unit-types can share the same corpse.
**
**    UnitType::CorpseScript
**
**          Index into corpse animation script. Used if unit-types share
**          the same corpse but have different animations.
**
**    UnitType::_Speed
**
**          Non upgraded movement speed.
**          @note Until now we didn't support speed upgrades.
**
**    FIXME: continue this documentation
**
**    UnitType::Construction
**
**          What is shown in construction phase.
**
**    UnitType::SightRange
**
**          Sight range
**
**    UnitType::_HitPoints
**
**          Maximum hit points
**
**    UnitType::_MaxMana
**
**          Maximum mana points
**
**    UnitType::Magic
**
**          Unit is a mage
**
**    UnitType::_Costs[::MaxCosts]
**
**          How many resources needed
**
**    UnitType::TileWidth
**
**          Tile size on map width
**
**    UnitType::TileHeight
**
**          Tile size on map height
**
**    UnitType::BoxWidth
**
**          Selected box size width
**
**    UnitType::BoxHeight
**
**          Selected box size height
**
**    UnitType::NumDirections
**
**          Number of directions the unit can face
**
**    UnitType::MinAttackRange
**
**          Minimal attack range
**
**
**    UnitType::_AttackRange
**
**          How far can the unit attack
**
**    UnitType::ReactRangeComputer
**
**          Reacts on enemy for computer
**
**    UnitType::ReactRangePerson
**
**          Reacts on enemy for person player
**
**    UnitType::_Armor
**
**          Amount of armor this unit has
**
**    UnitType::Priority
**
**          Priority value / AI Treatment
**
**    UnitType::_BasicDamage
**
**          Basic damage dealt
**
**    UnitType::_PiercingDamage
**
**          Piercing damage dealt
**
**    UnitType::WeaponsUpgradable
**
**          Weapons could be upgraded
**
**    UnitType::ArmorUpgradable
**
**          Armor could be upgraded
**
**    UnitType::UnitType
**
**          Land / fly / naval
**
**          FIXME: original only visual effect, we do more with this!
**
**    UnitType::DecayRate
**
**          Decay rate in 1/6 seconds
**
**    UnitType::AnnoyComputerFactor
**
**          How much this annoys the computer
**
**          FIXME: not used
**
**    UnitType::MouseAction
**
**          Right click action
**
**    UnitType::Points
**
**          How many points you get for unit
**
**    UnitType::CanTarget
**
**          Which units can it attack
**
**    UnitType::LandUnit
**
**          Land animated
**
**    UnitType::AirUnit
**
**          Air animated
**
**    UnitType::SeaUnit
**
**          Sea animated
**
**    UnitType::ExplodeWhenKilled
**
**          Death explosion animated
**
**    UnitType::Critter
**
**          Unit is controlled by nobody
**
**    UnitType::Building
**
**          Building
**
**    UnitType::Submarine
**
**          Is only visible by CanSeeSubmarine
**
**    UnitType::CanSeeSubmarine
**
**          Only this units can see Submarine
**
**    UnitType::CowerWorker
**
**          Is a worker, runs away if attcked
**
**    UnitType::Tanker
**
**          FIXME: used? Can transport oil
**
**    UnitType::Transporter
**
**          Can transport units
**
**    UnitType::GivesOil
**
**          We get here oil
**
**    UnitType::StoresGold
**
**          We can store oil/gold/wood here
**
**    UnitType::Vanishes
**
**          Corpes & destroyed places
**
**    UnitType::GroundAttack
**
**          Can do command ground attack
**
**    UnitType::IsUndead
**
**          Unit is already dead
**
**    UnitType::ShoreBuilding
**
**          Building must be build on coast
**
**    UnitType::CanCastSpell
**
**          Unit is able to use spells
**
**    UnitType::StoresWood
**
**          We can store wood here
**
**    UnitType::CanAttack
**
**          FIXME: docu
**
**    UnitType::Tower
**
**          FIXME: docu
**
**    UnitType::OilPatch
**
**          FIXME: docu
**
**    UnitType::GoldMine
**
**          FIXME: docu
**
**    UnitType::Hero
**
**          FIXME: docu
**
**    UnitType::StoresOil
**
**          We can store oil here
**
**    UnitType::Volatile
**
**          Invisiblity/unholy armor kills unit
**
**    UnitType::CowerMage
**
**          FIXME: docu
**
**    UnitType::Organic
**
**          Organic can be healed
**
**    UnitType::SelectableByRectangle
**
**          Selectable with mouse rectangle
**
**    UnitType::Teleporter
**
**          Can teleport other units.
**
**    UnitType::Sound
**
**          Sounds for events
**
**    UnitType::Weapon
**
**          Currently sound for weapon
**
**    FIXME: temporary solution
**
**    UnitType::Supply
**
**          Food supply
**
**    UnitType::Demand
**
**          Food demand
**
**    UnitType::ImproveIncomes[::MaxCosts]
**
**          Gives the player an improved income.
**
**    UnitType::FieldFlags
**
**          Flags that are set, if an unit enters a map field or cleared, if
**          an unit leaves a map field.
**
**    UnitType::MovementMask
**
**          Movement mask, this value is and'ed to the map field flags, to
**          see if an unit can enter or placed on the map field.
**
**    UnitType::Stats[::PlayerMax]
**
**          Unit status for each player
**          FIXME: This stats should? be moved into the player struct
**
**    UnitType::Type
**
**          Type as number
**          FIXME: Should us a general name f.e. Slot here?
**
**    UnitType::Property
**
**          CCL property storage
**
**    UnitType::Sprite
**
**          Sprite images
**
**    UnitType::ShadowSprite
**
**          Shadow sprite images
**
**    UnitType::PlayerColorSprite
**
**          Sprite images of the player colors.  This image is drawn
**          over UnitType::Sprite.  Used with OpenGL only.
*/

/*----------------------------------------------------------------------------
--    Includes
----------------------------------------------------------------------------*/

#include "video.h"
#include "icons.h"
#include "sound_id.h"
#include "unitsound.h"
#include "upgrade_structs.h"
#include "construct.h"

/*----------------------------------------------------------------------------
--    Declarations
----------------------------------------------------------------------------*/

/**
**    Defines the animation for different actions.
*/
00446 typedef struct _animation_ {
    unsigned char Flags;            /// Flags for actions
00448     signed char         Pixel;            /// Change the position in pixels
00449     unsigned char Sleep;            /// Wait for next animation
00450     int                 Frame;            /// Sprite-frame to display
} Animation;

#define AnimationRestart      1     /// Restart animation
#define AnimationReset        2     /// Animation could here be aborted
#define AnimationSound        4     /// Play sound
#define AnimationMissile      8     /// Fire projectil
#define AnimationEnd          0x80  /// Animation end in memory

/**
**    Define all animations scripts of an unittype.
*/
00462 typedef struct __animations__ {
    Animation*    Still;                  /// Standing still
00464     Animation*    Move;             /// Unit moving
00465     Animation*    Attack;                 /// Unit attacking/working
00466     Animation*    Die;              /// Unit dieing
00467     Animation**   Extend;                 /// For future extensions
} Animations;

/**
**      Missile type definition (used in config tables)
**
**    @todo Shouldn't I move this into missle.h?
*/
00475 typedef struct _missile_config_ {
    char*   Name;             /// Config missile name
00477     MissileType*Missile;            /// Identifier to use to run time
} MissileConfig;

/**
**    Typedef of base structure of unit-type
*/
typedef struct _unit_type_ UnitType;

    /// Base structure of unit-type
00486 struct _unit_type_ {
    const void*   OType;                  /// Object type (future extensions)

00489     char*   Ident;                  /// Identifier
00490     char*   Name;             /// Pretty name shown from the engine
00491     char*   SameSprite;       /// Unit-type shared sprites
00492     char*   File[TilesetMax]; /// Sprite files
00493     char*   ShadowFile;       /// Shadow file

00495     int           Width;                  /// Sprite width
00496     int           Height;                 /// Sprite height
00497     int           ShadowWidth;            /// Shadow sprite width
00498     int           ShadowHeight;           /// Shadow sprite height
00499     int           ShadowOffset;           /// Shadow vertical offset

00501     Animations*   Animations;       /// Animation scripts

00503     IconConfig    Icon;             /// Icon to display for this unit
00504     MissileConfig Missile;          /// Missile weapon

00506     char*   CorpseName;       /// Corpse type name
00507     UnitType*     CorpseType;       /// Corpse unit-type
00508     int           CorpseScript;           /// Corpse script start

00510     int           _Speed;                 /// Movement speed

// this is taken from the UDTA section
00513     Construction*Construction;            /// What is shown in construction phase
00514     int           _SightRange;            /// Sight range
00515     int           _HitPoints;       /// Maximum hit points
00516     unsigned      _MaxMana : 8;           /// Maximum mana points
    // FIXME: only flag
00518     int           Magic;                  /// Unit can cast spells

00520     int           _Costs[MaxCosts]; /// How many resources needed

00522     int           TileWidth;        /// Tile size on map width
00523     int           TileHeight;       /// Tile size on map height
00524     int           BoxWidth;         /// Selected box size width
00525     int           BoxHeight;        /// Selected box size height
00526     int           NumDirections;          /// Number of directions unit can face
00527     int           MinAttackRange;         /// Minimal attack range
00528     int           _AttackRange;           /// How far can the unit attack
00529     int           ReactRangeComputer;     /// Reacts on enemy for computer
00530     int           ReactRangePerson; /// Reacts on enemy for person player
00531     int           _Armor;                 /// Amount of armor this unit has
00532     int           Priority;         /// Priority value / AI Treatment
00533     int           _BasicDamage;           /// Basic damage dealt
00534     int           _PiercingDamage;  /// Piercing damage dealt
00535     int           WeaponsUpgradable;      /// Weapons could be upgraded
00536     int           ArmorUpgradable;  /// Armor could be upgraded
    // FIXME: original only visual effect, we do more with this!
    enum {
      UnitTypeLand,                 /// Unit lives on land
00540       UnitTypeFly,                  /// Unit lives in air
00541       UnitTypeNaval,                /// Unit lives on water
    }       UnitType;         /// Land / fly / naval
00543     int           DecayRate;        /// Decay rate in 1/6 seconds
    // FIXME: not used
00545     int           AnnoyComputerFactor;    /// How much this annoys the computer
00546     int           MouseAction;            /// Right click action
#define MouseActionNone       0           /// Nothing
#define MouseActionAttack     1           /// Attack
#define MouseActionMove       2           /// Move
#define MouseActionHarvest    3           /// Harvest or mine gold
#define MouseActionHaulOil    4           /// Haul oil
#define MouseActionDemolish   5           /// Demolish
#define MouseActionSail       6           /// Sail
    int           Points;                 /// How many points you get for unit
00555     int           CanTarget;        /// Which units can it attack
#define CanTargetLand   1                 /// Can attack land units
#define CanTargetSea    2                 /// Can attack sea units
#define CanTargetAir    4                 /// Can attack air units

    unsigned LandUnit : 1;          /// Land animated
00561     unsigned AirUnit : 1;           /// Air animated
00562     unsigned SeaUnit : 1;           /// Sea animated
00563     unsigned ExplodeWhenKilled : 1; /// Death explosion animated
00564     unsigned Critter : 1;           /// Unit is controlled by nobody
00565     unsigned Building : 1;          /// Building
00566     unsigned Submarine : 1;         /// Is only visible by CanSeeSubmarine
00567     unsigned CanSeeSubmarine : 1;   /// Only this units can see Submarine
00568     unsigned CowerWorker : 1;       /// Is a worker, runs away if attcked
00569     unsigned Tanker : 1;            /// FIXME: used? Can transport oil
00570     unsigned Transporter : 1;       /// Can transport units
00571     unsigned GivesOil : 1;          /// We get here oil
00572     unsigned StoresGold : 1;        /// We can store oil/gold/wood here
00573     unsigned Vanishes : 1;          /// Corpes & destroyed places
00574     unsigned GroundAttack : 1;            /// Can do command ground attack
00575     unsigned IsUndead : 1;          /// Unit is already dead
00576     unsigned ShoreBuilding : 1;           /// Building must be build on coast
00577     unsigned CanCastSpell : 1;            /// Unit is able to use spells
00578     unsigned StoresWood : 1;        /// We can store wood here
00579     unsigned CanAttack : 1;         /// Unit can attack
00580     unsigned Tower : 1;             /// Unit can attack, but not move
00581     unsigned OilPatch : 1;          /// Platform can be build here
00582     unsigned GoldMine : 1;          /// Gold can be collected here
00583     unsigned Hero : 1;              /// Is hero only used for triggers 
00584     unsigned StoresOil : 1;         /// We can store oil here
00585     unsigned Volatile : 1;          /// Invisiblity/unholy armor kills unit
00586     unsigned CowerMage : 1;         /// FIXME: docu
00587     unsigned Organic : 1;           /// Organic can be healed

00589     unsigned SelectableByRectangle : 1;   /// Selectable with mouse rectangle
00590     unsigned Teleporter : 1;        /// Can teleport other units.

00592     UnitSound Sound;                /// Sounds for events
    // FIXME: temporary solution
00594     WeaponSound Weapon;                 /// Currently sound for weapon

00596     int           Supply;                 /// Food supply
00597     int           Demand;                 /// Food demand

// --- FILLED UP ---

00601     int           ImproveIncomes[MaxCosts];/// Gives player an improved income

00603     unsigned      FieldFlags;       /// Unit map field flags
00604     unsigned      MovementMask;           /// Unit check this map flags for move

      // FIXME: This stats should? be moved into the player struct
00607     UnitStats Stats[PlayerMax];           /// Unit status for each player

      // FIXME: Should us a general name f.e. Slot here?
00610     int           Type;             /// Type as number

00612     void*   Property;         /// CCL property storage

00614     Graphic*      Sprite;                 /// Sprite images
00615     Graphic*      ShadowSprite;           /// Shadow sprite image
#ifdef USE_OPENGL
    Graphic*      PlayerColorSprite[PlayerMax]; /// Sprites with player colors
#endif
};

    // FIXME: ARI: should be dynamic (ccl..), JOHNS: Pud only supports 255.
    /// How many unit-types are currently supported
#define UnitTypeMax     0xFF

/*----------------------------------------------------------------------------
--    Variables
----------------------------------------------------------------------------*/

extern const char UnitTypeType[];   /// Unit-type type
extern UnitType* UnitTypes;         /// All unit-types
extern int NumUnitTypes;            /// Number of unit-types made

// FIXME: this hardcoded unit-types must be removed!!
extern UnitType*UnitTypeOilPatch;   /// Oil patch unit-type pointer
extern UnitType*UnitTypeGoldMine;   /// Gold-mine unit-type pointer
extern UnitType*UnitTypeHumanTanker;      /// Orc tanker unit-type pointer
extern UnitType*UnitTypeOrcTanker;  /// Human tanker unit-type pointer
extern UnitType*UnitTypeHumanTankerFull;/// Orc tanker full unit-type pointer
extern UnitType*UnitTypeOrcTankerFull;    /// Human tanker full unit-type pointer
extern UnitType*UnitTypeHumanWorker;      /// Human worker
extern UnitType*UnitTypeOrcWorker;  /// Orc worker
extern UnitType*UnitTypeHumanWorkerWithGold;    /// Human worker with gold
extern UnitType*UnitTypeOrcWorkerWithGold;      /// Orc worker with gold
extern UnitType*UnitTypeHumanWorkerWithWood;    /// Human worker with wood
extern UnitType*UnitTypeOrcWorkerWithWood;      /// Orc worker with wood
extern UnitType*UnitTypeHumanWall;  /// Human wall
extern UnitType*UnitTypeOrcWall;    /// Orc wall
extern UnitType*UnitTypeCritter;    /// Critter unit-type pointer
extern UnitType*UnitTypeBerserker;  /// Berserker for berserker regeneration

extern char** UnitTypeWcNames;            /// Mapping wc-number 2 symbol

/*----------------------------------------------------------------------------
--    Functions
----------------------------------------------------------------------------*/

extern void UnitTypeCclRegister(void);    /// Register ccl features

extern void UpdateStats(int reset_to_default);        /// Update unit stats
extern void ParsePudUDTA(const char*,int); /// Parse pud udta table
extern UnitType* UnitTypeByIdent(const char*);  /// Get unit-type by ident
extern UnitType* UnitTypeByWcNum(unsigned);     /// Get unit-type by wc number

    /// Get the animations structure by ident
extern Animations* AnimationsByIdent(const char* ident);

extern void SaveUnitTypes(FILE* file);    /// Save the unit-type table
extern UnitType* NewUnitTypeSlot(char*);/// Allocate an empty unit-type slot
    /// Draw the sprite frame of unit-type
extern void DrawUnitType(const UnitType* type,int frame,int x,int y);

extern void InitUnitTypes(int reset_player_stats);    /// Init unit-type table
extern void LoadUnitTypes(void);    /// Load the unit-type data
extern void CleanUnitTypes(void);   /// Cleanup unit-type module

//@}

#endif      // !__UNITTYPE_H__

Generated by  Doxygen 1.6.0   Back to index