[Add] Commiting project. [Dead project].
33
Lephisto.log
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
Log Started: Sun Nov 4 22:08:00 2012
|
||||||
|
|
||||||
|
Warning: Failed to open file (line 0) Using defaults
|
||||||
|
Configuration:
|
||||||
|
Resolution: 640 x 480
|
||||||
|
Fullscreen: false
|
||||||
|
Use VBOs: false
|
||||||
|
Enable SDL Parachute: true
|
||||||
|
Compress Textures: true
|
||||||
|
|
||||||
|
Got video info
|
||||||
|
Video mode set
|
||||||
|
Extensions verified
|
||||||
|
Audio initialised
|
||||||
|
Current state pointer set
|
||||||
|
Font lists generated
|
||||||
|
Warning: Could not load ./data/font.png
|
||||||
|
Font texture loaded
|
||||||
|
Font texture bound
|
||||||
|
Fonts built
|
||||||
|
Warning: Could not load ./data/title.png
|
||||||
|
Warning: Could not load ./data/background.png
|
||||||
|
MainMenu initialised
|
||||||
|
Main menu created
|
||||||
|
|
||||||
|
And Suddenly! Out of the depths of hell came LEPHISTO!
|
||||||
|
MainMenu deleted
|
||||||
|
Audio shutdown
|
||||||
|
SDL shutdown
|
||||||
|
Shutdown sucessful
|
||||||
|
|
||||||
|
Log Closed: Sun Nov 4 22:08:05 2012
|
||||||
|
|
217
Lephisto.pro
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
QT -= core \
|
||||||
|
gui
|
||||||
|
DESTDIR = build
|
||||||
|
OBJECTS_DIR = src
|
||||||
|
TARGET = Lephisto
|
||||||
|
LIBS += -lGL \
|
||||||
|
-lGLU \
|
||||||
|
-lSDL \
|
||||||
|
-lSDL_image
|
||||||
|
CONFIG += warn_on \
|
||||||
|
x11 \
|
||||||
|
opengl
|
||||||
|
SOURCES += src/Camera.cpp \
|
||||||
|
src/City.cpp \
|
||||||
|
src/CityManager.cpp \
|
||||||
|
src/collisions.cpp \
|
||||||
|
src/Config.cpp \
|
||||||
|
src/EnvironmentObject.cpp \
|
||||||
|
src/extensions.cpp \
|
||||||
|
src/font.cpp \
|
||||||
|
src/Frustum.cpp \
|
||||||
|
src/GameState.cpp \
|
||||||
|
src/image.cpp \
|
||||||
|
src/Log.cpp \
|
||||||
|
src/main.cpp \
|
||||||
|
src/MainMenu.cpp \
|
||||||
|
src/Map.cpp \
|
||||||
|
src/normals.cpp \
|
||||||
|
src/Ocean.cpp \
|
||||||
|
src/Player.cpp \
|
||||||
|
src/Point.cpp \
|
||||||
|
src/QuadBox.cpp \
|
||||||
|
src/QuadNode.cpp \
|
||||||
|
src/StateCity.cpp \
|
||||||
|
src/StateSailing.cpp \
|
||||||
|
src/Terrain.cpp \
|
||||||
|
src/tinyxmlparser.cpp \
|
||||||
|
src/tinyxmlerror.cpp \
|
||||||
|
src/tinyxml.cpp \
|
||||||
|
src/tinystr.cpp \
|
||||||
|
src/Wave.cpp \
|
||||||
|
src/WaveEmitter.cpp \
|
||||||
|
src/BoundBox.cpp \
|
||||||
|
src/Model.cpp \
|
||||||
|
src/Product.cpp \
|
||||||
|
src/Economy.cpp \
|
||||||
|
src/CityEconomy.cpp \
|
||||||
|
src/SkyBox.cpp \
|
||||||
|
src/Menu.cpp \
|
||||||
|
src/StateBattle.cpp \
|
||||||
|
src/Ships.cpp \
|
||||||
|
src/WaveEmitter.cpp \
|
||||||
|
src/Wave.cpp \
|
||||||
|
src/tinyxmlparser.cpp \
|
||||||
|
src/tinyxmlerror.cpp \
|
||||||
|
src/tinyxml.cpp \
|
||||||
|
src/tinystr.cpp \
|
||||||
|
src/Terrain.cpp \
|
||||||
|
src/StateSailing.cpp \
|
||||||
|
src/StateCity.cpp \
|
||||||
|
src/StateBattle.cpp \
|
||||||
|
src/sound.cpp \
|
||||||
|
src/SkyBox.cpp \
|
||||||
|
src/Ships.cpp \
|
||||||
|
src/QuadNode.cpp \
|
||||||
|
src/QuadBox.cpp \
|
||||||
|
src/Product.cpp \
|
||||||
|
src/Point.cpp \
|
||||||
|
src/Player.cpp \
|
||||||
|
src/Ocean.cpp \
|
||||||
|
src/normals.cpp \
|
||||||
|
src/Model.cpp \
|
||||||
|
src/Menu.cpp \
|
||||||
|
src/Map.cpp \
|
||||||
|
src/MainMenu.cpp \
|
||||||
|
src/main.cpp \
|
||||||
|
src/Log.cpp \
|
||||||
|
src/image.cpp \
|
||||||
|
src/GameState.cpp \
|
||||||
|
src/Frustum.cpp \
|
||||||
|
src/font.cpp \
|
||||||
|
src/extensions.cpp \
|
||||||
|
src/EnvironmentObject.cpp \
|
||||||
|
src/Economy.cpp \
|
||||||
|
src/Config.cpp \
|
||||||
|
src/collisions.cpp \
|
||||||
|
src/CityManager.cpp \
|
||||||
|
src/CityEconomy.cpp \
|
||||||
|
src/City.cpp \
|
||||||
|
src/Camera.cpp \
|
||||||
|
src/BoundBox.cpp \
|
||||||
|
src/sound.cpp \
|
||||||
|
src/Menu/MenuContainer.cpp \
|
||||||
|
src/Menu/DataContainer.cpp \
|
||||||
|
src/Menu/Button.cpp \
|
||||||
|
src/StateBattle/Bullet.cpp \
|
||||||
|
src/SoundStream.cpp \
|
||||||
|
src/Cargo.cpp
|
||||||
|
HEADERS += src/Camera.h \
|
||||||
|
src/ccmath.h \
|
||||||
|
src/City.h \
|
||||||
|
src/CityManager.h \
|
||||||
|
src/collisions.h \
|
||||||
|
src/Config.h \
|
||||||
|
src/EnvironmentObject.h \
|
||||||
|
src/extensions.h \
|
||||||
|
src/font.h \
|
||||||
|
src/Frustum.h \
|
||||||
|
src/GameState.h \
|
||||||
|
src/image.h \
|
||||||
|
src/Log.h \
|
||||||
|
src/MainMenu.h \
|
||||||
|
src/Map.h \
|
||||||
|
src/normals.h \
|
||||||
|
src/Ocean.h \
|
||||||
|
src/Player.h \
|
||||||
|
src/Point.h \
|
||||||
|
src/QuadBox.h \
|
||||||
|
src/QuadNode.h \
|
||||||
|
src/StateCity.h \
|
||||||
|
src/StateSailing.h \
|
||||||
|
src/Terrain.h \
|
||||||
|
src/tinyxml.h \
|
||||||
|
src/Wave.h \
|
||||||
|
src/WaveEmitter.h \
|
||||||
|
src/BoundBox.h \
|
||||||
|
src/Model.h \
|
||||||
|
src/Product.h \
|
||||||
|
src/Callback.h \
|
||||||
|
src/Economy.h \
|
||||||
|
src/CityEconomy.h \
|
||||||
|
src/SkyBox.h \
|
||||||
|
src/Menu.h \
|
||||||
|
src/StateBattle.h \
|
||||||
|
src/Ships.h \
|
||||||
|
src/WaveEmitter.h \
|
||||||
|
src/Wave.h \
|
||||||
|
src/tinyxml.h \
|
||||||
|
src/tinystr.h \
|
||||||
|
src/Terrain.h \
|
||||||
|
src/StateSailing.h \
|
||||||
|
src/StateCity.h \
|
||||||
|
src/StateBattle.h \
|
||||||
|
src/sound.h \
|
||||||
|
src/SkyBox.h \
|
||||||
|
src/Ships.h \
|
||||||
|
src/QuadNode.h \
|
||||||
|
src/QuadBox.h \
|
||||||
|
src/Product.h \
|
||||||
|
src/Point.h \
|
||||||
|
src/Player.h \
|
||||||
|
src/Ocean.h \
|
||||||
|
src/normals.h \
|
||||||
|
src/Model.h \
|
||||||
|
src/Menu.h \
|
||||||
|
src/Map.h \
|
||||||
|
src/MainMenu.h \
|
||||||
|
src/Log.h \
|
||||||
|
src/image.h \
|
||||||
|
src/GameState.h \
|
||||||
|
src/Frustum.h \
|
||||||
|
src/font.h \
|
||||||
|
src/extensions.h \
|
||||||
|
src/EnvironmentObject.h \
|
||||||
|
src/Economy.h \
|
||||||
|
src/Config.h \
|
||||||
|
src/collisions.h \
|
||||||
|
src/CityManager.h \
|
||||||
|
src/CityEconomy.h \
|
||||||
|
src/City.h \
|
||||||
|
src/ccmath.h \
|
||||||
|
src/Camera.h \
|
||||||
|
src/Callback.h \
|
||||||
|
src/BoundBox.h \
|
||||||
|
src/sound.h \
|
||||||
|
src/Menu/MenuContainer.h \
|
||||||
|
src/Menu/DataContainer.h \
|
||||||
|
src/Menu/Button.h \
|
||||||
|
src/StateBattle/Bullet.h \
|
||||||
|
src/SoundStream.h \
|
||||||
|
src/Cargo.h
|
||||||
|
OTHER_FILES += build/data/background.png \
|
||||||
|
build/data/background.psd \
|
||||||
|
build/data/city.png \
|
||||||
|
build/data/detail.png \
|
||||||
|
build/data/font.png \
|
||||||
|
build/data/land.png \
|
||||||
|
build/data/loading \
|
||||||
|
page.psd \
|
||||||
|
build/data/loading.png \
|
||||||
|
build/data/map.png \
|
||||||
|
build/data/mapscreen.png \
|
||||||
|
build/data/SaraCraft.conf \
|
||||||
|
build/data/ship.vtx \
|
||||||
|
build/data/water.png \
|
||||||
|
src/QuadNode.o \
|
||||||
|
src/QuadBox.o \
|
||||||
|
src/Point.o \
|
||||||
|
src/Player.o \
|
||||||
|
src/Ocean.o \
|
||||||
|
src/normals.o \
|
||||||
|
src/Map.o \
|
||||||
|
src/Makefile \
|
||||||
|
src/MainMenu.o \
|
||||||
|
src/main.o \
|
||||||
|
src/Log.o \
|
||||||
|
src/image.o \
|
||||||
|
src/GameState.o \
|
||||||
|
src/Frustum.o \
|
||||||
|
src/font.o \
|
||||||
|
src/extensions.o \
|
||||||
|
src/EnvironmentObject.o \
|
||||||
|
src/Config.o \
|
||||||
|
src/collisions.o \
|
||||||
|
src/CityManager.o \
|
||||||
|
src/City.o \
|
||||||
|
src/Camera.o
|
87
README
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
Lephisto : SaraCraft Studio's
|
||||||
|
|
||||||
|
SaraCraft is looking to produce a 3D RPG, similar to http://pirates.wikia.com/wiki/Pirates_of_the_Caribbean_%28game%29
|
||||||
|
It is simultaneously being developed in Linux and Windows, with a strong emphasis on cross-platform compatability.
|
||||||
|
The project is still early on in development, although it is just beginning to look like an actual game.
|
||||||
|
|
||||||
|
I have added audio in this release using Ogg Vorbis files and OpenAL. Music is streamed off of the disk,
|
||||||
|
while the sound effects are loaded directly into memory.
|
||||||
|
I still have some tweaking to do, and currently do not take advantage of OpenAL's 3d capabilities.
|
||||||
|
|
||||||
|
We have fairly complete naval battles now.
|
||||||
|
Players periodically see ships and have the choice to investigate further or sail away.
|
||||||
|
After the battle (assuming victory), the player may take the captured cargo.
|
||||||
|
More work will be done as I add additional gameplay features such as nationalities and ship crews.
|
||||||
|
|
||||||
|
Basic trading capabilities are present now. You can now buy and sell goods in towns,
|
||||||
|
as well as capture cargo in naval battles.
|
||||||
|
I am making progress towards a more functional (and dynamic) economy.
|
||||||
|
|
||||||
|
In order to allow for the trading and the naval battles, I reworked how ships are handled and added a few new ships.
|
||||||
|
art is complimentary of a good friend of mine: Maja.
|
||||||
|
|
||||||
|
Our menu system has been reworked to make creating menus easier for the developers. It also now allows for mouse input.
|
||||||
|
Someone will still bitch at me.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Once Maja provided the new model, I had to rewrite the model loading code so we could use it.
|
||||||
|
The new code is somewhat of a hybrid between the old system and what is planned for the future.
|
||||||
|
For now it still uses display lists, although I may move towards VA/VBO's in the future.
|
||||||
|
Eventually, I'll probably write my own model format, like .scm (saracraft model) but for now it just loads .obj files.
|
||||||
|
|
||||||
|
There is a new automatic menu generation system, so we don't have to recode a basic menu everytime we need
|
||||||
|
to create a new menu in for the game. Rather than copying and pasting code, we can now just pass this menu
|
||||||
|
class a few lists and it will generate the menus automatically, cool huh?
|
||||||
|
|
||||||
|
The ocean rendering has been updated.
|
||||||
|
The actual shore line no longer moves, which will allow us to improve the heightmap,
|
||||||
|
since low elevation land won't spend half of the time underwater.
|
||||||
|
There are also waves breaking on the shore lines.
|
||||||
|
The actual wave motion may change some, but the effect is pretty good in general.
|
||||||
|
(Thanks to someone in ES IRC for noting that it was not too great, can not remember who)
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
SDL library
|
||||||
|
SDL_image library
|
||||||
|
video card capable of multi-texturing
|
||||||
|
|
||||||
|
Config.xml:
|
||||||
|
This is the configuration file.
|
||||||
|
It is now fairly straight-forward xml, loaded with the tinyxml library.
|
||||||
|
The Width and Height values should be integers and they determine the resolution of the window.
|
||||||
|
Fullscreen should be either "true" or "false" and change whether Lephisto runs fullscreen or in a window.
|
||||||
|
VBO should also be either "true" or "false" and specifies whether to use VBOs to draw the terrain or just vertex arrays.
|
||||||
|
If VBOs are enabled, but not supported by the video card, Lephisto logs a warning and falls back on vertex arrays.
|
||||||
|
The configuration loading code is now much more flexible, simpler, and more robust.
|
||||||
|
The SDLParachute should be set to "true" unless you are trying to get a core dump for debugging
|
||||||
|
(then set it to "false"). CompressTextures enables ("true") or disables ("false") compressing the textures when
|
||||||
|
they are stored in video memory. Almost everyone should be able to enable this setting, but if you have trouble,
|
||||||
|
you can try disabling compressed textures.
|
||||||
|
|
||||||
|
Game Controls:
|
||||||
|
up - speed up
|
||||||
|
down - slow down
|
||||||
|
left - turn left
|
||||||
|
right - turn right
|
||||||
|
'm' - display the map
|
||||||
|
'q' - Fire port (left) cannons (in naval battles)
|
||||||
|
'e' - Fire starboard (right) cannons (in naval batles)
|
||||||
|
'c' - abrupt turn-around (for testing)
|
||||||
|
'd' - dump player info (for testing)
|
||||||
|
'z' - take screenshot
|
||||||
|
esc - go to the menu
|
||||||
|
|
||||||
|
When looking at the map, hold 't' and click the mouse to teleport to that location.
|
||||||
|
This is just a development feature, but it sure is useful for testing. Also, 'i' will display some debugging information.
|
||||||
|
|
||||||
|
Known issues:
|
||||||
|
- Errors loading files are not handled gracefully
|
||||||
|
- Some Cities are difficult or impossible to enter
|
||||||
|
- Closing the game window directly (without choosing "Exit" from the main menu) can cause crashes
|
||||||
|
|
||||||
|
Developers:
|
||||||
|
Allanis
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
VLack
|
@ -1,4 +0,0 @@
|
|||||||
ShipWreck
|
|
||||||
=========
|
|
||||||
|
|
||||||
Old Lephisto project from 2009/2010. Simply storing it here for coderot.
|
|
10
build/Config.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<GameConfiguration>
|
||||||
|
<Resolution>
|
||||||
|
<Width>800</Width>
|
||||||
|
<Height>600</Height>
|
||||||
|
</Resolution>
|
||||||
|
<Fullscreen>false</Fullscreen>
|
||||||
|
<VBO>false</VBO>
|
||||||
|
<SDLParachute>true</SDLParachute>
|
||||||
|
</GameConfiguration>
|
||||||
|
|
27
build/Makefile
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
CC = g++
|
||||||
|
CFLAGS = -ansi -Wall -g
|
||||||
|
LDADD = -lGL -lGLU -lpthread -lSDL -lSDL_image -lopenal -lalut -lvorbisfile -L/usr/X11
|
||||||
|
LDADDSTATIC = -Wl,-Bstatic -lSDL -lSDL_image -lopenal -lalut -L/usr/X11 -Wl,-Bdynamic -lasound -lartsc -lesd -lpulse -lpulse-simple -ldirectfb -lvga -laa -lcaca -ljpeg -ltiff -lpthread -lGL -lGLU -Wl,-Bdynamic
|
||||||
|
|
||||||
|
.PHONY: default static all clean
|
||||||
|
|
||||||
|
default: all
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(MAKE) -C ../src/Menu
|
||||||
|
$(MAKE) -C ../src/StateBattle
|
||||||
|
$(MAKE) -C ../src
|
||||||
|
$(CC) $(CFLAGS) -o Lephisto ../src/main.cpp ../src/Menu/*.o ../src/StateBattle/*.o ../src/*.o $(LDADD)
|
||||||
|
|
||||||
|
static:
|
||||||
|
@echo -e "\033[1;31mThis is an experimental build, if it does not work, don't complain...\033[0m"
|
||||||
|
@sleep 1
|
||||||
|
$(MAKE) -C ../src/Menu
|
||||||
|
$(MAKE) -C ../src
|
||||||
|
$(CC) $(CFLAGS) -o build/Lephisto-static ../src/main.cpp ../src/Menu/*.o ../src/StateBattle/*.o ../src/*.o $(LDADDSTATIC)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C ../src/Menu clean
|
||||||
|
$(MAKE) -C ../src/StateBattle clean
|
||||||
|
$(MAKE) -C ../src clean
|
||||||
|
rm -f Lephisto Lephisto.log
|
BIN
build/SDL.dll
Normal file
BIN
build/SDL_image.dll
Normal file
100
build/data/City.xml
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" standalone=no>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City1</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-110</x>
|
||||||
|
<z>-92</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City2</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-86</x>
|
||||||
|
<z>-228</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City3</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-38</x>
|
||||||
|
<z>-162</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City4</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-375</x>
|
||||||
|
<z>-21</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City5</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-315</x>
|
||||||
|
<z>0</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City6</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>-277</x>
|
||||||
|
<z>-28</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City7</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>236</x>
|
||||||
|
<z>-235</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City8</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>18</x>
|
||||||
|
<z>-20</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City9</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>77</x>
|
||||||
|
<z>-25</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City10</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>4</x>
|
||||||
|
<z>25</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<name>City11</name>
|
||||||
|
<visible>TRUE</visible>
|
||||||
|
<location>
|
||||||
|
<x>87</x>
|
||||||
|
<z>-18</z>
|
||||||
|
</location>
|
||||||
|
</object>
|
263
build/data/Product.xml
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
<?xml version="1.0" standalone=no>
|
||||||
|
|
||||||
|
<Economy>
|
||||||
|
<City name="City1">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
<City name="City2">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City3">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City4">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City5">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City6">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City7">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City8">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City9">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City10">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
<City name="City11">
|
||||||
|
<Product>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Value>5</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Value>10</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Value>7</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
<Product>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
<Value>20</Value>
|
||||||
|
<Demand>1</Demand>
|
||||||
|
</Product>
|
||||||
|
</City>
|
||||||
|
|
||||||
|
</Economy>
|
||||||
|
|
||||||
|
<Products>
|
||||||
|
<Name>Sugar</Name>
|
||||||
|
<Name>Cocoa</Name>
|
||||||
|
<Name>Rum</Name>
|
||||||
|
<Name>Tobacco</Name>
|
||||||
|
</Products>
|
32
build/data/Ships.xml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<Ship>
|
||||||
|
<Name>Sloop</Name>
|
||||||
|
<Model>./data/Ships/sloop.obj</Model>
|
||||||
|
<Texture>./data/Ships/sloop.png</Texture>
|
||||||
|
<Scale>1</Scale>
|
||||||
|
<Damage>10</Damage>
|
||||||
|
<CargoSize>100</CargoSize>
|
||||||
|
</Ship>
|
||||||
|
<Ship>
|
||||||
|
<Name>Fluyt</Name>
|
||||||
|
<Model>./data/Ships/fluyt.obj</Model>
|
||||||
|
<Texture>./data/Ships/fluyt.png</Texture>
|
||||||
|
<Scale>.32</Scale>
|
||||||
|
<Damage>10</Damage>
|
||||||
|
<CargoSize>100</CargoSize>
|
||||||
|
</Ship>
|
||||||
|
<Ship>
|
||||||
|
<Name>Brig</Name>
|
||||||
|
<Model>./data/Ships/brig.obj</Model>
|
||||||
|
<Texture>./data/Ships/brig.png</Texture>
|
||||||
|
<Scale>.32</Scale>
|
||||||
|
<Damage>10</Damage>
|
||||||
|
<CargoSize>100</CargoSize>
|
||||||
|
</Ship>
|
||||||
|
<Ship>
|
||||||
|
<Name>Schooner</Name>
|
||||||
|
<Model>./data/Ships/schooner.obj</Model>
|
||||||
|
<Texture>./data/Ships/schooner.png</Texture>
|
||||||
|
<Scale>.32</Scale>
|
||||||
|
<Damage>10</Damage>
|
||||||
|
<CargoSize>100</CargoSize>
|
||||||
|
</Ship>
|
7475
build/data/Ships/brig.obj
Normal file
BIN
build/data/Ships/brig.png
Normal file
After Width: | Height: | Size: 24 KiB |
5943
build/data/Ships/fluyt.obj
Normal file
BIN
build/data/Ships/fluyt.png
Normal file
After Width: | Height: | Size: 70 KiB |
6101
build/data/Ships/schooner.obj
Normal file
BIN
build/data/Ships/schooner.png
Normal file
After Width: | Height: | Size: 55 KiB |
2623
build/data/Ships/sloop.obj
Normal file
BIN
build/data/Ships/sloop.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
build/data/background.png
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
build/data/background.psd
Normal file
BIN
build/data/battledefeat.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
build/data/battlesuccess.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
build/data/battletie.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
build/data/city.png
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
build/data/detail.png
Normal file
After Width: | Height: | Size: 287 KiB |
BIN
build/data/enterbattle.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
build/data/font.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
build/data/heightmap.png
Normal file
After Width: | Height: | Size: 161 KiB |
BIN
build/data/hit.ogg
Normal file
BIN
build/data/land.png
Normal file
After Width: | Height: | Size: 1008 KiB |
BIN
build/data/loading page.psd
Normal file
BIN
build/data/loading.png
Normal file
After Width: | Height: | Size: 375 KiB |
BIN
build/data/mapscreen.png
Normal file
After Width: | Height: | Size: 338 KiB |
418
build/data/ship.vtx
Normal file
@ -0,0 +1,418 @@
|
|||||||
|
# Ship model made for the SaraCraft team
|
||||||
|
# by Marty - T2G Student
|
||||||
|
|
||||||
|
S .025 .0225 .03
|
||||||
|
T 20 0 0
|
||||||
|
|
||||||
|
M 0.8 0.5 0.0 1.0
|
||||||
|
|
||||||
|
B q
|
||||||
|
# Main Mast
|
||||||
|
|
||||||
|
N 0 0.0107137 0.999943
|
||||||
|
-10 13 1.25
|
||||||
|
-7 13 1.25
|
||||||
|
-8 123 .5
|
||||||
|
-9 123 .5
|
||||||
|
|
||||||
|
N 0 0.0107137 -0.999943
|
||||||
|
-10 13 -1.25
|
||||||
|
-9 123 -.5
|
||||||
|
-8 123 -.5
|
||||||
|
-7 13 -1.25
|
||||||
|
|
||||||
|
N -0.999943 0.0107137 0
|
||||||
|
-10 13 -1.25
|
||||||
|
-10 13 1.25
|
||||||
|
-9 123 .5
|
||||||
|
-9 123 -.5
|
||||||
|
|
||||||
|
N 0.999943 0.0107137 0
|
||||||
|
-7 13 1.25
|
||||||
|
-7 13 -1.25
|
||||||
|
-8 123 -.5
|
||||||
|
-8 123 .5
|
||||||
|
|
||||||
|
N 0 1 0
|
||||||
|
-9 123 -.5
|
||||||
|
-9 123 .5
|
||||||
|
-8 123 .5
|
||||||
|
-8 123 -.5
|
||||||
|
|
||||||
|
# Back Mast
|
||||||
|
N 0 0.0095886 0.999954
|
||||||
|
29 20 1
|
||||||
|
31 20 1
|
||||||
|
30.5 93 .3
|
||||||
|
29.5 93 .3
|
||||||
|
|
||||||
|
N 0 0.0095886 -0.999954
|
||||||
|
31 20 -1
|
||||||
|
29 20 -1
|
||||||
|
29.5 93 -.3
|
||||||
|
30.5 93 -.3
|
||||||
|
|
||||||
|
N 0.999977 0.00684915 0
|
||||||
|
31 20 1
|
||||||
|
31 20 -1
|
||||||
|
30.5 93 -.3
|
||||||
|
30.5 93 .3
|
||||||
|
|
||||||
|
N -0.999977 0.00684915 0
|
||||||
|
29 20 -1
|
||||||
|
29 20 1
|
||||||
|
29.5 93 .3
|
||||||
|
29.5 93 -.3
|
||||||
|
|
||||||
|
N 0 1 0
|
||||||
|
29.5 93 -.3
|
||||||
|
29.5 93 .3
|
||||||
|
30.5 93 .3
|
||||||
|
30.5 93 -.3
|
||||||
|
|
||||||
|
# Front Mast
|
||||||
|
N 0.999984 0.00568173 0
|
||||||
|
-69 20 1
|
||||||
|
-69 20 -1
|
||||||
|
-69.5 103 -.3
|
||||||
|
-69.5 103 .3
|
||||||
|
|
||||||
|
N -0.999984 0.00568173 0
|
||||||
|
-71 20 -1
|
||||||
|
-71 20 1
|
||||||
|
-70.5 103 .3
|
||||||
|
-70.5 103 -.3
|
||||||
|
|
||||||
|
N 0 0.00795429 -0.999968
|
||||||
|
-69 20 -1
|
||||||
|
-71 20 -1
|
||||||
|
-70.5 103 -.3
|
||||||
|
-69.5 103 -.3
|
||||||
|
|
||||||
|
N 0 0.00795429 0.999968
|
||||||
|
-71 20 1
|
||||||
|
-69 20 1
|
||||||
|
-69.5 103 .3
|
||||||
|
-70.5 103 .3
|
||||||
|
|
||||||
|
N 0 1 0
|
||||||
|
-70.5 103 -.3
|
||||||
|
-70.5 103 .3
|
||||||
|
-69.5 103 .3
|
||||||
|
-69.5 103 -.3
|
||||||
|
|
||||||
|
# Front Diag. Mast
|
||||||
|
N -0.267644 -0.963518 0
|
||||||
|
-84 20 -.5
|
||||||
|
-84 20 .5
|
||||||
|
-120 30 .2
|
||||||
|
-120 30 -.2
|
||||||
|
|
||||||
|
N 0.256901 0.966438 0
|
||||||
|
-80 20 .5
|
||||||
|
-80 20 -.5
|
||||||
|
-119.5 30.5 -.2
|
||||||
|
-119.5 30.5 .2
|
||||||
|
|
||||||
|
N 0 0.0285598 0.999592
|
||||||
|
-84 20 .5
|
||||||
|
-80 20 .5
|
||||||
|
-119.5 30.5 .2
|
||||||
|
-120 30 .2
|
||||||
|
|
||||||
|
N 0 0.0299865 -0.99955
|
||||||
|
-80 20 -.5
|
||||||
|
-84 20 -.5
|
||||||
|
-120 30 -.2
|
||||||
|
-119.5 30.5 -.2
|
||||||
|
|
||||||
|
N -0.707107 0.707107 0
|
||||||
|
-119.5 30.5 -.2
|
||||||
|
-120 30 -.2
|
||||||
|
-120 30 .2
|
||||||
|
-119.5 30.5 .2
|
||||||
|
E
|
||||||
|
|
||||||
|
|
||||||
|
# Ship hull
|
||||||
|
B t
|
||||||
|
N 0 1 0
|
||||||
|
-85 20 0
|
||||||
|
-77 20 9
|
||||||
|
-77 20 -9
|
||||||
|
|
||||||
|
-77 20 -9
|
||||||
|
-77 20 9
|
||||||
|
-60 20 12
|
||||||
|
|
||||||
|
-77 20 -9
|
||||||
|
-60 20 12
|
||||||
|
-60 20 -12
|
||||||
|
|
||||||
|
N 0.573462 0.819232 0
|
||||||
|
-60 20 -12
|
||||||
|
-60 20 12
|
||||||
|
-50 13 12
|
||||||
|
|
||||||
|
-60 20 -12
|
||||||
|
-50 13 12
|
||||||
|
-50 13 -12
|
||||||
|
|
||||||
|
N 0 1 0
|
||||||
|
-50 13 -12
|
||||||
|
-50 13 12
|
||||||
|
14 13 12
|
||||||
|
|
||||||
|
-50 13 -12
|
||||||
|
14 13 12
|
||||||
|
14 13 -12
|
||||||
|
|
||||||
|
N -0.759257 0.650791 0
|
||||||
|
14 13 -12
|
||||||
|
14 13 12
|
||||||
|
20 20 15
|
||||||
|
|
||||||
|
14 13 -12
|
||||||
|
20 20 15
|
||||||
|
20 20 -15
|
||||||
|
|
||||||
|
N 0 1 0
|
||||||
|
20 20 -15
|
||||||
|
20 20 15
|
||||||
|
45 20 15
|
||||||
|
|
||||||
|
20 20 -15
|
||||||
|
45 20 15
|
||||||
|
45 20 -15
|
||||||
|
|
||||||
|
N 0.961524 -0.274721 0
|
||||||
|
45 20 -15
|
||||||
|
45 20 15
|
||||||
|
43 13 15
|
||||||
|
|
||||||
|
45 20 -15
|
||||||
|
43 13 15
|
||||||
|
43 13 -15
|
||||||
|
|
||||||
|
N 0.447214 -0.894427 0
|
||||||
|
43 13 -15
|
||||||
|
43 13 15
|
||||||
|
37 10 12
|
||||||
|
|
||||||
|
43 13 -15
|
||||||
|
37 10 12
|
||||||
|
37 10 -12
|
||||||
|
|
||||||
|
N 0.923077 -0.384615 0
|
||||||
|
37 10 -12
|
||||||
|
37 10 12
|
||||||
|
32 -2 8
|
||||||
|
|
||||||
|
37 10 -12
|
||||||
|
32 -2 8
|
||||||
|
32 -2 -8
|
||||||
|
|
||||||
|
N 0.707107 -0.707107 0
|
||||||
|
32 -2 -8
|
||||||
|
32 -2 8
|
||||||
|
28 -6 0
|
||||||
|
|
||||||
|
N 0 -0.894427 -0.447214
|
||||||
|
32 -2 -8
|
||||||
|
28 -6 0
|
||||||
|
-50 -2 -8
|
||||||
|
|
||||||
|
-50 -2 -8
|
||||||
|
28 -6 0
|
||||||
|
-60 -6 0
|
||||||
|
|
||||||
|
N -0.26479 -0.688455 -0.675215
|
||||||
|
-50 -2 -8
|
||||||
|
-60 -6 0
|
||||||
|
-73 -1 0
|
||||||
|
|
||||||
|
-73 -1 0
|
||||||
|
-60 -6 0
|
||||||
|
-50 -2 8
|
||||||
|
|
||||||
|
N -0.313931 -0.423895 0.849565
|
||||||
|
-73 -1 0
|
||||||
|
-50 -2 8
|
||||||
|
-77 20 9
|
||||||
|
|
||||||
|
N -0.171578 -0.253842 0.951906
|
||||||
|
-77 20 9
|
||||||
|
-50 -2 8
|
||||||
|
-50 13 12
|
||||||
|
|
||||||
|
N -0.168665 -0.24095 0.955769
|
||||||
|
-77 20 9
|
||||||
|
-50 13 12
|
||||||
|
-60 20 12
|
||||||
|
|
||||||
|
N 0 -0.257663 0.966235
|
||||||
|
-50 13 12
|
||||||
|
-50 -2 8
|
||||||
|
14 13 12
|
||||||
|
|
||||||
|
14 13 12
|
||||||
|
-50 -2 8
|
||||||
|
32 -2 8
|
||||||
|
|
||||||
|
N -0.0392886 -0.301212 0.952747
|
||||||
|
14 13 12
|
||||||
|
32 -2 8
|
||||||
|
37 10 12
|
||||||
|
|
||||||
|
N -0.0807866 -0.619364 0.780937
|
||||||
|
37 10 12
|
||||||
|
43 13 15
|
||||||
|
14 13 12
|
||||||
|
|
||||||
|
N 0 0 1
|
||||||
|
20 20 15
|
||||||
|
43 13 15
|
||||||
|
45 20 15
|
||||||
|
|
||||||
|
N -0.0974785 -0.320286 0.942292
|
||||||
|
14 13 12
|
||||||
|
43 13 15
|
||||||
|
20 20 15
|
||||||
|
|
||||||
|
N 0 -0.894427 0.447214
|
||||||
|
32 -2 8
|
||||||
|
-50 -2 8
|
||||||
|
28 -6 0
|
||||||
|
|
||||||
|
28 -6 0
|
||||||
|
-50 -2 8
|
||||||
|
-60 -6 0
|
||||||
|
|
||||||
|
N -0.0807866 -0.619364 -0.780937
|
||||||
|
37 10 -12
|
||||||
|
14 13 -12
|
||||||
|
43 13 -15
|
||||||
|
|
||||||
|
N -0.0974785 -0.320286 -0.942292
|
||||||
|
43 13 -15
|
||||||
|
14 13 -12
|
||||||
|
20 20 -15
|
||||||
|
|
||||||
|
N 0 -0 -1
|
||||||
|
43 13 -15
|
||||||
|
20 20 -15
|
||||||
|
45 20 -15
|
||||||
|
|
||||||
|
N -0.0392886 -0.301212 -0.952747
|
||||||
|
37 10 -12
|
||||||
|
32 -2 -8
|
||||||
|
14 13 -12
|
||||||
|
|
||||||
|
N 0 -0.257663 -0.966235
|
||||||
|
14 13 -12
|
||||||
|
32 -2 -8
|
||||||
|
-50 -2 -8
|
||||||
|
|
||||||
|
14 13 -12
|
||||||
|
-50 -2 -8
|
||||||
|
-50 13 -12
|
||||||
|
|
||||||
|
N -0.171578 -0.253842 -0.951906
|
||||||
|
-50 13 -12
|
||||||
|
-50 -2 -8
|
||||||
|
-77 20 -9
|
||||||
|
|
||||||
|
N -0.168665 -0.24095 -0.955769
|
||||||
|
-50 13 -12
|
||||||
|
-77 20 -9
|
||||||
|
-60 20 -12
|
||||||
|
|
||||||
|
N -0.687345 -0.392769 0.610974
|
||||||
|
-73 -1 0
|
||||||
|
-77 20 9
|
||||||
|
-85 20 0
|
||||||
|
|
||||||
|
N -0.687345 -0.392769 -0.610974
|
||||||
|
-73 -1 0
|
||||||
|
-85 20 0
|
||||||
|
-77 20 -9
|
||||||
|
|
||||||
|
N -0.313931 -0.423895 -0.849565
|
||||||
|
-73 -1 0
|
||||||
|
-77 20 -9
|
||||||
|
-50 -2 -8
|
||||||
|
|
||||||
|
|
||||||
|
# Sails
|
||||||
|
M 0.8 0.8 0.8 1.0
|
||||||
|
|
||||||
|
N -0.933346 0.358979 0
|
||||||
|
-10 103 15
|
||||||
|
-10 103 -15
|
||||||
|
-15 90 -7.5
|
||||||
|
|
||||||
|
N -0.971324 0.220755 0.0883022
|
||||||
|
-10 103 15
|
||||||
|
-15 90 -7.5
|
||||||
|
-15 83 10
|
||||||
|
|
||||||
|
N -1 0 0
|
||||||
|
-15 90 -7.5
|
||||||
|
-15 83 -10
|
||||||
|
-15 83 10
|
||||||
|
|
||||||
|
N -1 0 0
|
||||||
|
-15 76 7.5
|
||||||
|
-15 83 10
|
||||||
|
-15 83 -10
|
||||||
|
|
||||||
|
N -0.971324 -0.220755 -0.0883022
|
||||||
|
-10 63 -15
|
||||||
|
-15 76 7.5
|
||||||
|
-15 83 -10
|
||||||
|
|
||||||
|
N -0.933346 -0.358979 0
|
||||||
|
-15 76 7.5
|
||||||
|
-10 63 -15
|
||||||
|
-10 63 15
|
||||||
|
|
||||||
|
N -0.916246 0.134742 -0.377278
|
||||||
|
-10 103 -15
|
||||||
|
-15 83 -10
|
||||||
|
-15 90 -7.5
|
||||||
|
|
||||||
|
N -0.707107 0 -0.707107
|
||||||
|
-10 103 -15
|
||||||
|
-10 63 -15
|
||||||
|
-15 83 -10
|
||||||
|
|
||||||
|
N -0.916246 -0.134742 0.377278
|
||||||
|
-10 63 15
|
||||||
|
-15 83 10
|
||||||
|
-15 76 7.5
|
||||||
|
|
||||||
|
N -0.83205 0 0.5547
|
||||||
|
-10 63 15
|
||||||
|
-10 103 15
|
||||||
|
-15 83 10
|
||||||
|
|
||||||
|
-10.5 60 20
|
||||||
|
-10.5 60 -20
|
||||||
|
-10.5 23 -20
|
||||||
|
|
||||||
|
-10.5 60 20
|
||||||
|
-10.5 23 -20
|
||||||
|
-10.5 23 20
|
||||||
|
|
||||||
|
E
|
||||||
|
|
||||||
|
# Ropes
|
||||||
|
B L
|
||||||
|
N 0 -1 0
|
||||||
|
-119.5 30.5 0
|
||||||
|
-70 103 0
|
||||||
|
-8.5 123 0
|
||||||
|
30 93 0
|
||||||
|
45 20 0
|
||||||
|
|
||||||
|
E
|
BIN
build/data/skybox1/BK.png
Normal file
After Width: | Height: | Size: 1.1 MiB |
BIN
build/data/skybox1/DN.png
Normal file
After Width: | Height: | Size: 600 KiB |
BIN
build/data/skybox1/FT.png
Normal file
After Width: | Height: | Size: 1.1 MiB |
BIN
build/data/skybox1/LT.png
Normal file
After Width: | Height: | Size: 795 KiB |
BIN
build/data/skybox1/RT.png
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
build/data/skybox1/UP.png
Normal file
After Width: | Height: | Size: 392 KiB |
BIN
build/data/surf.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
build/data/title.ogg
Normal file
BIN
build/data/title.png
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
build/data/water.png
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
build/jpeg.dll
Normal file
BIN
build/libpng12-0.dll
Normal file
BIN
build/libtiff-3.dll
Normal file
BIN
build/zlib1.dll
Normal file
119
src/BoundBox.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include "BoundBox.h"
|
||||||
|
#include "Point.h"
|
||||||
|
|
||||||
|
BoundBox::BoundBox() {
|
||||||
|
b1 = NULL;
|
||||||
|
b2 = NULL;
|
||||||
|
b3 = NULL;
|
||||||
|
b4 = NULL;
|
||||||
|
|
||||||
|
t1 = NULL;
|
||||||
|
t2 = NULL;
|
||||||
|
t3 = NULL;
|
||||||
|
t4 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundBox::BoundBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) {
|
||||||
|
b1 = new Point(minX, minY, minZ);
|
||||||
|
b2 = new Point(maxX, minY, minZ);
|
||||||
|
b3 = new Point(minX, minY, maxZ);
|
||||||
|
b4 = new Point(maxX, minY, maxZ);
|
||||||
|
|
||||||
|
t1 = new Point(minX, maxY, minZ);
|
||||||
|
t2 = new Point(maxX, maxY, minZ);
|
||||||
|
t3 = new Point(minX, maxY, maxZ);
|
||||||
|
t4 = new Point(maxX, maxY, maxZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundBox::~BoundBox() {
|
||||||
|
delete b1;
|
||||||
|
delete b2;
|
||||||
|
delete b3;
|
||||||
|
delete b4;
|
||||||
|
|
||||||
|
delete t1;
|
||||||
|
delete t2;
|
||||||
|
delete t3;
|
||||||
|
delete t4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoundBox::setHeight(GLfloat low, GLfloat high) {
|
||||||
|
if ((b1 == NULL) || (b2 == NULL) || (b3 == NULL) || (b4 == NULL)) {
|
||||||
|
printf("NULL!\n");
|
||||||
|
}
|
||||||
|
b1->y = low;
|
||||||
|
b2->y = low;
|
||||||
|
b3->y = low;
|
||||||
|
b4->y = low;
|
||||||
|
|
||||||
|
t1 = new Point(b1->x, high, b1->z);
|
||||||
|
t2 = new Point(b2->x, high, b2->z);
|
||||||
|
t3 = new Point(b3->x, high, b3->z);
|
||||||
|
t4 = new Point(b4->x, high, b4->z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoundBox::draw() {
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glNormal3f(0, 1, 0);
|
||||||
|
b1->draw();
|
||||||
|
b2->draw();
|
||||||
|
|
||||||
|
b2->draw();
|
||||||
|
b4->draw();
|
||||||
|
|
||||||
|
b4->draw();
|
||||||
|
b3->draw();
|
||||||
|
|
||||||
|
b3->draw();
|
||||||
|
b1->draw();
|
||||||
|
|
||||||
|
b1->draw();
|
||||||
|
t1->draw();
|
||||||
|
|
||||||
|
b2->draw();
|
||||||
|
t2->draw();
|
||||||
|
|
||||||
|
b3->draw();
|
||||||
|
t3->draw();
|
||||||
|
|
||||||
|
b4->draw();
|
||||||
|
t4->draw();
|
||||||
|
|
||||||
|
t1->draw();
|
||||||
|
t2->draw();
|
||||||
|
|
||||||
|
t2->draw();
|
||||||
|
t4->draw();
|
||||||
|
|
||||||
|
t4->draw();
|
||||||
|
t3->draw();
|
||||||
|
|
||||||
|
t3->draw();
|
||||||
|
t1->draw();
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoundBox::dump() {
|
||||||
|
b1->dump();
|
||||||
|
b2->dump();
|
||||||
|
b3->dump();
|
||||||
|
b4->dump();
|
||||||
|
|
||||||
|
t1->dump();
|
||||||
|
t2->dump();
|
||||||
|
t3->dump();
|
||||||
|
t4->dump();
|
||||||
|
printf("\n");
|
||||||
|
}
|
32
src/BoundBox.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOUNDBOX_H_
|
||||||
|
#define _BOUNDBOX_H_
|
||||||
|
|
||||||
|
class Point;
|
||||||
|
|
||||||
|
class BoundBox {
|
||||||
|
public:
|
||||||
|
// Contructor
|
||||||
|
BoundBox();
|
||||||
|
|
||||||
|
// Pass in max/min x/y/z
|
||||||
|
BoundBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~BoundBox();
|
||||||
|
|
||||||
|
Point *b1, *b2, *b3, *b4;
|
||||||
|
Point *t1, *t2, *t3, *t4;
|
||||||
|
|
||||||
|
void setHeight(GLfloat low, GLfloat high);
|
||||||
|
|
||||||
|
// Debuggind purposes :)
|
||||||
|
void draw();
|
||||||
|
void dump();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
41
src/Callback.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* Callback function class
|
||||||
|
* Borrowed from CodeGuru.com : Modyified by Allanis
|
||||||
|
* http://www.codeguru.com/Cpp/Cpp/cpp_mfc/callbacks/article.php/c4129/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CCALLBACK_H_
|
||||||
|
|
||||||
|
#define _CCALLBACK_H_
|
||||||
|
|
||||||
|
class cCallback {
|
||||||
|
public:
|
||||||
|
virtual void Execute(int ButtonID) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class cInstance>
|
||||||
|
|
||||||
|
class TCallback : public cCallback {
|
||||||
|
public:
|
||||||
|
TCallback() { pFunction = 0; }
|
||||||
|
|
||||||
|
typedef void (cInstance::*tFunction)(int Param);
|
||||||
|
|
||||||
|
virtual void Execute(int ButtonID) const {
|
||||||
|
if (pFunction) (cInst->*pFunction)(ButtonID);
|
||||||
|
else printf("ERROR : the callback function has not been defined !!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCallback (cInstance *cInstancePointer,
|
||||||
|
tFunction pFunctionPointer) {
|
||||||
|
cInst = cInstancePointer;
|
||||||
|
pFunction = pFunctionPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
cInstance *cInst;
|
||||||
|
tFunction pFunction;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
99
src/Camera.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "ccmath.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#if !defined (MSVC6)
|
||||||
|
using namespace std;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Camera::Camera(float winRatio, float x, float y, float z) {
|
||||||
|
changeRatio(winRatio);
|
||||||
|
|
||||||
|
// Set the camera position
|
||||||
|
setPosCalcAngle(x, y, z);
|
||||||
|
|
||||||
|
//calcValues();
|
||||||
|
|
||||||
|
//setProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::setPosition(float x, float y, float z) {
|
||||||
|
position[0] = x;
|
||||||
|
position[1] = y;
|
||||||
|
position[2] = z;
|
||||||
|
|
||||||
|
setCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::setPosCalcAngle(float x, float y, float z) {
|
||||||
|
position[0] = x;
|
||||||
|
position[1] = y;
|
||||||
|
position[2] = z;
|
||||||
|
|
||||||
|
calcValues();
|
||||||
|
setCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::changeRatio(float winRatio) {
|
||||||
|
ratio = winRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::setProjection() {
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluPerspective(60.0, ratio, 1.0, 512.0);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::calcValues() {
|
||||||
|
angle = radiansToDegrees(atan2(position[1], abs(position[0])));
|
||||||
|
angle2 = (180.0/M_PI)*atan2(position[0], position[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::setCamera() {
|
||||||
|
//OOOOOH, we DID set it for good... set it away wherever it was dropped, so randomly :P
|
||||||
|
// This should stop it from bitching at us.
|
||||||
|
setProjection();
|
||||||
|
|
||||||
|
glRotatef(angle, 1.0, 0.0, 0.0);
|
||||||
|
glRotatef(angle2, 0.0, 1.0, 0.0);
|
||||||
|
glTranslatef(position[0], -1*position[1], -1*position[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::setAngle(float a1,float a2) {
|
||||||
|
angle = a1;
|
||||||
|
angle2 = a2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::changeAngle(float da1,float da2) {
|
||||||
|
angle += da1;
|
||||||
|
angle2 += da2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::changePosition(float dx,float dy,float dz) {
|
||||||
|
this->position[0] += dx;
|
||||||
|
this->position[1] += dy;
|
||||||
|
this->position[2] += dz;
|
||||||
|
|
||||||
|
setCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::getPosition(vec3 &ret) {
|
||||||
|
ret[0] = this->position[0];
|
||||||
|
ret[1] = this->position[1];
|
||||||
|
ret[2] = this->position[2];
|
||||||
|
}
|
45
src/Camera.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CAMERA_H_
|
||||||
|
#define _CAMERA_H_
|
||||||
|
|
||||||
|
typedef float vec3[3];
|
||||||
|
|
||||||
|
class Camera {
|
||||||
|
public:
|
||||||
|
// Contructor, pass in window width & height
|
||||||
|
Camera(float winRatio, float x, float y, float z);
|
||||||
|
|
||||||
|
// Set the camera location
|
||||||
|
void setPosition(float x, float y, float z);
|
||||||
|
void setPosCalcAngle(float x,float y,float z);
|
||||||
|
|
||||||
|
void changePosition(float dx,float dy,float dz);
|
||||||
|
|
||||||
|
void getPosition(vec3& ret);
|
||||||
|
|
||||||
|
// Update the ratio
|
||||||
|
void changeRatio(float winRatio);
|
||||||
|
|
||||||
|
// Set the projection matrix
|
||||||
|
void setProjection();
|
||||||
|
|
||||||
|
void setCamera();
|
||||||
|
|
||||||
|
void setAngle(float a1,float a2);
|
||||||
|
void changeAngle(float da1,float da2);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Calculate the dist, angles based on position
|
||||||
|
void calcValues();
|
||||||
|
|
||||||
|
float ratio;
|
||||||
|
float angle;
|
||||||
|
float angle2;
|
||||||
|
vec3 position;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
125
src/Cargo.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "Log.h"
|
||||||
|
#include "ccmath.h"
|
||||||
|
#include "Economy.h"
|
||||||
|
#include "Cargo.h"
|
||||||
|
|
||||||
|
Cargo::Cargo(string nameIn, unsigned int sizeIn) {
|
||||||
|
size = sizeIn;
|
||||||
|
filled = 0;
|
||||||
|
name = nameIn;
|
||||||
|
|
||||||
|
products.resize(Economy::Econ->ProductCount());
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < products.size(); i++) {
|
||||||
|
products[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cargo::~Cargo() {
|
||||||
|
// Nothing realy needs to happen here
|
||||||
|
products.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Cargo::getFilled() {
|
||||||
|
return filled;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Cargo::getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cargo::setSize(unsigned int sizeIn) {
|
||||||
|
size = sizeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Cargo::getAvailQty() {
|
||||||
|
return size - filled;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Cargo::getQty(unsigned int product) throw ( const char *) {
|
||||||
|
if(product >= products.size()) {
|
||||||
|
throw "Invalid product";
|
||||||
|
}
|
||||||
|
|
||||||
|
return products[product];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cargo::setQty(unsigned int product, unsigned int qty) throw ( const char *) {
|
||||||
|
unsigned int oldQty;
|
||||||
|
|
||||||
|
if(product >= products.size()) {
|
||||||
|
throw "Invalid product";
|
||||||
|
}
|
||||||
|
|
||||||
|
oldQty = products[product];
|
||||||
|
products[product] = qty;
|
||||||
|
|
||||||
|
filled = filled + (qty - oldQty);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Cargo::addQty(unsigned int product, int qty) throw ( const char *) {
|
||||||
|
if(product >= products.size()) {
|
||||||
|
throw "Invalid product";
|
||||||
|
}
|
||||||
|
if((qty < 0 && (-1*qty > products[product]))) {
|
||||||
|
throw "Result would be negative";
|
||||||
|
}
|
||||||
|
|
||||||
|
products[product] = products[product] + qty;
|
||||||
|
filled += qty;
|
||||||
|
|
||||||
|
return products[product];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cargo::fillRandom() throw ( const char*) {
|
||||||
|
fillRandom((int) (size * randBellCurve()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cargo::fillRandom(unsigned int qty) throw(const char *) {
|
||||||
|
unsigned int avgQty;
|
||||||
|
unsigned int tempQty;
|
||||||
|
|
||||||
|
if(qty > size) {
|
||||||
|
throw "Qty greater than size";
|
||||||
|
}
|
||||||
|
|
||||||
|
avgQty = qty / products.size();
|
||||||
|
Log::logger->message("AvgQty: %u", avgQty);
|
||||||
|
|
||||||
|
// Loop through all but last
|
||||||
|
for(unsigned int i = 0; i < (products.size() - 1); i++) {
|
||||||
|
tempQty = (int) ((randBellCurve() + .5) * avgQty);
|
||||||
|
if(tempQty > getAvailQty()) {
|
||||||
|
tempQty = getAvailQty();
|
||||||
|
}
|
||||||
|
|
||||||
|
products[i] = tempQty;
|
||||||
|
|
||||||
|
filled += tempQty;
|
||||||
|
|
||||||
|
// If it's full, there is no sence to keep going on
|
||||||
|
if(getAvailQty() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
products[products.size()-1] = qty - filled;
|
||||||
|
filled = qty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cargo::dump() {
|
||||||
|
Log::logger->message("%s", name.c_str());
|
||||||
|
Log::logger->message("Size:\t%u", size);
|
||||||
|
Log::logger->message("Filled:\t%u", filled);
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < products.size(); i++) {
|
||||||
|
Log::logger->message("%s:\t%u", Economy::Econ->ProdList[i].c_str(), products[i]);
|
||||||
|
}
|
||||||
|
}
|
44
src/Cargo.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CARGO_H_
|
||||||
|
#define _CARGO_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Product;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Cargo {
|
||||||
|
public:
|
||||||
|
Cargo(string nameIn, unsigned int sizeIn);
|
||||||
|
~Cargo();
|
||||||
|
|
||||||
|
unsigned int getFilled();
|
||||||
|
unsigned int getSize();
|
||||||
|
void setSize(unsigned int sizeIn);
|
||||||
|
unsigned int getAvailQty();
|
||||||
|
|
||||||
|
unsigned int getQty(unsigned int product) throw ( const char *);
|
||||||
|
void setQty(unsigned int product, unsigned int qty) throw ( const char *);
|
||||||
|
unsigned int addQty(unsigned int product, int qty) throw ( const char *);
|
||||||
|
|
||||||
|
void fillRandom() throw (const char*);
|
||||||
|
void fillRandom(unsigned int qty) throw ( const char *);
|
||||||
|
|
||||||
|
void dump();
|
||||||
|
|
||||||
|
private:
|
||||||
|
vector<int> products;
|
||||||
|
|
||||||
|
unsigned int size;
|
||||||
|
unsigned filled;
|
||||||
|
|
||||||
|
string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
144
src/City.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "EnvironmentObject.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "Terrain.h"
|
||||||
|
#include "Economy.h"
|
||||||
|
#include "Product.h"
|
||||||
|
#include "CityEconomy.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "City.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
City::City(Terrain *land, string cityName, int cityLocX, int cityLocZ) : EnvironmentObject(cityName, cityLocX, cityLocZ, true) {
|
||||||
|
int xDiff = (int) land->getWidth() / 2;
|
||||||
|
int zDiff = (int) land->getHeight() / 2;
|
||||||
|
|
||||||
|
height = land->getHeight(cityLocX + xDiff, cityLocZ + zDiff);
|
||||||
|
|
||||||
|
MyEconomy = Economy::Econ->CreateCity(cityName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
City::~City(){
|
||||||
|
}
|
||||||
|
|
||||||
|
void City::DisplayObject() {
|
||||||
|
// Right now, we are just drawing a box where the city will be..
|
||||||
|
|
||||||
|
float size = 1;
|
||||||
|
|
||||||
|
//glDisable(GL_TEXTURE_2D);
|
||||||
|
//glEnable(GL_BLEND);
|
||||||
|
//glEnable(GL_COLOR_MATERIAL);
|
||||||
|
//glColor4f(1, 1, 0, 4);
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
// Box top
|
||||||
|
glNormal3f(0, 1, 0);
|
||||||
|
glVertex3f(locX - size, height+5, locZ - size);
|
||||||
|
glVertex3f(locX - size, height+5, locZ + size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ + size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ - size);
|
||||||
|
|
||||||
|
// North
|
||||||
|
glVertex3f(locX - size, height+0, locZ - size);
|
||||||
|
glVertex3f(locX - size, height+5, locZ - size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ - size);
|
||||||
|
glVertex3f(locX + size, height+0, locZ - size);
|
||||||
|
|
||||||
|
// East
|
||||||
|
glVertex3f(locX + size, height+0, locZ - size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ - size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ + size);
|
||||||
|
glVertex3f(locX + size, height+0, locZ + size);
|
||||||
|
|
||||||
|
// South
|
||||||
|
glVertex3f(locX - size, height+0, locZ + size);
|
||||||
|
glVertex3f(locX + size, height+0, locZ + size);
|
||||||
|
glVertex3f(locX + size, height+5, locZ + size);
|
||||||
|
glVertex3f(locX - size, height+5, locZ + size);
|
||||||
|
|
||||||
|
// West
|
||||||
|
glVertex3f(locX - size, height+0, locZ - size);
|
||||||
|
glVertex3f(locX - size, height+0, locZ + size);
|
||||||
|
glVertex3f(locX - size, height+5, locZ + size);
|
||||||
|
glVertex3f(locX - size, height+5, locZ - size);
|
||||||
|
|
||||||
|
// Do not need to draw the bottom.
|
||||||
|
|
||||||
|
// This points from the origin to the city. helps to find the city.
|
||||||
|
//glVertex3f(0,5,0);
|
||||||
|
//glVertex3f(locX, 5, locZ);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
//glEnable(GL_TEXTURE_2D);
|
||||||
|
//glDisable(GL_BLEND);
|
||||||
|
//glDisable(GL_COLOR_MATERIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// woot, i have frets on fire again.
|
||||||
|
|
||||||
|
void City::MapDisplay() {
|
||||||
|
float screenX, screenY;
|
||||||
|
float multi;
|
||||||
|
float winWidth, winHeight;
|
||||||
|
const char* tempName; // = name.c_str();
|
||||||
|
// Need an icon to display for each city with a name.. right now, it can be an X.
|
||||||
|
|
||||||
|
// Our glprintf has some issues if you try to pass a std::string
|
||||||
|
// so by changing the string to a character array, it eleminates this problem.
|
||||||
|
|
||||||
|
tempName = name.c_str();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the difference in the grid from the map to the sailing screen
|
||||||
|
* needs to be dealt with. You see a very similar piece of code
|
||||||
|
* in Map.cpp to deal with where to draw the ship.
|
||||||
|
*/
|
||||||
|
winWidth = Config::configuration->getWinWidth();
|
||||||
|
winHeight = Config::configuration->getWinHeight();
|
||||||
|
|
||||||
|
multi = winWidth / 812.0;
|
||||||
|
screenX = (winWidth / 2) - ((-1 * locX) * multi);
|
||||||
|
screenX -= 6; // the text does not put it EXACTLY where we want it, so we have to move it slightly.
|
||||||
|
|
||||||
|
multi = winHeight / 500.0f;
|
||||||
|
screenY = (winHeight / 2) - ((-1 * locZ) * multi);
|
||||||
|
screenY -= 5; // Same again, we will need to mmove it slightly.
|
||||||
|
|
||||||
|
glColor3f(1, 0, 0);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(screenX, screenY, 0);
|
||||||
|
|
||||||
|
glPrintf(0, "x");
|
||||||
|
glNewLine();
|
||||||
|
glPrintf(0, "%s", tempName);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Product*> City::ProductInformation() {
|
||||||
|
return MyEconomy->getProductList();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool City::CheckName(const char *cityName) {
|
||||||
|
if(name.compare(cityName)) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
43
src/City.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is inherited from the environment object. It will
|
||||||
|
// keep the lacation, name, and economic information of the city.
|
||||||
|
|
||||||
|
#ifndef _CITY_H_
|
||||||
|
#define _CITY_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "EnvironmentObject.h"
|
||||||
|
|
||||||
|
class Product;
|
||||||
|
class Terrain;
|
||||||
|
class CityEconomy;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class City: public EnvironmentObject {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
City(Terrain *land, string cityName, int cityLocX, int cityLocY);
|
||||||
|
|
||||||
|
//Destructor
|
||||||
|
~City();
|
||||||
|
|
||||||
|
// Method
|
||||||
|
void DisplayObject();
|
||||||
|
void MapDisplay();
|
||||||
|
|
||||||
|
vector<Product*> ProductInformation();
|
||||||
|
|
||||||
|
bool CheckName(const char* cityName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// We can put product information and crap here, whatever.
|
||||||
|
float height;
|
||||||
|
CityEconomy* MyEconomy;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
90
src/CityEconomy.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include "Product.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "CityEconomy.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
CityEconomy::CityEconomy(const char* CityName, vector<Product*> ProductList) {
|
||||||
|
myProducts = ProductList;
|
||||||
|
myName = CityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
CityEconomy::~CityEconomy() {
|
||||||
|
unsigned int i;
|
||||||
|
Product* tempProduct;
|
||||||
|
|
||||||
|
for(i = 0; i < myProducts.size(); i++) {
|
||||||
|
tempProduct = (Product*)myProducts[i];
|
||||||
|
delete tempProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
myProducts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
string CityEconomy::getCityName() {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Product* CityEconomy::getProduct(char* ProductName) {
|
||||||
|
string compare;
|
||||||
|
Product* tempProduct = NULL;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
compare = ProductName;
|
||||||
|
|
||||||
|
for(i = 0; i < myProducts.size(); i++) {
|
||||||
|
tempProduct = (Product*)myProducts[i];
|
||||||
|
if(compare == tempProduct->GetName()) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempProduct;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float CityEconomy::getPrice(char* ProductName) {
|
||||||
|
string compare;
|
||||||
|
Product* tempProduct = NULL;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
compare = ProductName;
|
||||||
|
|
||||||
|
for(i = 0; i < myProducts.size(); i++) {
|
||||||
|
tempProduct = (Product*)myProducts[i];
|
||||||
|
if(compare == tempProduct->GetName()) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tempProduct == NULL) {
|
||||||
|
// This should probably throw an exception
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempProduct->GetMedianPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CityEconomy::Print() {
|
||||||
|
unsigned int i;
|
||||||
|
Product* temp;
|
||||||
|
|
||||||
|
cout << myName << ":\n";
|
||||||
|
for(i = 0; i < myProducts.size(); i++) {
|
||||||
|
temp = (Product*)myProducts[i];
|
||||||
|
temp->Print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Product*> CityEconomy::getProductList() {
|
||||||
|
return myProducts;
|
||||||
|
}
|
45
src/CityEconomy.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*
|
||||||
|
* This is a container for each of the citys to keep teack of the state
|
||||||
|
* of its own economy. It also allows the economy class to work on it.
|
||||||
|
* Each instance is kept in the Economy class and the cities must access it
|
||||||
|
* through the economy interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CITYECONOMY_H_
|
||||||
|
#define _CITYECONOMY_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Product;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class CityEconomy {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
CityEconomy(const char* CityName, vector<Product*> ProductList);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~CityEconomy();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
string getCityName();
|
||||||
|
|
||||||
|
Product* getProduct(char*ProductName);
|
||||||
|
float getPrice(char* ProductName);
|
||||||
|
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
vector<Product*> getProductList();
|
||||||
|
|
||||||
|
// Bunch of other crap?
|
||||||
|
private:
|
||||||
|
vector<Product*> myProducts;
|
||||||
|
string myName;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
180
src/CityManager.cpp
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include "ccmath.h"
|
||||||
|
#include "City.h"
|
||||||
|
#include "EnvironmentObject.h"
|
||||||
|
#include "Terrain.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Product.h"
|
||||||
|
#include "CityManager.h"
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
#define MAX_CITIES 32 // This MAY need to be bigger soon.
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
CityManager::CityManager(Terrain *land) {
|
||||||
|
LoadCityConfig("data/City.xml", land);
|
||||||
|
|
||||||
|
//WorldEcon = new Economy("data/Product.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
CityManager::~CityManager() {
|
||||||
|
CityList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
City* CityManager::CheckCollision(Player *player) {
|
||||||
|
// Used to determine if the player is sailing towards the city
|
||||||
|
float angleToCity;
|
||||||
|
float diffAngles;
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
// No sense in checking if the player isn't moving
|
||||||
|
if(player->speed == 0) return NULL;
|
||||||
|
|
||||||
|
for(i=0; i<CityList.size(); i++) {
|
||||||
|
// Check the distance to each city
|
||||||
|
// This isn't really efficient, but since there aren't many cities
|
||||||
|
// it's not really worth doing something fancier.
|
||||||
|
if(CityList[i]->calcDist(player->x, player->z) < 3) {
|
||||||
|
// It's in range, now make sure the angle is close
|
||||||
|
|
||||||
|
angleToCity = CityList[i]->calcAngle(player->x, player->z);
|
||||||
|
|
||||||
|
diffAngles = abs(player->rot - angleToCity);
|
||||||
|
if(diffAngles > M_PI) diffAngles = 2*M_PI - diffAngles;
|
||||||
|
|
||||||
|
if(diffAngles < degreesToRadians(15)) {
|
||||||
|
// The player is close and headed +-5 degrees of city
|
||||||
|
return CityList[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No collision
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CityManager::DisplayCities() {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
// Save some gl calls, just do this once for all the cities
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
glColor4f(1, 1, 0, .4);
|
||||||
|
|
||||||
|
// I'm not sure why, but if you don't do this, then City1
|
||||||
|
// (CityList[0]) doesn't get displayed. It's probably not worth worrying
|
||||||
|
// about since we will hopefully be getting city models soon.
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
CityList[i]->DisplayObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CityManager::MapDisplay() {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
CityList[i]->MapDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CityManager::LoadCityConfig(const char *filename, Terrain *land) {
|
||||||
|
City* TempCity;
|
||||||
|
TiXmlElement* object;
|
||||||
|
TiXmlElement* location;
|
||||||
|
TiXmlNode* node;
|
||||||
|
TiXmlDocument doc( filename );
|
||||||
|
TiXmlText* cityString;
|
||||||
|
string cityName;
|
||||||
|
vector<Product*> tempList;
|
||||||
|
int locX, locZ;
|
||||||
|
int objNum = 0;
|
||||||
|
|
||||||
|
doc.LoadFile();
|
||||||
|
node = doc.FirstChild();
|
||||||
|
|
||||||
|
for(node = node->NextSibling(); node; node = node->NextSibling()) {
|
||||||
|
objNum++;
|
||||||
|
try {
|
||||||
|
// Get the name of the city
|
||||||
|
object = node->FirstChild("name")->ToElement();
|
||||||
|
if(object == NULL) throw 0;
|
||||||
|
cityString = object->FirstChild()->ToText();
|
||||||
|
if(cityString == NULL) throw 0;
|
||||||
|
//cityString = object->ToText();
|
||||||
|
cityName = cityString->Value();
|
||||||
|
|
||||||
|
// Get the X location
|
||||||
|
location = node->FirstChild("location")->ToElement();
|
||||||
|
if(location == NULL) throw 1;
|
||||||
|
object = location->FirstChild("x")->ToElement();
|
||||||
|
if(object == NULL) throw 1;
|
||||||
|
cityString = object->FirstChild()->ToText();
|
||||||
|
if(cityString == NULL) throw 1;
|
||||||
|
sscanf(cityString->Value(), "%d", &locX);
|
||||||
|
|
||||||
|
// Get the Z location
|
||||||
|
object = location->FirstChild("z")->ToElement();
|
||||||
|
if(object == NULL) throw 2;
|
||||||
|
cityString = object->FirstChild()->ToText();
|
||||||
|
if(cityString == NULL) throw 2;
|
||||||
|
sscanf(cityString->Value(), "%d", &locZ);
|
||||||
|
|
||||||
|
TempCity = new City(land, cityName, locX, locZ);
|
||||||
|
|
||||||
|
CityList.push_back(TempCity);
|
||||||
|
} catch(int j) {
|
||||||
|
switch (j) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: Problem with Object Name.");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: Problem with Object x Location.");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Log::logger->message("Warning: Problem with Object y Location.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log::logger->message("Warning: Problem with City Config file.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CityManager::CheckCity(const char *cityName) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
if(CityList[i]->CheckName(cityName)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
40
src/CityManager.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CITYMANAGER_H_
|
||||||
|
#define _CITYMANAGER_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Just so I do not have to include any defines
|
||||||
|
class EnvironmentObject;
|
||||||
|
class Player;
|
||||||
|
class City;
|
||||||
|
class Terrain;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class CityManager {
|
||||||
|
public:
|
||||||
|
// Constructor!
|
||||||
|
CityManager(Terrain *land);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~CityManager();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
City* CheckCollision(Player *player);
|
||||||
|
|
||||||
|
void DisplayCities();
|
||||||
|
void MapDisplay();
|
||||||
|
|
||||||
|
bool CheckCity(const char *cityName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
vector<City*> CityList;
|
||||||
|
void LoadCityConfig(const char *filename, Terrain *land);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
302
src/Config.cpp
Normal file
@ -0,0 +1,302 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "extensions.h"
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Config *Config::configuration = NULL;
|
||||||
|
|
||||||
|
Config::Config(const char *filename) {
|
||||||
|
TiXmlDocument doc(filename);
|
||||||
|
TiXmlElement* config;
|
||||||
|
TiXmlElement* resolution;
|
||||||
|
TiXmlElement* temp;
|
||||||
|
TiXmlText* data;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
winWidth = 640;
|
||||||
|
winHeight = 480;
|
||||||
|
fullscreen = false;
|
||||||
|
useVBO = false;
|
||||||
|
SDLParachute = true;
|
||||||
|
CompressTextures = true;
|
||||||
|
|
||||||
|
doc.LoadFile();
|
||||||
|
if(doc.Error()) {
|
||||||
|
Log::logger->message("Warning: %s (line %d) Using defaults", doc.ErrorDesc(), doc.ErrorRow());
|
||||||
|
LogConfig();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
config = doc.FirstChildElement("GameConfiguration"); // This get's the <GameConfiguration> tag
|
||||||
|
if(config == NULL) {
|
||||||
|
Log::logger->message("Warning: <GameConfiguration> did not parse correctly.");
|
||||||
|
LogConfig();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
resolution = config->FirstChildElement("Resoution"); // Get <resolution>
|
||||||
|
if(resolution == NULL) throw 0;
|
||||||
|
|
||||||
|
// Handle the resolution
|
||||||
|
temp = resolution->FirstChildElement("Width");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
n = sscanf(data->Value(), "%d", &winWidth);
|
||||||
|
if(n != 1) throw 1;
|
||||||
|
|
||||||
|
temp = resolution->FirstChildElement("Height");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 2;
|
||||||
|
n = sscanf(data->Value(), "%d", &winHeight);
|
||||||
|
if(n != 1) throw 2;
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: <Resolution> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: Invalid <Width> data, using defaults");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Log::logger->message("Warning: Invalid <Height> data, using defaults");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not get to here
|
||||||
|
Log::logger->message("Warning: Unknown <Resolution> error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set it back to the defaults
|
||||||
|
winWidth = 640;
|
||||||
|
winHeight = 480;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Handle Fullscreen
|
||||||
|
temp = config->FirstChildElement("Fullscreen");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
if(strcmp(data->Value(), "true") == 0) {
|
||||||
|
fullscreen = true;
|
||||||
|
} else if(strcmp(data->Value(), "false") == 0) {
|
||||||
|
fullscreen = false;
|
||||||
|
} else {
|
||||||
|
throw 1;
|
||||||
|
}
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: <Fullscreen> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: Invalid Fullscreen data, using defaults");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not get here
|
||||||
|
Log::logger->message("Warning: Unknown <Fullscreen> error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Handle Vertex buffer objects
|
||||||
|
temp = config->FirstChildElement("VBO");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
if(strcmp(data->Value(), "true") == 0) {
|
||||||
|
useVBO = true;
|
||||||
|
} else if(strcmp(data->Value(), "false") == 0) {
|
||||||
|
useVBO = false;
|
||||||
|
} else {
|
||||||
|
throw 1;
|
||||||
|
}
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: Invalid <VBO> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: Invalid VBO data, using defaults");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not get here
|
||||||
|
Log::logger->message("Warning: Unknown <VBO> error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Deal with SDLParachute
|
||||||
|
temp = config->FirstChildElement("SDLParachute");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
if(strcmp(data->Value(), "true") == 0) {
|
||||||
|
SDLParachute = true;
|
||||||
|
} else {
|
||||||
|
throw 1;
|
||||||
|
}
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: <SDLParachute> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: Invalid SDLParachute data, using default");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// We should not get here....
|
||||||
|
Log::logger->message("Warning: Unknown <SDLParachute> error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Deal with CompressTextures
|
||||||
|
temp = config->FirstChildElement("CompressTextures");
|
||||||
|
if(temp == NULL) throw 0;
|
||||||
|
|
||||||
|
data = temp->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
if(strcmp(data->Value(), "false") == 0) {
|
||||||
|
CompressTextures = true;
|
||||||
|
} else if(strcmp(data->Value(), "false") == 0) {
|
||||||
|
CompressTextures = false;
|
||||||
|
} else {
|
||||||
|
throw 1;
|
||||||
|
}
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning:CompressTextures> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: invalid CompressTexture data, using default");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Shouldn't get here
|
||||||
|
Log::logger->message("Warning: Unknown <CompressTexture> error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Doesn't realy need to do anything.
|
||||||
|
Config::~Config() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// This needs to happen after we have an openGL context, so it can not happen in the constructor
|
||||||
|
bool Config::checkExtensions() {
|
||||||
|
// This could probably be nicer.
|
||||||
|
bool supportMultiTex = checkExtension("GL_ARB_multitexture");
|
||||||
|
bool supportVBO = checkExtension("GL_ARB_vertex_buffer_object");
|
||||||
|
|
||||||
|
// Make sure we have support for multitexturing.
|
||||||
|
if(!supportMultiTex) {
|
||||||
|
// Probably should just throw an exeption.
|
||||||
|
Log::logger->message("Error: Your video card is crap and does not support multitexturing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we do not try to use vertex buffer objects without support
|
||||||
|
if(!supportVBO && useVBO) {
|
||||||
|
useVBO = false;
|
||||||
|
Log::logger->message("Warning: Your video card does not support VBOs, falling back onto VAs");
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have multitexturing so we can continue forth.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::checkVBO() {
|
||||||
|
return useVBO;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Config::getWinWidth() {
|
||||||
|
return winWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Config::getWinHeight() {
|
||||||
|
return winHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::checkFullscreen() {
|
||||||
|
return fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::checkSDLParachute() {
|
||||||
|
return SDLParachute;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::checkCompressTextures() {
|
||||||
|
return CompressTextures;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::openConfig(const char *filename) {
|
||||||
|
if(configuration != NULL) {
|
||||||
|
Log::logger->message("Warning: Open config on non-NULL configuration");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration = new Config(filename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::closeConfig() {
|
||||||
|
if (configuration == NULL) {
|
||||||
|
Log::logger->message("Warning: Close config on NULL configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete configuration;
|
||||||
|
configuration = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::LogConfig() {
|
||||||
|
ostringstream outputString;
|
||||||
|
|
||||||
|
outputString << "Configuration:" << endl;
|
||||||
|
outputString << "Resolution: " << winWidth << " x " << winHeight << endl;
|
||||||
|
|
||||||
|
outputString << "Fullscreen: ";
|
||||||
|
if(fullscreen) outputString << "true";
|
||||||
|
else outputString << "false";
|
||||||
|
outputString << endl;
|
||||||
|
|
||||||
|
outputString << "Use VBOs: ";
|
||||||
|
if(useVBO) outputString << "true";
|
||||||
|
else outputString << "false";
|
||||||
|
outputString << endl;
|
||||||
|
|
||||||
|
outputString << "Enable SDL Parachute: ";
|
||||||
|
if(SDLParachute) outputString << "true";
|
||||||
|
else outputString << "false";
|
||||||
|
|
||||||
|
outputString << endl;
|
||||||
|
|
||||||
|
outputString << "Compress Textures: ";
|
||||||
|
if(CompressTextures) outputString << "true";
|
||||||
|
else outputString << "false";
|
||||||
|
|
||||||
|
Log::logger->message(outputString.str());
|
||||||
|
}
|
59
src/Config.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
public:
|
||||||
|
//constructor
|
||||||
|
Config(const char *filename);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Config();
|
||||||
|
|
||||||
|
// Make sure the necesary extensions are supported, this needs to happen after we have an openGL context.
|
||||||
|
bool checkExtensions();
|
||||||
|
|
||||||
|
// Check to see whether or not to use Vertex Buffer Objects
|
||||||
|
bool checkVBO();
|
||||||
|
|
||||||
|
// Returns winWidth/winHeight
|
||||||
|
int getWinWidth();
|
||||||
|
int getWinHeight();
|
||||||
|
|
||||||
|
// check to see whether or not to go fullscreen
|
||||||
|
bool checkFullscreen();
|
||||||
|
|
||||||
|
// Check to see whether or not to enable the SDL parachute
|
||||||
|
bool checkSDLParachute();
|
||||||
|
|
||||||
|
// Check to see whether or not to compress textures
|
||||||
|
bool checkCompressTextures();
|
||||||
|
|
||||||
|
static bool openConfig(const char *filename);
|
||||||
|
static void closeConfig();
|
||||||
|
|
||||||
|
static Config *configuration;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Window dimensions
|
||||||
|
int winWidth;
|
||||||
|
int winHeight;
|
||||||
|
|
||||||
|
// True is fullscreen, false is windowed mode.
|
||||||
|
bool fullscreen;
|
||||||
|
|
||||||
|
// bool for vertex buffer object usage
|
||||||
|
bool useVBO;
|
||||||
|
|
||||||
|
// Boolian to see whether or not we should enable the SDL parachute
|
||||||
|
// This should probably be true unless you want to get a core file or something stupid
|
||||||
|
bool SDLParachute;
|
||||||
|
|
||||||
|
// Boolian to see whether or not to compress textures on load
|
||||||
|
// This should probably always be true, unless your video card can not handle it
|
||||||
|
bool CompressTextures;
|
||||||
|
|
||||||
|
// Sending config options to logger
|
||||||
|
void LogConfig();
|
||||||
|
};
|
237
src/Economy.cpp
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "Player.h"
|
||||||
|
#include "Cargo.h"
|
||||||
|
#include "Product.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "tinyxml.h"
|
||||||
|
#include "CityManager.h"
|
||||||
|
#include "CityEconomy.h"
|
||||||
|
#include "Economy.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Economy *Economy::Econ = NULL;
|
||||||
|
|
||||||
|
Economy::Economy(const char* filename) {
|
||||||
|
TiXmlNode* Products;
|
||||||
|
TiXmlNode* ForProducts;
|
||||||
|
TiXmlElement* Prod;
|
||||||
|
TiXmlText* data;
|
||||||
|
string prodName;
|
||||||
|
|
||||||
|
doc.LoadFile(filename);
|
||||||
|
if(doc.Error()) {
|
||||||
|
Log::logger->message("Error: Could not open Economy file.\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Products = doc.FirstChild("Products");
|
||||||
|
|
||||||
|
for(ForProducts = Products->FirstChildElement("Name");
|
||||||
|
ForProducts;
|
||||||
|
ForProducts = ForProducts->NextSibling("Name")) {
|
||||||
|
|
||||||
|
if(ForProducts == NULL) throw -1;
|
||||||
|
Prod = ForProducts->ToElement();
|
||||||
|
data = Prod->FirstChild()->ToText();
|
||||||
|
prodName = data->Value();
|
||||||
|
|
||||||
|
ProdList.push_back(prodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Economy::~Economy() {
|
||||||
|
unsigned int i;
|
||||||
|
CityEconomy* temp;
|
||||||
|
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
temp = (CityEconomy*)CityList[i];
|
||||||
|
delete temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
CityList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Economy::CreateEcon() {
|
||||||
|
if(Econ != NULL) {
|
||||||
|
Log::logger->message("Warning: Multiple calls to CreateEcon()");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Econ = new Economy("data/Product.xml");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Economy::Step() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Economy::Print() {
|
||||||
|
unsigned int i;
|
||||||
|
CityEconomy* temp;
|
||||||
|
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
temp = (CityEconomy*) CityList[i];
|
||||||
|
temp->Print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CityEconomy* Economy::CreateCity(const char* CityName) {
|
||||||
|
TiXmlNode* City;
|
||||||
|
TiXmlElement* CityElement;
|
||||||
|
TiXmlElement* Prod;
|
||||||
|
TiXmlElement* Value;
|
||||||
|
TiXmlElement* Demand;
|
||||||
|
TiXmlText* data;
|
||||||
|
TiXmlNode* node;
|
||||||
|
Product* tempProduct;
|
||||||
|
vector<Product*> ProductList;
|
||||||
|
CityEconomy* tempCE;
|
||||||
|
string name;
|
||||||
|
string cityName;
|
||||||
|
float price;
|
||||||
|
int demand;
|
||||||
|
int proNum;
|
||||||
|
int n;
|
||||||
|
int ID;
|
||||||
|
|
||||||
|
EconomyNode = doc.FirstChild("Economy");
|
||||||
|
|
||||||
|
for(City = EconomyNode->FirstChildElement("City");
|
||||||
|
City;
|
||||||
|
City = City->NextSibling("City")) {
|
||||||
|
|
||||||
|
if(City == NULL) throw -1;
|
||||||
|
CityElement = City->ToElement();
|
||||||
|
cityName = CityElement->Attribute("name");
|
||||||
|
if(cityName == CityName) {
|
||||||
|
|
||||||
|
for(node = City->FirstChild("Product"); node; node = node->NextSibling("Product")) {
|
||||||
|
if(node == NULL) throw 0;
|
||||||
|
proNum++;
|
||||||
|
try {
|
||||||
|
Prod = node->FirstChildElement("Name");
|
||||||
|
if(Prod == NULL) throw 1;
|
||||||
|
data = Prod->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
name = data->Value();
|
||||||
|
ID = FindID(name);
|
||||||
|
|
||||||
|
Value = node->FirstChildElement("Value");
|
||||||
|
if(Value == NULL) throw 2;
|
||||||
|
data = Value->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 2;
|
||||||
|
n = sscanf(data->Value(), "%f", &price);
|
||||||
|
if(n == -1) {
|
||||||
|
Log::logger->message("Error: Bad XML document.\n");
|
||||||
|
throw 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Demand = node->FirstChildElement("Demand");
|
||||||
|
if(Demand == NULL) throw 3;
|
||||||
|
data = Demand->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 3;
|
||||||
|
n = sscanf(data->Value(), "%i", &demand);
|
||||||
|
if(n == -1) throw 3;
|
||||||
|
|
||||||
|
tempProduct = new Product(ID, price, demand);
|
||||||
|
|
||||||
|
ProductList.push_back(tempProduct);
|
||||||
|
} catch(int i) {
|
||||||
|
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("Warning: <Product> did not parse correctly.");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("Warning: <Name> did not parse correctly.");
|
||||||
|
City->Print(stdout, 0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Log::logger->message("Warning: <Value> did not parse correctly.");
|
||||||
|
City->Print(stdout, 0);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Log::logger->message("Warning: <Demand> did not parse correctly.");
|
||||||
|
City->Print(stdout, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log::logger->message("Warning: Unknown error occured.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} // Catch (int i)
|
||||||
|
} // for loop
|
||||||
|
tempCE = new CityEconomy(cityName.c_str(), ProductList);
|
||||||
|
ProductList.clear();
|
||||||
|
CityList.push_back(tempCE);
|
||||||
|
break;
|
||||||
|
} // if(cityName == CityName)
|
||||||
|
} // For loop
|
||||||
|
return tempCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Economy::CheckCities(CityManager* tempManager) {
|
||||||
|
unsigned int i;
|
||||||
|
for(i = 0; i < CityList.size(); i++) {
|
||||||
|
if(!tempManager->CheckCity(CityList[i]->getCityName().c_str()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Economy::ProductCount() {
|
||||||
|
return (int)ProdList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Economy::BuyProduct(Player *data, int ProdID, float price) {
|
||||||
|
Cargo *playerCargo = data->getCargo();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Make sure the player can afford it, and has room for it
|
||||||
|
if((data->gold < price) || (playerCargo->getAvailQty() <= 0)) return;
|
||||||
|
|
||||||
|
playerCargo->addQty(ProdID, 1);
|
||||||
|
data->gold -= (int) price;
|
||||||
|
Log::logger->message("Purchased %s", ProdList[ProdID].c_str());
|
||||||
|
} catch (const char *e) {
|
||||||
|
Log::logger->message(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Economy::SellProduct(Player *data, int ProdID, float price) {
|
||||||
|
Cargo *playerCargo = data->getCargo();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(playerCargo->getQty(ProdID) <= 0) return;
|
||||||
|
|
||||||
|
playerCargo->addQty(ProdID, -1);
|
||||||
|
data->gold += (int) price;
|
||||||
|
Log::logger->message("Sold %u", ProdList[ProdID].c_str());
|
||||||
|
} catch (const char *e) {
|
||||||
|
Log::logger->message(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Economy::FindID(string Name) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < ProdList.size(); i++) {
|
||||||
|
if(ProdList[i] == Name) return (int) i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
76
src/Economy.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* The Economy class is the top level of all the
|
||||||
|
* economies present in Lephisto. It is the authority
|
||||||
|
* on how products and prices change.
|
||||||
|
*
|
||||||
|
* After the creation of the Economy, the economy
|
||||||
|
* doesn't interact much with other classes. Each
|
||||||
|
* City will have a pointer to an element within
|
||||||
|
* the economy so the city can access and change
|
||||||
|
* the information if it wants to. The only thing that
|
||||||
|
* needs to be called is Step() once and a while
|
||||||
|
* so that the Economy will actualy change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ECONOMY_H_
|
||||||
|
#define _ECONOMY_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
//class Product;
|
||||||
|
class CityManager;
|
||||||
|
class CityEconomy;
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Economy {
|
||||||
|
public:
|
||||||
|
/* Constructor
|
||||||
|
* the constructor creates the Economy and opens
|
||||||
|
* the file in filename. It does not create the
|
||||||
|
* CityEconomies, they are created using CreateCity.
|
||||||
|
* This allows a basic error checking system so that
|
||||||
|
* there aren't cities within Economies and no
|
||||||
|
* Economies without cities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Economy(const char* filename);
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
~Economy();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
bool CreateEcon(); // This creates the Economy for the static Economy
|
||||||
|
// This changes the state of the economy
|
||||||
|
void Step();
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
CityEconomy* CreateCity(const char* CityName);
|
||||||
|
|
||||||
|
static Economy* Econ;
|
||||||
|
|
||||||
|
bool CheckCities(CityManager* tempManager);
|
||||||
|
|
||||||
|
int ProductCount();
|
||||||
|
|
||||||
|
void BuyProduct(Player *data, int ProdID, float price);
|
||||||
|
void SellProduct(Player *data, int ProdID, float price);
|
||||||
|
|
||||||
|
vector<string> ProdList;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int FindID(string Name);
|
||||||
|
vector<CityEconomy*> CityList;
|
||||||
|
|
||||||
|
TiXmlDocument doc;
|
||||||
|
TiXmlNode* EconomyNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
50
src/EnvironmentObject.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This class is a parent to any object which may apear
|
||||||
|
* in the game. Initialy the things that I can think of now
|
||||||
|
* would be cities, hidden treasures, and maybe enemy ships.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "ccmath.h"
|
||||||
|
#include "EnvironmentObject.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
EnvironmentObject::EnvironmentObject() {
|
||||||
|
locX = 0;
|
||||||
|
locZ = 0;
|
||||||
|
visible = false;
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
EnvironmentObject::~EnvironmentObject() {
|
||||||
|
}
|
||||||
|
|
||||||
|
EnvironmentObject::EnvironmentObject(string objName, int objLocX, int objLocZ, bool objVisible) {
|
||||||
|
locX = objLocX;
|
||||||
|
locZ = objLocZ;
|
||||||
|
visible = objVisible;
|
||||||
|
name = objName;
|
||||||
|
}
|
||||||
|
|
||||||
|
string EnvironmentObject::getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
float EnvironmentObject::calcDist(float x, float z) {
|
||||||
|
return sqrt((x-locX)+(x-locX)+(z-locZ)*(z-locZ));
|
||||||
|
}
|
||||||
|
|
||||||
|
float EnvironmentObject::calcAngle(float x, float z) {
|
||||||
|
// Um, don't ask.
|
||||||
|
float angle = atan2(locZ - z, x - locX);
|
||||||
|
|
||||||
|
// atan2 returns from -PI to PI, so move 0 to 2*PI
|
||||||
|
if(angle < 0) angle = 2*M_PI + angle;
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
42
src/EnvironmentObject.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ENVIRONMENTOBJECT_H_
|
||||||
|
#define _ENVIRONMENTOBJECT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class EnvironmentObject {
|
||||||
|
public:
|
||||||
|
// Construction is underway!
|
||||||
|
EnvironmentObject();
|
||||||
|
EnvironmentObject(string objName, int objLocX, int objLocZ, bool objVisible);
|
||||||
|
|
||||||
|
// No idea why this is needed here but not in GameState
|
||||||
|
virtual ~EnvironmentObject() = 0;
|
||||||
|
|
||||||
|
// Returns the name of the object.
|
||||||
|
string getName();
|
||||||
|
|
||||||
|
// Returns distance from (x, z) to object
|
||||||
|
float calcDist(float x, float z);
|
||||||
|
|
||||||
|
// Return angle in radians from (x, z) to object
|
||||||
|
float calcAngle(float x, float z);
|
||||||
|
|
||||||
|
virtual void DisplayObject() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int locX;
|
||||||
|
int locZ;
|
||||||
|
bool visible;
|
||||||
|
string name;
|
||||||
|
|
||||||
|
private: // ?
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
135
src/Frustum.cpp
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include "Point.h"
|
||||||
|
#include "BoundBox.h"
|
||||||
|
#include "Frustum.h"
|
||||||
|
|
||||||
|
void Frustum::getFrustum() {
|
||||||
|
float proj[16];
|
||||||
|
float modl[16];
|
||||||
|
float clip[16];
|
||||||
|
//float t;
|
||||||
|
|
||||||
|
// Get the current PROJECTION matrix
|
||||||
|
glGetFloatv(GL_PROJECTION_MATRIX, proj);
|
||||||
|
|
||||||
|
// Get the current MODELVIEW matrix
|
||||||
|
glGetFloatv(GL_MODELVIEW_MATRIX, modl);
|
||||||
|
|
||||||
|
// Combine the two matrices (multiply projection by modelview)
|
||||||
|
clip[0] = modl[0]*proj[0] + modl[1]*proj[4] + modl[2]*proj[8] + modl[3]*proj[12];
|
||||||
|
clip[1] = modl[0]*proj[1] + modl[1]*proj[5] + modl[2]*proj[9] + modl[3]*proj[13];
|
||||||
|
clip[2] = modl[0]*proj[2] + modl[1]*proj[6] + modl[2]*proj[10] + modl[3]*proj[14];
|
||||||
|
clip[3] = modl[0]*proj[3] + modl[1]*proj[7] + modl[2]*proj[11] + modl[3]*proj[15];
|
||||||
|
|
||||||
|
clip[4] = modl[4]*proj[0] + modl[5]*proj[4] + modl[6]*proj[8] + modl[7]*proj[12];
|
||||||
|
clip[5] = modl[4]*proj[1] + modl[5]*proj[5] + modl[6]*proj[9] + modl[7]*proj[13];
|
||||||
|
clip[6] = modl[4]*proj[2] + modl[5]*proj[6] + modl[6]*proj[10] + modl[7]*proj[14];
|
||||||
|
clip[7] = modl[4]*proj[3] + modl[5]*proj[7] + modl[6]*proj[11] + modl[7]*proj[15];
|
||||||
|
|
||||||
|
clip[8] = modl[8]*proj[0] + modl[9]*proj[4] + modl[10]*proj[8] + modl[11]*proj[12];
|
||||||
|
clip[9] = modl[8]*proj[1] + modl[9]*proj[5] + modl[10]*proj[9] + modl[11]*proj[13];
|
||||||
|
clip[10] = modl[8]*proj[2] + modl[9]*proj[6] + modl[10]*proj[10] + modl[11]*proj[14];
|
||||||
|
clip[11] = modl[8]*proj[3] + modl[9]*proj[7] + modl[10]*proj[11] + modl[11]*proj[15];
|
||||||
|
|
||||||
|
clip[12] = modl[12]*proj[0] + modl[13]*proj[4] + modl[14]*proj[8] + modl[15]*proj[12];
|
||||||
|
clip[13] = modl[12]*proj[1] + modl[13]*proj[5] + modl[14]*proj[9] + modl[15]*proj[13];
|
||||||
|
clip[14] = modl[12]*proj[2] + modl[13]*proj[6] + modl[14]*proj[10] + modl[15]*proj[14];
|
||||||
|
clip[15] = modl[12]*proj[3] + modl[13]*proj[7] + modl[14]*proj[11] + modl[15]*proj[15];
|
||||||
|
|
||||||
|
// Extract the numbers for the RIGHT plane
|
||||||
|
frustum[0][0] = clip[3] - clip[0];
|
||||||
|
frustum[0][1] = clip[7] - clip[4];
|
||||||
|
frustum[0][2] = clip[11] - clip[8];
|
||||||
|
frustum[0][3] = clip[15] - clip[12];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
/*
|
||||||
|
t = sqrt(frustum[0][0]*frustum[0][0] + frustum[0][1]*frustum[0][1] + frustum[0][2]*frustum[0][2]);
|
||||||
|
frustum[0][0] /= t;
|
||||||
|
frustum[0][1] /= t;
|
||||||
|
frustum[0][2] /= t;
|
||||||
|
frustum[0][3] /= t;
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Extract the numbers for the LEFT plane
|
||||||
|
frustum[1][0] = clip[3] + clip[0];
|
||||||
|
frustum[1][1] = clip[7] + clip[4];
|
||||||
|
frustum[1][2] = clip[11] + clip[ 8];
|
||||||
|
frustum[1][3] = clip[15] + clip[12];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
|
||||||
|
// Extract the BOTTOM plane
|
||||||
|
frustum[2][0] = clip[3] + clip[1];
|
||||||
|
frustum[2][1] = clip[7] + clip[5];
|
||||||
|
frustum[2][2] = clip[11] + clip[9];
|
||||||
|
frustum[2][3] = clip[15] + clip[13];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
|
||||||
|
// Extract the TOP plane
|
||||||
|
frustum[3][0] = clip[3] - clip[1];
|
||||||
|
frustum[3][1] = clip[7] - clip[5];
|
||||||
|
frustum[3][2] = clip[11] - clip[ 9];
|
||||||
|
frustum[3][3] = clip[15] - clip[13];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
|
||||||
|
// Extract the FAR plane
|
||||||
|
frustum[4][0] = clip[3] - clip[2];
|
||||||
|
frustum[4][1] = clip[7] - clip[6];
|
||||||
|
frustum[4][2] = clip[11] - clip[10];
|
||||||
|
frustum[4][3] = clip[15] - clip[14];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
|
||||||
|
// Extract the NEAR plane
|
||||||
|
frustum[5][0] = clip[3] + clip[2];
|
||||||
|
frustum[5][1] = clip[7] + clip[6];
|
||||||
|
frustum[5][2] = clip[11] + clip[10];
|
||||||
|
frustum[5][3] = clip[15] + clip[14];
|
||||||
|
|
||||||
|
// Normalize the result (not needed for boxes)
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Frustum::checkBox(BoundBox *box) {
|
||||||
|
// Check each frustum plane
|
||||||
|
for(int p=0; p<6; p++) {
|
||||||
|
// Check each point of the box
|
||||||
|
// Bottom points
|
||||||
|
if(frustum[p][0]*box->b1->x + frustum[p][1]*box->b1->y + frustum[p][2]*box->b1->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->b2->x + frustum[p][1]*box->b2->y + frustum[p][2]*box->b2->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->b3->x + frustum[p][1]*box->b3->y + frustum[p][2]*box->b3->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->b4->x + frustum[p][1]*box->b4->y + frustum[p][2]*box->b4->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Top points
|
||||||
|
if(frustum[p][0]*box->t1->x + frustum[p][1]*box->t1->y + frustum[p][2]*box->t1->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->t2->x + frustum[p][1]*box->t2->y + frustum[p][2]*box->t2->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->t3->x + frustum[p][1]*box->t3->y + frustum[p][2]*box->t3->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
if(frustum[p][0]*box->t4->x + frustum[p][1]*box->t4->y + frustum[p][2]*box->t4->z + frustum[p][3] > 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// It's not in front of ANY plane, return false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Got through all the checks, it passed
|
||||||
|
return true;
|
||||||
|
}
|
23
src/Frustum.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FRUSTUM_H_
|
||||||
|
#define _FRUSTUM_H_
|
||||||
|
|
||||||
|
class BoundBox;
|
||||||
|
|
||||||
|
// Frustum used for culling quadtree
|
||||||
|
class Frustum {
|
||||||
|
public:
|
||||||
|
// Extracts projection data
|
||||||
|
void getFrustum();
|
||||||
|
|
||||||
|
bool checkBox(BoundBox *box);
|
||||||
|
|
||||||
|
private:
|
||||||
|
float frustum[6][4];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
195
src/GameState.cpp
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
GameState *GameState::mainMenu = NULL;
|
||||||
|
GameState **GameState::currentPtr = NULL;
|
||||||
|
|
||||||
|
unsigned char GameState::nextScreen = 0;
|
||||||
|
|
||||||
|
GameState::GameState(GameState *prev) {
|
||||||
|
previous = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
// This has basicaly nothing to do.
|
||||||
|
GameState::~GameState() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static function to set mainMenu pointer
|
||||||
|
void GameState::setMainMenu(GameState *menu) {
|
||||||
|
if((menu != NULL) && (mainMenu != NULL)) {
|
||||||
|
Log::logger->message("Warning: setMainMenu called with non-null mainMenu pointer");
|
||||||
|
}
|
||||||
|
mainMenu = menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static function to set currentPtr pointer
|
||||||
|
void GameState::setCurrentPtr(GameState **current) {
|
||||||
|
if(currentPtr != NULL) {
|
||||||
|
Log::logger->message("Warning: setCurrentPtr called with non-null currentPtr pointer");
|
||||||
|
}
|
||||||
|
currentPtr = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameState::doExit() {
|
||||||
|
// The MainMenu object needs to overload this
|
||||||
|
if (mainMenu != NULL) {
|
||||||
|
mainMenu->doExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
|
const Uint32 Rmask = 0xFF,
|
||||||
|
Gmask = 0xFF<<8,
|
||||||
|
Bmask = 0xFF<<(2*8),
|
||||||
|
Amask = 0xFF<<(3*8);
|
||||||
|
#else
|
||||||
|
const Uint32 Rmask = 0xFF<<(3*8),
|
||||||
|
Gmask = 0xFF<<(2*8),
|
||||||
|
Bmask = 0xFF<<8,
|
||||||
|
Amask = 0xFF;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void GameState::takeScreenshot() {
|
||||||
|
//char buf[strlen("screenshotXXX.bmp")+1]; Need to look at this doesn't compile under vs for windows
|
||||||
|
char buf[18];
|
||||||
|
FILE* fp;
|
||||||
|
|
||||||
|
unsigned count = nextScreen;
|
||||||
|
|
||||||
|
//int width = Config::configuration->getWinWidth();
|
||||||
|
//int height = Config::configuration->getWinHeight();
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
if(count > 255) {
|
||||||
|
Log::logger->message("Error: All 256 screenshot names are taken, could not take screenshot");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
_snprintf(buf,strlen("screenshotXXX.bmp")+1,"Screenshot%u.bmp",count);
|
||||||
|
#endif
|
||||||
|
snprintf(buf,strlen("screenshotXXX.bmp")+1,"Screenshot%u.bmp",count);
|
||||||
|
|
||||||
|
// Check to see if the file already exists
|
||||||
|
if(!(fp = fopen(buf,"r")))
|
||||||
|
// The file does not exist, so may as well use it.
|
||||||
|
break;
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextScreen = count;
|
||||||
|
|
||||||
|
// Ginto is currently trying to make this work
|
||||||
|
// TODO: get openGL pixel data into a texture, then get pixel data from texture
|
||||||
|
|
||||||
|
int w = Config::configuration->getWinWidth(),h = Config::configuration->getWinHeight();
|
||||||
|
// get previous frame, because the current may not have been drawn yet
|
||||||
|
glReadBuffer(GL_FRONT);
|
||||||
|
|
||||||
|
Uint32* pixels = new Uint32[w*h];
|
||||||
|
|
||||||
|
glReadPixels(0,0,w,h,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
|
||||||
|
|
||||||
|
// flip image vertically because GL normally gives pixels upside down
|
||||||
|
Uint32* tmpBuf = new Uint32[w];
|
||||||
|
for(int y=0;y<h/2;++y) {
|
||||||
|
memcpy(tmpBuf,pixels+y*w,w*sizeof(Uint32));
|
||||||
|
memcpy(pixels+y*w,pixels+(h-y-1)*w,w*sizeof(Uint32));
|
||||||
|
memcpy(pixels+(h-y-1)*w,tmpBuf,w*sizeof(Uint32));
|
||||||
|
}
|
||||||
|
delete tmpBuf;
|
||||||
|
|
||||||
|
SDL_Surface* img = SDL_CreateRGBSurfaceFrom(pixels,w,h,32,w*4,Rmask,Gmask,Bmask,Amask);
|
||||||
|
|
||||||
|
SDL_SaveBMP(img,buf);
|
||||||
|
|
||||||
|
SDL_FreeSurface(img);
|
||||||
|
delete pixels;
|
||||||
|
// if(!(fp = fopen(buf,"w"))) {
|
||||||
|
// Log::logger->message("could not open screenshot file for writing");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameState::switchState(GameState *next, GameState *prev) {
|
||||||
|
// Prepare to leave this state
|
||||||
|
switchFrom();
|
||||||
|
|
||||||
|
// Set the next state's previous pointer, if it's not NULL
|
||||||
|
// If it is null, just leave the previous pointer alone
|
||||||
|
if(prev != NULL) {
|
||||||
|
next->previous = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare to enter the next state
|
||||||
|
next->switchTo(prev);
|
||||||
|
|
||||||
|
// Hand control over to the next state
|
||||||
|
*currentPtr = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameState::displaySplashScreen(string imageFile, string text, float shade) {
|
||||||
|
GLuint loadingTexture;
|
||||||
|
|
||||||
|
// Temp storage for window width and height
|
||||||
|
int width = Config::configuration->getWinWidth();
|
||||||
|
int height = Config::configuration->getWinHeight();
|
||||||
|
|
||||||
|
// Show the loading screen
|
||||||
|
|
||||||
|
// Get ready for text mode
|
||||||
|
EnterTextMode(width, height);
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
BuildTexture(imageFile.c_str(), &loadingTexture, GL_CLAMP, false);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, loadingTexture);
|
||||||
|
|
||||||
|
// Clear the depth buffer
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Set the color
|
||||||
|
glColor3f(shade, shade, shade);
|
||||||
|
|
||||||
|
// Draw the actual background quad
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex3f(0, 0, 0);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex3f(0, height, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex3f(width, height, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex3f(width, 0, 0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Draw the text
|
||||||
|
glTranslatef(0, (float) height * .5 - (16/2), 0);
|
||||||
|
glTranslatef(width * 0.5 - (text.length() * 10 / 2), 0, 0);
|
||||||
|
glColor3f(0, 0, 1);
|
||||||
|
glPrint(text.c_str(), 0);
|
||||||
|
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
|
||||||
|
// Done with the texture so get shut of it
|
||||||
|
glDeleteTextures(1, &loadingTexture);
|
||||||
|
}
|
60
src/GameState.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GAMESTATE_H_
|
||||||
|
#define _GAMESTATE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class GameState {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
GameState(GameState *prev);
|
||||||
|
|
||||||
|
// Need a virtual destructor to make sure the proper destructor get's called.
|
||||||
|
virtual ~GameState() = 0;
|
||||||
|
|
||||||
|
// Initialize the mainMenu pointer
|
||||||
|
// This only needs to happen once per execution
|
||||||
|
static void setMainMenu(GameState *menu);
|
||||||
|
|
||||||
|
// Initialize the currentPtr
|
||||||
|
// This only needs to happen once per execution
|
||||||
|
static void setCurrentPtr(GameState **current);
|
||||||
|
|
||||||
|
// Main state loop
|
||||||
|
virtual void loop() = 0;
|
||||||
|
|
||||||
|
// Call this to exit
|
||||||
|
virtual void doExit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GameState *previous;
|
||||||
|
|
||||||
|
// All states share these pointers, so make them static
|
||||||
|
static GameState *mainMenu;
|
||||||
|
static GameState **currentPtr;
|
||||||
|
|
||||||
|
// For screenshots
|
||||||
|
static unsigned char nextScreen;
|
||||||
|
|
||||||
|
// Save a screenshot to disk
|
||||||
|
void takeScreenshot();
|
||||||
|
|
||||||
|
// Display a splash screen
|
||||||
|
void displaySplashScreen(std::string imageFile, std::string text, float shade);
|
||||||
|
|
||||||
|
// Switch to next, giving prev as the previous state
|
||||||
|
virtual void switchState(GameState *next, GameState *prev);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Things to do when switching to this state from oldState
|
||||||
|
virtual void switchTo(GameState *oldState) = 0;
|
||||||
|
|
||||||
|
// Things to do when switching from this state
|
||||||
|
virtual void switchFrom() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
102
src/Log.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Log *Log::logger = NULL;
|
||||||
|
|
||||||
|
Log::Log(bool logToFile) {
|
||||||
|
time_t timestamp;
|
||||||
|
|
||||||
|
if(logToFile) {
|
||||||
|
logFile.open("Lephisto.log", ios::out);
|
||||||
|
if(!logToFile) {
|
||||||
|
// We can not open log file.
|
||||||
|
cerr << "Warning: Cannot open error.log for write, continuing without logging\n";
|
||||||
|
} else {
|
||||||
|
// Log file is open, let's give it a nice time stamp.
|
||||||
|
timestamp = time(NULL);
|
||||||
|
logFile << "Log Started: " << ctime(×tamp) << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::~Log() {
|
||||||
|
time_t timestamp;
|
||||||
|
|
||||||
|
// We only realy need to close logFile if it is already open.
|
||||||
|
if(logFile) {
|
||||||
|
// Give it a pretty closeing timestamp
|
||||||
|
timestamp = time(NULL);
|
||||||
|
logFile << endl << "Log Closed: " << ctime(×tamp) << endl;
|
||||||
|
|
||||||
|
// Close log file
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::message(std::string msg) {
|
||||||
|
if(logFile) {
|
||||||
|
logFile << msg << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr << msg << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::message(const char *msg, ...) {
|
||||||
|
va_list vargList; // This is to handlle the variable arguments
|
||||||
|
|
||||||
|
char outBuf[1024];
|
||||||
|
unsigned short outLen;
|
||||||
|
|
||||||
|
// This takes the arguments and puts them into the character array.
|
||||||
|
va_start(vargList, msg);
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList);
|
||||||
|
#else
|
||||||
|
outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
va_end(vargList);
|
||||||
|
|
||||||
|
if(outLen >= sizeof(outBuf)) {
|
||||||
|
outLen = sizeof(outBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(logFile) {
|
||||||
|
logFile << outBuf << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr << outBuf << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Log::openLog(bool logToFile) {
|
||||||
|
// Make sure the logger has not already been initialized.
|
||||||
|
if(logger != NULL) {
|
||||||
|
logger->message("Warning: Multiple calls to OpenLog()");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger = new Log(logToFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::closeLog() {
|
||||||
|
if(logger == NULL) {
|
||||||
|
cerr << "Warning: Call to closeLog with NULL logger pointer" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete logger;
|
||||||
|
logger = NULL;
|
||||||
|
}
|
33
src/Log.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LOG_H_
|
||||||
|
#define _LOG_H_
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Log {
|
||||||
|
public:
|
||||||
|
// Construtor
|
||||||
|
Log(bool logToFile);
|
||||||
|
|
||||||
|
// Deconstructor
|
||||||
|
~Log();
|
||||||
|
|
||||||
|
// Log an error message
|
||||||
|
void message(std::string msg);
|
||||||
|
void message(const char *msg, ...);
|
||||||
|
|
||||||
|
static bool openLog(bool logToFile);
|
||||||
|
static void closeLog();
|
||||||
|
|
||||||
|
static Log *logger;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ofstream logFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
158
src/MainMenu.cpp
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "Config.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
#include "StateSailing.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
#include "MainMenu.h"
|
||||||
|
|
||||||
|
MainMenu::MainMenu(bool *doneIn): GameState(NULL) {
|
||||||
|
displaySplashScreen("./data/title.png", "", 1);
|
||||||
|
// Set the static Gamestate mainMenu pointer to this
|
||||||
|
GameState::setMainMenu(this);
|
||||||
|
// Bool value to set to quit
|
||||||
|
done = doneIn;
|
||||||
|
|
||||||
|
// Set the pointer to the main sailing state to null
|
||||||
|
mainGame = NULL;
|
||||||
|
|
||||||
|
// Ahh.. this is better --Allanis
|
||||||
|
cont_callback.SetCallback(this, &MainMenu::continueGame);
|
||||||
|
new_callback.SetCallback(this, &MainMenu::newGame);
|
||||||
|
save_callback.SetCallback(this, &MainMenu::saveGame);
|
||||||
|
load_callback.SetCallback(this, &MainMenu::loadGame);
|
||||||
|
exit_callback.SetCallback(this, &MainMenu::exit);
|
||||||
|
|
||||||
|
menu = new Menu("./data/background.png", NULL, this);
|
||||||
|
|
||||||
|
menu->addList("Menu", 0, .4);
|
||||||
|
|
||||||
|
menu->addMenuItem("Continue Game", &cont_callback, "Menu", false);
|
||||||
|
menu->addMenuItem("New Game", &new_callback, "Menu", true);
|
||||||
|
menu->addMenuItem("Save Game", &save_callback, "Menu", false);
|
||||||
|
menu->addMenuItem("Load Game", &load_callback, "Menu", true);
|
||||||
|
menu->addMenuItem("Exit", &exit_callback, "Menu", true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(!LoadOgg(".data/title.ogg", &buffer)) {
|
||||||
|
Log::logger->message("Could not load data/title.ogg");
|
||||||
|
}
|
||||||
|
|
||||||
|
SetListener();
|
||||||
|
|
||||||
|
source = GenSource(buffer);
|
||||||
|
|
||||||
|
alSourcePlay(source);
|
||||||
|
*/
|
||||||
|
Log::logger->message("MainMenu initialised");
|
||||||
|
}
|
||||||
|
|
||||||
|
MainMenu::~MainMenu() {
|
||||||
|
|
||||||
|
if(previous == mainGame) previous = NULL;
|
||||||
|
delete mainGame;
|
||||||
|
delete menu;
|
||||||
|
|
||||||
|
// Delete buffer and source
|
||||||
|
/*
|
||||||
|
alSourceStop(source);
|
||||||
|
alDeleteSources(1, &source);
|
||||||
|
alDeleteBuffers(1, &buffer);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Set the static GameState mainMenu back to NULL
|
||||||
|
GameState::setMainMenu(NULL);
|
||||||
|
|
||||||
|
Log::logger->message("MainMenu deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::loop() {
|
||||||
|
menu->loop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::doExit() {
|
||||||
|
*done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::switchTo(GameState *oldState) {
|
||||||
|
if(previous == NULL) {
|
||||||
|
menu->changeEnabled("Continue Game", "Menu", false);
|
||||||
|
menu->changeEnabled("Save Game", "Menu", false);
|
||||||
|
} else {
|
||||||
|
menu->changeEnabled("Continue Game", "Menu", true);
|
||||||
|
menu->changeEnabled("Save Game", "Menu", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu->switchTo(oldState);
|
||||||
|
|
||||||
|
/*
|
||||||
|
SetListener();
|
||||||
|
alSourcePlay(source);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::switchFrom() {
|
||||||
|
//alSourceStop(source);
|
||||||
|
//music.
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::continueGame(int i) {
|
||||||
|
if(previous != NULL) {
|
||||||
|
switchState(previous, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void MainMenu::newGame(int i) {
|
||||||
|
// New game
|
||||||
|
if(mainGame == NULL) {
|
||||||
|
// Create a new game
|
||||||
|
mainGame = new StateSailing();
|
||||||
|
} else {
|
||||||
|
// Just reset existing game
|
||||||
|
mainGame->newGame();
|
||||||
|
}
|
||||||
|
switchState(mainGame, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::saveGame(int i) {
|
||||||
|
// Save the game
|
||||||
|
// Once I allow multiple save games this will need to change
|
||||||
|
|
||||||
|
//Should not try to save if the game has not even started
|
||||||
|
if(mainGame != NULL) {
|
||||||
|
mainGame->saveGame();
|
||||||
|
switchState(mainGame, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::loadGame(int i) {
|
||||||
|
if(mainGame == NULL) {
|
||||||
|
// Need to initialize the gamestate
|
||||||
|
mainGame = new StateSailing();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the game
|
||||||
|
mainGame->loadGame();
|
||||||
|
|
||||||
|
// Now switch to game mode
|
||||||
|
switchState(mainGame, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::exit(int ID) {
|
||||||
|
doExit();
|
||||||
|
}
|
63
src/MainMenu.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MAINMENU_H_
|
||||||
|
#define _MAINMENU_H_
|
||||||
|
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <AL/al.h>
|
||||||
|
#include "GameState.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
|
||||||
|
// So I don't have to include the headers
|
||||||
|
class StateSailing;
|
||||||
|
|
||||||
|
class MainMenu: public GameState {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
MainMenu(bool *doneIn);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~MainMenu();
|
||||||
|
|
||||||
|
// Need to implement the loop function
|
||||||
|
void loop();
|
||||||
|
|
||||||
|
// Need to implement the switchTo function
|
||||||
|
void switchTo(GameState *oldState);
|
||||||
|
|
||||||
|
// Need to implement the switchFrom function
|
||||||
|
void switchFrom();
|
||||||
|
|
||||||
|
// Override the exit function
|
||||||
|
void doExit();
|
||||||
|
|
||||||
|
// Callback functions
|
||||||
|
void continueGame(int i);
|
||||||
|
void newGame(int i);
|
||||||
|
void saveGame(int i);
|
||||||
|
void loadGame(int i);
|
||||||
|
void exit(int i);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Set to false to exit
|
||||||
|
bool *done;
|
||||||
|
|
||||||
|
// Main sailing game state
|
||||||
|
StateSailing *mainGame;
|
||||||
|
|
||||||
|
// Menu class
|
||||||
|
Menu *menu;
|
||||||
|
|
||||||
|
// Callback functions
|
||||||
|
TCallback<MainMenu> cont_callback;
|
||||||
|
TCallback<MainMenu> new_callback;
|
||||||
|
TCallback<MainMenu> save_callback;
|
||||||
|
TCallback<MainMenu> load_callback;
|
||||||
|
TCallback<MainMenu> exit_callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
25
src/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
CC = g++
|
||||||
|
CFLAGS = -ansi -Wall -g
|
||||||
|
LDADD = -lGL -lGLU -lpthread -lSDL -lSDL_image -lopenal -lalut -lvorbisfile -L/usr/X11
|
||||||
|
objects = BoundBox.o Camera.o City.o CityEconomy.o CityManager.o Config.o \
|
||||||
|
Economy.o EnvironmentObject.o Frustum.o GameState.o Log.o MainMenu.o \
|
||||||
|
Map.o Menu.o Model.o Ocean.o Player.o Point.o Product.o QuadBox.o \
|
||||||
|
QuadNode.o Ships.o SkyBox.o StateBattle.o StateCity.o \
|
||||||
|
StateSailing.o Terrain.o Wave.o WaveEmitter.o collisions.o \
|
||||||
|
extensions.o font.o image.o normals.o Cargo.o \
|
||||||
|
tinystr.o tinyxml.o tinyxmlerror.o tinyxmlparser.o
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: default all clean
|
||||||
|
|
||||||
|
default: all
|
||||||
|
|
||||||
|
%.cpp: %.h
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
all: $(objects)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(objects)
|
240
src/Map.cpp
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
#include "StateSailing.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "Map.h"
|
||||||
|
#include "CityManager.h"
|
||||||
|
|
||||||
|
Map::Map(StateSailing *curGame, Player *playerPos) : GameState(curGame) {
|
||||||
|
|
||||||
|
winWidth = Config::configuration->getWinWidth();
|
||||||
|
winHeight = Config::configuration->getWinHeight();
|
||||||
|
|
||||||
|
// Set the pointer to the main sailing state to null
|
||||||
|
mainGame = NULL;
|
||||||
|
|
||||||
|
PlayerMap = playerPos;
|
||||||
|
|
||||||
|
// Load the background
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
BuildTexture("./data/mapscreen.png", &map_background, GL_CLAMP, false);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, map_background);
|
||||||
|
|
||||||
|
curMousePosX = 0;
|
||||||
|
curMousePosY = 0;
|
||||||
|
|
||||||
|
info = false;
|
||||||
|
|
||||||
|
transport = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map::~Map() {
|
||||||
|
glDeleteTextures(1, &map_background);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::loop() {
|
||||||
|
// Draw the scene
|
||||||
|
display();
|
||||||
|
|
||||||
|
// Process incoming events
|
||||||
|
processEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::display() {
|
||||||
|
|
||||||
|
float screenX, screenY;
|
||||||
|
float multi;
|
||||||
|
StateSailing* tempState;
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// Draw the background
|
||||||
|
// Bind the background texture
|
||||||
|
glBindTexture(GL_TEXTURE_2D, map_background);
|
||||||
|
|
||||||
|
// Set the color
|
||||||
|
glColor3f(.6, .6, .6);
|
||||||
|
|
||||||
|
// Draw the actual background quad
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex3f(0, 0, 0);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex3f(0, winHeight, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex3f(winWidth, winHeight, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex3f(winWidth, 0, 0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Need to display the ship somehow!
|
||||||
|
multi = winWidth / 812.0;
|
||||||
|
screenX = (winWidth / 2) + (PlayerMap->x * multi);
|
||||||
|
multi = winHeight / 500.0;
|
||||||
|
screenY = (winHeight / 2) + (PlayerMap->z * multi);
|
||||||
|
|
||||||
|
glColor3f(0, 1, 1); // This is the color of the X
|
||||||
|
|
||||||
|
glLineWidth(3.0);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glVertex3f(screenX - 5.0, screenY + 5.0, 0);
|
||||||
|
glVertex3f(screenX + 5.0, screenY - 5.0, 0);
|
||||||
|
glVertex3f(screenX - 5.0, screenY - 5.0, 0);
|
||||||
|
glVertex3f(screenX + 5.0, screenY + 5.0, 0);
|
||||||
|
glEnd();
|
||||||
|
glLineWidth(1.0);
|
||||||
|
|
||||||
|
// Draw the text -- This is for debugging!
|
||||||
|
if(info) {
|
||||||
|
glTranslatef(0, (float) winHeight * .4, 0);
|
||||||
|
glColor3f(0, 1, 1);
|
||||||
|
|
||||||
|
glPrintf(0, "MapScreen x=%f z=%f", PlayerMap->x, PlayerMap->z);
|
||||||
|
glNewLine();
|
||||||
|
glPrintf(0, "OnMap x=%f y=%f", screenX, screenY);
|
||||||
|
glNewLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
glColor3f(1, 1, 1);
|
||||||
|
|
||||||
|
tempState = (StateSailing*)previous;
|
||||||
|
|
||||||
|
tempState->cities->MapDisplay();
|
||||||
|
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::processEvents() {
|
||||||
|
// Our SDL event placeholder.
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
handle_mouse_move();
|
||||||
|
// Grab all the events off the queue.
|
||||||
|
while( SDL_PollEvent( &event ) ) {
|
||||||
|
switch( event.type ) {
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
//Handle key presses.
|
||||||
|
handle_key_down( &event.key.keysym );
|
||||||
|
break;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
handle_key_up(&event.key.keysym);
|
||||||
|
break;
|
||||||
|
case SDL_QUIT:
|
||||||
|
//Handle quit requests (like Ctrl-c).
|
||||||
|
doExit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::handle_mouse_move() {
|
||||||
|
float multi;
|
||||||
|
Uint8 buttons;
|
||||||
|
|
||||||
|
buttons = SDL_GetMouseState(&curMousePosX, &curMousePosY);
|
||||||
|
|
||||||
|
if((buttons == SDL_BUTTON(1)) && transport) {
|
||||||
|
multi = winWidth / 812.0;
|
||||||
|
PlayerMap->x = -1*((winWidth / 2) - curMousePosX) / multi;
|
||||||
|
multi = winHeight / 500.0;
|
||||||
|
PlayerMap->z = -1*((winHeight / 2) - curMousePosY) / multi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::handle_key_up(SDL_keysym* keysym) {
|
||||||
|
switch(keysym->sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
// Go back to the game, if it is loaded
|
||||||
|
if(previous != NULL) {
|
||||||
|
switchState(previous, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_m:
|
||||||
|
// Go back to the game, if it is loaded
|
||||||
|
if(previous != NULL) {
|
||||||
|
switchState(previous, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_t:
|
||||||
|
// Stop the transport function
|
||||||
|
transport = false;
|
||||||
|
break;
|
||||||
|
case SDLK_i:
|
||||||
|
// Turn info on/off
|
||||||
|
info = ((info) ? false : true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::handle_key_down(SDL_keysym* keysym) {
|
||||||
|
switch( keysym->sym ) {
|
||||||
|
case SDLK_z:
|
||||||
|
takeScreenshot();
|
||||||
|
break;
|
||||||
|
case SDLK_t:
|
||||||
|
transport = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::doExit() {
|
||||||
|
*done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::switchTo(GameState *oldState) {
|
||||||
|
|
||||||
|
EnterTextMode(winWidth, winHeight); // What is this? Why do I need this here?
|
||||||
|
|
||||||
|
transport = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::switchFrom() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::drawGui() {
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glBindTexture(GL_TEXTURE_2D, map_background);
|
||||||
|
|
||||||
|
glColor3f(0, 0, 0);
|
||||||
|
|
||||||
|
//Draw quad for map
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0,0);
|
||||||
|
glVertex3f(10, winHeight - 250, 0);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex3f(10, winHeight - 10, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex3f(370, winHeight - 10, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex3f(370, winHeight - 250, 0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glColor3f(1, 1, 1);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
75
src/Map.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _MAP_H_
|
||||||
|
|
||||||
|
#define _MAP_H_
|
||||||
|
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include "GameState.h"
|
||||||
|
// So I do not have to include the headers.
|
||||||
|
class StateSailing;
|
||||||
|
|
||||||
|
class Map: public GameState {
|
||||||
|
public:
|
||||||
|
//Constructor
|
||||||
|
Map(StateSailing *curGame, Player *playerPos);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
virtual ~Map();
|
||||||
|
|
||||||
|
// Need to implement the loop function
|
||||||
|
void loop();
|
||||||
|
|
||||||
|
void switchTo(GameState *oldState);
|
||||||
|
|
||||||
|
void switchFrom();
|
||||||
|
|
||||||
|
void doExit();
|
||||||
|
|
||||||
|
// I plan on drawing the map in the upper left corner of the screen while sailing. let's see.
|
||||||
|
void drawGui();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Set to false to exit
|
||||||
|
bool *done;
|
||||||
|
|
||||||
|
// Background texture
|
||||||
|
GLuint map_background;
|
||||||
|
|
||||||
|
// Number of menu items
|
||||||
|
//int numItems;
|
||||||
|
|
||||||
|
// Selected menu item
|
||||||
|
// int selected;
|
||||||
|
|
||||||
|
// Handles processing SDL events
|
||||||
|
void processEvents();
|
||||||
|
|
||||||
|
// Main sailing game state
|
||||||
|
StateSailing *mainGame;
|
||||||
|
|
||||||
|
// Player, we will need to get our position on the map
|
||||||
|
Player *PlayerMap;
|
||||||
|
|
||||||
|
// Keyboard handler functions
|
||||||
|
void handle_key_up(SDL_keysym* keysym);
|
||||||
|
void handle_key_down(SDL_keysym* keysym);
|
||||||
|
void handle_mouse_move();
|
||||||
|
|
||||||
|
void display();
|
||||||
|
|
||||||
|
int winWidth;
|
||||||
|
int winHeight;
|
||||||
|
|
||||||
|
int curMousePosX;
|
||||||
|
int curMousePosY;
|
||||||
|
|
||||||
|
bool transport;
|
||||||
|
bool info;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
391
src/Menu.cpp
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*
|
||||||
|
* This class is intended to be a base class for all the menu systems
|
||||||
|
* in Lephisto. this will extend the GameState class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "Config.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Menu::Menu(const char* image, GameState *from, GameState *to): GameState(NULL) {
|
||||||
|
// Bool valie to set to quit
|
||||||
|
done = false;
|
||||||
|
|
||||||
|
// Make Set from and to gamestates
|
||||||
|
fromState = from;
|
||||||
|
toState = to;
|
||||||
|
|
||||||
|
// Get ready for text mode
|
||||||
|
EnterTextMode(Config::configuration->getWinWidth(),
|
||||||
|
Config::configuration->getWinHeight());
|
||||||
|
|
||||||
|
// Load the background
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
BuildTexture(image, &background, GL_CLAMP, false);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, background);
|
||||||
|
|
||||||
|
Selected = 0;
|
||||||
|
ButtonID = 0;
|
||||||
|
mouseActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu::~Menu() {
|
||||||
|
unsigned int i;
|
||||||
|
glDeleteTextures(1, &background);
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
delete lists[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
lists.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::loop() {
|
||||||
|
while(!lists[Selected]->Select()) {
|
||||||
|
Selected += 1;
|
||||||
|
if(Selected > (int) lists.size()) Selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the menu
|
||||||
|
display();
|
||||||
|
|
||||||
|
// Process incoming events
|
||||||
|
processEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::display() {
|
||||||
|
int width = Config::configuration->getWinWidth();
|
||||||
|
int height = Config::configuration->getWinHeight();
|
||||||
|
int i;
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// Draw the background
|
||||||
|
// Bind the background texture
|
||||||
|
glBindTexture(GL_TEXTURE_2D, background);
|
||||||
|
|
||||||
|
// Set the color
|
||||||
|
glColor3f(.8, .8, .8);
|
||||||
|
|
||||||
|
// Draw the actual background quad
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex3f(0, 0 , 0);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex3f(0, height, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex3f(width, height, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex3f(width, 0, 0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Draw the text.
|
||||||
|
for(i = 0; i < (signed)lists.size(); i++) {
|
||||||
|
glLoadIdentity();
|
||||||
|
//glTranslatef((float) width * lists[i].x, (float) height * lists[i].y, 0);
|
||||||
|
lists[i]->Display();
|
||||||
|
}
|
||||||
|
glColor3f(1, 1, 1);
|
||||||
|
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::processEvents() {
|
||||||
|
// Our SDL event placeholder
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
handle_mouse();
|
||||||
|
|
||||||
|
// Grab all the events off the queue
|
||||||
|
while(SDL_PollEvent(&event)) {
|
||||||
|
switch(event.type) {
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
// Handle key presses
|
||||||
|
handle_key_down(&event.key.keysym);
|
||||||
|
break;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
handle_key_up(&event.key.keysym);
|
||||||
|
break;
|
||||||
|
case SDL_QUIT:
|
||||||
|
// Handle quit requests (like Ctrl-c)
|
||||||
|
doExit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::handle_key_up(SDL_keysym* keysym) {
|
||||||
|
switch(keysym->sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
// Go back to the game, if it is loaded anyway.
|
||||||
|
if((fromState != NULL) && (toState != NULL)) {
|
||||||
|
switchState(fromState, toState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_RETURN:
|
||||||
|
lists[Selected]->Execute();
|
||||||
|
break;
|
||||||
|
case SDLK_p:
|
||||||
|
Print();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::handle_key_down(SDL_keysym* keysym) {
|
||||||
|
mouseActive = false;
|
||||||
|
int newSelected;
|
||||||
|
|
||||||
|
switch(keysym->sym) {
|
||||||
|
case SDLK_UP:
|
||||||
|
lists[Selected]->SelectionUp();
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
lists[Selected]->SelectionDown();
|
||||||
|
break;
|
||||||
|
case SDLK_LEFT:
|
||||||
|
newSelected = Selected - 1;
|
||||||
|
if(newSelected < 0) newSelected = lists.size() - 1;
|
||||||
|
while(!lists[newSelected]->Select()) {
|
||||||
|
newSelected -= 1;
|
||||||
|
if(newSelected < 0) newSelected = lists.size() - 1;
|
||||||
|
}
|
||||||
|
lists[Selected]->Deselect();
|
||||||
|
Selected = newSelected;
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
newSelected = Selected + 1;
|
||||||
|
if(newSelected >= (int) lists.size()) newSelected = 0;
|
||||||
|
while(!lists[newSelected]->Select()) {
|
||||||
|
newSelected += 1;
|
||||||
|
if(newSelected >= (int) lists.size()) newSelected = 0;
|
||||||
|
}
|
||||||
|
lists[Selected]->Deselect();
|
||||||
|
Selected = newSelected;
|
||||||
|
break;
|
||||||
|
case SDLK_z:
|
||||||
|
takeScreenshot();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::doExit() {
|
||||||
|
*done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::switchTo(GameState *oldState) {
|
||||||
|
// Set selected to return to game
|
||||||
|
Selected = 0;
|
||||||
|
|
||||||
|
while(!lists[Selected]->Select()) {
|
||||||
|
Selected += 1;
|
||||||
|
if(Selected > (int) lists.size()) Selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
EnterTextMode(Config::configuration->getWinWidth(),
|
||||||
|
Config::configuration->getWinHeight());
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::switchFrom() {
|
||||||
|
lists[Selected]->Deselect();
|
||||||
|
Selected = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::addList(string Name, float x, float y) {
|
||||||
|
MenuContainer *tempContainer;
|
||||||
|
|
||||||
|
tempContainer = new MenuContainer(Name, x, y, maLeft);
|
||||||
|
|
||||||
|
lists.push_back(tempContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::addList(string Name, float x, float y, int alignment) {
|
||||||
|
MenuContainer *tempContainer;
|
||||||
|
|
||||||
|
if((alignment < maLeft) || (alignment > maRight))
|
||||||
|
addList(Name, x, y);
|
||||||
|
|
||||||
|
tempContainer = new MenuContainer(Name, x, y, alignment);
|
||||||
|
lists.push_back(tempContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Menu::addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->GetName() == List) {
|
||||||
|
lists[i]->AddButton(Text, recallFunc, enabled, ButtonID);
|
||||||
|
ButtonID++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ButtonID - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Menu::addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled, float red, float green, float blue) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->GetName() == List) {
|
||||||
|
lists[i]->AddButton(Text, recallFunc, enabled, ButtonID, red, green, blue);
|
||||||
|
ButtonID++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ButtonID - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::addDataItem(string Text, string List) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->GetName() == List) {
|
||||||
|
lists[i]->AddData(Text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::addDataItem(string Text, string List, float red, float green, float blue) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->GetName() == List) {
|
||||||
|
lists[i]->AddData(Text, red, green, blue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::changeEnabled(string Text, string List, bool enabled) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->GetName() == List) {
|
||||||
|
lists[i]->ChangeEnabled(Text, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::handle_mouse() {
|
||||||
|
unsigned int i;
|
||||||
|
Uint8 buttons;
|
||||||
|
|
||||||
|
buttons = SDL_GetMouseState(&curMousePosX, &curMousePosY);
|
||||||
|
|
||||||
|
if((!mouseActive) && (!((curMousePosX == lastMousePosX) && (curMousePosY == lastMousePosY))))
|
||||||
|
mouseActive = true;
|
||||||
|
|
||||||
|
buttonDown = MouseButtonDown(buttons, 1);
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if(lists[i]->LocationWithin(curMousePosX, curMousePosY)) {
|
||||||
|
if(lists[i]->MouseSelect(curMousePosX, curMousePosY)) {
|
||||||
|
if(Selected != (int) i) {
|
||||||
|
lists[Selected]->Deselect();
|
||||||
|
Selected = i;
|
||||||
|
}
|
||||||
|
if(mouseActive && buttonDown) {
|
||||||
|
lists[Selected]->Execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastMousePosX = curMousePosX;
|
||||||
|
lastMousePosY = curMousePosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Menu::MouseLocToMenu(int locX, int locY) {
|
||||||
|
/*
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++) {
|
||||||
|
if((locX >= lists[i].TopLeftX)
|
||||||
|
&& (locX <= lists[i].BottomRightX)
|
||||||
|
&& (locY >= lists[i].TopLeftY)
|
||||||
|
&& (locY <= lists[i].BottomRightY)) {
|
||||||
|
|
||||||
|
hSelected = (int) i;
|
||||||
|
return ContainerSelection(locX, locY, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Menu::ContainerSelection(int locX, int locY, int container) {
|
||||||
|
/*
|
||||||
|
unsigned int i;
|
||||||
|
float vertical;
|
||||||
|
menuItem* tempItem;
|
||||||
|
|
||||||
|
vertical = lists[container].TopLeftY;
|
||||||
|
//tempItem = lists[container];
|
||||||
|
|
||||||
|
for(i = 0; i < lists[container].menuItems.size(); i++) {
|
||||||
|
tempItem = &lists[container].menuItems[i];
|
||||||
|
if((locY > (vertical + (18 * tempItem->order))
|
||||||
|
&& (locY < (vertical + (18 * (tempItem->order + 1)))))) {
|
||||||
|
|
||||||
|
vSelected = (int) i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::Print() {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < lists.size(); i++)
|
||||||
|
lists[i]->Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Menu::MouseButtonDown(Uint8 buttons, int buttonNumber) {
|
||||||
|
if(((buttons & buttonNumber) == buttonNumber) && ((lastButtonState & buttonNumber) == buttonNumber)) {
|
||||||
|
lastButtonState = buttons;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((buttons & buttonNumber) == buttonNumber) && ((lastButtonState & buttonNumber) != buttonNumber)) {
|
||||||
|
lastButtonState = buttons;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastButtonState = buttons;
|
||||||
|
return false;
|
||||||
|
}
|
198
src/Menu.h
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*
|
||||||
|
* The Menu Class is used as out basis for any of the menus in the game.
|
||||||
|
* It has functionality to create lists of buttons or to display data
|
||||||
|
* on top of a background image. There are a number of improvements
|
||||||
|
* which could be made to the Menu class (animation, better mouse control,
|
||||||
|
* changes in font, color, different kinds of input like a text box
|
||||||
|
* control, etc.) but at the moment, this is simple and functional.
|
||||||
|
*
|
||||||
|
*##############################################################################
|
||||||
|
* This is just a brief overview of the functionality of the new menu class.
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* For a start, it is a child class of GameState. So it inherits all the
|
||||||
|
* functionality of the parent. Usualy you aren't going to give it full
|
||||||
|
* control of execution. You'll have another GameState call menu->loop()
|
||||||
|
* inside its own loop(). This also means that you need to call menu->switchTo()
|
||||||
|
* in your other GameStates switchTo() class, because there is some important
|
||||||
|
* display code that won't load if you don't. (Look at the way MainMenu.cpp is set up
|
||||||
|
* if you are confused.
|
||||||
|
*
|
||||||
|
* The constructor is typical, it takes a background image as an argument. It
|
||||||
|
* is then ready to be displayed with loop().
|
||||||
|
*
|
||||||
|
* The menu functionality of the class is found in two structures: Lists and
|
||||||
|
* items... If you think about how a menu is displayed, there are different
|
||||||
|
* options one on top of the next. So the idea of a lists is that it is the
|
||||||
|
* container for those options. Having this structure allows you to have different
|
||||||
|
* lists in different parts of the screen.
|
||||||
|
*
|
||||||
|
* To create a list, you'll use a Menu::addList(string Name, float x, float y).
|
||||||
|
* The name is realy important. It is how you get back to the list you have
|
||||||
|
* created. The two float arguments are the location on the location on the screen. The location
|
||||||
|
* is a percentage of the screen, so you're limited to between 1 and 0. It won't
|
||||||
|
* error check this because it just means you won't be able to see the list.
|
||||||
|
*
|
||||||
|
* To add items to the list, there are two different items you have access to.
|
||||||
|
* MenuItems are selectable. You need to provide the text to display, a callback
|
||||||
|
* function, which list you want it to be part of and whether or not it's
|
||||||
|
* selectable. You can change if it's selectable or not. Each MenuItem in a menu
|
||||||
|
* gets a unique ID which is returned when you call Menu::addMenuItem. This can
|
||||||
|
* be used to identify which button was pressed, or used to modify the buttons
|
||||||
|
* if needed. The recall function is is relatively complex, so you'll need to
|
||||||
|
* look at either MainMenu or StateCity to see it in use.
|
||||||
|
* The recall functions are void and takes one argument (int).
|
||||||
|
* This argument is the ID of the button which was pressed, so that mutiple
|
||||||
|
* buttons can use the same recall function and still distinguish between which
|
||||||
|
* called the recall function. At this point, there is no other kind of
|
||||||
|
* function allowed.
|
||||||
|
*
|
||||||
|
* The other kind of item is a data item. This needs no callback function because
|
||||||
|
* it can never be selected. It's handy when you need to just display information
|
||||||
|
* (say for example the economy in a city).
|
||||||
|
*
|
||||||
|
* Menu::changeEnabled(string Text, string List, bool enabled) moves a menu item
|
||||||
|
* from being enabled or not depending on if you pass false or true to the final
|
||||||
|
* argument.
|
||||||
|
*
|
||||||
|
* Menu::switchToData and Menu::switchToMenu are not fully tested and probably don't work.
|
||||||
|
* Please don't use them.
|
||||||
|
*#######################################################################################
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MENU_H_
|
||||||
|
#define _MENU_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "SDL/SDL.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
#include "StateSailing.h"
|
||||||
|
#include "Menu/MenuContainer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
typedef enum {maLeft, maCenter, maRight} MenuAlignment;
|
||||||
|
|
||||||
|
class Menu: public GameState {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Menu(const char* image, GameState *from, GameState *to);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Menu();
|
||||||
|
|
||||||
|
// Need to implement the loop function
|
||||||
|
void loop();
|
||||||
|
|
||||||
|
// Need to implement the switchTo function
|
||||||
|
void switchTo(GameState *oldState);
|
||||||
|
|
||||||
|
// Need to implement the switchFrom function
|
||||||
|
void switchFrom();
|
||||||
|
|
||||||
|
// Override the exit function
|
||||||
|
void doExit();
|
||||||
|
|
||||||
|
// Add a list
|
||||||
|
void addList(string Name, float x, float y);
|
||||||
|
void addList(string Name, float x, float y, int alignment);
|
||||||
|
|
||||||
|
// Add a menu item
|
||||||
|
int addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled);
|
||||||
|
//int addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled, GLuint image);
|
||||||
|
int addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled, float red, float green, float blue);
|
||||||
|
//int addMenuItem(string Text, cCallback *recallFunc, string List, bool enabled, GLuint image,
|
||||||
|
//float red, float green, float blue);
|
||||||
|
|
||||||
|
// Add a data item
|
||||||
|
void addDataItem(string Text, string List); // Doesn't need a callback because it is not selectable
|
||||||
|
//void addDataItem(string Text, string List, GLuint image);
|
||||||
|
void addDataItem(string Text, string List, float red, float green, float blue);
|
||||||
|
|
||||||
|
// Enable/Disable a menu Item
|
||||||
|
void changeEnabled(string Text, string List, bool enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
// Set to false to exit
|
||||||
|
bool *done;
|
||||||
|
|
||||||
|
// Background texture
|
||||||
|
GLuint background;
|
||||||
|
|
||||||
|
// Menu lists
|
||||||
|
vector<MenuContainer*> lists;
|
||||||
|
|
||||||
|
// Selected list item
|
||||||
|
int Selected;
|
||||||
|
|
||||||
|
// Handles processing SDL events
|
||||||
|
void processEvents();
|
||||||
|
|
||||||
|
// Keyboard handler functions
|
||||||
|
void handle_key_up(SDL_keysym* keysym);
|
||||||
|
void handle_key_down(SDL_keysym* keysym);
|
||||||
|
|
||||||
|
// Mouse functions
|
||||||
|
void handle_mouse();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MouseButtonDown takes a button number
|
||||||
|
* (Left = 1, Middle = 2, Right = 3),
|
||||||
|
* and the current butons pressed, it
|
||||||
|
* tells you true if this is the first frame
|
||||||
|
* in which the button was pressed. So it
|
||||||
|
* will not return true every frame the button
|
||||||
|
* is pressed, but only the first time for
|
||||||
|
* each click.
|
||||||
|
* to find out if the buttin is pressed every fram try:
|
||||||
|
* buttonDown = (buttons == SDL_BUTTON(buttonNumber));
|
||||||
|
*/
|
||||||
|
bool MouseButtonDown(Uint8 buttons, int buttonNumber);
|
||||||
|
Uint8 lastButtonState;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MouseLocToMenu translates the location
|
||||||
|
* of the mouse to the corresponding button
|
||||||
|
* on the menu. It returns true if it is
|
||||||
|
* within a button, and false otherwise.
|
||||||
|
* It also changes the hSelected if it needs to.
|
||||||
|
*/
|
||||||
|
bool MouseLocToMenu(int locX, int locY);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is similar to MoseLocToMenu exept
|
||||||
|
* its at the listContainer level and it will
|
||||||
|
* change vSelected.
|
||||||
|
*/
|
||||||
|
bool ContainerSelection(int locX, int locY, int container);
|
||||||
|
|
||||||
|
// Mouse variables
|
||||||
|
int curMousePosX;
|
||||||
|
int curMousePosY;
|
||||||
|
int lastMousePosX;
|
||||||
|
int lastMousePosY;
|
||||||
|
bool buttonDown;
|
||||||
|
bool mouseActive;
|
||||||
|
|
||||||
|
// Gamestates for switching
|
||||||
|
GameState *fromState;
|
||||||
|
GameState *toState;
|
||||||
|
|
||||||
|
void display();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ButtonID is a unique identifier for each button,
|
||||||
|
* it can be used instead of the name of the button,
|
||||||
|
* and the name of the list together. It is also used
|
||||||
|
* in callback situations.
|
||||||
|
*/
|
||||||
|
int ButtonID;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
124
src/Menu/Button.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "../font.h"
|
||||||
|
#include "../Log.h"
|
||||||
|
#include "DataContainer.h"
|
||||||
|
#include "Button.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Button::Button(string Text, cCallback *recallFunc, bool enabled,
|
||||||
|
int ID): DataContainer(Text) {
|
||||||
|
reFunc = recallFunc;
|
||||||
|
amIEnabled = enabled;
|
||||||
|
myID = ID;
|
||||||
|
selected = false;
|
||||||
|
|
||||||
|
if(enabled) {
|
||||||
|
redColor = .8;
|
||||||
|
blueColor = .8;
|
||||||
|
greenColor = .8;
|
||||||
|
}
|
||||||
|
|
||||||
|
permRed = redColor;
|
||||||
|
permBlue = blueColor;
|
||||||
|
permGreen = greenColor;
|
||||||
|
amISelectable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Button::Button(string Text, float red, float green, float blue,
|
||||||
|
cCallback *recallFunc, bool enabled,
|
||||||
|
int ID): DataContainer(Text, red, green, blue) {
|
||||||
|
reFunc = recallFunc;
|
||||||
|
amIEnabled = enabled;
|
||||||
|
myID = ID;
|
||||||
|
selected = false;
|
||||||
|
|
||||||
|
permRed = red;
|
||||||
|
permGreen = green;
|
||||||
|
permBlue = blue;
|
||||||
|
amISelectable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Button::~Button() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::ChangeCallback(cCallback *recallFunc) {
|
||||||
|
reFunc = recallFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::ChangeEnabled(bool enabled) {
|
||||||
|
amIEnabled = enabled;
|
||||||
|
|
||||||
|
if(enabled) {
|
||||||
|
redColor = .8;
|
||||||
|
blueColor = .8;
|
||||||
|
greenColor = .8;
|
||||||
|
} else {
|
||||||
|
redColor = .2;
|
||||||
|
blueColor = .2;
|
||||||
|
greenColor = .2;
|
||||||
|
}
|
||||||
|
|
||||||
|
permRed = redColor;
|
||||||
|
permBlue = blueColor;
|
||||||
|
permGreen = greenColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::Execute() {
|
||||||
|
reFunc->Execute(myID);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Button::GetEnabled() {
|
||||||
|
return amIEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Button::GetID() {
|
||||||
|
return myID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::Select() {
|
||||||
|
selected = true;
|
||||||
|
|
||||||
|
redColor = 0;
|
||||||
|
greenColor = 1;
|
||||||
|
blueColor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::Deselect() {
|
||||||
|
selected = false;
|
||||||
|
|
||||||
|
redColor = permRed;
|
||||||
|
greenColor = permGreen;
|
||||||
|
blueColor = permBlue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Button::Selectable() {
|
||||||
|
return amIEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::Print() {
|
||||||
|
Log::logger->message("\n\tText:\t%s", myText.c_str());
|
||||||
|
if (amIEnabled)
|
||||||
|
Log::logger->message("\tSelectable:\tTrue");
|
||||||
|
else
|
||||||
|
Log::logger->message("\tSelectable:\tFalse");
|
||||||
|
if (selected)
|
||||||
|
Log::logger->message("\tSelected:\tTrue");
|
||||||
|
else
|
||||||
|
Log::logger->message("\tSelected:\tFalse");
|
||||||
|
Log::logger->message("\tID:\t%i", myID);
|
||||||
|
Log::logger->message("\tColor RGB:\t%i %i %i", redColor, greenColor, blueColor);
|
||||||
|
}
|
56
src/Menu/Button.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BUTTON_H_
|
||||||
|
#define _BUTTON_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../Callback.h"
|
||||||
|
#include "DataContainer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Button: DataContainer {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Button(string Text, cCallback *recallFunc, bool enabled, int ID);
|
||||||
|
Button(string Text, float red, float green, float blue,
|
||||||
|
cCallback *recallFunc, bool enabled, int ID);
|
||||||
|
|
||||||
|
// Deconstructor
|
||||||
|
~Button();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
void ChangeEnabled(bool enabled);
|
||||||
|
bool GetEnabled();
|
||||||
|
|
||||||
|
void ChangeCallback(cCallback *recallFunc);
|
||||||
|
|
||||||
|
int GetID();
|
||||||
|
|
||||||
|
void Select();
|
||||||
|
void Deselect();
|
||||||
|
|
||||||
|
void Execute();
|
||||||
|
|
||||||
|
bool Selectable();
|
||||||
|
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
private:
|
||||||
|
cCallback *reFunc;
|
||||||
|
|
||||||
|
bool amIEnabled;
|
||||||
|
int myID;
|
||||||
|
|
||||||
|
bool selected;
|
||||||
|
|
||||||
|
float permRed;
|
||||||
|
float permGreen;
|
||||||
|
float permBlue;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
76
src/Menu/DataContainer.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "../font.h"
|
||||||
|
#include "../Log.h"
|
||||||
|
#include "DataContainer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
DataContainer::DataContainer(string Text) {
|
||||||
|
myText = Text;
|
||||||
|
redColor = 0.2;
|
||||||
|
blueColor = 0.2;
|
||||||
|
greenColor = 0.2;
|
||||||
|
|
||||||
|
amISelectable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataContainer::DataContainer(string Text, float red, float green, float blue) {
|
||||||
|
myText = Text;
|
||||||
|
redColor = red;
|
||||||
|
blueColor = blue;
|
||||||
|
greenColor = green;
|
||||||
|
|
||||||
|
amISelectable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataContainer::~DataContainer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataContainer::ChangeText(string Text) {
|
||||||
|
myText = Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
string DataContainer::GetText() {
|
||||||
|
return myText;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataContainer::Display() {
|
||||||
|
float color[4];
|
||||||
|
|
||||||
|
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||||
|
|
||||||
|
glColor3f(redColor, greenColor, blueColor);
|
||||||
|
glPrint(myText.c_str(), 0);
|
||||||
|
|
||||||
|
glColor3f(color[0], color[1], color[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataContainer::Selectable() {
|
||||||
|
return amISelectable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataContainer::Print() {
|
||||||
|
Log::logger->message("\n\tText:\t%s", myText.c_str());
|
||||||
|
if(amISelectable)
|
||||||
|
Log::logger->message("\tSelectable:\tTrue");
|
||||||
|
else
|
||||||
|
Log::logger->message("\tSelectable:\tFalse");
|
||||||
|
Log::logger->message("\tColor RGB:\t%i %i %i", redColor, greenColor, blueColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataContainer::GetLength() {
|
||||||
|
return (int)myText.length();
|
||||||
|
}
|
53
src/Menu/DataContainer.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*
|
||||||
|
* This class is the parent of the button class. It is
|
||||||
|
* what text or data is displayed with. It is also what
|
||||||
|
* the button will derive.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DATACONTAINER_H_
|
||||||
|
#define _DATACONTAINER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DataContainer {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
DataContainer(string Text);
|
||||||
|
DataContainer(string Text, float red, float green, float blue);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
virtual ~DataContainer();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
void ChangeText(string Text);
|
||||||
|
string GetText();
|
||||||
|
|
||||||
|
void Display();
|
||||||
|
|
||||||
|
void SetColor(float red, float green, float blue);
|
||||||
|
|
||||||
|
int GetLength();
|
||||||
|
|
||||||
|
virtual bool Selectable();
|
||||||
|
|
||||||
|
virtual void Print();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
string myText;
|
||||||
|
|
||||||
|
float redColor;
|
||||||
|
float greenColor;
|
||||||
|
float blueColor;
|
||||||
|
|
||||||
|
bool amISelectable; // ???????????
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
18
src/Menu/Makefile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
CC = g++
|
||||||
|
CFLAGS = -ansi -Wall -g
|
||||||
|
LDADD = -lGL -lGLU -lpthread -lSDL -lSDL_image -lopenal -lalut -lvorbisfile -L/usr/X11
|
||||||
|
objects = Button.o DataContainer.o MenuContainer.o
|
||||||
|
|
||||||
|
.PHONY: default all clean
|
||||||
|
|
||||||
|
default: all
|
||||||
|
|
||||||
|
%.cpp: %.h
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
all: $(objects)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(objects)
|
300
src/Menu/MenuContainer.cpp
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "../font.h"
|
||||||
|
#include "../Callback.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
#include "../Log.h"
|
||||||
|
#include "../Menu.h"
|
||||||
|
#include "DataContainer.h"
|
||||||
|
#include "Button.h"
|
||||||
|
#include "MenuContainer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
MenuContainer::MenuContainer(string name, float x, float y, int alignment) {
|
||||||
|
myName = name;
|
||||||
|
locX = x;
|
||||||
|
locY = y;
|
||||||
|
|
||||||
|
TopLeftX = (float)Config::configuration->getWinWidth() * x;
|
||||||
|
TopLeftY = (float)Config::configuration->getWinHeight() * y;
|
||||||
|
BottomRightX = TopLeftX;
|
||||||
|
BottomRightY = TopLeftY;
|
||||||
|
|
||||||
|
align = alignment;
|
||||||
|
|
||||||
|
selected = false;
|
||||||
|
button = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuContainer::~MenuContainer() {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < list.size(); i++)
|
||||||
|
delete list[i];
|
||||||
|
|
||||||
|
list.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::AddButton(string Text, cCallback *recallFunc, bool enabled, int ID) {
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
tempButton = new Button(Text, recallFunc, enabled, ID);
|
||||||
|
list.push_back((DataContainer*)tempButton);
|
||||||
|
|
||||||
|
BottomRightY += 18;
|
||||||
|
if ((BottomRightX - TopLeftX) < (Text.length() * 16))
|
||||||
|
BottomRightX = TopLeftX + (Text.length() * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::AddButton(string Text, cCallback *recallFunc, bool enabled, int ID, float red, float green, float blue) {
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
tempButton = new Button(Text, red, green, blue, recallFunc, enabled, ID);
|
||||||
|
list.push_back((DataContainer*)tempButton);
|
||||||
|
|
||||||
|
BottomRightY += 18;
|
||||||
|
if((BottomRightX - TopLeftX) < (Text.length() * 16))
|
||||||
|
BottomRightX = TopLeftX + (Text.length() * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::AddData(string Text) {
|
||||||
|
DataContainer *tempContainer;
|
||||||
|
|
||||||
|
tempContainer = new DataContainer(Text);
|
||||||
|
list.push_back(tempContainer);
|
||||||
|
|
||||||
|
BottomRightY += 18;
|
||||||
|
if ((BottomRightX - TopLeftX) < (Text.length() * 16))
|
||||||
|
BottomRightX = TopLeftX + (Text.length() * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::AddData(string Text, float red, float green, float blue) {
|
||||||
|
DataContainer *tempContainer;
|
||||||
|
|
||||||
|
tempContainer = new DataContainer(Text, red, green, blue);
|
||||||
|
list.push_back(tempContainer);
|
||||||
|
|
||||||
|
BottomRightY += 18;
|
||||||
|
if((BottomRightX - TopLeftX) < (Text.length() * 16))
|
||||||
|
BottomRightX = TopLeftX + (Text.length() * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::Display() {
|
||||||
|
unsigned int i;
|
||||||
|
float alignTranslate;
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glTranslatef(TopLeftX, TopLeftY, 0.0);
|
||||||
|
|
||||||
|
for (i = 0; i < list.size(); i++) {
|
||||||
|
alignTranslate = 0.0;
|
||||||
|
if(align == maCenter) {
|
||||||
|
// If the text is centered, we need to move it left half its length
|
||||||
|
alignTranslate = (float)((list[i]->GetLength() * 10) / 2);
|
||||||
|
} else if(align == maRight) {
|
||||||
|
// If the text is right alligned, move it left the whole length
|
||||||
|
alignTranslate = (float)(list[i]->GetLength() * 10);
|
||||||
|
}
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef((-1.0) * alignTranslate, 0, 0);
|
||||||
|
list[i]->Display();
|
||||||
|
glPopMatrix();
|
||||||
|
glNewLine();
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuContainer::LocationWithin(int x, int y) {
|
||||||
|
|
||||||
|
if ((x >= TopLeftX) && (x <= BottomRightX) && (y >= TopLeftY) && (y <= BottomRightY)) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (i = 0; i < list.size(); i++) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempItem = (Button*)list[i];
|
||||||
|
if ((locY > (TopLeftY + (18 * i)) && (locY < (TopLeftY + (18 * (i + 1)))))) {
|
||||||
|
|
||||||
|
tempItem->Select();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::SelectionDown() {
|
||||||
|
unsigned int i;
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
if (!selected) return;
|
||||||
|
|
||||||
|
for (i = button + 1; i < list.size(); i++) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempButton = (Button*)list[i];
|
||||||
|
tempButton->Select();
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Deselect();
|
||||||
|
button = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; (int) i < button; i++) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempButton = (Button*)list[i];
|
||||||
|
tempButton->Select();
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Deselect();
|
||||||
|
button = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::SelectionUp() {
|
||||||
|
int i;
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
if (!selected) return;
|
||||||
|
|
||||||
|
for (i = button - 1; i >= 0; i--) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempButton = (Button*)list[i];
|
||||||
|
tempButton->Select();
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Deselect();
|
||||||
|
button = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = (int)list.size() - 1; i > button; i--) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempButton = (Button*)list[i];
|
||||||
|
tempButton->Select();
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Deselect();
|
||||||
|
button = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuContainer::Select() {
|
||||||
|
unsigned int i;
|
||||||
|
Button* tempButton;
|
||||||
|
|
||||||
|
if (selected) return true;
|
||||||
|
|
||||||
|
for (i = 0; i < list.size(); i++) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
button = i;
|
||||||
|
tempButton = (Button*)list[i];
|
||||||
|
tempButton->Select();
|
||||||
|
selected = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::Deselect() {
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
if (!selected) return;
|
||||||
|
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Deselect();
|
||||||
|
button = -1;
|
||||||
|
selected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string MenuContainer::GetName() {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::Execute() {
|
||||||
|
Button *tempButton;
|
||||||
|
|
||||||
|
if (!selected) {
|
||||||
|
Log::logger->message("Error: MenuContainer not Selected!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tempButton = (Button*)list[button];
|
||||||
|
tempButton->Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::Print() {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
Log::logger->message("-----------------");
|
||||||
|
Log::logger->message("List:\t%s", myName.c_str());
|
||||||
|
Log::logger->message("-----------------");
|
||||||
|
for (i = 0; i < list.size(); i++)
|
||||||
|
list[i]->Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuContainer::ChangeEnabled(string Text, bool enabled) {
|
||||||
|
unsigned int i;
|
||||||
|
Button* tempButton;
|
||||||
|
|
||||||
|
for (i = 0; i < list.size(); i++) {
|
||||||
|
if (list[i]->GetText() == Text) {
|
||||||
|
tempButton = (Button*) list[i];
|
||||||
|
tempButton->ChangeEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuContainer::MouseSelect(int x, int y) {
|
||||||
|
unsigned int i;
|
||||||
|
Button* tempItem;
|
||||||
|
|
||||||
|
for (i = 0; i < list.size(); i++) {
|
||||||
|
if (list[i]->Selectable()) {
|
||||||
|
tempItem = (Button*)list[i];
|
||||||
|
if ((y > (TopLeftY + (18 * i)) && (y < (TopLeftY + (18 * (i + 1)))))) {
|
||||||
|
|
||||||
|
// This short circuits the problem of
|
||||||
|
// hovering. If you hover over a button
|
||||||
|
// without this line, it will always
|
||||||
|
// select and deselect the same button...
|
||||||
|
// not a good thing.
|
||||||
|
if (button == (int) i) return true;
|
||||||
|
|
||||||
|
tempItem->Select();
|
||||||
|
if (button != -1) {
|
||||||
|
tempItem = (Button*)list[button];
|
||||||
|
tempItem->Deselect();
|
||||||
|
}
|
||||||
|
button = i;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
79
src/Menu/MenuContainer.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MENUCONTAINER_H_
|
||||||
|
#define _MENUCONTAINER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "../Callback.h"
|
||||||
|
#include "DataContainer.h"
|
||||||
|
#include "Button.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class MenuContainer {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
MenuContainer(string name, float x, float y, int alignment);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~MenuContainer();
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
void AddButton(string Text, cCallback *recallFunc, bool enabled, int ID);
|
||||||
|
void AddButton(string Text, cCallback *recallFunc, bool enabled, int ID, float red, float green, float blue);
|
||||||
|
void AddData(string Text);
|
||||||
|
void AddData(string Text, float red, float green, float blue);
|
||||||
|
|
||||||
|
// These two methods are for mouse handling.
|
||||||
|
// The first simply returns if the mouse is
|
||||||
|
// within the MenuContainer. The second should
|
||||||
|
// only get called if the first returns true.
|
||||||
|
// MouseSelect changes the selection if
|
||||||
|
// appropriate and returns true, or it does
|
||||||
|
// nothing and returns false.
|
||||||
|
bool LocationWithin(int x, int y);
|
||||||
|
bool MouseSelect(int x, int y);
|
||||||
|
|
||||||
|
void Display();
|
||||||
|
|
||||||
|
// These methods move the selected item up and down the list
|
||||||
|
void SelectionDown();
|
||||||
|
void SelectionUp();
|
||||||
|
|
||||||
|
// This tells this list that it is selected and can display
|
||||||
|
// one of its items as such. It returns true if it has some
|
||||||
|
// selectable items and false if not.
|
||||||
|
bool Select();
|
||||||
|
void Deselect();
|
||||||
|
|
||||||
|
void ChangeEnabled(string Text, bool enabled);
|
||||||
|
|
||||||
|
string GetName();
|
||||||
|
|
||||||
|
void Execute();
|
||||||
|
|
||||||
|
void Print();
|
||||||
|
private:
|
||||||
|
vector<DataContainer*> list;
|
||||||
|
string myName;
|
||||||
|
float locX;
|
||||||
|
float locY;
|
||||||
|
|
||||||
|
int align;
|
||||||
|
|
||||||
|
float TopLeftX;
|
||||||
|
float TopLeftY;
|
||||||
|
float BottomRightX;
|
||||||
|
float BottomRightY;
|
||||||
|
|
||||||
|
int button;
|
||||||
|
|
||||||
|
bool selected;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
514
src/Model.cpp
Normal file
@ -0,0 +1,514 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include "Log.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "BoundBox.h"
|
||||||
|
#include "extensions.h"
|
||||||
|
#include "Model.h"
|
||||||
|
|
||||||
|
// Helpers for loadObj
|
||||||
|
#define T(x) (model->triangles[(x)])
|
||||||
|
|
||||||
|
struct ObjTriangle {
|
||||||
|
GLuint vindices[3]; // Array of triangle vertex indices
|
||||||
|
GLuint nindices[3]; // Array of triangle normal indices
|
||||||
|
GLuint tindices[3]; // Array of triangle texcoord indices
|
||||||
|
GLuint findex; // index of triangle facet normal
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ObjGroup {
|
||||||
|
char* name; // Name of this group
|
||||||
|
GLuint numtriangles; // Number of triangles in this group
|
||||||
|
GLuint* triangles; // Array of triangle indices
|
||||||
|
//GLuint material; // Index to material for group
|
||||||
|
struct ObjGroup* next; // Pointer to next group in model
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct ObjMaterial
|
||||||
|
{
|
||||||
|
char* name; // Name of material
|
||||||
|
GLfloat diffuse[4]; // Diffuse component
|
||||||
|
GLfloat ambient[4]; // Ambient component
|
||||||
|
GLfloat specular[4]; // Specular component
|
||||||
|
GLfloat emmissive[4]; // Emmissive component
|
||||||
|
GLfloat shininess; // Specular exponent
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ObjModel {
|
||||||
|
char* pathname; // Path to this model
|
||||||
|
char* mtllibname; // Name of the material library
|
||||||
|
|
||||||
|
GLuint numvertices; // Number of vertices in model
|
||||||
|
GLfloat* vertices; // Srray of vertices
|
||||||
|
|
||||||
|
GLuint numnormals; // Number of normals in model
|
||||||
|
GLfloat* normals; // Array of normals
|
||||||
|
|
||||||
|
GLuint numtexcoords; // Number of texcoords in model
|
||||||
|
GLfloat* texcoords; // Array of texture coordinates
|
||||||
|
|
||||||
|
GLuint numfacetnorms; // Number of facetnorms in model
|
||||||
|
GLfloat* facetnorms; // Array of facetnorms
|
||||||
|
|
||||||
|
GLuint numtriangles; // Number of triangles in model
|
||||||
|
ObjTriangle* triangles; // Array of triangles */
|
||||||
|
|
||||||
|
//GLuint nummaterials; // Number of materials in model
|
||||||
|
//ObjMaterial* materials; // Array of materials
|
||||||
|
|
||||||
|
GLuint numgroups; // Number of groups in model
|
||||||
|
ObjGroup* groups; // Linked list of groups
|
||||||
|
|
||||||
|
GLfloat position[3]; // Position of the model
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Model::Model(const char *textureName) {
|
||||||
|
loaded = false;
|
||||||
|
|
||||||
|
BuildTexture(textureName, &texture, GL_CLAMP_TO_EDGE, true);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
Model::~Model() {
|
||||||
|
glDeleteTextures(1, &texture);
|
||||||
|
|
||||||
|
glDeleteLists(displayList, 1);
|
||||||
|
|
||||||
|
delete modelBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::draw() {
|
||||||
|
if (loaded) {
|
||||||
|
glCallList(displayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::startList() {
|
||||||
|
GLfloat material[4];
|
||||||
|
|
||||||
|
material[0] = 1.0;
|
||||||
|
material[1] = 1.0;
|
||||||
|
material[2] = 1.0;
|
||||||
|
material[3] = 1.0;
|
||||||
|
|
||||||
|
displayList = glGenLists(1);
|
||||||
|
if (displayList == 0) {
|
||||||
|
// Probably should throw and exception
|
||||||
|
Log::logger->message("Could not generate model display list");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glNewList(displayList, GL_COMPILE);
|
||||||
|
|
||||||
|
glMaterialfv(GL_FRONT, GL_AMBIENT, material);
|
||||||
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, material);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::loadObj(const char *filename, float scale) {
|
||||||
|
ObjModel *model;
|
||||||
|
|
||||||
|
model = objLoad(filename);
|
||||||
|
if (!model) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale it properly
|
||||||
|
objScale(model, scale);
|
||||||
|
|
||||||
|
modelBox = objGenerateBox(model);
|
||||||
|
|
||||||
|
startList();
|
||||||
|
objDraw(model);
|
||||||
|
glEndList();
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjModel* Model::objLoad(const char *filename) {
|
||||||
|
ObjModel* model;
|
||||||
|
FILE* file;
|
||||||
|
|
||||||
|
/* open the file */
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
if (!file) {
|
||||||
|
// Probably should throw an exception
|
||||||
|
Log::logger->message("Warning: Failed to open file %s", filename);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* allocate a new model */
|
||||||
|
model = (ObjModel*)malloc(sizeof(ObjModel));
|
||||||
|
model->pathname = strdup(filename);
|
||||||
|
model->mtllibname = NULL;
|
||||||
|
model->numvertices = 0;
|
||||||
|
model->vertices = NULL;
|
||||||
|
model->numnormals = 0;
|
||||||
|
model->normals = NULL;
|
||||||
|
model->numtexcoords = 0;
|
||||||
|
model->texcoords = NULL;
|
||||||
|
model->numfacetnorms = 0;
|
||||||
|
model->facetnorms = NULL;
|
||||||
|
model->numtriangles = 0;
|
||||||
|
model->triangles = NULL;
|
||||||
|
//model->nummaterials = 0;
|
||||||
|
//model->materials = NULL;
|
||||||
|
model->numgroups = 0;
|
||||||
|
model->groups = NULL;
|
||||||
|
model->position[0] = 0.0;
|
||||||
|
model->position[1] = 0.0;
|
||||||
|
model->position[2] = 0.0;
|
||||||
|
|
||||||
|
/* Make a first pass through the file to get a count of the number
|
||||||
|
* of vertices, normals, texcoords & triangles
|
||||||
|
*/
|
||||||
|
objFirstPass(model, file);
|
||||||
|
|
||||||
|
/* allocate memory */
|
||||||
|
model->vertices = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||||
|
3 * (model->numvertices + 1));
|
||||||
|
model->triangles = (ObjTriangle*)malloc(sizeof(ObjTriangle) *
|
||||||
|
model->numtriangles);
|
||||||
|
if (model->numnormals) {
|
||||||
|
model->normals = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||||
|
3 * (model->numnormals + 1));
|
||||||
|
}
|
||||||
|
if (model->numtexcoords) {
|
||||||
|
model->texcoords = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||||
|
2 * (model->numtexcoords + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewind to beginning of file and read in the data this pass
|
||||||
|
rewind(file);
|
||||||
|
|
||||||
|
objSecondPass(model, file);
|
||||||
|
|
||||||
|
/* close the file */
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::objDraw(ObjModel *model) {
|
||||||
|
ObjGroup* group;
|
||||||
|
ObjTriangle* triangle;
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
|
||||||
|
group = model->groups;
|
||||||
|
while (group) {
|
||||||
|
for (unsigned int i = 0; i < group->numtriangles; i++) {
|
||||||
|
triangle = &T(group->triangles[i]);
|
||||||
|
|
||||||
|
glNormal3fv(&model->normals[3 * triangle->nindices[0]]);
|
||||||
|
glTexCoord2fv(&model->texcoords[2 * triangle->tindices[0]]);
|
||||||
|
glVertex3fv(&model->vertices[3 * triangle->vindices[0]]);
|
||||||
|
|
||||||
|
glNormal3fv(&model->normals[3 * triangle->nindices[1]]);
|
||||||
|
glTexCoord2fv(&model->texcoords[2 * triangle->tindices[1]]);
|
||||||
|
glVertex3fv(&model->vertices[3 * triangle->vindices[1]]);
|
||||||
|
|
||||||
|
glNormal3fv(&model->normals[3 * triangle->nindices[2]]);
|
||||||
|
glTexCoord2fv(&model->texcoords[2 * triangle->tindices[2]]);
|
||||||
|
glVertex3fv(&model->vertices[3 * triangle->vindices[2]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
group = group->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::objFirstPass(ObjModel *model, FILE* file) {
|
||||||
|
GLuint numvertices; // Number of vertices in model
|
||||||
|
GLuint numnormals; // Number of normals in model
|
||||||
|
GLuint numtexcoords; // Number of texcoords in model
|
||||||
|
GLuint numtriangles; // Number of triangles in model
|
||||||
|
ObjGroup* group; // Current group */
|
||||||
|
unsigned v, n, t;
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
/* Make a default group */
|
||||||
|
group = objAddGroup(model, "default");
|
||||||
|
|
||||||
|
numvertices = numnormals = numtexcoords = numtriangles = 0;
|
||||||
|
while(fscanf(file, "%s", buf) != EOF) {
|
||||||
|
switch(buf[0]) {
|
||||||
|
case '#': /* comment */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
case 'v': /* v, vn, vt */
|
||||||
|
switch(buf[1]) {
|
||||||
|
case '\0': /* vertex */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
numvertices++;
|
||||||
|
break;
|
||||||
|
case 'n': /* normal */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
numnormals++;
|
||||||
|
break;
|
||||||
|
case 't': /* texcoord */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
numtexcoords++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("glmFirstPass(): Unknown token \"%s\".\n", buf);
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
case 'g': /* group */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
#if SINGLE_STRING_GROUP_NAMES
|
||||||
|
sscanf(buf, "%s", buf);
|
||||||
|
#else
|
||||||
|
buf[strlen(buf)-1] = '\0'; /* nuke '\n' */
|
||||||
|
#endif
|
||||||
|
group = objAddGroup(model, buf);
|
||||||
|
break;
|
||||||
|
case 'f': /* face */
|
||||||
|
v = n = t = 0;
|
||||||
|
fscanf(file, "%s", buf);
|
||||||
|
if (sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3) {
|
||||||
|
/* v/t/n */
|
||||||
|
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||||
|
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||||
|
numtriangles++;
|
||||||
|
group->numtriangles++;
|
||||||
|
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||||
|
numtriangles++;
|
||||||
|
group->numtriangles++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log::logger->message("Warning: Invalid .obj file");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the stats in the model structure
|
||||||
|
model->numvertices = numvertices;
|
||||||
|
model->numnormals = numnormals;
|
||||||
|
model->numtexcoords = numtexcoords;
|
||||||
|
model->numtriangles = numtriangles;
|
||||||
|
|
||||||
|
// Allocate memory for the triangles in each group
|
||||||
|
group = model->groups;
|
||||||
|
while(group) {
|
||||||
|
group->triangles = (GLuint*)malloc(sizeof(GLuint) * group->numtriangles);
|
||||||
|
group->numtriangles = 0;
|
||||||
|
group = group->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjGroup* Model::objAddGroup(ObjModel *model, char *name) {
|
||||||
|
ObjGroup* group;
|
||||||
|
|
||||||
|
group = objFindGroup(model, name);
|
||||||
|
if (!group) {
|
||||||
|
group = (ObjGroup*)malloc(sizeof(ObjGroup));
|
||||||
|
group->name = strdup(name);
|
||||||
|
//group->material = 0;
|
||||||
|
group->numtriangles = 0;
|
||||||
|
group->triangles = NULL;
|
||||||
|
group->next = model->groups;
|
||||||
|
model->groups = group;
|
||||||
|
model->numgroups++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjGroup* Model::objFindGroup(ObjModel* model, char* name) {
|
||||||
|
ObjGroup* group;
|
||||||
|
|
||||||
|
group = model->groups;
|
||||||
|
while(group) {
|
||||||
|
if (!strcmp(name, group->name))
|
||||||
|
break;
|
||||||
|
group = group->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::objSecondPass(ObjModel* model, FILE* file) {
|
||||||
|
GLuint numvertices; // Number of vertices in model
|
||||||
|
GLuint numnormals; // Number of normals in model
|
||||||
|
GLuint numtexcoords; // Number of texcoords in model
|
||||||
|
GLuint numtriangles; // Number of triangles in model
|
||||||
|
GLfloat* vertices; // Array of vertices
|
||||||
|
GLfloat* normals; // Array of normals
|
||||||
|
GLfloat* texcoords; // Array of texture coordinates
|
||||||
|
ObjGroup* group; // Current group pointer
|
||||||
|
//GLuint material; // Current material
|
||||||
|
GLuint v, n, t;
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
/* set the pointer shortcuts */
|
||||||
|
vertices = model->vertices;
|
||||||
|
normals = model->normals;
|
||||||
|
texcoords = model->texcoords;
|
||||||
|
group = model->groups;
|
||||||
|
|
||||||
|
/* On the second pass through the file, read all the data into the
|
||||||
|
* allocated arrays
|
||||||
|
*/
|
||||||
|
numvertices = numnormals = numtexcoords = 1;
|
||||||
|
numtriangles = 0;
|
||||||
|
//material = 0;
|
||||||
|
while(fscanf(file, "%s", buf) != EOF) {
|
||||||
|
switch(buf[0]) {
|
||||||
|
case '#': /* comment */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
case 'v': /* v, vn, vt */
|
||||||
|
switch(buf[1]) {
|
||||||
|
case '\0': /* vertex */
|
||||||
|
fscanf(file, "%f %f %f",
|
||||||
|
&vertices[3 * numvertices + 0],
|
||||||
|
&vertices[3 * numvertices + 1],
|
||||||
|
&vertices[3 * numvertices + 2]);
|
||||||
|
numvertices++;
|
||||||
|
break;
|
||||||
|
case 'n': /* normal */
|
||||||
|
fscanf(file, "%f %f %f",
|
||||||
|
&normals[3 * numnormals + 0],
|
||||||
|
&normals[3 * numnormals + 1],
|
||||||
|
&normals[3 * numnormals + 2]);
|
||||||
|
numnormals++;
|
||||||
|
break;
|
||||||
|
case 't': /* texcoord */
|
||||||
|
fscanf(file, "%f %f",
|
||||||
|
&texcoords[2 * numtexcoords + 0],
|
||||||
|
&texcoords[2 * numtexcoords + 1]);
|
||||||
|
numtexcoords++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
sscanf(buf, "%s %s", buf, buf);
|
||||||
|
//group->material = material = glmFindMaterial(model, buf);
|
||||||
|
break;
|
||||||
|
case 'g': /* group */
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
#if SINGLE_STRING_GROUP_NAMES
|
||||||
|
sscanf(buf, "%s", buf);
|
||||||
|
#else
|
||||||
|
buf[strlen(buf)-1] = '\0'; /* nuke '\n' */
|
||||||
|
#endif
|
||||||
|
group = objFindGroup(model, buf);
|
||||||
|
//group->material = material;
|
||||||
|
break;
|
||||||
|
case 'f': /* face */
|
||||||
|
v = n = t = 0;
|
||||||
|
fscanf(file, "%s", buf);
|
||||||
|
if (sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3) {
|
||||||
|
/* v/t/n */
|
||||||
|
T(numtriangles).vindices[0] = v;
|
||||||
|
T(numtriangles).tindices[0] = t;
|
||||||
|
T(numtriangles).nindices[0] = n;
|
||||||
|
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||||
|
T(numtriangles).vindices[1] = v;
|
||||||
|
T(numtriangles).tindices[1] = t;
|
||||||
|
T(numtriangles).nindices[1] = n;
|
||||||
|
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||||
|
T(numtriangles).vindices[2] = v;
|
||||||
|
T(numtriangles).tindices[2] = t;
|
||||||
|
T(numtriangles).nindices[2] = n;
|
||||||
|
group->triangles[group->numtriangles++] = numtriangles;
|
||||||
|
numtriangles++;
|
||||||
|
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||||
|
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||||
|
T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
|
||||||
|
T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
|
||||||
|
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||||
|
T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
|
||||||
|
T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
|
||||||
|
T(numtriangles).vindices[2] = v;
|
||||||
|
T(numtriangles).tindices[2] = t;
|
||||||
|
T(numtriangles).nindices[2] = n;
|
||||||
|
group->triangles[group->numtriangles++] = numtriangles;
|
||||||
|
numtriangles++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log::logger->message("Warning: Invalid .obj file");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* eat up rest of line */
|
||||||
|
fgets(buf, sizeof(buf), file);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::objScale(ObjModel* model, float scale) {
|
||||||
|
GLuint i;
|
||||||
|
|
||||||
|
for (i = 1; i <= model->numvertices; i++) {
|
||||||
|
model->vertices[3 * i + 0] *= scale;
|
||||||
|
model->vertices[3 * i + 1] *= scale;
|
||||||
|
model->vertices[3 * i + 2] *= scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundBox* Model::objGenerateBox(ObjModel* model) {
|
||||||
|
float minX, maxX, minY, maxY, minZ, maxZ;
|
||||||
|
float tempVertex;
|
||||||
|
|
||||||
|
minX = 10000;
|
||||||
|
maxX = -10000;
|
||||||
|
minY = 10000;
|
||||||
|
maxY = -10000;
|
||||||
|
minZ = 10000;
|
||||||
|
maxZ = -10000;
|
||||||
|
|
||||||
|
for(unsigned int i = 1; i <= model->numvertices; i++) {
|
||||||
|
tempVertex = model->vertices[3 * i + 0];
|
||||||
|
if(tempVertex < minX) minX = tempVertex;
|
||||||
|
if(tempVertex > maxX) maxX = tempVertex;
|
||||||
|
|
||||||
|
tempVertex = model->vertices[3 * i + 1];
|
||||||
|
if(tempVertex < minY) minY = tempVertex;
|
||||||
|
if(tempVertex > maxY) maxY = tempVertex;
|
||||||
|
|
||||||
|
tempVertex = model->vertices[3 * i + 2];
|
||||||
|
if(tempVertex < minZ) minZ = tempVertex;
|
||||||
|
if(tempVertex > maxZ) maxZ = tempVertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BoundBox(minX, maxX, minY, maxY, minZ, maxZ);
|
||||||
|
}
|
56
src/Model.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MODEL_H_
|
||||||
|
#define _MODEL_H_
|
||||||
|
|
||||||
|
|
||||||
|
struct ObjModel;
|
||||||
|
struct ObjGroup;
|
||||||
|
class BoundBox;
|
||||||
|
|
||||||
|
class Model {
|
||||||
|
public:
|
||||||
|
// This just loads a texture, need to call a loadFORMAT metod
|
||||||
|
Model(const char *textureName);
|
||||||
|
|
||||||
|
// do whatever cleanup is necessary
|
||||||
|
~Model();
|
||||||
|
|
||||||
|
// Draws the actual model
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
// Add all file format dependant loadFORMAT functions here
|
||||||
|
// Loads a .obj file
|
||||||
|
void loadObj(const char *filename, float scale);
|
||||||
|
|
||||||
|
BoundBox *modelBox;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Starts and sets up display list, call from all LoadFORMAT functions
|
||||||
|
void startList();
|
||||||
|
|
||||||
|
// texture the model
|
||||||
|
GLuint texture;
|
||||||
|
|
||||||
|
// Display list to display the model
|
||||||
|
// Eventually this will be replaced by a VBO/VA
|
||||||
|
GLuint displayList;
|
||||||
|
|
||||||
|
// Whether the model has been loaded or not
|
||||||
|
bool loaded;
|
||||||
|
|
||||||
|
// Add all loadFORMAT helper functions here
|
||||||
|
ObjModel* objLoad(const char *filename);
|
||||||
|
void objDraw(ObjModel *model);
|
||||||
|
void objFirstPass(ObjModel *model, FILE *file);
|
||||||
|
ObjGroup* objAddGroup(ObjModel *model, char *name);
|
||||||
|
ObjGroup* objFindGroup(ObjModel *model, char *name);
|
||||||
|
void objSecondPass(ObjModel* model, FILE* file);
|
||||||
|
void objScale(ObjModel* model, float scale);
|
||||||
|
BoundBox* objGenerateBox(ObjModel* model);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
144
src/Ocean.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ccmath.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include "image.h"
|
||||||
|
#include "normals.h"
|
||||||
|
#include "Ocean.h"
|
||||||
|
#include "extensions.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "WaveEmitter.h"
|
||||||
|
|
||||||
|
#define OCEAN_TEXSCALE 6
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
Ocean::Ocean(int sizeX, int sizeZ) {
|
||||||
|
width = sizeX;
|
||||||
|
height = sizeZ;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
// Set up the texture
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
BuildTexture("./data/water.png", &texture, GL_REPEAT, true);
|
||||||
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
|
||||||
|
// Set up the wave texture
|
||||||
|
BuildTexture("./data/surf.png", &waveTexture, GL_CLAMP_TO_EDGE, true);
|
||||||
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
|
||||||
|
// Set up the material;
|
||||||
|
material[0] = 0.23;
|
||||||
|
material[1] = 0.35;
|
||||||
|
material[2] = 0.7;
|
||||||
|
material[3] = 0.45;
|
||||||
|
|
||||||
|
// Generate the display list
|
||||||
|
list = glGenLists(1);
|
||||||
|
if(list == 0) {
|
||||||
|
printf("Could not generate waves\n");
|
||||||
|
}
|
||||||
|
glNewList(list, GL_COMPILE);
|
||||||
|
|
||||||
|
// Draw the actual water
|
||||||
|
// Use the material
|
||||||
|
glMaterialfv(GL_FRONT, GL_AMBIENT, material);
|
||||||
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, material);
|
||||||
|
|
||||||
|
// Enable the texture
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
|
glNormal3f(0, 1, 0);
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex3f(-1*width/2, 0, -1*height/2);
|
||||||
|
glTexCoord2f(0, height/OCEAN_TEXSCALE);
|
||||||
|
glVertex3f(-1*width/2, 0, height/2);
|
||||||
|
glTexCoord2f(width/OCEAN_TEXSCALE, height/OCEAN_TEXSCALE);
|
||||||
|
glVertex3f(width/2, 0, height/2);
|
||||||
|
glTexCoord2f(width/OCEAN_TEXSCALE, 0);
|
||||||
|
glVertex3f(width/2, 0, -1*height/2);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Done with the list
|
||||||
|
glEndList();
|
||||||
|
|
||||||
|
// Generate the wave list
|
||||||
|
WaveEmitter::generateWaveList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ocean::~Ocean() {
|
||||||
|
// Delete the texture
|
||||||
|
glDeleteTextures(1, &texture);
|
||||||
|
|
||||||
|
// Delete the display list
|
||||||
|
glDeleteLists(list, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// The wave emitters will be deleted by the quad tree
|
||||||
|
waveEmitters.clear();
|
||||||
|
|
||||||
|
WaveEmitter::deleteActiveWaves();
|
||||||
|
|
||||||
|
WaveEmitter::deleteWaveList();
|
||||||
|
|
||||||
|
Log::logger->message("Ocean deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ocean::draw() {
|
||||||
|
float mult = sin(count);
|
||||||
|
float mult2 = cos(count);
|
||||||
|
|
||||||
|
GLfloat shift = (.25*mult)/OCEAN_TEXSCALE;
|
||||||
|
GLfloat shift2 = (.25*mult2*(width/height))/OCEAN_TEXSCALE;
|
||||||
|
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, waveTexture);
|
||||||
|
WaveEmitter::drawActiveWaves();
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
// Get ready to manipulate the texture matrix
|
||||||
|
glMatrixMode(GL_TEXTURE);
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
// Move around the texture
|
||||||
|
glTranslatef(shift, shift2, 0);
|
||||||
|
|
||||||
|
// Draw the actual waves
|
||||||
|
glCallList(list);
|
||||||
|
|
||||||
|
// Reset the matrix
|
||||||
|
glPopMatrix();
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ocean::update(unsigned int ticks) {
|
||||||
|
unsigned int numEmitters = waveEmitters.size();
|
||||||
|
|
||||||
|
count += .002*ticks;
|
||||||
|
if(count > TWO_PI) count -= TWO_PI;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < numEmitters; i++) {
|
||||||
|
waveEmitters[i]->update(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
WaveEmitter::updateActiveWaves(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ocean::addEmitter(WaveEmitter*emitter) {
|
||||||
|
// This just puts a pointer to a wave emitter into the vector
|
||||||
|
waveEmitters.push_back(emitter);
|
||||||
|
}
|
56
src/Ocean.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _OCEAN_H_
|
||||||
|
#define _OCEAN_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class WaveEmitter;
|
||||||
|
|
||||||
|
class Ocean {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Ocean(int sizeX, int sizeZ);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Ocean();
|
||||||
|
|
||||||
|
// Draw the actual water
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
// Update the waters position
|
||||||
|
void update(unsigned int ticks);
|
||||||
|
|
||||||
|
// Add a WaveEmitter to the master list
|
||||||
|
void addEmitter(WaveEmitter *emitter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Size of water patch
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
// Texture handle
|
||||||
|
GLuint texture;
|
||||||
|
|
||||||
|
// Texture handle for waves
|
||||||
|
GLuint waveTexture;
|
||||||
|
|
||||||
|
// Material
|
||||||
|
GLfloat material[4];
|
||||||
|
|
||||||
|
// For sin/cos to move texture
|
||||||
|
GLfloat count;
|
||||||
|
|
||||||
|
// For display list
|
||||||
|
GLuint list;
|
||||||
|
|
||||||
|
// Pointer to all of the wave emitters (This makes update easier)
|
||||||
|
vector< WaveEmitter* > waveEmitters;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
229
src/Player.cpp
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <vector>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include "Player.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Ships.h"
|
||||||
|
#include "Economy.h"
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Player::Player() {
|
||||||
|
x = 0.0;
|
||||||
|
z = 0.0;
|
||||||
|
rot = 0.0;
|
||||||
|
speed = 0.0;
|
||||||
|
|
||||||
|
gold = 100;
|
||||||
|
|
||||||
|
ship = ShipManager::list->newShip(0, "Player");
|
||||||
|
}
|
||||||
|
|
||||||
|
Player::~Player() {
|
||||||
|
delete ship;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Player::load(int number) {
|
||||||
|
GLfloat tx, tz, trot, tspeed;
|
||||||
|
int tdamage;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
TiXmlDocument doc("./LSave.xml");
|
||||||
|
TiXmlElement* Lephisto;
|
||||||
|
TiXmlElement* SavedGame;
|
||||||
|
TiXmlElement* Location;
|
||||||
|
TiXmlElement* loc;
|
||||||
|
TiXmlElement* Direction;
|
||||||
|
TiXmlElement* Speed;
|
||||||
|
TiXmlElement* Damage;
|
||||||
|
TiXmlText* data;
|
||||||
|
|
||||||
|
|
||||||
|
doc.LoadFile();
|
||||||
|
if(doc.Error()) {
|
||||||
|
Log::logger->message("\nError: Could not open saved game file\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Lephisto = doc.FirstChildElement("Lephisto");
|
||||||
|
if(Lephisto == NULL) {
|
||||||
|
Log::logger->message("\nError: <Lephisto> did not parse correctly.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SavedGame = Lephisto->FirstChildElement("SavedGame");
|
||||||
|
if(SavedGame == NULL) {
|
||||||
|
Log::logger->message("\nError: <SavedGame> did not parse correctly.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Location = SavedGame->FirstChildElement("Location");
|
||||||
|
if(Location == NULL) throw 0;
|
||||||
|
|
||||||
|
// Handle location
|
||||||
|
loc = Location->FirstChildElement("x");
|
||||||
|
if(loc == NULL) throw 1;
|
||||||
|
data = loc->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 1;
|
||||||
|
n = sscanf(data->Value(), "%f", &tx);;
|
||||||
|
if(n != 1) throw 1;
|
||||||
|
loc = Location->FirstChildElement("z");
|
||||||
|
if(loc == NULL) throw 2;
|
||||||
|
data = loc->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 2;
|
||||||
|
n = sscanf(data->Value(), "%f", &tz);
|
||||||
|
if(n != 1) throw 2;
|
||||||
|
|
||||||
|
// Handle the direction
|
||||||
|
Direction = SavedGame->FirstChildElement("Direction");
|
||||||
|
if(Direction == NULL) throw 3;
|
||||||
|
data = Direction->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 3;
|
||||||
|
n = sscanf(data->Value(), "%f", &trot);
|
||||||
|
if(n != 1) throw 3;
|
||||||
|
|
||||||
|
// Handle speed
|
||||||
|
Speed = SavedGame->FirstChildElement("Speed");
|
||||||
|
if(Speed == NULL) throw 4;
|
||||||
|
data = Speed->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 4;
|
||||||
|
n = sscanf(data->Value(), "%f", &tspeed);
|
||||||
|
if(n != 1) throw 4;
|
||||||
|
|
||||||
|
// Deal with ship
|
||||||
|
// Idealy this would call a method of the ship object that would get itself loaded from XML
|
||||||
|
// that could also call a method on the cargo object that loads itself. However, for now, just saving the damage will do.
|
||||||
|
Damage = SavedGame->FirstChildElement("Damage");
|
||||||
|
if(Damage == NULL) throw 5;
|
||||||
|
data = Damage->FirstChild()->ToText();
|
||||||
|
if(data == NULL) throw 5;
|
||||||
|
n = sscanf(data->Value(), "%d", &tdamage);
|
||||||
|
if(n != 1) throw 5;
|
||||||
|
} catch(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
Log::logger->message("\nWarning: <Location> did not parse correctly\n");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Log::logger->message("\nWarning: <x> did not parse correctly\n");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Log::logger->message("\nWarning: <z> did not parse correctly\n");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Log::logger->message("\nWarning: <Direction> did not parse correctly\n");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Log::logger->message("\nWarning: <Speed> did not parse correctly");
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
Log::logger->message("\nWarning: <Damage> did not parse correctly\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log::logger->message("\nWarning: Unknown Saved Game.. Error\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = tx;
|
||||||
|
z = tz;
|
||||||
|
rot = trot;
|
||||||
|
speed = tspeed;
|
||||||
|
ship->damage = tdamage;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Player::save(int number) {
|
||||||
|
int n;
|
||||||
|
TiXmlDocument doc;
|
||||||
|
TiXmlElement* Lephisto = new TiXmlElement("");
|
||||||
|
TiXmlElement* SavedGame = new TiXmlElement("");
|
||||||
|
TiXmlElement* Location = new TiXmlElement("");
|
||||||
|
TiXmlElement* locX = new TiXmlElement("");
|
||||||
|
TiXmlElement* locZ = new TiXmlElement("");
|
||||||
|
TiXmlElement* Direction = new TiXmlElement("");
|
||||||
|
TiXmlElement* Speed = new TiXmlElement("");
|
||||||
|
TiXmlElement* Damage = new TiXmlElement("");
|
||||||
|
TiXmlText* data = new TiXmlText("");
|
||||||
|
char temp[80] = ""; // Needs to have a size otherwise we will get a buffer overflow
|
||||||
|
|
||||||
|
//Lephisto = doc.RootElement();
|
||||||
|
|
||||||
|
Lephisto->SetValue("Lephisto");
|
||||||
|
|
||||||
|
SavedGame->SetValue("SavedGame");
|
||||||
|
Location->SetValue("Location");
|
||||||
|
locX->SetValue("x");
|
||||||
|
locZ->SetValue("z");
|
||||||
|
|
||||||
|
n = sprintf(temp, "%f", z);
|
||||||
|
data->SetValue(temp);
|
||||||
|
locZ->InsertEndChild(*data);
|
||||||
|
|
||||||
|
Location->InsertEndChild(*locX);
|
||||||
|
Location->InsertEndChild(*locZ);
|
||||||
|
|
||||||
|
Direction->SetValue("Direction");
|
||||||
|
n = sprintf(temp, "%f", rot);
|
||||||
|
data->SetValue(temp);
|
||||||
|
Direction->InsertEndChild(*data);
|
||||||
|
|
||||||
|
Speed->SetValue("Speed");
|
||||||
|
n = sprintf(temp, "%f", speed);
|
||||||
|
data->SetValue(temp);
|
||||||
|
Speed->InsertEndChild(*data);
|
||||||
|
|
||||||
|
Damage->SetValue("Damage");
|
||||||
|
n = sprintf(temp, "%d", ship->damage);
|
||||||
|
data->SetValue(temp);
|
||||||
|
Damage->InsertEndChild(*data);
|
||||||
|
|
||||||
|
SavedGame->InsertEndChild(*Location);
|
||||||
|
SavedGame->InsertEndChild(*Direction);
|
||||||
|
SavedGame->InsertEndChild(*Speed);
|
||||||
|
SavedGame->InsertEndChild(*Damage);
|
||||||
|
|
||||||
|
|
||||||
|
Lephisto->InsertEndChild(*SavedGame);
|
||||||
|
|
||||||
|
doc.InsertEndChild(*Lephisto);
|
||||||
|
|
||||||
|
doc.SaveFile(".LSave.xml");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::reset() {
|
||||||
|
x = 0.0;
|
||||||
|
z = 0.0;
|
||||||
|
rot = 0.0;
|
||||||
|
speed = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::dump() {
|
||||||
|
Log::logger->message("X: %f Z:%f\nRot: %f\nSpeed: %f\n\n", x, z, rot, speed);
|
||||||
|
|
||||||
|
ship->dump();
|
||||||
|
|
||||||
|
Log::logger->message("Gold:\t%i\n", gold);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cargo* Player::getCargo() {
|
||||||
|
return ship->cargo;
|
||||||
|
}
|
43
src/Player.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PLAYER_H_
|
||||||
|
#define _PLAYER_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Ship;
|
||||||
|
class Cargo;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Player {
|
||||||
|
public:
|
||||||
|
Player();
|
||||||
|
|
||||||
|
~Player();
|
||||||
|
|
||||||
|
// The ship contains all of these fields, we could just use them..
|
||||||
|
GLfloat x;
|
||||||
|
GLfloat z;
|
||||||
|
GLfloat rot;
|
||||||
|
GLfloat speed;
|
||||||
|
|
||||||
|
bool load(int);
|
||||||
|
bool save(int);
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void dump();
|
||||||
|
|
||||||
|
// This just returns the ship's cargo, so you can avoid going through the ship
|
||||||
|
Cargo* getCargo();
|
||||||
|
|
||||||
|
// We will need to work this out once we get things like fleets and stuff.
|
||||||
|
Ship *ship;
|
||||||
|
|
||||||
|
int gold;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
49
src/Point.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include "./Point.h"
|
||||||
|
|
||||||
|
// Generic constructor
|
||||||
|
Point::Point() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
z = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy constructor
|
||||||
|
Point::Point(Point *copy) {
|
||||||
|
x = copy->x;
|
||||||
|
y = copy->y;
|
||||||
|
z = copy->z;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct point at (xIn, yIn, zIn)
|
||||||
|
Point::Point(GLfloat xIn, GLfloat yIn, GLfloat zIn) {
|
||||||
|
x = xIn;
|
||||||
|
y = yIn;
|
||||||
|
z = zIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::dump() {
|
||||||
|
printf("(%f, %f, %f)\n", x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Average two points, store in result
|
||||||
|
void Point::average(Point *a, Point *b, Point *result) {
|
||||||
|
result->x = (int) (a->x + b->x)/2;
|
||||||
|
result->y = (int) (a->y + b->y)/2;
|
||||||
|
result->z = (int) (a->z + b->z)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::draw() {
|
||||||
|
glVertex3f(x, y, z);
|
||||||
|
}
|
36
src/Point.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _POINT_H_
|
||||||
|
|
||||||
|
#define _POINT_H_
|
||||||
|
|
||||||
|
// A point in 3d space
|
||||||
|
class Point {
|
||||||
|
public:
|
||||||
|
// Generic constructor
|
||||||
|
Point();
|
||||||
|
|
||||||
|
// Copy contrustor
|
||||||
|
Point(Point *copy);
|
||||||
|
|
||||||
|
// Construct a point at (xIn, yIn, zIn);
|
||||||
|
Point(GLfloat xIn, GLfloat yIn, GLfloat zIn);
|
||||||
|
|
||||||
|
GLfloat x;
|
||||||
|
GLfloat y;
|
||||||
|
GLfloat z;
|
||||||
|
|
||||||
|
// Dump the coords
|
||||||
|
void dump();
|
||||||
|
|
||||||
|
// Give the glVertex3f call for this point
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
// Average two points, store the result
|
||||||
|
static void average(Point *a, Point *b, Point *result);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
77
src/Product.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Economy.h"
|
||||||
|
#include "Product.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Product::Product() {
|
||||||
|
ID = -1;
|
||||||
|
medianPrice = 0.0;
|
||||||
|
demand = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Product::Product(int myID, float myMedianPrice, int myDemand) {
|
||||||
|
ID = myID;
|
||||||
|
medianPrice = myMedianPrice;
|
||||||
|
demand = myDemand;
|
||||||
|
}
|
||||||
|
|
||||||
|
Product::~Product() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Product::SetMedianPrice(float Price) {
|
||||||
|
medianPrice = Price;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Product::SetDemand(int Demand) {
|
||||||
|
demand = Demand;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Product::IncreaseDemand() {
|
||||||
|
++demand;
|
||||||
|
return demand;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Product::IncreaseDemand(int amount) {
|
||||||
|
demand += amount;
|
||||||
|
return demand;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Product::DecreaseDemand() {
|
||||||
|
--demand;
|
||||||
|
return demand;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Product::DecreaseDemand(int amount) {
|
||||||
|
demand -= amount;
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Product::GetName() {
|
||||||
|
return Economy::Econ->ProdList[ID];
|
||||||
|
}
|
||||||
|
|
||||||
|
float Product::GetMedianPrice() {
|
||||||
|
return medianPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Product::GetDemand() {
|
||||||
|
return demand;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Product::Print() {
|
||||||
|
cout << "Product Name: " << GetName() << "\n\tPrice: " << medianPrice << "\n\tDemand: " << demand
|
||||||
|
<< endl;
|
||||||
|
}
|
47
src/Product.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* This software is the propery of 'SaraCraft' - developed by Allanis.
|
||||||
|
* Only members directly assosiated with the SaraCraft project may view/change
|
||||||
|
* this code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PRODUCT_H_
|
||||||
|
#define _PRODUCT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Product {
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Product();
|
||||||
|
Product(int myID, float myMedianPrice, int myDemand);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Product();
|
||||||
|
|
||||||
|
//methods
|
||||||
|
void SetMedianPrice(float Price);
|
||||||
|
void SetDemand(int Demand);
|
||||||
|
|
||||||
|
// Without an argument, the increase is one
|
||||||
|
int IncreaseDemand();
|
||||||
|
int IncreaseDemand(int amount);
|
||||||
|
|
||||||
|
// Without an argument, the decrease is one
|
||||||
|
int DecreaseDemand();
|
||||||
|
int DecreaseDemand(int amount);
|
||||||
|
|
||||||
|
// these get the private data
|
||||||
|
string GetName();
|
||||||
|
float GetMedianPrice();
|
||||||
|
int GetDemand();
|
||||||
|
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int ID;
|
||||||
|
float medianPrice;
|
||||||
|
int demand;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|