Added Free Heroes 2 game engine

This commit is contained in:
pelya
2010-11-12 17:37:35 +02:00
parent d52fe9940c
commit 51af6aee88
407 changed files with 247046 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
# The application settings for Android libSDL port
AppSettingVersion=15
LibSdlVersion=1.2
AppName="Free Heroes 2"
AppFullName=com.googlecode.fheroes2
ScreenOrientation=h
InhibitSuspend=n
AppDataDownloadUrl="Game data|keys.zip"
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
AppNeedsArrowKeys=n
AppNeedsTextInput=y
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n
NonBlockingSwapBuffers=n
RedefinedKeys="LCTRL m t h e"
AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
MultiABI=n
AppVersionCode=100
AppVersionName="1.0.0"
CompiledLibraries="sdl_net sdl_mixer sdl_image png"
CustomBuildScript=n
AppCflags='-fexceptions -finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_NET -DWITH_XML -DWITH_IMAGE'
AppLdflags=''
AppSubdirsBuild=''
AppUseCrystaXToolchain=y
AppCmdline='fheroes -d'
ReadmeText='^You may press "Home" now - the data will be downloaded in background'

Binary file not shown.

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,28 @@
# makefile
# project: Free Heroes2
#
# Options:
# DEBUG: build in debug mode
# RELEASE: build with addons extensions
#
# WITHOUT_ZLIB: build without zlib (disable comressed save files)
# WITHOUT_MIXER: build without SDL_mixer library
# WITHOUT_AUDIOCD: disable audio cd support
# WITHOUT_NETWORK: build without SDL_net library
# WITHOUT_UNICODE: build without unicode (disable translation and ttf font)
# WITHOUT_IMAGE: build without SDL_image library (disable cache image, icn2png)
# WITHOUT_EDITOR
# WITHOUT_XML: skip build tinyxml, used for load alt. resources
# WITH_TOOLS: build tools
TARGET := fheroes2
all:
$(MAKE) -C src
@cp src/dist/$(TARGET) .
#ifndef WITHOUT_UNICODE
# @cp src/dist/$(TARGET).pot files/lang
#endif
clean:
$(MAKE) -C src clean

View File

@@ -0,0 +1,26 @@
*****************************************
AUTHORS
*****************************************
_________________________
The Free Heroes2 project
~~~~~~~~~~~~~~~~~~~~~~~~~
Andrey Afletdinov, <fheroes2@gmail.com>
* general support
Josh Matthews, <josh@joshmatthews.net>
* assorted updates and fixes
Vasya Makarov, <drmoriarty@users.sourceforge.net>
Peter Lemenkov, <peter_lemenkov@users.sourceforge.net>
* minor updates and fixes
Steven Aus, <stevenaus@users.sourceforge.net>
* heroes2 game expert
Igor Orlov, <igororlov@inbox.ru>
* Russian translation
PhoneixS <phoneixsegovia@gmail.com>
* Spanish translation

View File

@@ -0,0 +1,455 @@
SVN - up to r1945
Sep, 18, 2010
+ Updated: Dialog::ThievesGuild
+ Fixed: wince double click, wince auto videomode
+ Updated translations: russian, swedish, spanish
+ Added options: "heroes: recalculate movement points after creatures movement"
+ Fixed Heroes::ActionToDwellingRecruitMonster and Heroes::ActionToDwellingBattleMonster
+ Added "Anduran Battle Garb" artifact combined
+ Added: multiple icons for mass spells
+ Added options: heroes: surrendering gives some experience
+ Updated monster animation on maps
+ Fixed "Ultimate Stuff" sprite for Loyalty version
+ Fixed Maps::Tiles::GoodForUltimateArtifact
+ Added stats files (stevenaus ver.)
+ Fixed result for wins side
+ Fixed race/skill weight is 0, Skill::Secondary::GetWeightSkillFromRace
+ Fixed out of range for Interface::Basic::GetDimensionDoorDestination
+ Fixed zlogo leak memory
+ Added switch on/off mouse emulation
+ Added option: remember mp/sp for surrendering/retreating heroes
+ Added option for recruit hero cost to be dependent on hero level
+ Fixed default extra haste, slow values
+ Added optins: allow buy spellbook from shrines
+ Added: allow buy spellbook and visit Mage Guild for unions
+ Fixed autosave remember
+ Fixed scholar repeat dialog
Jun, 06, 2010
+ Added feature: Eagle Eye Scholar
+ Fixed heroes meetings and castle visit, with unions disabled
+ Added options: world: only the first monster will attack (H2 orig).
+ Added dynamic castle bottom passable check
+ Added dynamic intarface settings
+ Updated translation, update changelog, release out 1895
+ Fixed multiple maps: human only settings
+ Fixed multiplayer map filter
+ Fixed multiplayer map filter
+ Fixed necromancer morale info
+ Added fix for race with custom portrait
+ Added random dwelling2 builds for default castle
+ Fixed fullscreen options
+ Fixed pockept keyb, and fixed build
+ Added pocketpc virtual keyboard, remove dialog_chat.cpp
May, 27, 2010
+ Update translation files
+ Fixed: genie ability, added custom genie ability, rename battle.xml to animations.xml
+ Fixed: blind spell, dwarf magic resist, resurect dead troop
+ Fixed: necromancer morale info
+ Fixed: necromancer skeletons up
+ Fixed: battle catapult targets
+ Updated: diplomacy for surrender and join monster
+ Updated: gameover conditions (WINS_SIDE), added unions (alliance)
+ Added: pocketpc virtual keyboard
+ Fixed: dwelling count with begin week
+ Fixed: World::NewMonth actions
+ Fixed: multiplayer map filter
Apr, 24, 2010
+ Added: extended scouting capability
+ Fixed: manual set hero portrait and class type
+ Fixed: spell duration for magic monsters
+ Fixed: air element + lightning 200% damage
+ Fixed: elemental immunable mind spells
+ Added: groupped/spread battle format
+ Added: hero patrol mode
+ Update: wins/loss game conditions, update game info dialog
+ Added: battle hard skip with +2 defense
+ Fixed: autosave remember settings
+ Fixed: set guardian with last troop
+ Added: pickup artifact scenario messages
+ Added: artifacts affinities HideousMask, StatesmanQuill, CrystalBall, extra settings CrystalBall added spells Visions and IdentifyHero
+ Fixed: broken bridge animation
Apr, 9, 2010
+ Update latest translation files from launchpad
+ Update battle: fixed blind, paralize and stone
+ Added options, battle: skip turn and +2 defence
+ Fixed original version Slow and Haste speed
+ Added check save format
+ Updated battle: added check end battle after tower action
+ Fixed shipyard check
+ Updated battle: added check for probable overflow count troop
+ Added settings: no in-built requirements artifacts
+ Fixed mageguild learn hero
+ Fixed castle building animation
+ Fixed archers attack
+ Added settings: archmage can resists (20%) bad spells, magic creatures can resists (20%) same magic
+ Fixed magic resist troop battle animation
+ Updated captain: added spell book defaults, update captain stats with modificators
+ Fixed morale modificator with end battle
+ Fixed crash, out of range: hero retreat
+ Fixed Battle::Stats::GetCommander Battle::Stats::GetArmy with hypnotize and berzerker
+ Fixed dwelling population with hero present
+ Fixed artifact bar redraw
+ Added check for changes SetGuardians
+ Fixed battle AllowApplySpell without commander, fixed battle obstacle position, fixed Medusa Stone spell duration
+ Fixed archers animation handfighting attack
+ Fixed wagon camp passable sprite
+ Fixed load game and new game state
+ Updated load/save dialogue, added settings: remember last filename
+ Fixed AI magick, shots and move priority
+ Added visited Xanadu update visited shrine, update, name shrine info
+ Added confirm autosave
+ Updated visited witch hut, and name
Mar, 27, 2010
+ Added set guardian for capture objects
+ Fixed obstacles positions for battle, added archers penalty from obstacles
+ Fixed show radar opposite position for hotseat game
+ Updated: main dialogues with yellow color for header
+ Added: customizing value: heroes restore spell points per day, update globals.xml
+ Fixed name objects: Mines, Campfire, update 'Treasure Chest' and 'Sea Chest'
+ Added sorting spell for open book
+ Fixed golem attack sprite direction
+ Fixed shot sound attack
+ Fixed AI spellcast after move
+ Fixed spells 'Town Gate' and 'Town Portal' check other hero present
+ Added ext. info for joining and recruits monster dwellings, for shrine, for resources, witch hut and other
+ Added Symbian port
+ Added polish translation
+ Added more visited info check
+ Fixed whirlpool sprite detect, added customizing wirlpool percent to globals.xml
+ Update objects and artifacts names
+ Added cast spell 'Town Portal'
Mar, 20, 2010
+ Fixed Lightning Bolt damage
+ Added Dialog::Settings
+ Added plural form for monster name
+ Update text, separate context for spell Slow and speed Slow
+ Fixed Necromancy skill ability
+ Added Visions spell, and 'Identify Hero' spell
+ Update dialog scenario, set default params from last game
+ Update show status info: skip empty army
+ Fixed redraw top hero sprite with objects
+ Added 'Haunt' spell
+ Added 'Set Elemental Guardians' spell
+ Added customizing secondary skills
+ Added customization params kingdom::max_heroes
+ Fixed restore spell points from mysticism
+ Fixed 'Standing Stones' secondary visited
+ Fixed starting spell points for recruit heroes
+ Updated AI for double cell attack monsters
+ Updated battle GetDamage algorithm
Mar, 13, 2010
+ Added customizing 'Dimension Door' spell
+ Added spells customizing (spell cost and damage and others params)
+ Fixed casting spell from scroll artifact
+ Fixed Mage and ArchMage battle animation
+ Fixed battle 'Hypnotize' spell and Resurrect Spells apply
+ Fixed battle artifact 'Wizard's Hat' and 'Hourglass'
+ Fixed catapult order destroy objects
+ Added SDL-1.3 build support
+ Fixed "Start with hero in each player.." option
+ Added cast 'Dimension Door', 'Summon Boat', 'Town Gate'
+ Added customizing spells
+ Added pocketpc hardware buttons support
Mar, 7, 2010
+ Fixed joined monster
+ Fixed battle animations
+ Added status message for resurrect spells and death spells
+ Fixed battle necromancy ability
+ Fixed monster magick attack
+ Added bridge animation for battle
+ Fixed battle order speed troop
+ Updated spell action for Battle AI
+ Fixed battle wins/loss music
+ Fixed "mirror image" and "summon elemental" spell for battle
+ Fixed update dwelling population
+ Fixed recruit monster from "water altar " and "eath altar"
Feb, 17, 2010
+ Fixed Coliseum and Storm building ability
+ Added dismiss troop warning and update troop total cost info
+ Fixed game over result for wins_side
+ Fixed move point and spell point for recruit hero
+ Added customizing skill heroes and captain
+ Added customizing buildings, payments costs and profits
+ Added customizing monster stats
+ Added load alternative animation sprite for battle
+ Fixed battle morale
+ Fixed dublicate maps directory
+ Updated grown monsters on maps, fixed genie initial count
+ Fixed pyramid action
+ Fixed distrupting ray spell animation, fixed battle yellow status
+ Fixed start dialogues for loaded game
+ Fixed battle morale with skip turn
+ Fixed battle archers
Feb, 8, 2010
+ Fixed catapult animation
+ Added battle ai mass spell action
+ Fixed moat path restriction
+ Updates speed animations
+ Added system info (free memory, time for pocketpc)
+ Fixed config read
+ Updated new battle logic
Jan, 29, 2010
+ Added new battle engine, QVGA support
+ Fixed spells lasting past the end of a battle
+ Fixed spells lasting indefinitely in battle
+ Fixed monsters casting spells on dead units
+ Added heroes path store
+ Fixed hot seat crash
+ Fixed redistribute army
+ Fixed spell book filter
Nov, 27, 2009
+ fixed multiple pickup maps event
+ fixed sounds in battle being clipped. Stop battle music at end of battle summary.
+ added new mixer code, alternative sound load update code, reduce memory usage
Nov, 8, 2009
+ fixed heroes fadein/fadeout
+ fixed multiple maps event
+ update mixer
+ added options alt resource, support ogg sounds
+ added options hide ai move
+ fixed obelisk action, updated open puzzle algorithm
+ added builtin icon (mingw32, mingw32ce)
+ update artifact Arm of the Martyr
+ added artifact Spell Scroll
+ fixed heroes action (meetings/battle) with other heroes (shipmaster)
+ added rescan path for heroes with new day
+ added check full bag artifacts for heroes;
+ added ActionToTravelersTent and ActionToBarrier
+ fixed battle: fix flag, fix count troop visible
+ fixed 65k count for battle troop
Oct, 22, 2009 - Development build, 1299
+ Updated size army for heroes/castles info
+ Updated save file format version
+ Updated AI move, fix redraw status window
+ Added support translation for name and description maps, maps messages
+ Fixed recruit hero with empty army
+ Fixed restore magic point for heroes
+ Added tap delay settings, update high scores dialogue
+ Added buy magic book for pocketpc version
+ Fixed capture abandoned mine, add AI action abandoned mine
+ Fixed AI move midi cd music
+ Added store high scores and update high scores dialogue
+ Added force lang options
+ Added translation for original map files (sign, rumors, events message, sphinx riddle)
+ Added emulation the right mouse button for tap mode
+ Added low memory actions
+ Update pocketpc dialogues
+ Fixed more problems with troops moving too close in battle.
+ Keep battle win/lose music from looping. Play the puzzle music when not using midi.
+ Fixed incorrect battle results being displayed when battling AI.
+ Fixed trolls starting with much more health than they should in battle.
+ Fixed various problems in battle causing troops to attack from too far away.
Oct, 7, 2009 - Development build, 1235
+ Fixed for Battle: DrawShadow and DrawCell support 8 bit for default depth, fast move cursor for battle scene, fix left click for move current troop, set cursor WAR_NONE after kick
+ added puzzle dialogue for pocketpc version, fix for redraw heroes move
+ added binary save format
+ few updates for pocketpc version
+ added buy boat and marketplace dialogue for pocketpc
+ added tap mode and offset pointer settings for pocketpc (one touch as mouse click)
Developers
+ added WITHOUT_EDITOR, WITHOUT_ZLIB and WITHOUT_XML build options
Sep, 28, 2009 - Development build, 1210
+ More updates for pocketpc version
Sep, 17, 2009 - Development build, 1195
Users
+ Added pocketpc version interface
+ Added load fheroes2.cfg and gamedata from FHEROES2_DATA environment
+ Added new options: "use fade = on/off", "hide interface = on/off"
+ Added add hot key: m - move hero, o - system dialog, n - start new game
+ Added new interface: hide interface
+ Fixed performance, (remove delay from pathfinding)
+ Fixed castle resource panel
+ Fixed visit obelisk
+ Fixed building for differences plathorm (OSX, mingw32, wince)
+ Fixed Abandoned Mine name, add extra text in quick info.
+ Added zlib support for xml save files
+ Update music readme with more specific information.
+ Update translation files from launchpad
Developers
+ Added CONFIGURE_FHEROES2_DATA build defines for gamedata
+ Added WITHOUT_MIXER build option
+ Redistribute main loop game_startgame.cpp, move radar, buttons, status to interface gui, other small changes.
May 30, 2009 - Development build r1117
Users
+ Memory usage reductions.
+ Fixed various battle summary window glitches.
+ Fixed numerous errors with multi-cell attacks (dragons, cyclopes, etc).
+ Corrected logic error causing AI units to believe they could attack when they
shouldn't, and vice versa.
+ Added game over conditions.
+ Added puzzle piece fading effect.
+ Creatures can now receive morale boosts when not attacking.
+ Fixed text for recruiting free monster dwellings.
+ Fixed incorrect logic for halving damage through castle walls.
+ Fixed rare siuation in battle when ranged troops think they are performing a
melee attack even if they are not.
+ Fixed starting resource for AI.
+ Enabled key repeating.
+ Hero path arrows now reflect movement penalties.
+ Double clicking on an entry in a file selection box will choose that item.
+ Added Spanish translation.
+ Multiple events can now occur on the same day.
+ Fixed bug causing obelisks not to be counted past the first visited,
causing maps like Dragon Rider to now work.
+ Fixed music restarting with every step taken by a player's hero.
+ Fixed relatively rare crash involving the AI and ranged units in battle,
most obvious in the opening turn of Dragon Rider.
+ If a hero is attacked while in a castle, a castle battle is now initiated,
and as many troops as possible in the castle's army are moved into the
defending hero's army.
Developers
+ SDL_Mixer music and sound callbacks removed, as they were potentially dangerous
as used.
April 23, 2009 - Development build r1021
Users
+ Added glowing outlines around currently selected monster in battles.
+ Battle victory/defeat music now plays properly when viewing the summary.
+ Races are no longer grayed out on the scenario panel when restarting a game.
+ All units in battle now deal a minimum of 1 damage, with damage modifiers
now capped at -30% and 300% as specified in the original manual.
+ Heroes may no longer surrender to non-heroes.
+ Removed 'Upgrade' and 'Dismiss' buttons from monster info dialogs in battle.
+ Fixed bug causing enemy corpses to resurrect with 65000 units.
+ Heroes now receive experience corresponding to amount of damage dealt in battles,
and the new number displays properly in the summary dialog.
+ Extra income is no longer received on the first day of the game.
+ Added support for Eagle Eye and Necromancy skills.
+ Elves and Rangers will no longer perform hand to hand combat attacks twice.
+ Screenshots now save to files/screenshot_[time].(png|bmp)
+ Starting monster stack sizes are now more in line with Heroes II defaults.
+ Added an info window in the status bar when collecting resources.
+ Added support for Diplomacy skill: monsters will now offer to join you
if your army is powerful enough.
+ Saving and loading of games has been implemented, as has autosave
(configured in fheroes2.cfg)
+ Fixed various bugs with heroes learning spells when entering a castle
and class-specific starting spells.
+ Fixed a bug in which the computer would take over certain battles in which
a hero or captain was not present. This fixes the map Revolution, among others.
+ The keep and towers will now deal appropriate damage in castle battles.
+ Battle status messages are now visible for longer.
+ Heroes now level up at game start as they do in HoMM II.
+ Fixed a bug causing heroes to gain levels in multiple primary skills on levelup.
+ Genies now have 9% chance to halve the size of any troop attacked in battle.
+ Ghosts gain 1 unit for every unit they kill.
+ Pathfinding will now avoid tiles which would trigger a battle.
Developers
+ Added wrapper library around SDL_net and networking client/server examples.
+ Added support for replacing ICN files at runtime with other images.
March 19, 2009 - Development build r915
Users
+ Added Russian translation .po file.
+ Added actions for Mermaids, Sirens, Arenas, Stables, Barrow Mounds, Elemental Recruiting, Jails, HutMagi,
EyeMagi, and Sphinxes.
+ Added load and save game support.
+ AI battles now use battle system logic to properly decide outcomes.
+ Added support for castle and town battles.
+ Arrow keys now move the current hero, while CTRL+arrow scrolls the map view.
Developers
+ Removed libxml2 dependence
+ Added build options (WITHOUT_PNG, WITHOUT_UNICODE)
+ Battle engine rewritten to separate logic from display, and to allow
for future expansion (ie. castles/towns).
+ Added gettext support.
+ Unicode support with TTF font render.
February 1, 2009 - Development build r850
Users
+ Added icn2png convertor tools
+ Campfires now give gold rewards along with other resources. (afletdinov)
+ Numeric fields now accept keyboard input. (afletdinov)
+ Black Dragons now correctly cost 2 sulphur. (afletdinov)
+ Artifacts with resource costs are now fixed, instead of changing randomly
each time a hero touches the artifact. (afletdinov)
+ Fixed maps generating the same random artifact multiple times. (afletdinov)
+ Added actions for Tree of Knowledge, Oracle, and Demon Cave map objects. (afletdinov)
+ Fixed various endian issues which made fheroes2 unplayable on AmigaOS. (afletdinov)
+ Added keyboard hotkeys for buttons on the main menu and ending the turn in game.
(afletdinov, revvy)
Developers
+ Nothing.
December 25, 2008 - Development build r807
Users
+ Heroes now level up and learn new skills based on race tables from
HoMM II. (afletdinov)
+ Wide monsters in battle now properly reflect in place, fixing a number of
overlapping troop bugs. (revvy)
+ Animation speed on the main adventure screen can now be controlled from the
settings panel in game. (afletdinov)
+ Added animations for previously static objects (stone liths, treasure chests,
fountains). (afletdinov)
+ Added rudimentary AI for castle building, recruiting troops and controlling
heroes. (afletdinov)
+ Stopped end turn confirmation dialog from appearing when all heroes cannot
move any further along their paths, but still have movement points
remaining. (revvy)
+ Added music to Barbarian castle. (afletdinov)
+ Tiles surrounding a monster on the adventure screen now show the battle
mouse cursor. (afletdinov)
+ Battle summary screen no longer misses some captured artifacts. (revvy)
+ Added ultimate artifact puzzle interface. (revvy, afletdinov)
+ Fixed a bug preventing remaining HP information from showing up in the monster
info window in battle. (revvy)
+ Fixed recurring problem in battles where AI units would walk next to a unit
but not attack. (revvy)
+ Fixed bug causing marketplace dialog to close after every trade. (revvy)
+ Fixed various problems with dialogs being slightly transparent and very ugly.
(afletdinov, revvy)
+ Fixed bug causing experience award display on battle summary screen to
always show 0. (revvy)
+ Tiles surrounding monsters on the adventure screen now display the proper
fight cursor. (afletdinov)
+ All major dialogs should respond like HoMM II to ESC and RET key presses.
(afletdinov)
+ Message boxes now display the title in proper yellow letters. (afletdinov)
+ Monsters now properly draw in front of scenery and other monsters while
moving in battle. (revvy)
+ Many more bug fixes.
Developers
+ Army::Troops has been split into Army::Troop (for storing monster type, total
number, and primary skill) and Army::BattleTroop, which holds information
about animation, hit points, and position. (revvy)
+ Fixed a couple endian issues, so fheroes2 should theoretically work perfectly
on MacOS (revvy, afletdinov)
November 20, 2008 - Development build r571
+ Everything!

View File

@@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@@ -0,0 +1,68 @@
# Default config fheroes2.cfg options:
#
# path to directory data
# data = data
#
# path to directory maps, you can set few maps
# maps = maps
# maps = c:\other_maps
#
# use alternative resource
# alt resource = off
#
# sound: on off
sound = on
#
# music: on,midi,cd,ext,off
music = midi
#
# sound volume: 0 - 10
# sound volume = 6
#
# music volume: 0 - 10
# music volume = 6
#
# external play music command:
# playmus command = ""
#
# video mode (640x480, 800x576, 1024x768, 1280x1024 or other divisible 32)
videomode = 800x480
#
# current animation speed: 0 - 10
# animation = 6
#
# fullscreen: on off (F4 switch)
fullscreen = on
#
# debug
debug = on
#
# use ttf fonts
# unicode = off
#
# force lang
# lang = en
#
# font name (only with unicode = on)
# fonts normal = dejavusans.ttf
# fonts small = dejavusans.ttf
# fonts normal size = 15
# fonts small size = 10
#
# fonts render engine: (blended/solid) (only with unicode = on)
# fonts render = solid
#
# network port:
# port = 5154
#
# pocket pc emulation (set auto on for videomode < 640x480)
# pocket pc = off
#
# pocket pc options:
# tap delay = 1050
# pointer offset x = 0
# pointer offset y = 0
#
# virtual key mapping:
# key_273 = '.'
# key_275 = '/'

View File

@@ -0,0 +1,104 @@
# fheroes2 hot keys
#
# 1. syntax:
# <events name> = <keycode> (do not forget to remove comments '#')
#
#
# 2.1 default events:
# default ready - (default keycode: 13 = 'return')
# default exit - (default keycode: 27 = 'esc')
# default left - (default keycode: no set)
# default right - (default keycode: no set)
#
# 2.2 system hotkeys:
# system fullscreen - (default keycode: 285 = F4)
# system screenshot - (default keycode: 316 = PRINT)
#
# 2.2 buttons:
# button newgame - (default keycode: 110 = 'n')
# button loadgame - (default keycode: 108 = 'l')
# button highscores - (default keycode: 104 = 'h')
# button credits - (default keycode: 99 = 'c')
# button standard - (default keycode: 115 = 's')
# button campain - (default keycode: 99 = 'c')
# button multigame - (default keycode: 109 = 'm')
# button settings - (default keycode: 116 = 't')
# button select - (default keycode: 115 = 's')
# button hotseat - (default keycode: 104 = 'h')
# button network - (default keycode: 110 = 'n')
# button host - (default keycode: 104 = 'h')
# button guest - (default keycode: 103 = 'g')
#
# 2.3 game events:
# end turn - (default keycode: 101 = 'e')
# next hero - (default keycode: 104 = 'h')
# next town - (default keycode: 116 = 't')
# continue move - (default keycode: 109 = 'm')
# save game - (default keycode: 115 = 's')
# load game - (default keycode: 108 = 'l')
# show file dialog - (default keycode: 102 = 'f')
# show system options - (default keycode: 111 = 'o')
# show puzzle maps - (default keycode: 112 = 'p')
# show game info - (default keycode: 105 = 'i')
# dig artifact - (default keycode: 100 = 'd')
# cast spell - (default keycode: 99 = 'c')
# default action - (default keycode: 32 = 'space')
# move left - (default keycode: 276 = 'left')
# move right - (default keycode: 275 = 'right')
# move up - (default keycode: 273 = 'up')
# move down - (default keycode: 274 = 'down')
# move top left - (default keycode: no set)
# move top right - (default keycode: no set)
# move bottom left - (default keycode: no set)
# move bottom right - (default keycode: no set)
# open focus - (default keycode: 13 = 'return')
# scroll left - (default keycode: no set)
# scroll right - (default keycode: no set)
# scroll up - (default keycode: no set)
# scroll down - (default keycode: no set)
# control panel - (default keycode: 49 = '1')
# show radar - (default keycode: 50 = '2')
# show buttons - (default keycode: 51 = '3')
# show status - (default keycode: 52 = '4')
# show icons - (default keycode: 53 = '5')
#
# 2.4 system events:
# emulate mouse toggle - (default keycode: no set)
# emulate mouse left - (default keycode: 276 = 'left')
# emulate mouse right - (default keycode: 275 = 'right')
# emulate mouse up - (default keycode: 273 = 'up')
# emulate mouse down - (default keycode: 274 = 'down')
# emulate press left - (default keycode: no set)
# emulate press right - (default keycode: no set)
# switch group - (default keycode: no set)
#
# 2.5 battle events:
# battle cast spell - (default keycode: 99 = 'c')
# battle retreat - (default keycode: 27 = 'esc')
# battle surrender - (default keycode: 115 = 's')
# battle auto switch - (default keycode: 97 = 'a')
# battle options - (default keycode: 111 = 'o')
# battle hard skip - (default keycode: 104 = 'h')
# battle soft skip - (default keycode: 32 = 'space')
# 3. events descriptions:
# default ready - ok/yes buttons
# default exit - no/cancel buttons, exit from game
# default left - left button
# default right - right button
# default action - focus on hero: if path set - continue move, or repeat object action, or open dialog
# focus on town: open dialog
# open focus - open dialog for hero/town
# emulate mouse toggle - toggle switch for "emulate mouse keys" as (mouse move/or keys)
# switch group - not used, reserved
#
#
# 4. how to retrieve keycode:
# - set "debug = 0x12" (fheroes2.cfg)
# - start game
# - go to "high scores"
# - press key (should be show dialog with keycode)
#
#
# 5. how to use this (example):
default exit = 27

View File

@@ -0,0 +1,8 @@
Load alternative png images.
To do this you need to define the parameter "alt resource" in the configuration file.
The approximate structure:
name.icn/001.png
name.icn/002.png
name.icn/003.png
For more detail see log file.

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" ?>
<icn name="name.icn" count="3">
<sprite name="0.png" ox="-12" oy="30"/>
<sprite name="1.png" ox="0" oy="0"/>
<sprite name="2.png" ox="0" oy="0"/>
</icn>

View File

@@ -0,0 +1,3 @@
copy fheroes2.pot to ${LANGUAGE_CODE}/LC_MESSAGES/fheroes2.po
translate, and run:
msgfmt fheroes2.po -o fheroes2.mo

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#
# makefile
#
all:
msgmerge -U fheroes2.po ../../fheroes2.pot
msgfmt fheroes2.po -o fheroes2.mo

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
List of required track names for full music support (ogg or mp3 support):
02.ogg - Random for Battle
03.ogg - Random for Battle
04.ogg - Random for Battle
05.ogg - Barbarian Castle
06.ogg - Sorceress Castle
07.ogg - Warlock Castle
08.ogg - Wizard Castle
09.ogg - Necromancer Castle
10.ogg - Knight Castle
11.ogg - Lava Theme
12.ogg - Wasteland Theme
13.ogg - Desert Theme
14.ogg - Snow Theme
15.ogg - Swamp Theme
16.ogg - Beach Theme
17.ogg - Dirt Theme
18.ogg - Grass Theme
23.ogg - Map Puzzle
28.ogg - AI Turns
29.ogg - Battle Wins
30.ogg - Battle Loss
42.ogg - Main Menu

View File

@@ -0,0 +1,311 @@
sound list:
aelmattk.ogg -
aelmkill.ogg -
aelmmove.ogg -
aelmwnce.ogg -
antimagk.ogg -
archattk.ogg -
archkill.ogg -
archmove.ogg -
archshot.ogg -
archwnce.ogg -
armgedn.ogg -
badluck.ogg -
badmrle.ogg -
berzerk.ogg -
bless.ogg -
blind.ogg -
bloodlus.ogg -
boarattk.ogg -
boarkill.ogg -
boarmove.ogg -
boarwnce.ogg -
boneattk.ogg -
bonekill.ogg -
bonemove.ogg -
bonewnce.ogg -
buildtwn.ogg -
catsnd00.ogg -
catsnd02.ogg -
cavlattk.ogg -
cavlkill.ogg -
cavlmove.ogg -
cavlwnce.ogg -
chainlte.ogg -
cntrattk.ogg -
cntrkill.ogg -
cntrmove.ogg -
cntrshot.ogg -
cntrwnce.ogg -
coldray.ogg -
coldring.ogg -
cure.ogg -
curse.ogg -
cyclattk.ogg -
cyclkill.ogg -
cyclmove.ogg -
cyclwnce.ogg -
digsound.ogg -
dipmagk.ogg -
disruptr.ogg -
drawbrg.ogg -
drgnattk.ogg -
drgnkill.ogg -
drgnmove.ogg -
drgnslay.ogg -
drgnwnce.ogg -
druiattk.ogg -
druikill.ogg -
druimove.ogg -
druishot.ogg -
druiwnce.ogg -
dwrfattk.ogg -
dwrfkill.ogg -
dwrfmove.ogg -
dwrfwnce.ogg -
eelmattk.ogg -
eelmkill.ogg -
eelmmove.ogg -
eelmwnce.ogg -
elf_attk.ogg -
elf_kill.ogg -
elf_move.ogg -
elf_shot.ogg -
elf_wnce.ogg -
erthquak.ogg -
expernce.ogg -
felmattk.ogg -
felmkill.ogg -
felmmove.ogg -
felmwnce.ogg -
fireball.ogg -
gargattk.ogg -
gargkill.ogg -
gargmove.ogg -
gargwnce.ogg -
gblnattk.ogg -
gblnkill.ogg -
gblnmove.ogg -
gblnwnce.ogg -
geniattk.ogg -
genikill.ogg -
genimove.ogg -
geniwnce.ogg -
ghstattk.ogg -
ghstkill.ogg -
ghstmove.ogg -
ghstwnce.ogg -
golmattk.ogg -
golmkill.ogg -
golmmove.ogg -
golmwnce.ogg -
goodluck.ogg -
goodmrle.ogg -
grifattk.ogg -
grifkill.ogg -
grifmove.ogg -
grifwnce.ogg -
h2mine.ogg -
halfattk.ogg -
halfkill.ogg -
halfmove.ogg -
halfshot.ogg -
halfwnce.ogg -
haste.ogg -
hydrattk.ogg -
hydrkill.ogg -
hydrmove.ogg -
hydrwnce.ogg -
hypnotiz.ogg -
keepshot.ogg -
killfade.ogg -
lichattk.ogg -
lichexpl.ogg -
lichkill.ogg -
lichmove.ogg -
lichshot.ogg -
lichwnce.ogg -
lightblt.ogg -
loop0000.ogg -
loop0001.ogg -
loop0002.ogg -
loop0003.ogg -
loop0004.ogg -
loop0005.ogg -
loop0006.ogg -
loop0007.ogg -
loop0008.ogg -
loop0009.ogg -
loop0010.ogg -
loop0011.ogg -
loop0012.ogg -
loop0013.ogg -
loop0014.ogg -
loop0015.ogg -
loop0016.ogg -
loop0017.ogg -
loop0018.ogg -
loop0019.ogg -
loop0020.ogg -
loop0021.ogg -
loop0022.ogg -
loop0023.ogg -
loop0024.ogg -
loop0025.ogg -
loop0026.ogg -
loop0027.ogg -
magcarow.ogg -
mageattk.ogg -
magekill.ogg -
magemove.ogg -
mageshot.ogg -
magewnce.ogg -
massbles.ogg -
masscure.ogg -
masscurs.ogg -
masshast.ogg -
massshie.ogg -
massslow.ogg -
medsattk.ogg -
medskill.ogg -
medsmove.ogg -
medswnce.ogg -
meteor~1.ogg -
minoattk.ogg -
minokill.ogg -
minomove.ogg -
minownce.ogg -
mirrorim.ogg -
mnrdeath.ogg -
mumyattk.ogg -
mumykill.ogg -
mumymove.ogg -
mumywnce.ogg -
nmadattk.ogg -
nmadkill.ogg -
nmadmove.ogg -
nmadwnce.ogg -
nwherolv.ogg -
ogreattk.ogg -
ogrekill.ogg -
ogremove.ogg -
ogrewnce.ogg -
orc_attk.ogg -
orc_kill.ogg -
orc_move.ogg -
orc_shot.ogg -
orc_wnce.ogg -
paralize.ogg -
phoeattk.ogg -
phoekill.ogg -
phoemove.ogg -
phoewnce.ogg -
pickup01.ogg -
pickup02.ogg -
pickup03.ogg -
pickup04.ogg -
pickup05.ogg -
pickup06.ogg -
pickup07.ogg -
pikeattk.ogg -
pikekill.ogg -
pikemove.ogg -
pikewnce.ogg -
pldnattk.ogg -
pldnkill.ogg -
pldnmove.ogg -
pldnwnce.ogg -
prebattl.ogg -
protect.ogg -
psntattk.ogg -
psntkill.ogg -
psntmove.ogg -
psntwnce.ogg -
resurect.ogg -
resurtru.ogg -
roc_attk.ogg -
roc_kill.ogg -
roc_move.ogg -
roc_wnce.ogg -
roguattk.ogg -
rogukill.ogg -
rogumove.ogg -
roguwnce.ogg -
rsbryfzl.ogg -
shield.ogg -
skelattk.ogg -
skelkill.ogg -
skelmove.ogg -
skelwnce.ogg -
slow.ogg -
sprtattk.ogg -
sprtkill.ogg -
sprtmove.ogg -
sprtwnce.ogg -
stelskin.ogg -
stoneski.ogg -
stonskin.ogg -
storm.ogg -
sumnelm.ogg -
swdmattk.ogg -
swdmkill.ogg -
swdmmove.ogg -
swdmwnce.ogg -
telein.ogg -
telptin.ogg -
telptout.ogg -
titnattk.ogg -
titnkill.ogg -
titnmove.ogg -
titnshot.ogg -
titnwnce.ogg -
treasure.ogg -
trllattk.ogg -
trllkill.ogg -
trllmove.ogg -
trllshot.ogg -
trllwnce.ogg -
unicattk.ogg -
unickill.ogg -
unicmove.ogg -
unicwnce.ogg -
vampattk.ogg -
vampext1.ogg -
vampext2.ogg -
vampkill.ogg -
vampmove.ogg -
vampwnce.ogg -
welmattk.ogg -
welmkill.ogg -
welmmove.ogg -
welmwnce.ogg -
wolfattk.ogg -
wolfkill.ogg -
wolfmove.ogg -
wolfwnce.ogg -
wsnd00.ogg -
wsnd01.ogg -
wsnd02.ogg -
wsnd03.ogg -
wsnd04.ogg -
wsnd05.ogg -
wsnd06.ogg -
wsnd10.ogg -
wsnd11.ogg -
wsnd12.ogg -
wsnd13.ogg -
wsnd14.ogg -
wsnd15.ogg -
wsnd16.ogg -
wsnd20.ogg -
wsnd21.ogg -
wsnd22.ogg -
wsnd23.ogg -
wsnd24.ogg -
wsnd25.ogg -
wsnd26.ogg -
zombattk.ogg -
zombkill.ogg -
zombmove.ogg -
zombwnce.ogg -

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" ?>
<animations>
<!--
<icn name="unknown.icn">
<animation state="idle" start="0" count="0"/> // idle frame
<animation state="move" start="0" count="0"/> // move frame
<animation state="fly1" start="0" count="0"/> // jump up frame
<animation state="fly2" start="0" count="0"/> // fly frame
<animation state="fly3" start="0" count="0"/> // jump down frame
<animation state="shot0" start="0" count="0"/> // prepare shot frame
<animation state="shot1" start="0" count="0"/> // shot up frame
<animation state="shot2" start="0" count="0"/> // shot frame
<animation state="shot3" start="0" count="0"/> // shot down frame
<animation state="attk0" start="0" count="0"/> // prepare attack frame
<animation state="attk1" start="0" count="0"/> // attack up frame
<animation state="attk2" start="0" count="0"/> // attack frame
<animation state="attk3" start="0" count="0"/> // attack down frame
<animation state="wcne" start="0" count="0"/> // wcne frame
<animation state="kill" start="0" count="0"/> // kill frame
</icn> -->
<icn name="peasant.icn">
<animation state="idle" start="1" count="4"/>
<animation state="move" start="5" count="8"/>
<animation state="attk1" start="16" count="6"/>
<animation state="attk2" start="22" count="6"/>
<animation state="attk3" start="28" count="6"/>
<animation state="wcne" start="13" count="3"/>
<animation state="kill" start="34" count="4"/>
</icn>
<icn name="archer.icn">
<animation state="idle" start="1" count="4"/>
<animation state="move" start="5" count="8"/>
<animation state="shot0" start="16" count="4"/>
<animation state="shot1" start="20" count="4"/>
<animation state="shot2" start="24" count="4"/>
<animation state="shot3" start="28" count="4"/>
<animation state="attk0" start="32" count="4"/>
<animation state="attk1" start="36" count="3"/>
<animation state="attk2" start="39" count="3"/>
<animation state="attk3" start="42" count="3"/>
<animation state="wcne" start="13" count="3"/>
<animation state="kill" start="45" count="6"/>
</icn>
<!-- more other -->
</animations>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" ?>
<battle>
<genie enemy_half_percent="10" />
</battle>

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" ?>
<buildings>
<!-- <building gold="0" wood="0" mercury="0" ore="0" sulfur="0" crystal="0" gems="0" /> -->
<thieves_guild gold="750" wood="5" />
<tavern gold="500" wood="5" />
<shipyard gold="2000" wood="20" />
<well gold="500" />
<statue gold="1250" ore="5" />
<left_turret gold="1500" ore="5" />
<right_turret gold="1500" ore="5" />
<marketplace gold="500" wood="5" />
<moat gold="750" />
<castle gold="5000" wood="20" ore="20" />
<captain gold="500" />
<mage_guild1 gold="2000" wood="5" ore="5" />
<mage_guild2 gold="1000" wood="5" mercury="4" ore="5" sulfur="4" crystal="4" gems="4" />
<mage_guild3 gold="1000" wood="5" mercury="6" ore="5" sulfur="6" crystal="6" gems="6" />
<mage_guild4 gold="1000" wood="5" mercury="8" ore="5" sulfur="8" crystal="8" gems="8" />
<mage_guild5 gold="1000" wood="5" mercury="10" ore="5" sulfur="10" crystal="10" gems="10" />
<farm gold="1000" />
<garbage_he gold="1000" />
<crystal_gar gold="1000" />
<waterfall gold="1000" />
<orchard gold="1000" />
<skull_pile gold="1000" />
<fortification gold="1500" wood="5" ore="15" />
<coliseum gold="2000" wood="10" ore="10" />
<rainbow gold="1500" crystal="10" />
<dungeon gold="3000" wood="5" ore="10" />
<library gold="1500" wood="5" mercury="5" ore="5" sulfur="5" crystal="5" gems="5" />
<storm gold="1000" mercury="10" sulfur="10" />
<shrine gold="4000" wood="10" crystal="10" />
<!-- knight dwelling -->
<thatched_hut gold="200" />
<archery_range gold="1000" />
<upg_archery_range gold="1500" wood="5" />
<blacksmith gold="1000" ore="5" />
<upg_blacksmith gold="1500" ore="5" />
<armory gold="2000" wood="10" ore="10" />
<upg_armory gold="2000" wood="5" ore="5" />
<jousting_arena gold="3000" wood="20" />
<upg_jousting_arena gold="3000" wood="10" />
<cathedral gold="5000" wood="20" crystal="20" />
<upg_cathedral gold="5000" wood="10" crystal="10" />
<!-- barbarian dwelling -->
<hut gold="300" />
<stick_hut gold="800" wood="5" />
<upg_stick_hut gold="1200" wood="5" />
<den gold="1000" />
<adobe gold="2000" wood="10" ore="10" />
<upg_adobe gold="3000" wood="5" ore="5" />
<bridge gold="4000" ore="20" />
<upg_bridge gold="2000" ore="10" />
<cyclop_pyramid gold="6000" ore="20" crystal="20" />
<!-- sorceress dwelling -->
<treehouse gold="500" wood="5" />
<cottage gold="1000" wood="5" />
<upg_cottage gold="1500" wood="5" />
<elves_arhery_range gold="1500" />
<upg_elves_archery_range gold="1500" wood="5" />
<stonehenge gold="1500" ore="10" />
<upd_stonehenge gold="1500" mercury="5" />
<fenced_meadow gold="3000" wood="10" gems="10" />
<phoenix_red_tower gold="10000" mercury="20" ore="30" />
<!-- warlock dwelling -->
<cave gold="500" />
<crypt gold="1000" ore="10" />
<nest gold="2000" />
<maze gold="3000" gems="10" />
<upg_maze gold="2000" gems="5" />
<swamp gold="4000" sulfur="10" />
<green_tower gold="15000" ore="30" sulfur="20" />
<red_tower gold="5000" ore="5" sulfur="10" />
<black_tower gold="5000" ore="5" sulfur="10" />
<!-- wizard dwelling -->
<habitat gold="400" />
<pen gold="800" />
<foundry gold="1500" wood="5" ore="5" />
<upg_foundry gold="1500" mercury="5" />
<cliff_nest gold="3000" wood="5" />
<ivory_tower gold="3500" wood="5" mercury="5" ore="5" sulfur="5" crystal="5" gems="5" />
<upg_ivory_tower gold="4000" wood="5" ore="5" />
<cloud_castle gold="12500" wood="5" ore="5" gems="20" />
<upg_cloud_castle gold="12500" wood="5" ore="5" gems="20" />
<!-- necromancer dwelling -->
<excavation gold="400" />
<graveyard gold="1000" />
<upg_graveyard gold="1000" />
<pyramid gold="1500" ore="10" />
<upg_pyramid gold="1500" ore="5" />
<mansion gold="3000" wood="10" />
<upg_mansion gold="4000" wood="5" crystal="10" gems="10" />
<mausoleum gold="4000" wood="10" sulfur="10" />
<upg_mausoleum gold="3000" ore="5" crystal="5" />
<laboratory gold="10000" wood="10" mercury="5" ore="10" sulfur="5" crystal="5" gems="5" />
</buildings>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" ?>
<globals>
<!-- starting resource (gold max: 65535, resource max: 255 ) -->
<starting_resource ai_always="easy">
<easy gold="10000" wood="30" mercury="10" ore="30" sulfur="10" crystal="10" gems="10" />
<normal gold="7500" wood="20" mercury="5" ore="20" sulfur="5" crystal="5" gems="5" />
<hard gold="5000" wood="10" mercury="2" ore="10" sulfur="2" crystal="2" gems="2" />
<expert gold="2500" wood="5" mercury="0" ore="5" sulfur="0" crystal="0" gems="0" />
<impossible gold="0" wood="0" mercury="0" ore="0" sulfur="0" crystal="0" gems="0" />
</starting_resource>
<!-- kingdom params -->
<kingdom max_heroes="8" />
<!-- clear fog distance -->
<view_distance town="4" castle="5" heroes="4" artifact_telescope="1" object_observation_tower="10" object_magi_eyes="9" />
<!-- additional growth -->
<castle_extra_growth well="2" wel2="8" />
<!-- restore spell point: 0 - 10 -->
<heroes spell_points_per_day="1" />
<game_over lost_towns_days="7" />
<!-- whirlpool percent: 1 - 90 -->
<whirlpool percent="50" />
</globals>

View File

@@ -0,0 +1,158 @@
<?xml version="1.0" ?>
<monsters>
<!--
speed:
crawling = 1,
veryslow = 2,
slow = 3,
average = 4,
fast = 5,
veryfast = 6,
ultrafast = 7,
blazing = 8,
instant = 9
-->
<!-- first: unknown monster -->
<monster skip="0" attack="1" defense="1" damage_min="1" damage_max="1" hp="1" speed="1" grown="0" shots="0" gold="0" wood="0" mercury="0" ore="0" sulfur="0" crystal="0" gems="0" />
<!-- peasant -->
<monster attack="1" defense="1" damage_min="1" damage_max="1" hp="1" speed="2" grown="12" gold="20" />
<!-- archer -->
<monster attack="5" defense="3" damage_min="2" damage_max="3" hp="10" speed="2" grown="8" shots="12" gold="150" />
<!-- ranger -->
<monster attack="5" defense="3" damage_min="2" damage_max="3" hp="10" speed="4" grown="8" shots="24" gold="200" />
<!-- pikeman -->
<monster attack="5" defense="9" damage_min="3" damage_max="4" hp="15" speed="4" grown="5" gold="200" />
<!-- veteran pikeman -->
<monster attack="5" defense="9" damage_min="3" damage_max="4" hp="20" speed="5" grown="5" gold="250" />
<!-- swordsman -->
<monster attack="7" defense="9" damage_min="4" damage_max="6" hp="25" speed="4" grown="4" gold="250" />
<!-- master swordsman -->
<monster attack="7" defense="9" damage_min="4" damage_max="6" hp="30" speed="5" grown="4" gold="300" />
<!-- cavalry -->
<monster attack="10" defense="9" damage_min="5" damage_max="10" hp="30" speed="6" grown="3" gold="300" />
<!-- champion -->
<monster attack="10" defense="9" damage_min="5" damage_max="10" hp="40" speed="7" grown="3" gold="375" />
<!-- paladin -->
<monster attack="11" defense="12" damage_min="10" damage_max="20" hp="50" speed="5" grown="2" gold="600" />
<!-- crusader -->
<monster attack="11" defense="12" damage_min="10" damage_max="20" hp="65" speed="6" grown="2" gold="1000" />
<!-- goblin -->
<monster attack="3" defense="1" damage_min="1" damage_max="2" hp="3" speed="4" grown="10" gold="40" />
<!-- orc -->
<monster attack="3" defense="4" damage_min="2" damage_max="3" hp="10" speed="2" grown="8" shots="8" gold="140" />
<!-- orc chief -->
<monster attack="3" defense="4" damage_min="3" damage_max="4" hp="15" speed="3" grown="8" shots="16" gold="175" />
<!-- wolf -->
<monster attack="6" defense="2" damage_min="3" damage_max="5" hp="20" speed="6" grown="5" gold="200" />
<!-- ogre -->
<monster attack="9" defense="5" damage_min="4" damage_max="6" hp="40" speed="2" grown="4" gold="300" />
<!-- ogre lord -->
<monster attack="9" defense="5" damage_min="5" damage_max="7" hp="60" speed="4" grown="4" gold="500" />
<!-- troll -->
<monster attack="10" defense="5" damage_min="5" damage_max="7" hp="40" speed="4" grown="3" shots="8" gold="600" />
<!-- war troll -->
<monster attack="10" defense="5" damage_min="7" damage_max="9" hp="40" speed="5" grown="3" shots="16" gold="700" />
<!-- cyclops -->
<monster attack="12" defense="9" damage_min="12" damage_max="24" hp="80" speed="5" grown="2" gold="750" crystal="1" />
<!-- sprite -->
<monster attack="4" defense="2" damage_min="1" damage_max="2" hp="2" speed="4" grown="8" gold="50" />
<!-- dwarf -->
<monster attack="6" defense="5" damage_min="2" damage_max="4" hp="20" speed="2" grown="6" gold="200" />
<!-- battle swarf -->
<monster attack="6" defense="6" damage_min="2" damage_max="4" hp="20" speed="4" grown="6" gold="250" />
<!-- elf -->
<monster attack="4" defense="3" damage_min="2" damage_max="3" hp="15" speed="4" grown="4" shots="24" gold="250" />
<!-- grand wlf -->
<monster attack="5" defense="5" damage_min="2" damage_max="3" hp="15" speed="6" grown="4" shots="24" gold="300" />
<!-- druid -->
<monster attack="7" defense="5" damage_min="5" damage_max="8" hp="25" speed="5" grown="3" shots="8" gold="350" />
<!-- greater druid -->
<monster attack="7" defense="7" damage_min="5" damage_max="8" hp="25" speed="6" grown="3" shots="16" gold="400" />
<!-- unicorn -->
<monster attack="10" defense="9" damage_min="7" damage_max="14" hp="40" speed="5" grown="2" gold="500" />
<!-- phoenix -->
<monster attack="12" defense="10" damage_min="20" damage_max="40" hp="100" speed="7" grown="1" gold="1500" mercury="1" />
<!-- centaur -->
<monster attack="3" defense="1" damage_min="1" damage_max="2" hp="5" speed="4" grown="8" shots="8" gold="60" />
<!-- gargoyle -->
<monster attack="4" defense="7" damage_min="2" damage_max="3" hp="15" speed="6" grown="6" gold="200" />
<!-- griffin -->
<monster attack="6" defense="6" damage_min="3" damage_max="5" hp="25" speed="4" grown="4" gold="300" />
<!-- minotaur -->
<monster attack="9" defense="8" damage_min="5" damage_max="10" hp="35" speed="4" grown="3" gold="400" />
<!-- minotaur king -->
<monster attack="9" defense="8" damage_min="5" damage_max="10" hp="45" speed="6" grown="3" gold="500" />
<!-- hydra -->
<monster attack="8" defense="9" damage_min="6" damage_max="12" hp="75" speed="2" grown="2" gold="800" />
<!-- green dragon -->
<monster attack="12" defense="12" damage_min="25" damage_max="50" hp="200" speed="4" grown="1" gold="3000" sulfur="1" />
<!-- red dragon -->
<monster attack="13" defense="13" damage_min="25" damage_max="50" hp="250" speed="5" grown="1" gold="3500" sulfur="1" />
<!-- black dragon -->
<monster attack="14" defense="14" damage_min="25" damage_max="50" hp="300" speed="6" grown="1" gold="4000" sulfur="2" />
<!-- halfling -->
<monster attack="2" defense="1" damage_min="1" damage_max="3" hp="3" speed="3" grown="8" shots="8" gold="50" />
<!-- boar -->
<monster attack="5" defense="4" damage_min="2" damage_max="3" hp="15" speed="6" grown="6" gold="150" />
<!-- iron golem -->
<monster attack="5" defense="10" damage_min="4" damage_max="5" hp="30" speed="2" grown="4" gold="300" />
<!-- steel golem -->
<monster attack="7" defense="10" damage_min="4" damage_max="5" hp="35" speed="3" grown="4" gold="350" />
<!-- roc -->
<monster attack="7" defense="7" damage_min="4" damage_max="8" hp="40" speed="4" grown="3" gold="400" />
<!-- magi -->
<monster attack="11" defense="7" damage_min="7" damage_max="9" hp="30" speed="5" grown="2" shots="12" gold="600" />
<!-- archmagi -->
<monster attack="12" defense="8" damage_min="7" damage_max="9" hp="35" speed="6" grown="2" shots="24" gold="700" />
<!-- giant -->
<monster attack="13" defense="10" damage_min="20" damage_max="30" hp="150" speed="4" grown="1" gold="2000" gems="1" />
<!-- titan -->
<monster attack="15" defense="15" damage_min="20" damage_max="30" hp="300" speed="6" grown="1" shots="24" gold="5000" gems="2" />
<!-- skeleton -->
<monster attack="4" defense="3" damage_min="2" damage_max="3" hp="4" speed="4" grown="8" gold="75" />
<!-- zombie -->
<monster attack="5" defense="2" damage_min="2" damage_max="3" hp="15" speed="2" grown="6" gold="150" />
<!-- mutant zombie -->
<monster attack="5" defense="2" damage_min="2" damage_max="3" hp="25" speed="4" grown="6" gold="200" />
<!-- mummy -->
<monster attack="6" defense="6" damage_min="3" damage_max="4" hp="25" speed="4" grown="4" gold="250" />
<!-- royal mummy -->
<monster attack="6" defense="6" damage_min="3" damage_max="4" hp="30" speed="5" grown="4" gold="300" />
<!-- vampire -->
<monster attack="8" defense="6" damage_min="5" damage_max="7" hp="30" speed="4" grown="3" gold="500" />
<!-- vampire lord -->
<monster attack="8" defense="6" damage_min="5" damage_max="7" hp="40" speed="5" grown="3" gold="650" />
<!-- lich -->
<monster attack="7" defense="12" damage_min="8" damage_max="10" hp="25" speed="5" grown="2" shots="12" gold="750" />
<!-- power lich -->
<monster attack="7" defense="13" damage_min="8" damage_max="10" hp="35" speed="6" grown="2" shots="24" gold="900" />
<!-- bone dragon -->
<monster attack="11" defense="9" damage_min="25" damage_max="45" hp="150" speed="4" grown="1" gold="1500" />
<!-- rogue -->
<monster attack="6" defense="1" damage_min="1" damage_max="2" hp="4" speed="5" grown="4" gold="50" />
<!-- nomad -->
<monster attack="7" defense="6" damage_min="2" damage_max="5" hp="20" speed="6" grown="4" gold="200" />
<!-- ghost -->
<monster attack="8" defense="7" damage_min="4" damage_max="6" hp="20" speed="5" grown="4" gold="1000" />
<!-- genie -->
<monster attack="10" defense="9" damage_min="20" damage_max="30" hp="50" speed="6" grown="4" gold="650" gems="1" />
<!-- medusa -->
<monster attack="8" defense="9" damage_min="6" damage_max="10" hp="35" speed="4" grown="4" gold="500" />
<!-- earth element -->
<monster attack="8" defense="8" damage_min="4" damage_max="5" hp="50" speed="3" grown="4" gold="500" />
<!-- air element -->
<monster attack="7" defense="7" damage_min="2" damage_max="8" hp="35" speed="6" grown="4" gold="500" />
<!-- fire element -->
<monster attack="8" defense="6" damage_min="4" damage_max="6" hp="40" speed="5" grown="4" gold="500" />
<!-- water element -->
<monster attack="6" defense="8" damage_min="3" damage_max="7" hp="45" speed="4" grown="4" gold="500" />
</monsters>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<payments>
<!-- <payment gold="0" wood="0" mercury="0" ore="0" sulfur="0" crystal="0" gems="0" /> -->
<buy_boat gold="1000" wood="10" />
<buy_spell_book gold="500" />
<buy_spell_book_from_shrine1 gold="1250" />
<buy_spell_book_from_shrine2 gold="1000" />
<buy_spell_book_from_shrine3 gold="750" />
<!-- recruit hero: main price -->
<recruit_hero gold="2500" />
<!-- recruit hero: level price -->
<recruit_level gold="500" />
</payments>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" ?>
<profits>
<!-- <profit gold="0" wood="0" mercury="0" ore="0" sulfur="0" crystal="0" gems="0" /> -->
<castle gold="1000" />
<town gold="250" />
<statue gold="250" />
<dungeon gold="500" />
<sawmill wood="2" />
<alchemylab mercury="1" />
<mine_ore ore="2" />
<mine_sulfur sulfur="1" />
<mine_crystal crystal="1" />
<mine_gems gems="1" />
<mine_gold gold="1000" />
<ultimate_golden_goose gold="10000" />
<endless_sack_gold gold="1000" />
<endless_bag_gold gold="750" />
<endless_purse_gold gold="500" />
<endless_cord_wood wood="2" />
<endless_vial_mercury mercury="1" />
<endless_cart_ore ore="2" />
<endless_pouch_sulfur sulfur="1" />
<endless_pouch_crystal crystal="1" />
<endless_pouch_gems gems="1" />
</profits>

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" ?>
<skills>
<!--
sec skill values: archery, ballistics, diplomacy, eagleeye, estates, leadership, logistics, luck, mysticism, navigation, necromancy, pathfinding, scouting, wisdom
level value: basic = 1, advanced = 2, expert = 2
spells: see spell.h
-->
<captain>
<knight attack="2" defense="2" power="1" knowledge="1" />
<barbarian attack="3" defense="1" power="1" knowledge="1" />
<sorceress attack="0" defense="0" power="2" knowledge="3" />
<warlock attack="0" defense="0" power="3" knowledge="2" />
<wizard attack="0" defense="1" power="2" knowledge="2" />
<necromancer attack="1" defense="0" power="2" knowledge="2" />
</captain>
<initial>
<knight attack="2" defense="2" power="1" knowledge="1" ballistics="1" leadership="1" />
<barbarian attack="3" defense="1" power="1" knowledge="1" pathfinding="2" />
<sorceress attack="0" defense="0" power="2" knowledge="3" book="1" spell="15" wisdom="1" navigation="2" />
<warlock attack="0" defense="0" power="3" knowledge="2" book="1" spell="19" wisdom="1" scouting="2" />
<wizard attack="0" defense="1" power="2" knowledge="2" book="1" spell="17" wisdom="2" />
<necromancer attack="1" defense="0" power="2" knowledge="2" book="1" spell="10" wisdom="1" necromancy="1" />
</initial>
<maturity>
<primary>
<under>
<!-- total sum: 100 -->
<knight attack="35" defense="45" power="10" knowledge="10" />
<barbarian attack="55" defense="35" power="5" knowledge="5" />
<sorceress attack="10" defense="10" power="30" knowledge="50" />
<warlock attack="10" defense="10" power="50" knowledge="30" />
<wizard attack="10" defense="10" power="40" knowledge="40" />
<necromancer attack="15" defense="15" power="35" knowledge="35" />
</under>
<over>
<!-- total sum: 100 -->
<knight level="10" attack="25" defense="25" power="25" knowledge="25" />
<barbarian level="10" attack="30" defense="30" power="20" knowledge="20" />
<sorceress level="10" attack="20" defense="20" power="30" knowledge="30" />
<warlock level="10" attack="20" defense="20" power="30" knowledge="30" />
<wizard level="10" attack="20" defense="20" power="30" knowledge="30" />
<necromancer level="10" attack="25" defense="25" power="25" knowledge="25" />
</over>
</primary>
<secondary>
<!-- total sum: 32 -->
<knight archery="2" ballistics="4" diplomacy="3" eagleeye="1" estates="3" leadership="5" logistics="3" luck="1" mysticism="1" navigation="2" necromancy="0" pathfinding="3" scouting="2" wisdom="2" />
<barbarian archery="3" ballistics="3" diplomacy="2" eagleeye="1" estates="2" leadership="3" logistics="3" luck="2" mysticism="1" navigation="3" necromancy="0" pathfinding="4" scouting="4" wisdom="1" />
<sorceress archery="3" ballistics="3" diplomacy="2" eagleeye="2" estates="2" leadership="1" logistics="2" luck="3" mysticism="3" navigation="4" necromancy="0" pathfinding="2" scouting="1" wisdom="4" />
<warlock archery="1" ballistics="3" diplomacy="2" eagleeye="3" estates="2" leadership="1" logistics="2" luck="1" mysticism="3" navigation="2" necromancy="1" pathfinding="2" scouting="4" wisdom="5" />
<wizard archery="1" ballistics="3" diplomacy="2" eagleeye="3" estates="2" leadership="2" logistics="2" luck="2" mysticism="4" navigation="2" necromancy="0" pathfinding="2" scouting="2" wisdom="5" />
<necromancer archery="1" ballistics="3" diplomacy="2" eagleeye="3" estates="2" leadership="0" logistics="2" luck="1" mysticism="3" navigation="2" necromancy="5" pathfinding="3" scouting="1" wisdom="4" />
</secondary>
</maturity>
<secondary>
<!--
<wisdom basic="3" advanced="4" expert="5" />
-->
<mysticism basic="2" advanced="3" expert="4" />
<leadership basic="1" advanced="2" expert="3" />
<luck basic="1" advanced="2" expert="3" />
<scouting basic="1" advanced="2" expert="3" />
<ballistics basic="0" advanced="0" expert="0" />
<estates basic="100" advanced="250" expert="500" />
<!-- percents: max 100 -->
<logistics basic="10" advanced="20" expert="30" />
<navigation basic="33" advanced="66" expert="100" />
<archery basic="10" advanced="25" expert="50" />
<necromancy basic="10" advanced="20" expert="30" />
<eagleeye basic="20" advanced="30" expert="40" />
<diplomacy basic="25" advanced="50" expert="100" />
<pathfinding basic="25" advanced="50" expert="100" />
</secondary>
</skills>

View File

@@ -0,0 +1,139 @@
<?xml version="1.0" ?>
<spells>
<!-- first: unknown spell -->
<spell skip="0" cost="1" />
<!-- Fireball -->
<spell cost="9" extra="10" />
<!-- Fireblast -->
<spell cost="15" extra="10" />
<!-- Lightning Bolt -->
<spell cost="7" extra="25" />
<!-- Chain Lightning -->
<spell cost="15" extra="40" />
<!-- Teleport -->
<spell cost="9" />
<!-- Cure -->
<spell cost="6" extra="5" />
<!-- Mass Cure -->
<spell cost="15" extra="5" />
<!-- Resurrect -->
<spell cost="12" extra="50" />
<!-- Resurrect True -->
<spell cost="15" extra="50" />
<!-- Haste (if set: current + extra, or zero: default h2) -->
<spell cost="3" extra="0" />
<!-- Mass Haste (extra used from Haste) -->
<spell cost="10" />
<!-- Slow (if set: current - extra, or zero: default h2) -->
<spell cost="3" extra="0" />
<!-- Mass Slow (extra used from Slow) -->
<spell cost="15" />
<!-- Blind -->
<spell cost="6" />
<!-- Bless -->
<spell cost="3" />
<!-- Mass Bless -->
<spell cost="12" />
<!-- Stoneskin -->
<spell cost="3" extra="3" />
<!-- Steelskin -->
<spell cost="6" extra="5" />
<!-- Curse -->
<spell cost="3" />
<!-- Mass Curse -->
<spell cost="12" />
<!-- Holy Word -->
<spell cost="9" extra="10" />
<!-- Holy Shout -->
<spell cost="12" extra="20" />
<!-- Anti-Magic -->
<spell cost="7" />
<!-- Dispel Magic -->
<spell cost="5" />
<!-- Mass Dispel -->
<spell cost="12" />
<!-- Magic Arrow -->
<spell cost="3" extra="10" />
<!-- Berserker -->
<spell cost="12" />
<!-- Armageddon -->
<spell cost="20" extra="50" />
<!-- Elemental Storm -->
<spell cost="15" extra="25" />
<!-- Meteor Shower -->
<spell cost="15" extra="25" />
<!-- Paralyze -->
<spell cost="9" />
<!-- Hypnotize -->
<spell cost="15" extra="25" />
<!-- Cold Ray -->
<spell cost="6" extra="20" />
<!-- Cold Ring -->
<spell cost="9" extra="10" />
<!-- Disrupting Ray -->
<spell cost="7" extra="3" />
<!-- Death Ripple -->
<spell cost="6" extra="5" />
<!-- Death Wave -->
<spell cost="10" extra="10" />
<!-- Dragon Slayer -->
<spell cost="6" extra="5" />
<!-- Blood Lust -->
<spell cost="3" extra="3" />
<!-- Animate Dead -->
<spell cost="10" extra="50" />
<!-- Mirror Image -->
<spell cost="25" />
<!-- Shield -->
<spell cost="3" extra="2" />
<!-- Mass Shield -->
<spell cost="7" />
<!-- Summon Earth Elemental -->
<spell cost="30" extra="3" />
<!-- Summon Air Elemental -->
<spell cost="30" extra="3" />
<!-- Summon Fire Elemental -->
<spell cost="30" extra="3" />
<!-- Summon Water Elemental -->
<spell cost="30" extra="3" />
<!-- Earthquake -->
<spell cost="15" />
<!-- View Mines -->
<spell cost="1" />
<!-- View Resources -->
<spell cost="1" />
<!-- View Artifacts -->
<spell cost="2" />
<!-- View Towns -->
<spell cost="2" />
<!-- View Heroes -->
<spell cost="2" />
<!-- View All -->
<spell cost="3" />
<!-- Identify Hero -->
<spell cost="3" />
<!-- Summon Boat -->
<spell cost="5" />
<!-- Dimension Door (distance settings, or distance="0" for defaults: 14) OR:
current_distance = configurable_distance * (current_sp * configurable_hp) / (configurable_sp * current_hp) -->
<spell cost="10" distance="10" sp="2" hp="100" />
<!-- Town Gate -->
<spell cost="10" />
<!-- Town Portal -->
<spell cost="20" />
<!-- Visions -->
<spell cost="6" />
<!-- Haunt -->
<spell cost="8" extra="4" />
<!-- Set Earth Guardian -->
<spell cost="15" extra="4" />
<!-- Set Air Guardian -->
<spell cost="15" extra="4" />
<!-- Set Fire Guardian -->
<spell cost="15" extra="4" />
<!-- Set Water Guardian -->
<spell cost="15" extra="4" />
</spells>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -0,0 +1,68 @@
Free Heroes2 Engine (is not playable version.)
Prerequisites:
You need to have these libraries (with equivalent devel versions) to build fHeroes2:
- SDL
optional library:
- SDL_mixer (play music: internal midi or external ogg tracks) or build WITHOUT_MIXER
- SDL_image (loading external sprites, create screenshot in png format) or build WITHOUT_IMAGE
- SDL_ttf (unicode support) or build WITHOUT_UNICODE
- SDL_net or build WITHOUT_NETWORK
- libogg
- libpng
- gettext
SDL libraries can be found at http://www.libsdl.org .
Sourcecode you can get it here: http://sourceforge.net/projects/fheroes2/
And translations: http://translations.launchpad.net/fheroes2
Copy origin data/*.agg in to data directory.
Copy maps files (*.mp2) in to maps directory.
Hot keys:
F4 - switch to fullscreen
PrintScreen - create screenshot
Up - move hero top
Down - move hero bottom
Left - move hero left
Right - move hero right
Ctrl + Up - scroll map top (alt. key ';')
Ctrl + Down - scroll map bottom (alt. key '/')
Ctrl + Left - scroll map left (alt. key ',')
Ctrl + Right - scroll map right (alt. key '.')
e - end turn
t - next town
h - next hero
m - move hero
s - save game to fheroes2.sav
l - load game
i - game info
p - puzzle dialog
d - digging artifact for current hero
space or a - default action
return or n - open dialog
o - system dialog
1 - show/hide control panel
2 - show/hide radar (only for option: hide interface = on)
3 - show/hide buttons (only for option: hide interface = on)
4 - show/hide status window (only for option: hide interface = on)
5 - show/hide hero/town icons (only for option: hide interface = on)
Main menu:
n - new game
s - standard game
c - campaign game
m - multi-player game
Battle:
Esc - fast retreat
space - skip turn (soft: heroes3 version)
s - skip turn (hard)
o - options dialog
a - set auto battle
c - show spell book
h - show heroes dialog

View File

@@ -0,0 +1,94 @@
# makefile
# project: Free Heroes2
#
TARGET := fheroes2
SDL_LIBS := $(shell sdl-config --libs)
SDL_FLAGS := $(shell sdl-config --cflags)
CFLAGS := $(CFLAGS) -Wall -fsigned-char -DWITH_KEYMAPPING
LDFLAGS :=
LIBS :=
ifdef DEBUG
CFLAGS := $(CFLAGS) -O0 -g -pedantic -DWITH_DEBUG
else
CFLAGS := $(CFLAGS) -O2
endif
ifndef WITHOUT_MIXER
CFLAGS := $(CFLAGS) -DWITH_MIXER
SDL_LIBS := $(SDL_LIBS) -lSDL_mixer
endif
ifndef WITHOUT_IMAGE
CFLAGS := $(CFLAGS) -DWITH_IMAGE $(shell libpng12-config --cflags) -DWITH_ZLIB
SDL_LIBS := $(SDL_LIBS) -lSDL_image $(shell libpng12-config --libs) -lz
endif
ifndef WITHOUT_UNICODE
CFLAGS := $(CFLAGS) -DWITH_TTF
SDL_LIBS := $(SDL_LIBS) -lSDL_ttf
endif
ifndef WITHOUT_NETWORK
CFLAGS := $(CFLAGS) -DWITH_NET
SDL_LIBS := $(SDL_LIBS) -lSDL_net
endif
ifndef WITHOUT_XML
CFLAGS := $(CFLAGS) -DWITH_XML
endif
ifndef WITHOUT_ZLIB
CFLAGS := $(CFLAGS) -DWITH_ZLIB
LIBS := $(LIBS) -lz
endif
ifndef WITHOUT_EDITOR
CFLAGS := $(CFLAGS) -DWITH_EDITOR
endif
ifdef RELEASE
CFLAGS := $(CFLAGS) -DBUILD_RELEASE
endif
CFLAGS := $(SDL_FLAGS) $(CFLAGS)
LIBS := $(SDL_LIBS) $(LIBS)
ifeq ($(PLATFORM),)
ifeq ($(OS),Windows_NT)
PLATFORM := mingw
else
PLATFORM := unix
endif
endif
include Makefile.$(PLATFORM)
export CXX AR LINK WINDRES LDFLAGS CFLAGS LIBS PLATFORM
.PHONY: clean
all:
ifndef WITHOUT_XML
$(MAKE) -C xmlccwrap
endif
$(MAKE) -C engine
$(MAKE) -C dist
ifdef WITH_TOOLS
$(MAKE) -C tools
endif
ifndef WITHOUT_UNICODE
$(MAKE) -C dist pot
endif
clean:
ifndef WITHOUT_XML
$(MAKE) -C xmlccwrap clean
endif
ifdef WITH_TOOLS
$(MAKE) -C tools clean
endif
$(MAKE) -C dist clean
$(MAKE) -C engine clean

View File

@@ -0,0 +1,5 @@
include Makefile.unix
ifndef WITHOUT_UNICODE
LIBS := $(LIBS) -lintl -liconv
endif

View File

@@ -0,0 +1,27 @@
ifndef WITHOUT_MIXER
LIBS := $(LIBS) -lSDL -lmad -lvorbisfile -lvorbis -logg
endif
ifndef WITHOUT_IMAGE
LIBS := $(LIBS) -lSDL -lpng -ljpeg
endif
ifndef WITHOUT_UNICODE
LIBS := $(LIBS) -lintl -lfreetype
endif
ifndef WITHOUT_AUDIOCD
CFLAGS := $(CFLAGS) -DWITH_AUDIOCD
endif
ifdef WITH_ICONS
IDICON := 1099
CFLAGS := $(CFLAGS) -DID_ICON=$(IDICON)
export IDICON
endif
AR := i686-pc-mingw32-ar
CXX := i686-pc-mingw32-g++
WINDRES := i686-pc-mingw32-windres
CFLAGS := $(CFLAGS) -O2 -static
LIBS := -static -Wl,-Bstatic $(LIBS) -lwinmm

View File

@@ -0,0 +1,20 @@
ifndef WITHOUT_MIXER
LIBS := $(LIBS) -lSDL -lmad -lvorbisfile -lvorbis -logg
endif
ifndef WITHOUT_UNICODE
LIBS := $(LIBS) -lintl -lfreetype
endif
ifdef WITH_ICONS
IDICON := 1099
CFLAGS := $(CFLAGS) -DID_ICON=$(IDICON)
export IDICON
endif
AR := arm-mingw32ce-ar
CXX := arm-mingw32ce-g++
WINDRES := arm-mingw32ce-windres
CFLAGS := $(CFLAGS) -ffunction-sections -DWITHOUT_MOUSE -Os -static
LIBS := -Wl,-Bstatic $(LIBS) -lmmtimer
LDFLAGS := -static $(LDFLAGS) -Wl,--gc-sections

View File

@@ -0,0 +1,16 @@
AR := ar
CXX := g++
LINK := libtool
SIMPLE_LINK_FLAGS := -dynamic -undefined suppress -flat_namespace
ifndef WITHOUT_UNICODE
LIBS := $(LIBS) -lintl -liconv
endif
# the config scripts generate link flags like -Wl,-framework which screws up
# libtool on OS X, so we remove the -Wl, prefix and everything works fine.
search_pattern := -Wl
comma_pattern := ,
LINK_FLAGS := $(subst $(search_pattern),,$(LIBS))
LINK_FLAGS := $(subst $(comma_pattern), ,$(LINK_FLAGS)) $(SIMPLE_LINK_FLAGS)

View File

@@ -0,0 +1,2 @@
AR := ar
CXX := g++

View File

@@ -0,0 +1,280 @@
/*
Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
"Philip D. Bober" <wildfire1138@mchsi.com>
*/
/* 2010 - support: sdl 1.3 - fheroes2 team */
/* 2009 - changed: save 16bpp, 24bpp - fheroes2 team */
/* 2008 - changed: default color - fheroes2 team */
/**
* 4/17/04 - IMG_SavePNG & IMG_SavePNG_RW - Philip D. Bober
* 11/08/2004 - Compr fix, levels -1,1-7 now work - Tyler Montbriand
*/
#include <stdlib.h>
#include "SDL.h"
#include "IMG_savepng.h"
#ifdef WITH_IMAGE
#include "png.h"
int IMG_SavePNG(const char *file, SDL_Surface *surf,int compression){
SDL_RWops *fp;
int ret;
fp=SDL_RWFromFile(file,"wb");
if( fp == NULL ) {
return (-1);
}
ret=IMG_SavePNG_RW(fp,surf,compression);
SDL_RWclose(fp);
return ret;
}
static void png_write_data(png_structp png_ptr,png_bytep data, png_size_t length){
SDL_RWops *rp = (SDL_RWops*) png_get_io_ptr(png_ptr);
SDL_RWwrite(rp,data,1,length);
}
int IMG_SavePNG_RW(SDL_RWops *src, SDL_Surface *surf,int compression){
png_structp png_ptr;
png_infop info_ptr;
SDL_PixelFormat *fmt=NULL;
SDL_Surface *tempsurf=NULL;
int ret,funky_format;
unsigned int i;
Uint8 used_alpha, temp_alpha = 0;
png_colorp palette;
Uint8 *palette_alpha=NULL;
png_byte **row_pointers=NULL;
png_ptr=NULL;info_ptr=NULL;palette=NULL;ret=-1;
funky_format=0;
if( !src || !surf) {
goto savedone; /* Nothing to do. */
}
row_pointers=(png_byte **)malloc(surf->h * sizeof(png_byte*));
if (!row_pointers) {
SDL_SetError("Couldn't allocate memory for rowpointers");
goto savedone;
}
png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
if (!png_ptr){
SDL_SetError("Couldn't allocate memory for PNG file");
goto savedone;
}
info_ptr= png_create_info_struct(png_ptr);
if (!info_ptr){
SDL_SetError("Couldn't allocate image information for PNG file");
goto savedone;
}
/* setup custom writer functions */
png_set_write_fn(png_ptr,(voidp)src,png_write_data,NULL);
if (setjmp(png_jmpbuf(png_ptr))){
SDL_SetError("Unknown error writing PNG");
goto savedone;
}
if(compression>Z_BEST_COMPRESSION)
compression=Z_BEST_COMPRESSION;
if(compression == Z_NO_COMPRESSION) // No compression
{
png_set_filter(png_ptr,0,PNG_FILTER_NONE);
png_set_compression_level(png_ptr,Z_NO_COMPRESSION);
}
else if(compression<0) // Default compression
png_set_compression_level(png_ptr,Z_DEFAULT_COMPRESSION);
else
png_set_compression_level(png_ptr,compression);
fmt=surf->format;
if(fmt->BitsPerPixel==8){ /* Paletted */
png_set_IHDR(png_ptr,info_ptr,
surf->w,surf->h,8,PNG_COLOR_TYPE_PALETTE,
PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
palette=(png_colorp) malloc(fmt->palette->ncolors * sizeof(png_color));
if (!palette) {
SDL_SetError("Couldn't create memory for palette");
goto savedone;
}
for (i=0;(signed int)i<fmt->palette->ncolors;i++) {
palette[i].red=fmt->palette->colors[i].r;
palette[i].green=fmt->palette->colors[i].g;
palette[i].blue=fmt->palette->colors[i].b;
}
png_set_PLTE(png_ptr,info_ptr,palette,fmt->palette->ncolors);
if (surf->flags&SDL_SRCCOLORKEY) {
Uint32 colorkey = 0;
#if SDL_VERSION_ATLEAST(1, 3, 0)
SDL_GetColorKey(surf, &colorkey);
#else
colorkey = fmt->colorkey + 1;
#endif
palette_alpha=(Uint8 *)malloc((colorkey+1)*sizeof(Uint8));
if (!palette_alpha) {
SDL_SetError("Couldn't create memory for palette transparency");
goto savedone;
}
memset(palette_alpha, 0, (colorkey+1)*sizeof(Uint8));
palette_alpha[colorkey]=0;
png_set_tRNS(png_ptr,info_ptr,palette_alpha,(colorkey+1),NULL);
}
}else{ /* Truecolor */
png_set_IHDR(png_ptr,info_ptr,
surf->w,surf->h,8,PNG_COLOR_TYPE_RGB_ALPHA,
PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
}
png_write_info(png_ptr, info_ptr);
if (fmt->BitsPerPixel==8) { /* Paletted */
for(i=0;(signed int)i<surf->h;i++){
row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch;
}
if(SDL_MUSTLOCK(surf)){
SDL_LockSurface(surf);
}
png_write_image(png_ptr, row_pointers);
if(SDL_MUSTLOCK(surf)){
SDL_UnlockSurface(surf);
}
}else{ /* Truecolor */
if(fmt->BytesPerPixel==3){
if(fmt->Amask){ /* check for 24 bit with alpha */
funky_format=1;
}else{
/* Check for RGB/BGR/GBR/RBG/etc surfaces.*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
if(fmt->Rmask!=0xFF0000
|| fmt->Gmask!=0x00FF00
|| fmt->Bmask!=0x0000FF){
#else
if(fmt->Rmask!=0x0000FF
|| fmt->Gmask!=0x00FF00
|| fmt->Bmask!=0xFF0000){
#endif
funky_format=1;
}
}
}else if (fmt->BytesPerPixel==4){
if (!fmt->Amask) { /* check for 32bit but no alpha */
funky_format=1;
}else{
/* Check for ARGB/ABGR/GBAR/RABG/etc surfaces.*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
if(fmt->Rmask!=0xFF000000
|| fmt->Gmask!=0x00FF0000
|| fmt->Bmask!=0x0000FF00
|| fmt->Amask!=0x000000FF){
#else
if(fmt->Rmask!=0x000000FF
|| fmt->Gmask!=0x0000FF00
|| fmt->Bmask!=0x00FF0000
|| fmt->Amask!=0xFF000000){
#endif
funky_format=1;
}
}
}else{ /* 555 or 565 16 bit color */
funky_format=1;
}
if (funky_format) {
/* Allocate non-funky format, and copy pixeldata in*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32,
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
if(!tempsurf){
SDL_SetError("Couldn't allocate temp surface");
goto savedone;
}
if(surf->flags&SDL_SRCALPHA){
#if SDL_VERSION_ATLEAST(1, 3, 0)
SDL_GetSurfaceAlphaMod(surf, &temp_alpha);
#else
temp_alpha=fmt->alpha;
#endif
used_alpha=1;
SDL_SetAlpha(surf,0,255); /* Set for an opaque blit */
}else{
used_alpha=0;
}
if(SDL_BlitSurface(surf,NULL,tempsurf,NULL)!=0){
SDL_SetError("Couldn't blit surface to temp surface");
SDL_FreeSurface(tempsurf);
goto savedone;
}
if (used_alpha) {
SDL_SetAlpha(surf,SDL_SRCALPHA,(Uint8)temp_alpha); /* Restore alpha settings*/
}
for(i=0;(signed int)i<tempsurf->h;i++){
row_pointers[i]= ((png_byte*)tempsurf->pixels) + i*tempsurf->pitch;
}
if(SDL_MUSTLOCK(tempsurf)){
SDL_LockSurface(tempsurf);
}
png_write_image(png_ptr, row_pointers);
if(SDL_MUSTLOCK(tempsurf)){
SDL_UnlockSurface(tempsurf);
}
SDL_FreeSurface(tempsurf);
} else {
for(i=0;(signed int)i<surf->h;i++){
row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch;
}
if(SDL_MUSTLOCK(surf)){
SDL_LockSurface(surf);
}
png_write_image(png_ptr, row_pointers);
if(SDL_MUSTLOCK(surf)){
SDL_UnlockSurface(surf);
}
}
}
png_write_end(png_ptr, NULL);
ret=0; /* got here, so nothing went wrong. YAY! */
savedone: /* clean up and return */
png_destroy_write_struct(&png_ptr,&info_ptr);
if (palette) {
free(palette);
}
if (palette_alpha) {
free(palette_alpha);
}
if (row_pointers) {
free(row_pointers);
}
return ret;
}
#endif

View File

@@ -0,0 +1,56 @@
/*
Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
"Philip D. Bober" <wildfire1138@mchsi.com>
*/
#ifndef __IMG_SAVETOPNG_H__
#define __IMG_SAVETOPNG_H__
/* #include <SDL/begin_code.h> */
#ifdef __cplusplus
extern "C" {
#endif
#define IMG_COMPRESS_OFF 0
#define IMG_COMPRESS_MAX 9
#define IMG_COMPRESS_DEFAULT -1
#ifdef WITH_IMAGE
/**
* Takes a filename, a surface to save, and a compression level. The
* compression level can be 0(min) through 9(max), or -1(default).
*/
DECLSPEC int SDLCALL IMG_SavePNG(const char *file,
SDL_Surface *surf,
int compression);
/**
* Takes a SDL_RWops pointer, a surface to save, and a compression level.
* compression can be 0(min) through 9(max), or -1(default).
*/
DECLSPEC int SDLCALL IMG_SavePNG_RW(SDL_RWops *src,
SDL_Surface *surf,
int compression);
#endif
#ifdef __cplusplus
}
#endif
#endif/*__IMG_SAVETOPNG_H__*/

View File

@@ -0,0 +1,20 @@
# makefile
# project: Free Heroes2
# libSDL C++ wrapper engine
TARGET := libengine
all: $(TARGET).a
$(TARGET).a: $(patsubst %.cpp, %.o, $(wildcard *.cpp))
$(AR) crvs $@ $^
%.o: %.cpp
$(CXX) -c -MD $< $(CFLAGS)
include $(wildcard *.d)
.PHONY: clean
clean:
rm -f *.a *.so *.d *.o

View File

@@ -0,0 +1,86 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include "audio.h"
namespace Audio
{
static Spec hardware;
}
Audio::Spec::Spec()
{
freq = 0;
format = 0;
channels = 0;
silence = 0;
samples = 0;
size = 0;
callback = NULL;
userdata = NULL;
}
Audio::CVT::CVT()
{
needed = 0;
src_format = 0;
dst_format = 0;
rate_incr = 0;
buf = NULL;
len = 0;
len_cvt = 0;
len_mult = 0;
len_ratio = 0;
filters[0] = NULL;
filters[1] = NULL;
filters[2] = NULL;
filters[3] = NULL;
filters[4] = NULL;
filters[5] = NULL;
filters[6] = NULL;
filters[7] = NULL;
filters[8] = NULL;
filters[9] = NULL;
filter_index = 0;
}
bool Audio::CVT::Build(const Audio::Spec & src, const Audio::Spec & dst)
{
if(1 == SDL_BuildAudioCVT(this, src.format, src.channels, src.freq, dst.format, dst.channels, dst.freq)) return true;
std::cerr << "Audio::CVT::Build: " << SDL_GetError() << std::endl;
return false;
}
bool Audio::CVT::Convert(void)
{
if(0 == SDL_ConvertAudio(this)) return true;
std::cerr << "Audio::CVT::Convert: " << SDL_GetError() << std::endl;
return false;
}
Audio::Spec & Audio::GetHardwareSpec(void)
{
return hardware;
}

View File

@@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2AUDIO_H
#define H2AUDIO_H
#include "types.h"
namespace Audio
{
struct Spec : public SDL_AudioSpec
{
Spec();
};
struct CVT : public SDL_AudioCVT
{
CVT();
bool Build(const Spec & src, const Spec & dst);
bool Convert(void);
};
Spec & GetHardwareSpec(void);
}
#endif

View File

@@ -0,0 +1,135 @@
/***************************************************************************
* Copyright (C) 2008 by Josh Matthews <josh@joshmatthews.net> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef WITH_AUDIOCD
#include <iostream>
#include "audio_mixer.h"
#include "audio_cdrom.h"
namespace Cdrom
{
void Open(void);
void Close(void);
static SDL_CD *cd = NULL;
static int currentTrack = -1;
static unsigned int startTime = 0;
static unsigned int tickLength;
static SDL_Thread *loopThread;
static SDL_mutex *cdLock;
int LoopCheck(void *data);
}
void Cdrom::Open(void)
{
for(int i = 0; i < SDL_CDNumDrives(); i++)
{
SDL_CD *drive = SDL_CDOpen(i);
if(drive)
{
if(!CD_INDRIVE(SDL_CDStatus(drive)))
{
SDL_CDClose(drive);
continue;
}
else
if(drive->numtracks > 1 && drive->track[0].type == SDL_DATA_TRACK)
{
cd = drive;
break;
}
}
}
if(cd)
{
loopThread = SDL_CreateThread(&LoopCheck, NULL);
cdLock = SDL_CreateMutex();
}
std::cerr << "Cdrom::Open: " << (cd ? "found CD audio device." : "no CDROM devices available.") << std::endl;
}
void Cdrom::Close(void)
{
if(cd)
{
SDL_CDStop(cd);
SDL_KillThread(loopThread);
SDL_DestroyMutex(cdLock);
SDL_CDClose(cd);
cd = NULL;
}
}
bool Cdrom::isValid(void)
{
return cd;
}
int Cdrom::LoopCheck(void *data)
{
while(1)
{
SDL_Delay(5000);
SDL_LockMutex(cdLock);
if(startTime && SDL_GetTicks() - startTime > tickLength)
Play(currentTrack, true, true);
SDL_UnlockMutex(cdLock);
}
return 0;
}
void Cdrom::Play(const u8 track, bool loop, bool force)
{
if(Mixer::isValid() && cd)
{
SDL_LockMutex(cdLock);
if(currentTrack != track || force)
{
if(SDL_CDPlayTracks(cd, track, 0, 1, 0) < 0)
std::cerr << "Cdrom::Play: Couldn't play track " << static_cast<int>(track) << std::endl;
currentTrack = track;
if(loop)
{
tickLength = (unsigned int)((cd->track[track].length / CD_FPS) * 0.01f);
startTime = SDL_GetTicks();
}
else startTime = 0;
if(SDL_CDStatus(cd) != CD_PLAYING)
std::cerr << "Cdrom::Play: CD is not playing" << SDL_GetError() << std::endl;
}
SDL_UnlockMutex(cdLock);
}
}
void Cdrom::Pause(void)
{
if(cd) SDL_CDPause(cd);
}
#endif

View File

@@ -0,0 +1,37 @@
/***************************************************************************
* Copyright (C) 2008 by Josh Matthews <josh@joshmatthews.net> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2AUDIO_CDROM_H
#define H2AUDIO_CDROM_H
#ifdef WITH_AUDIOCD
#include "types.h"
namespace Cdrom
{
bool isValid(void);
void Play(const u8 track, bool loop, bool force = false);
void Pause(void);
}
#endif
#endif

View File

@@ -0,0 +1,490 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <algorithm>
#include <iostream>
#include "engine.h"
#include "audio.h"
#include "audio_cdrom.h"
#include "audio_music.h"
#include "audio_mixer.h"
namespace Mixer
{
void Init(void);
void Quit(void);
bool valid = false;
}
bool Mixer::isValid(void)
{
return valid;
}
#ifdef WITH_MIXER
#include "SDL_mixer.h"
void FreeChannel(int channel)
{
Mixer::chunk_t* sample = Mix_GetChunk(channel);
if(sample) Mix_FreeChunk(sample);
}
void Mixer::Init(void)
{
if(SDL::SubSystem(SDL_INIT_AUDIO))
{
Audio::Spec & hardware = Audio::GetHardwareSpec();
hardware.freq = 22050;
hardware.format = AUDIO_S16;
hardware.channels = 2;
hardware.samples = 2048;
if(0 != Mix_OpenAudio(hardware.freq, hardware.format, hardware.channels, hardware.samples))
{
std::cerr << "Mixer: " << SDL_GetError() << std::endl;
valid = false;
}
else
{
int channels = 0;
Mix_QuerySpec(&hardware.freq, &hardware.format, &channels);
hardware.channels = channels;
valid = true;
}
}
else
{
std::cerr << "Mixer: audio subsystem not initialize" << std::endl;
valid = false;
}
}
void Mixer::Quit(void)
{
if(! SDL::SubSystem(SDL_INIT_AUDIO) || !valid) return;
Mixer::Reset();
valid = false;
Mix_CloseAudio();
}
void Mixer::SetChannels(u8 num)
{
Mix_AllocateChannels(num);
Mix_ReserveChannels(1);
}
void Mixer::FreeChunk(chunk_t *sample)
{
if(sample) Mix_FreeChunk(sample);
}
Mixer::chunk_t* Mixer::LoadWAV(const char* file)
{
Mix_Chunk *sample = Mix_LoadWAV(file);
if(!sample) std::cerr << "Mixer::LoadWAV: " << Mix_GetError() << std::endl;
return sample;
}
Mixer::chunk_t* Mixer::LoadWAV(const u8* ptr, u32 size)
{
Mix_Chunk *sample = Mix_LoadWAV_RW(SDL_RWFromConstMem(ptr, size), 1);
if(!sample) std::cerr << "Mixer::LoadWAV: "<< Mix_GetError() << std::endl;
return sample;
}
int Mixer::Play(chunk_t* sample, int channel, bool loop)
{
int res = Mix_PlayChannel(channel, sample, loop ? -1 : 0);
if(res == -1) std::cerr << "Mixer::Play: " << Mix_GetError() << std::endl;;
return res;
}
int Mixer::Play(const char* file, int channel, bool loop)
{
if(valid)
{
chunk_t* sample = LoadWAV(file);
if(sample)
{
Mix_ChannelFinished(FreeChannel);
return Play(sample, channel, loop);
}
}
return -1;
}
int Mixer::Play(const u8* ptr, u32 size, int channel, bool loop)
{
if(valid && ptr)
{
chunk_t* sample = LoadWAV(ptr, size);
if(sample)
{
Mix_ChannelFinished(FreeChannel);
return Play(sample, channel, loop);
}
}
return -1;
}
u16 Mixer::MaxVolume(void)
{
return MIX_MAX_VOLUME;
}
u16 Mixer::Volume(int channel, s16 vol)
{
if(!valid) return 0;
return Mix_Volume(channel, vol > MIX_MAX_VOLUME ? MIX_MAX_VOLUME : vol);
}
void Mixer::Pause(int channel)
{
Mix_Pause(channel);
}
void Mixer::Resume(int channel)
{
Mix_Resume(channel);
}
void Mixer::Stop(int channel)
{
Mix_HaltChannel(channel);
}
void Mixer::Reset(void)
{
Music::Reset();
#ifdef WITH_AUDIOCD
if(Cdrom::isValid()) Cdrom::Pause();
#endif
Mix_HaltChannel(-1);
}
u8 Mixer::isPlaying(int channel)
{
return Mix_Playing(channel);
}
u8 Mixer::isPaused(int channel)
{
return Mix_Paused(channel);
}
void Mixer::Reduce(void)
{
}
void Mixer::Enhance(void)
{
}
#else
enum { MIX_PLAY = 0x01, MIX_LOOP = 0x02, MIX_REDUCE = 0x04, MIX_ENHANCE = 0x08 };
struct chunk_t
{
chunk_t() : data(NULL), length(0), position(0), volume1(0), state(0) {};
bool this_ptr(const chunk_t* ch) const{ return ch == this; };
const u8 * data;
u32 length;
u32 position;
s16 volume1;
s16 volume2;
u8 state;
};
namespace Mixer
{
bool PredicateIsFreeSound(const chunk_t &);
void PredicateStopSound(chunk_t &);
void PredicateStartSound(chunk_t &);
void AudioCallBack(void*, u8*, int);
std::vector<chunk_t> chunks;
u8 reserved_channels;
}
void Mixer::PredicateStopSound(chunk_t & ch)
{
SDL_LockAudio();
ch.state &= ~MIX_PLAY;
SDL_UnlockAudio();
}
void Mixer::PredicateStartSound(chunk_t & ch)
{
SDL_LockAudio();
ch.state |= MIX_PLAY;
SDL_UnlockAudio();
}
bool Mixer::PredicateIsFreeSound(const chunk_t & ch)
{
return !(ch.state & MIX_PLAY);
}
void Mixer::AudioCallBack(void *unused, u8 *stream, int length)
{
for(u8 ii = 0; ii < chunks.size(); ++ii)
{
chunk_t & ch = chunks[ii];
if((ch.state & MIX_PLAY) && ch.volume1)
{
if(ch.state & MIX_REDUCE)
{
ch.volume1 -= 10;
if(ch.volume1 <= 0)
{
ch.volume1 = 0;
ch.state &= ~MIX_REDUCE;
}
}
else
if(ch.state & MIX_ENHANCE)
{
ch.volume1 += 10;
if(ch.volume1 >= ch.volume2)
{
ch.volume1 = ch.volume2;
ch.state &= ~MIX_ENHANCE;
}
}
SDL_MixAudio(stream, &ch.data[ch.position], (ch.position + length > ch.length ? ch.length - ch.position : length), ch.volume1);
ch.position += length;
if(ch.position >= ch.length)
{
ch.position = 0;
if(!(ch.state & MIX_LOOP)) ch.state &= ~MIX_PLAY;
}
}
}
}
void Mixer::Init(void)
{
if(SDL::SubSystem(SDL_INIT_AUDIO))
{
Audio::Spec spec;
spec.freq = 22050;
spec.format = AUDIO_S16;
spec.channels = 2;
spec.samples = 2048;
spec.callback = AudioCallBack;
if(0 > SDL_OpenAudio(&spec, &Audio::GetHardwareSpec()))
{
std::cerr << "Mixer::Init: " << SDL_GetError() << std::endl;
valid = false;
}
else
{
SDL_PauseAudio(0);
valid = true;
reserved_channels = 0;
}
}
else
{
std::cerr << "Mixer::Init: audio subsystem not initialize" << std::endl;
valid = false;
}
}
void Mixer::Quit(void)
{
if(! SDL::SubSystem(SDL_INIT_AUDIO) || !valid) return;
Music::Reset();
Mixer::Reset();
SDL_CloseAudio();
chunks.clear();
valid = false;
}
void Mixer::SetChannels(u8 num)
{
chunks.resize(num);
reserved_channels = 1;
}
u16 Mixer::MaxVolume(void)
{
return SDL_MIX_MAXVOLUME;
}
u16 Mixer::Volume(int ch, s16 vol)
{
if(!valid) return 0;
if(vol > SDL_MIX_MAXVOLUME) vol = SDL_MIX_MAXVOLUME;
if(ch < 0)
{
for(u8 ii = 0; ii < chunks.size(); ++ii)
{
SDL_LockAudio();
chunks[ii].volume1 = vol;
chunks[ii].volume2 = vol;
SDL_UnlockAudio();
}
}
else
if(ch < static_cast<int>(chunks.size()))
{
if(0 > vol)
{
vol = chunks[ch].volume1;
}
else
{
SDL_LockAudio();
chunks[ch].volume1 = vol;
chunks[ch].volume2 = vol;
SDL_UnlockAudio();
}
}
return vol;
}
int Mixer::Play(const u8* ptr, u32 size, int channel, bool loop)
{
if(valid && ptr)
{
chunk_t* ch = NULL;
if(0 > channel)
{
std::vector<chunk_t>::iterator it = std::find_if(chunks.begin(), chunks.end(), std::bind2nd(std::mem_fun_ref(&chunk_t::this_ptr), ptr));
if(it == chunks.end())
{
it = std::find_if(chunks.begin() + reserved_channels, chunks.end(), PredicateIsFreeSound);
if(it == chunks.end())
{
std::cerr << "Mixer::PlayRAW: mixer is full" << std::endl;
return -1;
}
}
ch = &(*it);
channel = it - chunks.begin();
}
else
if(channel < static_cast<int>(chunks.size()))
ch = &chunks[channel];
if(ch)
{
SDL_LockAudio();
ch->state |= (loop ? MIX_LOOP | MIX_PLAY : MIX_PLAY);
ch->data = ptr;
ch->length = size;
ch->position = 0;
SDL_UnlockAudio();
}
return channel;
}
return -1;
}
void Mixer::Pause(int ch)
{
if(! valid) return;
if(0 > ch)
std::for_each(chunks.begin(), chunks.end(), PredicateStopSound);
else
if(ch < static_cast<int>(chunks.size())) PredicateStopSound(chunks[ch]);
}
void Mixer::Resume(int ch)
{
if(! valid) return;
if(0 > ch)
std::for_each(chunks.begin(), chunks.end(), PredicateStartSound);
else
if(ch < static_cast<int>(chunks.size())) PredicateStartSound(chunks[ch]);
}
u8 Mixer::isPlaying(int ch)
{
return 0 <= ch && ch < static_cast<int>(chunks.size()) && (chunks[ch].state & MIX_PLAY);
}
u8 Mixer::isPaused(int ch)
{
return 0 <= ch && ch < static_cast<int>(chunks.size()) && !(chunks[ch].state & MIX_PLAY);
}
void Mixer::Stop(int ch)
{
Pause(ch);
}
void Mixer::Reset(void)
{
Music::Reset();
#ifdef WITH_AUDIOCD
if(Cdrom::isValid()) Cdrom::Pause();
#endif
Pause(-1);
}
void Mixer::Reduce(void)
{
if(! valid) return;
std::vector<chunk_t>::iterator it = chunks.begin();
for(; it != chunks.end(); ++it)
{
if((*it).state & MIX_PLAY)
{
SDL_LockAudio();
(*it).state |= MIX_REDUCE;
SDL_UnlockAudio();
}
}
}
void Mixer::Enhance(void)
{
if(! valid) return;
std::vector<chunk_t>::iterator it = chunks.begin();
for(; it != chunks.end(); ++it)
{
if((*it).state & MIX_PLAY)
{
SDL_LockAudio();
(*it).state |= MIX_ENHANCE;
SDL_UnlockAudio();
}
}
}
#endif

View File

@@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2AUDIO_MIXER_H
#define H2AUDIO_MIXER_H
#include <vector>
#include "types.h"
#ifdef WITH_MIXER
#include "SDL_mixer.h"
#endif
namespace Mixer
{
#ifdef WITH_MIXER
typedef Mix_Chunk chunk_t;
void FreeChunk(chunk_t*);
chunk_t* LoadWAV(const char*);
chunk_t* LoadWAV(const u8*, u32);
int Play(chunk_t*, int, bool);
int Play(const char*, int = -1, bool = false);
#endif
int Play(const u8*, u32, int = -1, bool = false);
void SetChannels(u8);
u16 MaxVolume(void);
u16 Volume(int ch, s16 = -1);
void Pause(int ch = -1);
void Resume(int ch = -1);
void Stop(int ch = -1);
void Reset(void);
u8 isPlaying(int);
u8 isPaused(int);
bool isValid(void);
void Reduce(void);
void Enhance(void);
}
#endif

View File

@@ -0,0 +1,213 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include "audio_mixer.h"
#include "audio_music.h"
#ifdef WITH_MIXER
#include "SDL_mixer.h"
namespace Music
{
void Play(bool);
static Mix_Music * music = NULL;
static u16 fadein = 0;
static u16 fadeout = 0;
}
void Music::Play(bool loop)
{
if(fadein)
{
if(music && Mix_FadeInMusic(music, loop ? -1 : 0, fadein) == -1)
std::cerr << "Music::Play: " << Mix_GetError() << std::endl;
}
else
{
if(music && Mix_PlayMusic(music, loop ? -1 : 0) == -1)
std::cerr << "Music::Play: " << Mix_GetError() << std::endl;
}
}
void Music::Play(const u8* ptr, u32 size, bool loop)
{
if(! Mixer::isValid()) return;
if(ptr && size)
{
Reset();
SDL_RWops *rwops = SDL_RWFromConstMem(ptr, size);
music = Mix_LoadMUS_RW(rwops);
SDL_FreeRW(rwops);
Music::Play(loop);
}
}
void Music::Play(const char* file, bool loop)
{
if(! Mixer::isValid()) return;
Reset();
music = Mix_LoadMUS(file);
if(! music)
std::cerr << "Music::Play: " << Mix_GetError() << std::endl;
else
Music::Play(loop);
}
void Music::SetFadeIn(u16 f)
{
fadein = f;
}
void Music::SetFadeOut(u16 f)
{
fadeout = f;
}
u16 Music::Volume(s16 vol)
{
return Mixer::isValid() ? (Mix_VolumeMusic(vol > MIX_MAX_VOLUME ? MIX_MAX_VOLUME : vol)) : 0;
}
void Music::Pause(void)
{
if(! Mixer::isValid() && music) Mix_PauseMusic();
}
void Music::Resume(void)
{
if(Mixer::isValid() && music) Mix_ResumeMusic();
}
void Music::Reset(void)
{
if(Mixer::isValid() && music)
{
if(fadeout)
while(!Mix_FadeOutMusic(fadeout) && Mix_PlayingMusic()) SDL_Delay(50);
else
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}
}
bool Music::isPlaying(void)
{
return Mixer::isValid() && Mix_PlayingMusic();
}
bool Music::isPaused(void)
{
return Mixer::isValid() && Mix_PausedMusic();
}
#else
#include "thread.h"
struct info_t
{
info_t() : loop(false){};
std::string run;
bool loop;
};
namespace Music
{
SDL::Thread music;
info_t info;
}
int callbackPlayMusic(void *ptr)
{
if(ptr && system(NULL))
{
info_t & info = *reinterpret_cast<info_t *>(ptr);
if(info.loop)
{
while(1){ system(info.run.c_str()); DELAY(10); }
}
else
return system(info.run.c_str());
}
return -1;
}
void Music::Play(const u8* ptr, u32 size, bool loop)
{
}
void Music::Play(const char* run, bool loop)
{
if(music.IsRun())
{
if(info.run == run) return;
music.Kill();
}
info.run = run;
info.loop = loop;
music.Create(callbackPlayMusic, &info);
}
void Music::SetFadeIn(u16 f)
{
}
void Music::SetFadeOut(u16 f)
{
}
u16 Music::Volume(s16 vol)
{
return 0;
}
void Music::Pause(void)
{
}
void Music::Resume(void)
{
}
bool Music::isPlaying(void)
{
return music.IsRun();
}
bool Music::isPaused(void)
{
return false;
}
void Music::Reset(void)
{
if(music.IsRun()) music.Kill();
}
#endif

View File

@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2AUDIO_MUSIC_H
#define H2AUDIO_MUSIC_H
#include "types.h"
namespace Music
{
void Play(const u8* ptr, u32 size, bool loop);
void Play(const char* file, bool loop);
u16 Volume(s16 vol);
void SetFadeIn(u16);
void SetFadeOut(u16);
void Pause(void);
void Resume(void);
void Reset(void);
bool isPlaying(void);
bool isPaused(void);
}
#endif

View File

@@ -0,0 +1,106 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "background.h"
#include "display.h"
Background::Background(const Rect &rt) : Surface(), Rect(rt)
{
}
Background::Background(s16 x, s16 y, u16 w, u16 h) : Surface(), Rect(x, y, w, h)
{
}
Background::Background(const Point &pt, u16 w, u16 h) : Surface(), Rect(pt, w, h)
{
}
bool Background::isValid(void) const
{
return Surface::isValid();
}
void Background::Save(void)
{
// resize background
if(Surface::isValid() && (Size::w != Surface::w() || Size::h != Surface::h())) FreeSurface(*this);
if(0 == Rect::w || 0 == Rect::h) return;
if(! Surface::isValid()) Set(Rect::w, Rect::h, false);
Blit(Display::Get(), *this, 0, 0);
SetDisplayFormat();
}
void Background::Save(s16 ax, s16 ay)
{
x = ax;
y = ay;
Save();
}
void Background::Save(s16 ax, s16 ay, u16 aw, u16 ah)
{
x = ax;
y = ay;
Size::w = aw;
Size::h = ah;
Save();
}
void Background::Save(const Point &pt)
{
x = pt.x;
y = pt.y;
Save();
}
void Background::Save(const Rect &rt)
{
Save(rt.x, rt.y, rt.w, rt.h);
}
void Background::Restore(void)
{
if(Surface::isValid())
Display::Get().Blit(*this, x, y);
}
const Rect & Background::GetRect(void) const
{
return *this;
}
const Point & Background::GetPos(void) const
{
return *this;
}
const Size & Background::GetSize(void) const
{
return *this;
}

View File

@@ -0,0 +1,50 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2BACKGROUND_H
#define H2BACKGROUND_H
#include "types.h"
#include "rect.h"
#include "surface.h"
class Background : protected Surface, protected Rect
{
public:
Background(const Rect &rt = Rect());
Background(s16 x, s16 y, u16 w, u16 h);
Background(const Point &pt, u16 w, u16 h);
bool isValid(void) const;
void Save(void);
void Save(s16 ax, s16 ay);
void Save(s16 ax, s16 ay, u16 aw ,u16 ah);
void Save(const Point &pt);
void Save(const Rect &rt);
void Restore(void);
const Rect & GetRect(void) const;
const Point & GetPos(void) const;
const Size & GetSize(void) const;
};
#endif

View File

@@ -0,0 +1,389 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include <algorithm>
#include <string>
#include "rect.h"
#include "types.h"
#include "error.h"
#include "display.h"
UpdateRects::UpdateRects() : bits(NULL), len(0), bf(0), bw(0)
{
}
UpdateRects::~UpdateRects()
{
delete [] bits;
}
void UpdateRects::SetVideoMode(u16 dw, u16 dh)
{
if(dw < 640)
{
bw = 4;
bf = 2;
}
else
if(dw > 640)
{
bw = 16;
bf = 4;
}
else
{
bw = 8;
bf = 3;
}
// fix bw and bf
while(((dw % bw) || (dh % bw)) && 1 < bf)
{
bw >>= 1;
--bf;
}
len = (dw >> bf) * (dh >> bf);
len = (len % 8 ? (len >> 3) + 1 : len >> 3);
if(bits) delete [] bits;
bits = new u8 [len];
std::fill(bits, bits + len, 0);
rects.reserve(len / 4);
}
size_t UpdateRects::Size(void) const
{
return rects.size();
}
void UpdateRects::Clear(void)
{
std::fill(bits, bits + len, 0);
rects.clear();
}
SDL_Rect* UpdateRects::Data(void)
{
return rects.size() ? &rects[0] : NULL;
}
void UpdateRects::PushRect(s16 px, s16 py, u16 pw, u16 ph)
{
Display & display = Display::Get();
if(0 != pw && 0 != ph &&
px + pw > 0 && py + ph > 0 &&
px < display.w() && py < display.h())
{
if(px < 0)
{
pw += px;
px = 0;
}
if(py < 0)
{
ph += py;
py = 0;
}
if(px + pw > display.w())
pw = display.w() - px;
if(py + ph > display.h())
ph = display.h() - py;
const u16 dw = display.w() >> bf;
s16 xx, yy;
for(yy = py; yy < py + ph; yy += bw)
for(xx = px; xx < px + pw; xx += bw)
SetBit((yy >> bf) * dw + (xx >> bf), 1);
yy = py + ph - 1;
for(xx = px; xx < px + pw; xx += bw)
SetBit((yy >> bf) * dw + (xx >> bf), 1);
xx = px + pw - 1;
for(yy = py; yy < py + ph; yy += bw)
SetBit((yy >> bf) * dw + (xx >> bf), 1);
yy = py + ph - 1;
xx = px + pw - 1;
SetBit((yy >> bf) * dw + (xx >> bf), 1);
}
}
bool UpdateRects::BitsToRects(void)
{
Display & display = Display::Get();
const u16 dbf = display.w() >> bf;
const size_t len2 = len << 3;
size_t index;
SDL_Rect rect;
SDL_Rect* prt = NULL;
for(index = 0; index < len2; ++index)
{
if(GetBit(index))
{
if(NULL != prt)
{
if(static_cast<size_t>(rect.y) == (index / dbf) * bw)
rect.w += bw;
else
{
rects.push_back(*prt);
prt = NULL;
}
}
if(NULL == prt)
{
rect.x = (index % dbf) * bw;
rect.y = (index / dbf) * bw;
rect.w = bw;
rect.h = bw;
prt = &rect;
}
}
else
{
if(prt)
{
rects.push_back(*prt);
prt = NULL;
}
}
}
if(prt)
{
rects.push_back(*prt);
prt = NULL;
}
return rects.size();
}
void UpdateRects::SetBit(u32 index, bool value)
{
if(value != GetBit(index))
bits[index >> 3] ^= (1 << (index % 8));
}
bool UpdateRects::GetBit(u32 index) const
{
return (bits[index >> 3] >> (index % 8));
}
Display::Display()
{
}
Display::~Display()
{
}
Display & Display::operator= (const Display & dp)
{
surface = SDL_GetVideoSurface();
return *this;
}
void Display::SetVideoMode(const u16 w, const u16 h, u32 flags)
{
Display & display = Display::Get();
if(display.isValid() && display.w() == w && display.h() == h) return;
if(display.surface && (display.surface->flags & SDL_FULLSCREEN)) flags |= SDL_FULLSCREEN;
display.surface = SDL_SetVideoMode(w, h, 16, flags);
if(!display.surface)
Error::Except("SDL_SetVideoMode: ", SDL_GetError());
display.update_rects.SetVideoMode(display.w(), display.h());
}
/* flip */
void Display::Flip()
{
Display & display = Display::Get();
if(display.surface->flags & SDL_HWSURFACE)
SDL_Flip(display.surface);
else
if(display.update_rects.BitsToRects())
{
SDL_UpdateRects(display.surface, display.update_rects.Size(), display.update_rects.Data());
display.update_rects.Clear();
}
}
/* full screen */
void Display::FullScreen(void)
{
Display & display = Display::Get();
SDL_WM_ToggleFullScreen(display.surface);
}
/* set caption main window */
void Display::SetCaption(const std::string & caption)
{
SDL_WM_SetCaption(caption.c_str(), NULL);
}
/* set icons window */
void Display::SetIcons(const Surface & icons)
{
SDL_WM_SetIcon(const_cast<SDL_Surface *>(icons.GetSurface()), NULL);
}
/* hide system cursor */
void Display::HideCursor(void)
{
SDL_ShowCursor(SDL_DISABLE);
}
/* show system cursor */
void Display::ShowCursor(void)
{
SDL_ShowCursor(SDL_ENABLE);
}
bool Display::Fade(u8 fadeTo)
{
Display & display = Display::Get();
u8 alpha = display.GetAlpha();
if(alpha == fadeTo) return false;
else
if(alpha < fadeTo) return Rise(fadeTo);
if(display.w() != 640 || display.h() != 480) return false;
Surface temp(display);
temp.SetDisplayFormat();
temp.Blit(display);
const u32 black = temp.MapRGB(0, 0, 0);
while(alpha > fadeTo)
{
alpha -= alpha - 10 > fadeTo ? 10 : alpha - fadeTo;
display.Fill(black);
temp.SetAlpha(alpha);
display.Blit(temp);
display.Flip();
DELAY(10);
}
return true;
}
bool Display::Rise(u8 riseTo)
{
Display & display = Display::Get();
u8 alpha = display.GetAlpha();
if(alpha == riseTo) return false;
else
if(riseTo < alpha) return Fade(riseTo);
if(display.w() != 640 || display.h() != 480) return false;
Surface temp(display);
temp.SetDisplayFormat();
temp.Blit(display);
const u32 black = temp.MapRGB(0, 0, 0);
while(alpha < riseTo)
{
alpha += alpha + 10 < riseTo ? 10 : riseTo - alpha;
display.Fill(black);
temp.SetAlpha(alpha);
display.Blit(temp);
display.Flip();
DELAY(10);
}
return true;
}
/* get video display */
Display & Display::Get(void)
{
static Display inside;
return inside;
}
int Display::GetMaxMode(Size & result, bool rotate)
{
SDL_Rect** modes = SDL_ListModes(NULL, SDL_ANYFORMAT);
if(modes == (SDL_Rect **) 0)
{
std::cerr << "Display::GetMaxMode: " << "no modes available" << std::endl;
return 0;
}
else
if(modes == (SDL_Rect **) -1)
{
//std::cout << "Display::GetMaxMode: " << "all modes available" << std::endl;
return -1;
}
else
{
int max = 0;
int cur = 0;
for(int ii = 0; modes[ii]; ++ii)
{
if(max < modes[ii]->w * modes[ii]->h)
{
max = modes[ii]->w * modes[ii]->h;
cur = ii;
}
}
result.w = modes[cur]->w;
result.h = modes[cur]->h;
if(rotate && result.w < result.h)
{
cur = result.w;
result.w = result.h;
result.h = cur;
}
}
return 1;
}
void Display::AddUpdateRect(s16 px, s16 py, u16 pw, u16 ph)
{
if(0 == (surface->flags & SDL_HWSURFACE))
update_rects.PushRect(px, py, pw, ph);
}

View File

@@ -0,0 +1,84 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2DISPLAY_H
#define H2DISPLAY_H
#include <string>
#include "surface.h"
#include "rect.h"
class UpdateRects
{
public:
UpdateRects();
~UpdateRects();
void SetVideoMode(u16, u16);
void PushRect(s16, s16, u16, u16);
void Clear(void);
size_t Size(void) const;
SDL_Rect* Data(void);
bool BitsToRects(void);
protected:
void SetBit(u32, bool);
bool GetBit(u32) const;
std::vector<SDL_Rect> rects;
u8* bits;
u32 len;
u8 bf;
u8 bw;
};
class Display : public Surface
{
public:
~Display();
static Display & Get(void);
static void SetVideoMode(const u16 w, const u16 h, u32 flags);
static int GetMaxMode(Size &, bool enable_rotate);
static void HideCursor(void);
static void ShowCursor(void);
static void SetCaption(const std::string & caption);
static void SetIcons(const Surface & icons);
void AddUpdateRect(s16, s16, u16, u16);
static void Flip();
static void FullScreen(void);
static bool Fade(u8 fadeTo=0);
static bool Rise(u8 riseTo=255);
Display & operator= (const Display & dp);
private:
Display();
UpdateRects update_rects;
};
#endif

View File

@@ -0,0 +1,165 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "error.h"
#include "engine.h"
#include "font.h"
#include "sdlnet.h"
namespace Mixer
{
void Init(void);
void Quit(void);
}
#ifdef WITH_AUDIOCD
namespace Cdrom
{
void Open(void);
void Close(void);
}
#endif
#ifdef _WIN32_WCE
namespace WINCE
{
bool isRunning(void);
int CreateTrayIcon(void);
void DeleteTrayIcon(void);
}
#endif
bool SDL::Init(const u32 system)
{
#ifdef _WIN32_WCE
SDL_putenv("DEBUG_VIDEO=1");
SDL_putenv("DEBUG_VIDEO_GAPI=1");
if(WINCE::isRunning()) return false;
#endif
if(0 > SDL_Init(system))
{
std::cerr << "SDL::Init: error: " << SDL_GetError() << std::endl;
return false;
}
if(SDL_INIT_AUDIO & system) Mixer::Init();
#ifdef WITH_AUDIOCD
if(SDL_INIT_CDROM & system) Cdrom::Open();
#endif
#ifdef WITH_TTF
SDL::Font::Init();
#endif
#ifdef WITH_NET
Network::Init();
#endif
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#ifdef _WIN32_WCE
WINCE::CreateTrayIcon();
#endif
return true;
}
void SDL::Quit(void)
{
#ifdef _WIN32_WCE
WINCE::DeleteTrayIcon();
#endif
#ifdef WITH_NET
Network::Quit();
#endif
#ifdef WITH_TTF
SDL::Font::Quit();
#endif
#ifdef WITH_AUDIOCD
if(SubSystem(SDL_INIT_CDROM)) Cdrom::Close();
#endif
if(SubSystem(SDL_INIT_AUDIO)) Mixer::Quit();
SDL_Quit();
}
bool SDL::SubSystem(const u32 system)
{
return system & SDL_WasInit(system);
}
#ifdef _WIN32_WCE
#include <windows.h>
#include <shellapi.h>
#ifdef __MINGW32CE__
#undef Shell_NotifyIcon
extern "C" {
BOOL WINAPI Shell_NotifyIcon(DWORD, PNOTIFYICONDATAW);
};
#endif
// wincommon/SDL_sysevents.c
extern HICON screen_icn;
extern HINSTANCE SDL_Instance;
extern HWND SDL_Window;
bool WINCE::isRunning(void)
{
HWND hwnd = FindWindow(NULL, L"SDL_app");
if(hwnd)
{
ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
}
return hwnd;
}
int WINCE::CreateTrayIcon(void)
{
#ifdef ID_ICON
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.uID = ID_ICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE;
nid.hWnd = SDL_Window;
nid.uCallbackMessage = WM_USER;
nid.hIcon = ::LoadIcon(SDL_Instance, MAKEINTRESOURCE(ID_ICON));
return Shell_NotifyIcon(NIM_ADD, &nid);
#endif
return 0;
}
void WINCE::DeleteTrayIcon(void)
{
#ifdef ID_ICON
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.uID = ID_ICON;
nid.hWnd = SDL_Window;
Shell_NotifyIcon(NIM_DELETE, &nid);
#endif
}
#endif

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2ENGINE_H
#define H2ENGINE_H
#include "background.h"
#include "display.h"
#include "localevent.h"
#include "error.h"
#include "rect.h"
#include "spritecursor.h"
#include "surface.h"
#include "palette.h"
#include "rand.h"
#include "tools.h"
#include "audio.h"
#include "audio_mixer.h"
#include "audio_music.h"
#include "audio_cdrom.h"
#include "types.h"
#define INIT_VIDEO SDL_INIT_VIDEO
#define INIT_AUDIO SDL_INIT_AUDIO
#define INIT_TIMER SDL_INIT_TIMER
#define INIT_CDROM SDL_INIT_CDROM
namespace SDL
{
bool Init(const u32 system = INIT_VIDEO);
void Quit(void);
bool SubSystem(const u32 system);
}
#endif

View File

@@ -0,0 +1,32 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <stdexcept>
#include <iostream>
#include "error.h"
/* exception */
void Error::Except(const char* message, const char* cstr)
{
std::cerr << "Error::Except: " << message << cstr << std::endl;
throw Exception();
}

View File

@@ -0,0 +1,38 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2ERROR_H
#define H2ERROR_H
#include <string>
class Error
{
public:
Error(){};
~Error(){};
class Exception{};
static void Except(const char*, const char*);
};
#endif

View File

@@ -0,0 +1,143 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef WITH_TTF
#include <iostream>
#include "font.h"
#include "engine.h"
#include "surface.h"
#include "SDL_ttf.h"
bool SDL::Font::init = false;
SDL::Font::Font() : fnt(NULL)
{
}
SDL::Font::~Font()
{
if(fnt) TTF_CloseFont(fnt);
}
void SDL::Font::Init(void)
{
if(0 != TTF_Init()) std::cerr << "Font::Init: error" << std::endl;
else init = true;
}
void SDL::Font::Quit(void)
{
TTF_Quit();
init = false;
}
bool SDL::Font::isValid(void) const
{
return fnt;
}
bool SDL::Font::Open(const std::string & filename, u8 size)
{
if(init)
{
if(fnt) TTF_CloseFont(fnt);
fnt = TTF_OpenFont(filename.c_str(), size);
if(!fnt) std::cerr << "Font::Open: error open: " << filename << std::endl;
}
return fnt;
}
void SDL::Font::SetStyle(u8 style)
{
if(fnt) TTF_SetFontStyle(fnt, style);
}
void SDL::Font::RenderText(Surface & dst, const std::string & msg, const Colors & clr, render_t render)
{
if(dst.surface) Surface::FreeSurface(dst);
if(fnt) switch(render)
{
case BLENDED: dst.surface = TTF_RenderUTF8_Blended(fnt, msg.c_str(), clr); break;
default: dst.surface = TTF_RenderUTF8_Solid(fnt, msg.c_str(), clr); break;
}
}
void SDL::Font::RenderChar(Surface & dst, char ch, const Colors & clr, render_t render)
{
char buf[2] = { '\0', '\0' };
buf[0] = ch;
if(dst.surface) Surface::FreeSurface(dst);
if(fnt) switch(render)
{
case BLENDED: dst.surface = TTF_RenderUTF8_Blended(fnt, buf, clr); break;
default: dst.surface = TTF_RenderUTF8_Solid(fnt, buf, clr); break;
}
}
void SDL::Font::RenderUnicodeText(Surface & dst, const u16 *msg, const Colors & clr, render_t render)
{
if(dst.surface) Surface::FreeSurface(dst);
if(fnt) switch(render)
{
case BLENDED: dst.surface = TTF_RenderUNICODE_Blended(fnt, msg, clr); break;
default: dst.surface = TTF_RenderUNICODE_Solid(fnt, msg, clr); break;
}
}
void SDL::Font::RenderUnicodeChar(Surface & dst, u16 ch, const Colors & clr, render_t render)
{
u16 buf[2] = { L'\0', L'\0' };
buf[0] = ch;
if(dst.surface) Surface::FreeSurface(dst);
if(fnt) switch(render)
{
case BLENDED: dst.surface = TTF_RenderUNICODE_Blended(fnt, buf, clr); break;
default: dst.surface = TTF_RenderUNICODE_Solid(fnt, buf, clr); break;
}
}
int SDL::Font::Height(void) const
{
return fnt ? TTF_FontHeight(fnt) : 0;
}
int SDL::Font::Ascent(void) const
{
return fnt ? TTF_FontAscent(fnt) : 0;
}
int SDL::Font::Descent(void) const
{
return fnt ? TTF_FontDescent(fnt) : 0;
}
int SDL::Font::LineSkip(void) const
{
return fnt ? TTF_FontLineSkip(fnt) : 0;
}
#endif

View File

@@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2FONT_H
#define H2FONT_H
#ifdef WITH_TTF
#include <string>
#include "types.h"
#include "SDL_ttf.h"
class Surface;
namespace SDL
{
class Font
{
public:
enum render_t { SOLID, BLENDED };
Font();
~Font();
static void Init(void);
static void Quit(void);
bool Open(const std::string &, u8);
bool isValid(void) const;
void SetStyle(u8);
int Height(void) const;
int Ascent(void) const;
int Descent(void) const;
int LineSkip(void) const;
void RenderText(Surface &, const std::string &, const Colors &, render_t = SOLID);
void RenderChar(Surface &, char, const Colors &, render_t = SOLID);
void RenderUnicodeText(Surface &, const u16 *, const Colors &, render_t = SOLID);
void RenderUnicodeChar(Surface &, u16, const Colors &, render_t = SOLID);
private:
TTF_Font *fnt;
static bool init;
};
}
#endif
#endif

View File

@@ -0,0 +1,883 @@
/***************************************************************************
* Copyright (C) 2008 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "error.h"
#include "display.h"
#include "audio_music.h"
#include "audio_mixer.h"
#include "localevent.h"
#define TAP_DELAY_EMULATE 1050
LocalEvent::LocalEvent() : modes(0), key_value(KEY_NONE), mouse_state(0),
mouse_button(0), mouse_st(0, 0), redraw_cursor_func(NULL), keyboard_filter_func(NULL),
clock_delay(TAP_DELAY_EMULATE), loop_delay(1)
{
#ifdef WITHOUT_MOUSE
emulate_mouse = false;
emulate_mouse_up = KEY_UP;
emulate_mouse_down = KEY_DOWN;
emulate_mouse_left = KEY_LEFT;
emulate_mouse_right = KEY_RIGHT;
emulate_mouse_step = 10;
emulate_press_left = KEY_NONE;
emulate_press_right = KEY_NONE;
#endif
}
const Point & LocalEvent::GetMousePressLeft(void) const
{
return mouse_pl;
}
const Point & LocalEvent::GetMousePressMiddle(void) const
{
return mouse_pm;
}
const Point & LocalEvent::GetMousePressRight(void) const
{
return mouse_pr;
}
const Point & LocalEvent::GetMouseReleaseLeft(void) const
{
return mouse_rl;
}
const Point & LocalEvent::GetMouseReleaseMiddle(void) const
{
return mouse_rm;
}
const Point & LocalEvent::GetMouseReleaseRight(void) const
{
return mouse_rr;
}
void LocalEvent::SetTapMode(bool f)
{
if(f)
SetModes(TAP_MODE);
else
{
ResetModes(TAP_MODE);
ResetModes(CLOCK_ON);
clock.Stop();
}
}
void LocalEvent::SetTapDelayForRightClickEmulation(u32 d)
{
clock_delay = d < 200 ? TAP_DELAY_EMULATE : d;
}
void LocalEvent::SetMouseOffsetX(s16 x)
{
SetModes(MOUSE_OFFSET);
mouse_st.x = x;
}
void LocalEvent::SetMouseOffsetY(s16 y)
{
SetModes(MOUSE_OFFSET);
mouse_st.y = y;
}
void LocalEvent::SetModes(flag_t f)
{
modes |= f;
}
void LocalEvent::ResetModes(flag_t f)
{
modes &= ~f;
}
void LocalEvent::SetGlobalFilter(bool f)
{
f ? SetModes(GLOBAL_FILTER) : ResetModes(GLOBAL_FILTER);
}
const char* KeySymGetName(KeySym sym)
{
return SDL_GetKeyName(static_cast<SDLKey>(sym));
}
KeySym GetKeySym(int key)
{
switch(key)
{
default: break;
case SDLK_RETURN: return KEY_RETURN;
case SDLK_LEFT: return KEY_LEFT;
case SDLK_RIGHT: return KEY_RIGHT;
case SDLK_UP: return KEY_UP;
case SDLK_DOWN: return KEY_DOWN;
case SDLK_ESCAPE: return KEY_ESCAPE;
case SDLK_KP_ENTER: return KEY_RETURN;
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_EXCLAIM: return KEY_EXCLAIM;
case SDLK_QUOTEDBL: return KEY_QUOTEDBL;
case SDLK_HASH: return KEY_HASH;
case SDLK_DOLLAR: return KEY_DOLLAR;
case SDLK_AMPERSAND: return KEY_AMPERSAND;
case SDLK_QUOTE: return KEY_QUOTE;
case SDLK_LEFTPAREN: return KEY_LEFTPAREN;
case SDLK_RIGHTPAREN: return KEY_RIGHTPAREN;
case SDLK_ASTERISK: return KEY_ASTERISK;
case SDLK_PLUS: return KEY_PLUS;
case SDLK_COMMA: return KEY_COMMA;
case SDLK_MINUS: return KEY_MINUS;
case SDLK_PERIOD: return KEY_PERIOD;
case SDLK_SLASH: return KEY_SLASH;
case SDLK_COLON: return KEY_COLON;
case SDLK_SEMICOLON: return KEY_SEMICOLON;
case SDLK_LESS: return KEY_LESS;
case SDLK_EQUALS: return KEY_EQUALS;
case SDLK_GREATER: return KEY_GREATER;
case SDLK_QUESTION: return KEY_QUESTION;
case SDLK_AT: return KEY_AT;
case SDLK_LEFTBRACKET: return KEY_LEFTBRACKET;
case SDLK_BACKSLASH: return KEY_BACKSLASH;
case SDLK_RIGHTBRACKET: return KEY_RIGHTBRACKET;
case SDLK_CARET: return KEY_CARET;
case SDLK_UNDERSCORE: return KEY_UNDERSCORE;
case SDLK_LALT: return KEY_ALT;
case SDLK_RALT: return KEY_ALT;
case SDLK_LCTRL: return KEY_CONTROL;
case SDLK_RCTRL: return KEY_CONTROL;
case SDLK_LSHIFT: return KEY_SHIFT;
case SDLK_RSHIFT: return KEY_SHIFT;
case SDLK_TAB: return KEY_TAB;
case SDLK_SPACE: return KEY_SPACE;
case SDLK_DELETE: return KEY_DELETE;
case SDLK_PAGEUP: return KEY_PAGEUP;
case SDLK_PAGEDOWN: return KEY_PAGEDOWN;
case SDLK_F1: return KEY_F1;
case SDLK_F2: return KEY_F2;
case SDLK_F3: return KEY_F3;
case SDLK_F4: return KEY_F4;
case SDLK_F5: return KEY_F5;
case SDLK_F6: return KEY_F6;
case SDLK_F7: return KEY_F7;
case SDLK_F8: return KEY_F8;
case SDLK_F9: return KEY_F9;
case SDLK_F10: return KEY_F10;
case SDLK_F11: return KEY_F11;
case SDLK_F12: return KEY_F12;
case SDLK_PRINT: return KEY_PRINT;
case SDLK_0: return KEY_0;
case SDLK_1: return KEY_1;
case SDLK_2: return KEY_2;
case SDLK_3: return KEY_3;
case SDLK_4: return KEY_4;
case SDLK_5: return KEY_5;
case SDLK_6: return KEY_6;
case SDLK_7: return KEY_7;
case SDLK_8: return KEY_8;
case SDLK_9: return KEY_9;
case SDLK_a: return KEY_a;
case SDLK_b: return KEY_b;
case SDLK_c: return KEY_c;
case SDLK_d: return KEY_d;
case SDLK_e: return KEY_e;
case SDLK_f: return KEY_f;
case SDLK_g: return KEY_g;
case SDLK_h: return KEY_h;
case SDLK_i: return KEY_i;
case SDLK_j: return KEY_j;
case SDLK_k: return KEY_k;
case SDLK_l: return KEY_l;
case SDLK_m: return KEY_m;
case SDLK_n: return KEY_n;
case SDLK_o: return KEY_o;
case SDLK_p: return KEY_p;
case SDLK_q: return KEY_q;
case SDLK_r: return KEY_r;
case SDLK_s: return KEY_s;
case SDLK_t: return KEY_t;
case SDLK_u: return KEY_u;
case SDLK_v: return KEY_v;
case SDLK_w: return KEY_w;
case SDLK_x: return KEY_x;
case SDLK_y: return KEY_y;
case SDLK_z: return KEY_z;
#ifdef _WIN32_WCE
case 0xC1: return KEY_APP01;
case 0xC2: return KEY_APP02;
case 0xC3: return KEY_APP03;
case 0xC4: return KEY_APP04;
case 0xC5: return KEY_APP05;
case 0xC6: return KEY_APP06;
case 0xC7: return KEY_APP07;
case 0xC8: return KEY_APP08;
case 0xC9: return KEY_APP09;
case 0xCA: return KEY_APP10;
case 0xCB: return KEY_APP11;
case 0xCC: return KEY_APP12;
case 0xCD: return KEY_APP13;
case 0xCE: return KEY_APP14;
case 0xCF: return KEY_APP15;
#endif
}
return KEY_NONE;
}
LocalEvent & LocalEvent::Get(void)
{
static LocalEvent le;
return le;
}
bool LocalEvent::HandleEvents(bool delay)
{
SDL_Event event;
ResetModes(MOUSE_MOTION);
ResetModes(KEY_PRESSED);
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_ACTIVEEVENT:
if(event.active.state & SDL_APPACTIVE)
{
if(Mixer::isValid())
{
//iconify
if(0 == event.active.gain)
{
Mixer::Reset();
Music::Pause();
loop_delay = 100;
}
else
loop_delay = 1;
}
}
break;
// keyboard
case SDL_KEYDOWN:
case SDL_KEYUP:
HandleKeyboardEvent(event.key);
break;
// mouse motion
case SDL_MOUSEMOTION:
HandleMouseMotionEvent(event.motion);
break;
// mouse button
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
HandleMouseButtonEvent(event.button);
break;
// exit
case SDL_QUIT:
Error::Except("LocalEvent::HandleEvents: ", "quit event: ok.");
return false;
default:
break;
}
// need for wheel up/down delay
if(SDL_BUTTON_WHEELDOWN == event.button.button || SDL_BUTTON_WHEELUP == event.button.button) break;
}
// emulate press right
if((modes & TAP_MODE) && (modes & CLOCK_ON))
{
clock.Stop();
if(clock_delay < clock.Get())
{
ResetModes(CLICK_LEFT);
ResetModes(CLOCK_ON);
mouse_pr = mouse_cu;
SetModes(MOUSE_PRESSED);
mouse_button = SDL_BUTTON_RIGHT;
}
}
if(delay) SDL_Delay(loop_delay);
return true;
}
bool LocalEvent::MouseMotion(void) const
{
return modes & MOUSE_MOTION;
}
bool LocalEvent::MouseMotion(const Rect &rt) const
{
return modes & MOUSE_MOTION ? rt & mouse_cu : false;
}
bool LocalEvent::MousePressLeft(void) const
{
return (modes & MOUSE_PRESSED) && SDL_BUTTON_LEFT == mouse_button;
}
bool LocalEvent::MouseReleaseLeft(void) const
{
return !(modes & MOUSE_PRESSED) && SDL_BUTTON_LEFT == mouse_button;
}
bool LocalEvent::MousePressMiddle(void) const
{
return (modes & MOUSE_PRESSED) && SDL_BUTTON_MIDDLE == mouse_button;
}
bool LocalEvent::MouseReleaseMiddle(void) const
{
return !(modes & MOUSE_PRESSED) && SDL_BUTTON_MIDDLE == mouse_button;
}
bool LocalEvent::MousePressRight(void) const
{
return (modes & MOUSE_PRESSED) && SDL_BUTTON_RIGHT == mouse_button;
}
bool LocalEvent::MouseReleaseRight(void) const
{
return !(modes & MOUSE_PRESSED) && SDL_BUTTON_RIGHT == mouse_button;
}
void LocalEvent::HandleKeyboardEvent(SDL_KeyboardEvent & event)
{
if(KEY_NONE != GetKeySym(event.keysym.sym))
{
(event.type == SDL_KEYDOWN) ? SetModes(KEY_PRESSED) : ResetModes(KEY_PRESSED);
#ifdef WITHOUT_MOUSE
if(emulate_mouse && EmulateMouseAction(GetKeySym(event.keysym.sym))) return;
#endif
key_value = GetKeySym(event.keysym.sym);
}
}
void LocalEvent::HandleMouseMotionEvent(const SDL_MouseMotionEvent & motion)
{
mouse_state = motion.state;
SetModes(MOUSE_MOTION);
mouse_cu.x = motion.x;
mouse_cu.y = motion.y;
if(modes & MOUSE_OFFSET) mouse_cu += mouse_st;
}
void LocalEvent::HandleMouseButtonEvent(const SDL_MouseButtonEvent & button)
{
button.state == SDL_PRESSED ? SetModes(MOUSE_PRESSED) : ResetModes(MOUSE_PRESSED);
mouse_button = button.button;
mouse_cu.x = button.x;
mouse_cu.y = button.y;
if(modes & MOUSE_OFFSET) mouse_cu += mouse_st;
if(modes & MOUSE_PRESSED)
switch(button.button)
{
case SDL_BUTTON_WHEELDOWN:
case SDL_BUTTON_WHEELUP:
mouse_pm = mouse_cu;
break;
case SDL_BUTTON_LEFT:
mouse_pl = mouse_cu;
SetModes(CLICK_LEFT);
// emulate press right
if(modes & TAP_MODE){ clock.Start(); SetModes(CLOCK_ON); }
break;
case SDL_BUTTON_MIDDLE:
mouse_pm = mouse_cu;
SetModes(CLICK_MIDDLE);
break;
case SDL_BUTTON_RIGHT:
mouse_pr = mouse_cu;
SetModes(CLICK_RIGHT);
break;
default:
break;
}
else
switch(button.button)
{
case SDL_BUTTON_WHEELDOWN:
case SDL_BUTTON_WHEELUP:
mouse_rm = mouse_cu;
break;
case SDL_BUTTON_LEFT:
mouse_rl = mouse_cu;
// emulate press right
if(modes & TAP_MODE){ ResetModes(CLOCK_ON); }
break;
case SDL_BUTTON_MIDDLE:
mouse_rm = mouse_cu;
break;
case SDL_BUTTON_RIGHT:
mouse_rr = mouse_cu;
break;
default:
break;
}
}
bool LocalEvent::MouseClickLeft(void)
{
if(MouseReleaseLeft() && (CLICK_LEFT & modes))
{
ResetModes(CLICK_LEFT);
return true;
}
return false;
}
bool LocalEvent::MouseClickLeft(const Rect &rt)
{
//if(MouseReleaseLeft() && (rt & mouse_rl) && (CLICK_LEFT & modes) && ((modes & TAP_MODE) || (rt & mouse_pl)))
if(MouseReleaseLeft() && (rt & mouse_pl) && (rt & mouse_rl) && (CLICK_LEFT & modes))
{
ResetModes(CLICK_LEFT);
return true;
}
return false;
}
bool LocalEvent::MouseClickMiddle(void)
{
if(MouseReleaseMiddle() && (CLICK_MIDDLE & modes))
{
ResetModes(CLICK_MIDDLE);
return true;
}
return false;
}
bool LocalEvent::MouseClickMiddle(const Rect &rt)
{
if(MouseReleaseMiddle() && (rt & mouse_pm) && (rt & mouse_rm) && (CLICK_MIDDLE & modes))
{
ResetModes(CLICK_MIDDLE);
return true;
}
return false;
}
bool LocalEvent::MouseClickRight(void)
{
if(MouseReleaseRight() && (CLICK_RIGHT & modes))
{
ResetModes(CLICK_RIGHT);
return true;
}
return false;
}
bool LocalEvent::MouseClickRight(const Rect &rt)
{
if(MouseReleaseRight() && (rt & mouse_pr) && (rt & mouse_rr) && (CLICK_RIGHT & modes))
{
ResetModes(CLICK_RIGHT);
return true;
}
return false;
}
bool LocalEvent::MouseWheelUp(void) const
{
return (modes & MOUSE_PRESSED) && SDL_BUTTON_WHEELUP == mouse_button;
}
bool LocalEvent::MouseWheelDn(void) const
{
return (modes & MOUSE_PRESSED) && SDL_BUTTON_WHEELDOWN == mouse_button;
}
bool LocalEvent::MousePressLeft(const Rect &rt) const
{
return MousePressLeft() && (rt & mouse_pl);
}
bool LocalEvent::MousePressLeft(const Point &pt, u16 w, u16 h) const
{
return MousePressLeft() && (Rect(pt.x, pt.y, w, h) & mouse_pl);
}
bool LocalEvent::MousePressMiddle(const Rect &rt) const
{
return MousePressMiddle() && (rt & mouse_pm);
}
bool LocalEvent::MousePressRight(const Rect &rt) const
{
return MousePressRight() && (rt & mouse_pr);
}
bool LocalEvent::MouseReleaseLeft(const Rect &rt) const
{
return MouseReleaseLeft() && (rt & mouse_rl);
}
bool LocalEvent::MouseReleaseMiddle(const Rect &rt) const
{
return MouseReleaseMiddle() && (rt & mouse_rm);
}
bool LocalEvent::MouseReleaseRight(const Rect &rt) const
{
return MouseReleaseRight() && (rt & mouse_rr);
}
void LocalEvent::ResetPressLeft(void)
{
mouse_pl.x = -1;
mouse_pl.y = -1;
}
void LocalEvent::ResetPressRight(void)
{
mouse_pr.x = -1;
mouse_pr.y = -1;
}
void LocalEvent::ResetPressMiddle(void)
{
mouse_pm.x = -1;
mouse_pm.y = -1;
}
void LocalEvent::ResetReleaseLeft(void)
{
mouse_rl.x = -1;
mouse_rl.y = -1;
}
void LocalEvent::ResetReleaseRight(void)
{
mouse_rr.x = -1;
mouse_rr.y = -1;
}
void LocalEvent::ResetReleaseMiddle(void)
{
mouse_rm.x = -1;
mouse_rm.y = -1;
}
bool LocalEvent::MouseWheelUp(const Rect &rt) const
{
return MouseWheelUp() && (rt & mouse_cu);
}
bool LocalEvent::MouseWheelDn(const Rect &rt) const
{
return MouseWheelDn() && (rt & mouse_cu);
}
bool LocalEvent::MouseCursor(const Rect &rt) const
{
return rt & mouse_cu;
}
const Point & LocalEvent::GetMouseCursor(void)
{
#ifdef WITHOUT_MOUSE
if(!emulate_mouse)
#endif
{
int x, y;
SDL_PumpEvents();
SDL_GetMouseState(&x, &y);
mouse_cu.x = x;
mouse_cu.y = y;
}
if(modes & MOUSE_OFFSET) mouse_cu += mouse_st;
return mouse_cu;
}
u16 LocalEvent::KeyMod(void) const
{
return SDL_GetModState();
}
KeySym LocalEvent::KeyValue(void) const
{
return key_value;
}
bool LocalEvent::KeyPress(void) const
{
return modes & KEY_PRESSED;
}
bool LocalEvent::KeyPress(KeySym key) const
{
return key == key_value && (modes & KEY_PRESSED);
}
void LocalEvent::SetGlobalFilterMouseEvents(void (*pf)(u16, u16))
{
redraw_cursor_func = pf;
}
void LocalEvent::SetGlobalFilterKeysEvents(void (*pf)(int, u16))
{
keyboard_filter_func = pf;
}
#if SDL_VERSION_ATLEAST(1, 3, 0)
int LocalEvent::GlobalFilterEvents(void *userdata, SDL_Event *event)
#else
int LocalEvent::GlobalFilterEvents(const SDL_Event *event)
#endif
{
LocalEvent & le = LocalEvent::Get();
// motion
if((le.modes & GLOBAL_FILTER) && SDL_MOUSEMOTION == event->type)
{
// redraw cursor
if(le.redraw_cursor_func)
{
if(le.modes & MOUSE_OFFSET)
(*(le.redraw_cursor_func))(event->motion.x + le.mouse_st.x, event->motion.y + le.mouse_st.y);
else
(*(le.redraw_cursor_func))(event->motion.x, event->motion.y);
}
}
// key
if((le.modes & GLOBAL_FILTER) && SDL_KEYDOWN == event->type)
{
// key event
if(le.keyboard_filter_func)
(*(le.keyboard_filter_func))(event->key.keysym.sym, event->key.keysym.mod);
}
return 1;
}
void LocalEvent::SetState(u32 type, bool enable)
{
SDL_EventState(type, enable ? SDL_ENABLE : SDL_IGNORE);
}
u8 LocalEvent::GetState(u32 type)
{
return SDL_EventState(type, SDL_QUERY);
}
void LocalEvent::SetStateDefaults(void)
{
// enable events
SetState(SDL_ACTIVEEVENT, true);
SetState(SDL_USEREVENT, true);
SetState(SDL_KEYDOWN, true);
SetState(SDL_KEYUP, true);
SetState(SDL_MOUSEMOTION, true);
SetState(SDL_MOUSEBUTTONDOWN, true);
SetState(SDL_MOUSEBUTTONUP, true);
SetState(SDL_QUIT, true);
// ignore events
SetState(SDL_JOYAXISMOTION, false);
SetState(SDL_JOYBALLMOTION, false);
SetState(SDL_JOYHATMOTION, false);
SetState(SDL_JOYBUTTONUP, false);
SetState(SDL_JOYBUTTONDOWN, false);
SetState(SDL_SYSWMEVENT, false);
SetState(SDL_VIDEORESIZE, false);
SetState(SDL_VIDEOEXPOSE, false);
#if SDL_VERSION_ATLEAST(1, 3, 0)
SDL_SetEventFilter(GlobalFilterEvents, NULL);
#else
SDL_SetEventFilter(GlobalFilterEvents);
#endif
}
#ifdef WITHOUT_MOUSE
void LocalEvent::ToggleEmulateMouse(void)
{
emulate_mouse = emulate_mouse ? false : true;
}
void LocalEvent::SetEmulateMouse(bool f)
{
emulate_mouse = f;
if(f) mouse_cu = Point(0, 0);
}
void LocalEvent::SetEmulateMouseUpKey(KeySym k)
{
emulate_mouse_up = k;
}
void LocalEvent::SetEmulateMouseDownKey(KeySym k)
{
emulate_mouse_down = k;
}
void LocalEvent::SetEmulateMouseLeftKey(KeySym k)
{
emulate_mouse_left = k;
}
void LocalEvent::SetEmulateMouseRightKey(KeySym k)
{
emulate_mouse_right = k;
}
void LocalEvent::SetEmulateMouseStep(u8 s)
{
emulate_mouse_step = s;
}
void LocalEvent::SetEmulatePressLeftKey(KeySym k)
{
emulate_press_left = k;
}
void LocalEvent::SetEmulatePressRightKey(KeySym k)
{
emulate_press_right = k;
}
bool LocalEvent::EmulateMouseAction(KeySym key)
{
if((key == emulate_mouse_up ||
key == emulate_mouse_down ||
key == emulate_mouse_left ||
key == emulate_mouse_right ||
key == emulate_press_left ||
key == emulate_press_right))
{
if(emulate_mouse_up == key)
{
mouse_cu.y -= emulate_mouse_step;
SetModes(MOUSE_MOTION);
}
else
if(emulate_mouse_down == key)
{
mouse_cu.y += emulate_mouse_step;
SetModes(MOUSE_MOTION);
}
else
if(emulate_mouse_left == key)
{
mouse_cu.x -= emulate_mouse_step;
SetModes(MOUSE_MOTION);
}
else
if(emulate_mouse_right == key)
{
mouse_cu.x += emulate_mouse_step;
SetModes(MOUSE_MOTION);
}
if(mouse_cu.x < 0) mouse_cu.x = 0;
if(mouse_cu.y < 0) mouse_cu.y = 0;
if(mouse_cu.x > Display::Get().w()) mouse_cu.x = Display::Get().w();
if(mouse_cu.y > Display::Get().h()) mouse_cu.y = Display::Get().h();
if(emulate_press_left == key)
{
if(modes & KEY_PRESSED)
{
mouse_pl = mouse_cu;
SetModes(MOUSE_PRESSED);
SetModes(CLICK_LEFT);
}
else
{
mouse_rl = mouse_cu;
ResetModes(MOUSE_PRESSED);
}
mouse_button = SDL_BUTTON_LEFT;
}
else
if(emulate_press_right == key)
{
if(modes & KEY_PRESSED)
{
mouse_pr = mouse_cu;
SetModes(MOUSE_PRESSED);
}
else
{
mouse_rr = mouse_cu;
ResetModes(MOUSE_PRESSED);
}
mouse_button = SDL_BUTTON_RIGHT;
}
if((modes & MOUSE_MOTION) && redraw_cursor_func)
{
if(modes & MOUSE_OFFSET)
(*(redraw_cursor_func))(mouse_cu.x + mouse_st.x, mouse_cu.y + mouse_st.y);
else
(*(redraw_cursor_func))(mouse_cu.x, mouse_cu.y);
}
ResetModes(KEY_PRESSED);
return true;
}
return false;
}
#endif

View File

@@ -0,0 +1,306 @@
/***************************************************************************
* Copyright (C) 2006 by Andrey Afletdinov <fheroes2@gmail.com> *
* Copyright (C) 2008 by Josh Matthews <josh@joshmatthews.net> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2LOCALEVENT_H
#define H2LOCALEVENT_H
#include "rect.h"
#include "thread.h"
#include "types.h"
enum KeyMod { MOD_NONE = KMOD_NONE, MOD_CTRL = KMOD_CTRL, MOD_SHIFT = KMOD_SHIFT, MOD_ALT = KMOD_ALT, MOD_CAPS = KMOD_CAPS };
enum KeySym
{
KEY_NONE = -1,
KEY_UNKNOWN = SDLK_UNKNOWN,
KEY_BACKSPACE = SDLK_BACKSPACE,
KEY_RETURN = SDLK_RETURN,
KEY_ESCAPE = SDLK_ESCAPE,
KEY_SPACE = SDLK_SPACE,
KEY_EXCLAIM = SDLK_EXCLAIM,
KEY_QUOTEDBL = SDLK_QUOTEDBL,
KEY_HASH = SDLK_HASH,
KEY_DOLLAR = SDLK_DOLLAR,
KEY_AMPERSAND = SDLK_AMPERSAND,
KEY_QUOTE = SDLK_QUOTE,
KEY_LEFTPAREN = SDLK_LEFTPAREN,
KEY_RIGHTPAREN = SDLK_RIGHTPAREN,
KEY_ASTERISK = SDLK_ASTERISK,
KEY_PLUS = SDLK_PLUS,
KEY_COMMA = SDLK_COMMA,
KEY_MINUS = SDLK_MINUS,
KEY_PERIOD = SDLK_PERIOD,
KEY_SLASH = SDLK_SLASH,
KEY_COLON = SDLK_COLON,
KEY_SEMICOLON = SDLK_SEMICOLON,
KEY_LESS = SDLK_LESS,
KEY_EQUALS = SDLK_EQUALS,
KEY_GREATER = SDLK_GREATER,
KEY_QUESTION = SDLK_QUESTION,
KEY_AT = SDLK_AT,
KEY_LEFTBRACKET = SDLK_LEFTBRACKET,
KEY_BACKSLASH = SDLK_BACKSLASH,
KEY_RIGHTBRACKET = SDLK_RIGHTBRACKET,
KEY_CARET = SDLK_CARET,
KEY_UNDERSCORE = SDLK_UNDERSCORE,
KEY_ALT = SDLK_LALT,
KEY_CONTROL = SDLK_LCTRL,
KEY_SHIFT = SDLK_LSHIFT,
KEY_TAB = SDLK_TAB,
KEY_DELETE = SDLK_DELETE,
KEY_PAGEUP = SDLK_PAGEUP,
KEY_PAGEDOWN = SDLK_PAGEDOWN,
KEY_F1 = SDLK_F1,
KEY_F2 = SDLK_F2,
KEY_F3 = SDLK_F3,
KEY_F4 = SDLK_F4,
KEY_F5 = SDLK_F5,
KEY_F6 = SDLK_F6,
KEY_F7 = SDLK_F7,
KEY_F8 = SDLK_F8,
KEY_F9 = SDLK_F9,
KEY_F10 = SDLK_F10,
KEY_F11 = SDLK_F11,
KEY_F12 = SDLK_F12,
KEY_PRINT = SDLK_PRINT,
KEY_LEFT = SDLK_LEFT,
KEY_RIGHT = SDLK_RIGHT,
KEY_UP = SDLK_UP,
KEY_DOWN = SDLK_DOWN,
KEY_0 = SDLK_0,
KEY_1 = SDLK_1,
KEY_2 = SDLK_2,
KEY_3 = SDLK_3,
KEY_4 = SDLK_4,
KEY_5 = SDLK_5,
KEY_6 = SDLK_6,
KEY_7 = SDLK_7,
KEY_8 = SDLK_8,
KEY_9 = SDLK_9,
KEY_a = SDLK_a,
KEY_b = SDLK_b,
KEY_c = SDLK_c,
KEY_d = SDLK_d,
KEY_e = SDLK_e,
KEY_f = SDLK_f,
KEY_g = SDLK_g,
KEY_h = SDLK_h,
KEY_i = SDLK_i,
KEY_j = SDLK_j,
KEY_k = SDLK_k,
KEY_l = SDLK_l,
KEY_m = SDLK_m,
KEY_n = SDLK_n,
KEY_o = SDLK_o,
KEY_p = SDLK_p,
KEY_q = SDLK_q,
KEY_r = SDLK_r,
KEY_s = SDLK_s,
KEY_t = SDLK_t,
KEY_u = SDLK_u,
KEY_v = SDLK_v,
KEY_w = SDLK_w,
KEY_x = SDLK_x,
KEY_y = SDLK_y,
KEY_z = SDLK_z,
#ifdef _WIN32_WCE
KEY_APP01 = 0xC1,
KEY_APP02 = 0xC2,
KEY_APP03 = 0xC3,
KEY_APP04 = 0xC4,
KEY_APP05 = 0xC5,
KEY_APP06 = 0xC6,
KEY_APP07 = 0xC7,
KEY_APP08 = 0xC8,
KEY_APP09 = 0xC9,
KEY_APP10 = 0xCA,
KEY_APP11 = 0xCB,
KEY_APP12 = 0xCC,
KEY_APP13 = 0xCD,
KEY_APP14 = 0xCE,
KEY_APP15 = 0xCF,
#endif
KEY_LAST
};
const char* KeySymGetName(KeySym);
KeySym GetKeySym(int);
class LocalEvent
{
public:
static LocalEvent & Get(void);
void SetGlobalFilterMouseEvents(void (*pf)(u16, u16));
void SetGlobalFilterKeysEvents(void (*pf)(int, u16));
void SetGlobalFilter(bool);
void SetTapMode(bool);
void SetTapDelayForRightClickEmulation(u32);
void SetMouseOffsetX(s16);
void SetMouseOffsetY(s16);
static void SetStateDefaults(void);
static void SetState(u32 type, bool enable);
static u8 GetState(u32 type);
bool HandleEvents(bool delay = true);
bool MouseMotion(void) const;
bool MouseMotion(const Rect &rt) const;
const Point & GetMouseCursor(void);
const Point & GetMousePressLeft(void) const;
const Point & GetMousePressMiddle(void) const;
const Point & GetMousePressRight(void) const;
const Point & GetMouseReleaseLeft(void) const;
const Point & GetMouseReleaseMiddle(void) const;
const Point & GetMouseReleaseRight(void) const;
void ResetPressLeft(void);
void ResetPressRight(void);
void ResetPressMiddle(void);
void ResetReleaseLeft(void);
void ResetReleaseRight(void);
void ResetReleaseMiddle(void);
bool MouseClickLeft(void);
bool MouseClickMiddle(void);
bool MouseClickRight(void);
bool MouseClickLeft(const Rect &rt);
bool MouseClickMiddle(const Rect &rt);
bool MouseClickRight(const Rect &rt);
bool MouseWheelUp(void) const;
bool MouseWheelDn(void) const;
bool MousePressLeft(void) const;
bool MousePressLeft(const Rect &rt) const;
bool MousePressLeft(const Point &pt, u16 w, u16 h) const;
bool MousePressMiddle(void) const;
bool MousePressMiddle(const Rect &rt) const;
bool MousePressRight(void) const;
bool MousePressRight(const Rect &rt) const;
bool MouseReleaseLeft(void) const;
bool MouseReleaseLeft(const Rect &rt) const;
bool MouseReleaseMiddle(void) const;
bool MouseReleaseMiddle(const Rect &rt) const;
bool MouseReleaseRight(void) const;
bool MouseReleaseRight(const Rect &rt) const;
bool MouseWheelUp(const Rect &rt) const;
bool MouseWheelDn(const Rect &rt) const;
bool MouseCursor(const Rect &rt) const;
bool KeyPress(void) const;
bool KeyPress(KeySym key) const;
KeySym KeyValue(void) const;
u16 KeyMod(void) const;
#ifdef WITHOUT_MOUSE
void ToggleEmulateMouse(void);
void SetEmulateMouse(bool);
void SetEmulateMouseUpKey(KeySym);
void SetEmulateMouseDownKey(KeySym);
void SetEmulateMouseLeftKey(KeySym);
void SetEmulateMouseRightKey(KeySym);
void SetEmulateMouseStep(u8);
void SetEmulatePressLeftKey(KeySym);
void SetEmulatePressRightKey(KeySym);
bool EmulateMouseAction(KeySym);
#endif
private:
LocalEvent();
void HandleMouseMotionEvent(const SDL_MouseMotionEvent & motion);
void HandleMouseButtonEvent(const SDL_MouseButtonEvent & button);
void HandleKeyboardEvent(SDL_KeyboardEvent &);
#if SDL_VERSION_ATLEAST(1, 3, 0)
static int GlobalFilterEvents(void *userdata, SDL_Event *event);
#else
static int GlobalFilterEvents(const SDL_Event *event);
#endif
enum flag_t
{
KEY_PRESSED = 0x0001,
MOUSE_MOTION = 0x0002,
MOUSE_PRESSED = 0x0004,
GLOBAL_FILTER = 0x0008,
CLICK_LEFT = 0x0010,
CLICK_RIGHT = 0x0020,
CLICK_MIDDLE = 0x0040,
TAP_MODE = 0x0080,
MOUSE_OFFSET = 0x0100,
CLOCK_ON = 0x0200
};
void SetModes(flag_t);
void ResetModes(flag_t);
u16 modes;
KeySym key_value;
u8 mouse_state;
u8 mouse_button;
Point mouse_st; // mouse offset for pocketpc
Point mouse_pl; // press left
Point mouse_pm; // press middle
Point mouse_pr; // press right
Point mouse_rl; // release left
Point mouse_rm; // release middle
Point mouse_rr; // release right
Point mouse_cu; // point cursor
void (*redraw_cursor_func)(u16, u16);
void (*keyboard_filter_func)(int, u16);
SDL::Time clock;
u32 clock_delay;
u8 loop_delay;
#ifdef WITHOUT_MOUSE
bool emulate_mouse;
KeySym emulate_mouse_up;
KeySym emulate_mouse_down;
KeySym emulate_mouse_left;
KeySym emulate_mouse_right;
u8 emulate_mouse_step;
KeySym emulate_press_left;
KeySym emulate_press_right;
#endif
};
#endif

View File

@@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include "midi.h"
u8 MIDI::UnpackDelta(const u8 *p, u32 & d)
{
const u8 *p2 = p;
d = 0;
while(*p2 & 0x80)
{
if(4 <= p2 - p)
{
std::cerr << "Event: unpack delta mistake" << std::endl;
break;
}
d |= 0x0000007F & static_cast<u32>(*p2);
d <<= 7;
++p2;
}
d += *p2;
return p2 - p + 1;
}
u8 MIDI::PackDelta(u8 *p, const u32 & d)
{
const u8 c1 = static_cast<char>(d & 0x0000007F);
const u8 c2 = static_cast<char>((d & 0x00003F80) >> 7);
const u8 c3 = static_cast<char>((d & 0x001FC000) >> 14);
const u8 c4 = static_cast<char>((d & 0x0FE00000) >> 21);
if(c4)
{ p[0] = c4 | 0x80; p[1] = c3 | 0x80; p[2] = c2 | 0x80; p[3] = c1; }
else
if(c3)
{ p[0] = c3 | 0x80; p[1] = c2 | 0x80; p[2] = c1; }
else
if(c2)
{ p[0] = c2 | 0x80; p[1] = c1; }
else
{ p[0] = c1; }
return (c4 ? 4 : (c3 ? 3 : (c2 ? 2 : 1)));
}

View File

@@ -0,0 +1,34 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_H
#define MIDI_H
#include "types.h"
namespace MIDI
{
u8 UnpackDelta(const u8 *p, u32 & d);
u8 PackDelta(u8 *p, const u32 & d);
}
#endif

View File

@@ -0,0 +1,203 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cstring>
#include <iostream>
#include <iomanip>
#include "midi_chunk.h"
using namespace MIDI;
Chunk::Chunk() : size(0), data(NULL)
{
memset(id, '\0', 4);
}
Chunk::Chunk(const char *i, const u32 s, const u8 *p) : size(s), data(NULL)
{
i ? memcpy(id, i, 4) : memset(id, '\0', 4);
if(size)
{
data = new u8[size];
if(p) memcpy(data, p, size); else memset(data, '\0', size);
}
}
Chunk::Chunk(std::istream & i) : size(0), data(NULL)
{
memset(id, '\0', 4);
Read(i);
}
Chunk::Chunk(const u8 *p) : size(0), data(NULL)
{
memset(id, '\0', 4);
Read(p);
}
Chunk::Chunk(const Chunk & c) : size(c.size), data(NULL)
{
c.id ? memcpy(id, c.id, 4) : memset(id, '\0', 4);
if(size)
{
data = new u8 [size];
memcpy(data, c.data, size);
}
}
Chunk::~Chunk()
{
if(data) delete [] data;
}
Chunk & Chunk::operator= (const Chunk & c)
{
if(data) delete [] data;
data = NULL;
c.id ? memcpy(id, c.id, 4) : memset(id, '\0', 4);
size = c.size;
if(size)
{
data = new u8 [size];
memcpy(data, c.data, size);
}
return *this;
}
bool Chunk::Read(std::istream & i)
{
if(i.fail()) return false;
i.read(id, 4);
i.read(reinterpret_cast<char *>(&size), 4);
SwapBE32(size);
if(data) delete [] data;
data = NULL;
if(size)
{
data = new u8 [size];
i.read(reinterpret_cast<char *>(data), size);
}
return true;
}
bool Chunk::Read(const std::vector<u8> & b)
{
if(8 > b.size()) return false;
memcpy(id, &b[0], 4);
size = ReadBE32(&b[4]);
if(data) delete [] data;
data = NULL;
if(size + 8 > b.size()) size = b.size() - 8;
if(size)
{
data = new u8 [size];
memcpy(data, &b[8], size);
}
return true;
}
bool Chunk::Read(const u8 *p)
{
if(NULL == p) return false;
memcpy(id, p, 4);
size = ReadBE32(&p[4]);
if(data) delete [] data;
data = NULL;
if(size)
{
data = new u8 [size];
memcpy(data, &p[8], size);
}
return true;
}
bool Chunk::Write(std::ostream & o) const
{
if(o.fail()) return false;
o.write(id, 4);
u32 x = size;
SwapBE32(x);
o.write(reinterpret_cast<char *>(&x), 4);
if(size && data) o.write(reinterpret_cast<char *>(data), size);
return true;
}
bool Chunk::Write(u8 *p) const
{
if(NULL == p) return false;
memcpy(p, id, 4);
WriteBE32(&p[4], size);
if(size && data) memcpy(&p[8], data, size);
return true;
}
void Chunk::Dump(void) const
{
std::cerr << "id: ";
std::cerr.write(id, 4);
std::cerr << std::endl << "size: " << std::dec << size << std::endl << "data: " << std::endl;
u8 endline = 0;
for(u32 ii = 0; ii < size; ++ii)
{
std::cerr << " 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<u32>(static_cast<u8>(data[ii])) << ":";
++endline;
if(endline > 15)
{
endline = 0;
std::cerr << std::endl;
}
}
std::cerr << std::endl;
}

View File

@@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_CHUNK_H
#define MIDI_CHUNK_H
#include <ostream>
#include <istream>
#include <vector>
#include "midi.h"
namespace MIDI
{
class Chunk
{
public:
char id[4];
u32 size;
u8* data;
Chunk();
Chunk(const char *i, const u32 s, const u8 *p = NULL);
Chunk(std::istream & i);
Chunk(const u8 *p);
Chunk(const Chunk & c);
~Chunk();
Chunk & operator= (const Chunk & c);
bool Write(std::ostream & o) const;
bool Write(u8 *p) const;
bool Read(std::istream & i);
bool Read(const u8 *p);
bool Read(const std::vector<u8> & b);
void Dump(void) const;
};
}
#endif

View File

@@ -0,0 +1,146 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cstring>
#include <iomanip>
#include <iostream>
#include "midi_event.h"
using namespace MIDI;
Event::Event() : delta(0), status(0), sp(0)
{
}
Event::Event(const u32 dl, const u8 st, const u32 sz, const u8 *p) : delta(dl), status(st), data(NULL)
{
if(sz)
{
data = new u8 [sz];
size = sz;
memcpy(data, p, size);
}
SetDelta(dl);
}
Event::Event(const Event & e)
{
delta = e.delta;
status = e.status;
data = NULL;
size = e.size;
if(size)
{
data = new u8 [size];
memcpy(data, e.data, size);
}
memcpy(pack, e.pack, 4);
sp = e.sp;
}
Event::~Event()
{
if(data) delete [] data;
}
Event & Event::operator= (const Event & e)
{
if(data) delete [] data;
delta = e.delta;
status = e.status;
data = NULL;
size = e.size;
if(size)
{
data = new u8 [size];
memcpy(data, e.data, size);
}
memcpy(pack, e.pack, 4);
sp = e.sp;
return *this;
}
void Event::SetDelta(const u32 dl)
{
sp = MIDI::PackDelta(pack, dl);
}
u32 Event::Size(void) const
{
return 1 + sp + size;
}
bool Event::Write(u8 *p) const
{
if(NULL == p) return false;
memcpy(p, pack, sp);
p+= sp;
*p = status;
if(size) memcpy(p + 1, data, size);
return true;
}
bool Event::Write(std::ostream & o) const
{
if(o.fail()) return false;
o.write(reinterpret_cast<const char*>(pack), sp);
o.write(&status, 1);
if(size) o.write(reinterpret_cast<const char*>(data), size);
return true;
}
void Event::Dump(void) const
{
std::cerr << std::hex << std::setfill('0') \
<< "[dl:0x" << std::setw(4) << delta \
<< ":st:0x" << std::setw(2) << static_cast<u16>(static_cast<u8>(status)) << ":dt";
u8 endline = 0;
for(u32 ii = 0; ii < size; ++ii)
{
std::cerr << " 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<u32>(static_cast<u8>(data[ii])) << ":";
++endline;
if(endline > 15)
{
endline = 0;
std::cerr << std::endl;
}
}
std::cerr << "]" << std::endl;
}

View File

@@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_EVENT_H
#define MIDI_EVENT_H
#include <ostream>
#include "midi.h"
namespace MIDI
{
class Event
{
public:
Event();
Event(const u32 dl, const u8 st, const u32 sz, const u8 *p);
Event(const Event &);
~Event();
Event & operator= (const Event &);
u32 Size(void) const;
u32 Delta(void) const { return delta; };
u8 Status(void) const { return status; };
void SetDelta(const u32 dl);
void Dump(void) const;
bool Write(u8 *p) const;
bool Write(std::ostream & o) const;
protected:
u32 delta;
char status;
u8* data;
u32 size;
u8 pack[4];
u8 sp;
};
}
#endif

View File

@@ -0,0 +1,228 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <string>
#include <fstream>
#include <iostream>
#include "midi_chunk.h"
#include "midi_mid.h"
using namespace MIDI;
Mid::Mid()
{
}
Mid::Mid(const Mid & m) : mthd(m.mthd)
{
std::list<MTrk *>::const_iterator it1 = m.tracks.begin();
std::list<MTrk *>::const_iterator it2 = m.tracks.end();
for(; it1 != it2; ++it1) if(*it1) tracks.push_back(new MTrk(**it1));
}
Mid::~Mid()
{
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) if(*it1) delete *it1;
}
}
Mid & Mid::operator= (const Mid & m)
{
mthd = m.mthd;
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) delete *it1;
}
std::list<MTrk *>::const_iterator it1 = m.tracks.begin();
std::list<MTrk *>::const_iterator it2 = m.tracks.end();
for(; it1 != it2; ++it1) if(*it1) tracks.push_back(new MTrk(**it1));
return *this;
}
bool Mid::Read(const std::vector<u8> & body)
{
mthd.Read(body);
if(! mthd.isValid())
{
std::cerr << "Mid::Read: " << "error format" << std::endl;
return false;
}
const u32 count = mthd.Tracks();
const u8 *ptr = &body[mthd.Size()];
for(u16 ii = 0; ii < count; ++ii)
{
if(ptr >= &body[0] + body.size())
{
std::cerr << "Mid::Read: " << "error read chunk, total: " << count << ", current: " << ii << std::endl;
return false;
}
const Chunk chunk(ptr);
if(0 == memcmp(ID_MTRK, chunk.id, 4)) tracks.push_back(new MTrk(chunk.data, chunk.size));
else --ii;
ptr += 8 + chunk.size;
}
return true;
}
bool Mid::Read(const std::string & filename)
{
std::ifstream fd(filename.c_str(), std::ios::binary);
if(!fd.is_open())
{
std::cerr << "Mid::Read: " << "error read: " << filename << std::endl;
return false;
}
mthd.Read(fd);
if(! mthd.isValid())
{
std::cerr << "Mid::Read: " << "error format: " << filename << std::endl;
return false;
}
const u32 count = mthd.Tracks();
for(u16 ii = 0; ii < count; ++ii)
{
if(fd.fail())
{
std::cerr << "Mid::Read: " << "error read chunk, total: " << count << ", current: " << ii << std::endl;
return false;
}
const Chunk chunk(fd);
if(0 == memcmp(ID_MTRK, chunk.id, 4)) tracks.push_back(new MTrk(chunk.data, chunk.size));
else --ii;
}
fd.close();
return true;
}
u32 Mid::Size(void) const
{
u32 total = mthd.Size();
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) if(*it1) total += (*it1)->Size();
}
return total;
}
bool Mid::Write(std::vector<u8> & body)
{
body.resize(Size());
u8 *ptr = &body[0];
mthd.Write(ptr);
ptr += mthd.Size();
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) if(*it1){ (*it1)->Write(ptr); ptr += (*it1)->Size(); }
}
return true;
}
bool Mid::Write(const std::string & filename)
{
std::ofstream fd(filename.c_str(), std::ios::binary);
if(!fd.is_open())
{
std::cerr << "Mid::Write: " << "error write: " << filename << std::endl;
return false;
}
mthd.Write(fd);
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) if(*it1) (*it1)->Write(fd);
}
fd.close();
return true;
}
void Mid::Dump(void) const
{
mthd.Dump();
if(tracks.size())
{
std::list<MTrk *>::const_iterator it1 = tracks.begin();
std::list<MTrk *>::const_iterator it2 = tracks.end();
for(; it1 != it2; ++it1) if(*it1) (*it1)->Dump();
}
}
void Mid::AddTrack(MTrk & track)
{
tracks.push_back(new MTrk(track));
mthd.SetTracks(mthd.Tracks() + 1);
}

View File

@@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_MID_H
#define MIDI_MID_H
#include <vector>
#include <list>
#include "midi.h"
#include "midi_mthd.h"
#include "midi_mtrk.h"
namespace MIDI
{
class Mid
{
public:
Mid();
Mid(const Mid & m);
~Mid();
Mid & operator= (const Mid & m);
bool Read(const std::string & filename);
bool Read(const std::vector<u8> & body);
bool Write(const std::string & filename);
bool Write(std::vector<u8> & body);
u32 Size(void) const;
void SetFormat(const u16 f){ mthd.SetFormat(f); };
void SetTracks(const u16 t){ mthd.SetTracks(t); };
void SetPPQN(const u16 p){ mthd.SetPPQN(p); };
void AddTrack(MTrk & track);
void Dump(void) const;
private:
MThd mthd;
std::list<MTrk *> tracks;
};
}
#endif

View File

@@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include "midi_mthd.h"
using namespace MIDI;
void MThd::Dump(void) const
{
std::cerr << "[MThd] format: " << Format() << ", tracks: " << Tracks() << ", ppqn: " << PPQN() << std::endl;
}
void MThd::SetFormat(const u16 f)
{
WriteBE16(reinterpret_cast<u8*>(&data[0]), f);
}
void MThd::SetTracks(const u16 t)
{
WriteBE16(reinterpret_cast<u8*>(&data[2]), t);
}
void MThd::SetPPQN(const u16 p)
{
WriteBE16(reinterpret_cast<u8*>(&data[4]), p);
}

View File

@@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_MTHD_H
#define MIDI_MTHD_H
#include <vector>
#include <istream>
#include <cstring>
#include "midi.h"
#include "midi_chunk.h"
#define ID_MTHD "MThd"
namespace MIDI
{
class MThd : protected Chunk
{
public:
MThd() : Chunk(ID_MTHD, 6) {};
MThd(const u8 *p, const u32 s) : Chunk(ID_MTHD, s, p) {};
MThd(std::istream & i) : Chunk(i) {};
bool isValid(void) const{ return 0 == memcmp(Chunk::id, ID_MTHD, 4); };
bool Read(std::istream & is){ return Chunk::Read(is); };
bool Read(const std::vector<u8> & b){ return Chunk::Read(b); };
bool Write(std::ostream & os) const{ return Chunk::Write(os); };
bool Write(u8* b) const{ return Chunk::Write(b); };
void SetFormat(const u16 f);
void SetTracks(const u16 t);
void SetPPQN(const u16 p);
const u8* Data(void) const{ return Chunk::data; };
u32 Size(void) const{ return 8 + size; };
u16 Format(void) const{ return ReadBE16(reinterpret_cast<const u8*>(&data[0])); };
u16 Tracks(void) const{ return ReadBE16(reinterpret_cast<const u8*>(&data[2])); };
u16 PPQN(void) const{ return ReadBE16(reinterpret_cast<const u8*>(&data[4])); };
void Dump(void) const;
};
}
#endif

View File

@@ -0,0 +1,348 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iomanip>
#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include "midi_mtrk.h"
using namespace MIDI;
struct meta_t
{
meta_t() : command(0), quantity(0), duration(0){}
meta_t(u8 c, u8 q, u32 d) : command(c), quantity(q), duration(d){}
bool operator< (const meta_t & m) const{ return duration < m.duration; }
void decrease_duration(u32 delta) { duration -= delta; }
u8 command;
u8 quantity;
u32 duration;
};
MTrk::MTrk(const u8 *p, const u32 s)
{
const u8 *ptr = p;
bool end = false;
while(ptr && !end && ptr < (p + s))
{
u32 delta = 0;
const u8 s = MIDI::UnpackDelta(ptr, delta);
ptr += s;
const u8 status = *ptr;
ptr += 1;
switch(status >> 4)
{
// meta
case 0x0F:
{
u32 size = 0;
const u8 s = MIDI::UnpackDelta(ptr + 1, size);
if(0xFF == status && 0x2F == *ptr)
{
end = true;
events.push_back(new Event(delta, status, 1 + s + size, ptr));
}
ptr += 1 + s + size;
}
break;
// note off
case 0x08:
// note on
case 0x09:
// key pressure
case 0x0A:
// control change
case 0x0B:
// pitch bend
case 0x0E:
{
events.push_back(new Event(delta, status, 2, ptr));
ptr += 2;
}
break;
// program change
case 0x0C:
// chanel pressure
case 0x0D:
{
events.push_back(new Event(delta, status, 1, ptr));
ptr += 1;
}
break;
// unused command
default:
end = true;
CloseEvents();
std::cerr << "unknown st: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(status) << ", ln: " << static_cast<int>(p + s - ptr) << std::endl;
break;
}
}
}
MTrk::MTrk(const MTrk & t)
{
std::list<Event *>::const_iterator it1 = t.events.begin();
std::list<Event *>::const_iterator it2 = t.events.end();
for(; it1 != it2; ++it1) if(*it1) events.push_back(new Event(**it1));
}
MTrk::~MTrk()
{
if(events.size())
{
std::list<Event *>::const_iterator it1 = events.begin();
std::list<Event *>::const_iterator it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) delete *it1;
}
}
u32 MTrk::Size(void) const
{
u32 result = 8; // id + size
std::list<Event *>::const_iterator it1 = events.begin();
std::list<Event *>::const_iterator it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) result += (*it1)->Size();
return result;
}
bool MTrk::Write(std::ostream & o) const
{
if(o.fail()) return false;
o.write(ID_MTRK, 4);
u32 size = 0;
std::list<Event *>::const_iterator it1 = events.begin();
std::list<Event *>::const_iterator it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) size += (*it1)->Size();
u32 x = size;
SwapBE32(x);
o.write(reinterpret_cast<char *>(&x), 4);
if(events.size())
{
it1 = events.begin();
it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) (*it1)->Write(o);
}
return true;
}
bool MTrk::Write(u8 *p) const
{
if(NULL == p) return false;
memcpy(p, ID_MTRK, 4);
p+= 4;
u32 size = 0;
std::list<Event *>::const_iterator it1 = events.begin();
std::list<Event *>::const_iterator it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) size += (*it1)->Size();
u32 x = size;
WriteBE32(p, x);
p+= 4;
if(events.size())
{
it1 = events.begin();
it2 = events.end();
for(; it1 != it2; ++it1) if(*it1){ (*it1)->Write(p); p += (*it1)->Size(); }
}
return true;
}
void MTrk::AddEvent(const Event & e)
{
events.push_back(new Event(e));
}
void MTrk::CloseEvents(void)
{
events.push_back(new Event(0, 0xFF, 2, reinterpret_cast<const u8*>("\057\000")));
}
void MTrk::Dump(void) const
{
std::cerr << "[MTrk]\n";
if(events.size())
{
std::list<Event *>::const_iterator it1 = events.begin();
std::list<Event *>::const_iterator it2 = events.end();
for(; it1 != it2; ++it1) if(*it1) (*it1)->Dump();
}
std::cerr << std::endl;
}
void MTrk::ImportXmiEVNT(const Chunk & evnt)
{
const u8 *ptr = evnt.data;
u8 buf[2];
u32 delta = 0;
u32 delta2 = 0;
std::list<meta_t> notesoff;
std::list<meta_t>::iterator it1, it2;
while(ptr && ptr < (evnt.data + evnt.size))
{
// insert event: note off
if(delta)
{
// sort duration
notesoff.sort();
it1 = notesoff.begin();
it2 = notesoff.end();
delta2 = 0;
// apply delta
for(; it1 != it2; ++it1)
{
if((*it1).duration <= delta)
{
buf[0] = (*it1).quantity;
buf[1] = 0x7F;
// note off
events.push_back(new Event((*it1).duration - delta2, (*it1).command, 2, buf));
delta2 += ((*it1).duration - delta2);
}
}
// remove end notes
while(notesoff.size() && notesoff.front().duration <= delta)
notesoff.pop_front();
// fixed delta
if(delta2) delta -= delta2;
// decrease duration
std::for_each(notesoff.begin(), notesoff.end(), std::bind2nd(std::mem_fun_ref(&meta_t::decrease_duration), delta));
}
// interval
if(*ptr < 128)
{
delta += *ptr;
++ptr;
}
else
// command
{
// end
if(0xFF == *ptr && 0x2F == *(ptr + 1))
{
events.push_back(new Event(delta, *ptr, 2, ptr + 1));
break;
}
else
switch(*ptr >> 4)
{
// meta
case 0x0F:
{
u32 size = 0;
size += 1 + MIDI::UnpackDelta(ptr + 2, size);
ptr += size + 1;
delta = 0;
}
break;
// key pressure
case 0x0A:
// control change
case 0x0B:
// pitch bend
case 0x0E:
{
events.push_back(new Event(delta, *ptr, 2, ptr + 1));
ptr += 3;
delta = 0;
}
break;
// note off
case 0x08:
{
events.push_back(new Event(delta, *ptr, 2, ptr + 1));
u32 duration = 0;
const u8 s = MIDI::UnpackDelta(ptr + 3, duration);
notesoff.push_back(meta_t(*ptr - 0x10, *(ptr + 1), duration));
ptr += 3 + s;
delta = 0;
}
break;
// note on
case 0x09:
{
events.push_back(new Event(delta, *ptr, 2, ptr + 1));
u32 duration = 0;
const u8 s = MIDI::UnpackDelta(ptr + 3, duration);
notesoff.push_back(meta_t(*ptr - 0x10, *(ptr + 1), duration));
ptr += 3 + s;
delta = 0;
}
break;
// program change
case 0x0C:
// chanel pressure
case 0x0D:
{
events.push_back(new Event(delta, *ptr, 1, ptr + 1));
ptr += 2;
delta = 0;
}
break;
// unused command
default:
CloseEvents();
std::cerr << "unknown st: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(*ptr) << ", ln: " << static_cast<int>(evnt.data + evnt.size - ptr) << std::endl;
break;
}
}
}
}

View File

@@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_TRACK_H
#define MIDI_TRACK_H
#include <list>
#include <ostream>
#include "midi.h"
#include "midi_chunk.h"
#include "midi_event.h"
#define ID_MTRK "MTrk"
namespace MIDI
{
u8 UnpackDelta(const char *p, u32 & d);
u8 PackDelta(char *p, const u32 & d);
class MTrk
{
public:
MTrk() {};
MTrk(const u8 *p, const u32 s);
MTrk(const MTrk & t);
~MTrk();
bool Write(std::ostream & o) const;
bool Write(u8 *p) const;
u32 Size(void) const;
void AddEvent(const Event & e);
void ImportXmiEVNT(const Chunk & c);
void CloseEvents(void);
void Dump(void) const;
private:
std::list<Event *> events;
};
}
#endif

View File

@@ -0,0 +1,138 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <fstream>
#include <iostream>
#include <cstring>
#include <vector>
#include "midi_xmi.h"
#define ID_FORM "FORM"
#define ID_CAT "CAT "
#define ID_XMID "XMID"
#define ID_TIMB "TIMB"
#define ID_EVNT "EVNT"
using namespace MIDI;
Xmi::Xmi()
{
}
bool Xmi::Read(const std::vector<u8> & body)
{
if(0 == body.size())
{
std::cerr << "Xmi: " << "incorrect size" << std::endl;
return false;
}
const u8 *ptr = &body[0];
if(memcmp(ID_FORM, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect id: " << ID_FORM << std::endl;
return false;
}
head.Read(ptr);
ptr += 8 + head.size;
if(memcmp(ID_CAT, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect id: " << ID_CAT<< std::endl;
return false;
}
ptr += 8;
if(memcmp(ID_XMID, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect cat id: " << ID_XMID << std::endl;
return false;
}
ptr += 4;
if(memcmp(ID_FORM, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect xmid id: " << ID_FORM << std::endl;
return false;
}
else
ptr += 8;
if(memcmp(ID_XMID, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect form id: " << ID_XMID << std::endl;
return false;
}
ptr += 4;
if(memcmp(ID_TIMB, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect id: " << ID_TIMB << std::endl;
return false;
}
timb.Read(ptr);
ptr += 8 + timb.size;
if(memcmp(ID_EVNT, ptr, 4))
{
std::cerr << "Xmi: " << "incorrect id: " << ID_EVNT << std::endl;
return false;
}
evnt.Read(ptr);
return true;
}
bool Xmi::Read(const std::string & filename)
{
std::ifstream fd(filename.c_str(), std::ios::binary);
if(!fd.is_open())
{
std::cerr << "Xmi: " << "error read: " << filename.c_str() << std::endl;
return false;
}
fd.seekg(0, std::ios_base::end);
const u32 size = fd.tellg();
fd.seekg(0, std::ios_base::beg);
std::vector<u8> body(size);
fd.read(reinterpret_cast<char*>(&body[0]), size);
fd.close();
return Read(body);
}
void Xmi::Dump(void) const
{
head.Dump();
timb.Dump();
evnt.Dump();
}

View File

@@ -0,0 +1,52 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MIDI_XMI_H
#define MIDI_XMI_H
#include <list>
#include "midi.h"
#include "midi_chunk.h"
namespace MIDI
{
class Xmi
{
public:
Xmi();
bool Read(const std::string & filename);
bool Read(const std::vector<u8> & body);
const Chunk & TIMB(void) const { return timb; }
const Chunk & EVNT(void) const { return evnt; }
void Dump(void) const;
private:
Chunk head;
Chunk timb;
Chunk evnt;
};
}
#endif

View File

@@ -0,0 +1,87 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "SDL.h"
#include "surface.h"
#include "error.h"
#include "palette_h2.h"
#include "palette.h"
#define PALETTE_SIZE 255
Palette::Palette()
{
sdlpal = new SDL_Palette;
sdlpal->ncolors = PALETTE_SIZE;
sdlpal->colors = new SDL_Color[PALETTE_SIZE];
pal = new u32 [PALETTE_SIZE];
Surface sfa;
sfa.CreateSurface(1, 1, Surface::GetDefaultDepth(), SDL_SWSURFACE|SDL_SRCALPHA);
const unsigned char *p = kb_pal;
for(u16 ii = 0; ii < PALETTE_SIZE; ++ii)
{
sdlpal->colors[ii].r = *p++;
sdlpal->colors[ii].g = *p++;
sdlpal->colors[ii].b = *p++;
sdlpal->colors[ii].r <<= 2;
sdlpal->colors[ii].g <<= 2;
sdlpal->colors[ii].b <<= 2;
pal[ii] = SDL_MapRGBA(sfa.surface->format, sdlpal->colors[ii].r, sdlpal->colors[ii].g, sdlpal->colors[ii].b, 0xFF);
}
}
Palette::~Palette()
{
if(sdlpal)
{
if(sdlpal->colors) delete [] sdlpal->colors;
delete sdlpal;
}
if(pal) delete [] pal;
}
Palette & Palette::Get(void)
{
static Palette pal_cache;
return pal_cache;
}
u16 Palette::Size(void) const
{
return PALETTE_SIZE;
}
u32 Palette::GetColor(u16 index) const
{
return index < PALETTE_SIZE ? pal[index] : 0;
}
const SDL_Palette * Palette::SDLPalette(void) const
{
return sdlpal;
}

View File

@@ -0,0 +1,49 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2PALETTE_H
#define H2PALETTE_H
#include "types.h"
struct SDL_Palette;
struct SDL_Color;
class Palette
{
public:
~Palette();
static Palette & Get(void);
u16 Size(void) const;
u32 GetColor(u16) const;
const SDL_Palette * SDLPalette(void) const;
private:
Palette();
u32* pal;
SDL_Palette *sdlpal;
};
#endif

View File

@@ -0,0 +1,55 @@
#ifndef H2KBPAL_H
#define H2KBPAL_H
static const unsigned char kb_pal[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f,
0x3f, 0x3c, 0x3c, 0x3c, 0x3a, 0x3a, 0x3a, 0x37, 0x37, 0x37, 0x35, 0x35, 0x35, 0x32, 0x32, 0x32,
0x30, 0x30, 0x30, 0x2d, 0x2d, 0x2d, 0x2b, 0x2b, 0x2b, 0x29, 0x29, 0x29, 0x26, 0x26, 0x26, 0x24,
0x24, 0x24, 0x21, 0x21, 0x21, 0x1f, 0x1f, 0x1f, 0x1c, 0x1c, 0x1c, 0x1a, 0x1a, 0x1a, 0x17, 0x17,
0x17, 0x15, 0x15, 0x15, 0x12, 0x12, 0x12, 0x10, 0x10, 0x10, 0x0e, 0x0e, 0x0e, 0x0b, 0x0b, 0x0b,
0x09, 0x09, 0x09, 0x06, 0x06, 0x06, 0x04, 0x04, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x3f,
0x3b, 0x37, 0x3c, 0x37, 0x32, 0x3a, 0x34, 0x2e, 0x38, 0x31, 0x2a, 0x36, 0x2e, 0x26, 0x34, 0x2a,
0x22, 0x32, 0x28, 0x1e, 0x30, 0x25, 0x1b, 0x2e, 0x22, 0x18, 0x2b, 0x1f, 0x15, 0x29, 0x1c, 0x12,
0x27, 0x1a, 0x0f, 0x25, 0x18, 0x0d, 0x23, 0x15, 0x0b, 0x21, 0x13, 0x08, 0x1f, 0x11, 0x07, 0x1d,
0x0f, 0x05, 0x1a, 0x0d, 0x04, 0x18, 0x0c, 0x03, 0x16, 0x0a, 0x02, 0x14, 0x09, 0x01, 0x12, 0x07,
0x01, 0x0f, 0x06, 0x00, 0x0d, 0x05, 0x00, 0x0b, 0x04, 0x00, 0x09, 0x03, 0x00, 0x30, 0x33, 0x3f,
0x2b, 0x2e, 0x3c, 0x26, 0x2a, 0x3a, 0x22, 0x26, 0x38, 0x1e, 0x22, 0x36, 0x1a, 0x1e, 0x34, 0x16,
0x1a, 0x31, 0x13, 0x16, 0x2f, 0x10, 0x13, 0x2d, 0x0d, 0x10, 0x2b, 0x0a, 0x0d, 0x29, 0x08, 0x0c,
0x26, 0x07, 0x0a, 0x24, 0x05, 0x09, 0x22, 0x04, 0x08, 0x20, 0x03, 0x07, 0x1e, 0x02, 0x06, 0x1c,
0x01, 0x05, 0x19, 0x01, 0x05, 0x17, 0x00, 0x04, 0x15, 0x00, 0x03, 0x13, 0x00, 0x03, 0x11, 0x2b,
0x38, 0x27, 0x27, 0x35, 0x23, 0x24, 0x33, 0x20, 0x20, 0x30, 0x1c, 0x1d, 0x2e, 0x19, 0x1a, 0x2c,
0x17, 0x17, 0x29, 0x14, 0x14, 0x27, 0x11, 0x12, 0x24, 0x0f, 0x0f, 0x22, 0x0c, 0x0d, 0x1f, 0x0a,
0x0b, 0x1d, 0x09, 0x09, 0x1b, 0x07, 0x08, 0x19, 0x06, 0x06, 0x17, 0x05, 0x05, 0x15, 0x03, 0x03,
0x13, 0x02, 0x02, 0x10, 0x01, 0x01, 0x0e, 0x01, 0x01, 0x0c, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x08,
0x00, 0x00, 0x06, 0x00, 0x3f, 0x3d, 0x34, 0x3e, 0x3a, 0x2b, 0x3d, 0x38, 0x23, 0x3c, 0x37, 0x1b,
0x3b, 0x35, 0x14, 0x3a, 0x33, 0x0d, 0x39, 0x32, 0x05, 0x38, 0x31, 0x00, 0x36, 0x2f, 0x08, 0x34,
0x2c, 0x07, 0x32, 0x28, 0x06, 0x2f, 0x26, 0x06, 0x2d, 0x23, 0x06, 0x2a, 0x1f, 0x05, 0x27, 0x1c,
0x04, 0x25, 0x19, 0x03, 0x22, 0x16, 0x03, 0x1f, 0x13, 0x02, 0x1d, 0x11, 0x02, 0x1a, 0x0f, 0x00,
0x18, 0x0c, 0x00, 0x15, 0x0a, 0x00, 0x13, 0x08, 0x00, 0x39, 0x33, 0x3e, 0x36, 0x2f, 0x3b, 0x32,
0x2a, 0x39, 0x30, 0x27, 0x36, 0x2d, 0x23, 0x34, 0x2a, 0x1f, 0x31, 0x27, 0x1c, 0x2f, 0x24, 0x19,
0x2d, 0x21, 0x16, 0x2a, 0x1e, 0x13, 0x28, 0x1c, 0x11, 0x25, 0x19, 0x0e, 0x23, 0x17, 0x0c, 0x20,
0x14, 0x0a, 0x1e, 0x12, 0x08, 0x1b, 0x10, 0x06, 0x19, 0x0e, 0x05, 0x17, 0x0b, 0x02, 0x14, 0x08,
0x01, 0x11, 0x06, 0x00, 0x0e, 0x04, 0x00, 0x0b, 0x2d, 0x3d, 0x3f, 0x2a, 0x3a, 0x3c, 0x28, 0x38,
0x3a, 0x25, 0x36, 0x38, 0x22, 0x33, 0x35, 0x20, 0x31, 0x33, 0x1e, 0x2e, 0x31, 0x1c, 0x2c, 0x2f,
0x19, 0x2a, 0x2c, 0x17, 0x27, 0x2a, 0x16, 0x25, 0x28, 0x14, 0x23, 0x25, 0x12, 0x20, 0x23, 0x10,
0x1d, 0x20, 0x0e, 0x1a, 0x1d, 0x0c, 0x18, 0x1b, 0x0a, 0x15, 0x18, 0x08, 0x13, 0x16, 0x07, 0x10,
0x13, 0x05, 0x0e, 0x10, 0x04, 0x0b, 0x0e, 0x03, 0x09, 0x0b, 0x02, 0x07, 0x09, 0x3f, 0x39, 0x39,
0x3d, 0x34, 0x34, 0x3c, 0x2f, 0x2f, 0x3a, 0x2b, 0x2b, 0x39, 0x27, 0x27, 0x37, 0x23, 0x23, 0x36,
0x1f, 0x1f, 0x34, 0x1b, 0x1b, 0x33, 0x17, 0x17, 0x31, 0x14, 0x14, 0x30, 0x11, 0x11, 0x2f, 0x0e,
0x0e, 0x2e, 0x0b, 0x0b, 0x2d, 0x09, 0x09, 0x2a, 0x08, 0x08, 0x27, 0x06, 0x06, 0x24, 0x04, 0x04,
0x21, 0x03, 0x03, 0x1e, 0x02, 0x02, 0x1b, 0x01, 0x01, 0x18, 0x00, 0x00, 0x15, 0x00, 0x00, 0x12,
0x00, 0x00, 0x3f, 0x39, 0x27, 0x3e, 0x36, 0x23, 0x3d, 0x34, 0x1f, 0x3c, 0x31, 0x1c, 0x3b, 0x2e,
0x18, 0x3a, 0x2b, 0x14, 0x39, 0x28, 0x11, 0x38, 0x24, 0x0e, 0x38, 0x21, 0x0b, 0x33, 0x1d, 0x08,
0x2e, 0x19, 0x06, 0x29, 0x16, 0x04, 0x25, 0x12, 0x02, 0x20, 0x0f, 0x01, 0x1b, 0x0c, 0x00, 0x17,
0x0a, 0x00, 0x3f, 0x16, 0x03, 0x37, 0x0d, 0x01, 0x30, 0x05, 0x00, 0x29, 0x00, 0x00, 0x3f, 0x3f,
0x00, 0x3f, 0x33, 0x00, 0x30, 0x23, 0x00, 0x23, 0x12, 0x00, 0x29, 0x34, 0x00, 0x25, 0x2f, 0x00,
0x21, 0x2b, 0x00, 0x1e, 0x27, 0x01, 0x1a, 0x23, 0x01, 0x17, 0x1e, 0x01, 0x13, 0x1a, 0x01, 0x10,
0x16, 0x01, 0x0d, 0x12, 0x01, 0x0a, 0x1e, 0x34, 0x06, 0x1a, 0x31, 0x01, 0x12, 0x2d, 0x00, 0x0e,
0x2b, 0x03, 0x15, 0x2f, 0x00, 0x0e, 0x2b, 0x00, 0x10, 0x2d, 0x21, 0x38, 0x3f, 0x00, 0x26, 0x3f,
0x00, 0x14, 0x39, 0x00, 0x00, 0x29, 0x23, 0x23, 0x2f, 0x1c, 0x1c, 0x27, 0x15, 0x15, 0x1f, 0x0f,
0x0f, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif

View File

@@ -0,0 +1,85 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iterator>
#include "rand.h"
void Rand::Init(void){ std::srand((u32) std::time(0)); }
u32 Rand::Get(u32 min, u32 max){ return max ? min + Get(max - min) : static_cast<u32>((min + 1) * (std::rand() / (RAND_MAX + 1.0))); }
Rand::Queue::Queue(u32 size)
{
reserve(size);
}
void Rand::Queue::Reset(void)
{
clear();
}
void Rand::Queue::Push(s32 value, u32 percent)
{
if(percent)
push_back(std::make_pair(value, percent));
}
size_t Rand::Queue::Size(void) const
{
return size();
}
s32 Rand::Queue::Get(void)
{
std::vector<ValuePercent>::iterator it;
// get max
it = begin();
u32 max = 0;
for(; it != end(); ++it) max += (*it).second;
// set weight (from 100)
it = begin();
for(; it != end(); ++it) (*it).second = 100 * (*it).second / max;
// get max
max = 0;
it = begin();
for(; it != end(); ++it) max += (*it).second;
u8 rand = Rand::Get(max);
u8 amount = 0;
it = begin();
for(; it != end(); ++it)
{
amount += (*it).second;
if(rand <= amount) return (*it).first;
}
std::cerr << "Rand::Queue::Get:" << " weight not found, return 0" << std::endl;
return 0;
}

View File

@@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef H2RAND_H
#define H2RAND_H
#include <vector>
#include <list>
#include <utility>
#include "types.h"
namespace Rand
{
void Init(void);
u32 Get(u32 min, u32 max = 0);
template< typename T > const T * Get(const std::vector< T > & vec)
{
if(vec.empty()) return NULL;
return & vec[Rand::Get(vec.size() - 1)];
}
template< typename T > const T * Get(const std::list< T > & list)
{
if(list.empty()) return NULL;
u32 index1 = Rand::Get(list.size() - 1);
u32 index2 = 0;
typename std::list<T>::const_iterator it = list.begin();
for(; it != list.end(); ++it) if(index1 == index2++) break;
return & (*it);
}
typedef std::pair<s32, u32> ValuePercent;
class Queue : private std::vector<ValuePercent>
{
public:
Queue(u32 size = 0);
void Reset(void);
void Push(s32, u32);
size_t Size(void) const;
s32 Get(void);
};
}
#endif

Some files were not shown because too many files have changed in this diff Show More