diff --git a/.gitignore b/.gitignore
index cc0b6a3..e11069d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,48 +1,31 @@
-# Object files
+# Compiled object files.
+*.slo
+*.lo
*.o
-# Libraries
-*.lib
+# Compiled Dynsamic libs.
+*.so
+
+# Compiled Static libs.
+*.lai
+*.la
*.a
-# Shared objects (inc. Windows DLLs)
-*.dll
-*.so
-*.so.*
-*.dylib
-*.bin
-
-# Executables
-*.exe
-*.out
-*.app
-
-# Crap.
-*.log
+# Project Specific.
+*Lephisto3D*
+bin/*
+*Makefile
+*Makefile.in
+*.stash
*.swp
-*.txt
-*.tsv
-*.pdf
-*.pyc
-*bin/Lephisto
-*bin/mksprite
-*bin/ldata
-*bin/test.xml
-*pack
-*core
-screenshots/*.png
-*VERSION
-utils/resedit/*.xml
-docs/doxygen/docs/*
-docs/doxygen/lua/*
-
-
-# Windows Crap
-win32/Lephisto/*
-win32/Pack/*
-win32/Makefile
-
-# Qt crap.
-qt/*.user
-qt/Makefile
-
+*.swo
+*.cache
+*.deps
+*aclocal.m4
+*compile
+*config.log
+*config.status
+*configure
+*depcomp
+*install-sh
+*missing
diff --git a/README b/README
index d4fc205..739e596 100644
--- a/README
+++ b/README
@@ -1,131 +1,2 @@
-Lephisto : SaraCraft Studio's
-
-Overview:
-~~~~~~~~~
-Lephisto was the first game project I worked on. I have decided to start a new project and as originally planned when
-ceasing work on the original, re-use the name!
-
-Dependencies:
-~~~~~~~~~~~~~
-OpenGL
-SDL
-sdl_image
-freetype2
-libpng
-
-Compiling:
-~~~~~~~~~~
-
-----------------------
--- Linux.
- -- cd Lephisto/bin/
- -- make
-----------------------
-
-Instalation:
-~~~~~~~~~~~~~
-Installation is not currently supported.
-
-Bugs/Crashes and problems:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Please visit the bug tracker https://github.com/Allanis/Lephisto/issues?state=open
-and report any issues that you are having. Please ensure that your bug has not
-already been documented before posting.
-
-
-Dependencies:
-~~~~~~~~~~~~~
- -- Debian:
- -- Binary:
- -- libsdl1.2debian
- -- libsdl-image1.2
- -- libsdl-mixer1.2
- -- libgl1-mesa-dri
- -- libxml2
- -- libfreetype6
- -- libpng12-0
-
- -- Source:
- -- libsdl1.2-dev
- -- libsdl-image1.2-dev
- -- libsdl-mixer1.2-dev
- -- libgl1-mesa-dev
- -- libxml2-dev
- -- libfreetype6-dev
- -- libpng12-dev
-
-
-Instructions:
-~~~~~~~~~~~~~
-Keys:
- =========================================================
- Lephisto uses a dynamic keybinding system that allows you
- to configure the keybinds to joystick, keyboard or a mix
- of both.
- -- Joystick.
- If you are going to use a joystick, You will have to tell
- Lephisto which joystick to use. You can either use the -j
- or -J parameter from the terminal or put it in the conf
- file.
- -- Eg.
- -- ./Lephisto -j 0
- -- ./Lephisto -J "Precision"
- -- joystick = "Precision" # in conf file.
-
- -- Syntax.
- KEY_IDENTIFIER = { type = KEY_TYPE, key = KEY_NUMBER,
- [reverse = KEY_REVERSE, mod = MOD_IDENTIFIER] }
-
- KEY_IDENTIFIER is the indetifier given below:
- KEY_TYPE can be one of keyboard, jaxis or jbutton.
- KEY_NUMBER is the number of the key (found with xev usually, just
- convert the keysym from hex to base 10).
- KEY_REVERSE is whether it is reversed or not, which
- is only useful in the case of jaxis.
- MOD_IDENTIFIER is the modifier to take into account, can be on of:
- lctrl, rctrl, lshift, rshift, lmeta, rmeta, ralt, lalt
- It isn't used with joystick bindings.
-
- -- Eg.
- accel = { type = "jbutton", key = 0 }
- =========================================================
-
- Movement:
- -- w : Accelerate.
- -- Double tap for afterburners.
- -- a : Left.
- -- d : Right.
- -- s : Turn 180 degree, so you can stop easily.
-
- Combat:
- -- Space : Primary weapons.
- -- Tab : Target.
- -- 'r' : Target closest hostile ship.
- -- 'f' : Faces the target.
- -- 'b' : Board the target.
- -- 'LALT' : Fires secondary weapon.
- -- 'e' : Cycle through secondary weapons.
- -- 'LCTRL+e' : Cycle backwards through secondary weapons.
-
- Escorts:
- -- Cycle through secondary weapons until you find fighter bay, then fire
- secondary weapon with LALT to dispatch fighters.
- -- 1 : Command escort to attack.
- -- 2 : Command escort to hold.
- -- 3 : Command escort to return to hold.
- -- 4 : Command escort to clear all commands.
-
- Space:
- -- 'p' : Cycles through planets.
- -- 'l' : Attempts to land or targets nearest planet.
- -- 'h' : Cycles through hyperspace jump points.
- -- 'j' : Jump through hyperspace.
- -- 'm' : StarMap
-
- GUI:
- -- '0' : Zoom in.
- -- '9' : Zoom out.
- -- F12 : Take a screenshot.
- -- ESC : Menu.
- -- 'i' : Opens the character information window.
+-- Lephisto3D --
diff --git a/TODO b/TODO
deleted file mode 100644
index 044be07..0000000
--- a/TODO
+++ /dev/null
@@ -1,67 +0,0 @@
-Vital:
-
- -- Developer mode.
- -- Lua console.
- -- Run missions.
- -- See mount points.
- -- Integrate the resource editor possibly.
- -- Asteroids.
- -- Real news.
- -- Event System.
- -- Like mission system, but they occur naturally/randomly.
- -- Has similar power to mission system.
- -- More missions.
- -- Empire shipping campaign.
- -- FLF Nebulae campaign.
- -- Space Trader Missions.
- -- Misc Empire Guard missions.
- -- Pirate Missions.
- -- FLF Missions.
-
-Major:
- -- Unique pilot system (besides mission uniques).
- -- Escorts available for hire.
- -- Nicer AI.
- -- Ship fleet movement (Maybe based on boids?)
- -- Options menu needs to do something.
- -- Configuration app for keybindings.
- -- Secondary weapon revamp.
- -- Players should be able to configure what outfits they want as secondary.
- -- Players should also be able to set hotkeys for secondary weapons.
-
-Minor:
- -- Pilot communication system.
- -- Request fuel.
- -- Hybrid Ships.
- -- Start out with X skillpoints that get spread out by use, use fast at first.
- -- Can't use normal gear.
- -- Very rare.
- -- Random mutation for cloaking/displacement abilities.
- -- Optimize texture usage.
- -- All land graphics should be on land only (optionally).
- -- Planet space graphics should be ondemand.
- -- Improved graphics.
- -- Have ships flying in nebulae leave traces.
- -- Missile smoke.
- -- Engine glow -> need models.
- -- More special effects.
- -- Cloaking effects?
- -- Maybe some fancy displacement effects for some ships.
- -- Dynamic politics - Faction wide ai.
- -- Allow player to create faction and control fleets.
- -- Cinematic scenes.
- -- Allow for subsystems getting damaged.
- -- Allow mouse movement (steering).
- -- Pilot titles.
- -- Would usually indicate changes on the base ship equipment.
- -- Radar improvements.
- -- Non-linear - See alot more data then currently possible.
- -- Objects always in sight (depending on resolution).
- -- Allow creating collision masks to make collision more realistic.
- -- Improve font system to handle unicode.
- -- Mission improvements.
- -- Allow creation of OSD (On Screen Displays).
-
-SOMEDAY!! MAYBE...:
- -- 3d models (not actually a 3D perspective, just no sprites).
-
diff --git a/bin/Makefile b/bin/Makefile
deleted file mode 100644
index 261a6bd..0000000
--- a/bin/Makefile
+++ /dev/null
@@ -1,166 +0,0 @@
-# OPTIONS.
-DEBUG := 1
-#DEBUG_PARANOID := 1
-export DEBUG
-
-OS := LINUX
-#OS := FREEBSD
-#OS := WIN32
-#OS := MACOS
-export OS
-
-# Data path.
-#LDATA_DEF := \"../ldata\"
-
-#CC = clang
-
-# VERSION.
-VMAJOR := 0
-VMINOR := 3
-VREV := 5
-VERSION = -DVMAJOR=$(VMAJOR) -DVMINOR=$(VMINOR) -DVREV=$(VREV)
-VERSIONFILE = VERSION
-
-# OBJECTS.
-APPNAME := Lephisto
-OBJS := $(patsubst %.c, %.o, $(wildcard ../src/*.c))
-
-# CFLAGS
-CLUA := -I../lib/lua
-CCSPARSE := -I../lib/csparse
-CSDL := $(shell sdl-config --cflags) -DGL_GLEXT_PROTOTYPES
-CXML := $(shell xml2-config --cflags)
-CTTF := $(shell freetype-config --cflags)
-CPNG := #$(shell libpng-config libpng --cflags)
-CGL :=
-CFLAGS := $(CLUA) $(CCSPARSE) $(CSDL) $(CXML) $(CTTF) $(CPNG) $(CGL) $(VERSION) -D$(OS)
-ifdef LDATA_DEF
-CFLAGS += -DLDATA_DEF=$(LDATA_DEF)
-endif
-
-# Debug stuff.
-ifdef DEBUG
-CFLAGS += -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes \
- -Winline -Wcast-align -Wmissing-declarations -fstack-protector \
- -fstack-protector-all -g -DDEBUG -DLUA_USE_APICHECK -std=c99
-
-ifdef DEBUG_PARANOID
-CFLAGS += -DDEBUG_PARANOID
-endif
-
-# Handle OS Debug stuff here.
-
-# Linux Stuff.
-ifeq ($(OS), LINUX)
-LDFLAGS += -rdynamic
-endif # Linux.
-
-else # DEBUG
-CFLAGS += -O2 -funroll-loops -pipe -std=c99
-endif
-
-# LDFLAGS.
-LDLUA := ../lib/lua/liblua.a
-LDCSPARSE := ../lib/csparse/libcsparse.a
-LDSDL := $(shell sdl-config --libs) -lSDL_image -lSDL_mixer -lpng
-LDXML := $(shell xml2-config --libs)
-LDTTF := $(shell freetype-config --libs)
-CPNG := #$(shell libpng-config libpng --libs)
-LDGL := -lGL
-LDFLAGS := -lm $(LDLUA) $(LDCSPARSE) $(LDSDL) $(LDXML) $(LDTTF) $(CPNG) $(LDGL) $(LDPNG)
-
-# This is just for gstat to run some analysis on performance.
-ifdef DEBUG
-LDFLAGS += -pg
-endif
-
-# DATA.
-DATA_MISC := ../AUTHORS VERSION
-DATA_AI := $(wildcard ../scripts/ai/*.lua \
- ../scripts/ai/*/*.lua)
-DATA_GFX := $(wildcard ../gfx/*.png \
- ../gfx/*/*.png \
- ../gfx/*/*/*.png)
-DATA_XML := $(wildcard ../dat/*.xml ../dat/*.ttf ../dat/intro)
-DATA_SND := $(wildcard ../snd/music/*.ogg \
- ../snd/sounds/*.wav) ../snd/music.lua
-DATA_MISN := $(wildcard ../dat/missions/*.lua \
- ../dat/missions/*/*.lua \
- ../dat/mission/*/*/*.lua)
-
-DATA := ldata
-DATAFILES := $(DATA_MISC) $(DATA_AI) $(DATA_GFX) $(DATA_XML) $(DATA_SND) $(DATA_MISN)
-
-# TARGETS.
-.PHONY: all help csparse lua utils docs clean distclean
-
-%.o: %.c %.h
- @$(CC) -c $(CFLAGS) -o $@ $<
- @echo " CC $@"
-
-all: utils ldata lua csparse Lephisto
-
-help:
- @echo "Possible targets are:":
- @echo " lua - Builds Lua support."
- @echo " csparse - Builds CSparse support."
- @echo " lephisto - Builds the Lephisto binary."
- @echo " mkspr - Builds the mkspr utility."
- @echo " ldata - Creates the ldata file."
- @echo " utils - Builds all the utilities."
- @echo " docs - Creates the doxygen documentation."
- @echo " clean - Removes Lephisto's main binary and ldata file."
- @echo " distclean - Removes everything done."
-
-$(APPNAME): $(OBJS)
- @$(CC) $(LDFLAGS) -o $(APPNAME) $(OBJS) ../lib/lua/liblua.a ../lib/csparse/libcsparse.a
- @echo " LD $(APPNAME)"
-
-lua: ../lib/lua/liblua.a
-
-../lib/lua/liblua.a:
- +@$(MAKE) -C ../lib/lua a
-
-csparse: ../lib/csparse/libcsparse.a
-
-../lib/csparse/libcsparse.a:
- +@$(MAKE) -C ../lib/csparse
-
-pack: ../src/md5.c ../src/pack.c ../utils/pack/main.c
- @$(MAKE) -C ../utils/pack
-
-mksprite: ../utils/mkspr/main.c
- @$(MAKE) -C ../utils/mkspr
-
-$(VERSIONFILE):
- @echo -n "$(VMAJOR).$(VMINOR).$(VREV)" > $(VERSIONFILE)
-
-ldata: pack $(DATAFILES)
- @echo -n "$(VMAJOR).$(VMINOR).$(VREV)" > $(VERSIONFILE)
- @echo " Creating ldata..\n"
- @./pack $(DATA) $(DATAFILES)
-
-utils: pack mksprite
-
-docs:
- +@$(MAKE) -C ../docs/
-
-clean:
- @echo " Removing ldata"
- @$(RM) $(DATA)
- @echo " Removing object files"
- @$(RM) $(OBJS)
- @echo " Removing main binary ($(APPNAME))"
- @$(RM) $(APPNAME)
-
-distclean: clean
- @echo " Cleaning utilites"
- @$(MAKE) -C ../utils/pack clean
- @$(MAKE) -C ../utils/mkspr clean
- @echo " Cleaning Lua"
- @$(MAKE) -C ../lib/lua clean
- @echo " Cleaning CSparse."
- @$(MAKE) -C ../lib/csparse clean
- @echo " Removing build tool binaries."
- @$(RM) Lephisto mksprite ldata pack gmon.out VERSION
-
diff --git a/bin/conf.example b/bin/conf.example
deleted file mode 100644
index 08fef31..0000000
--- a/bin/conf.example
+++ /dev/null
@@ -1,47 +0,0 @@
---WINDOW.
-width = 800
-height = 640
-fullscreen = 0
-
--- SCREEN.
-fps = 0
-
--- SOUND.
-nosound = 0
-sound = 0.7
-music = 0.5
-
--- JOYSTICK.
--- Can be number or substring of joystick name.
-joystick = "Precision"
-
--- KEYBINDINGS.
--- Type can be keyboard, jaxis or jbutton.
---
--- If left is an axis, it will automatically set right to the same axis.
--- setting both to the same axis (key).
--- You can use reverse = 1 option to reverse them.
--- Currently keybindings work with the number of the key only (when doing
--- keyboard). Would be cool to have a gui to do this for you at some point.
-
--- Movement.
-accel = { type = "jbutton", key = 0 }
-left = { type = "jaxis", key = 0 }
-right = { type = "jaxis", key = 0 }
-
--- Combat.
-primary = { type = "jbutton", key = 1 }
-target = { type = "jbutton", key = 4 }
-target_nearest = { type = "jbutton", key = 3 }
-face = { type = "keyboard", key = 38 }
-board = { type = "keyboard", key = 57 }
-secondary = { type = "jbutton", key = 7 }
-secondary_next = { type = "jbutton", key = 5 }
-
--- Space.
-
--- Gui.
-mapzoomin = { type = "jbutton", key = 4 }
-mapzoomout = { type = "jbutton", key = 6 }
-screenshot = { type = "keyboard", key = 82 }
-
diff --git a/dat/SHIP b/dat/SHIP
deleted file mode 100644
index 5e84f0c..0000000
--- a/dat/SHIP
+++ /dev/null
@@ -1,14 +0,0 @@
-// ================
-// NOTES.
-// ================
-
-Units:
- Thrust, speed is in pixels/second.
- turn is in degrees per half a second.
-
- energy, armor and shield regen are in points a minute.
-
- crew is in, uh.. people.
- mass is in tons.
- cargo and weapon capacity are int tons.
-
diff --git a/dat/commodity.xml b/dat/commodity.xml
deleted file mode 100644
index 096559e..0000000
--- a/dat/commodity.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
- Airtight compressed nutrient packets. Very nutritious.
- 140
-
-
- All sorts of assorted ores. Needed for all sorts of production processes.
- 210
-
-
- Your basic industrial goods. From cutting lasers to processed metals.
- 340
-
-
- An assortment of medicines suitable for curing all sorts of ailments.
- 750
-
-
- All sorts of high quality luxury goods.
- 630
-
-
-
-
-
-
-
-
-
diff --git a/dat/faction.xml b/dat/faction.xml
deleted file mode 100644
index 119d215..0000000
--- a/dat/faction.xml
+++ /dev/null
@@ -1,164 +0,0 @@
-
-
-
- 0
-
-
-
-
- 0
-
- Trader
-
-
- Pirate
- Collective
- FLF
-
-
-
- Frontier Alliance
- 0
-
- Trader
-
-
- Pirate
- Collective
-
-
-
- Space Traders Guild
- 0
-
- Independent
- Empire
- Soromid
- Frontier
-
-
- Pirate
- FLF
- Collective
-
-
-
- Galactic Pirates
- -20
-
- Empire
- Dvaered
- Za'lek
- Collective
- Soromid
- Sirius
- Frontier
-
-
-
- empire
- 0
-
- Dvaered
- Soromid
- Za'lek
- Trader
- Sirius
-
-
- Pirate
- FLF
- Collective
-
-
-
- -100
-
- Empire
- Dvaered
- Za'lek
- Soromid
- Pirate
- FLF
- Sirius
- Frontier
-
-
-
- Frontier Liberation Front
- -10
-
- Empire
- Dvaered
- Za'lek
- Collective
- Soromid
-
-
-
- dvaered
- House Dvaered
- 0
-
- Empire
-
-
- Pirate
- FLF
- Collective
-
-
-
- zalek
- House Za'lek
- 0
-
- Empire
-
-
- Pirate
- Collective
- FLF
-
-
-
- sirius
- House Sirius
- 0
-
- Empire
-
-
- Pirate
- Collective
- FLF
-
-
-
- House Soromid
- 0
-
- Empire
- Trader
-
-
- Pirate
- FLF
- Collective
-
-
-
- goddard
- House Goddard
- 0
-
- Empire
- Trader
-
-
- Pirate
- FLF
- Collective
-
-
-
diff --git a/dat/fleet.xml b/dat/fleet.xml
deleted file mode 100644
index df50f7f..0000000
--- a/dat/fleet.xml
+++ /dev/null
@@ -1,323 +0,0 @@
-
-
-
- goddard
- Goddard
-
- Goddard
-
-
-
- trader
- Trader
-
- Llama
-
-
-
- trader
- Trader
-
- Koala
-
-
-
- trader
- Trader
-
- Mule
-
-
-
- trader
- Trader
-
- Llama
- Llama
- Koala
- Mule
-
-
-
- flf
- FLF
-
- Pacifier
-
-
-
- flf
- FLF
-
- Vendetta
-
-
-
- flf
- FLF
-
- Hyena
- Hyena
- Admonisher
- Vendetta
-
-
-
- flf
- FLF
-
- Hyena
- Hyena
- Hyena
- Admonisher
- Vendetta
- Vendetta
- Pacifier
-
-
-
- flf
- FLF
-
- Hyena
- Hyena
- Hyena
- Hyena
- Admonisher
- Admonisher
- Vendetta
- Vendetta
- Vendetta
- Pacifier
- Hawking
-
-
-
- pirate
- Pirate
-
- Hyena
-
-
-
- pirate
- Pirate
-
- Hyena
- Hyena
- Hyena
- Hyena
- Hyena
-
-
-
- pirate
- Pirate
-
- Pirate Admonisher
-
-
-
- pirate
- Pirate
-
- Pirate Vendetta
-
-
-
- pirate
- Pirate
-
- Pirate Ancestor
-
-
-
- pirate
- Pirate
-
- Pirate Kestrel
-
-
-
- collective
- Collective
-
- Drone
-
-
-
- collective
- Collective
-
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
-
-
-
- collective
- Collective
-
- Drone
- Drone
- Drone
- Drone
- Drone
- Drone
-
-
-
- dvaered
- Dvaered
-
- Dvaered Vendetta
-
-
-
- dvaered
- Dvaered
-
- Dvaered Ancestor
-
-
-
- dvaered
- Dvaered
-
- Dvaered Goddard
- Dvaered Ancestor
- Dvaered Ancestor
-
-
-
- dvaered
- Dvaered
-
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Ancestor
- Dvaered Ancestor
- Dvaered Goddard
-
-
-
- dvaered
- Dvaered
-
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Ancestor
- Dvaered Ancestor
- Dvaered Ancestor
- Dvaered Goddard
-
-
-
- empire
- Empire
-
- Empire Lancelot
-
-
-
- empire
- Empire
-
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Pacifier
- Empire Hawking
-
-
-
- empire
- Empire
-
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Admonisher
- Empire Admonisher
- Empire Pacifier
- Empire Hawking
- Empire Hawking
-
-
-
- empire
- Empire
-
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Admonisher
- Empire Pacifier
- Empire Hawking
-
-
-
- empire
- Empire
-
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Pacifier
-
-
-
- empire
- Empire
-
- Empire Pacifier
-
-
-
- empire
- Empire
-
- Empire Admonisher
-
-
-
- collective
- Collective
-
- Empire Hawking
-
-
-
- collective
- Collective
-
- Goddard
-
-
-
diff --git a/dat/fleetgroup.xml b/dat/fleetgroup.xml
deleted file mode 100644
index c2fbf92..0000000
--- a/dat/fleetgroup.xml
+++ /dev/null
@@ -1,129 +0,0 @@
-
-
-
- Goddard Goddard
- Goddard Goddard
-
-
- Trader Llama
- Trader Llama
- Trader Koala
- Trader Koala
- Trader Mule
-
-
- Trader Llama
- Trader Llama
- Trader Koala
- Trader Koala
- Trader Mule
- Trader Mule
- Sml Trader Convoy
-
-
- Trader Llama
- Trader Llama
- Trader Llama
- Trader Koala
- Trader Koala
- Trader Koala
- Trader Mule
- Trader Mule
- Trader Mule
- Sml Trader Convoy
- Sml Trader Convoy
-
-
- Pirate Hyena
- Pirate Vendetta
- Pirate Ancestor
- Pirate Hyena Pack
- Pirate Admonisher
-
-
- Pirate Hyena
- Pirate Vendetta
- Pirate Ancestor
- Pirate Hyena Pack
- Pirate Admonisher
-
-
- Pirate Hyena
- Pirate Hyena
- Pirate Vendetta
- Pirate Vendetta
- Pirate Ancestor
- Pirate Ancestor
- Pirate Hyena Pack
- Pirate Admonisher
- Pirate Kestrel
-
-
- Empire Pacifier
- Empire Pacifier
-
-
- Empire Lancelot
- Empire Admonisher
- Empire Pacifier
-
-
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Pacifier
-
-
- Empire Lancelot
- Empire Lancelot
- Empire Admonisher
- Empire Admonisher
- Empire Pacifier
- Empire Pacifier
- Empire Sml Defense
-
-
- Collective Drone
- Collective Drone
- Collective Sml Swarm
-
-
- Collective Drone
- Collective Drone
- Collective Drone
- Collective Sml Swarm
- Collective Sml Swarm
-
-
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Ancestor
-
-
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Ancestor
- Dvaered Ancestor
- Dvaered Goddard
-
-
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Vendetta
- Dvaered Ancestor
- Dvaered Ancestor
- Dvaered Goddard
- Dvaered Sml Force
-
-
- FLF Vendetta
- FLF Pacifier
- FLF Sml Force
-
-
- FLF Vendetta
- FLF Pacifier
- FLF Sml Force
- FLF Med Force
-
-
diff --git a/dat/font.ttf b/dat/font.ttf
deleted file mode 100644
index 2072cda..0000000
Binary files a/dat/font.ttf and /dev/null differ
diff --git a/dat/gui.xml b/dat/gui.xml
deleted file mode 100644
index 2d70a4a..0000000
--- a/dat/gui.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
- minimal_energy
- minimal_fuel
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dat/intro b/dat/intro
deleted file mode 100644
index 5a3dbe5..0000000
--- a/dat/intro
+++ /dev/null
@@ -1,23 +0,0 @@
- Humans had always looked up at the skies at night, dreaming of being one with the stars. Yet they could never imagine what their dreams got them in.
-
- They ended getting into space and the revolution that this provoked. With the advent of terraforming technologies colonists began flocking to the stars en masse. Many worlds were colonized and humanity expanded. It was still slow traveling and time was starting to erode humanity's unity.
-
- Then came the great advance in travel. Light speeds were finally broken. This technology spread quickly and reignited the colonization spree. Humans had conquered a great part of the galaxy. Things were hectic though, with mankind fragmented in many factions. A federation was created to attempt to affront this.
-
- Yet this only incremented tension. Man was too fractured to be weaved together with diplomacy. War broke out, timidly at first, but quickly gathering momentum. Thus began the Great Faction War.
-
- Being the first space-era all out global war, the Faction War brought much pain and misery to humanity. Many planets were annihilated, trillions killed, all in the name each faction. Mankind started becoming tribal and isolated, separated by vast space filled with the debris of battleships and smoldering planets. Then came hope at the hand of Emperor Daedris.
-
- A newly forged Empire began sweeping the factions, dominating with clear military superiority. Some factions resisted at first, but most saw the only way was to submit to the iron fist of the Emperor. Eventually there was only the Empire. Those who helped in the birth of this Empire were given the status of Great House, and the golden age began.
-
- Trade routes were created, patrols were installed and piracy was non-existent. Supplies were being moved all around the Empire and population was booming. Technology advanced quickly and permitted the terraforming of many new planets. All was working well.
-
- Eventually corruption started to appear, slowly at first, but ended up avalanching. The Great Houses started bickering between each other. Privateers and Pirates started appearing, while the Emperor started to get drowned in bureaucracy. Terrorism also began to appear by sectors of the Empire not content with their status.
-
- Then suddenly, silence. No one knows exactly what happened, but a gigantic explosion shook the foundations of the universe. The magnitude of the explosion was so enormous that it quickly annihilated many planets leaving a gigantic void in the center of the Empire. Humanity's birthplace was near the epicenter, and the entire area was covered in a gigantic nebulae. It is referred to as The Incident and marks the end of the golden age.
-
- You find yourself in a universe with a decaying Empire, full of piracy and corruption shaken to it's very bones by the Incident. However where there is chaos, there is also opportunity.
-
-
-
- Welcome to the universe of Lephisto...
diff --git a/dat/mission.xml b/dat/mission.xml
deleted file mode 100644
index 154ac69..0000000
--- a/dat/mission.xml
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
- tutorial
-
- 1
-
-
- None
-
-
-
- neutral/cargo
-
- 960
- Computer
- Independent
- Empire
- Soromid
- Dvaered
- Frontier
- Goddard
-
-
-
- empire/emp_cargo00
-
- 1
-
-
- 80
- Bar
- Empire
-
-
-
- empire/es_cargo
-
- player.getFaction("Empire") >= 0 and var.peek("es_cargo") == true
- 350
- Computer
- Empire
- Soromid
-
-
-
- empire/shipping/es00.lua
-
- player.getFaction("Empire") >= 0 and var.peek("es_misn") >= 3
- 30
- Bar
- Empire
-
-
-
- empire/collective/ec00
-
- 1
-
-
- var.peek("es_cargo") == true and space.getSystem("NGC-7291"):jumpDist() < 5 and player.getFaction("Empire") > 5 and player.getRating() > 5 and var.peek("collective_fail") ~= true
- 80
- Bar
- Empire
-
-
-
- empire/collective/ec01
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("collective_fail") ~= true
- Collective Scouting
- 100
- Bar
- Omega Station
-
-
-
- empire/collective/ec02
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("collective_fail") ~= true
- Collective Espionage 1
- 100
- Bar
- Omega Station
-
-
-
- empire/collective/ec03
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("collective_fail") ~= true
- Collective Espionage 2
- 100
- Bar
- Omega Station
-
-
-
- empire/collective/ec04
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("emp_commando") ~= nil and time.get() > var.peek("emp_commando")
- Collective Espionage 3
- 100
- Land
- Omega Station
-
-
-
- empire/collective/ec05
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("collective_fail") ~= true
- Collective Distraction
- 100
- Bar
- Omega Station
-
-
-
- empire/collective/ec06
-
- 1
-
-
- player.getFaction("Empire") > 5 and var.peek("collective_fail") ~= true
- Operation Black Trinity
- 100
- Bar
- Omega Station
-
-
-
- neutral/nebu_satellite
-
- 1
-
-
- 15
- Bar
- Independent
- Empire
- Soromid
- Dvaered
- Frontier
- Goddard
-
-
-
- dvaered/dv_patrol
-
- 366
- player.getFaction("Dvaered") > 5 and player.getRating() > 100
- Computer
- Dvaered
-
-
-
diff --git a/dat/missions/dvaered/dv_patrol.lua b/dat/missions/dvaered/dv_patrol.lua
deleted file mode 100644
index 15270c9..0000000
--- a/dat/missions/dvaered/dv_patrol.lua
+++ /dev/null
@@ -1,176 +0,0 @@
---[[
--- Handles random Dvaered Patrol missions.
---
--- Stage 1: Travelling.
--- Stage 2: Must clear enemies.
--- Stage 3: Continue travelling.
---]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default English.
- misn_desc = {}
- misn_desc[1] = "Patrol %d systems for hostiles: "
- misn_desc[2] = "Travel to the %s system and check for hostiles."
- misn_desc[3] = "Return to %s in the %s system for payment."
- misn_reward = "%d credits"
- title = {}
- title[1] = "DV: Routine %d sector patrol"
- title[2] = "DV: Patrol %d sectors"
- title[3] = "DV: Scan of %d sectors"
- accpet_title = "Mission Accepted"
- msg_title = {}
- msg_msg = {}
- msg_title[1] = "Mission Success"
- msg_msg[1] = "You are greeted by a Dvaered official and recieve your payment of %d credits for your contribution in keeping Dvaered systems clean."
- msg_msg[2] = "DV: Engage hostiles."
- msg_msg[3] = "MISSION FAILED: Fled from the heat of battle."
- msg_msg[5] = "DV: Patrol finished, return to base."
-end
-
--- Create the mission.
-function create()
- -- Get systems to patrol.
- num_systems = rnd.int(2, 4)
- systems = {}
- s = space.getSystem():adjacentSystems()
- systems[1] = s[rnd.int(1, #s)]
- for i = 2, num_systems do
- s = systems[i-1]:adjacentSystems()
- systems[i] = s[rnd.int(1, #s)]
- end
- system1, system2, system3, system4 = unpack(systems)
- base, base_sys = space_getPlanet()
- misn_setMarker(systems[1])
-
- -- Create the description.
- desc = string.format(misn_desc[1], num_systems) .. systems[1]:name()
- for i = 2, num_systems-1 do
- desc = desc ..", " .. systems[i]:name()
- end
- desc = desc .. " and " .. systems[num_systems]:name() .. "."
-
- -- Set mission stage.
- misn_stage = 1
- visited = 0
-
- -- Calculate reward.
- reward = 10000
- for i = 1, num_systems do
- reward = reward + 15000 + 5000 * rnd.twosigma()
- end
-
- -- Set some details.
- misn.setTitle(string.format(title[rnd.int(1, 3)], num_systems))
- misn.setDesc(desc)
- misn_setReward(string.format(misn_reward, reward))
-end
-
--- Mission is accepted.
-function accept()
- if misn.accept() then
-
- -- Update the description.
- misn.setDesc(string.format(misn_desc[2], systems[1]:name()))
-
- -- Set the hooks.
- hook.land("land")
- hook.enter("jump")
- end
-end
-
--- Jump hook.
-function jump()
- if misn_stage == 1 then
- sys = space.getSystem()
-
- -- Hack in case it wasn't saved.
- if systems == nil then
- systems = { system1, system2, system3, system4 }
- end
-
- -- Check to see if system is next.
- if sys == systems[visited+1] then
- visited = visited + 1
-
- -- Get the next goal.
- setNextGoal()
- end
- elseif misn_stage == 3 then
- player.msg(msg_msg[3])
- misn.finish(false)
- end
-end
-
--- Set the next goal.
-function setNextGoal()
- -- Check to see if there are enemies.
- f = faction.get("Dvaered")
- enemies = pilot.get(f:enemies())
- hostiles = #enemies
- if hostiles > 0 then
- misn_stage = 3
-
- -- Set hooks.
- for k,v in ipairs(enemies) do
- v:setHostile() -- Should be hostile to player.
- hook.pilot(v, "disable", "death")
- hook.pilot(v, "jump", "death")
- end
-
- -- Update description and send messages.
- player.msg(msg_msg[2])
- misn.setDesc(string.format(misn_desc[4], sys:name()))
-
- -- No hostiles, continue route.
- else
- -- Finished visiting systems.
- if visited >= #systems then
- misn_stage = 2
- player.msg(msg_msg[5])
- misn.setDesc(string.format(misn_desc[3], base:name(), base_sys:name()))
- misn.setMarker(base_sys)
-
- -- Need to visit more systems.
- else
- player.msg(msg_msg[4])
- misn.setDesc(string.format(misn_desc[2], systems[visited+1]:name()))
- misn.setMarker(systems[visited+1])
- end
- end
-end
-
--- Pilot death hook.
-function death()
- hostiles = hostiles - 1
- if hostiles <= 0 then
- misn_stage = 1
- setNextGoal()
- end
-end
-
--- land hook.
-function land()
- landed = space.getPlanet()
- if misn_stage == 2 and landed == base then
- player.pay(reward)
- tk.msg(msg_title[1], string.format(msg_msg[1], reward))
-
- -- Increase dv patrol mission counter.
- n = var.peek("dv_patrol")
- if n ~= nil then
- var.push("dv_patrol", n+1)
- else
- var.push("dv_patrol", 1)
- end
-
- -- Modify the faction standing.
- if player.getFaction("Dvaered") < 70 then
- player.modFaction("Dvaered", rnd.rnd(1, num_systems/2));
- end
-
- misn.finish(true)
- end
-end
-
diff --git a/dat/missions/empire/collective/ec00.lua b/dat/missions/empire/collective/ec00.lua
deleted file mode 100644
index c0ab8ae..0000000
--- a/dat/missions/empire/collective/ec00.lua
+++ /dev/null
@@ -1,94 +0,0 @@
---[[
--- Start the collective mini campaign.
---
--- You must inspect a stray drone.
---]]
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default english.
- misn_title = "Collective Scout"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Find a scout last seen in the %s system."
- misn_desc[2] = "Travel back to %s in %s."
- title = {}
- title[1] = "Empire Officer"
- title[2] = "Briefing"
- title[3] = "Mission Accomplished"
- text = {}
- text[1] = [[As you enter the bar you notice some one signal to you from the counter. You notice he's wearing an Empire insignia on his uniform.
-"Hello %s, we have a reconnaissance you might be interested. You up for the challenge?"]]
- text[2] = [["I don't think we've met. I'm Sargent Dimitri. If all goes well you'll be reporting to me for the next assignments."
-"This week Collective activity has increased heavily around NGC-7291. We've been trying to contain them, but reports detect that a scout broke through. The scout was last detected near %s. We expect it to not have gone far. You are to locate the scout and report back to %s in the %s system. It seems like the Collective is planning something and we want to follow their game a bit more"
-"It is of vital important that you do not engage the drone. Report back as soon as you locate it."]]
- text[3] = [[After landing you head to the Empire military headquarters and find Sgt. Dimitri there.
-"Well it seems like the drone has some strange fixation with %s. We aren't quite sure what to make of it, but intelligence is on it. Report back at the bar in bit and we'll see what we can do about the Collective"]]
- msg_killdrone = "Mission Failed: You weren't supposed to kill the drone!"
-end
-
-function create()
- -- Intro text.
- if tk.yesno(title[1], string.format(text[1], player.name()))
- then
- misn.accept()
-
- misn_stage = 0
- misn_nearby = space.getSystem("Coriolis")
- misn_target = space.getSystem("Dune")
- misn_base,misn_base_sys = space.getPlanet("Omega Station")
- misn_base_sys = "NGC-7291"
- misn.setMarker(misn_nearby) -- Not exact target.
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(string.format(misn_desc[1],misn_nearby:name()))
-
- -- Flavour text and mini-briefing.
- tk.msg(title[2], string.format(text[2], misn_nearby:name(),
- misn_base:name(), misn_base_sys:name()))
-
- hook.enter("enter")
- hook.land("land")
- end
-end
-
-function enter()
- sys = space.getSystem()
-
- -- Additional fleets.
- if sys:name() == "NGC-7291" then -- Increase action for realism.
- pilot.add("Empire Sml Defense")
- pilot.add("Collective Sml Swarm")
- elseif sys == misn_target then
- p = pilot.add("Collective Drone", "scout")
- for k,v in pairs(p) do
- hook.pilot(v, "death", "kill")
- end
- end
-
- -- Update mission.
- if misn_stage == 0 and sys == misn_target then
- misn.setDesc(string.format(misn_desc[2], misn_base:name() ,misn_base_sys:name()))
- misn_stage = 1
- misn.setMarker(misn_base_sys) -- Now we mark return to base.
- end
-end
-
-function land()
- planet = space.getPlanet()
-
- if misn_stage == 1 and planet == misn_base then
- tk.msg(title[3], string.format(text[3],misn_target:name()))
- player.modFaction("Empire", 5)
- misn.finish(true)
- end
-end
-
-function kill()
- player.msg(msg_killdrone)
- misn.finish(false)
- var.push("collective_fail", true)
-end
-
diff --git a/dat/missions/empire/collective/ec01.lua b/dat/missions/empire/collective/ec01.lua
deleted file mode 100644
index ebefc6b..0000000
--- a/dat/missions/empire/collective/ec01.lua
+++ /dev/null
@@ -1,75 +0,0 @@
---[[
--- Second mission in the mini collective compaign.
---
--- You must inspect a system for wireless communications.
---]]
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default language.
- misn_title = "Collective Espionage"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Scan the Collective systems for wireless communications."
- misn_desc[2] = "Travel back to %s in %s."
- title = {}
- title[1] = "Sargent Dimitri"
- title[2] = "Collective Espionage"
- title[3] = "Mission Accomplished"
- text = {}
- text[1] = [[You notice Sargent Dimitri at the bar, he calls you over.
- "We managed to capture the drone after you located it. It didn't seem to be in good health. Our scientists are studying it as we speak, but we've found something strange in it. Some sort of weird wireless module. We'd like you to go run through the collective systems to see if you can pick up any strange wireless communications. Just do a quick run through, be careful of the Collective though. You interested in doing the run? It'll be dangerous."]]
- text[2] = [["Just run through some systems while keeping your communications system on logging. We'll parse the results when you get back. Good luck."]]
- text[3] = [[After landing, Sargent Dimitri greets you on the pad.
- "I suppose all went well? Those drones can really give a beating. We'll have the researchers start looking at your logs right away. Meet me in the bar again in a while."]]
-end
-
-function create()
- -- Intro text.
- if tk.yesno(title[1], text[1]) then
- misn.accept()
-
- misn_stage = 0
- systems_visited = 0 -- Number of Collective systems visited.
- misn_base,misn_base_sys = space.getPlanet("Omega Station")
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(misn_desc[1])
-
- tk.msg(title[2], text[2])
-
- hook.enter("enter")
- end
-end
-
-function enter()
- local sys = space.getSystem()
- local factions = sys:faction()
-
- -- Increment system visited count.
- if misn_stage == 0 and factions["Collective"] then
- systems_visited = systems_visited + 1
-
- -- Visited enough systems.
- if misn_stage == 0 and systems_visited >= 2 then
- misn.setDesc(string.format(misn_desc[2],
- misn_base:name(), misn_base_sys:name()))
- misn_stage = 1
- misn.setMarker(misn_base_sys) -- Now we mark return to base.
- hook.land("land")
- end
- end
-end
-
-function land()
- local planet = space.getPlanet()
-
- if misn_stage == 1 and planet == misn_base then
- tk.msg(title[3], text[3])
- player.modFaction("Empire", 5);
- misn.finish(true)
- end
-end
-
diff --git a/dat/missions/empire/collective/ec02.lua b/dat/missions/empire/collective/ec02.lua
deleted file mode 100644
index 6555d59..0000000
--- a/dat/missions/empire/collective/ec02.lua
+++ /dev/null
@@ -1,79 +0,0 @@
---[[
--- Third mission in the collective campaign.
---
--- You must land on an ex-empire planet in collective territory and return.
---]]
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated yet.
-else -- Default English.
- misn_title = "Collective Espionage"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Land on %s in the %s system to monitor Collective communications."
- misn_desc[2] = "Travel back to %s in %s."
- title = {}
- title[1] = "Collective Espionage"
- title[2] = "Mission Accomplished"
- text = {}
- text[1] = [[You notice Sargent Dimitry at one of the booths. You head over to see what the results are.
- "Hello again there %s. Bad news on your latest run, you got nothing other than the usual robotic chatter. We'll have to send you out again, this time we'll follow a different approach. Interested in giving it another shot?]]
- text[2] = [["On your last run you where monitoring while out in the open, while you do get better signals, upon noticing your presence. This mission will consist of hiding and moitoring from a safer spot, Hopefully catching them more relaxed."
- "When the Collective struck, they quickly took many systems, one of the bigger hits was %s, an important gas gient rich in methane. They destroyed the gas refineries and slaughtered the humans, there was nothing we could do. the turbulance and dense atmosphere should be able to hide your ship."]]
- text[3] = [["The plan is to have you infiltrate Collective space alone, to no arouse too much suspicion. Once inside you should head to %s system. Stay low and monitor all frequencies in the system. If anything is suspicious, we'll surely catch it then."
- "Good luck, I'll be waiting for you on your return."]]
- text[4] = [[You quickly land on %s and hide in the deep dense methane atmosphere it has. Your monitoring gear flickers into action, hopefully catching something of use. With some luck there won't be too many collective ships when you take off.]]
- text[5] = [[As your ship touches ground you see Sargent Dimitry come out to greet you.
- "How was the weather", he mentions jokingly. "Glad to see you're in one peice. We'll get right on analyzing the data acquired. These robots have to be up to something. Meet me in the bar later, meanwhile give yourself a treat, you earned it. We've made a 100k scred deposit in your bank account, enjoyu it"]]
-end
-
-function create()
- -- Intro text.
- if tk.yesno(title[1], string.format(text[1], player.name())) then
- misn.accept()
-
- misn_stage = 0
- systems_visited = 0 -- Number of Collective systems visited.
- misn_base, misn_base_sys = space.getPlanet("Omega Station")
- misn_target, misn_target_sys = space.getPlanet("Eiroik")
- misn.setMarker(misn_target_sys)
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(string.format(misn_desc[1], misn_target:name(), misn_target_sys:name()))
-
- tk.msg(title[1], string.format(text[2], misn_target:name()))
- tk.msg(title[1], string.format(text[3]. misn_target:name(), misn_target_sys:name()))
-
- hook.enter("land")
- end
-end
-
-function land()
- planet = space.getPlanet()
-
- -- First mission part is landing on the planet.
- if misn_stage == 0 and planet == misn_target then
- -- Sinister music landing.
- music.load("landing_sinister")
- music.play()
-
- -- Some text.
- tk.msg(title[1], string.format(text[4], misn_target:name()))
- misn_stage = 1
- misn.setDesc(string.format(misn_desc[1], misn_base:name(), misn_base_sys:name()))
- misn.setMarker(misn_base_sys)
-
- -- Return bit.
- elseif misn_stage == 1 and planet == misn_base then
- tk.msg(title[2], text[5])
-
- -- Rewards.
- player.modFaction("Empire", 5)
- player.pay(10000)
-
- misn.finish(true)
- end
-end
-
diff --git a/dat/missions/empire/collective/ec03.lua b/dat/missions/empire/collective/ec03.lua
deleted file mode 100644
index cf8d764..0000000
--- a/dat/missions/empire/collective/ec03.lua
+++ /dev/null
@@ -1,92 +0,0 @@
--- [[
--- Collective Espionage III
---
--- Fourth mission in the collective mini campaign.
---
--- You must distract the collective forces by breaching into their systems
--- while a commando lands to monitor wireless.
--- ]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default English.
- misn_title = "Collective Espionage"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Go to draw the Collective's attention in the %s system."
- misn_desc[2] = "Travel back to %s in %s."
- title = {}
- title[1] = "Collective Espionage"
- title[2] = "Mission Accomplished"
- text = {}
- text[1] = [[You find Sergeant Dimitri at the bar as usual. He looks somewhat excited as you approach.
- "It looks like you got something. It's not very clear because of %s's atmosphere creating a lot of noise, but it does seem to be similar to Empire transmissions. We've got another plan to try to get a cleaner signal. It'll be uglier than the last one. You in?"]]
- text[2] = [["Here's the plan: We want to drop a commando team on %s to set up more sophisticated surveillance. We've already got a team assembled. Your job would be to provide a distraction."
- "The idea would be to have you fly deep into Collective territory and start causing disturbances. This is no suicidal mission so you'll have to fly back when things start getting ugly. Meanwhile we'll send a fast convoy with the commandos to %s who will start monitoring."]]
- text[3] = [["If all goes well, the commandos will stay 10STU before returning here with the results. Then we'll have a definitive answer on the communication issues. We aren't anticipating problems on the return, but we'll have some ships ready just in case they get chased."
- "Good luck and be careful out there", he adds before saluting you off onto your mission.]]
- text[4] = [[Your ship touches ground and once again you see the face of sergeant Dimitri.
- "How was the trip? I trust you didn't have too many issues evading the Collective. We won't hear from the commandos until 10STU from now when they get back, but I believe everything went well."
- "Stay alert. We'll probably need your assistance when they get back. Take the free time as vacation. I heard the weather on Caladan is pretty nice this time of year, maybe you should visit them. We'll keep in touch."]]
-end
-
-function create()
- commando_planet = "Eiroik"
-
- -- Intro text.
- if tk.yesno(title[1, string.format(text[1], commando_planet)) then
- misn_accept()
-
- misn_stage = 0
- misn_base, misn_base_sys = space.getPlanet("Omega Station")
- misn_target_sys = space.getSystem("C-28")
- misn.setMarker(misn_target_sys)
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(string.format(misn_desc[1], misn_target_sys:name()))
-
- tk.msg(title[1], string.format(text[2], commando_planet, commando_planet))
- tk.msg(title[1], text[3])
-
- hook.enter("jump")
- end
-end
-
--- Handles jumping to target system.
-function jump()
- local sys = space.getSystem()
- local factions = sys:faction()
-
- -- First mission part is landing on the planet.
- if misn_stage == 0 and sys == misn_target_sys then
- -- Maybe introducing a delay here would be interesting.
- misn_stage = 1
- misn_setDesc(string.format(misn_desc[2], misn_base:name(), misn_base_sys:name()))
- misn_setMarker(misn_base_sys)
- hook.land("land")
-
- elseif misn_stage == 1 and (sys:name() == "NGC-7132" or factions["Collective"]) then
- pilot.add("Collective Sml Swarm")
- end
-end
-
--- Handle arrival back to base.
-function land()
- planet = space.getPlanet()
-
- if misn_stage == 1 and planet == misn_base then
- tk.msg(title[2], text[4])
-
- -- Store time commando theoretically landed.
- var.push("emp_commando", time_get() + time.units(10))
-
- -- Rewards.
- player.modFaction("Empire", 5)
-
- misn.finish(true)
- end
-end
-
diff --git a/dat/missions/empire/collective/ec04.lua b/dat/missions/empire/collective/ec04.lua
deleted file mode 100644
index a4eb059..0000000
--- a/dat/missions/empire/collective/ec04.lua
+++ /dev/null
@@ -1,98 +0,0 @@
---[[
--- Collective Distraction.
---
--- Fifth mission in the collective mini campaign.
---
--- You must go rescue a team of commandos after being attacked by collective
--- forces on a surveillence mission.
---]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default english.
- misn_title = "Collective Distraction"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Check for survivors on %s in %s."
- misn_desc[2] = "Travel back to %s in %s."
- title = {}
- title[1] = "Collective Espionage"
- title[2] = "Eiroik"
- title[3] = "Mission Accomplished"
- text = {}
- text[1] = [[As soon as you exit the landing pad you see Sergeant Dimitri waiting for you. He seems a bit more nervouse than usual.
- "We haven't heard from the commando team, we have to assume the worst. It seems like Collective presence has also been incremented around %s. We need you to go check for survivors. Would you be willing to embark on another dangerous mission?"]]
- text[2] = [["We'll send extra forces to %s to try to weaken the blockade. You'll have to fly through and land on %s and see if there are any survivors. The increased drone patrols will pose an issue, be very careful, this is going to be no walk in the park."]]
- text[3] = [[The atmosphere once again starts giving your shields a workout as you land. You spend a while flying low until you see sensors pick up a reading of possible life forms. The silhouette of the transport ships is barely visible. It seems like they were detected and massacred. You try to see if you can salvage the readings from their equipment, but it seems like it's completely toasted.
- You spend a while searching until you find a datapad on one of the corpses, ignoring the stench of burnt flesh, you grab it, you've got one right?]]
- text[4] = [[Sergeant Dimitri's face cannot hide his sadness as he sees you approachwith no commando members.
- "No survivors eh? I had that gut feeling. At least you were able to salvage something? Good, at least it'll make these deaths not be completely futile. Meet me in the bar in a while. We're going to try to process this datapad. It'll hopefully have the final results."]]
-end
-
-function create()
- misn_target, misn_target_sys = sapce.getPlanet("Eiroik")
-
- -- Intro text.
- if tk.yesno(title[1], string.format(text[1], misn_target:name())) then
- misn.accept()
-
- misn_stage = 0
- blockade_sys = space.getSystem("NGC-7132")
- misn_base, misn_base_sys = space.getPlanet("Omega Station")
- misn.setMarker(misn_target_sys)
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(string.format(misn_desc[1], misn_target:name(), misn_target_sys:name()))
- tk.msg(title[1], string.format(text[2], blockade_sys:name(), misn_target:name()))
-
- hook.enter("jump")
- hook.land("land")
- end
-end
-
--- Handle jumping to target system.
-function jump()
- local sys = space.getSystem()
- local factions = sys:faction()
-
- -- Create some havoc.
- if factions["Collective"] then
- pilot.add("Collective Sml Swarm")
- pilot.add("Collective Sml Swarm")
- elseif sys == blockade_sys then
- pilot.add("Collective Sml Swarm")
- pilot.add("Collective Sml Swarm")
- pilot.add("Empire Sml Defense")
- end
-end
-
--- Handle arrival back to base.
-function land()
- local planet = space.getPlanet()
-
- -- Just landing.
- if misn_stage == 0 and planet == misn_target then
- -- Sinister music landing.
- music.load("landing_sinister")
- music.play()
-
- -- Some flavour text.
- tk.msg(title[2], text[3])
- misn_stage = 1
- misn.setDesc(string.format(misn_desc[2], misn_base:name(), misn_base_sys:name()))
- misn.setMarker(misn_base_sys)
- misn_cargo = player.addCargo("Datapad", 0)
- elseif misn_stage == 1 and planet == misn_base then
- tk.msg(title[3], text[4])
- player.rmCargo(misn_cargo)
-
- -- Rewards.
- player.modFaction("Empire", 5)
-
- misn.finish(true)
- end
-end
-
diff --git a/dat/missions/empire/collective/ec05.lua b/dat/missions/empire/collective/ec05.lua
deleted file mode 100644
index a4bd480..0000000
--- a/dat/missions/empire/collective/ec05.lua
+++ /dev/null
@@ -1,270 +0,0 @@
---[[
--- Operation Black Trinity.
---
--- Sixth mission in the collective mini campaign.
---
--- Notable compaign changes:
--- * Keer takes over command superseding Dimitri.
--- * First real combat begins.
--- * Most of the pilot is unrevealed.
---
--- Mission Obectives:
--- * Attempt to arrest Zakred.
--- * Kill Zakred.
---
--- Mission Stages:
--- 0) Get to the trinity.
--- 1) Trinity combat.
--- 2) Trinity dead/run.
--- 3) Ran away.
---
--- Not too happy with the text (it chews it all up for you), but then again,
--- I'm no writer. ;P
---]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else
- misn_title = "Operation Black Trinity"
- misn_reward = "None"
- misn_desc = {}
- misn_desc[1] = "Arrest the ESS Trinity in %s."
- misn_desc[2] = "Return to base at %s in %s."
- title = {}
- title[1] = "Bar"
- title[2] = "Interrogation Room"
- title[3] = "Operation Black Trinity"
- title[4] = "Mission Accomplished"
- title[5] = "Mission Failure"
- text = {}
- text[1] = [[As you enter the bar you can't seem to to see Sergeant Dimitri. You look a around a little for him, when you feel a heavy hand fall on your shoulder. It seems like two armed soldiers are here to escort you somewhere, and from the looks of their weapons, they mean business. You have no choice other than to comply.
- They start leading you away from the bar through some hallways you've never been through. Must be all those 'Authorized Personnel Only' signs and the armed guards that didn't make them too appealing.
- Finally they toss you into what seems to be an interrogation room, telling you just to wait there.]]
- text[2] = [[After what seems to be a decaSTU you hear the door open. You see a condecorated woman walk in with two soldiers at the door. She seems to be a Commodore from the insignia on her uniform.
- "Hello, I'm Commodore Keer, I've taken over the Collective issue. I have heard about your success in the previous missions and would like to offer you more continued work. However further procedings must be kept in strict confidentiality for the interest of the Empire. Are you willing to go all the way with this?"]]
- text[3] = [[You accept, she then dismisses both of the soldiers who proceed to wait outside.
- "We've been following Sergeant Dimitri's progress since he started at %s. The datapad you brought back has confirmed what we have suspected. We have an undercover Collective agent somewhere in the military who's been feeding ex-Commodore Welsh data. You don't understand right? Let me Explain."]]
- text[4] = [["The Collective was actually a project for the Empire, they were supposed to be the ultimate weapon in flexibility and offense. Commodore Welsh was in charge of the secret science facility on %s. Shortly after the Incident we stopped hearing from the science facility. We sent a recon and were met with hostile Collective Drones. It seems like the project had been a success, but the traitor Welsh went rogue. Under normal circumstances we would have easily crushed the Collective, but after the incident these are hardly normal circumstances."
- She goes on, "Things have got out of hand. We have had chances to crush Welsh, but he seems to have always evaded us and struck us where we were weakest. We always knew there must have been another traitor in our midst, but the datapad information we now know who it is."]]
- text[5] = [[She now clears her throat, "This operation has been dubbed "Operation Black Trinity". We have reason to believe that the ESS Trinity has been operating with the traitor Welsh. The ESS Trinity is commanded by Captain Zakred. You will form part of an assault team with primary objectives of arresting Zakred. If all goes wrong, you are ordered to kill Zakred. He must not escape."
- "We'll be sending you with a small force. You just stick around and if any trouble arises, take the ESS Trinity down. Zakred is currently doing some maneuver exercises in %s. You will have to find him there. The other ships will follow your lead to %s. Good luck!"]]
- text[6] = [[You see Commodore Keer with a dozen soldiers waiting for you outside the landing pad.
- Congratulations on the success %s. We never really expected to take Zakred alove. Good Riddance. The next step is to begin an all out attack on Collective territory. Meet up in the bar when you're ready. We'll need all available pilots."]]
- text[7] = [[You see Commodore Keer with a dozen soldiers waiting for you outside the landing pad.
- You weren't supposed to let the Trinity get away! Now we have no cards to play, we must wait for the Collective response or new information before being able to continue. We'll notify you if we have something you can do for us, but for now we just wait."]]
- -- Conversation between pilots.
- talk = {}
- talk[1] = "ESS Trinity: Please turn off your engines and prepare to be boarded."
- talk[2] = "You will never take me alive!"
- talk[3] = "Very well then. All units engage ESS Trinity."
- talk[4] = "Incoming Collective drones detected."
- talk[5] = "Mission Success: Return to base."
- talk[6] = "Mission Failure: Return to base."
-end
-
--- Create the mission.
-function create()
- tk.msg(title[1], text[1])
-
- -- Intro text.
- if tk.yesno(title[2], text[2])
- then
- misn.accept()
-
- -- Mission data.
- misn_stage = 0
- misn_base, misn_base_sys = space.getPlanet("Omega Station")
- misn_target_sys = space.getSystem("NCG-7690")
- misn.setMarker(misn_target_sys)
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward(misn_reward)
- misn.setDesc(string.format(misn_desc[1], misn_target_sys:name()))
- tk.msg(title[2], string.format(text[3], misn_base:name()))
- tk.msg(title[3], string.format(text[4], "Eiroik"))
- tk.msg(title[4], string.format(text[5], misn_target_sys:name()))
-
- -- Escorts.
- esc_pacifier = true
- esc_lancelot1 = true
- esc_lancelot2 = true
-
- hook.enter("jump")
- hook.land("land");
- end
-end
-
--- Handle jumping to target system.
-function jump()
- -- Only done for stage 1.
- if misn_stage == 0 then
- local sys = space.getSystem()
-
- -- Escorts enter a while back.
- enter_vect = player.pos()
- if enter_vect:dist() < 1000 then -- Assume landed.
- add_escorts()
- else -- Just jumped.
- misn.timerStart("add_escorts", rnd.int(2000, 5000))
- end
-
- -- Create some havoc.
- if sys == target_sys then
- -- Disable spawning and clear pilots -> make it more epic. ;P
- pilot.clear()
- pilot.toggleSpawn(false)
-
- misn_stage = 1
-
- -- Position trinity on the other side of the player.
- v = player.pos()
- x, y = v:get()
- v:set(-x, -y)
- trinity = pilot.add("Trinity", "noidle", v)
- trinity = trinity[1]
- hook.pilot(trinity, "death", "trinity_kill")
- hook.pilot(trinity, "jump", "trinity_jump")
-
- final_fight = 0
- misn.timerStart("final_talk", rnd.int(6000, 8000)) -- Escorts should be in system by now.
- end
-
- -- Player ran away from combat - big disgrace..
- elseif misn_stage == 1 then
- misn_stage = 3
- player.msg(talk[6])
- end
-end
-
--- Get the empire talker.
-function emp_talker()
- if esc_pacifier then
- talker = paci
- elseif esc_lancelot1 then
- talker = lance1
- elseif esc_lancelot2 then
- talker = lance2
- else
- -- I don't like the idea of player talking, but we need the conversation.
- talker = player.getPilot()
- end
- return talker
-end
-
--- Little talk when ESS Trinity is encountered.
-function final_talk()
- -- Empire taks about arresting.
- if final_fight == 0 then
- talker = emp_talker()
- talker:broadcast(talk[1])
-
- final_fight = 1
- misn.timerStart("final_talk", rnd.int(3000, 4000))
- elseif final_fight == 1 then
- talker = trinity
- talker:broadcast(talk[2])
-
- final_fight = 2
- misn.timerStart("final_talk", rnd.int(3000, 4000))
- elseif final_fight == 2 then
- -- Talk.
- talk = emp_talker()
- talker:broadcast(talk[3])
-
- -- ESS Trinity becomes collective now.
- trinity:setFaction("Collective")
- trinity:setHostile()
-
- final_fight = 3
- misn.timerStart("final_talk", rnd.int(4000, 5000))
- else if final_fight == 3 then
- player.msg(talk[4])
- misn.timerStart("call_drones", rnd.int(3000, 5000))
- end
-end
-
--- Calls help for the ESS Trinity.
-function call_drones()
- pilots = pilot.add("Collective Sml Swarm")
- for k, v in ipairs(pilots) do
- v:setHostile()
- end
-end
-
--- Add escorts that weren't killed sometime.
-function add_escorts()
- if esc_pacifier then
- enter_vect:add(rnd.int(-50,50), rnd.int(-50,50))
- paci = pilot.add("Empire Pacifier", "escorts_player", enter_vect)
- paci = paci[1]
- paci:setFriendly()
- hook.pilot(paci, "death", "paci_dead")
- end
- if esc_lancelot1 then
- enter_vect:add(rnd.int(-50,50), rnd.int(-50,50))
- lance1 = pilot.add("Empire Lancelot", "escort_player", enter_vect)
- lance1 = lance1[1]
- lance1:setFriendly()
- hook.pilot(lance1, "death", "lance1_dead")
- end
- if esc_lancelot2 then
- enter_vect:add(rnd.int(-50,50), rnd.int(-50,50))
- lance2 = pilot_add("Empire Lancelot", "escort_player", enter_vect)
- lance2 = lance[2]
- lance2:setFriendly()
- hook.pilot(lance2, "death", "lance2_dead")
- end
-end
-
--- Escort death functions -> will stop spawning.
-function paci_dead() esc_pacifier = false end
-function lanc1_dead() esc_lancelot1 = false end
-function lanc2_dead() esc_lancelot2 = false end
-
--- Handle arrival back to base.
-function land()
- local planet = space.getPlanet()
-
- -- Just landing.
- if(misn_stage == 2 or misn_stage == 3) and planet == misn_base then
- if trinity_alive or misn_stage == 3 then
- -- Failed to kill.
- tk.msg(title[5], text[7])
- var.push("trinity", true)
-
- -- Rewards.
- player.modFaction("Empire", -5)
- var.push("collective_fail", true)
- else
- -- Successfully killed.
- tk.msg(title[4], string.format(text[6], player.name()))
- var.push("trinity", false)
-
- -- Rewards.
- player.modFaction("Empire", 5)
- end
-
- misn.finish(true)
-
- end
-end
-
--- Trinity hooks.
-function trinity_kill() -- Got killed.
- player.msg(talk[5])
- misn_stage = 2
- trinity_alive = false
- misn.setDesc(string.format(misn_desc[2], misn_base:name(), misn_base_sys:name()))
- misn.setMarker(misn_base_sys)
-end
-
-function trinity_jump() -- Got away.
- player.msg(talk[6])
- misn_stage = 2
- trinity_alive = true
- misn.setDesc(string.format(misn_desc[2], misn_base:name(), misn_base_sys:name()))
- misn_setMarker(misn_base_sys)
-end
-
diff --git a/dat/missions/empire/collective/ec06.lua b/dat/missions/empire/collective/ec06.lua
deleted file mode 100644
index 8634d73..0000000
--- a/dat/missions/empire/collective/ec06.lua
+++ /dev/null
@@ -1,257 +0,0 @@
---[[
-
- Operation Cold Metal
-
- Seventh and final mission in the Collective Campaign
-
- Mission Objectives:
- -- Assault C-43
- -- Final Assault on C-28
- -- Kill the Starfire
- -- Kill the Trinity (if it got away in Operation Black Metal)
-
- Stages:
- 0) Just started..
- 1) Entered C-43.
- 2) Cleared C-43.
- 3) Entered C-28.
- 4) Cleared C-28.
- 5) Ran away.
-
-]]--
-
-lang = lephisto.lang()
-if lang == "es" then
- -- not translated atm
-else -- default english
- misn_title = "Operation Cold Metal"
- misn_reward = "Fame and Glory"
- misn_desc = {}
- misn_desc[1] = "Neutralize enemy forces in %s."
- misn_desc[2] = "Destroy the Starfire and hostiles in %s."
- misn_desc[3] = "Return to %s in the %s system."
- title = {}
- title[1] = "Bar"
- title[2] = "Operation Cold Metal"
- title[3] = "Mission Success"
- title[4] = "Cowardly Behaviour"
- text = {}
- text[1] = [[You see Commodore Keer at a table with a couple other pilots. She motions you over to sit down.
-She begins, "We're going to finally attack the Collective. We've gotten the Emperor himself to bless the mission and send some of his better pilots. Would you be interested in joining the destruction of the Collective?"]]
- text[2] = [["The Operation has been dubbed 'Cold Metal'. Our goal is to head to C-00, we'll take the route of %s, %s then C-00. Should we encounter the Starfire at any stage our goal will be to destroy it and head back. We'll also clear each system completely of Collective presence before continuing to the next system. See you in combat pilots."]]
- text[3] = [[As you do your approach to land on %s you notice big banners placed on the exterior of the station. They seem to be in celebration of the final defeat of the Collective. When you do land you are saluted by the welcoming committee in charge of saluting all the returning pilots.
-You notice Commodore Keer. Upon greeting her she says, "You did a good job out there. No need to worry about the Collective anymore. Without Welsh the Collective won't stand a chance, since they aren't truly autonomous. Right now we have some ships cleaning up the last of the Collective, shouldn't take too long to be back to normal."]]
- text[4] = [[She continues, "As a symbol of appreciation you should find a deposit of 500 thousand credits has been made to your account. There will be a celebration later today in the officer's room if you want to join in."
-
-And so ends the Collective threat...]]
- text[5] = [[You recieve a message signed by Commodore Keeras soon as you enter Empire space:
- There is no room for cowards in the Empires' fleet."
- The signature does seem valid.]]
- -- Conversation between pilots
- talk = {}
- talk[1] = "System Cleared: Procede to %s."
- talk[2] = "Mission Success: Return to %s."
- talk[3] = "Mission Failure: Return to %s."
-end
-
-
--- Creates the mission
-function create()
- -- Intro text
- if tk.yesno( title[1], text[1] )
- then
- misn.accept()
-
- -- Mission data.
- misn_stage = 0
- misn_base, misn_base_sys = space.getPlanet("Omega Station")
- misn_target_sys = space.getSystem("C-43")
- misn_final_sys = space.getSystem("C-28")
- misn.setMarker(misn_target_sys)
-
- -- Mission details.
- misn.setTitle(misn_title)
- misn.setReward( misn_reward )
- misn.setDesc( string.format(misn_desc[1], misn_target_sys:name() ))
-
- tk.msg( title[2], string.format( text[2],
- misn_target_sys:name(), misn_final_sys:name() ) )
-
- hook.enter("jump")
- hook.land("land")
- end
-end
-
-
--- Handles jumping to target system.
-function jump()
- sys = space.getSystem()
-
- if misn_stage == 0 then
- offset = 500
-
- -- Entering target system?
- if sys == misn_target_sys then
- -- Create big battle.
- enter_vect = player.pos()
- pilot.clear()
- pilot.toggleSpawn(false)
- -- Empire.
- emp_fleets = {}
- emp_fleets[1] = "Empire Sml Attack"
- emp_fleets[2] = "Empire Sml Attack"
- emp_fleets[3] = "Dvaered Goddard" -- They help empire.
- -- Get position
- x, y = enter_vect:get()
- -- Add pilots.
- for k,v in ipairs(emp_fleets) do
- spawn_vect:add(rnd.int(-offset, offset), rnd.int(-offset, offset))
- pilots = pilot.add(v, "def", spawn_vect)
- for k, v in ipairs(pilots) do
- v:setFriendly()
- end
- end
- -- Collective.
- col_fleets = {}
- col_fleets[1] = "Collective Sml Swarm"
- col_fleets[2] = "Collective Sml Swarm"
- col_fleets[3] = "Collective Sml Swarm"
- -- Set up position.
- x,y = enter_vect:get()
- spawn_vect = enter_vect.new(-x, -y)
- -- Count amount created
- col_alive = 0
- for k,v in ipairs(col_fleets) do
- spawn_vect:add(rnd.int(-offset, offset), rnd.int(-offset, offset))
- pilots = pilot.add(v, "def", spawn_vect)
- col_alive = col_alive + #pilots
- for k,v in ipairs(pilots) do
- v:setHostile()
- hook.pilot( v, "disable", "col_dead" )
- end
- end
-
- misn_stage = 1
- end
- elseif misn_stage == 2 then
- -- Entering target system?
- if sys == misn_final_sys then
-
- -- Create bigger battle
- enter_vect = player.pos()
- pilot.clear()
- pilot.toggleSpawn(false)
- -- Empire
- emp_fleets = {}
- emp_fleets[1] = "Empire Lge Attack"
- emp_fleets[2] = "Empire Med Attack"
- emp_fleets[3] = "Dvaered Goddard" -- They help empire.
- -- Get position.
- x, y = enter_vect:get()
- spawn_vect = enter_vect.new(x, y)
- -- Add pilots.
- for k,v in ipairs(emp_fleets) do
- spawn_vect:add(rnd.int(-offset,offset), rnd.int(-offset, offset))
- pilots = pilot.add(v, "def", spawn_vect)
- for k, v in ipairs(pilot) do
- v:setFriendly()
- end
- end
- -- Collective.
- col_fleets = {}
- col_fleets[1] = "Starfire"
- col_fleets[2] = "Collective Lge Swarm"
- col_fleets[3] = "Collective Lge Swarm"
- if var.peek("trinity") == true then
- col_fleets[4] = "Trinity"
- end
- -- Set up position.
- x,y = enter_vect:get()
- spawn_vect = enter_vect.new(-x, -y)
- -- Add pilots.
- col_alive = 0
- for k,v in ipairs(col_fleets) do
- spawn_vect:add(rnd.int(-offset, offset), rnd.int(-offset, offset))
- pilots = pilot.add(v, "def", spawn_vect)
-
- -- Handle special ships.
- if v == "Starfire" then
- starfire = pilots[1]
- elseif v == "Trinity" then
- trinity = pilots[1]
- end
-
- -- Count amount created.
- col_alive = col_alive + #pilots
- for k,v in ipairs(pilots) do
- v:setHostile()
- hook.pilot( v, "disable", "col_dead" )
- end
- end
- misn_stage = 3
- end
-
-
- elseif misn_stage == 1 or misn_stage == 3 then
- -- Fled from battle - disgraceful.
- misn_stage = 5
- player.msg( string.format( talk[3], misn_base_sys:name() ))
-
- elseif misn_stage == 5 then
- -- Lower faction by a lot, without making hostile.
- f = player.getFaction("Empire")
- if f > 0 then
- if f > 20 then player.modFactionRaw("Empire", -20)
- else player.modFactionRaw("Empire", -f)
- end
- end
-
- -- Display message.
- tk.msg(title[4], text[5])
-
- -- Mission failed.
- var.push("collective_fail", true)
- misn.finish(false)
- end
-end
-
-
--- Handles collective death.
-function col_dead()
- col_alive = col_alive - 1 -- Another one bites the dust.
-
- -- All dead -> area clear.
- if col_alive == 0 then
- if misn_stage == 1 then
- misn.setDesc( string.format(misn_desc[2], misn_final_sys:name() ))
- player.msg( string.format( talk[1], misn_final_sys:name() ))
- misn.setMarker(misn_final_sys)
- misn_stage = 2
- elseif misn_stage == 3 then
- misn.setDesc( string.format(misn_desc[3], misn_base:name(), misn_base_sys:name() ))
- player.msg( string.format( talk[2], misn_base_sys:name() ))
- misn.setMarker(misn_base_sys)
- misn_stage = 4
- end
- end
-end
-
-
--- Handles arrival back to base.
-function land()
- planet = space.getPlanet()
-
- -- Final landing stage
- if misn_stage == 4 and planet == misn_base then
- tk.msg( title[3], string.format(text[3], misn_base:name()))
-
- -- Rewards
- player.modFaction("Empire",5)
- misn.finish(true)
- diff.apply("collective_dead")
- player.pay( 500000 ) -- 500k
-
- tk.msg( title[3], text[4] )
- end
-end
-
diff --git a/dat/missions/empire/emp_cargo00.lua b/dat/missions/empire/emp_cargo00.lua
deleted file mode 100644
index a885f10..0000000
--- a/dat/missions/empire/emp_cargo00.lua
+++ /dev/null
@@ -1,75 +0,0 @@
---[[
--- Simple cargo mission that optns up the Empire cargo missions.
---]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default english.
- misn_title = "Empire Recruitment"
- misn_reward = "%d credits"
- misn_desc = "Deliver some parcels for the Empire to %s in %s."
- title = {}
- title[1] = "Spaceport Bar"
- title[2] = "Empire Recruitment"
- title[3] = "Mission Accomplished"
- text = {}
- text[1] = [[As you enter the bar you can't help to notice that a fellow at a table is looking at you since you came in. You tend to your business as if you hadn't noticed. A while later you feel a tap on your shoulder and see it's the same fellow.]]
- text[2] = [["Hello, sorry about interrupting you. I'm Lieutenant medek from the Empire Armada Shipping Division. We're having another recruitment operation and would be interested in having another pilot among us. Would be interesting in working for the Empire?"]]
- text[3] = [["Welcome aboard.", says medek before giving you a firm handshake. "At first you'll just be tested with cargo missions while we get data on your flying skills. Later you could get called for more important mission. Who knows? You could be the next dfighter, greatest pilot we ever had on the armada."
-He hits a couple buttons on his wrist computer that springs into action.
-"It looks like we already have a simple task for you. Deliver these parcels to %s. The best pilots started delivering papers and ended up flying into combat against gigantic warships with the Interception Division."]]
- text[4] = [[You deliver the parcels to the Empire Shipping station at the %s spaceport. Afterwards they make you do some paperwork to formalize your participation with the Empire. They tell you to keep an eye out for missions labeled ES in the mission computer which stand for Empire Shipping which you now have access to.
-You aren't too sure of what to make of your encounter with the Empire, only time will tell...]]
-end
-
-function create()
- local landed = space.getPlanet()
-
- -- Target destination.
- local i = 0
- repeat
- dest,system = space.getPlanet(misn.factions())
- i = i+1
- until dest ~= landed or i > 10
- -- Infinate loop protection.
- if i > 10 then
- misn.finish(false)
- end
- misn.setMarker(system)
-
- -- Intro text.
- tk.msg(title[1], text[1])
- if tk.yesno(title[1], text[2])
- then
- misn.accept()
-
- -- Mission details.
- reward = 3000
- misn.setTitle(misn_title)
- misn.setReward(string.format(misn_reward, reward))
- misn.setDesc(string.format(misn_desc, dest:name(), system:name()))
-
- -- Flavour text and mini-briefing.
- tk.msg(title[2], string.format( text[3], dest:name()))
-
- -- Set up the goal.
- parcels = player.addCargo("Parcels", 0)
- hook.land("land")
- end
-end
-
-function land()
- local landed = space.getPlanet()
- if landed == dest then
- if player.rmCargo(parcels) then
- player.pay(reward)
- -- More flavour text.
- tk.msg(title[3], string.format(text[4], dest:name()))
- var.push("es_cargo", true)
- player.modFaction("Empire", 3)
- misn.finish(true)
- end
- end
-end
-
diff --git a/dat/missions/empire/es_cargo.lua b/dat/missions/empire/es_cargo.lua
deleted file mode 100644
index a0d7d2a..0000000
--- a/dat/missions/empire/es_cargo.lua
+++ /dev/null
@@ -1,149 +0,0 @@
---[[
- Handle the randomly generated Empire cargo missions.
---]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default english.
- misn_desc = "The Empire needs to ship %d tons of %s to %s in the %s system by %s (%s left)."
- misn_reward = "%d credits"
- title = {}
- title[1] = "ES: Ship to %s"
- title[2] = "ES: Delivery to %s"
- full = {}
- full[1] = "Ship is full"
- full[2] = "Your ship is too full. You need to make room for %d more tons if you want to be able to accept the mission."
- msg_title = {}
- msg_title[1] = "Mission Accepted"
- msg_title[2] = "Too many missions"
- msg_title[3] = "Succesful Delivery"
- msg_msg = {}
- msg_msg[1] = "The Empire workers load the %d tons of %s onto your ship."
- msg_msg[2] = "You have too many active missions."
- msg_msg[3] = "The Empire workers unload the %s at the docks."
- miss = {}
- miss[1] = "Cargo Missing"
- miss[2] = "You are missing the %d tons of %s!."
- miss[3] = "MISSION FAILED: You have failed to deliver the goods to the Empire on time!"
-end
-
--- Empire shipping missions are always timed, but quite lax on the schedules.
--- Pays a bit more then the rush missions.
-
--- Create the mission.
-function create()
- -- Target destination.
- local i = 0
- local landed = space.getPlanet()
- repeat
- planet, system = space.getPlanet(misn.factions())
- i = i + 1
- until planet ~= landed or i > 10
- -- Infinite loop protection.
- if i > 10 then
- misn.finish(false)
- end
- misn.setMarker(system) -- Set system marker.
- misn_dist = system:jumpDist()
-
- -- Mission generics.
- misn_type = "Cargo"
- i = rnd.int(1)
- misn.setTitle(string.format(title[i+1], planet:name()))
-
- -- More mission specifics.
- carg_mass = rnd.int(10, 30)
- i = rnd.int(12)
- if i < 5 then
- carg_type = "Food"
- elseif i < 8 then
- carg_type = "Ore"
- elseif i < 10 then
- carg_type = "Industrial Goods"
- elseif i < 12 then
- carg_type = "Luxury Goods"
- else
- carg_type = "Medicine"
- end
-
- misn_time = time.get() + time.units(5) +
- rnd.int(time.units(5), time.units(8)) * misn_dist
- misn.setDesc(string.format( misn_desc, carg_mass, carg_type,
- planet:name(), system:name(),
- time.str(misn_time), time.str(misn_time-time.get())))
- reward = misn_dist * carg_mass * (500+rnd.int(250)) +
- carg_mass * (250+rnd.int(150)) +
- rnd.int(2500)
- misn.setReward(string.format( misn_reward, reward))
-end
-
--- Mission is accepted.
-function accept()
- if player.freeCargo() < carg_mass then
- tk.msg(full[1], string.format(full[2], carg_mass-player.freeCargo()))
- misn.finish()
- elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
- carg_id = player.addCargo(carg_type, carg_mass)
- tk.msg(msg_title[1], string.format(msg_msg[1], carg_mass, carg_type))
- hook.land("land") -- Only hook after accepting.
- hook.time("timeup")
- else
- tk.msg(msg_title[2], msg_title[2])
- misn.finish()
- end
-end
-
--- Land hook.
-function land()
- local landed = space.getPlanet()
- if landed == planet then
- if player.rmCargo(carg_id) then
- player.pay(reward)
- tk.msg(msg_title[3], string.format(msg_msg[3], carg_type))
-
- -- Increase empire shipping mission counter.
- n = var.peek("es_misn")
- if n ~= nil then
- var.push("es_misn", n+1)
- else
- var.push("es_misn", 1)
- end
-
- -- Increase faction.
- if player.getFaction("Empire") < 50 then
- player.modFaction("Empire", rnd.int(5))
- end
-
- misn.finish(true)
- else
- tk.msg(miss[1], string.format(miss[2], carg_mass, carg_type))
- end
- end
-end
-
--- Time hook.
-function timeup()
- if time.get() > misn_time then
- misn_timerStart("failed", 2000)
- else
- misn.setDesc(string.format( misn_desc, carg_mass, carg_type,
- planet:name(), system:name(),
- time.str(misn_time), time.str(misn_time-time.get())))
- end
-end
-
-function failed()
- player.msg(miss[3])
- if misn_type ~= "People" then
- player.jetCargo(cargo_id)
- end
- misn_finish(false)
-end
-
-function abort()
- if misn_type ~= "People" then
- player.jetCargo(carg_id)
- end
-end
-
diff --git a/dat/missions/empire/shipping/es00.lua b/dat/missions/empire/shipping/es00.lua
deleted file mode 100644
index 5b59e49..0000000
--- a/dat/missions/empire/shipping/es00.lua
+++ /dev/null
@@ -1,126 +0,0 @@
---[[
-
- Empire Shipping Prisoner Exchange
-
-]]--
-
-lang = naev.lang()
-if lang == "es" then
- -- not translated atm
-else -- default english
- misn_title = "Prisoner Exchange"
- misn_reward = "%d credits"
- misn_desc = {}
- misn_desc[1] = "Go to %s in the %s system to exchange prisoners with the FLF."
- misn_desc[2] = "Return to %s in the %s system to report what happened."
- title = {}
- title[1] = "Spaceport Bar"
- title[2] = "Prisoner Exchange"
- title[3] = "Mission Report"
- text = {}
- text[1] = [[You are approached by an Empire Commander.
-"Hello, you must be %s. I've heard about you. I'm Commander Soldner. We've got some harder missions for someone like you in the Empire Shipping division. There would be real danger involved in these missions unlike the ones you've been doing recently for the division. Would you be up for the challenge?"]]
- text[2] = [["We've got a prisoner exchange set up with the FLF to take place on %s in the %s system. They want a more neutral pilot to do the exchange. You would have to go to %s with some FLF prisoners aboard your ship and exchange them for some of our own. You won't have visible escorts but we will have your movements watched by ships in nearby sectors."
-"Once we get the men they captured back bring them over to %s in %s for debriefing. You'll be compensated for your troubles. Good luck."]]
- text[3] = [[The Prisoners are loaded on your ship along with a few marines to ensure nothing happens.]]
- text[4] = [[As you land you notice the starport has been emptied. You notice some explosives rigged on some of the columns. This doesn't look good. The marines tell you to sit still and go out to try to do the prisoner exchange.
-From the cockpit you see how the marines lead the prisoners in front of them with their guns to their back. You notice that some people step out of the shadows with weapons too, most likely the FLF.]]
- text[5] = [[You suddenly hear a blaring siren and hear shooting. You quickly start your engines and prepare for take off. You see shots all over and a couple of prisoner corpses as you leave the starport. As you remember the explosives you hear loud detonations behind you. This doesn't look to good.
-You start your climb out of the atmosphere and notice how you're picking up many FLF and Dvaered ships. Looks like you're going to have quite a run to get the hell out of here. It didn't go as you expected.]]
- text[6] = [[After you leave your ship in the Starport you meet up with Commander Soldner. From the look on his face it seems like he already knows about what happened.
-"It was all the Dvaered's fault. They just came in out of no where and started shooting. What a horrible mess. We're already working on sorting out the blame, we had good men there."
-He sighs, "Didn't want you to start with a mess like this, but if you're interested in another meet me up in the bar in a while. We get no rest here. We alread transfered the payment to your bank account."]]
-end
-
-
-function create ()
-
- -- Intro text
- if tk.yesno( title[1], string.format( text[1], player.name() ) )
- then
- misn.accept()
-
- -- target destination
- dest,destsys = space.getPlanet( faction.get("Frontier") )
- ret,retsys = space.getPlanet( "Polaris Prime" )
- misn.setMarker(destsys)
-
- -- Mission details
- misn_stage = 0
- reward = 50000
- misn.setTitle(misn_title)
- misn.setReward( string.format(misn_reward, reward) )
- misn.setDesc( string.format(misn_desc[1], dest:name(), destsys:name()))
-
- -- Flavour text and mini-briefing
- tk.msg( title[2], string.format( text[2], dest:name(), destsys:name(),
- dest:name(), ret:name(), retsys:name() ))
-
- -- Set up the goal
- prisoners = player.addCargo("Prisoners", 0)
- tk.msg( title[2], text[3] )
-
- -- Set hooks
- hook.land("land")
- hook.enter("enter")
- end
-end
-
-
-function land ()
- landed = space.getPlanet()
- if landed == dest and misn_stage == 0 then
- if player.rmCargo(prisoners) then
- -- Go on to next stage
- misn_stage = 1
-
- -- Some text
- tk.msg(title[2], text[4] )
- tk.msg(title[2], text[5] )
- misn.setMarker(retsys)
- misn.setDesc( string.format(misn_desc[2], ret:name(), retsys:name()))
-
- -- We'll take off right away again
- misn.takeoff()
- end
- elseif landed == ret and misn_stage == 1 then
-
- -- Rewards
- player.pay(reward)
- player.modFaction("Empire",5);
-
- -- Flavour text
- tk.msg(title[3], text[6] )
-
- misn.finish(true)
- end
-end
-
-
-function enter ()
- sys = space.getSystem()
- if misn_stage == 1 and sys == destsys then
-
- -- Get a position near the player
- enter_vect = player.pos()
- a = rnd.rnd() * 2 * math.pi
- d = rnd.rnd( 100, 200 )
- enter_vect:add( math.cos(a) * d, math.sin(a) * d )
-
- -- Create some pilots to go after the player
- pilot.add( "FLF Sml Force", "def", enter_vect )
-
- -- Get a far away position for fighting to happen
- -- We'll put the FLF first
- a = rnd.rnd() * 2 * math.pi
- d = rnd.rnd( 700, 1000 )
- enter_vect:set( math.cos(a) * d, math.sin(a) * d )
- pilot.add( "FLF Med Force", "def", enter_vect )
- -- Now the Dvaered
- a = rnd.rnd() * 2 * math.pi
- d = rnd.rnd( 200, 300 )
- enter_vect:add( math.cos(a) * d, math.sin(a) * d )
- pilot.add( "Dvaered Med Force", "def", enter_vect )
- end
-end
-
diff --git a/dat/missions/neutral/cargo.lua b/dat/missions/neutral/cargo.lua
deleted file mode 100644
index 888ea8a..0000000
--- a/dat/missions/neutral/cargo.lua
+++ /dev/null
@@ -1,210 +0,0 @@
--- [[
--- Handle the randomly created cargo delivery missions.
--- ]]
-
-lang = lephisto.lang()
-if lang == "es" then
- -- Not translated atm.
-else -- Default english.
- misn_desc = {}
- misn_desc[1] = "%s in the %s system needs a delivery of %d tons of %s."
- misn_desc[11] = "%s in the %s system needs a rush delivery of %d tons of %s before %s (%s left)."
- misn_desc[21] = "A group of %s needs to travel to %s in the %s system."
- misn_reward = "%d credits"
- title = {}
- title[1] = "Cargo delivery to %s"
- title[2] = "Freight delivery to %s"
- title[3] = "Transport to %s"
- title[4] = "Delivery to %s"
- title[11] = "Rush Delivery to %s"
- title[21] = "Transport %s to %s"
- title[22] = "Ferry %s to %s"
- full = {}
- full[1] = "Ship is full"
- full[2] = "Your ship is too full. You need to make room for %d more tons if you want to be able to accept the mission."
- accept_title = "Mission Accepted"
- accept_msg = {}
- accept_msg[1] = "The Workers load the %d tons of %s onto your ship."
- accept_msg[2] = "The %s board your ship."
- msg_title = {}
- msg_msg = {}
- msg_title[1] = "Too many missions"
- msg_msg[1] = "You have too many active missions."
- msg_title[2] = "Succesful Delivery"
- msg_msg[2] = "The workers unload the %s at the docks."
- msg_msg[5] = "The %s leave your ship."
- msg_title[3] = "Cargo Missing"
- msg_msg[3] = "You are missing the %d tons of %s!."
- msg_msg[4] = "MISSION FAILED: You have failed to delivery the goods on time!"
-end
-
--- Create the mission.
-function create()
- landed = space.getPlanet() -- Get landed planet.
-
- -- Only 50% chance of appearing on Dvaered systems.
- dv = faction.get("Dvaered")
- if landed:faction() == dv and rnd.int(1) == 0 then
- misn.finish(false)
- end
-
- -- Target destination.
- i = 0
- repeat
- planet, system = space.getPlanet(misn.factions())
- i = i + 1
- until planet ~= landed or i > 10
- -- Infinite loop protection.
- if i > 10 then
- misn.finish(false)
- end
- misn.setMarker(system) -- Mark the system.
- misn_dist = system:jumpDist()
-
- -- Mission generics.
- i = rnd.int(6)
- if i < 4 then -- Cargo delivery.
- misn_type = "Cargo"
- misn_faction = rnd.int(2)
- i = rnd.int(3)
- misn.setTitle(string.format(title[i+1], planet:name()))
- elseif i < 6 then-- Rush delivery.
- misn_type = "Rush"
- misn_faction = rnd.int(5)
- misn.setTitle(string.format(title[11], planet:name()))
- else -- People delivery :P
- misn_type = "People"
- misn.faction = rnd.int(1)
- carg_mass = 0
- i = rnd.int(5)
- if i < 2 then
- carg_type = "Colonists"
- elseif i < 4 then
- carg_type = "Tourists"
- else
- carg_type = "Pilgrims"
- end
- i = rnd.int(1)
- misn_setTitle(string.format(title[i+21], carg_type, planet:name()))
- end
-
- -- More mission specifics.
- if misn_type == "Cargo" or misn_type == "Rush" then
- carg_mass = rnd.int(10, 30)
- i = rnd.int(12) -- Set the goods.
- if i < 5 then
- carg_type = "Food"
- elseif i < 8 then
- carg_type = "Ore"
- elseif i < 10 then
- carg_type = "Industrial Goods"
- elseif i < 12 then
- carg_type = "Luxury Goods"
- else
- carg_type = "Medicine"
- end
- end
-
- -- Set reward and description.
- if misn_type == "Cargo" then
- misn.setDesc(string.format( misn_desc[1], planet:name(), system:name(), carg_mass, carg_type))
- reward = misn_dist * carg_mass * (250+rnd.int(150)) +
- carg_mass * (150+rnd.int(75)) +
- rnd.int(1500)
- elseif misn_type == "Rush" then
- misn_time = time.get() + time.units(2) +
- rnd.int(time.units(2), time.units(4)) * misn_dist
- misn.setDesc(string.format( misn_desc[11], planet:name(), system:name(),
- carg_mass, carg_type,
- time.str(misn_time), time.str(misn_time-time.get())))
- reward = misn_dist * carg_mass * (450+rnd.int(250)) +
- carg_mass * (250+rnd.int(125)) +
- rnd.int(2500)
- elseif misn_type == "People" then
- misn.setDesc(string.format(misn_desc[21], carg_type, planet:name(), system:name()))
- reward = misn_dist * (1000 + rnd.int(500)) + rnd.int(2000)
- end
- misn.setReward(string.format(misn_reward, reward))
-end
-
--- Mission is accepted.
-function accept()
- if player.freeCargo() < carg_mass then
- tk.msg(full[1], string.format(full[2], carg_mass-player.freeCargo()))
- misn.finish()
-
- elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
- carg_id = player.addCargo(carg_type, carg_mass)
-
- if misn_type == "People" then
- tk.msg(accept_title, string.format(accept_msg[2], carg_type))
- else
- tk.msg(accept_title, string.format(accept_msg[1], carg_mass, carg_type))
- end
-
- -- Set the hooks.
- hook.land("land") -- Only hook after accepting.
- if misn_type == "Rush" then -- Rush needs additional time hook.
- hook.time("timeup")
- end
- else
- tk.msg(msg_title[1], msg_msg[1])
- misn.finish()
- end
-end
-
--- Land hook.
-function land()
- landed = space.getPlanet()
- if landed == planet then
- if player.rmCargo(carg_id) then
- player.pay( reward )
- if misn_type == "People" then
- tk.msg(msg_title[2], string.format(msg_msg[5], carg_type))
- else
- tk.msg(msg_title[2], string.format(msg_msg[2], carg_type))
- end
-
- -- Modify the faction standing.
- if player.getFaction("Trader") < 70 then
- player.modFactionRaw("Trader", misn_faction)
- end
- if player.getFaction("Independent") < 30 then
- player.modFactionRaw("Independent", misn_faction/2)
- end
- if player.getFaction("Empire") < 10 then
- player.modFaction("Empire", misn_faction/3)
- end
-
- misn.finish(true)
- else
- tk.msg(msg_title[3], string.format(msg_msg[3], carg_mass, carg_type))
- end
- end
-end
-
--- Time hook.
-function timeup()
- if time.get() > misn_time then
- misn.timerStart("failed", 2000)
- else
- misn.setDesc(string.format( misn_desc[11], planet:name(), system:name(),
- carg_mass, carg_type,
- time.str(misn_time), time.str(misn_time-time.get())))
- end
-end
-
-function failed()
- player.msg(msg_msg[4])
- if misn_type ~= "People" then
- player.jetCargo(carg_id)
- end
- misn.finish(false)
-end
-
-function abort()
- if misn_type ~= "People" then
- player.jetCargo(carg_id)
- end
-end
-
diff --git a/dat/missions/neutral/nebu_satellite.lua b/dat/missions/neutral/nebu_satellite.lua
deleted file mode 100644
index 4fc0325..0000000
--- a/dat/missions/neutral/nebu_satellite.lua
+++ /dev/null
@@ -1,120 +0,0 @@
---[[
--- Nebulae Satellite.
---
--- One-shot mission.
---
--- Help some independent scientists put a satellite in the nebulae.
---]]
-
--- Localization stuff, translators would work here.
-lang = lephisto.lang()
-if lang == "es" then
-else -- Default to English.
- mtitle = {}
- mtitle[1] = "Nebulae Satellite"
- mreward = {}
- mreward[1] = "%d credits"
- mdesc = {}
- mdesc[1] = "Go to the %s system to launch the probe."
- mdesc[2] = "Drop off the scientists at %s in the %s system."
- title = {}
- title[1] = "Bar"
- title[2] = "Scientific Exploration"
- title[3] = "Mission Success"
- text = {}
- text[1] = [[You are sitting at the bar when you are approached by a couple of short guys. They seem a bit nervous and one mutters something about whether it's a good idea or not. Eventually one of them comes up to you.
- "Hello Captain, We're looking for a ship to take us into the Sol Nebulae. Would you be willing to take us there?]]
- text[2] = [["We had a trip scheduled with some Space Trader ship, but they backed out at the last minute. So we were stuck here until you came. We've got a probe satellite that we have to release in the %s system to monitor the nebulae's growth rate. The probe launch procedure is pretty straightforward and shouldn't have any complications."
- He takes a deep breath, "We hope to be able to find out more secrets of the Sol Nebulae so man can once again regain it's lost patrimony. So far the radiation and volatility of the deeper area haven't been very kind to our instruments. That's why we designed this Satellite we're going to launch."]]
- text[3] = [["The plan is for you to take us to %s so we can launch the probe, then back to our home at %s in the %s system. The probe will automatically send us the data we need if all goes well. You'll be paid %d credits when we arrive."]]
- text[4] = [[The scientists thank you for your help before going back to their home to continue their nebulae research.]]
- text[9] = [["You do ot have enough free cargo space to accept this mission!"]]
- launch = {}
- launch[1] = "Preparing to launch the satellite probe..."
- launch[2] = "Launch in 5..."
- launch[3] = "Satellite launch successful!"
-end
-
-function create()
- if tk.yesno(title[1], text[1]) then
- -- Check for cargo space.
- if player.freeCargo() < 3 then
- tk.msg(title[1], text[9])
- return
- end
- misn.accept()
-
- -- Set up mission variables.
- misn_stage = 0
- homeworld, homeworld_sys = space.getPlanet(misn.factions())
- satellite_sys = space.getSystem("Arandon") -- Not too unstable.
- credits = 75000
- cargo = player.addCargo("Satellite", 3)
-
- -- Set up mission information.
- misn.setTitle(mtitle[1])
- misn.setReward(string.format(mreward[1], credits))
- misn.setDesc(string.format(mdesc[1], satellite_sys:name()))
- misn.setMarker(satellite_sys)
-
- -- More flavour text.
- tk.msg(title[2], string.format(text[2], satellite_sys:name()))
- tk.msg(title[2], string.format(text[3], satellite_sys:name(),
- homeworld:name(), homeworld_sys:name(), credits))
-
- -- Set up hooks.
- hook.land("land")
- hook.enter("jump")
- end
-end
-
-function land()
- landed = space.getPlanet()
- -- Mission success.
- if misn_stage == 1 and landed == homeworld then
- tk.msg(title[3], text[4])
- player.pay(credits)
- misn.finish(true)
- end
-end
-
-function jump()
- sys = space.getSystem()
- -- Launch satellite.
- if misn_stage == 0 and sys == satellite_sys then
- misn.timerStart("beginLaunch", 3000)
- end
-end
-
---[[
--- Launch process.
---]]
-function beginLaunch()
- player.msg(launch[1])
- misn.timerStart("beginCountdown", 3000)
-end
-
-function beginCountdown()
- countdown = 5
- player.msg(launch[2])
- misn.timerStart("countLaunch", 1000)
-end
-
-function countLaunch()
- countdown = countdown - 1
- if countdown <= 0 then
- launchSatellite()
- else
- player.msg(string.format("%d..." countdown))
- misn.timerStart("countLaunch", 1000)
- end
-end
-
-function launchSatellite()
- misn_stage = 1
- player.msg(launch[3])
- player.jetCargo(cargo)
- misn.setDesc(string.format(mdesc[2], homeworld:name(), homeworld_sys:name()))
- misn.setMarker(homeworld_sys)
-end
-
diff --git a/dat/missions/tutorial.lua b/dat/missions/tutorial.lua
deleted file mode 100644
index c7f915d..0000000
--- a/dat/missions/tutorial.lua
+++ /dev/null
@@ -1,309 +0,0 @@
---[[
-
- The beginner player tutorial.
-
- Does simple stuff like teach the player to fly around or use her
- communications system.
-
- Step 1
- Basic flight.
-
- Step 2
- Braking.
-
- Step 3
- Targetting.
-
- Step 4
- Dummy combat.
-
- Step 5
- Board dummy.
-
- Step 6
- Real pirate.
-
- Step 7
- Landing.
-
- Step 8
- Hyperspace.
-
- Step 9
- Finished.
-
-]]--
-
--- Localization stuff, translators would work here.
-lang = lephisto.lang()
-if lang == "es" then
-else -- Default english.
- title = {}
- text = {}
- title[1] = "Tutorial"
- text[1] = "Would you like to run the Tutorial to learn how to play Lephisto?"
- text[2] = [[Welcome to the Lephisto Tutorial. This Tutorial assumes you are using the default keybindings, if you aren't please use whatever keybindings you switched to instead of the defaults.]]
- -- Step 1.
- title[2] = "Flight Tutorial"
- text[3] = [[We'll first start off by flying around. Use the 'a' and 'd' keys to turn and the 'w' key to accelerate. Try flying around the planet, it's hard at first but you'll get the hang of it eventually.]]
- -- Step 2.
- text[4] = [[Good. Now we'll try braking. Since you can only accelerate forward, you'll have to turn backwards and accelerate to break. To make this easier you can use the 's' key to turn around automatically. Then you accelerate until you stop. Look at the stars in the background for an indication of your velocity. Try braking now.]]
- text[5] = [[ Now you're getting the hang of it. It'll still take a while until you can fly well, but this is a start. ]]
- -- Step 3.
- title[3] = "Targetting Tutorial"
- text[6] = [[Now we'll work on targetting. To target you have multiple options.
- 'tab' cycles through ships.
- 'ctrl + tab' cycles through ships backwards.
- 't' targets nearest ship.
- 'r' targets nearest hostile.]]
- text[7] = [[I'll bring in a couple of ships so you can try playing around with targetting. You'll notice your targetted ship gets hilighted blue in the radar (top-right). You can use the + and - key on the keypad to change the zoom on the map. Yellow is neutral, red is hostile, green is friendly and grey is inert. The new ships will be yellow.]]
- -- Step 4.
- title[4] = "Combat Tutorial"
- text[8] = [[Now let's try using the weapon systems. There are primarily three keys:
- 'space' shoots primary weapons.
- 'e' selects secondary weapon.
- 'left alt' shoots secondary weapon.]]
- text[9] = [[Your ship (Llama) only has a single Laser Cannon as a primary weapon, so we'll try using that. I'll put in a Dummy Llama so you can try destroying it. So try targetting it with 'tab' or 't' and then approach it and shoot it with 'space' until it is disabled. You can also use 'f' to autoface the target you have selected.]]
- -- Step 5.
- text[10] = [[Good. Now that the Llama is disabled you can try to board it. To board a ship you must target it and then go very slow and stop above it. Once you're ontop of the ship you can hit 'b' which will allow you to board the ship to steal resources.
-Try to board the ship now.]]
- -- Back to Step 4.
- text[11] = [[You weren't supposed to destroy the Llama! I'll add another so you can try again.]]
- text[12] = [[Good. Now if the Llama had money or cargo you could attempt to steal it. Your probability is based on your crew versus their crew. The more crew you have the more chance. Since the ship has nothing just leave it be and we'll introduce real enemies.]]
- -- Step 6.
- text[13] = [[Now comes the real challenge. I'll bring in a real pirate to see how you fare with him. Don't worry, help is on the way.]]
- text[14] = [[That wasn't so scary was it? Now we'll learn more about other things like Landing. Landing allows you to not only regenerate all your shield and armour, but to buy/trade goods, outfits for your ship and ships. The only downside is that you take a while to land, so if you're in a hurry for some mission, it's good to try not to land.]]
- -- Step 7.
- title[5] = "Landing Tutorial"
- text[15] = [[Landing is also how you save in Lephisto. Every time you land, it'll save your game. So don't land if you just screwed up an important mission or pissed off a big faction. The keys involved with landing are:
- 'p' cycles through planets.
- 'l' lands or targets nearest planet if none selected. Needed to get confirmation.]]
- text[16] = [[The easiest way to land is to hit 'l' to get the first land target and get the land acknowledgement. Then you have to "board" the planet, meaning go and brake on top of it. Then you hit 'l' again to land. Try doing this now.]]
- text[17] = [[This is the land window. Here you can see an image of where you are with a description of where you landed. Depending on the planet you'll have various services available. Services include:
- * Commodity Exchange
- * Spaceport Bar
- * Mission Computer
- * Outfitting
- * Shipyard]]
- title[6] = "Commodity Exchange"
- text[18] = [[In the Commodity Exchange you can buy or sell goods. The goods available depend on where you are. Not every place has everything.]]
- title[7] = "Spaceport Bar"
- text[19] = [[The Spaceport Bar is a great place to find all sorts of esoteric missions. If you are looking for adventure you should always check the Spaceport Bar as soon as you land. Don't forget to have some cargo space available as most missions will use it.]]
- title[8] = "Mission Computer"
- text[20] = [[The Mission Computer is a place where you can find many missions available for getting quick money. Since these missions are created by computer systems they tend to not be too interesting compared to what you can find in the Spaceport Bar. They're a great way to start exploring the universe though.]]
- title[9] = "Outfitting"
- text[21] = [[The more advanced planets and stations will have Outfitting available. There you can modify your ship and add all sorts of gadgets allowing you to increase your ship's efficiency giving you an edge over the rest. Not every place has every outfit so it's good to travel all over to see what's available. It's advisable to always buy maps if they're available.]]
- title[10] = "Shipyard"
- text[22] = [[In the Shipyard you can buy ships. You can also store the ships you own and switch between them or sell them. It's very expensive to transport ships between systems, so it's usually best to go to where the ship is.]]
- text[23] = [[Try exploring a bit around the planet. When you're ready to leave click on 'Takeoff' and we'll continue the tutorial.]]
- -- Step 8.
- title[11] = "Navigation Tutorial"
- text[24] = [[In this final part of the tutorial we'll deal with long-distance navigation. All ships in Lephisto are equipped with a hyperspace drive and universe map. Important keys to remember:
- 'm' opens the system map.
- 'h' cycles through hyperspace targets.
- 'j' attemps to enter hyperspace or aborts an attempt.
- 'ctrl + j' actives autonavigation pilot.]]
- title[12] = "System Map"
- text[25] = [[We'll first talk about the map. When you open your map you'll notice it's very empty. That's because you haven't explored much yet. As you explore stuff or buy star maps it'll expand. Each circle represents a system, and the lines represent hyperspace routes. You can click on a system to select it as a hyperspace target. If it's far away the autonav system will make a route to it which your autonavigation pilot can use. The colour of each jump indicates whether you have enough fuel or not to make it.]]
- title[13] = "Nav System"
- text[26] = [[Once you have a target you'll notice it in your nav system. If you are far enough to jump it'll be green, otherwise it'll be grey. You can't jump near big gravity centers, meaning basically planets and space stations. Once you get far enough away it'll turn green and you can initialize the jump.]]
- text[27] = [[Now we'll try to jump, he's an overview of how it works:
- 1) Select target with map ('m') or cycle through targets with 'h'.
- 2) Get away from gravity wells until navigation turns green or use autopilot 'ctrl + j'.
- 3) Use 'j' to initialize the jump.
-
-Try doing this now, since you haven't explored any systems just pick any one and try jumping. I'd recommend the one on the bottom right if you don't want trouble]]
- -- Stage 9.
- title[14] = "Tutorial Finished"
- text[28] = [[And this concludes the tutorial. You should now know how to:
- * Fly
- * Target
- * Fight
- * Land
- * Jump
-
-You should start getting better by getting cargo missions at Mission Computers, which will also help you explore the universe.
-
-Enjoy them game!]]
- -- Mission details.
- misn_title = "Lephisto Tutorial"
- misn_reward = "Knowledge of how to play the game."
- misn_desc = "New Player Tutorial to learn how survive in the universe."
- -- Aborted mission.
- msg_abortTitle = "Tutorial Aborted"
- msg_abort = [[You seem to know more then is needed for the tutorial. Tutorial aborting.]]
-end
-
-
-function create ()
-
- if tk.yesno( title[1], text[1] )
- then
- misn.accept()
-
- -- Clear area of enemies.
- pilot.clear()
- pilot.toggleSpawn(false)
-
- -- Set basic mission information.
- misn.setTitle( misn_title )
- misn.setReward( misn_reward )
- misn.setDesc( misn_desc )
-
- -- Give indications on how to fly.
- misn_stage = 1
- tk.msg( title[1], text[2] )
- tk.msg( title[2], text[3] )
- misn.timerStart( "flightOver", 15000 ) -- 15 second timer to fly around
-
- -- Set Hooks
- hook.land( "tutLand" )
- hook.takeoff( "tutTakeoff" )
- hook.enter( "tutEnter" )
- end
-end
-
-
-function flightOver ()
- misn_stage = 2
- tk.msg( title[2], text[4] )
- misn.timerStart( "brakeOver", 1000 )
-end
-
-
-function brakeOver ()
- player = pilot.player()
-
- -- Check if player successfully braked.
- if player:vel():mod() < 10 then
- misn_stage = 3
- tk.msg( title[2], text[5] )
- tk.msg( title[3], text[6] )
- tk.msg( title[3], text[7] )
- pilots = pilot.add( "Sml Trader Convoy", "dummy" )
- for k,v in ipairs(pilots) do
- v:setFaction("Dummy")
- v:rename("Dummy")
- end
- misn.timerStart( "targetOver", 20000 ) -- 20 seconds to target
- else
- -- Keep on trying until he braked
- misn.timerStart( "brakeOver", 1000 )
- end
-end
-
-
-function targetOver ()
- misn_stage = 4
-
- -- Tell about combat.
- tk.msg( title[4], text[8] )
- tk.msg( title[4], text[9] )
-
- -- Clear pilots again.
- pilot.clear()
-
- addLlamaDummy()
-end
-
-
-function addLlamaDummy ()
- -- Add the combat dummy.
- pilots = pilot.add( "Trader Llama", "dummy" )
- for k,v in ipairs(pilots) do
- v:setFaction("Dummy")
- v:rename("Dummy")
- hook.pilot( v, "disable", "llamaDisabled" )
- hook.pilot( v, "death", "llamaDead" )
- hook.pilot( v, "board", "llamaBoard" )
- end
-end
-
-
-function llamaDisabled ()
- misn_stage = 5
- tk.msg( title[4], text[10] )
-end
-
-
-function llamaDead ()
- if misn_stage < 6 then
- misn_stage = 4
- tk.msg( title[4], text[11] )
- addLlamaDummy()
- end
-end
-
-
-function llamaBoard ()
- misn_stage = 6
- tk.msg( title[4], text[12] )
- misn.timerStart( "boardOver", 3000 )
-end
-
-
-function boardOver ()
- tk.msg( title[4], text[13] )
- pilot.clear() -- Get rid of disabled llama
- pilots = pilot.add( "Pirate Hyena" )
- for k,v in ipairs(pilots) do
- hook.pilot( v, "death", "hyenaDead" )
- hook.pilot(v, "jump", "hyenaDead") -- Treat jump as dead.
- end
- misn.timerStart( "bringHelp", 9000 ) -- Player "should" surive 9 seconds
-end
-
-
-function bringHelp ()
- pilot.add( "Empire Lancelot" )
- pilot.add( "Empire Lancelot" ) -- Lancelot crushes Hyena
-end
-
-
-function hyenaDead ()
- misn_stage = 7
- tk.msg( title[4], text[14] )
- tk.msg( title[5], text[15] )
- tk.msg( title[5], text[16] )
-end
-
-
-function tutLand ()
- -- Shouldn't be landing yet.
- if misn_stage ~= 7 then
- tk.msg( msg_abortTitle, msg_abort )
- misn.finish(false)
- else
- misn_stage = 8
- tk.msg( title[5], text[17] )
- tk.msg( title[6], text[18] )
- tk.msg( title[7], text[19] )
- tk.msg( title[8], text[20] )
- tk.msg( title[9], text[21] )
- tk.msg( title[10], text[22] )
- tk.msg( title[5], text[23] )
- end
-end
-
-
-function tutTakeoff ()
- misn_stage = 8
- misn_sys = space.getSystem()
- tk.msg( title[11], text[24] )
- tk.msg( title[12], text[25] )
- tk.msg( title[13], text[26] )
- tk.msg( title[13], text[27] )
-end
-
-
-function tutEnter ()
- enter_sys = space.getSystem()
- if misn_stage ~= 8 then
- tk.msg( msg_abortTitle, msg_abort )
- misn.finish(false)
- elseif enter_sys ~= misn_sys then
- misn_stage = 9
- tk.msg( title[14], text[28] )
- misn.finish(true)
- end
-end
diff --git a/dat/outfit.xml b/dat/outfit.xml
deleted file mode 100644
index d9bcf8c..0000000
--- a/dat/outfit.xml
+++ /dev/null
@@ -1,822 +0,0 @@
-
-
-
-
- 3
- 11
- Medium Weapon License
- 12
- 95000
- The Ripper does what it's name implies: it rips through enemies with ease. Only downside is the energy needed to power it.
- heavy
-
-
- ripper
- laser
- ShiS
- ExpS
- 700
- 700
- 400
- 10
- 22
- 18
-
-
-
-
- 6
- 2
- 5
- 5000
- Your basic laser. Fires charged energy beams that do a decent amount of damage to both shield and armour.
- laser
-
-
- laserred
- laser
- ShiS
- ExpS
- 500
- 550
- 300
- 25
- 8
- 10
-
-
-
-
- 4
- 4
- Medium Weapon License
- 20
- 25000
- Two laser cannons added on a rotating turret, allowing for 360 degrees of firepower.
- turret
-
-
- laserred
- laser
- ShiS
- ExpS
- 300
- 550
- 300
- 25
- 10
- 10
-
-
-
-
- 4
- 3
- 5
- 9000
- Plasma is very volatile, if properly controlled it can be very destructive, it does tend to dissipate quickly though.
- laser
-
-
- plasma
- laser
- ShiS
- PlaS
- 400
- 450
- 250
- 25
- 7
- 7
-
-
-
-
- 4
- 7
- Medium Weapon License
- 9
- 15000
- Ion pulses were originally intended only to deactivate shields since they had completely nullified the old radiation technology weapons. It was thought that by figuring out a way to deactivate shields fast the radiation technology would still be able to destroy the armour. By combining shield destruction power and armour destruction power, the perfect weapons could be designed. The Ion pulses ended up being very effective against armour and electronics. With the invention of the latest generation shields and armour materials, Ion pulses have lost much of the terrain they had as newfound technology.
- medium
-
-
- ion
- ion
- ShiS
- ExpS
- 800
- 500
- 400
- 13
- 13
- 15
-
-
-
-
- 3
- 11
- 35
- Heavy Weapon License
- 75000
- The heavy Ion Turret uses a bigger generator for each cannon giving it more punch then the Ion cannon. The drawback is that this augments the power usage considerably. Being designed for capital ships, this doesn't seem to worry the makers too much.
- turret2
-
-
- ion
- ion
- ShiS
- ExpS
- 400
- 500
- 400
- 7
- 17
- 17
-
-
-
-
- 2
- 8
- Heavy Weapon License
- 15
- 85000
- The rail gun is a cannon that uses heavy magnetic pulses to accelerate pieces of debris to extremely high velocities. The impact caused by the pieces of debris can tear apart even the strongest ship hulls.
- heavy
-
-
- mass
- mass
- ShiM
- ExpM
- 1100
- 650
- 500
- 10
- 35
- 40
-
-
-
-
- 1
- 11
- Heavy Weapon License
- 20
- 184000
- One of the more popular beam weapons for it's simplicity and size. Most heavy fighters have no trouble fitting one of these. Being fixed mounted it inherits their maneuverability, allowing for greater precision on agile ships.
- orion
-
-
- 6000
- 3
- 300
- 70
- 40
- ShiS
- ExpS
- beam_orion
- beam0
- beam_off0
-
-
-
-
- 1
- 13
- 60
- 745000
- The Ragnorak Beam is one of the most powerful beam class weapons on the market. It's designed for capital ship combat, although its extremely large payload makes it also somewhat useful for clearing enemy fighters.
- turret3
-
-
- 10000
- 5
- 400
- 50
- 130
- 100
- ShiS
- ExpS
- beam_ragnarok
- beam0
- beam_off0
-
-
-
-
- 2
- 4
- 10
- 25000
- Base for launching seeking missiles.
- missile
-
-
- Seeker Missile
- 1800
-
-
-
-
- 60
- 2
- 1
- 800
- The cheapest missile on the market, what it lacks in a decent tracking system it makes up for in affordability and firepower.
- missile
-
-
- missile
- missile
- ExpM
- ExpM
- 5
- 1
- 400
- 60
- 800
- 20
-
-
-
-
- 2
- 5
- Medium Weapon License
- 12
- 40000
- The Headhunter Launcher is one of the most used missile launchers by the security companies. Much more reliable then the regular missiles, Headhunters feature more sensors and an advanced tracking system making them much better at hitting their targets.
- missile
-
-
- Headhunter
- 2200
-
-
-
-
- 40
- 5
- Medium Weapon License
- 1
- 2000
- Headhunters first gained fame in the crush of the Araknoid, a fearsome battle against a pirate stronghold where the Empire crushed the pirates thanks to the advanced guidance system on the Headhunter. Now used by mercenaries and bounty hunters all over.
- missile
-
-
- headhunter
- missile
- ExpM
- ExpM
- 7
- 0.5
- 5
- 325
- 90
- 550
- 20
-
-
-
-
- 2
- 9
- Medium Weapon License
- 10
- 25000
- bansheelauncher
- The Banshee Launcher uses a quick action firing mechanism to be able to quickly launch the banshee rockets. The only drawback is that this mechanism can only be used with light rockets, limiting the payload the rockets can have.
-
-
- Banshee Rocket
- 300
-
-
-
-
- 40
- 6
- Medium Weapon License
- 0
- 100
- The Banshee Rocket gets it's name from the wail it makes when launched. They carry an EMP payload which is very helpful when attempting to disable ships.
- banshee
-
-
- banshee
- missile
- EmpS
- EmpS
- 0.8
- 12
- 0
- 600
- 15
-
-
-
-
- 3
- 99
- 8
- 25000
- Neutron Disruptor.
- neutron
-
-
- neutron
- neutron
- ShiS
- ExpS
- 400
- 650
- 275
- 15
- 5
- 7
-
-
-
-
- 10
- 3
- 2
- 22500
- A heavy battery that will increase your ship's energy to allow you to pack more firepower.
- capacitator
-
-
- 30
-
-
-
-
- 5
- 5
- 3
- 55000
- A big panel that will generate energy based off solar energy. This will allow your ship to regenerate its energy supplies faster.
- solar
-
-
- 75
-
-
-
-
- 12
- 9
- 3
- 75000
- An enhancement for the shield power system, allowing it to resist much heavier fire.
- capacitator
-
-
- 15
-
-
-
-
- 4
- 10
- 5
- 145000
- A shield generator that feeds off the ship's main energy line. It will allow you to generate your shield faster and give you a small maximum shield boost at the expense of draining some of the ship's energy.
- shield
-
-
- 15
- 15
- -50
-
-
-
-
- 1
- 13
- 1
- 125000
- This enhancement routes energy from the ship's energy supplies to the engine, giving the ship an increased thrust. It does not increase the ship's max speed nor turn abilities.
- reroute
-
-
- 70
- -50
-
-
-
-
- 1
- 13
- 1
- 135000
- By improving your ship's stabilization systems drastically, this modification will allow you to reach higher speeds while still keeping the ship stable.
- stabilizer
-
-
- 50
- 5
- -10
-
-
-
-
- 1
- 13
- 1
- 130000
- With the adding of a couple of additional steering thrusters you can make your ship very agile at turning.
- thruster
-
-
- 25
- -10
-
-
-
-
- 1
- 3
- 2
- 20000
- Being able to run from your enemies is a very powerful ability. A generic afterburner will allow you to do that. It may not be as powerful as some of the more high-end afterburners, but they're not nearly as affordable as a generic one.
- afterburner
-
-
- 0.5
- afterburner
- 100
- 50
- 50
- 30
- 60
-
-
-
-
- 1
- 13
- 4
- 95000
- The Hellburner is one of the best afterburners available in the market. They have a much better energy to speed ratio then the generics and are much stronger. A must for any spacefarer who is proud of his ship.
- afterburner2
-
-
- 0.9
- afterburner
- 185
- 100
- 85
- 50
- 65
-
-
-
-
- 4
- 3
- 5
- 15000
- The Fuel Pod allows a ship to store more fuel for hyperspace jumps. Each pod effectively increases a ship's range by a jump.
- fuel_pod
-
-
- 100
-
-
-
-
- 4
- 6
- 15
- 35000
- Cargo Pods are big containers you can attach to dedicated weapon space allowing you to transport more cargo. The drawback is that you lose a lot of weapon space and won't be able to defend your cargo as well...
- cargo_pod
-
-
- 15
-
-
-
-
- 4
- 8
- -10
- 65000
- Adding a Weapon Rack to your ship will allow you to enjoy the benefits of more weapon space at the cost of cargo space. It's often more wiser to have less cargo, but to guard it well.
- weapon_rack
-
-
- -15
-
-
-
-
- 1
- 4
- 0
- 7000
- A Star Map will give you details about all systems up to 2 jumps away. It's a great risk-free way to discover parts of the universe.
- map
-
-
- 2
-
-
-
-
- 1
- 7
- 2
- 40000
- This jammer allows you to block the targetting systems of some of the missiles headed towards you, giving them unpredictable behaviors, likely not to impact with your ship.
- jammer0
-
-
- 400
- 20
- 3
-
-
-
-
- 1
- 13
- 3
- 250000
- This jammer follows the much stricter military specifications, allowing it to deflect a much greater amount of missiles at more range then the civilian counterpart. The downside is that the energy requirements are much greater.
- jammer1
-
-
- 600
- 40
- 10
-
-
-
-
- 2
- 3
- Medium Weapon License
- 10
- 19000
- A base for launching Dvaered Mace rockets.
- mace
-
-
- Mace Rocket
- 2000
-
-
-
-
- 40
- 2
- Medium Weapon License
- 2
- 700
- The Mace rocket is a very heavy, fast accelerating rocket designed for high speed collisions. The rockets doesn't have too much explosive, instead it has a lot of fuel it uses for the acceleration. Most of the damage it does is from the impact and not the explosion though.
- mace
-
-
- mace
- missile
- ExpM
- ExpM
- 3
- 300
- 1000
- 35
-
-
-
-
- 2
- 7
- 17
- 31000
- empgrenadelauncher
- This launcher can fire EMP grenades in any direction using a unique internal guidance system. These are favored by traders for escaping from pirates.
-
-
- EMP Grenade
- 2000
-
-
-
-
- 30
- 6
- 1
- 600
- empgrenade
- This is a grenade that can be launched to unleash EMP blasts rendering most electronics in the area useless. Good for taking ships alive instead of killing them, as the EMP blasts rarely destroy the ship, leaving it intact with non-working electronics instead.
-
-
- empgrenade
- grenade
- EmpS
- EmpM
- 1.3
- 0
- 400
- 40
-
-
-
-
- 1
- 6
- 15
- 65000
- plasteel
- Plasteel was one of man's greatest improvements on materials. It's a cheap, very strong armour that seems to take the best from both plastic and steel. You can bend it relatively easily while keeping it's incredible strength. The Second Growth was only possible with this amazing new material.
-By adding quite a dense layer of Plasteel to your ship you can increase it's sturdiness by a lot. Although with the advent of even newer materials Plasteel is starting to fade in popularity, although it's lower price tag always seems to keep a loyal customer base.
-
-
- 35
-
-
-
-
- 1
- 9
- 35
- 365000
- nanobond
- Nanobond is the successor to Plasteel. It follows the same approach but has a much more refined manufacturing process with much more control on the small scale. The result is a much more robust and dense material although much more expensive.
-
-
- 120
-
-
-
-
- 1
- 15
- 57
- 1120000
- biometal
- Biometal is a metal armour that will actually regenerate itself thanks to some special bacteria it uses. The downside is that this makes it much bulkier and more expensive then just using a more refined Nanobond. The results are pretty formidable, but it's hard to equip such armour on anything short of a Destroyer.
-
-
- 150
- 60
-
-
-
-
- 3
- 11
- 3
- 430000
- droid
- This low maintenance droid crew will scour your ship to repair any damages caused by space hazards. They are very small and able to work both on the interior or exterior of the ship. Power is drawn from the ship to feed the robots, although the load is generally very low compared to the benefits of having a robotic repair crew.
-
-
- 30
- -5
- -40
-
-
-
-
- 1
- 9
- 12
- 170000
- reactor_i
- Adding a complementary reactor to your ship is a great way to get that extra energy boost you need. This do not replace the existing reactor but works alongside it and hooks up directly to the energy flux.
-
-
- 20
- 330
-
-
-
-
- 1
- 12
- 23
- 530000
- reactor_ii
- The class II reactor takes a different approach to energy creation then the class I reactor. The new fusion design allows it to have a higher energy output, but is deemed unstable at bigger loads. The result is a medium sized reactor that can't really suit the needs of the bigger warships.
-
-
- 60
- 720
-
-
-
-
- 1
- 12
- 46
- 970000
- reactor_iii
- The class III reactor pretty much makes all your energy worries negligible. It follows the traditional fusion approach of the class I reactor, only making it much bigger. The size increase makes it only fit comfortably on large vessels, but the energy output is also suited for those.
-
-
- 100
- 1620
-
-
-
-
- 1
- 14
- Light Combat Vessel License
- 80
- 830000
- lancelot_fighter
- This fighter bay allows your ship to carry a pair of Lancelot class Fighters. It comes with all the devices required for the maintenance and flight of the fighters.
-
-
- Lancelot Fighter
- 4000
-
-
-
-
- 2
- 12
- Light Combat Vessel License
- 0
- 500000
- lancelot_fighter
- This is a Lancelot class Fighter adapted for usage in the Lancelot Fighter Bay. It contains all the features of the standalone Lancelot with improved encrypted communication.
-
-
- Lancelot
-
-
-
-
- 1
- 7
- 0
- 75000
- license
- This license will authorize you to buy Cruise Ship and Bulk Carrier class ships.
-
-
-
-
-
- 1
- 5
- 0
- 50000
- license
- This license will authorize you to buy and use medium weapons like the Ion Cannon.
-
-
-
-
-
- 1
- 9
- 0
- 125000
- license
- This license will authorize you to buy and use heavy weapons like the Heavy Ion Turret.
-
-
-
-
-
- 1
- 9
- 0
- 175000
- license
- This license will authorize you to buy Fighter and Bomber class ships.
-
-
-
-
-
- 1
- 11
- 0
- 350000
- license
- This license will authorize you to buy Destroyer and Corvette class ships.
-
-
-
-
-
- 1
- 13
- 0
- 900000
- license
- This license will authorize you to buy Cruiser and Carrier class ships.
-
-
-
-
diff --git a/dat/planet.xml b/dat/planet.xml
deleted file mode 100644
index 0d243fe..0000000
--- a/dat/planet.xml
+++ /dev/null
@@ -1,823 +0,0 @@
-
-
-
-
- oceanic.png
- M01.png
-
-
- 0
- 0
-
-
- 0.5
- The bar is just off the starport with a great view of the harbor. You could watch the fishermen run frantically about attending their duties for hours.
- The surface of the planet is predominantly covered with water and the planetary climate is characterized by abundant precipitation and strong winds, yet tolerable enough to make special and expensive weather control measures unnecessary. Habitable land is often characterized by soft meadows, swamps and dense forests. The resource base of Caladan consists mainly of agriculture and biomass, with the locally bred and grown pundi rice being its main export, and fishing a traditional source of sustenance for its people. Other traditional products include wine and various livestock, most prominently cattle. Cuisine on Caladan is rather refined, with most dishes containing meat.
- Empire
-
- Food
- Ore
- Industrial Goods
- Medicine
-
-
- 5
- 0
-
- 31
- M
- 17000000
-
-
-
-
- methane.png
- J01.png
-
-
- 239
- 73
-
-
- 1
-
- 0
- 0
-
- J
- Eiroik used to be a mining planet under the Empire rule until the Collective wiped out the human colonies on it. The harsh atmosphere did the rest, erasing all tracks of former human life.
-
-
-
-
- station01.png
- 001.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- 3
- Collective
-
-
-
-
- gas.png
- I01.png
-
-
- 0
- 0
-
-
- 0.3
- There's nothing remarkable about the Nor spaceport bar. It's full of drunken Dvaereds trying to forget their hard labour.
- Nor was one of the first Dvaered worlds to be terraformed. It's abundance in gas and ores made it a strategic location and has since then been heavily reinforced after FLF attacks and sabotages.
- Dvaered
-
- Food
- Medicine
- Ore
- Industrial Goods
-
-
- 0
- 0
-
- 7
- I
- 130000
-
-
-
-
- traderoom.png
- D01.png
-
-
- 120
- -97
-
-
- 0.5
- The Jorlan people don't really have a habit for drinking. You only seem to see other spacefarers in the bar, but no natives.
- Jorlan is a small moon that orbits Haleb IV. It's inhabitants are mostly part of the ore refining process, as it supplies most of the Frontier with all sorts of alloys. Gas miners are also sent down to Haleb IV every dozen STU when the planetary conditions are favorable, otherwise the incredible winds can crush many ships like tin cans.
- Frontier
-
- Food
- Ore
- Industrial Goods
-
-
- 6
- 0
-
- 15
- D
- 5000000
-
-
-
-
- snow.png
- P00.png
-
-
- 0
- 0
-
-
- 0.3
- Most of the drinks served at the bar are served very warm with heavy infusions of all kinds of spices. They are designed to give a lot of energy to keep the body warm when walking in the cold base.
- Selphod is a very harsh and barren ice planet. Most of the locals have never ventured outside the established bases. The reason is that to be able to venture outside you have to wear really heavy thermal protection with a personal generator to keep the body temperature at optimal. Even then, if the gear isn't worn properly the cold will quickly enter and kill the living being in less then a mTSU.
- Empire
-
- Food
- Ore
- Industrial Goods
-
-
- 7
- 0
-
- 7
- P
- 27000
-
-
-
-
- lava.png
- A01.png
-
-
- 0
- 0
-
-
- 0.7
- The drinks served in the Furnance, as the bar calls itself are of a pretty strange variety. They are generally very strong and served at a warm temperature. The house specialties also contain volcanic ash which is harvested on the planet surface. A strange bar indeed.
- Doranthex Prime is a mostly molten planet. The only exception is a small island that drifts around the surface mainly around the polar regions. On this island the Dvaered have established a small base, mainly for research and military prototyping, although civilians are allowed in the main facilities. Due to the intense temperatures they are shielded by over 50m of temperature isolating plating, which doesn't allow any views of the planet itself once you've landed.
- Dvaered
-
- Food
-
-
- 0
- 0
-
- 3
- A
- 20000
-
-
-
-
- traderoom.png
- 003.png
-
-
- 0
- 0
-
-
- 0.5
- The bar is maintained by off-duty scientists and soldiers. It's very small and doesn't have much offerings. There's not much ambient noise, it seems like the boredom has gotten the best of most of the people.
- Named after the guardian dog of hell for its role in monitoring and observing the immense Sol nebulae. It was created shortly after the nebulae stabilized. Exact details are confidential and there's more then enough military influence to make it suspicious. With all the conspiracy theories around the Incident, one can never be too sure where reality ends and fiction starts.
- Empire
-
- 0
- 0
-
- 3
- 0
- 700
-
-
-
-
- I00.png
-
-
- -17
- -57
-
-
- 0
-
- 0
- 0
-
- I
-
-
-
-
- station00.png
- 000.png
-
-
- 54
- 47
-
-
- 0.8
- The Tau Prime algae has a very strong stench which seems to envelope the bar completely. The smell is so strong you can actually taste it. It doesn't taste nearly as good unprocessed. Most algae runners stop to grab drinks between runs to try to get the taste of the algae out of their mouth, although the usually use liquor made out of processed algae to do that.
- Tau Station was constructed with the sole purpose of exploiting the algae produced on Tau Prime. Being a completely watery algae world with a very corrosive environment, it was deemed more profitable to build a space station then a city on the planet surface. From the station windows you can see heavy algae collectors flying to and from the surface on their endless algae runs.
- Empire
-
- Food
-
-
- 7
- 0
-
- 7
- 0
- 12000
-
-
-
-
- station00.png
- 000.png
-
-
- 17
- 394
-
-
- 0.5
- The Raglan bar is a pretty small bar for Dvaered standards, and quite empty too.
- Raglan Outpost was established after the Dvaered-Frontier war broke out before the Incident. To this day the Frontier still is demanding for its dismantling in the halls of the Emperor, although he has yet to make a statement. Meanwhile the Dvaereds use this base intensively in their fight against the FLF.
- Dvaered
-
- 7
- 0
-
- 3
- 1
- 7000
-
-
-
-
- mining.png
- G00.png
-
-
- 0
- 0
-
-
- 0.7
- The spaceport bar is carved into a rich mineral deposit giving the walls great reflections and colours. The local drink are made partially with minerals giving all a rocky taste.
- Torloth is a heavy mining planet. It has rich ores and minerals in abundance with no local life forms to speak of. It's one of the strongholds of the Nexus corporation housing some of their important ship factories. Of course the bigger ships have to get built off planet.
- Empire
-
- Food
- Ore
- Industrial Goods
-
-
- 0
- 0
-
- 7
- G
- 350000
-
-
-
-
- station00.png
- 000.png
-
-
- 0
- 0
-
-
- 0.3
- The Omega Canteen is a dark place that seems calm, although everytime a robotic drone approaches an alarm sounds sending pilots to man their ships to fight off the menace.
- Built to defend the Empire from the Collective. The Omega Station has been the observer of countless battles fought in its sector. It's helped keep a stalemate in the sector.
- Empire
-
- Food
- Medicine
-
-
- 9
- 0
-
- 15
- 0
- 14000
-
-
-
-
- mining.png
- C00.png
-
-
- 0
- 0
-
-
- 127000
- 0.4
- The bar is designed for the workers of the terraforming project. It's a simple dusty bar constantly full of workers.
- Emperor's Fist is intended to be the new homeworld of the Emperor itself since the last one was destroyed in the Incident. It's a gigantic project that is attempting to completely adapt a C-class world to be suitable for the highest ranks of the Empire's aristocracy. Currently it doesn't have much past the Starport.
- Empire
-
- 0
- 0
-
- 3
- C
-
-
-
-
- M02.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- M
-
-
-
-
- desertic.png
- H00.png
-
-
- 0
- 0
-
-
- 0.3
- The Arrakeen canteen is a shady place. Many scoundrels and lowlifes make this their home to avoid notice from the universal police.
- Arrakis is a desert planet with no natural precipitation.
- Empire
-
- Food
- Ore
-
-
- 0
- 0
-
- 7
- H
- 32000
-
-
-
-
- mining.png
- L00.png
-
-
- 0
- 0
-
-
- 0.5
- "The bar has a strange old meter on one of the walls that seems to dance erratically. When you ask the bartender about it he mentions it measures the current pressure outside.
- Thar is a simple mining world owned by the Dvaered. It has a very variable atmosphere that can go from a few kilometers wide to barely existent in no time. The pressure changes are harmful to most lifeforms, making it an almost completely sterile planet. With the advent of terraforming techniques it was finally made habitable for humans so they could exploit some of the resources it has.
- Dvaered
-
- Food
- Ore
- Industrial Goods
-
-
- 0
- 0
-
- 7
- L
- 2000
-
-
-
-
- station01.png
- 001.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- 3
- Collective
-
-
-
-
- traderoom.png
- 002.png
-
-
- 77
- -42
-
-
- 318000
- 0.5
- Since you aren't allowed in the fancier bars you wander into the spaceport bar. You can only imagine how the Emperor's bar itself can be like.
- Polaris Prime has become recent home to the Emperor himself as he plans and constructs his new stronghold on Emperor's Fist. It is an immense station that has most things anyone would want.
- Empire
-
- Food
- Medicine
- Ore
- Luxury Goods
- Industrial Goods
-
-
- 15
- 0
-
- 31
- 1
-
-
-
-
- mining.png
- G01.png
-
-
- 0
- 0
-
-
- 0.5
- The one word that would describe the Jorcan spaceport bar would be dust. It's everywhere: on the seats, on the counter, in the drinks, on everyone's faces... It's not the usual finer dust you find on most worlds either, it's a thick, consistant, black, disgusting dust that you think you'll never be able to get off you.
- Jorcan is a very barren dull planet, like most mining worlds. It's very poor in deposits, but mining is still done heavily in an attempt to remove every single drop of ore from the planet.
- Dvaered
-
- Food
- Ore
-
-
- 0
- 0
-
- 7
- G
- 170000
-
-
-
-
- snow.png
- P01.png
-
-
- 0
- 0
-
-
- 0.5
- The Vlexair bar is small as far as Dvaered bars go. There's not much variety of drink other then the standard Dvaered grogs.
- Vlexair is a harsh frozen world. The planet wasn't always frozen though, it used to be a lush world until the planet's core froze. Since then it's an extremely dangerous environment suitable only to the Dvaered workers.
- Dvaered
-
- Food
- Medicine
- Ore
- Industrial Goods
-
-
- 0
- 0
-
- 7
- P
- 2500
-
-
-
-
- station01.png
- 001.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- 3
- Collective
-
-
-
-
- oceanic.png
- M04.png
-
-
- 0
- 0
-
-
- 0.7
- The Goddard Bar is unsurprisingly an old obsolete model remade as a bar. It's surprisingly comfortable and cozy as a bar, although every so often you can hear creaking in the ancient metal frame.
- Zhiru was a quiet planet, home of House Goddard, one of the minor Houses. One day House Goddard began a plan to create a massive spacecraft, based on their air-born planes. The result was the massive Goddard, named after the house that created it. The ship was a massive success and went about to give House Goddard fame throughout the galaxy. Now Zhiru is a booming ship factory, specialized in the creation and maintenance of the Goddard ships. This is all possible due to the weak gravity and atmosphere that envelopes Zhiru that allows the massive spacecraft to land and take off without much difficulty.
- Goddard
-
- Food
- Ore
- Industrial Goods
-
-
- 10
- 1001
-
- 31
- M
- 13000000
-
-
-
-
- station01.png
- 001.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- 3
- Collective
-
-
-
-
- gas.png
- D00.png
-
-
- 0
- 0
-
-
- 0.6
- The Slop and Grill is one of the nastiest taverns in the universe. The food and drink doesn't exactly help. Most of it is brewed on New Haven and wouldn't pass any of the minimal health insurance tests. Some of the booze even doubles as ship fuel if needed, which says a lot about the quality.The clients are also deep space thugs, pirates, black marketers, mercenaries and other shady folk that insist on keeping the ground coated with blood and broken teeth. Not a great place to bring the family.
- New Haven is a small planet located beyond the boundaries of law and justice. Founded by Bartax the Great, one of the most successful pirates to ever live after the old Haven was annihilated.The planet is mostly covered by very toxic gases and has a lot of radiation if you stray from the stronghold. These very features are what made the Empire qualify it as uninhabitable as it doesn't have any strategic resources. It's distance from other civilized worlds also gives it a nice cover from prying eyes.
- Pirate
-
- Medicine
- Luxury Goods
- Industrial Goods
-
-
- 13
- 9009
-
- 31
- D
- 9000
-
-
-
-
- station00.png
- 000.png
-
-
- 0
- 0
-
-
- 0.3
- The bar walls are covered with pictures of Empire soldiers fallen in the fight against Haven and piracy in general. It has become a custom of the Empire to put pictures of the fallen from fighting piracy. They are working on another addition to be able to fit more pictures.
- Zabween is an old station. It was first created as an outpost to fight piracy, but with the destruction of the Haven it has calmed down a lot. Now it's more of a gigantic commercial center selling all sorts of goods. It keeps a museum with all sorts of ships and weapons that were used in the final fight against Haven.
- Empire
-
- Food
- Medicine
- Luxury Goods
- Industrial Goods
-
-
- 9
- 0
-
- 31
- 0
- 4000
-
-
-
-
- aquatic.png
- O01.png
-
-
- 0
- 0
-
-
- 0.6
- The bar is very large and not too full. You notice the drink list has a "living" menu. When you ask the bartender about them, he says they specialize in drinks containing living beings. Generally jellyfish, but sometimes small cephalopods or more exotic beings. What strange habits.
- Cetrat is a small aquatic planet known for its medical algae that grows. No one has been able to reproduce it exactly as it is in the wild, but with the abundance of it all over there hasn't been too much effort in that field.
- Frontier
-
- Medicine
- Luxury Goods
-
-
- 6
- 0
-
- 15
- A
- 930000
-
-
-
-
- station02.png
- 002.png
-
-
- 0
- 0
-
-
- 0.2
- Another big dirty bar full of hulking, smelly, sweaty Dvaereds. They make a good brew though.
- Constructed by many captured and then enslaved FLF armsmen. The design is pretty sturdy but you can't help to think there must be a hidden bomb somewhere, just waiting to go off and kill the Dvaered oppressors.
- Dvaered
-
- 3
- 0
-
- 11
- 0
- 3000
-
-
-
-
- station02.png
- 002.png
-
-
- -53
- -77
-
-
- 0.8
- The Darkshed cantina is decorated with all sorts of odd artifacts that marked different tendencies in spaceship outfitting.
- Renowned for its outfit market and shipyards. Almost the entire Darkshed station is dedicated to trading outfits and ships. Mercenaries and bounty hunters from all over the galaxy come here to see the newest enhancements available in the market. This tends to also attract many of the shadier characters in the universe winding up with frequent fights where they test their newly bought outfits.
- Independent
-
- Food
- Ore
- Industrial Goods
- Medicine
- Luxury Goods
-
-
- 15
- 0
-
- 31
- 0
- 14000
-
-
-
-
- oceanic.png
- M05.png
-
-
- 0
- 0
-
-
- 812000
- 0.5
- The bar is a nice clean place unlike most other bars. It's been cleaned thoroughly for all the Empire officials that are starting to use the planet as their home.
- Nova Shakar was a somewhat abandoned Empire planet until the Emperor's Fist project was started. Since then it's become a major producer of goods for the project and has started to gain importance.
- Empire
-
- Food
- Medicine
- Ore
- Industrial Goods
-
-
- 6
- 0
-
- 15
- M
-
-
-
-
- station01.png
- 001.png
-
-
- 0
- 0
-
-
- 0
-
- 0
- 0
-
- 3
- Collective
-
-
-
-
- J00.png
-
-
- 17
- 23
-
-
- 0
-
- 0
- 0
-
- J
-
-
-
-
- aquatic.png
- O00.png
-
-
- 0
- 0
-
-
- 0.4
- The spaceport bar is approximately 3 km below the surface of the planet. Most of the walls are of a hardened transparent polymer that allows you to see into the darkness of the water. Every so often you can notice a gelatinous creature slide around, barely illuminated by the bar lighting.
- Anecu is a completely aquatic planet. It's surface is covered completely by water. In the shallow areas great underwater cities are constructed, as the climate above the water can be very harsh (waves been recorded to be up to 2 km high). The planet boasts of extensive ship designing facilities, using the high pressure water as a testbed for ships of all sorts.
- Dvaered
-
- Food
- Medicine
- Ore
- Luxury Goods
- Industrial Goods
-
-
- 6
- 0
-
- 31
- M
- 70000
-
-
-
diff --git a/dat/ship.xml b/dat/ship.xml
deleted file mode 100644
index f8a03c8..0000000
--- a/dat/ship.xml
+++ /dev/null
@@ -1,1084 +0,0 @@
-
-
-
- lancelot
- minimal
- engine
- Yacht
- 500000
- Nexus
- 9999
- Used for testing!
-
- 320
- 135
- 260
-
-
- 11340
- 11300
- 11380
- 11380
- 11360
- 11000
-
-
- 10
- 95
- 1000000
- 80000
- 600000
-
-
- Lancelot Fighter Bay
- Lancelot Fighter
- Ripper MK2
- Banshee Launcher
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
-
-
-
- llama
- minimal
- engine
- Yacht
- 120000
- Melendez Corp.
- 2
- One of the most widely used ships in the galaxy. Renowned for its stability and stubbornness. The design hasn't been modified much since its creation many many years ago. It was one of the first civilian use spacecrafts, first used by aristocracy and now used by everyone who cannot afford better.
-
- 220
- 150
- 260
-
-
- 50
- 60
- 240
- 80
- 50
- 500
-
-
- 2
- 32
- 400
- 25
- 20
-
-
- Laser Cannon
-
-
- 0
- 1
-
-
-
- hyena
- minimal
- engine
- Fighter
- 180000
- Aerosys
- 2
- The star product of Aerosys, the Hyena quickly has become a favorite of pirates far and wide. Not much of a fighter, nor does it pack too much of a punch, but they like to come in swarms to overcome their enemies. While the Aerosys' official stance is that it doesn't sell them to shady characters, it's widely known that they do as it seems there's a countless amount in the hands of pirates.
-
- 300
- 180
- 330
-
-
- 70
- 50
- 180
- 150
- 60
- 550
-
-
- 2
- 25
- 300
- 30
- 10
-
-
- Laser Cannon
-
-
- 0
- 1
-
-
-
- pacifier
- minimal
- engine
- Destroyer
- 1200000
- Nexus
- 8
- Medium Combat Vessel License
- The Pacifier is one of the older and trustier designs of the Nexus Corporation. Was constructed mainly to patrol border systems. They are very heavy fighters designed to be able to take a pounding and dish out damage, but the cost has been maneuverability. No reason to run away if you're in one of these.
-
- 180
- 115
- 200
-
-
- 260
- 180
- 420
- 240
- 90
- 1380
-
-
- 17
- 230
- 500
- 130
- 30
-
-
- Laser Cannon
- Laser Turret
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
-
-
-
- pacifier_empire
- minimal
- engine
- Destroyer
- 1200000
- Nexus
- 9999
- Medium Combat Vessel License
- An Empire Pacifier.
-
- 180
- 115
- 200
-
-
- 275
- 200
- 420
- 250
- 100
- 1380
-
-
- 17
- 230
- 500
- 130
- 30
-
-
- Ion Cannon
- Heavy Ion Turret
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
-
-
-
- hawking
- minimal
- engine
- Cruiser
- 7500000
- Nexus
- 9
- Heavy Combat Vessel License
- A heavy frigate designed for heavy combat. Used widely by the empire to establish control on its territory. Has more then enough firepower to not be taken lightly.
-
- 80
- 70
- 100
-
-
- 600
- 400
- 900
- 300
- 80
- 1600
-
-
- 35
- 3750
- 300
- 200
- 70
-
-
- Laser Turret
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
- 2
- 3
-
-
-
- hawking_empire
- minimal
- engine
- Cruiser
- 7500000
- Nexus
- 9999
- Heavy Combat Vessel License
- An Empire Hawking.
-
- 80
- 70
- 100
-
-
- 630
- 420
- 900
- 330
- 100
- 1600
-
-
- 35
- 3750
- 300
- 200
- 70
-
-
- Heavy Ion Turret
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
- 2
- 3
-
-
-
- lancelot
- minimal
- engine
- Fighter
- 500000
- Nexus
- 7
- Light Combat Vessel License
- One of the Nexus' prize heavy fighters. Was originally a secret design for the Empire military, but then disclosed. Now a modified version is available for civilians, although it doesn't meet up to the original specifications. Used by security agencies all over the universe for its reliability and availability. Proudly enforcing your security since UST 1132.
-
- 220
- 135
- 260
-
-
- 140
- 100
- 280
- 180
- 60
- 980
-
-
- 4
- 90
- 400
- 50
- 10
-
-
- Laser Cannon
- Seeker Launcher
- Seeker Missile
-
-
- 0
- 1
-
-
-
- lancelot_empire
- minimal
- engine
- Fighter
- 500000
- Nexus
- 9999
- Light Combat Vessel License
- An Empire Lancelot.
-
- 220
- 135
- 260
-
-
- 150
- 100
- 280
- 190
- 60
- 980
-
-
- 4
- 90
- 400
- 50
- 10
-
-
- Ripper MK2
- Headhunter Launcher
- Headhunter
- Milspec Jammer
-
-
- 0
- 1
-
-
-
- mule
- minimal
- engine
- Freighter
- 900000
- Melendez Corp.
- 5
- Large Civilian Vessel License
- A heavy liner specialized in freighting cargo all over the universe. Also has good accommodations for passengers depending on the model, allowing for enjoyable cruises. Was a favorite target of pirates until they added stock turrets to the new models which can now defend themselves properly.
-
- 100
- 100
- 100
-
-
- 160
- 200
- 300
- 100
- 40
- 800
-
-
- 13
- 1750
- 500
- 50
- 250
-
-
- Laser Turret
-
-
- 0
- 1
- 2
-
-
-
- drone
- minimal
- engine
- Drone
- 300000
- Robosys
- 99
- A robot drone.
-
- 320
- 200
- 360
-
-
- 70
- 40
- 300
- 240
- 420
- 600
-
-
- 1
- 15
- 1
- 24
- 1
-
-
- Neutron Disruptor
-
-
- 0
- 1
-
-
-
- gawain
- minimal
- engine
- Luxury Yacht
- 500000
- Nexus
- 11
- The Gawain is a very high end ship that heavily uses the technology developed with the Lancelot. It's widely used as a sporting rig as it is extremely maneuverable, although they are rarely used in combat because they are too expensive for the little firepower they can support.
-
- 320
- 170
- 340
-
-
- 90
- 50
- 240
- 100
- 70
- 700
-
-
- 2
- 28
- 400
- 35
- 15
-
-
- Ion Cannon
-
-
- 0
- 1
-
-
-
- goddard
- minimal
- engine
- Cruiser
- 11500000
- House Goddard
- 1001
- Heavy Combat Vessel License
- The archaic design of the Goddard is deceiving. Although it takes the shape of traditional flying intra-planet vessels, it's very suited for space travel. Production is entirely done on Zhiru in the Goddard system by House Goddard the sole provider and dealer in Goddards. Over time, specialization and improvements on the original design have kept it very competitive in the market. It's a classic of space.
-
- 100
- 80
- 130
-
-
- 800
- 500
- 2000
- 330
- 90
- 1700
-
-
- 52
- 4350
- 500
- 250
- 60
-
-
- Heavy Ion Turret
- Laser Turret
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
- 2
- 3
- 4
- 5
-
-
-
- goddard_dvaered
- minimal
- engine
- Cruiser
- 11500000
- House Goddard
- 9999
- Heavy Combat Vessel License
- A Dvaered Goddard.
-
- 100
- 80
- 130
-
-
- 800
- 500
- 2000
- 330
- 90
- 1700
-
-
- 52
- 4350
- 500
- 250
- 60
-
-
- Laser Turret
- Mace Launcher
- Mace Rocket
-
-
- 0
- 1
- 2
- 3
- 4
- 5
-
-
-
- admonisher
- minimal
- engine
- Corvette
- 900000
- Nexus
- 10
- Medium Combat Vessel License
- A very versatile combat ship. Nexus defines it as the combination between the ruggedness of the Pacifier and the agility of the Lancelot. Overall a very solid fighter.
-
- 200
- 105
- 200
-
-
- 240
- 170
- 380
- 240
- 90
- 1180
-
-
- 13
- 170
- 400
- 110
- 20
-
-
- Laser Cannon
- Plasma Blaster
- Headhunter Launcher
- Headhunter
-
-
- 0
- 1
-
-
-
- admonisher_pirate
- minimal
- engine
- Corvette
- 850000
- Skull and Bones
- 9009
- What do you get when you rip apart an Admonisher, hack up the internals and slap it back together? A Pirate Admonisher, which surprisingly works quite well.
-
- 205
- 110
- 210
-
-
- 250
- 175
- 390
- 260
- 60
- 1180
-
-
- 13
- 165
- 400
- 125
- 15
-
-
- Plasma Blaster
- Banshee Launcher
- Banshee Rocket
- Seeker Launcher
- Seeker Missile
- Civilian Jammer
-
-
- 0
- 1
-
-
-
- admonisher_empire
- minimal
- engine
- Corvette
- 900000
- Nexus
- 9999
- Medium Combat Vessel License
- An Empire Admonisher.
-
- 200
- 105
- 200
-
-
- 250
- 175
- 380
- 250
- 100
- 1180
-
-
- 13
- 170
- 400
- 110
- 20
-
-
- Ripper MK2
- Ion Cannon
- Headhunter Launcher
- Headhunter
- Milspec Jammer
-
-
- 0
- 1
-
-
-
- schroedinger
- minimal
- engine
- Scout
- 180000
- Sirius Systems
- 5
- The Schroedinger is primarily used as a reconnaissance vessel. It is very autonomous thanks to its special fuel tanks and light frame. The downside is that the ship is extremely vulnerable to attack. It also sports a twin pair of Eraedon engines, making it pretty maneuverable.
-
- 260
- 165
- 300
-
-
- 60
- 25
- 180
- 60
- 30
- 400
-
-
- 2
- 17
- 800
- 15
- 15
-
-
- Civilian Jammer
-
-
- 0
- 1
-
-
-
- vendetta
- minimal
- engine
- Fighter
- 400000
- House Dvaered
- 8
- Light Combat Vessel License
- The Vendetta displays the House Dvaered philosophy very well. Give a ship as many intimidating guns as you can, layer it with as much armour and you can, and sort of forget about giving it proper electronics. It's amazing to see that these fly.
-
- 200
- 125
- 180
-
-
- 70
- 160
- 500
- 90
- 30
- 600
-
-
- 4
- 67
- 300
- 60
- 5
-
-
- Laser Cannon
-
-
- 0
- 1
-
-
-
- vendetta_dvaered
- minimal
- engine
- Fighter
- 400000
- House Dvaered
- 9999
- A Dvaered Vendetta.
-
- 200
- 125
- 180
-
-
- 70
- 160
- 500
- 90
- 30
- 600
-
-
- 4
- 67
- 300
- 60
- 5
-
-
- Laser Cannon
- Mace Launcher
- Mace Rocket
-
-
- 0
- 1
-
-
-
- vendetta_pirate
- minimal
- engine
- Fighter
- 450000
- Skull and Bones
- 9009
- The Pirate Vendetta is even more intimidating then its regular counterpart. It's been heavily tweaked to be more adjusted to the pirate style of flying. Some of the armour has been removed to make more room for loot, while the reactor has been jacked up by a dubious technician. The ship ends up being much more solid then the original, but every so often the reactor goes nova destroying the ship. You hope it won't happen to you if you get in one.
-
- 210
- 135
- 190
-
-
- 80
- 150
- 540
- 95
- 32
- 625
-
-
- 4
- 65
- 300
- 60
- 10
-
-
- Plasma Blaster
- Laser Cannon
-
-
- 0
- 1
-
-
-
- ancestor
- minimal
- engine
- Bomber
- 600000
- House Dvaered
- 9
- Light Combat Vessel License
- Commonly referred to as the little Goddard, the Ancestor also has its roots in the primitive flying machines used by men many ages ago. Unlike the Goddard though, the electronics are done by House Dvaered, making it considerably inferior in that area.
-
- 180
- 105
- 220
-
-
- 100
- 190
- 600
- 90
- 30
- 700
-
-
- 6
- 80
- 300
- 80
- 10
-
-
- Laser Cannon
- Seeker Launcher
- Seeker Missile
-
-
- 0
- 1
-
-
-
- ancestor_dvaered
- minimal
- engine
- Bomber
- 600000
- House Dvaered
- 9999
- Light Combat Vessel License
- A Dvaered Ancestor.
-
- 180
- 105
- 220
-
-
- 100
- 190
- 600
- 90
- 30
- 700
-
-
- 6
- 80
- 300
- 80
- 10
-
-
- Laser Cannon
- Mace Launcher
- Mace Rocket
-
-
- 0
- 1
-
-
-
- ancestor_pirate
- minimal
- engine
- Bomber
- 550000
- Skull and Bones
- 9009
- Ancestors were one of the first ships to be fancied by pirates. The big intimidating wings and good top speeds would usually get ships to surrender without firing a shot. As better ships came out in the market, their use has fallen due to their archaic electronic and targetting systems.
-
- 180
- 100
- 225
-
-
- 120
- 180
- 600
- 100
- 35
- 650
-
-
- 6
- 74
- 400
- 75
- 15
-
-
- Plasma Blaster
- Seeker Launcher
- Seeker Missile
-
-
- 0
- 1
-
-
-
- koala
- minimal
- engine
- Courier
- 260000
- Melendez Corp.
- 5
- The Koala is your standard cargo vessel. It's a small ship with little weapon space but a decent amount of cargo space. Good for the entrepreneur working his way to a vast space trade empire.
-
- 200
- 140
- 220
-
-
- 70
- 90
- 270
- 90
- 50
- 500
-
-
- 3
- 63
- 400
- 20
- 45
-
-
- Laser Cannon
-
-
- 0
- 1
-
-
-
- kestrel
- minimal
- engine
- Cruiser
- 6000000
- Krain Industries
- 12
- Heavy Combat Vessel License
- The Kestrel was designed to be a sleek heavy assault cruiser. Generally more fragile then other cruisers, although it doesn't fall behind in firepower. Probably one of the most elegant cruisers on the market.
-
- 120
- 100
- 140
-
-
- 550
- 300
- 800
- 360
- 100
- 1400
-
-
- 27
- 2800
- 300
- 150
- 50
-
-
- Heavy Ion Turret
- Seeker Launcher
- Seeker Missile
-
-
- 0
- 1
- 2
- 3
-
-
-
- kestrel_pirate
- minimal
- engine
- Cruiser
- 5700000
- Skull and Bones
- 9009
- The Kestrel is the best ship made by the Skull and Bones. It is extremely agile for a cruiser yet doesn't lack the firepower necessary to question the authority of the Empire. A very strong ship for those pirates who can afford it.
-
- 130
- 110
- 150
-
-
- 600
- 280
- 830
- 380
- 90
- 1300
-
-
- 28
- 2725
- 300
- 160
- 55
-
-
- Heavy Ion Turret
- Seeker Launcher
- Seeker Missile
-
-
- 0
- 1
- 2
- 3
-
-
-
diff --git a/dat/spfx.xml b/dat/spfx.xml
deleted file mode 100644
index c3ae373..0000000
--- a/dat/spfx.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
- exps
- 400
-
-
- expm
- 450
-
-
- expl
- 500
-
-
- cargo
- 15000
- 5000
-
-
- emps
- 400
-
-
- empm
- 450
-
-
- shis
- 400
-
-
- shim
- 450
-
-
- plas
- 400
-
-
- plam
- 450
-
-
diff --git a/dat/ssys.xml b/dat/ssys.xml
deleted file mode 100644
index 14be99f..0000000
--- a/dat/ssys.xml
+++ /dev/null
@@ -1,1453 +0,0 @@
-
-
-
-
- Pirate Light Prescence
- Dvaered Medium Prescence
- Trader Light Prescence
-
-
- Torg
- Raelid
- Cygnus
- Doranthex
- Tau Prime
- Zacron
-
-
- -157
- 175
-
-
- Anecu
-
-
- 0
- 50
- 0
- 500
-
-
-
-
- Pirate Medium Prescence
- Empire Patrol Prescence
-
-
- NGC-7783
- NGC-7843
- NGC-7693
-
-
- 198
- 85
-
-
-
- 0
- 50
- 0
- 160
-
-
-
-
- Empire Light Prescence
- Dvaered Medium Prescence
- Trader Light Prescence
-
-
- Draygar
- Tau Prime
- Toaxis
- Zacron
- Arcanis
-
-
- -137
- 269
-
-
- Raelid Outpost
-
-
- 0
- 100
- 100
- 500
-
-
-
-
- Empire Patrol Prescence
-
-
- Myad
- Sigur
- Doeston
- Toaxis
- Arcanis
-
-
- -91
- 434
-
-
-
- 0
- 300
- 250
- 400
-
-
-
-
-
- Zerantix
- Polaris
- Toros
- Doeston
- Oriantis
-
-
- 43
- 566
-
-
-
- 0
- 600
- 600
- 500
-
-
-
-
- Empire Heavy Prescence
- Trader Light Prescence
-
-
- Shakar
- Gamma Polaris
-
-
- -237
- -45
-
-
-
- 0
- 0
- 0
- 100
-
-
-
-
- Pirate Medium Prescence
- Empire Patrol Prescence
-
-
- Coriolis
- NGC-7324
- NGC-7549
- NGC-7693
-
-
- 100
- -5
-
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Pirate Medium Prescence
- Empire Patrol Prescence
-
-
- Coriolis
- NGC-7723
- NGC-7690
- Dune
-
-
- 124
- 81
-
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Empire Patrol Prescence
-
-
- Arcanis
- Sigur
-
-
- 19
- 368
-
-
-
- 0
- 300
- 250
- 400
-
-
-
-
- Pirate Light Prescence
- Dvaered Medium Prescence
- Trader Light Prescence
-
-
- Vlexon
- Draygar
- Torg
- Gamma Polaris
- Goddard
-
-
- -176
- 109
-
-
- Doranthex Prime
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Heavy Prescence
-
-
- NGC-7723
- New Haven
-
-
- 235
- 155
-
-
-
- 0
- 100
- 0
- 120
-
-
-
-
- Empire Patrol Prescence
-
-
- NGC-8037
- Tau Prime
- Zylex
- Raelid
- Sigur
-
-
- -57
- 333
-
-
-
- 0
- 200
- 200
- 500
-
-
-
-
- Empire Medium Prescence
- Trader Heavy Prescence
- Pirate Light Prescence
-
-
- Borla
- Sirou
- Goddard
- Gamma Polaris
-
-
- -140
- -47
-
-
- Nova Shakar
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Light Prescence
-
-
- Mizar
- Haven
-
-
- 83
- 223
-
-
-
- 0
- 150
- 150
- 400
-
-
-
-
- Empire Patrol Prescence
-
-
- Arandon
- Myad
- Sigur
- Toros
- Zylex
-
-
- -43
- 513
-
-
- Cerberus
-
-
- 0
- 400
- 400
- 400
-
-
-
-
- Dvaered Medium Prescence
- Trader Light Prescence
- FLF Light Guerrilla
-
-
- Draygar
- Vlexon
- Klantar
- Doranthex
- Zacron
- Tuoladis
-
-
- -242
- 179
-
-
- Jorcan
-
-
- 0
- 0
- 0
- 100
-
-
-
-
- Collective Medium Prescence
-
-
- C-28
- C-14
-
-
- 147
- -296
-
-
- S00000
-
-
- 0
- 0
- 0
- 100
-
-
-
-
-
- Arandon
- Polaris
- Toros
- Sol
- Haered
-
-
- 64
- 677
-
-
-
- 0
- 700
- 750
- 500
-
-
-
-
- Collective Medium Prescence
-
-
- C-00
- C-43
- C-59
- C-14
-
-
- 79
- -265
-
-
- S38729
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Empire Patrol Prescence
-
-
- NGC-8037
- Zylex
- Doeston
- Arcanis
- Oriantis
-
-
- -15
- 435
-
-
-
- 0
- 350
- 300
- 400
-
-
-
-
- Pirate Light Prescence
- Empire Patrol Prescence
-
-
- NGC-7291
- NGC-7324
-
-
- 82
- -82
-
-
-
- 0
- 0
- 0
- 150
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
-
-
- NGC-7291
- Delta Pavonis
- NGC-6938
- NGC-7324
- Borla
-
-
- -15
- -32
-
-
-
- 0
- 0
- 0
- 300
-
-
-
-
- Pirate Light Prescence
- Trader Light Prescence
- Empire Light Prescence
-
-
- Coriolis
- NGC-7789
- Eridani
- NGC-7693
- Alteris
-
-
- 90
- 120
-
-
- Arrakis
-
-
- 0
- 0
- 0
- 300
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
- Empire Light Prescence
-
-
- Dune
- NGC-7693
- Alteris
- NGC-7690
-
-
- 73
- 46
-
-
-
- 0
- 0
- 0
- 300
-
-
-
-
- Trader Light Prescence
- FLF Medium Guerrilla
-
-
- Dakron
- Theras
- Haleb
-
-
- -379
- 342
-
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Trader Heavy Prescence
- Empire Heavy Prescence
- Dvaered Light Prescence
-
-
- Doranthex
- Vlexon
- Sirou
- Goddard
- Shakar
-
-
- -204
- 6
-
-
- Emperor's Fist
- Polaris Prime
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Light Prescence
- Trader Medium Prescence
- Empire Medium Prescence
-
-
- Delta Pavonis
- Tau Prime
- Borla
- Goddard
- Draygar
-
-
- -85
- 88
-
-
- Torloth
-
-
- 0
- 50
- 0
- 400
-
-
-
-
- Pirate Light Prescence
- Trader Medium Prescence
- Empire Medium Prescence
-
-
- Draconis
- Draygar
- Raelid
- Arcanis
- Cygnus
-
-
- -94
- 177
-
-
- Tau Prime
- Tau Station
-
-
- 0
- 100
- 100
- 600
-
-
-
-
-
- Arandon
- Zerantix
- Sol
-
-
- 148
- 590
-
-
-
- 0
- 800
- 800
- 400
-
-
-
-
- Pirate Light Prescence
- Empire Patrol Prescence
-
-
- NGC-7690
-
-
- 148
- -74
-
-
-
- 0
- 0
- 0
- 100
-
-
-
-
- Pirate Medium Prescence
-
-
- NGC-7968
-
-
- 122
- 277
-
-
-
- 0
- 300
- 200
- 300
-
-
-
-
- Collective Medium Prescence
-
-
- C-14
- C-59
- NGC-7132
- C-28
-
-
- 27
- -262
-
-
- S23491
- Eiroik
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Collective Light Prescence
- Empire Heavy Prescence
- Trader Light Prescence
-
-
- NGC-7324
- NGC-7273
- NGC-7132
- NGC-7414
-
-
- 13
- -117
-
-
- Omega Station
-
-
- 0
- 0
- 0
- 300
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
- Empire Light Prescence
- Empire Light Prescence
-
-
- Cygnus
- NGC-7273
- NGC-6938
- Shakar
- Delta Pavonis
- Goddard
-
-
- -68
- 8
-
-
-
- 0
- 0
- 0
- 400
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
- Empire Light Prescence
-
-
- Draconis
- Eridani
- NGC-7968
-
-
- 19
- 197
-
-
-
- 0
- 100
- 100
- 500
-
-
-
-
- Collective Light Prescence
-
-
- NGC-7291
- C-59
- C-43
-
-
- 35
- -169
-
-
-
- 0
- 0
- 0
- 200
-
-
-
-
-
- Arandon
- Sigur
-
-
- 60
- 497
-
-
-
- 0
- 450
- 500
- 400
-
-
-
-
- Pirate Light Prescence
- Trader Light Prescence
- Empire Medium Prescence
-
-
- Tau Prime
- Mizar
-
-
- -33
- 220
-
-
- Zabween
-
-
- 0
- 100
- 100
- 600
-
-
-
-
- Empire Patrol Prescence
-
-
- Doeston
- Zylex
- Tormulex
-
-
- -104
- 549
-
-
-
- 0
- 350
- 300
- 400
-
-
-
-
- Pirate Light Prescence
- Empire Patrol Prescence
-
-
- Borla
- NGC-7273
-
-
- -59
- -79
-
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Dvaered Medium Prescence
- Trader Light Prescence
- FLF Light Guerrilla
-
-
- Torg
- Theras
- Tuoladis
- Dakron
-
-
- -296
- 244
-
-
- Nor
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
- Empire Medium Prescence
-
-
- Coriolis
- Delta Pavonis
- Eridani
- Dune
- NGC-7324
-
-
- 33
- 47
-
-
- Darkshed
- Ozogo X
-
-
- 0
- 0
- 0
- 400
-
-
-
-
-
- Myad
- Toros
-
-
- -78
- 636
-
-
-
- 0
- 500
- 500
- 400
-
-
-
-
- Dvaered Medium Prescence
- Trader Light Prescence
- FLF Light Guerrilla
-
-
- Slaccid
- Theras
- Klantar
- Tuoladis
-
-
- -388
- 250
-
-
- Thar
-
-
- 0
- 0
- 0
- 500
-
-
-
-
-
- Arandon
- Zerantix
- Doeston
- Tormulex
-
-
- 8
- 642
-
-
-
- 0
- 650
- 700
- 400
-
-
-
-
- Dvaered Light Prescence
- Trader Light Prescence
- FLF Medium Guerrilla
-
-
- Zacron
- Theras
- Raelid
- Zylex
-
-
- -176
- 360
-
-
-
- 0
- 200
- 150
- 500
-
-
-
-
- Dvaered Medium Prescence
- Trader Light Prescence
- FLF Medium Guerrilla
-
-
- Vlexon
- Torg
- Klantar
- Dakron
-
-
- -328
- 157
-
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Medium Prescence
- Trader Light Prescence
- Empire Light Prescence
-
-
- NGC-7291
- Alteris
- NGC-7273
- NGC-7690
- NGC-7414
-
-
- 40
- -31
-
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Pirate Heavy Prescence
-
-
- NGC-7843
-
-
- 307
- 156
-
-
- New Haven
-
-
- 0
- 300
- 0
- 100
-
-
-
-
-
- Zerantix
- Sol
-
-
- 176
- 751
-
-
-
- 0
- 800
- 800
- 400
-
-
-
-
- Collective Medium Prescence
-
-
- C-00
- C-28
- C-43
-
-
- 52
- -331
-
-
- S49281
-
-
- 0
- 0
- 0
- 100
-
-
-
-
- Dvaered Light Prescence
- Trader Medium Prescence
- FLF Light Guerrilla
-
-
- Dakron
- Slaccid
- Klantar
- Haleb
- Zacron
- Toaxis
-
-
- -266
- 321
-
-
- Cetrat
-
-
- 0
- 50
- 0
- 400
-
-
-
-
-
- Zerantix
- Polaris
- Haered
-
-
- 145
- 682
-
-
-
- 0
- 950
- 900
- 500
-
-
-
-
-
- NGC-7723
-
-
- 264
- 52
-
-
-
- 0
- 50
- 0
- 140
-
-
-
-
- Pirate Light Prescence
- Trader Light Prescence
- Empire Light Prescence
-
-
- Delta Pavonis
- Mizar
- Dune
- Alteris
-
-
- 20
- 131
-
-
- Selphod
-
-
- 0
- 50
- 0
- 500
-
-
-
-
- Collective Medium Prescence
-
-
- C-28
- NGC-7132
- C-43
-
-
- 75
- -214
-
-
- S72839
-
-
- 0
- 0
- 0
- 200
-
-
-
-
- Dvaered Medium Prescence
- Trader Medium Prescence
- FLF Light Guerrilla
-
-
- Slaccid
- Theras
-
-
- -327
- 403
-
-
- Haleb IV
- Jorlan
- Raglan Outpost
-
-
- 0
- 0
- 0
- 400
-
-
-
-
- Empire Light Prescence
- Dvaered Medium Prescence
- Trader Medium Prescence
-
-
- Doranthex
- Torg
- Gamma Polaris
- Tuoladis
-
-
- -262
- 99
-
-
- Vlexair
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Light Prescence
- Trader Medium Prescence
- Empire Medium Prescence
-
-
- Cygnus
- Borla
- Eridani
- NGC-7273
- Alteris
-
-
- -10
- 28
-
-
- Caladan
-
-
- 0
- 0
- 0
- 500
-
-
-
-
- Pirate Light Prescence
- Empire Patrol Prescence
-
-
- Dune
-
-
- 156
- 176
-
-
-
- 0
- 0
- 0
- 100
-
-
-
-
- Dvaered Medium Prescence
- Trader Light Prescence
- FLF Medium Guerrilla
-
-
- Draygar
- Torg
- Raelid
- Theras
- Toaxis
-
-
- -193
- 252
-
-
-
- 0
- 50
- 0
- 500
-
-
-
-
- Pirate Light Prescence
- Trader Heavy Prescence
- Goddard Prescence
- Empire Light Prescence
-
-
- Doranthex
- Borla
- Gamma Polaris
- Shakar
- Cygnus
-
-
- -122
- 24
-
-
- Zhiru
-
-
- 0
- 0
- 0
- 500
-
-
-
diff --git a/dat/start.xml b/dat/start.xml
deleted file mode 100644
index cd6f2c3..0000000
--- a/dat/start.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
- Dark Tides
-
- TestShip
-
- 1000000000000
- 9999999999999999
-
-
- 1300
- 1400
-
-
- Delta Pavonis
- 150
- 150
-
- Tutorial
-
-
diff --git a/dat/unidiff.xml b/dat/unidiff.xml
deleted file mode 100644
index ec7133b..0000000
--- a/dat/unidiff.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
-
- remove
- remove
- remove
- remove
- remove
- remove
- add
- add
-
-
- remove
- remove
- remove
- remove
- add
- add
-
-
- remove
- remove
- remove
- remove
- add
- add
-
-
- remove
- remove
- remove
- remove
- add
- add
-
-
- remove
- remove
- remove
- remove
- add
-
-
- remove
- remove
-
-
- remove
- remove
- remove
- add
-
-
-
diff --git a/docs/Makefile b/docs/Makefile
deleted file mode 100644
index cd5b715..0000000
--- a/docs/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-.PHONY: all lua doxy
-
-all: doxy lua
-
-doxy:
- @echo " DOC docs/doxygen"
- @(cd doxygen; doxygen)
-
-lua:
- @echo " DOC docs/lua"
- @(cd doxygen; sh luadoc.sh)
-
diff --git a/docs/ai/API b/docs/ai/API
deleted file mode 100644
index cdcb9a2..0000000
--- a/docs/ai/API
+++ /dev/null
@@ -1,225 +0,0 @@
-// ================
-// CONSTANTS!
-// ================
-
-number player
- -- players pilot id.
-
-// ================
-// TASKS!
-// ================
-
-pushtask(number pos, string name, int/pointer targer)
- -- Pushes a task onto the queue.
- -- pos : Place task at the beginning if 0, or end if 1.
- -- name : Function name, this is to be defined in the lua file.
- -- target : int or pointer containing target info (for example, could be
- pilot id or a Vec2).
- -- return nil.
-
-poptask()
- -- Pops the current task from the list.
- -- return nil
-
-taskname()
- -- Returns the current task name.
- -- return string name of the current task.
-
-// ================
-// CONSULT!
-// ================
-
-target()
- -- Gets the current target.
- -- return pointer to the target.
-
-targerid()
- -- Gets the current targets id.
- -- return number of the current target id.
-
-rndpilot()
- -- Gets a random target ID
- -- return number of random target id.
-
-dist(Vec2 vect)
- -- Gets the distance from the position of the Vec2 vect.
- -- Vect point to calculate the distance from.
- -- return nil.
-
-pos([number pilot])
- -- Get the pilots position of the current pilots position if no pilot
- is specified.
- -- pilot ID of the pilot to get the position of, if no params are called
- it uses the current pilot as target.
- -- return Vec2
-
-minbrakedist()
- -- Returns the minimum required braking distance assuming all goes well.
- -- return number distance needed to brake.
-
-armour([number pilot])
- -- Returns the total amount of armour left.
-
-shield()
- -- Returns the total amount of shield left.
-
-parmour()
- -- Returns the percentage of armour remaining.
- -- pilot - Optional pilot id, if not the current pilot is used.
-
-pshield()
- -- Returns the percentage of shield remaining.
- -- pilot - Optional pilot id, if not the current pilot is used.
-
-cargofree()
- -- Return amount of free space the pilot has.
-
-// ================
-// BOOLEAN!
-// ================
-
-exists(number id)
- -- Check to see if pilot id is valid.
- -- id -- Pilot to check.
- -- return true if the pilot is valid.
-
-ismaxval()
- -- Check if velocity is maximum.
- -- return true if velocity is max, false otherwise.
-
-isstopped()
- -- Check if we are stopped.
- -- return true if stopped, false otherwise.
-
-isenemy(Pilot pilot)
- -- Check if p is an enemy of current pilot.
- -- p - Pilot to check if enemy.
- -- return true if p is enemy.
-
-isally(Pilot p)
- -- Check if p is an ally of current pilot.
- -- p - Pilot to check if ally.
- -- return true if p is ally.
-
-incombat([number id])
- -- Queries whether a pilot is in combat or not.
- -- id - Pilot to check if is in combat. -- Defaults to self.
- -- return if pilos is in combat or not.
-
-// ================
-// MOVEMENT!
-// ================
-
-accel(number mod)
- -- Accelerates the pilot.
- -- mod float that represents speed to accel to (1. is full speed, 0. is stopped).
- -- return nil.
-
-turn(number mod)
- -- Turns the pilot.
- -- mod float that represents the turning ratio between -1(max right) and 1(max left).
- -- return nil.
-
-face(number/Vec2 target, number invert)
- -- Turn to face the current target.
- -- target pilot ID or Vec2 to face.
- -- invert face away if 1
- -- return number offset from target in grad
-
-brake()
- -- Makes the pilot brake (backthrust).
- -- return nil.
-
-getnearestplanet()
- -- Gets the nearest friendly planet's position.
- -- return position to the nearest friendly planet.
-
-getrndplanet()
- -- Gets the position of a random friendly planet.
- -- return position to a random friendly planet.
-
-// ================
-// COMBAT!
-// ================
-
-combat([number b])
- -- Set pilot as either in combat or out (for comm etc.)
- -- b - if 0 set the pilot to be in combat, if 1 or ommitted sets it to be in combat.
- -- return nil
-
-settarget(number target)
- -- Set the target for the pilot, should be called each frame.
- -- target - Pilot to be targeted.
- -- return nil.
-
-secondary()
- -- Tries to set the best secondary weapon (defaults to launchers).
- -- return the type of secondary weapon set ("None", "Weapon", "Launcher")
-
-shoot([number weapon])
- -- Make the pilot shoot weapons.
- -- weapon to shoot, 1 if primary, 2 if secondary, 3 if both. Defaults to 1.
- -- return nil.
-
-getenemy()
- -- return the id of the nearest enemy or 0 if none is found.
-
-// ================
-// TIMERS!
-// ================
-
-settimer(number t, number delay)
- -- Set timer t to wait for delay ms.
- -- t - Timer to set.
- -- delay - Delay time in ms to wait.
- -- return nil.
-
-timeup(number t)
- -- Return true if time is up for timer t.
- -- t - timer to check.
- -- return boolean true if timer t is up.
-
-// ================
-// MESSAGING!
-// ================
-
-comm(number id, string message)
- -- Make the pilot say something to the pilot of id.
- -- id - of the pilot to speak to.
- -- message - string to output.
- -- return nil
-
-broadcast(string message)
- -- Make the pilot broadcast a message to everyone in the system.
- -- message - string to say to everyone in the system.
- -- return nil
-
-// ================
-// LOOT
-// ================
-
-setcredits(number creds)
- -- Set the pilot's credits. Only works during create.
- -- creds - Pilot's credits.
- -- return nil.
-
-setcargo(string cargo, number quantity)
- -- Give the pilot quantity of cargo, only works during create.
- -- cargo - name of cargo to give the pilot.
- -- quantity - amount to give.
- -- return nil.
-
-shipprice()
- -- Get the price of the pilot's ship.
- -- return the price of the ship.
-
-// ================
-// MISC
-// ================
-
-rng(number low, number high)
- -- Return a random number between low and high.
- -- low - minimum to return.
- -- high - maximum to return
- -- return random number between low and high.
-
diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile
deleted file mode 100644
index 337689d..0000000
--- a/docs/doxygen/Doxyfile
+++ /dev/null
@@ -1,1833 +0,0 @@
-# Doxyfile 1.8.1.2
-
-# This file describes the settings to be used by the documentation system
-# doxygen (www.doxygen.org) for a project
-#
-# All text after a hash (#) is considered a comment and will be ignored
-# The format is:
-# TAG = value [value, ...]
-# For lists items can also be appended using:
-# TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (" ")
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-
-# This tag specifies the encoding used for all characters in the config file
-# that follow. The default is UTF-8 which is also the encoding used for all
-# text before the first occurrence of this tag. Doxygen uses libiconv (or the
-# iconv built into libc) for the transcoding. See
-# http://www.gnu.org/software/libiconv for the list of possible encodings.
-
-DOXYFILE_ENCODING = UTF-8
-
-# The PROJECT_NAME tag is a single word (or sequence of words) that should
-# identify the project. Note that if you do not use Doxywizard you need
-# to put quotes around the project name if it contains spaces.
-
-PROJECT_NAME = Lephisto
-
-# The PROJECT_NUMBER tag can be used to enter a project or revision number.
-# This could be handy for archiving the generated documentation or
-# if some version control system is used.
-
-PROJECT_NUMBER = 0.0.0
-
-# Using the PROJECT_BRIEF tag one can provide an optional one line description
-# for a project that appears at the top of each page and should give viewer
-# a quick idea about the purpose of the project. Keep the description short.
-
-PROJECT_BRIEF = "Lephisto is a 2D action/RPG based around a space trading economy with lots to do."
-
-# With the PROJECT_LOGO tag one can specify an logo or icon that is
-# included in the documentation. The maximum height of the logo should not
-# exceed 55 pixels and the maximum width should not exceed 200 pixels.
-# Doxygen will copy the logo to the output directory.
-
-PROJECT_LOGO = /drv/storage/Images/SaraCraft/Logo/saracraft_logo1.png
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
-# base path where the generated documentation will be put.
-# If a relative path is entered, it will be relative to the location
-# where doxygen was started. If left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = /home/allanis/src/Lephisto/docs/doxygen/docs
-
-# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
-# 4096 sub-directories (in 2 levels) under the output directory of each output
-# format and will distribute the generated files over these directories.
-# Enabling this option can be useful when feeding doxygen a huge amount of
-# source files, where putting all generated files in the same directory would
-# otherwise cause performance problems for the file system.
-
-CREATE_SUBDIRS = NO
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all constant output in the proper language.
-# The default language is English, other supported languages are:
-# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
-# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
-# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
-# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
-# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak,
-# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
-
-OUTPUT_LANGUAGE = English
-
-# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
-# include brief member descriptions after the members that are listed in
-# the file and class documentation (similar to JavaDoc).
-# Set to NO to disable this.
-
-BRIEF_MEMBER_DESC = YES
-
-# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
-# the brief description of a member or function before the detailed description.
-# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-
-REPEAT_BRIEF = YES
-
-# This tag implements a quasi-intelligent brief description abbreviator
-# that is used to form the text in various listings. Each string
-# in this list, if found as the leading text of the brief description, will be
-# stripped from the text and the result after processing the whole list, is
-# used as the annotated text. Otherwise, the brief description is used as-is.
-# If left blank, the following values are used ("$name" is automatically
-# replaced with the name of the entity): "The $name class" "The $name widget"
-# "The $name file" "is" "provides" "specifies" "contains"
-# "represents" "a" "an" "the"
-
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# Doxygen will generate a detailed section even if there is only a brief
-# description.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
-# inherited members of a class in the documentation of that class as if those
-# members were ordinary class members. Constructors, destructors and assignment
-# operators of the base classes will not be shown.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
-# path before files name in the file list and in the header files. If set
-# to NO the shortest path that makes the file name unique will be used.
-
-FULL_PATH_NAMES = YES
-
-# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
-# can be used to strip a user-defined part of the path. Stripping is
-# only done if one of the specified strings matches the left-hand part of
-# the path. The tag can be used to show relative paths in the file list.
-# If left blank the directory from which doxygen is run is used as the
-# path to strip.
-
-STRIP_FROM_PATH =
-
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
-# the path mentioned in the documentation of a class, which tells
-# the reader which header file to include in order to use a class.
-# If left blank only the name of the header file containing the class
-# definition is used. Otherwise one should specify the include paths that
-# are normally passed to the compiler using the -I flag.
-
-STRIP_FROM_INC_PATH =
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
-# (but less readable) file names. This can be useful if your file system
-# doesn't support long names like on DOS, Mac, or CD-ROM.
-
-SHORT_NAMES = NO
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
-# will interpret the first line (until the first dot) of a JavaDoc-style
-# comment as the brief description. If set to NO, the JavaDoc
-# comments will behave just like regular Qt-style comments
-# (thus requiring an explicit @brief command for a brief description.)
-
-JAVADOC_AUTOBRIEF = NO
-
-# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
-# interpret the first line (until the first dot) of a Qt-style
-# comment as the brief description. If set to NO, the comments
-# will behave just like regular Qt-style comments (thus requiring
-# an explicit \brief command for a brief description.)
-
-QT_AUTOBRIEF = NO
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
-# treat a multi-line C++ special comment block (i.e. a block of //! or ///
-# comments) as a brief description. This used to be the default behaviour.
-# The new default is to treat a multi-line C++ comment block as a detailed
-# description. Set this tag to YES if you prefer the old behaviour instead.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
-# member inherits the documentation from any documented member that it
-# re-implements.
-
-INHERIT_DOCS = YES
-
-# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
-# a new page for each member. If set to NO, the documentation of a member will
-# be part of the file/class/namespace that contains it.
-
-SEPARATE_MEMBER_PAGES = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab.
-# Doxygen uses this value to replace tabs by spaces in code fragments.
-
-TAB_SIZE = 8
-
-# This tag can be used to specify a number of aliases that acts
-# as commands in the documentation. An alias has the form "name=value".
-# For example adding "sideeffect=\par Side Effects:\n" will allow you to
-# put the command \sideeffect (or @sideeffect) in the documentation, which
-# will result in a user-defined paragraph with heading "Side Effects:".
-# You can put \n's in the value part of an alias to insert newlines.
-
-ALIASES = "luamod=Lua module: "
-ALIASES += "luafunc=@param L Lua State \
- @return Number of variables on the Lua State stack.\n\
-
Lua function: "
-ALIASES += "luaparam=Lua function parameter: "
-ALIASES += "luareturn=Lua return parameter: "
-
-# This tag can be used to specify a number of word-keyword mappings (TCL only).
-# A mapping has the form "name=value". For example adding
-# "class=itcl::class" will allow you to use the command class in the
-# itcl::class meaning.
-
-TCL_SUBST =
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
-# sources only. Doxygen will then generate output that is more tailored for C.
-# For instance, some of the names that are used will be different. The list
-# of all members will be omitted, etc.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
-# sources only. Doxygen will then generate output that is more tailored for
-# Java. For instance, namespaces will be presented as packages, qualified
-# scopes will look different, etc.
-
-OPTIMIZE_OUTPUT_JAVA = NO
-
-# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
-# sources only. Doxygen will then generate output that is more tailored for
-# Fortran.
-
-OPTIMIZE_FOR_FORTRAN = NO
-
-# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
-# sources. Doxygen will then generate output that is tailored for
-# VHDL.
-
-OPTIMIZE_OUTPUT_VHDL = NO
-
-# Doxygen selects the parser to use depending on the extension of the files it
-# parses. With this tag you can assign which parser to use for a given extension.
-# Doxygen has a built-in mapping, but you can override or extend it using this
-# tag. The format is ext=language, where ext is a file extension, and language
-# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C,
-# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make
-# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C
-# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions
-# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen.
-
-EXTENSION_MAPPING =
-
-# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all
-# comments according to the Markdown format, which allows for more readable
-# documentation. See http://daringfireball.net/projects/markdown/ for details.
-# The output of markdown processing is further processed by doxygen, so you
-# can mix doxygen, HTML, and XML commands with Markdown formatting.
-# Disable only in case of backward compatibilities issues.
-
-MARKDOWN_SUPPORT = YES
-
-# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
-# to include (a tag file for) the STL sources as input, then you should
-# set this tag to YES in order to let doxygen match functions declarations and
-# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
-# func(std::string) {}). This also makes the inheritance and collaboration
-# diagrams that involve STL classes more complete and accurate.
-
-BUILTIN_STL_SUPPORT = NO
-
-# If you use Microsoft's C++/CLI language, you should set this option to YES to
-# enable parsing support.
-
-CPP_CLI_SUPPORT = NO
-
-# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
-# Doxygen will parse them like normal C++ but will assume all classes use public
-# instead of private inheritance when no explicit protection keyword is present.
-
-SIP_SUPPORT = NO
-
-# For Microsoft's IDL there are propget and propput attributes to indicate getter
-# and setter methods for a property. Setting this option to YES (the default)
-# will make doxygen replace the get and set methods by a property in the
-# documentation. This will only work if the methods are indeed getting or
-# setting a simple type. If this is not the case, or you want to show the
-# methods anyway, you should set this option to NO.
-
-IDL_PROPERTY_SUPPORT = NO
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
-# the same type (for instance a group of public functions) to be put as a
-# subgroup of that type (e.g. under the Public Functions section). Set it to
-# NO to prevent subgrouping. Alternatively, this can be done per class using
-# the \nosubgrouping command.
-
-SUBGROUPING = YES
-
-# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and
-# unions are shown inside the group in which they are included (e.g. using
-# @ingroup) instead of on a separate page (for HTML and Man pages) or
-# section (for LaTeX and RTF).
-
-INLINE_GROUPED_CLASSES = NO
-
-# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and
-# unions with only public data fields will be shown inline in the documentation
-# of the scope in which they are defined (i.e. file, namespace, or group
-# documentation), provided this scope is documented. If set to NO (the default),
-# structs, classes, and unions are shown on a separate page (for HTML and Man
-# pages) or section (for LaTeX and RTF).
-
-INLINE_SIMPLE_STRUCTS = NO
-
-# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
-# is documented as struct, union, or enum with the name of the typedef. So
-# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
-# with name TypeT. When disabled the typedef will appear as a member of a file,
-# namespace, or class. And the struct will be named TypeS. This can typically
-# be useful for C code in case the coding convention dictates that all compound
-# types are typedef'ed and only the typedef is referenced, never the tag name.
-
-TYPEDEF_HIDES_STRUCT = NO
-
-# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
-# determine which symbols to keep in memory and which to flush to disk.
-# When the cache is full, less often used symbols will be written to disk.
-# For small to medium size projects (<1000 input files) the default value is
-# probably good enough. For larger projects a too small cache size can cause
-# doxygen to be busy swapping symbols to and from disk most of the time
-# causing a significant performance penalty.
-# If the system has enough physical memory increasing the cache will improve the
-# performance by keeping more symbols in memory. Note that the value works on
-# a logarithmic scale so increasing the size by one will roughly double the
-# memory usage. The cache size is given by this formula:
-# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
-# corresponding to a cache size of 2^16 = 65536 symbols.
-
-SYMBOL_CACHE_SIZE = 0
-
-# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be
-# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given
-# their name and scope. Since this can be an expensive process and often the
-# same symbol appear multiple times in the code, doxygen keeps a cache of
-# pre-resolved symbols. If the cache is too small doxygen will become slower.
-# If the cache is too large, memory is wasted. The cache size is given by this
-# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0,
-# corresponding to a cache size of 2^16 = 65536 symbols.
-
-LOOKUP_CACHE_SIZE = 0
-
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
-# documentation are documented, even if no documentation was available.
-# Private class members and static file members will be hidden unless
-# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
-
-EXTRACT_ALL = YES
-
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
-# will be included in the documentation.
-
-EXTRACT_PRIVATE = NO
-
-# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal
-# scope will be included in the documentation.
-
-EXTRACT_PACKAGE = NO
-
-# If the EXTRACT_STATIC tag is set to YES all static members of a file
-# will be included in the documentation.
-
-EXTRACT_STATIC = NO
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
-# defined locally in source files will be included in the documentation.
-# If set to NO only classes defined in header files are included.
-
-EXTRACT_LOCAL_CLASSES = YES
-
-# This flag is only useful for Objective-C code. When set to YES local
-# methods, which are defined in the implementation section but not in
-# the interface are included in the documentation.
-# If set to NO (the default) only methods in the interface are included.
-
-EXTRACT_LOCAL_METHODS = NO
-
-# If this flag is set to YES, the members of anonymous namespaces will be
-# extracted and appear in the documentation as a namespace called
-# 'anonymous_namespace{file}', where file will be replaced with the base
-# name of the file that contains the anonymous namespace. By default
-# anonymous namespaces are hidden.
-
-EXTRACT_ANON_NSPACES = NO
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
-# undocumented members of documented classes, files or namespaces.
-# If set to NO (the default) these members will be included in the
-# various overviews, but no documentation section is generated.
-# This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy.
-# If set to NO (the default) these classes will be included in the various
-# overviews. This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_CLASSES = NO
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
-# friend (class|struct|union) declarations.
-# If set to NO (the default) these declarations will be included in the
-# documentation.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
-# documentation blocks found inside the body of a function.
-# If set to NO (the default) these blocks will be appended to the
-# function's detailed documentation block.
-
-HIDE_IN_BODY_DOCS = NO
-
-# The INTERNAL_DOCS tag determines if documentation
-# that is typed after a \internal command is included. If the tag is set
-# to NO (the default) then the documentation will be excluded.
-# Set it to YES to include the internal documentation.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
-# file names in lower-case letters. If set to YES upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
-
-CASE_SENSE_NAMES = NO
-
-# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
-# will show members with their full class and namespace scopes in the
-# documentation. If set to YES the scope will be hidden.
-
-HIDE_SCOPE_NAMES = YES
-
-# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
-# will put a list of the files that are included by a file in the documentation
-# of that file.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
-# will list include files with double quotes in the documentation
-# rather than with sharp brackets.
-
-FORCE_LOCAL_INCLUDES = NO
-
-# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
-# is inserted in the documentation for inline members.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
-# will sort the (detailed) documentation of file and class members
-# alphabetically by member name. If set to NO the members will appear in
-# declaration order.
-
-SORT_MEMBER_DOCS = YES
-
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
-# brief documentation of file, namespace and class members alphabetically
-# by member name. If set to NO (the default) the members will appear in
-# declaration order.
-
-SORT_BRIEF_DOCS = NO
-
-# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
-# will sort the (brief and detailed) documentation of class members so that
-# constructors and destructors are listed first. If set to NO (the default)
-# the constructors will appear in the respective orders defined by
-# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
-# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
-# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
-
-SORT_MEMBERS_CTORS_1ST = NO
-
-# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
-# hierarchy of group names into alphabetical order. If set to NO (the default)
-# the group names will appear in their defined order.
-
-SORT_GROUP_NAMES = NO
-
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
-# sorted by fully-qualified names, including namespaces. If set to
-# NO (the default), the class list will be sorted only by class name,
-# not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the
-# alphabetical list.
-
-SORT_BY_SCOPE_NAME = NO
-
-# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to
-# do proper type resolution of all parameters of a function it will reject a
-# match between the prototype and the implementation of a member function even
-# if there is only one candidate or it is obvious which candidate to choose
-# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen
-# will still accept a match between prototype and implementation in such cases.
-
-STRICT_PROTO_MATCHING = NO
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or
-# disable (NO) the todo list. This list is created by putting \todo
-# commands in the documentation.
-
-GENERATE_TODOLIST = YES
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or
-# disable (NO) the test list. This list is created by putting \test
-# commands in the documentation.
-
-GENERATE_TESTLIST = YES
-
-# The GENERATE_BUGLIST tag can be used to enable (YES) or
-# disable (NO) the bug list. This list is created by putting \bug
-# commands in the documentation.
-
-GENERATE_BUGLIST = YES
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
-# disable (NO) the deprecated list. This list is created by putting
-# \deprecated commands in the documentation.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# The ENABLED_SECTIONS tag can be used to enable conditional
-# documentation sections, marked by \if sectionname ... \endif.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
-# the initial value of a variable or macro consists of for it to appear in
-# the documentation. If the initializer consists of more lines than specified
-# here it will be hidden. Use a value of 0 to hide initializers completely.
-# The appearance of the initializer of individual variables and macros in the
-# documentation can be controlled using \showinitializer or \hideinitializer
-# command in the documentation regardless of this setting.
-
-MAX_INITIALIZER_LINES = 30
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
-# at the bottom of the documentation of classes and structs. If set to YES the
-# list will mention the files that were used to generate the documentation.
-
-SHOW_USED_FILES = YES
-
-# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
-# This will remove the Files entry from the Quick Index and from the
-# Folder Tree View (if specified). The default is YES.
-
-SHOW_FILES = YES
-
-# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
-# Namespaces page. This will remove the Namespaces entry from the Quick Index
-# and from the Folder Tree View (if specified). The default is YES.
-
-SHOW_NAMESPACES = YES
-
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from
-# the version control system). Doxygen will invoke the program by executing (via
-# popen()) the command , where is the value of
-# the FILE_VERSION_FILTER tag, and is the name of an input file
-# provided by doxygen. Whatever the program writes to standard output
-# is used as the file version. See the manual for examples.
-
-FILE_VERSION_FILTER =
-
-# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
-# by doxygen. The layout file controls the global structure of the generated
-# output files in an output format independent way. To create the layout file
-# that represents doxygen's defaults, run doxygen with the -l option.
-# You can optionally specify a file name after the option, if omitted
-# DoxygenLayout.xml will be used as the name of the layout file.
-
-LAYOUT_FILE =
-
-# The CITE_BIB_FILES tag can be used to specify one or more bib files
-# containing the references data. This must be a list of .bib files. The
-# .bib extension is automatically appended if omitted. Using this command
-# requires the bibtex tool to be installed. See also
-# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style
-# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this
-# feature you need bibtex and perl available in the search path.
-
-CITE_BIB_FILES =
-
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated
-# by doxygen. Possible values are YES and NO. If left blank NO is used.
-
-QUIET = YES
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated by doxygen. Possible values are YES and NO. If left blank
-# NO is used.
-
-WARNINGS = YES
-
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
-# automatically be disabled.
-
-WARN_IF_UNDOCUMENTED = YES
-
-# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some
-# parameters in a documented function, or documenting parameters that
-# don't exist or using markup commands wrongly.
-
-WARN_IF_DOC_ERROR = YES
-
-# The WARN_NO_PARAMDOC option can be enabled to get warnings for
-# functions that are documented, but have no documentation for their parameters
-# or return value. If set to NO (the default) doxygen will only warn about
-# wrong or incomplete parameter documentation, but not about the absence of
-# documentation.
-
-WARN_NO_PARAMDOC = NO
-
-# The WARN_FORMAT tag determines the format of the warning messages that
-# doxygen can produce. The string should contain the $file, $line, and $text
-# tags, which will be replaced by the file and line number from which the
-# warning originated and the warning text. Optionally the format may contain
-# $version, which will be replaced by the version of the file (if it could
-# be obtained via FILE_VERSION_FILTER)
-
-WARN_FORMAT = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning
-# and error messages should be written. If left blank the output is written
-# to stderr.
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag can be used to specify the files and/or directories that contain
-# documented source files. You may enter file names like "myfile.cpp" or
-# directories like "/usr/src/myproject". Separate the files or directories
-# with spaces.
-
-INPUT = /home/allanis/src/Lephisto
-
-# This tag can be used to specify the character encoding of the source files
-# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
-# also the default input encoding. Doxygen uses libiconv (or the iconv built
-# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
-# the list of possible encodings.
-
-INPUT_ENCODING = UTF-8
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank the following patterns are tested:
-# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh
-# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py
-# *.f90 *.f *.for *.vhd *.vhdl
-
-FILE_PATTERNS = *.c \
- *.cc \
- *.cxx \
- *.cpp \
- *.c++ \
- *.d \
- *.java \
- *.ii \
- *.ixx \
- *.ipp \
- *.i++ \
- *.inl \
- *.h \
- *.hh \
- *.hxx \
- *.hpp \
- *.h++ \
- *.idl \
- *.odl \
- *.cs \
- *.php \
- *.php3 \
- *.inc \
- *.m \
- *.markdown \
- *.md \
- *.mm \
- *.dox \
- *.py \
- *.f90 \
- *.f \
- *.for \
- *.vhd \
- *.vhdl \
- *.vhdl \
- *.lua
-
-# The RECURSIVE tag can be used to turn specify whether or not subdirectories
-# should be searched for input files as well. Possible values are YES and NO.
-# If left blank NO is used.
-
-RECURSIVE = YES
-
-# The EXCLUDE tag can be used to specify files and/or directories that should be
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-# Note that relative paths are relative to the directory from which doxygen is
-# run.
-
-EXCLUDE =
-
-# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
-# directories that are symbolic links (a Unix file system feature) are excluded
-# from the input.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories. Note that the wildcards are matched
-# against the file with absolute path, so to exclude all test directories
-# for example use the pattern */test/*
-
-EXCLUDE_PATTERNS =
-
-# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
-# (namespaces, classes, functions, etc.) that should be excluded from the
-# output. The symbol name can be a fully qualified name, a word, or if the
-# wildcard * is used, a substring. Examples: ANamespace, AClass,
-# AClass::ANamespace, ANamespace::*Test
-
-EXCLUDE_SYMBOLS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or
-# directories that contain example code fragments that are included (see
-# the \include command).
-
-EXAMPLE_PATH =
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank all files are included.
-
-EXAMPLE_PATTERNS = *
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude
-# commands irrespective of the value of the RECURSIVE tag.
-# Possible values are YES and NO. If left blank NO is used.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or
-# directories that contain image that are included in the documentation (see
-# the \image command).
-
-IMAGE_PATH =
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command , where
-# is the value of the INPUT_FILTER tag, and is the name of an
-# input file. Doxygen will then use the output that the filter program writes
-# to standard output. If FILTER_PATTERNS is specified, this tag will be
-# ignored.
-
-INPUT_FILTER =
-
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
-# basis. Doxygen will compare the file name with each pattern and apply the
-# filter if there is a match. The filters are a list of the form:
-# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
-# info on how filters are used. If FILTER_PATTERNS is empty or if
-# non of the patterns match the file name, INPUT_FILTER is applied.
-
-FILTER_PATTERNS =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER) will be used to filter the input files when producing source
-# files to browse (i.e. when SOURCE_BROWSER is set to YES).
-
-FILTER_SOURCE_FILES = NO
-
-# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
-# pattern. A pattern will override the setting for FILTER_PATTERN (if any)
-# and it is also possible to disable source filtering for a specific pattern
-# using *.ext= (so without naming a filter). This option only has effect when
-# FILTER_SOURCE_FILES is enabled.
-
-FILTER_SOURCE_PATTERNS =
-
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will
-# be generated. Documented entities will be cross-referenced with these sources.
-# Note: To get rid of all source code in the generated output, make sure also
-# VERBATIM_HEADERS is set to NO.
-
-SOURCE_BROWSER = YES
-
-# Setting the INLINE_SOURCES tag to YES will include the body
-# of functions and classes directly in the documentation.
-
-INLINE_SOURCES = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
-# doxygen to hide any special comment blocks from generated source code
-# fragments. Normal C, C++ and Fortran comments will always remain visible.
-
-STRIP_CODE_COMMENTS = YES
-
-# If the REFERENCED_BY_RELATION tag is set to YES
-# then for each documented function all documented
-# functions referencing it will be listed.
-
-REFERENCED_BY_RELATION = NO
-
-# If the REFERENCES_RELATION tag is set to YES
-# then for each documented function all documented entities
-# called/used by that function will be listed.
-
-REFERENCES_RELATION = NO
-
-# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
-# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
-# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
-# link to the source code. Otherwise they will link to the documentation.
-
-REFERENCES_LINK_SOURCE = YES
-
-# If the USE_HTAGS tag is set to YES then the references to source code
-# will point to the HTML generated by the htags(1) tool instead of doxygen
-# built-in source browser. The htags tool is part of GNU's global source
-# tagging system (see http://www.gnu.org/software/global/global.html). You
-# will need version 4.8.6 or higher.
-
-USE_HTAGS = NO
-
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
-# will generate a verbatim copy of the header file for each class for
-# which an include is specified. Set to NO to disable this.
-
-VERBATIM_HEADERS = YES
-
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
-# of all compounds will be generated. Enable this if the project
-# contains a lot of classes, structs, unions or interfaces.
-
-ALPHABETICAL_INDEX = YES
-
-# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
-# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
-# in which this list will be split (can be a number in the range [1..20])
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all
-# classes will be put under the same header in the alphabetical index.
-# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
-# should be ignored while generating the index headers.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
-# generate HTML output.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `html' will be used as the default path.
-
-HTML_OUTPUT = html
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
-# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
-# doxygen will generate files with .html extension.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a personal HTML header for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard header. Note that when using a custom header you are responsible
-# for the proper inclusion of any scripts and style sheets that doxygen
-# needs, which is dependent on the configuration options used.
-# It is advised to generate a default header using "doxygen -w html
-# header.html footer.html stylesheet.css YourConfigFile" and then modify
-# that header. Note that the header is subject to change so you typically
-# have to redo this when upgrading to a newer version of doxygen or when
-# changing the value of configuration settings such as GENERATE_TREEVIEW!
-
-HTML_HEADER =
-
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard footer.
-
-HTML_FOOTER =
-
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
-# style sheet that is used by each HTML page. It can be used to
-# fine-tune the look of the HTML output. If the tag is left blank doxygen
-# will generate a default style sheet. Note that doxygen will try to copy
-# the style sheet file to the HTML output directory, so don't put your own
-# style sheet in the HTML output directory as well, or it will be erased!
-
-HTML_STYLESHEET =
-
-# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the HTML output directory. Note
-# that these files will be copied to the base HTML output directory. Use the
-# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
-# files. In the HTML_STYLESHEET file, use the file name only. Also note that
-# the files will be copied as-is; there are no commands or markers available.
-
-HTML_EXTRA_FILES =
-
-# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
-# Doxygen will adjust the colors in the style sheet and background images
-# according to this color. Hue is specified as an angle on a colorwheel,
-# see http://en.wikipedia.org/wiki/Hue for more information.
-# For instance the value 0 represents red, 60 is yellow, 120 is green,
-# 180 is cyan, 240 is blue, 300 purple, and 360 is red again.
-# The allowed range is 0 to 359.
-
-HTML_COLORSTYLE_HUE = 192
-
-# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of
-# the colors in the HTML output. For a value of 0 the output will use
-# grayscales only. A value of 255 will produce the most vivid colors.
-
-HTML_COLORSTYLE_SAT = 122
-
-# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to
-# the luminance component of the colors in the HTML output. Values below
-# 100 gradually make the output lighter, whereas values above 100 make
-# the output darker. The value divided by 100 is the actual gamma applied,
-# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2,
-# and 100 does not change the gamma.
-
-HTML_COLORSTYLE_GAMMA = 83
-
-# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
-# page will contain the date and time when the page was generated. Setting
-# this to NO can help when comparing the output of multiple runs.
-
-HTML_TIMESTAMP = YES
-
-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
-# documentation will contain sections that can be hidden and shown after the
-# page has loaded.
-
-HTML_DYNAMIC_SECTIONS = NO
-
-# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of
-# entries shown in the various tree structured indices initially; the user
-# can expand and collapse entries dynamically later on. Doxygen will expand
-# the tree to such a level that at most the specified number of entries are
-# visible (unless a fully collapsed tree already exceeds this amount).
-# So setting the number of entries 1 will produce a full collapsed tree by
-# default. 0 is a special value representing an infinite number of entries
-# and will result in a full expanded tree by default.
-
-HTML_INDEX_NUM_ENTRIES = 100
-
-# If the GENERATE_DOCSET tag is set to YES, additional index files
-# will be generated that can be used as input for Apple's Xcode 3
-# integrated development environment, introduced with OSX 10.5 (Leopard).
-# To create a documentation set, doxygen will generate a Makefile in the
-# HTML output directory. Running make will produce the docset in that
-# directory and running "make install" will install the docset in
-# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
-# it at startup.
-# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
-# for more information.
-
-GENERATE_DOCSET = NO
-
-# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
-# feed. A documentation feed provides an umbrella under which multiple
-# documentation sets from a single provider (such as a company or product suite)
-# can be grouped.
-
-DOCSET_FEEDNAME = "Doxygen generated docs"
-
-# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
-# should uniquely identify the documentation set bundle. This should be a
-# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
-# will append .docset to the name.
-
-DOCSET_BUNDLE_ID = org.doxygen.Project
-
-# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify
-# the documentation publisher. This should be a reverse domain-name style
-# string, e.g. com.mycompany.MyDocSet.documentation.
-
-DOCSET_PUBLISHER_ID = org.doxygen.Publisher
-
-# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher.
-
-DOCSET_PUBLISHER_NAME = Publisher
-
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files
-# will be generated that can be used as input for tools like the
-# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
-# of the generated HTML documentation.
-
-GENERATE_HTMLHELP = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
-# be used to specify the file name of the resulting .chm file. You
-# can add a path in front of the file if the result should not be
-# written to the html output directory.
-
-CHM_FILE =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
-# be used to specify the location (absolute path including file name) of
-# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
-# the HTML help compiler on the generated index.hhp.
-
-HHC_LOCATION =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
-# controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
-
-GENERATE_CHI = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
-# is used to encode HtmlHelp index (hhk), content (hhc) and project file
-# content.
-
-CHM_INDEX_ENCODING =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
-# controls whether a binary table of contents is generated (YES) or a
-# normal table of contents (NO) in the .chm file.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members
-# to the contents of the HTML help documentation and to the tree view.
-
-TOC_EXPAND = NO
-
-# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
-# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated
-# that can be used as input for Qt's qhelpgenerator to generate a
-# Qt Compressed Help (.qch) of the generated HTML documentation.
-
-GENERATE_QHP = NO
-
-# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
-# be used to specify the file name of the resulting .qch file.
-# The path specified is relative to the HTML output folder.
-
-QCH_FILE =
-
-# The QHP_NAMESPACE tag specifies the namespace to use when generating
-# Qt Help Project output. For more information please see
-# http://doc.trolltech.com/qthelpproject.html#namespace
-
-QHP_NAMESPACE = org.doxygen.Project
-
-# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
-# Qt Help Project output. For more information please see
-# http://doc.trolltech.com/qthelpproject.html#virtual-folders
-
-QHP_VIRTUAL_FOLDER = doc
-
-# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to
-# add. For more information please see
-# http://doc.trolltech.com/qthelpproject.html#custom-filters
-
-QHP_CUST_FILTER_NAME =
-
-# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the
-# custom filter to add. For more information please see
-#
-# Qt Help Project / Custom Filters .
-
-QHP_CUST_FILTER_ATTRS =
-
-# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
-# project's
-# filter section matches.
-#
-# Qt Help Project / Filter Attributes .
-
-QHP_SECT_FILTER_ATTRS =
-
-# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
-# be used to specify the location of Qt's qhelpgenerator.
-# If non-empty doxygen will try to run qhelpgenerator on the generated
-# .qhp file.
-
-QHG_LOCATION =
-
-# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
-# will be generated, which together with the HTML files, form an Eclipse help
-# plugin. To install this plugin and make it available under the help contents
-# menu in Eclipse, the contents of the directory containing the HTML and XML
-# files needs to be copied into the plugins directory of eclipse. The name of
-# the directory within the plugins directory should be the same as
-# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
-# the help appears.
-
-GENERATE_ECLIPSEHELP = NO
-
-# A unique identifier for the eclipse help plugin. When installing the plugin
-# the directory name containing the HTML and XML files should also have
-# this name.
-
-ECLIPSE_DOC_ID = org.doxygen.Project
-
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs)
-# at top of each HTML page. The value NO (the default) enables the index and
-# the value YES disables it. Since the tabs have the same information as the
-# navigation tree you can set this option to NO if you already set
-# GENERATE_TREEVIEW to YES.
-
-DISABLE_INDEX = NO
-
-# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
-# structure should be generated to display hierarchical information.
-# If the tag value is set to YES, a side panel will be generated
-# containing a tree-like index structure (just like the one that
-# is generated for HTML Help). For this to work a browser that supports
-# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
-# Windows users are probably better off using the HTML help feature.
-# Since the tree basically has the same information as the tab index you
-# could consider to set DISABLE_INDEX to NO when enabling this option.
-
-GENERATE_TREEVIEW = YES
-
-# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values
-# (range [0,1..20]) that doxygen will group on one line in the generated HTML
-# documentation. Note that a value of 0 will completely suppress the enum
-# values from appearing in the overview section.
-
-ENUM_VALUES_PER_LINE = 4
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
-# used to set the initial width (in pixels) of the frame in which the tree
-# is shown.
-
-TREEVIEW_WIDTH = 250
-
-# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open
-# links to external symbols imported via tag files in a separate window.
-
-EXT_LINKS_IN_WINDOW = NO
-
-# Use this tag to change the font size of Latex formulas included
-# as images in the HTML documentation. The default is 10. Note that
-# when you change the font size after a successful doxygen run you need
-# to manually remove any form_*.png images from the HTML output directory
-# to force them to be regenerated.
-
-FORMULA_FONTSIZE = 10
-
-# Use the FORMULA_TRANPARENT tag to determine whether or not the images
-# generated for formulas are transparent PNGs. Transparent PNGs are
-# not supported properly for IE 6.0, but are supported on all modern browsers.
-# Note that when changing this option you need to delete any form_*.png files
-# in the HTML output before the changes have effect.
-
-FORMULA_TRANSPARENT = YES
-
-# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax
-# (see http://www.mathjax.org) which uses client side Javascript for the
-# rendering instead of using prerendered bitmaps. Use this if you do not
-# have LaTeX installed or if you want to formulas look prettier in the HTML
-# output. When enabled you may also need to install MathJax separately and
-# configure the path to it using the MATHJAX_RELPATH option.
-
-USE_MATHJAX = NO
-
-# When MathJax is enabled you need to specify the location relative to the
-# HTML output directory using the MATHJAX_RELPATH option. The destination
-# directory should contain the MathJax.js script. For instance, if the mathjax
-# directory is located at the same level as the HTML output directory, then
-# MATHJAX_RELPATH should be ../mathjax. The default value points to
-# the MathJax Content Delivery Network so you can quickly see the result without
-# installing MathJax. However, it is strongly recommended to install a local
-# copy of MathJax from http://www.mathjax.org before deployment.
-
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
-
-# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension
-# names that should be enabled during MathJax rendering.
-
-MATHJAX_EXTENSIONS =
-
-# When the SEARCHENGINE tag is enabled doxygen will generate a search box
-# for the HTML output. The underlying search engine uses javascript
-# and DHTML and should work on any modern browser. Note that when using
-# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
-# (GENERATE_DOCSET) there is already a search function so this one should
-# typically be disabled. For large projects the javascript based search engine
-# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
-
-SEARCHENGINE = YES
-
-# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
-# implemented using a PHP enabled web server instead of at the web client
-# using Javascript. Doxygen will generate the search PHP script and index
-# file to put on the web server. The advantage of the server
-# based approach is that it scales better to large projects and allows
-# full text search. The disadvantages are that it is more difficult to setup
-# and does not have live searching capabilities.
-
-SERVER_BASED_SEARCH = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
-# generate Latex output.
-
-GENERATE_LATEX = YES
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `latex' will be used as the default path.
-
-LATEX_OUTPUT = latex
-
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
-# invoked. If left blank `latex' will be used as the default command name.
-# Note that when enabling USE_PDFLATEX this option is only used for
-# generating bitmaps for formulas in the HTML output, but not in the
-# Makefile that is written to the output directory.
-
-LATEX_CMD_NAME = latex
-
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
-# generate index for LaTeX. If left blank `makeindex' will be used as the
-# default command name.
-
-MAKEINDEX_CMD_NAME = makeindex
-
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
-# LaTeX documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_LATEX = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used
-# by the printer. Possible values are: a4, letter, legal and
-# executive. If left blank a4wide will be used.
-
-PAPER_TYPE = a4
-
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
-# packages that should be included in the LaTeX output.
-
-EXTRA_PACKAGES =
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
-# the generated latex document. The header should contain everything until
-# the first chapter. If it is left blank doxygen will generate a
-# standard header. Notice: only use this tag if you know what you are doing!
-
-LATEX_HEADER =
-
-# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for
-# the generated latex document. The footer should contain everything after
-# the last chapter. If it is left blank doxygen will generate a
-# standard footer. Notice: only use this tag if you know what you are doing!
-
-LATEX_FOOTER =
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will
-# contain links (just like the HTML output) instead of page references
-# This makes the output suitable for online browsing using a pdf viewer.
-
-PDF_HYPERLINKS = YES
-
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
-# plain latex in the generated Makefile. Set this option to YES to get a
-# higher quality PDF documentation.
-
-USE_PDFLATEX = YES
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
-# command to the generated LaTeX files. This will instruct LaTeX to keep
-# running if errors occur, instead of asking the user for help.
-# This option is also used when generating formulas in HTML.
-
-LATEX_BATCHMODE = NO
-
-# If LATEX_HIDE_INDICES is set to YES then doxygen will not
-# include the index chapters (such as File Index, Compound Index, etc.)
-# in the output.
-
-LATEX_HIDE_INDICES = NO
-
-# If LATEX_SOURCE_CODE is set to YES then doxygen will include
-# source code with syntax highlighting in the LaTeX output.
-# Note that which sources are shown also depends on other settings
-# such as SOURCE_BROWSER.
-
-LATEX_SOURCE_CODE = NO
-
-# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
-# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See
-# http://en.wikipedia.org/wiki/BibTeX for more info.
-
-LATEX_BIB_STYLE = plain
-
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
-# The RTF output is optimized for Word 97 and may not look very pretty with
-# other RTF readers or editors.
-
-GENERATE_RTF = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `rtf' will be used as the default path.
-
-RTF_OUTPUT = rtf
-
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
-# RTF documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_RTF = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
-# will contain hyperlink fields. The RTF file will
-# contain links (just like the HTML output) instead of page references.
-# This makes the output suitable for online browsing using WORD or other
-# programs which support those fields.
-# Note: wordpad (write) and others do not support links.
-
-RTF_HYPERLINKS = NO
-
-# Load style sheet definitions from file. Syntax is similar to doxygen's
-# config file, i.e. a series of assignments. You only have to provide
-# replacements, missing definitions are set to their default value.
-
-RTF_STYLESHEET_FILE =
-
-# Set optional variables used in the generation of an rtf document.
-# Syntax is similar to doxygen's config file.
-
-RTF_EXTENSIONS_FILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
-# generate man pages
-
-GENERATE_MAN = NO
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `man' will be used as the default path.
-
-MAN_OUTPUT = man
-
-# The MAN_EXTENSION tag determines the extension that is added to
-# the generated man pages (default is the subroutine's section .3)
-
-MAN_EXTENSION = .3
-
-# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
-# then it will generate one additional man file for each entity
-# documented in the real man page(s). These additional files
-# only source the real man page, but without them the man command
-# would be unable to find the correct page. The default is NO.
-
-MAN_LINKS = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES Doxygen will
-# generate an XML file that captures the structure of
-# the code including all documentation.
-
-GENERATE_XML = NO
-
-# The XML_OUTPUT tag is used to specify where the XML pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `xml' will be used as the default path.
-
-XML_OUTPUT = xml
-
-# The XML_SCHEMA tag can be used to specify an XML schema,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_SCHEMA =
-
-# The XML_DTD tag can be used to specify an XML DTD,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_DTD =
-
-# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
-# dump the program listings (including syntax highlighting
-# and cross-referencing information) to the XML output. Note that
-# enabling this will significantly increase the size of the XML output.
-
-XML_PROGRAMLISTING = YES
-
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
-# generate an AutoGen Definitions (see autogen.sf.net) file
-# that captures the structure of the code including all
-# documentation. Note that this feature is still experimental
-# and incomplete at the moment.
-
-GENERATE_AUTOGEN_DEF = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_PERLMOD tag is set to YES Doxygen will
-# generate a Perl module file that captures the structure of
-# the code including all documentation. Note that this
-# feature is still experimental and incomplete at the
-# moment.
-
-GENERATE_PERLMOD = NO
-
-# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
-# the necessary Makefile rules, Perl scripts and LaTeX code to be able
-# to generate PDF and DVI output from the Perl module output.
-
-PERLMOD_LATEX = NO
-
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
-# nicely formatted so it can be parsed by a human reader. This is useful
-# if you want to understand what is going on. On the other hand, if this
-# tag is set to NO the size of the Perl module output will be much smaller
-# and Perl will parse it just the same.
-
-PERLMOD_PRETTY = YES
-
-# The names of the make variables in the generated doxyrules.make file
-# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
-# This is useful so different doxyrules.make files included by the same
-# Makefile don't overwrite each other's variables.
-
-PERLMOD_MAKEVAR_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
-# evaluate all C-preprocessor directives found in the sources and include
-# files.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
-# names in the source code. If set to NO (the default) only conditional
-# compilation will be performed. Macro expansion can be done in a controlled
-# way by setting EXPAND_ONLY_PREDEF to YES.
-
-MACRO_EXPANSION = NO
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
-# then the macro expansion is limited to the macros specified with the
-# PREDEFINED and EXPAND_AS_DEFINED tags.
-
-EXPAND_ONLY_PREDEF = NO
-
-# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
-# pointed to by INCLUDE_PATH will be searched when a #include is found.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by
-# the preprocessor.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will
-# be used.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that
-# are defined before the preprocessor is started (similar to the -D option of
-# gcc). The argument of the tag is a list of macros of the form: name
-# or name=definition (no spaces). If the definition and the = are
-# omitted =1 is assumed. To prevent a macro definition from being
-# undefined via #undef or recursively expanded use the := operator
-# instead of the = operator.
-
-PREDEFINED =
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
-# this tag can be used to specify a list of macro names that should be expanded.
-# The macro definition that is found in the sources will be used.
-# Use the PREDEFINED tag if you want to use a different macro definition that
-# overrules the definition found in the source code.
-
-EXPAND_AS_DEFINED =
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
-# doxygen's preprocessor will remove all references to function-like macros
-# that are alone on a line, have an all uppercase name, and do not end with a
-# semicolon, because these will confuse the parser if not removed.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES option can be used to specify one or more tagfiles. For each
-# tag file the location of the external documentation should be added. The
-# format of a tag file without this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where "loc1" and "loc2" can be relative or absolute paths
-# or URLs. Note that each tag file must have a unique name (where the name does
-# NOT include the path). If a tag file is not located in the directory in which
-# doxygen is run, you must also specify the path to the tagfile here.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create
-# a tag file that is based on the input files it reads.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed
-# in the class index. If set to NO only the inherited external classes
-# will be listed.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will
-# be listed.
-
-EXTERNAL_GROUPS = YES
-
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of `which perl').
-
-PERL_PATH = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
-# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
-# or super classes. Setting the tag to NO turns the diagrams off. Note that
-# this option also works with HAVE_DOT disabled, but it is recommended to
-# install and use dot, since it yields more powerful graphs.
-
-CLASS_DIAGRAMS = YES
-
-# You can define message sequence charts within doxygen comments using the \msc
-# command. Doxygen will then run the mscgen tool (see
-# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
-# documentation. The MSCGEN_PATH tag allows you to specify the directory where
-# the mscgen tool resides. If left empty the tool is assumed to be found in the
-# default search path.
-
-MSCGEN_PATH =
-
-# If set to YES, the inheritance and collaboration graphs will hide
-# inheritance and usage relations if the target is undocumented
-# or is not a class.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz, a graph visualization
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section
-# have no effect if this option is set to NO (the default)
-
-HAVE_DOT = YES
-
-# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
-# allowed to run in parallel. When set to 0 (the default) doxygen will
-# base this on the number of processors available in the system. You can set it
-# explicitly to a value larger than 0 to get control over the balance
-# between CPU load and processing speed.
-
-DOT_NUM_THREADS = 0
-
-# By default doxygen will use the Helvetica font for all dot files that
-# doxygen generates. When you want a differently looking font you can specify
-# the font name using DOT_FONTNAME. You need to make sure dot is able to find
-# the font, which can be done by putting it in a standard location or by setting
-# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the
-# directory containing the font.
-
-DOT_FONTNAME = Helvetica
-
-# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
-# The default size is 10pt.
-
-DOT_FONTSIZE = 10
-
-# By default doxygen will tell dot to use the Helvetica font.
-# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to
-# set the path where dot can find it.
-
-DOT_FONTPATH =
-
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect inheritance relations. Setting this tag to YES will force the
-# CLASS_DIAGRAMS tag to NO.
-
-CLASS_GRAPH = YES
-
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect implementation dependencies (inheritance, containment, and
-# class references variables) of the class with other documented classes.
-
-COLLABORATION_GRAPH = YES
-
-# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for groups, showing the direct groups dependencies
-
-GROUP_GRAPHS = YES
-
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
-# Language.
-
-UML_LOOK = NO
-
-# If the UML_LOOK tag is enabled, the fields and methods are shown inside
-# the class node. If there are many fields or methods and many nodes the
-# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS
-# threshold limits the number of items for each type to make the size more
-# managable. Set this to 0 for no limit. Note that the threshold may be
-# exceeded by 50% before the limit is enforced.
-
-UML_LIMIT_NUM_FIELDS = 10
-
-# If set to YES, the inheritance and collaboration graphs will show the
-# relations between templates and their instances.
-
-TEMPLATE_RELATIONS = NO
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
-# tags are set to YES then doxygen will generate a graph for each documented
-# file showing the direct and indirect include dependencies of the file with
-# other documented files.
-
-INCLUDE_GRAPH = YES
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
-# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
-# documented header file showing the documented files that directly or
-# indirectly include this file.
-
-INCLUDED_BY_GRAPH = YES
-
-# If the CALL_GRAPH and HAVE_DOT options are set to YES then
-# doxygen will generate a call dependency graph for every global function
-# or class method. Note that enabling this option will significantly increase
-# the time of a run. So in most cases it will be better to enable call graphs
-# for selected functions only using the \callgraph command.
-
-CALL_GRAPH = NO
-
-# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
-# doxygen will generate a caller dependency graph for every global function
-# or class method. Note that enabling this option will significantly increase
-# the time of a run. So in most cases it will be better to enable caller
-# graphs for selected functions only using the \callergraph command.
-
-CALLER_GRAPH = NO
-
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
-# will generate a graphical hierarchy of all classes instead of a textual one.
-
-GRAPHICAL_HIERARCHY = YES
-
-# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES
-# then doxygen will show the dependencies a directory has on other directories
-# in a graphical way. The dependency relations are determined by the #include
-# relations between the files in the directories.
-
-DIRECTORY_GRAPH = YES
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot. Possible values are svg, png, jpg, or gif.
-# If left blank png will be used. If you choose svg you need to set
-# HTML_FILE_EXTENSION to xhtml in order to make the SVG files
-# visible in IE 9+ (other browsers do not have this requirement).
-
-DOT_IMAGE_FORMAT = png
-
-# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
-# enable generation of interactive SVG images that allow zooming and panning.
-# Note that this requires a modern browser other than Internet Explorer.
-# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you
-# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files
-# visible. Older versions of IE do not have SVG support.
-
-INTERACTIVE_SVG = NO
-
-# The tag DOT_PATH can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found in the path.
-
-DOT_PATH =
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the
-# \dotfile command).
-
-DOTFILE_DIRS =
-
-# The MSCFILE_DIRS tag can be used to specify one or more directories that
-# contain msc files that are included in the documentation (see the
-# \mscfile command).
-
-MSCFILE_DIRS =
-
-# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
-# nodes that will be shown in the graph. If the number of nodes in a graph
-# becomes larger than this value, doxygen will truncate the graph, which is
-# visualized by representing a node as a red box. Note that doxygen if the
-# number of direct children of the root node in a graph is already larger than
-# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
-# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
-
-DOT_GRAPH_MAX_NODES = 50
-
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
-# graphs generated by dot. A depth value of 3 means that only nodes reachable
-# from the root by following a path via at most 3 edges will be shown. Nodes
-# that lay further from the root node will be omitted. Note that setting this
-# option to 1 or 2 may greatly reduce the computation time needed for large
-# code bases. Also note that the size of a graph can be further restricted by
-# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
-
-MAX_DOT_GRAPH_DEPTH = 0
-
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, because dot on Windows does not
-# seem to support this out of the box. Warning: Depending on the platform used,
-# enabling this option may lead to badly anti-aliased labels on the edges of
-# a graph (i.e. they become hard to read).
-
-DOT_TRANSPARENT = NO
-
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10)
-# support this, this feature is disabled by default.
-
-DOT_MULTI_TARGETS = NO
-
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
-# generate a legend page explaining the meaning of the various boxes and
-# arrows in the dot generated graphs.
-
-GENERATE_LEGEND = YES
-
-# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
-# remove the intermediate dot files that are used to generate
-# the various graphs.
-
-DOT_CLEANUP = YES
diff --git a/docs/doxygen/luadoc.sh b/docs/doxygen/luadoc.sh
deleted file mode 100755
index 7854d81..0000000
--- a/docs/doxygen/luadoc.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-# Run this from docs directory.
-# Create docs/lua directory.
-test -d lua || mkdir lua
-# Convert doxygen comments to luadoc comments.
-for F in ../../src/llua_*.c
-do
-sed -n '
- 1 i -- This is file was generated automatically from C sources to feed luadoc
-#converts doxygens /** to luadocs ---
- s|^ */\*\*|---|p
-#convert special tags to lua expressions.
-#notice lines after @luafunc & @luamod will be ignored by luadoc
-#also doxygen comments that do not contain a any of this tags have no
-#influence on luadoc output
- s|^ *\* *@luafunc|function|p
- s|^ *\* *@luamod *\(.*\)|module "\1"|p
-#rename some tags:
- s|^ *\* *@brief|-- @description|p
- s|^ *\* *@luaparam|-- @param|p
- s|^ *\* *@luareturn|-- @return|p # We accept both @luareturn & @return
-#keep tags luadoc understands:
-# s|^ *\* *@param|-- @param|p # Use luaparam, param reserved for C arguments.
- s|^ *\* *@see|-- @see|p
- s|^ *\* *@return|-- @return|p
- s|^ *\* *@usage|-- @usage|p
- s|^ *\* *@description|-- @description|p
- s|^ *\* *@name|-- @name|p
- s|^ *\* *@class|-- @class|p
- s|^ *\* *@field|-- @field|p
- s|^ *\* *@release|-- @release|p
-#remove other tags:
- \|^ *\* *@.*|d
-#insert newline between comments, replace */ by \n
- \|^ *\*/|c
-#keep other comments, replace * by --
- s|^ *\*|--|p
-#delete everything else, just in case
- d
-' $F > lua/`basename $F`.luadoc
-done
-# Run luadoc, put html files into lua dir.
-(
- cd lua
- luadoc --nofiles *.luadoc
- rm *.luadoc
-)
-
diff --git a/docs/factions/empire b/docs/factions/empire
deleted file mode 100644
index 92d98ef..0000000
--- a/docs/factions/empire
+++ /dev/null
@@ -1,11 +0,0 @@
-MILITARY RANKS:
- * Emperor
- * Admiral
- * Vice-Admiral
- * Commodore
- * Captain
- * Commander
- * Sergeant
- * Lieutenant
- * Ensign
-
diff --git a/docs/factions/overview b/docs/factions/overview
deleted file mode 100644
index a4629e4..0000000
--- a/docs/factions/overview
+++ /dev/null
@@ -1,51 +0,0 @@
--- Faction Overview. --
-
-EMPIRE:
--------
-
- -- The Empire consists of the hard nuclei (Emperor) and assosciated Houses.
- The Houses can only be created by the Emporer's whim and are allowed to
- participate in the Galaxy politics.
-
- -- GREAT HOUSES:
- -- SIRIUS
- -- Religious nuts.
-
- -- PROTERON:
- -- Close allies of Sirius.
-
- -- SOROMID:
- -- Emperor's right hand.
-
- -- DRAKTHARR:
- -- Brutal and more primitive, very warlike.
-
- -- TEK'NUS:
- -- Technophiles of the Empire, distrusted by most.
-
- -- MINOR HOUSES:
- -- These houses are given the privileges to participate in the Council,
- but do not have the powers the other Houses have, nor the influence.
-
- -- GODDARD:
- -- Design and take care of the Goddard ships.
-
-DETOURS LIBERATION FRONT:
--------------------------
-
- -- The Early Tribes that where shunned in the Empire creation and have since
- then forged the Detours Liberation Front (DLF) into a guerilla resistance
- movement to resist the advances by the Empire. They employ dirty tactics
- to level the playing field against the superior Empire.
-
-SPACE TRADERS:
---------------
- -- Independent guild of merchants, protected by the Emporer himself. They
- keep the galaxy working with their deliveries.
-
-GALACTIC PIRATES:
---------
- -- Space brought an entire new dimenstion to pirating. These outlaws attack
- any ship transporting anything of value with no regard nor respect to
- authority.
-
diff --git a/docs/plot/campaign_collective b/docs/plot/campaign_collective
deleted file mode 100644
index 49d3ecb..0000000
--- a/docs/plot/campaign_collective
+++ /dev/null
@@ -1,78 +0,0 @@
--- C O L L E C T I V E C A M P A I G N --
-
-OVERVIEW:
----------
- -- Short campaign, mainly to use as an introduction to Lephisto and for the
- first release.
-
-HISTORY:
---------
- -- The Collective are a recently new menace. They caught the empire off
- guard and took over a few systems which they proceded to systematically
- purge of all life forms. The Empire then responded to the attack and a
- stalemate was reached. Frequent skirmishes still accured around the
- border star systems.
-
- A lot of speculation has been created among the Collective. Top secret
- scientific experiment gone wrong? New weapon of the Detours? Long-existing
- civilization converted to robots? No one knows for sure.
-
-PLOT OVERVIEW:
---------------
-
- -- Initial stalemate.
- -- Drone breaks blockade, seems to be malfunctioning.
- -- Drone captured and analyzed, weird wireless module found (seeminglyu of
- empire make), seems to have had corruption on AI.
- -- Fly back to listen on wireless conversations.
- -- Nothing reported, try again and deeper and hide on planet.
- -- Logs display Empire Military craft detect around area, seemingly
- communicate with Empire.
- -- Need distraction to monitor with a special covert ops team.
- -- Covert ops discovered and slaughtered, must check for survivors.
- -- One survivor hidden with data.
- -- Proof the the ESS Trinity communicates with the collective (preparing
- coup).
- -- Prepare trap for the ESS Trinity to arrest.
- -- ESS Trinity jumps to Collective space.
- -- Final showdown at NCG-7132.
- -- ESS Trinity destroyed, Collective/Empire suffer heavy losses.
- -- Cinematic scene to finish:
- -- You see the ESS Trinity release the AI limiter.
- -- Collective back off.
- -- Scientists and militaries found guilty. Their heads roll.
- -- End of Collective conflift.
-
-MISSIONS:
----------
- -- Collective Scout
- -- Find scout that broke through blockade.
- -- If combat rating is high enough (>200), you disable and board it.
- -- Else you just locate it.
- -- Fly back to Omega Station.
-
- -- Collective Espionage I
- -- Fly around systems listening on signals, enforce minimum system time.
- -- Fly back to Omega Station.
-
- -- Collective Espionage II
- -- Enter deeper into space and land on planet that got annihilated.
- -- Fly back to Omega Station.
-
- -- Collective Espionage III
- -- Fly very deep into collective space, make nuisance of yourself.
- -- Fly back to Omega Station.
-
- -- Operation Green Giant
- -- Fly to the planet and land amidst heavy Collective opposition.
- -- Fly back to Omega Station.
-
- -- Operation Back Trinity
- -- Attempt to stop ESS Trinity on way to Collective space.
- -- Trinity will jump (unless you destroy it *really* fast) leaving collective
- drones behind for you to fight.
- -- Rebrief at Omega Station.
- -- Showdown at NCG-7132.
- -- If flee, different ending with no medal.
- -- If win, cinema scene.
-
diff --git a/docs/plot/setting b/docs/plot/setting
deleted file mode 100644
index 5847d50..0000000
--- a/docs/plot/setting
+++ /dev/null
@@ -1,49 +0,0 @@
-GLOBAL.
-~~~~~~~
-
-* Catastrophic event (pre-hyperspace and long-range communication - englobe
- under some type of technology)
- * Destruction of earth and nearby stuff - big crater or something as a
- symbol.
-
-* Massive fleeing (entire civilizations/cultures) design gigantic exploration
- ships that flee in different directions.
-
-* Establishment of multiple parallel human civilizations far from each other as
- a sort of "dark age" where everything is isolated and progress is very slow.
-
- --
-
-* Now it would branch off as each evolve differently, some ideas:
- * Humans that discover friendly aliens, form conjoint society and evolve
- together.
- * Maybe a good place to introduce hybrid biological ships.
-
- * Humans that discover hostile aliens, kill each other in long feudal war.
- * Humans killed off by.. { plague, end of supplies, aliens }, find derelict
- ship or annihilated systems (partially destroyed stations and whatnot).
- * Humans hit technological singularity then:
- * Robots proceed to exterminate humans creating a hostile robotic
- faction.
- * Humans evolve into cyborgs and/or "living robotic ships"
-
- * Discovery of hyperspace and the consequent acquiration by all/almost all
- factions would then make it easier to communicate and travel, increasing
- friendships (and enemies)
- * A couple civilizations fuse together forming "The Empire" which will
- be a strong faction with importance in the early game (you will start
- in Empire terratory).
-
- * Player would come into an unstable world few years after hyperspace with
- every increasing technological advancement and such, making it all more
- intersting.
-
-TRAVEL AND HYPERSPACE.
-~~~~~~~~~~~~~~~~~~~~~
-
-* Hyperspace will be the latest version of travel that actually makes it spread
- out, older versions (more primitive) would be the huge "guild highliners"
- (Need to get rid of dune plagerism) and jump gates.
-
-* Need some fancy name for it.
-
diff --git a/docs/ships/classification b/docs/ships/classification
deleted file mode 100644
index b6d2a4a..0000000
--- a/docs/ships/classification
+++ /dev/null
@@ -1,48 +0,0 @@
-Contains an overview of ship classification in Lephisto.
-
-STANDARD SHIPS
- -- Military
-
- -- Large Ships:
- -- Carrier
- -- Must contain fighter bays.
- -- Cuiser
- -- No fighter bays.
-
- -- Medium Ships:
- -- Destroyer
- -- Fast and maneuverable.
- -- Vorvette
- -- Maneuverable and lightly armed.
-
- -- Small Ships:
- -- Bomber
- -- Heavy bomb usage.
- -- Fighter
- -- Standard small ship.
- -- Scout
- -- Not intended for combat.
-
- -- Merchant
-
- -- Large Ships
- -- Cruise ships
- -- Basically a larger yacht.
-
- -- Small Ships.
- -- Luxery Yacht
- -- Very expensive.
- Yacht
- -- Not expensive.
-
- ROBOTIC SHIPS:
-
- -- Large Ships
- -- Mothership
-
- -- Small Ships
- -- Drone
-
- HYBRID SHIPS
- -- TODO
-
diff --git a/gfx/gui/minimal.png b/gfx/gui/minimal.png
deleted file mode 100644
index 1d9063c..0000000
Binary files a/gfx/gui/minimal.png and /dev/null differ
diff --git a/gfx/gui/minimal_energy.png b/gfx/gui/minimal_energy.png
deleted file mode 100644
index 5136c01..0000000
Binary files a/gfx/gui/minimal_energy.png and /dev/null differ
diff --git a/gfx/gui/minimal_fuel.png b/gfx/gui/minimal_fuel.png
deleted file mode 100644
index 29e6ceb..0000000
Binary files a/gfx/gui/minimal_fuel.png and /dev/null differ
diff --git a/gfx/gui/minimal_pilot.png b/gfx/gui/minimal_pilot.png
deleted file mode 100644
index 2186e72..0000000
Binary files a/gfx/gui/minimal_pilot.png and /dev/null differ
diff --git a/gfx/gui/minimal_planet.png b/gfx/gui/minimal_planet.png
deleted file mode 100644
index 8eb8a2d..0000000
Binary files a/gfx/gui/minimal_planet.png and /dev/null differ
diff --git a/gfx/loading/admonisher.png b/gfx/loading/admonisher.png
deleted file mode 100644
index 4a6c702..0000000
Binary files a/gfx/loading/admonisher.png and /dev/null differ
diff --git a/gfx/loading/gawain.png b/gfx/loading/gawain.png
deleted file mode 100644
index 7d6706b..0000000
Binary files a/gfx/loading/gawain.png and /dev/null differ
diff --git a/gfx/loading/goddard.png b/gfx/loading/goddard.png
deleted file mode 100644
index 6554cf5..0000000
Binary files a/gfx/loading/goddard.png and /dev/null differ
diff --git a/gfx/loading/llama.png b/gfx/loading/llama.png
deleted file mode 100644
index f67677f..0000000
Binary files a/gfx/loading/llama.png and /dev/null differ
diff --git a/gfx/loading/mule.png b/gfx/loading/mule.png
deleted file mode 100644
index d35b1aa..0000000
Binary files a/gfx/loading/mule.png and /dev/null differ
diff --git a/gfx/loading/pacifier.png b/gfx/loading/pacifier.png
deleted file mode 100644
index 39af474..0000000
Binary files a/gfx/loading/pacifier.png and /dev/null differ
diff --git a/gfx/logo/dvaered_small.png b/gfx/logo/dvaered_small.png
deleted file mode 100644
index 5d74e41..0000000
Binary files a/gfx/logo/dvaered_small.png and /dev/null differ
diff --git a/gfx/logo/empire_small.png b/gfx/logo/empire_small.png
deleted file mode 100644
index bc6ecd4..0000000
Binary files a/gfx/logo/empire_small.png and /dev/null differ
diff --git a/gfx/logo/goddard_small.png b/gfx/logo/goddard_small.png
deleted file mode 100644
index a126185..0000000
Binary files a/gfx/logo/goddard_small.png and /dev/null differ
diff --git a/gfx/logo/sirius_small.png b/gfx/logo/sirius_small.png
deleted file mode 100644
index e462684..0000000
Binary files a/gfx/logo/sirius_small.png and /dev/null differ
diff --git a/gfx/logo/zalek_small.png b/gfx/logo/zalek_small.png
deleted file mode 100644
index 598f5fb..0000000
Binary files a/gfx/logo/zalek_small.png and /dev/null differ
diff --git a/gfx/outfit/check.sh b/gfx/outfit/check.sh
deleted file mode 100755
index 0f824dc..0000000
--- a/gfx/outfit/check.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env bash
-
-DATA="../../dat/outfit.xml"
-
-echo "Checking for unused graphics.."
-echo
-
-# Check unused space gfx.
-echo " Unused outfit store gfx."
-cd store
-for SPACE in *.png; do
- if [ -z "`grep ${SPACE%.png} ../$DATA | grep ""`" ]; then
- echo " $SPACE"
- fi
-done
-cd ..
-
-# Check unused exteria gfx.
-echo " Unused outfit gfx"
-cd space
-for SPACE in *.png; do
- if [ -z "`grep ${SPACE%.png} ../$DATA | grep ""`" ]; then
- echo " $SPACE"
- fi
-done
-cd ..
-
-echo
-echo
-echo "Checking for overused graphics.."
-echo
-
-# Check overused.
-echo " Overused outfit store gfx"
-cd store
-for SPACE in *.png; do
- COUNT=`grep ${SPACE%.png} ../$DATA | grep -c ""`
- if [ $COUNT -gt 1 ]; then
- echo " $SPACE => $COUNT times"
- fi
-done
-cd ..
-
-# Check unused exteria gfx.
-echo " Overused outfit gfx"
-cd space
-for SPACE in *.png; do
- COUNT=`grep ${SPACE%.png} ../$DATA | grep -c ""`
- if [ $COUNT -gt 1 ]; then
- echo " $SPACE => $COUNT times"
- fi
-done
-cd ..
-
diff --git a/gfx/outfit/space/banshee.png b/gfx/outfit/space/banshee.png
deleted file mode 100644
index c212cca..0000000
Binary files a/gfx/outfit/space/banshee.png and /dev/null differ
diff --git a/gfx/outfit/space/beam_orion.png b/gfx/outfit/space/beam_orion.png
deleted file mode 100644
index 80354cc..0000000
Binary files a/gfx/outfit/space/beam_orion.png and /dev/null differ
diff --git a/gfx/outfit/space/beam_ragnarok.png b/gfx/outfit/space/beam_ragnarok.png
deleted file mode 100644
index 2faacfb..0000000
Binary files a/gfx/outfit/space/beam_ragnarok.png and /dev/null differ
diff --git a/gfx/outfit/space/empgrenade.png b/gfx/outfit/space/empgrenade.png
deleted file mode 100644
index 5600523..0000000
Binary files a/gfx/outfit/space/empgrenade.png and /dev/null differ
diff --git a/gfx/outfit/space/headhunter.png b/gfx/outfit/space/headhunter.png
deleted file mode 100644
index 01050af..0000000
Binary files a/gfx/outfit/space/headhunter.png and /dev/null differ
diff --git a/gfx/outfit/space/ion.png b/gfx/outfit/space/ion.png
deleted file mode 100644
index cd14010..0000000
Binary files a/gfx/outfit/space/ion.png and /dev/null differ
diff --git a/gfx/outfit/space/lasergreen.png b/gfx/outfit/space/lasergreen.png
deleted file mode 100644
index 0365762..0000000
Binary files a/gfx/outfit/space/lasergreen.png and /dev/null differ
diff --git a/gfx/outfit/space/laserred.png b/gfx/outfit/space/laserred.png
deleted file mode 100644
index e28b124..0000000
Binary files a/gfx/outfit/space/laserred.png and /dev/null differ
diff --git a/gfx/outfit/space/mace.png b/gfx/outfit/space/mace.png
deleted file mode 100644
index b601d6d..0000000
Binary files a/gfx/outfit/space/mace.png and /dev/null differ
diff --git a/gfx/outfit/space/mass.png b/gfx/outfit/space/mass.png
deleted file mode 100644
index fefa7b3..0000000
Binary files a/gfx/outfit/space/mass.png and /dev/null differ
diff --git a/gfx/outfit/space/missile.png b/gfx/outfit/space/missile.png
deleted file mode 100644
index 92b59fe..0000000
Binary files a/gfx/outfit/space/missile.png and /dev/null differ
diff --git a/gfx/outfit/space/neutron.png b/gfx/outfit/space/neutron.png
deleted file mode 100644
index f8c4e4a..0000000
Binary files a/gfx/outfit/space/neutron.png and /dev/null differ
diff --git a/gfx/outfit/space/particle.png b/gfx/outfit/space/particle.png
deleted file mode 100644
index c852bf3..0000000
Binary files a/gfx/outfit/space/particle.png and /dev/null differ
diff --git a/gfx/outfit/space/plasma.png b/gfx/outfit/space/plasma.png
deleted file mode 100644
index 3d3aba4..0000000
Binary files a/gfx/outfit/space/plasma.png and /dev/null differ
diff --git a/gfx/outfit/space/ripper.png b/gfx/outfit/space/ripper.png
deleted file mode 100644
index 73bb83d..0000000
Binary files a/gfx/outfit/space/ripper.png and /dev/null differ
diff --git a/gfx/outfit/store/afterburner.png b/gfx/outfit/store/afterburner.png
deleted file mode 100644
index c4a0c54..0000000
Binary files a/gfx/outfit/store/afterburner.png and /dev/null differ
diff --git a/gfx/outfit/store/afterburner2.png b/gfx/outfit/store/afterburner2.png
deleted file mode 100644
index 8f38127..0000000
Binary files a/gfx/outfit/store/afterburner2.png and /dev/null differ
diff --git a/gfx/outfit/store/banshee.png b/gfx/outfit/store/banshee.png
deleted file mode 100644
index 038b88b..0000000
Binary files a/gfx/outfit/store/banshee.png and /dev/null differ
diff --git a/gfx/outfit/store/bansheelauncher.png b/gfx/outfit/store/bansheelauncher.png
deleted file mode 100644
index 5214518..0000000
Binary files a/gfx/outfit/store/bansheelauncher.png and /dev/null differ
diff --git a/gfx/outfit/store/biometal.png b/gfx/outfit/store/biometal.png
deleted file mode 100644
index 12a40aa..0000000
Binary files a/gfx/outfit/store/biometal.png and /dev/null differ
diff --git a/gfx/outfit/store/capacitator.png b/gfx/outfit/store/capacitator.png
deleted file mode 100644
index 1e3b23e..0000000
Binary files a/gfx/outfit/store/capacitator.png and /dev/null differ
diff --git a/gfx/outfit/store/cargo_pod.png b/gfx/outfit/store/cargo_pod.png
deleted file mode 100644
index c04e7fb..0000000
Binary files a/gfx/outfit/store/cargo_pod.png and /dev/null differ
diff --git a/gfx/outfit/store/droid.png b/gfx/outfit/store/droid.png
deleted file mode 100644
index 7438e13..0000000
Binary files a/gfx/outfit/store/droid.png and /dev/null differ
diff --git a/gfx/outfit/store/empgrenade.png b/gfx/outfit/store/empgrenade.png
deleted file mode 100644
index a4370ce..0000000
Binary files a/gfx/outfit/store/empgrenade.png and /dev/null differ
diff --git a/gfx/outfit/store/empgrenadelauncher.png b/gfx/outfit/store/empgrenadelauncher.png
deleted file mode 100644
index 7caa71d..0000000
Binary files a/gfx/outfit/store/empgrenadelauncher.png and /dev/null differ
diff --git a/gfx/outfit/store/fuel_pod.png b/gfx/outfit/store/fuel_pod.png
deleted file mode 100644
index 1e805c6..0000000
Binary files a/gfx/outfit/store/fuel_pod.png and /dev/null differ
diff --git a/gfx/outfit/store/heavy.png b/gfx/outfit/store/heavy.png
deleted file mode 100644
index 66c6816..0000000
Binary files a/gfx/outfit/store/heavy.png and /dev/null differ
diff --git a/gfx/outfit/store/ion.png b/gfx/outfit/store/ion.png
deleted file mode 100644
index 8bbd64e..0000000
Binary files a/gfx/outfit/store/ion.png and /dev/null differ
diff --git a/gfx/outfit/store/jammer0.png b/gfx/outfit/store/jammer0.png
deleted file mode 100644
index f966837..0000000
Binary files a/gfx/outfit/store/jammer0.png and /dev/null differ
diff --git a/gfx/outfit/store/jammer1.png b/gfx/outfit/store/jammer1.png
deleted file mode 100644
index 0410f5f..0000000
Binary files a/gfx/outfit/store/jammer1.png and /dev/null differ
diff --git a/gfx/outfit/store/lancelot_fighter.png b/gfx/outfit/store/lancelot_fighter.png
deleted file mode 100644
index 2a2e53b..0000000
Binary files a/gfx/outfit/store/lancelot_fighter.png and /dev/null differ
diff --git a/gfx/outfit/store/laser.png b/gfx/outfit/store/laser.png
deleted file mode 100644
index 150a450..0000000
Binary files a/gfx/outfit/store/laser.png and /dev/null differ
diff --git a/gfx/outfit/store/license.png b/gfx/outfit/store/license.png
deleted file mode 100644
index e1a839c..0000000
Binary files a/gfx/outfit/store/license.png and /dev/null differ
diff --git a/gfx/outfit/store/mace.png b/gfx/outfit/store/mace.png
deleted file mode 100644
index 949bcc2..0000000
Binary files a/gfx/outfit/store/mace.png and /dev/null differ
diff --git a/gfx/outfit/store/map.png b/gfx/outfit/store/map.png
deleted file mode 100644
index 3fb936a..0000000
Binary files a/gfx/outfit/store/map.png and /dev/null differ
diff --git a/gfx/outfit/store/medium.png b/gfx/outfit/store/medium.png
deleted file mode 100644
index 6381282..0000000
Binary files a/gfx/outfit/store/medium.png and /dev/null differ
diff --git a/gfx/outfit/store/missile.png b/gfx/outfit/store/missile.png
deleted file mode 100644
index 7952148..0000000
Binary files a/gfx/outfit/store/missile.png and /dev/null differ
diff --git a/gfx/outfit/store/nanobond.png b/gfx/outfit/store/nanobond.png
deleted file mode 100644
index c5a4808..0000000
Binary files a/gfx/outfit/store/nanobond.png and /dev/null differ
diff --git a/gfx/outfit/store/neutron.png b/gfx/outfit/store/neutron.png
deleted file mode 100644
index 6cf22a6..0000000
Binary files a/gfx/outfit/store/neutron.png and /dev/null differ
diff --git a/gfx/outfit/store/orion.png b/gfx/outfit/store/orion.png
deleted file mode 100644
index 6d5037c..0000000
Binary files a/gfx/outfit/store/orion.png and /dev/null differ
diff --git a/gfx/outfit/store/plasteel.png b/gfx/outfit/store/plasteel.png
deleted file mode 100644
index 85c22ce..0000000
Binary files a/gfx/outfit/store/plasteel.png and /dev/null differ
diff --git a/gfx/outfit/store/reactor_i.png b/gfx/outfit/store/reactor_i.png
deleted file mode 100644
index 69d9343..0000000
Binary files a/gfx/outfit/store/reactor_i.png and /dev/null differ
diff --git a/gfx/outfit/store/reactor_ii.png b/gfx/outfit/store/reactor_ii.png
deleted file mode 100644
index 51241e6..0000000
Binary files a/gfx/outfit/store/reactor_ii.png and /dev/null differ
diff --git a/gfx/outfit/store/reactor_iii.png b/gfx/outfit/store/reactor_iii.png
deleted file mode 100644
index 0709fb6..0000000
Binary files a/gfx/outfit/store/reactor_iii.png and /dev/null differ
diff --git a/gfx/outfit/store/reroute.png b/gfx/outfit/store/reroute.png
deleted file mode 100644
index 649f412..0000000
Binary files a/gfx/outfit/store/reroute.png and /dev/null differ
diff --git a/gfx/outfit/store/shield.png b/gfx/outfit/store/shield.png
deleted file mode 100644
index f4c2adc..0000000
Binary files a/gfx/outfit/store/shield.png and /dev/null differ
diff --git a/gfx/outfit/store/solar.png b/gfx/outfit/store/solar.png
deleted file mode 100644
index 9a75d2f..0000000
Binary files a/gfx/outfit/store/solar.png and /dev/null differ
diff --git a/gfx/outfit/store/stabilizer.png b/gfx/outfit/store/stabilizer.png
deleted file mode 100644
index 324811b..0000000
Binary files a/gfx/outfit/store/stabilizer.png and /dev/null differ
diff --git a/gfx/outfit/store/thruster.png b/gfx/outfit/store/thruster.png
deleted file mode 100644
index c37463b..0000000
Binary files a/gfx/outfit/store/thruster.png and /dev/null differ
diff --git a/gfx/outfit/store/turret.png b/gfx/outfit/store/turret.png
deleted file mode 100644
index b9dab5c..0000000
Binary files a/gfx/outfit/store/turret.png and /dev/null differ
diff --git a/gfx/outfit/store/turret2.png b/gfx/outfit/store/turret2.png
deleted file mode 100644
index a3c91fc..0000000
Binary files a/gfx/outfit/store/turret2.png and /dev/null differ
diff --git a/gfx/outfit/store/turret3.png b/gfx/outfit/store/turret3.png
deleted file mode 100644
index 0780426..0000000
Binary files a/gfx/outfit/store/turret3.png and /dev/null differ
diff --git a/gfx/outfit/store/weapon_rack.png b/gfx/outfit/store/weapon_rack.png
deleted file mode 100644
index 590444d..0000000
Binary files a/gfx/outfit/store/weapon_rack.png and /dev/null differ
diff --git a/gfx/planet/exterior/aquatic.png b/gfx/planet/exterior/aquatic.png
deleted file mode 100644
index ecde8b4..0000000
Binary files a/gfx/planet/exterior/aquatic.png and /dev/null differ
diff --git a/gfx/planet/exterior/desertic.png b/gfx/planet/exterior/desertic.png
deleted file mode 100644
index ff229bd..0000000
Binary files a/gfx/planet/exterior/desertic.png and /dev/null differ
diff --git a/gfx/planet/exterior/gas.png b/gfx/planet/exterior/gas.png
deleted file mode 100644
index a8554ef..0000000
Binary files a/gfx/planet/exterior/gas.png and /dev/null differ
diff --git a/gfx/planet/exterior/lava.png b/gfx/planet/exterior/lava.png
deleted file mode 100644
index f44b2f4..0000000
Binary files a/gfx/planet/exterior/lava.png and /dev/null differ
diff --git a/gfx/planet/exterior/methane.png b/gfx/planet/exterior/methane.png
deleted file mode 100644
index 9fa3fc4..0000000
Binary files a/gfx/planet/exterior/methane.png and /dev/null differ
diff --git a/gfx/planet/exterior/mining.png b/gfx/planet/exterior/mining.png
deleted file mode 100644
index d290653..0000000
Binary files a/gfx/planet/exterior/mining.png and /dev/null differ
diff --git a/gfx/planet/exterior/mining2.png b/gfx/planet/exterior/mining2.png
deleted file mode 100644
index 2092791..0000000
Binary files a/gfx/planet/exterior/mining2.png and /dev/null differ
diff --git a/gfx/planet/exterior/oceanic.png b/gfx/planet/exterior/oceanic.png
deleted file mode 100644
index 61b21e5..0000000
Binary files a/gfx/planet/exterior/oceanic.png and /dev/null differ
diff --git a/gfx/planet/exterior/snow.png b/gfx/planet/exterior/snow.png
deleted file mode 100644
index 4cd4556..0000000
Binary files a/gfx/planet/exterior/snow.png and /dev/null differ
diff --git a/gfx/planet/exterior/station00.png b/gfx/planet/exterior/station00.png
deleted file mode 100644
index ad4249a..0000000
Binary files a/gfx/planet/exterior/station00.png and /dev/null differ
diff --git a/gfx/planet/exterior/station01.png b/gfx/planet/exterior/station01.png
deleted file mode 100644
index d8db329..0000000
Binary files a/gfx/planet/exterior/station01.png and /dev/null differ
diff --git a/gfx/planet/exterior/station02.png b/gfx/planet/exterior/station02.png
deleted file mode 100644
index 51f87b7..0000000
Binary files a/gfx/planet/exterior/station02.png and /dev/null differ
diff --git a/gfx/planet/exterior/traderoom.png b/gfx/planet/exterior/traderoom.png
deleted file mode 100644
index 2d34fd0..0000000
Binary files a/gfx/planet/exterior/traderoom.png and /dev/null differ
diff --git a/gfx/planet/space/000.png b/gfx/planet/space/000.png
deleted file mode 100644
index 4727331..0000000
Binary files a/gfx/planet/space/000.png and /dev/null differ
diff --git a/gfx/planet/space/001.png b/gfx/planet/space/001.png
deleted file mode 100644
index a607789..0000000
Binary files a/gfx/planet/space/001.png and /dev/null differ
diff --git a/gfx/planet/space/002.png b/gfx/planet/space/002.png
deleted file mode 100644
index d4e10cf..0000000
Binary files a/gfx/planet/space/002.png and /dev/null differ
diff --git a/gfx/planet/space/003.png b/gfx/planet/space/003.png
deleted file mode 100644
index 1b8fe2b..0000000
Binary files a/gfx/planet/space/003.png and /dev/null differ
diff --git a/gfx/planet/space/A00.png b/gfx/planet/space/A00.png
deleted file mode 100644
index e2b9645..0000000
Binary files a/gfx/planet/space/A00.png and /dev/null differ
diff --git a/gfx/planet/space/A01.png b/gfx/planet/space/A01.png
deleted file mode 100644
index b7fb2a0..0000000
Binary files a/gfx/planet/space/A01.png and /dev/null differ
diff --git a/gfx/planet/space/C00.png b/gfx/planet/space/C00.png
deleted file mode 100644
index e3d05e5..0000000
Binary files a/gfx/planet/space/C00.png and /dev/null differ
diff --git a/gfx/planet/space/D00.png b/gfx/planet/space/D00.png
deleted file mode 100644
index 4bc7cdc..0000000
Binary files a/gfx/planet/space/D00.png and /dev/null differ
diff --git a/gfx/planet/space/D01.png b/gfx/planet/space/D01.png
deleted file mode 100644
index 179826a..0000000
Binary files a/gfx/planet/space/D01.png and /dev/null differ
diff --git a/gfx/planet/space/G00.png b/gfx/planet/space/G00.png
deleted file mode 100644
index 7640a32..0000000
Binary files a/gfx/planet/space/G00.png and /dev/null differ
diff --git a/gfx/planet/space/G01.png b/gfx/planet/space/G01.png
deleted file mode 100644
index ae64b2d..0000000
Binary files a/gfx/planet/space/G01.png and /dev/null differ
diff --git a/gfx/planet/space/H00.png b/gfx/planet/space/H00.png
deleted file mode 100644
index da345b5..0000000
Binary files a/gfx/planet/space/H00.png and /dev/null differ
diff --git a/gfx/planet/space/H01.png b/gfx/planet/space/H01.png
deleted file mode 100644
index 447b9de..0000000
Binary files a/gfx/planet/space/H01.png and /dev/null differ
diff --git a/gfx/planet/space/H02.png b/gfx/planet/space/H02.png
deleted file mode 100644
index 7321123..0000000
Binary files a/gfx/planet/space/H02.png and /dev/null differ
diff --git a/gfx/planet/space/I00.png b/gfx/planet/space/I00.png
deleted file mode 100644
index 93eda98..0000000
Binary files a/gfx/planet/space/I00.png and /dev/null differ
diff --git a/gfx/planet/space/I01.png b/gfx/planet/space/I01.png
deleted file mode 100644
index 4d35198..0000000
Binary files a/gfx/planet/space/I01.png and /dev/null differ
diff --git a/gfx/planet/space/J00.png b/gfx/planet/space/J00.png
deleted file mode 100644
index 4b868a5..0000000
Binary files a/gfx/planet/space/J00.png and /dev/null differ
diff --git a/gfx/planet/space/J01.png b/gfx/planet/space/J01.png
deleted file mode 100644
index fb6361f..0000000
Binary files a/gfx/planet/space/J01.png and /dev/null differ
diff --git a/gfx/planet/space/J02.png b/gfx/planet/space/J02.png
deleted file mode 100644
index 3a801ee..0000000
Binary files a/gfx/planet/space/J02.png and /dev/null differ
diff --git a/gfx/planet/space/K00.png b/gfx/planet/space/K00.png
deleted file mode 100644
index 07c1368..0000000
Binary files a/gfx/planet/space/K00.png and /dev/null differ
diff --git a/gfx/planet/space/L00.png b/gfx/planet/space/L00.png
deleted file mode 100644
index 4b22bbb..0000000
Binary files a/gfx/planet/space/L00.png and /dev/null differ
diff --git a/gfx/planet/space/M00.png b/gfx/planet/space/M00.png
deleted file mode 100644
index 73052ea..0000000
Binary files a/gfx/planet/space/M00.png and /dev/null differ
diff --git a/gfx/planet/space/M01.png b/gfx/planet/space/M01.png
deleted file mode 100644
index 5f41eaf..0000000
Binary files a/gfx/planet/space/M01.png and /dev/null differ
diff --git a/gfx/planet/space/M02.png b/gfx/planet/space/M02.png
deleted file mode 100644
index c049ba1..0000000
Binary files a/gfx/planet/space/M02.png and /dev/null differ
diff --git a/gfx/planet/space/M03.png b/gfx/planet/space/M03.png
deleted file mode 100644
index 1966899..0000000
Binary files a/gfx/planet/space/M03.png and /dev/null differ
diff --git a/gfx/planet/space/M04.png b/gfx/planet/space/M04.png
deleted file mode 100644
index 4f68b98..0000000
Binary files a/gfx/planet/space/M04.png and /dev/null differ
diff --git a/gfx/planet/space/M05.png b/gfx/planet/space/M05.png
deleted file mode 100644
index 2056cb5..0000000
Binary files a/gfx/planet/space/M05.png and /dev/null differ
diff --git a/gfx/planet/space/M06.png b/gfx/planet/space/M06.png
deleted file mode 100644
index 9515ce2..0000000
Binary files a/gfx/planet/space/M06.png and /dev/null differ
diff --git a/gfx/planet/space/O00.png b/gfx/planet/space/O00.png
deleted file mode 100644
index 76d2a37..0000000
Binary files a/gfx/planet/space/O00.png and /dev/null differ
diff --git a/gfx/planet/space/O01.png b/gfx/planet/space/O01.png
deleted file mode 100644
index d4b1360..0000000
Binary files a/gfx/planet/space/O01.png and /dev/null differ
diff --git a/gfx/planet/space/P00.png b/gfx/planet/space/P00.png
deleted file mode 100644
index f944e8d..0000000
Binary files a/gfx/planet/space/P00.png and /dev/null differ
diff --git a/gfx/planet/space/P01.png b/gfx/planet/space/P01.png
deleted file mode 100644
index 1a40ac8..0000000
Binary files a/gfx/planet/space/P01.png and /dev/null differ
diff --git a/gfx/planet/space/P02.png b/gfx/planet/space/P02.png
deleted file mode 100644
index c8730d1..0000000
Binary files a/gfx/planet/space/P02.png and /dev/null differ
diff --git a/gfx/saracraft_logo1.png b/gfx/saracraft_logo1.png
deleted file mode 100644
index 5e56cbb..0000000
Binary files a/gfx/saracraft_logo1.png and /dev/null differ
diff --git a/gfx/ship/admonisher.png b/gfx/ship/admonisher.png
deleted file mode 100644
index 39eb1b4..0000000
Binary files a/gfx/ship/admonisher.png and /dev/null differ
diff --git a/gfx/ship/admonisher_comm.png b/gfx/ship/admonisher_comm.png
deleted file mode 100644
index 8ab12c1..0000000
Binary files a/gfx/ship/admonisher_comm.png and /dev/null differ
diff --git a/gfx/ship/admonisher_empire.png b/gfx/ship/admonisher_empire.png
deleted file mode 100644
index 38693e6..0000000
Binary files a/gfx/ship/admonisher_empire.png and /dev/null differ
diff --git a/gfx/ship/admonisher_empire_comm.png b/gfx/ship/admonisher_empire_comm.png
deleted file mode 100644
index e646c72..0000000
Binary files a/gfx/ship/admonisher_empire_comm.png and /dev/null differ
diff --git a/gfx/ship/admonisher_pirate.png b/gfx/ship/admonisher_pirate.png
deleted file mode 100644
index 01d107c..0000000
Binary files a/gfx/ship/admonisher_pirate.png and /dev/null differ
diff --git a/gfx/ship/admonisher_pirate_comm.png b/gfx/ship/admonisher_pirate_comm.png
deleted file mode 100644
index 3f24139..0000000
Binary files a/gfx/ship/admonisher_pirate_comm.png and /dev/null differ
diff --git a/gfx/ship/admonisher_target.png b/gfx/ship/admonisher_target.png
deleted file mode 100644
index ab3874b..0000000
Binary files a/gfx/ship/admonisher_target.png and /dev/null differ
diff --git a/gfx/ship/ancestor.png b/gfx/ship/ancestor.png
deleted file mode 100644
index 1044f63..0000000
Binary files a/gfx/ship/ancestor.png and /dev/null differ
diff --git a/gfx/ship/ancestor_comm.png b/gfx/ship/ancestor_comm.png
deleted file mode 100644
index fed7f6c..0000000
Binary files a/gfx/ship/ancestor_comm.png and /dev/null differ
diff --git a/gfx/ship/ancestor_dvaered.png b/gfx/ship/ancestor_dvaered.png
deleted file mode 100644
index 7df9b48..0000000
Binary files a/gfx/ship/ancestor_dvaered.png and /dev/null differ
diff --git a/gfx/ship/ancestor_dvaered_comm.png b/gfx/ship/ancestor_dvaered_comm.png
deleted file mode 100644
index 72cd28c..0000000
Binary files a/gfx/ship/ancestor_dvaered_comm.png and /dev/null differ
diff --git a/gfx/ship/ancestor_pirate.png b/gfx/ship/ancestor_pirate.png
deleted file mode 100644
index 37595dc..0000000
Binary files a/gfx/ship/ancestor_pirate.png and /dev/null differ
diff --git a/gfx/ship/ancestor_pirate_comm.png b/gfx/ship/ancestor_pirate_comm.png
deleted file mode 100644
index 1f6d344..0000000
Binary files a/gfx/ship/ancestor_pirate_comm.png and /dev/null differ
diff --git a/gfx/ship/ancestor_target.png b/gfx/ship/ancestor_target.png
deleted file mode 100644
index a86f11f..0000000
Binary files a/gfx/ship/ancestor_target.png and /dev/null differ
diff --git a/gfx/ship/drone.png b/gfx/ship/drone.png
deleted file mode 100644
index fc68427..0000000
Binary files a/gfx/ship/drone.png and /dev/null differ
diff --git a/gfx/ship/drone_comm.png b/gfx/ship/drone_comm.png
deleted file mode 100644
index 1816ecb..0000000
Binary files a/gfx/ship/drone_comm.png and /dev/null differ
diff --git a/gfx/ship/drone_target.png b/gfx/ship/drone_target.png
deleted file mode 100644
index 5cddd54..0000000
Binary files a/gfx/ship/drone_target.png and /dev/null differ
diff --git a/gfx/ship/gawain.png b/gfx/ship/gawain.png
deleted file mode 100644
index 7d132b0..0000000
Binary files a/gfx/ship/gawain.png and /dev/null differ
diff --git a/gfx/ship/gawain_comm.png b/gfx/ship/gawain_comm.png
deleted file mode 100644
index 9c019de..0000000
Binary files a/gfx/ship/gawain_comm.png and /dev/null differ
diff --git a/gfx/ship/gawain_target.png b/gfx/ship/gawain_target.png
deleted file mode 100644
index c836b39..0000000
Binary files a/gfx/ship/gawain_target.png and /dev/null differ
diff --git a/gfx/ship/goddard.png b/gfx/ship/goddard.png
deleted file mode 100644
index 98524e8..0000000
Binary files a/gfx/ship/goddard.png and /dev/null differ
diff --git a/gfx/ship/goddard_comm.png b/gfx/ship/goddard_comm.png
deleted file mode 100644
index 7906b42..0000000
Binary files a/gfx/ship/goddard_comm.png and /dev/null differ
diff --git a/gfx/ship/goddard_dvaered.png b/gfx/ship/goddard_dvaered.png
deleted file mode 100644
index 9d6aaf0..0000000
Binary files a/gfx/ship/goddard_dvaered.png and /dev/null differ
diff --git a/gfx/ship/goddard_dvaered_comm.png b/gfx/ship/goddard_dvaered_comm.png
deleted file mode 100644
index 11d2889..0000000
Binary files a/gfx/ship/goddard_dvaered_comm.png and /dev/null differ
diff --git a/gfx/ship/goddard_target.png b/gfx/ship/goddard_target.png
deleted file mode 100644
index 929c82e..0000000
Binary files a/gfx/ship/goddard_target.png and /dev/null differ
diff --git a/gfx/ship/hawking.png b/gfx/ship/hawking.png
deleted file mode 100644
index 8049bd2..0000000
Binary files a/gfx/ship/hawking.png and /dev/null differ
diff --git a/gfx/ship/hawking_comm.png b/gfx/ship/hawking_comm.png
deleted file mode 100644
index 4b3b12f..0000000
Binary files a/gfx/ship/hawking_comm.png and /dev/null differ
diff --git a/gfx/ship/hawking_empire.png b/gfx/ship/hawking_empire.png
deleted file mode 100644
index 7fa7d1d..0000000
Binary files a/gfx/ship/hawking_empire.png and /dev/null differ
diff --git a/gfx/ship/hawking_empire_comm.png b/gfx/ship/hawking_empire_comm.png
deleted file mode 100644
index baaf87d..0000000
Binary files a/gfx/ship/hawking_empire_comm.png and /dev/null differ
diff --git a/gfx/ship/hawking_target.png b/gfx/ship/hawking_target.png
deleted file mode 100644
index 1324d77..0000000
Binary files a/gfx/ship/hawking_target.png and /dev/null differ
diff --git a/gfx/ship/hyena.png b/gfx/ship/hyena.png
deleted file mode 100644
index 1a80df3..0000000
Binary files a/gfx/ship/hyena.png and /dev/null differ
diff --git a/gfx/ship/hyena_comm.png b/gfx/ship/hyena_comm.png
deleted file mode 100644
index df57348..0000000
Binary files a/gfx/ship/hyena_comm.png and /dev/null differ
diff --git a/gfx/ship/hyena_target.png b/gfx/ship/hyena_target.png
deleted file mode 100644
index fe2b09a..0000000
Binary files a/gfx/ship/hyena_target.png and /dev/null differ
diff --git a/gfx/ship/kestrel.png b/gfx/ship/kestrel.png
deleted file mode 100644
index 0717084..0000000
Binary files a/gfx/ship/kestrel.png and /dev/null differ
diff --git a/gfx/ship/kestrel_comm.png b/gfx/ship/kestrel_comm.png
deleted file mode 100644
index 77f029f..0000000
Binary files a/gfx/ship/kestrel_comm.png and /dev/null differ
diff --git a/gfx/ship/kestrel_pirate.png b/gfx/ship/kestrel_pirate.png
deleted file mode 100644
index 121c972..0000000
Binary files a/gfx/ship/kestrel_pirate.png and /dev/null differ
diff --git a/gfx/ship/kestrel_pirate_comm.png b/gfx/ship/kestrel_pirate_comm.png
deleted file mode 100644
index c0a55c4..0000000
Binary files a/gfx/ship/kestrel_pirate_comm.png and /dev/null differ
diff --git a/gfx/ship/kestrel_target.png b/gfx/ship/kestrel_target.png
deleted file mode 100644
index 28365b2..0000000
Binary files a/gfx/ship/kestrel_target.png and /dev/null differ
diff --git a/gfx/ship/koala.png b/gfx/ship/koala.png
deleted file mode 100644
index 7792e39..0000000
Binary files a/gfx/ship/koala.png and /dev/null differ
diff --git a/gfx/ship/koala_comm.png b/gfx/ship/koala_comm.png
deleted file mode 100644
index 291e8fd..0000000
Binary files a/gfx/ship/koala_comm.png and /dev/null differ
diff --git a/gfx/ship/koala_target.png b/gfx/ship/koala_target.png
deleted file mode 100644
index 1aa7b73..0000000
Binary files a/gfx/ship/koala_target.png and /dev/null differ
diff --git a/gfx/ship/lancelot.png b/gfx/ship/lancelot.png
deleted file mode 100644
index eb02b53..0000000
Binary files a/gfx/ship/lancelot.png and /dev/null differ
diff --git a/gfx/ship/lancelot_comm.png b/gfx/ship/lancelot_comm.png
deleted file mode 100644
index fb013b7..0000000
Binary files a/gfx/ship/lancelot_comm.png and /dev/null differ
diff --git a/gfx/ship/lancelot_empire.png b/gfx/ship/lancelot_empire.png
deleted file mode 100644
index 596578d..0000000
Binary files a/gfx/ship/lancelot_empire.png and /dev/null differ
diff --git a/gfx/ship/lancelot_empire_comm.png b/gfx/ship/lancelot_empire_comm.png
deleted file mode 100644
index afe16ad..0000000
Binary files a/gfx/ship/lancelot_empire_comm.png and /dev/null differ
diff --git a/gfx/ship/lancelot_target.png b/gfx/ship/lancelot_target.png
deleted file mode 100644
index ca37e8b..0000000
Binary files a/gfx/ship/lancelot_target.png and /dev/null differ
diff --git a/gfx/ship/llama.png b/gfx/ship/llama.png
deleted file mode 100644
index 004fb73..0000000
Binary files a/gfx/ship/llama.png and /dev/null differ
diff --git a/gfx/ship/llama_comm.png b/gfx/ship/llama_comm.png
deleted file mode 100644
index b3bb8ea..0000000
Binary files a/gfx/ship/llama_comm.png and /dev/null differ
diff --git a/gfx/ship/llama_target.png b/gfx/ship/llama_target.png
deleted file mode 100644
index 8b11240..0000000
Binary files a/gfx/ship/llama_target.png and /dev/null differ
diff --git a/gfx/ship/mule.png b/gfx/ship/mule.png
deleted file mode 100644
index 69ff724..0000000
Binary files a/gfx/ship/mule.png and /dev/null differ
diff --git a/gfx/ship/mule_comm.png b/gfx/ship/mule_comm.png
deleted file mode 100644
index 25bc149..0000000
Binary files a/gfx/ship/mule_comm.png and /dev/null differ
diff --git a/gfx/ship/mule_target.png b/gfx/ship/mule_target.png
deleted file mode 100644
index 7949fa8..0000000
Binary files a/gfx/ship/mule_target.png and /dev/null differ
diff --git a/gfx/ship/pacifier.png b/gfx/ship/pacifier.png
deleted file mode 100644
index 667df5d..0000000
Binary files a/gfx/ship/pacifier.png and /dev/null differ
diff --git a/gfx/ship/pacifier_comm.png b/gfx/ship/pacifier_comm.png
deleted file mode 100644
index 44920cd..0000000
Binary files a/gfx/ship/pacifier_comm.png and /dev/null differ
diff --git a/gfx/ship/pacifier_empire.png b/gfx/ship/pacifier_empire.png
deleted file mode 100644
index 79111bf..0000000
Binary files a/gfx/ship/pacifier_empire.png and /dev/null differ
diff --git a/gfx/ship/pacifier_empire_comm.png b/gfx/ship/pacifier_empire_comm.png
deleted file mode 100644
index 694b5af..0000000
Binary files a/gfx/ship/pacifier_empire_comm.png and /dev/null differ
diff --git a/gfx/ship/pacifier_target.png b/gfx/ship/pacifier_target.png
deleted file mode 100644
index 3404256..0000000
Binary files a/gfx/ship/pacifier_target.png and /dev/null differ
diff --git a/gfx/ship/schroedinger.png b/gfx/ship/schroedinger.png
deleted file mode 100644
index 78ed8e4..0000000
Binary files a/gfx/ship/schroedinger.png and /dev/null differ
diff --git a/gfx/ship/schroedinger_comm.png b/gfx/ship/schroedinger_comm.png
deleted file mode 100644
index 8cf7bdd..0000000
Binary files a/gfx/ship/schroedinger_comm.png and /dev/null differ
diff --git a/gfx/ship/schroedinger_target.png b/gfx/ship/schroedinger_target.png
deleted file mode 100644
index 75aed09..0000000
Binary files a/gfx/ship/schroedinger_target.png and /dev/null differ
diff --git a/gfx/ship/vendetta.png b/gfx/ship/vendetta.png
deleted file mode 100644
index b95ac58..0000000
Binary files a/gfx/ship/vendetta.png and /dev/null differ
diff --git a/gfx/ship/vendetta_comm.png b/gfx/ship/vendetta_comm.png
deleted file mode 100644
index c96cc61..0000000
Binary files a/gfx/ship/vendetta_comm.png and /dev/null differ
diff --git a/gfx/ship/vendetta_dvaered.png b/gfx/ship/vendetta_dvaered.png
deleted file mode 100644
index bdff0bd..0000000
Binary files a/gfx/ship/vendetta_dvaered.png and /dev/null differ
diff --git a/gfx/ship/vendetta_dvaered_comm.png b/gfx/ship/vendetta_dvaered_comm.png
deleted file mode 100644
index 31a856b..0000000
Binary files a/gfx/ship/vendetta_dvaered_comm.png and /dev/null differ
diff --git a/gfx/ship/vendetta_pirate.png b/gfx/ship/vendetta_pirate.png
deleted file mode 100644
index 0345414..0000000
Binary files a/gfx/ship/vendetta_pirate.png and /dev/null differ
diff --git a/gfx/ship/vendetta_pirate_comm.png b/gfx/ship/vendetta_pirate_comm.png
deleted file mode 100644
index 83a3b5b..0000000
Binary files a/gfx/ship/vendetta_pirate_comm.png and /dev/null differ
diff --git a/gfx/ship/vendetta_target.png b/gfx/ship/vendetta_target.png
deleted file mode 100644
index ed57b68..0000000
Binary files a/gfx/ship/vendetta_target.png and /dev/null differ
diff --git a/gfx/spfx/cargo.png b/gfx/spfx/cargo.png
deleted file mode 100644
index 3bbed70..0000000
Binary files a/gfx/spfx/cargo.png and /dev/null differ
diff --git a/gfx/spfx/empm.png b/gfx/spfx/empm.png
deleted file mode 100644
index 57be2ea..0000000
Binary files a/gfx/spfx/empm.png and /dev/null differ
diff --git a/gfx/spfx/emps.png b/gfx/spfx/emps.png
deleted file mode 100644
index c215a72..0000000
Binary files a/gfx/spfx/emps.png and /dev/null differ
diff --git a/gfx/spfx/expl.png b/gfx/spfx/expl.png
deleted file mode 100644
index 1207166..0000000
Binary files a/gfx/spfx/expl.png and /dev/null differ
diff --git a/gfx/spfx/expm.png b/gfx/spfx/expm.png
deleted file mode 100644
index e3cec16..0000000
Binary files a/gfx/spfx/expm.png and /dev/null differ
diff --git a/gfx/spfx/exps.png b/gfx/spfx/exps.png
deleted file mode 100644
index d6bdb80..0000000
Binary files a/gfx/spfx/exps.png and /dev/null differ
diff --git a/gfx/spfx/plam.png b/gfx/spfx/plam.png
deleted file mode 100644
index ce98993..0000000
Binary files a/gfx/spfx/plam.png and /dev/null differ
diff --git a/gfx/spfx/plas.png b/gfx/spfx/plas.png
deleted file mode 100644
index 209e488..0000000
Binary files a/gfx/spfx/plas.png and /dev/null differ
diff --git a/gfx/spfx/shim.png b/gfx/spfx/shim.png
deleted file mode 100644
index b96e007..0000000
Binary files a/gfx/spfx/shim.png and /dev/null differ
diff --git a/gfx/spfx/shis.png b/gfx/spfx/shis.png
deleted file mode 100644
index 6f8bef2..0000000
Binary files a/gfx/spfx/shis.png and /dev/null differ
diff --git a/lib/csparse/Makefile b/lib/csparse/Makefile
deleted file mode 100644
index d8c65c9..0000000
--- a/lib/csparse/Makefile
+++ /dev/null
@@ -1,37 +0,0 @@
-CFLAGS := -O3
-
-AR := ar cr
-RANLIB := ranlib
-
-LIB := libcsparse.a
-
-RELPATH := lib/csparse
-
-all: libcsparse.a
-
-%.o: %.c
- @$(CC) -c $(CFLAGS) -o $@ $<
- @echo " CC $(RELPATH)$@"
-
-CS = cs_add.o cs_amd.o cs_chol.o cs_cholsol.o cs_counts.o cs_cumsum.o \
- cs_droptol.o cs_dropzeros.o cs_dupl.o cs_entry.o \
- cs_etree.o cs_fkeep.o cs_gaxpy.o cs_happly.o cs_house.o cs_ipvec.o \
- cs_lsolve.o cs_ltsolve.o cs_lu.o cs_lusol.o cs_util.o cs_multiply.o \
- cs_permute.o cs_pinv.o cs_post.o cs_pvec.o cs_qr.o cs_qrsol.o \
- cs_scatter.o cs_schol.o cs_sqr.o cs_symperm.o cs_tdfs.o cs_malloc.o \
- cs_transpose.o cs_compress.o cs_usolve.o cs_utsolve.o cs_scc.o \
- cs_maxtrans.o cs_dmperm.o cs_updown.o cs_print.o cs_norm.o cs_load.o \
- cs_dfs.o cs_reach.o cs_spsolve.o cs_ereach.o cs_leaf.o cs_randperm.o
-
-libcsparse.a: $(CS)
- @$(AR) $(LIB) $(CS)
- @$(RANLIB) $(LIB)
- @echo " LIB $(RELPATH)$@"
-
-clean:
- @$(RM) *.o
- @echo " Cleaning CSparse"
-
-distclean: clean
- @$(RM) *.a
-
diff --git a/lib/csparse/cs.h b/lib/csparse/cs.h
deleted file mode 100644
index e7867b0..0000000
--- a/lib/csparse/cs.h
+++ /dev/null
@@ -1,143 +0,0 @@
-#ifndef _CS_H
-#define _CS_H
-#include
-#include
-#include
-#include
-#ifdef MATLAB_MEX_FILE
-#include "mex.h"
-#endif
-#define CS_VER 2 /* CSparse Version 2.2.2 */
-#define CS_SUBVER 2
-#define CS_SUBSUB 2
-#define CS_DATE "Sept 23, 2008" /* CSparse release date */
-#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2008"
-
-/* --- primary CSparse routines and data structures ------------------------- */
-typedef struct cs_sparse /* matrix in compressed-column or triplet form */
-{
- int nzmax ; /* maximum number of entries */
- int m ; /* number of rows */
- int n ; /* number of columns */
- int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
- int *i ; /* row indices, size nzmax */
- double *x ; /* numerical values, size nzmax */
- int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
-} cs ;
-
-cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
-int cs_cholsol (int order, const cs *A, double *b) ;
-cs *cs_compress (const cs *T) ;
-int cs_dupl (cs *A) ;
-int cs_entry (cs *T, int i, int j, double x) ;
-int cs_gaxpy (const cs *A, const double *x, double *y) ;
-cs *cs_load (FILE *f) ;
-int cs_lusol (int order, const cs *A, double *b, double tol) ;
-cs *cs_multiply (const cs *A, const cs *B) ;
-double cs_norm (const cs *A) ;
-int cs_print (const cs *A, int brief) ;
-int cs_qrsol (int order, const cs *A, double *b) ;
-cs *cs_transpose (const cs *A, int values) ;
-/* utilities */
-void *cs_calloc (int n, size_t size) ;
-void *cs_free (void *p) ;
-void *cs_realloc (void *p, int n, size_t size, int *ok) ;
-cs *cs_spalloc (int m, int n, int nzmax, int values, int triplet) ;
-cs *cs_spfree (cs *A) ;
-int cs_sprealloc (cs *A, int nzmax) ;
-void *cs_malloc (int n, size_t size) ;
-
-/* --- secondary CSparse routines and data structures ----------------------- */
-typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */
-{
- int *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */
- int *q ; /* fill-reducing column permutation for LU and QR */
- int *parent ; /* elimination tree for Cholesky and QR */
- int *cp ; /* column pointers for Cholesky, row counts for QR */
- int *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */
- int m2 ; /* # of rows for QR, after adding fictitious rows */
- double lnz ; /* # entries in L for LU or Cholesky; in V for QR */
- double unz ; /* # entries in U for LU; in R for QR */
-} css ;
-
-typedef struct cs_numeric /* numeric Cholesky, LU, or QR factorization */
-{
- cs *L ; /* L for LU and Cholesky, V for QR */
- cs *U ; /* U for LU, R for QR, not used for Cholesky */
- int *pinv ; /* partial pivoting for LU */
- double *B ; /* beta [0..n-1] for QR */
-} csn ;
-
-typedef struct cs_dmperm_results /* cs_dmperm or cs_scc output */
-{
- int *p ; /* size m, row permutation */
- int *q ; /* size n, column permutation */
- int *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */
- int *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */
- int nb ; /* # of blocks in fine dmperm decomposition */
- int rr [5] ; /* coarse row decomposition */
- int cc [5] ; /* coarse column decomposition */
-} csd ;
-
-int *cs_amd (int order, const cs *A) ;
-csn *cs_chol (const cs *A, const css *S) ;
-csd *cs_dmperm (const cs *A, int seed) ;
-int cs_droptol (cs *A, double tol) ;
-int cs_dropzeros (cs *A) ;
-int cs_happly (const cs *V, int i, double beta, double *x) ;
-int cs_ipvec (const int *p, const double *b, double *x, int n) ;
-int cs_lsolve (const cs *L, double *x) ;
-int cs_ltsolve (const cs *L, double *x) ;
-csn *cs_lu (const cs *A, const css *S, double tol) ;
-cs *cs_permute (const cs *A, const int *pinv, const int *q, int values) ;
-int *cs_pinv (const int *p, int n) ;
-int cs_pvec (const int *p, const double *b, double *x, int n) ;
-csn *cs_qr (const cs *A, const css *S) ;
-css *cs_schol (int order, const cs *A) ;
-css *cs_sqr (int order, const cs *A, int qr) ;
-cs *cs_symperm (const cs *A, const int *pinv, int values) ;
-int cs_updown (cs *L, int sigma, const cs *C, const int *parent) ;
-int cs_usolve (const cs *U, double *x) ;
-int cs_utsolve (const cs *U, double *x) ;
-/* utilities */
-css *cs_sfree (css *S) ;
-csn *cs_nfree (csn *N) ;
-csd *cs_dfree (csd *D) ;
-
-/* --- tertiary CSparse routines -------------------------------------------- */
-int *cs_counts (const cs *A, const int *parent, const int *post, int ata) ;
-double cs_cumsum (int *p, int *c, int n) ;
-int cs_dfs (int j, cs *G, int top, int *xi, int *pstack, const int *pinv) ;
-int cs_ereach (const cs *A, int k, const int *parent, int *s, int *w) ;
-int *cs_etree (const cs *A, int ata) ;
-int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) ;
-double cs_house (double *x, double *beta, int n) ;
-int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf,
- int *ancestor, int *jleaf) ;
-int *cs_maxtrans (const cs *A, int seed) ;
-int *cs_post (const int *parent, int n) ;
-int *cs_randperm (int n, int seed) ;
-int cs_reach (cs *G, const cs *B, int k, int *xi, const int *pinv) ;
-int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark,
- cs *C, int nz) ;
-csd *cs_scc (cs *A) ;
-int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x,
- const int *pinv, int lo) ;
-int cs_tdfs (int j, int k, int *head, const int *next, int *post,
- int *stack) ;
-/* utilities */
-csd *cs_dalloc (int m, int n) ;
-csd *cs_ddone (csd *D, cs *C, void *w, int ok) ;
-cs *cs_done (cs *C, void *w, void *x, int ok) ;
-int *cs_idone (int *p, cs *C, void *w, int ok) ;
-csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok) ;
-
-#define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
-#define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
-#define CS_FLIP(i) (-(i)-2)
-#define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
-#define CS_MARKED(w,j) (w [j] < 0)
-#define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; }
-#define CS_CSC(A) (A && (A->nz == -1))
-#define CS_TRIPLET(A) (A && (A->nz >= 0))
-#endif
diff --git a/lib/csparse/cs_add.c b/lib/csparse/cs_add.c
deleted file mode 100644
index 2c3c146..0000000
--- a/lib/csparse/cs_add.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "cs.h"
-/* C = alpha*A + beta*B */
-cs *cs_add (const cs *A, const cs *B, double alpha, double beta)
-{
- int p, j, nz = 0, anz, *Cp, *Ci, *Bp, m, n, bnz, *w, values ;
- double *x, *Bx, *Cx ;
- cs *C ;
- if (!CS_CSC (A) || !CS_CSC (B)) return (NULL) ; /* check inputs */
- if (A->m != B->m || A->n != B->n) return (NULL) ;
- m = A->m ; anz = A->p [A->n] ;
- n = B->n ; Bp = B->p ; Bx = B->x ; bnz = Bp [n] ;
- w = cs_calloc (m, sizeof (int)) ; /* get workspace */
- values = (A->x != NULL) && (Bx != NULL) ;
- x = values ? cs_malloc (m, sizeof (double)) : NULL ; /* get workspace */
- C = cs_spalloc (m, n, anz + bnz, values, 0) ; /* allocate result*/
- if (!C || !w || (values && !x)) return (cs_done (C, w, x, 0)) ;
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- for (j = 0 ; j < n ; j++)
- {
- Cp [j] = nz ; /* column j of C starts here */
- nz = cs_scatter (A, j, alpha, w, x, j+1, C, nz) ; /* alpha*A(:,j)*/
- nz = cs_scatter (B, j, beta, w, x, j+1, C, nz) ; /* beta*B(:,j) */
- if (values) for (p = Cp [j] ; p < nz ; p++) Cx [p] = x [Ci [p]] ;
- }
- Cp [n] = nz ; /* finalize the last column of C */
- cs_sprealloc (C, 0) ; /* remove extra space from C */
- return (cs_done (C, w, x, 1)) ; /* success; free workspace, return C */
-}
diff --git a/lib/csparse/cs_amd.c b/lib/csparse/cs_amd.c
deleted file mode 100644
index 58b5d0e..0000000
--- a/lib/csparse/cs_amd.c
+++ /dev/null
@@ -1,364 +0,0 @@
-#include "cs.h"
-/* clear w */
-static int cs_wclear (int mark, int lemax, int *w, int n)
-{
- int k ;
- if (mark < 2 || (mark + lemax < 0))
- {
- for (k = 0 ; k < n ; k++) if (w [k] != 0) w [k] = 1 ;
- mark = 2 ;
- }
- return (mark) ; /* at this point, w [0..n-1] < mark holds */
-}
-
-/* keep off-diagonal entries; drop diagonal entries */
-static int cs_diag (int i, int j, double aij, void *other) { return (i != j) ; }
-
-/* p = amd(A+A') if symmetric is true, or amd(A'A) otherwise */
-int *cs_amd (int order, const cs *A) /* order 0:natural, 1:Chol, 2:LU, 3:QR */
-{
- cs *C, *A2, *AT ;
- int *Cp, *Ci, *last, *W, *len, *nv, *next, *P, *head, *elen, *degree, *w,
- *hhead, *ATp, *ATi, d, dk, dext, lemax = 0, e, elenk, eln, i, j, k, k1,
- k2, k3, jlast, ln, dense, nzmax, mindeg = 0, nvi, nvj, nvk, mark, wnvi,
- ok, cnz, nel = 0, p, p1, p2, p3, p4, pj, pk, pk1, pk2, pn, q, n, m, t ;
- unsigned int h ;
- /* --- Construct matrix C ----------------------------------------------- */
- if (!CS_CSC (A) || order <= 0 || order > 3) return (NULL) ; /* check */
- AT = cs_transpose (A, 0) ; /* compute A' */
- if (!AT) return (NULL) ;
- m = A->m ; n = A->n ;
- dense = CS_MAX (16, 10 * sqrt ((double) n)) ; /* find dense threshold */
- dense = CS_MIN (n-2, dense) ;
- if (order == 1 && n == m)
- {
- C = cs_add (A, AT, 0, 0) ; /* C = A+A' */
- }
- else if (order == 2)
- {
- ATp = AT->p ; /* drop dense columns from AT */
- ATi = AT->i ;
- for (p2 = 0, j = 0 ; j < m ; j++)
- {
- p = ATp [j] ; /* column j of AT starts here */
- ATp [j] = p2 ; /* new column j starts here */
- if (ATp [j+1] - p > dense) continue ; /* skip dense col j */
- for ( ; p < ATp [j+1] ; p++) ATi [p2++] = ATi [p] ;
- }
- ATp [m] = p2 ; /* finalize AT */
- A2 = cs_transpose (AT, 0) ; /* A2 = AT' */
- C = A2 ? cs_multiply (AT, A2) : NULL ; /* C=A'*A with no dense rows */
- cs_spfree (A2) ;
- }
- else
- {
- C = cs_multiply (AT, A) ; /* C=A'*A */
- }
- cs_spfree (AT) ;
- if (!C) return (NULL) ;
- cs_fkeep (C, &cs_diag, NULL) ; /* drop diagonal entries */
- Cp = C->p ;
- cnz = Cp [n] ;
- P = cs_malloc (n+1, sizeof (int)) ; /* allocate result */
- W = cs_malloc (8*(n+1), sizeof (int)) ; /* get workspace */
- t = cnz + cnz/5 + 2*n ; /* add elbow room to C */
- if (!P || !W || !cs_sprealloc (C, t)) return (cs_idone (P, C, W, 0)) ;
- len = W ; nv = W + (n+1) ; next = W + 2*(n+1) ;
- head = W + 3*(n+1) ; elen = W + 4*(n+1) ; degree = W + 5*(n+1) ;
- w = W + 6*(n+1) ; hhead = W + 7*(n+1) ;
- last = P ; /* use P as workspace for last */
- /* --- Initialize quotient graph ---------------------------------------- */
- for (k = 0 ; k < n ; k++) len [k] = Cp [k+1] - Cp [k] ;
- len [n] = 0 ;
- nzmax = C->nzmax ;
- Ci = C->i ;
- for (i = 0 ; i <= n ; i++)
- {
- head [i] = -1 ; /* degree list i is empty */
- last [i] = -1 ;
- next [i] = -1 ;
- hhead [i] = -1 ; /* hash list i is empty */
- nv [i] = 1 ; /* node i is just one node */
- w [i] = 1 ; /* node i is alive */
- elen [i] = 0 ; /* Ek of node i is empty */
- degree [i] = len [i] ; /* degree of node i */
- }
- mark = cs_wclear (0, 0, w, n) ; /* clear w */
- elen [n] = -2 ; /* n is a dead element */
- Cp [n] = -1 ; /* n is a root of assembly tree */
- w [n] = 0 ; /* n is a dead element */
- /* --- Initialize degree lists ------------------------------------------ */
- for (i = 0 ; i < n ; i++)
- {
- d = degree [i] ;
- if (d == 0) /* node i is empty */
- {
- elen [i] = -2 ; /* element i is dead */
- nel++ ;
- Cp [i] = -1 ; /* i is a root of assembly tree */
- w [i] = 0 ;
- }
- else if (d > dense) /* node i is dense */
- {
- nv [i] = 0 ; /* absorb i into element n */
- elen [i] = -1 ; /* node i is dead */
- nel++ ;
- Cp [i] = CS_FLIP (n) ;
- nv [n]++ ;
- }
- else
- {
- if (head [d] != -1) last [head [d]] = i ;
- next [i] = head [d] ; /* put node i in degree list d */
- head [d] = i ;
- }
- }
- while (nel < n) /* while (selecting pivots) do */
- {
- /* --- Select node of minimum approximate degree -------------------- */
- for (k = -1 ; mindeg < n && (k = head [mindeg]) == -1 ; mindeg++) ;
- if (next [k] != -1) last [next [k]] = -1 ;
- head [mindeg] = next [k] ; /* remove k from degree list */
- elenk = elen [k] ; /* elenk = |Ek| */
- nvk = nv [k] ; /* # of nodes k represents */
- nel += nvk ; /* nv[k] nodes of A eliminated */
- /* --- Garbage collection ------------------------------------------- */
- if (elenk > 0 && cnz + mindeg >= nzmax)
- {
- for (j = 0 ; j < n ; j++)
- {
- if ((p = Cp [j]) >= 0) /* j is a live node or element */
- {
- Cp [j] = Ci [p] ; /* save first entry of object */
- Ci [p] = CS_FLIP (j) ; /* first entry is now CS_FLIP(j) */
- }
- }
- for (q = 0, p = 0 ; p < cnz ; ) /* scan all of memory */
- {
- if ((j = CS_FLIP (Ci [p++])) >= 0) /* found object j */
- {
- Ci [q] = Cp [j] ; /* restore first entry of object */
- Cp [j] = q++ ; /* new pointer to object j */
- for (k3 = 0 ; k3 < len [j]-1 ; k3++) Ci [q++] = Ci [p++] ;
- }
- }
- cnz = q ; /* Ci [cnz...nzmax-1] now free */
- }
- /* --- Construct new element ---------------------------------------- */
- dk = 0 ;
- nv [k] = -nvk ; /* flag k as in Lk */
- p = Cp [k] ;
- pk1 = (elenk == 0) ? p : cnz ; /* do in place if elen[k] == 0 */
- pk2 = pk1 ;
- for (k1 = 1 ; k1 <= elenk + 1 ; k1++)
- {
- if (k1 > elenk)
- {
- e = k ; /* search the nodes in k */
- pj = p ; /* list of nodes starts at Ci[pj]*/
- ln = len [k] - elenk ; /* length of list of nodes in k */
- }
- else
- {
- e = Ci [p++] ; /* search the nodes in e */
- pj = Cp [e] ;
- ln = len [e] ; /* length of list of nodes in e */
- }
- for (k2 = 1 ; k2 <= ln ; k2++)
- {
- i = Ci [pj++] ;
- if ((nvi = nv [i]) <= 0) continue ; /* node i dead, or seen */
- dk += nvi ; /* degree[Lk] += size of node i */
- nv [i] = -nvi ; /* negate nv[i] to denote i in Lk*/
- Ci [pk2++] = i ; /* place i in Lk */
- if (next [i] != -1) last [next [i]] = last [i] ;
- if (last [i] != -1) /* remove i from degree list */
- {
- next [last [i]] = next [i] ;
- }
- else
- {
- head [degree [i]] = next [i] ;
- }
- }
- if (e != k)
- {
- Cp [e] = CS_FLIP (k) ; /* absorb e into k */
- w [e] = 0 ; /* e is now a dead element */
- }
- }
- if (elenk != 0) cnz = pk2 ; /* Ci [cnz...nzmax] is free */
- degree [k] = dk ; /* external degree of k - |Lk\i| */
- Cp [k] = pk1 ; /* element k is in Ci[pk1..pk2-1] */
- len [k] = pk2 - pk1 ;
- elen [k] = -2 ; /* k is now an element */
- /* --- Find set differences ----------------------------------------- */
- mark = cs_wclear (mark, lemax, w, n) ; /* clear w if necessary */
- for (pk = pk1 ; pk < pk2 ; pk++) /* scan 1: find |Le\Lk| */
- {
- i = Ci [pk] ;
- if ((eln = elen [i]) <= 0) continue ;/* skip if elen[i] empty */
- nvi = -nv [i] ; /* nv [i] was negated */
- wnvi = mark - nvi ;
- for (p = Cp [i] ; p <= Cp [i] + eln - 1 ; p++) /* scan Ei */
- {
- e = Ci [p] ;
- if (w [e] >= mark)
- {
- w [e] -= nvi ; /* decrement |Le\Lk| */
- }
- else if (w [e] != 0) /* ensure e is a live element */
- {
- w [e] = degree [e] + wnvi ; /* 1st time e seen in scan 1 */
- }
- }
- }
- /* --- Degree update ------------------------------------------------ */
- for (pk = pk1 ; pk < pk2 ; pk++) /* scan2: degree update */
- {
- i = Ci [pk] ; /* consider node i in Lk */
- p1 = Cp [i] ;
- p2 = p1 + elen [i] - 1 ;
- pn = p1 ;
- for (h = 0, d = 0, p = p1 ; p <= p2 ; p++) /* scan Ei */
- {
- e = Ci [p] ;
- if (w [e] != 0) /* e is an unabsorbed element */
- {
- dext = w [e] - mark ; /* dext = |Le\Lk| */
- if (dext > 0)
- {
- d += dext ; /* sum up the set differences */
- Ci [pn++] = e ; /* keep e in Ei */
- h += e ; /* compute the hash of node i */
- }
- else
- {
- Cp [e] = CS_FLIP (k) ; /* aggressive absorb. e->k */
- w [e] = 0 ; /* e is a dead element */
- }
- }
- }
- elen [i] = pn - p1 + 1 ; /* elen[i] = |Ei| */
- p3 = pn ;
- p4 = p1 + len [i] ;
- for (p = p2 + 1 ; p < p4 ; p++) /* prune edges in Ai */
- {
- j = Ci [p] ;
- if ((nvj = nv [j]) <= 0) continue ; /* node j dead or in Lk */
- d += nvj ; /* degree(i) += |j| */
- Ci [pn++] = j ; /* place j in node list of i */
- h += j ; /* compute hash for node i */
- }
- if (d == 0) /* check for mass elimination */
- {
- Cp [i] = CS_FLIP (k) ; /* absorb i into k */
- nvi = -nv [i] ;
- dk -= nvi ; /* |Lk| -= |i| */
- nvk += nvi ; /* |k| += nv[i] */
- nel += nvi ;
- nv [i] = 0 ;
- elen [i] = -1 ; /* node i is dead */
- }
- else
- {
- degree [i] = CS_MIN (degree [i], d) ; /* update degree(i) */
- Ci [pn] = Ci [p3] ; /* move first node to end */
- Ci [p3] = Ci [p1] ; /* move 1st el. to end of Ei */
- Ci [p1] = k ; /* add k as 1st element in of Ei */
- len [i] = pn - p1 + 1 ; /* new len of adj. list of node i */
- h %= n ; /* finalize hash of i */
- next [i] = hhead [h] ; /* place i in hash bucket */
- hhead [h] = i ;
- last [i] = h ; /* save hash of i in last[i] */
- }
- } /* scan2 is done */
- degree [k] = dk ; /* finalize |Lk| */
- lemax = CS_MAX (lemax, dk) ;
- mark = cs_wclear (mark+lemax, lemax, w, n) ; /* clear w */
- /* --- Supernode detection ------------------------------------------ */
- for (pk = pk1 ; pk < pk2 ; pk++)
- {
- i = Ci [pk] ;
- if (nv [i] >= 0) continue ; /* skip if i is dead */
- h = last [i] ; /* scan hash bucket of node i */
- i = hhead [h] ;
- hhead [h] = -1 ; /* hash bucket will be empty */
- for ( ; i != -1 && next [i] != -1 ; i = next [i], mark++)
- {
- ln = len [i] ;
- eln = elen [i] ;
- for (p = Cp [i]+1 ; p <= Cp [i] + ln-1 ; p++) w [Ci [p]] = mark;
- jlast = i ;
- for (j = next [i] ; j != -1 ; ) /* compare i with all j */
- {
- ok = (len [j] == ln) && (elen [j] == eln) ;
- for (p = Cp [j] + 1 ; ok && p <= Cp [j] + ln - 1 ; p++)
- {
- if (w [Ci [p]] != mark) ok = 0 ; /* compare i and j*/
- }
- if (ok) /* i and j are identical */
- {
- Cp [j] = CS_FLIP (i) ; /* absorb j into i */
- nv [i] += nv [j] ;
- nv [j] = 0 ;
- elen [j] = -1 ; /* node j is dead */
- j = next [j] ; /* delete j from hash bucket */
- next [jlast] = j ;
- }
- else
- {
- jlast = j ; /* j and i are different */
- j = next [j] ;
- }
- }
- }
- }
- /* --- Finalize new element------------------------------------------ */
- for (p = pk1, pk = pk1 ; pk < pk2 ; pk++) /* finalize Lk */
- {
- i = Ci [pk] ;
- if ((nvi = -nv [i]) <= 0) continue ;/* skip if i is dead */
- nv [i] = nvi ; /* restore nv[i] */
- d = degree [i] + dk - nvi ; /* compute external degree(i) */
- d = CS_MIN (d, n - nel - nvi) ;
- if (head [d] != -1) last [head [d]] = i ;
- next [i] = head [d] ; /* put i back in degree list */
- last [i] = -1 ;
- head [d] = i ;
- mindeg = CS_MIN (mindeg, d) ; /* find new minimum degree */
- degree [i] = d ;
- Ci [p++] = i ; /* place i in Lk */
- }
- nv [k] = nvk ; /* # nodes absorbed into k */
- if ((len [k] = p-pk1) == 0) /* length of adj list of element k*/
- {
- Cp [k] = -1 ; /* k is a root of the tree */
- w [k] = 0 ; /* k is now a dead element */
- }
- if (elenk != 0) cnz = p ; /* free unused space in Lk */
- }
- /* --- Postordering ----------------------------------------------------- */
- for (i = 0 ; i < n ; i++) Cp [i] = CS_FLIP (Cp [i]) ;/* fix assembly tree */
- for (j = 0 ; j <= n ; j++) head [j] = -1 ;
- for (j = n ; j >= 0 ; j--) /* place unordered nodes in lists */
- {
- if (nv [j] > 0) continue ; /* skip if j is an element */
- next [j] = head [Cp [j]] ; /* place j in list of its parent */
- head [Cp [j]] = j ;
- }
- for (e = n ; e >= 0 ; e--) /* place elements in lists */
- {
- if (nv [e] <= 0) continue ; /* skip unless e is an element */
- if (Cp [e] != -1)
- {
- next [e] = head [Cp [e]] ; /* place e in list of its parent */
- head [Cp [e]] = e ;
- }
- }
- for (k = 0, i = 0 ; i <= n ; i++) /* postorder the assembly tree */
- {
- if (Cp [i] == -1) k = cs_tdfs (i, k, head, next, P, w) ;
- }
- return (cs_idone (P, C, W, 1)) ;
-}
diff --git a/lib/csparse/cs_chol.c b/lib/csparse/cs_chol.c
deleted file mode 100644
index 5eb12b3..0000000
--- a/lib/csparse/cs_chol.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "cs.h"
-/* L = chol (A, [pinv parent cp]), pinv is optional */
-csn *cs_chol (const cs *A, const css *S)
-{
- double d, lki, *Lx, *x, *Cx ;
- int top, i, p, k, n, *Li, *Lp, *cp, *pinv, *s, *c, *parent, *Cp, *Ci ;
- cs *L, *C, *E ;
- csn *N ;
- if (!CS_CSC (A) || !S || !S->cp || !S->parent) return (NULL) ;
- n = A->n ;
- N = cs_calloc (1, sizeof (csn)) ; /* allocate result */
- c = cs_malloc (2*n, sizeof (int)) ; /* get int workspace */
- x = cs_malloc (n, sizeof (double)) ; /* get double workspace */
- cp = S->cp ; pinv = S->pinv ; parent = S->parent ;
- C = pinv ? cs_symperm (A, pinv, 1) : ((cs *) A) ;
- E = pinv ? C : NULL ; /* E is alias for A, or a copy E=A(p,p) */
- if (!N || !c || !x || !C) return (cs_ndone (N, E, c, x, 0)) ;
- s = c + n ;
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- N->L = L = cs_spalloc (n, n, cp [n], 1, 0) ; /* allocate result */
- if (!L) return (cs_ndone (N, E, c, x, 0)) ;
- Lp = L->p ; Li = L->i ; Lx = L->x ;
- for (k = 0 ; k < n ; k++) Lp [k] = c [k] = cp [k] ;
- for (k = 0 ; k < n ; k++) /* compute L(:,k) for L*L' = C */
- {
- /* --- Nonzero pattern of L(k,:) ------------------------------------ */
- top = cs_ereach (C, k, parent, s, c) ; /* find pattern of L(k,:) */
- x [k] = 0 ; /* x (0:k) is now zero */
- for (p = Cp [k] ; p < Cp [k+1] ; p++) /* x = full(triu(C(:,k))) */
- {
- if (Ci [p] <= k) x [Ci [p]] = Cx [p] ;
- }
- d = x [k] ; /* d = C(k,k) */
- x [k] = 0 ; /* clear x for k+1st iteration */
- /* --- Triangular solve --------------------------------------------- */
- for ( ; top < n ; top++) /* solve L(0:k-1,0:k-1) * x = C(:,k) */
- {
- i = s [top] ; /* s [top..n-1] is pattern of L(k,:) */
- lki = x [i] / Lx [Lp [i]] ; /* L(k,i) = x (i) / L(i,i) */
- x [i] = 0 ; /* clear x for k+1st iteration */
- for (p = Lp [i] + 1 ; p < c [i] ; p++)
- {
- x [Li [p]] -= Lx [p] * lki ;
- }
- d -= lki * lki ; /* d = d - L(k,i)*L(k,i) */
- p = c [i]++ ;
- Li [p] = k ; /* store L(k,i) in column i */
- Lx [p] = lki ;
- }
- /* --- Compute L(k,k) ----------------------------------------------- */
- if (d <= 0) return (cs_ndone (N, E, c, x, 0)) ; /* not pos def */
- p = c [k]++ ;
- Li [p] = k ; /* store L(k,k) = sqrt (d) in column k */
- Lx [p] = sqrt (d) ;
- }
- Lp [n] = cp [n] ; /* finalize L */
- return (cs_ndone (N, E, c, x, 1)) ; /* success: free E,s,x; return N */
-}
diff --git a/lib/csparse/cs_cholsol.c b/lib/csparse/cs_cholsol.c
deleted file mode 100644
index f3cf414..0000000
--- a/lib/csparse/cs_cholsol.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "cs.h"
-/* x=A\b where A is symmetric positive definite; b overwritten with solution */
-int cs_cholsol (int order, const cs *A, double *b)
-{
- double *x ;
- css *S ;
- csn *N ;
- int n, ok ;
- if (!CS_CSC (A) || !b) return (0) ; /* check inputs */
- n = A->n ;
- S = cs_schol (order, A) ; /* ordering and symbolic analysis */
- N = cs_chol (A, S) ; /* numeric Cholesky factorization */
- x = cs_malloc (n, sizeof (double)) ; /* get workspace */
- ok = (S && N && x) ;
- if (ok)
- {
- cs_ipvec (S->pinv, b, x, n) ; /* x = P*b */
- cs_lsolve (N->L, x) ; /* x = L\x */
- cs_ltsolve (N->L, x) ; /* x = L'\x */
- cs_pvec (S->pinv, x, b, n) ; /* b = P'*x */
- }
- cs_free (x) ;
- cs_sfree (S) ;
- cs_nfree (N) ;
- return (ok) ;
-}
diff --git a/lib/csparse/cs_compress.c b/lib/csparse/cs_compress.c
deleted file mode 100644
index d18e840..0000000
--- a/lib/csparse/cs_compress.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "cs.h"
-/* C = compressed-column form of a triplet matrix T */
-cs *cs_compress (const cs *T)
-{
- int m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj ;
- double *Cx, *Tx ;
- cs *C ;
- if (!CS_TRIPLET (T)) return (NULL) ; /* check inputs */
- m = T->m ; n = T->n ; Ti = T->i ; Tj = T->p ; Tx = T->x ; nz = T->nz ;
- C = cs_spalloc (m, n, nz, Tx != NULL, 0) ; /* allocate result */
- w = cs_calloc (n, sizeof (int)) ; /* get workspace */
- if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- for (k = 0 ; k < nz ; k++) w [Tj [k]]++ ; /* column counts */
- cs_cumsum (Cp, w, n) ; /* column pointers */
- for (k = 0 ; k < nz ; k++)
- {
- Ci [p = w [Tj [k]]++] = Ti [k] ; /* A(i,j) is the pth entry in C */
- if (Cx) Cx [p] = Tx [k] ;
- }
- return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */
-}
diff --git a/lib/csparse/cs_counts.c b/lib/csparse/cs_counts.c
deleted file mode 100644
index ff32b6f..0000000
--- a/lib/csparse/cs_counts.c
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "cs.h"
-/* column counts of LL'=A or LL'=A'A, given parent & post ordering */
-#define HEAD(k,j) (ata ? head [k] : j)
-#define NEXT(J) (ata ? next [J] : -1)
-static void init_ata (cs *AT, const int *post, int *w, int **head, int **next)
-{
- int i, k, p, m = AT->n, n = AT->m, *ATp = AT->p, *ATi = AT->i ;
- *head = w+4*n, *next = w+5*n+1 ;
- for (k = 0 ; k < n ; k++) w [post [k]] = k ; /* invert post */
- for (i = 0 ; i < m ; i++)
- {
- for (k = n, p = ATp[i] ; p < ATp[i+1] ; p++) k = CS_MIN (k, w [ATi[p]]);
- (*next) [i] = (*head) [k] ; /* place row i in linked list k */
- (*head) [k] = i ;
- }
-}
-int *cs_counts (const cs *A, const int *parent, const int *post, int ata)
-{
- int i, j, k, n, m, J, s, p, q, jleaf, *ATp, *ATi, *maxfirst, *prevleaf,
- *ancestor, *head = NULL, *next = NULL, *colcount, *w, *first, *delta ;
- cs *AT ;
- if (!CS_CSC (A) || !parent || !post) return (NULL) ; /* check inputs */
- m = A->m ; n = A->n ;
- s = 4*n + (ata ? (n+m+1) : 0) ;
- delta = colcount = cs_malloc (n, sizeof (int)) ; /* allocate result */
- w = cs_malloc (s, sizeof (int)) ; /* get workspace */
- AT = cs_transpose (A, 0) ; /* AT = A' */
- if (!AT || !colcount || !w) return (cs_idone (colcount, AT, w, 0)) ;
- ancestor = w ; maxfirst = w+n ; prevleaf = w+2*n ; first = w+3*n ;
- for (k = 0 ; k < s ; k++) w [k] = -1 ; /* clear workspace w [0..s-1] */
- for (k = 0 ; k < n ; k++) /* find first [j] */
- {
- j = post [k] ;
- delta [j] = (first [j] == -1) ? 1 : 0 ; /* delta[j]=1 if j is a leaf */
- for ( ; j != -1 && first [j] == -1 ; j = parent [j]) first [j] = k ;
- }
- ATp = AT->p ; ATi = AT->i ;
- if (ata) init_ata (AT, post, w, &head, &next) ;
- for (i = 0 ; i < n ; i++) ancestor [i] = i ; /* each node in its own set */
- for (k = 0 ; k < n ; k++)
- {
- j = post [k] ; /* j is the kth node in postordered etree */
- if (parent [j] != -1) delta [parent [j]]-- ; /* j is not a root */
- for (J = HEAD (k,j) ; J != -1 ; J = NEXT (J)) /* J=j for LL'=A case */
- {
- for (p = ATp [J] ; p < ATp [J+1] ; p++)
- {
- i = ATi [p] ;
- q = cs_leaf (i, j, first, maxfirst, prevleaf, ancestor, &jleaf);
- if (jleaf >= 1) delta [j]++ ; /* A(i,j) is in skeleton */
- if (jleaf == 2) delta [q]-- ; /* account for overlap in q */
- }
- }
- if (parent [j] != -1) ancestor [j] = parent [j] ;
- }
- for (j = 0 ; j < n ; j++) /* sum up delta's of each child */
- {
- if (parent [j] != -1) colcount [parent [j]] += colcount [j] ;
- }
- return (cs_idone (colcount, AT, w, 1)) ; /* success: free workspace */
-}
diff --git a/lib/csparse/cs_cumsum.c b/lib/csparse/cs_cumsum.c
deleted file mode 100644
index b8b7778..0000000
--- a/lib/csparse/cs_cumsum.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "cs.h"
-/* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
-double cs_cumsum (int *p, int *c, int n)
-{
- int i, nz = 0 ;
- double nz2 = 0 ;
- if (!p || !c) return (-1) ; /* check inputs */
- for (i = 0 ; i < n ; i++)
- {
- p [i] = nz ;
- nz += c [i] ;
- nz2 += c [i] ; /* also in double to avoid int overflow */
- c [i] = p [i] ; /* also copy p[0..n-1] back into c[0..n-1]*/
- }
- p [n] = nz ;
- return (nz2) ; /* return sum (c [0..n-1]) */
-}
diff --git a/lib/csparse/cs_dfs.c b/lib/csparse/cs_dfs.c
deleted file mode 100644
index 250dcf3..0000000
--- a/lib/csparse/cs_dfs.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "cs.h"
-/* depth-first-search of the graph of a matrix, starting at node j */
-int cs_dfs (int j, cs *G, int top, int *xi, int *pstack, const int *pinv)
-{
- int i, p, p2, done, jnew, head = 0, *Gp, *Gi ;
- if (!CS_CSC (G) || !xi || !pstack) return (-1) ; /* check inputs */
- Gp = G->p ; Gi = G->i ;
- xi [0] = j ; /* initialize the recursion stack */
- while (head >= 0)
- {
- j = xi [head] ; /* get j from the top of the recursion stack */
- jnew = pinv ? (pinv [j]) : j ;
- if (!CS_MARKED (Gp, j))
- {
- CS_MARK (Gp, j) ; /* mark node j as visited */
- pstack [head] = (jnew < 0) ? 0 : CS_UNFLIP (Gp [jnew]) ;
- }
- done = 1 ; /* node j done if no unvisited neighbors */
- p2 = (jnew < 0) ? 0 : CS_UNFLIP (Gp [jnew+1]) ;
- for (p = pstack [head] ; p < p2 ; p++) /* examine all neighbors of j */
- {
- i = Gi [p] ; /* consider neighbor node i */
- if (CS_MARKED (Gp, i)) continue ; /* skip visited node i */
- pstack [head] = p ; /* pause depth-first search of node j */
- xi [++head] = i ; /* start dfs at node i */
- done = 0 ; /* node j is not done */
- break ; /* break, to start dfs (i) */
- }
- if (done) /* depth-first search at node j is done */
- {
- head-- ; /* remove j from the recursion stack */
- xi [--top] = j ; /* and place in the output stack */
- }
- }
- return (top) ;
-}
diff --git a/lib/csparse/cs_dmperm.c b/lib/csparse/cs_dmperm.c
deleted file mode 100644
index 29f72f6..0000000
--- a/lib/csparse/cs_dmperm.c
+++ /dev/null
@@ -1,144 +0,0 @@
-#include "cs.h"
-/* breadth-first search for coarse decomposition (C0,C1,R1 or R0,R3,C3) */
-static int cs_bfs (const cs *A, int n, int *wi, int *wj, int *queue,
- const int *imatch, const int *jmatch, int mark)
-{
- int *Ap, *Ai, head = 0, tail = 0, j, i, p, j2 ;
- cs *C ;
- for (j = 0 ; j < n ; j++) /* place all unmatched nodes in queue */
- {
- if (imatch [j] >= 0) continue ; /* skip j if matched */
- wj [j] = 0 ; /* j in set C0 (R0 if transpose) */
- queue [tail++] = j ; /* place unmatched col j in queue */
- }
- if (tail == 0) return (1) ; /* quick return if no unmatched nodes */
- C = (mark == 1) ? ((cs *) A) : cs_transpose (A, 0) ;
- if (!C) return (0) ; /* bfs of C=A' to find R3,C3 from R0 */
- Ap = C->p ; Ai = C->i ;
- while (head < tail) /* while queue is not empty */
- {
- j = queue [head++] ; /* get the head of the queue */
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ;
- if (wi [i] >= 0) continue ; /* skip if i is marked */
- wi [i] = mark ; /* i in set R1 (C3 if transpose) */
- j2 = jmatch [i] ; /* traverse alternating path to j2 */
- if (wj [j2] >= 0) continue ;/* skip j2 if it is marked */
- wj [j2] = mark ; /* j2 in set C1 (R3 if transpose) */
- queue [tail++] = j2 ; /* add j2 to queue */
- }
- }
- if (mark != 1) cs_spfree (C) ; /* free A' if it was created */
- return (1) ;
-}
-
-/* collect matched rows and columns into p and q */
-static void cs_matched (int n, const int *wj, const int *imatch, int *p, int *q,
- int *cc, int *rr, int set, int mark)
-{
- int kc = cc [set], j ;
- int kr = rr [set-1] ;
- for (j = 0 ; j < n ; j++)
- {
- if (wj [j] != mark) continue ; /* skip if j is not in C set */
- p [kr++] = imatch [j] ;
- q [kc++] = j ;
- }
- cc [set+1] = kc ;
- rr [set] = kr ;
-}
-
-/* collect unmatched rows into the permutation vector p */
-static void cs_unmatched (int m, const int *wi, int *p, int *rr, int set)
-{
- int i, kr = rr [set] ;
- for (i = 0 ; i < m ; i++) if (wi [i] == 0) p [kr++] = i ;
- rr [set+1] = kr ;
-}
-
-/* return 1 if row i is in R2 */
-static int cs_rprune (int i, int j, double aij, void *other)
-{
- int *rr = (int *) other ;
- return (i >= rr [1] && i < rr [2]) ;
-}
-
-/* Given A, compute coarse and then fine dmperm */
-csd *cs_dmperm (const cs *A, int seed)
-{
- int m, n, i, j, k, cnz, nc, *jmatch, *imatch, *wi, *wj, *pinv, *Cp, *Ci,
- *ps, *rs, nb1, nb2, *p, *q, *cc, *rr, *r, *s, ok ;
- cs *C ;
- csd *D, *scc ;
- /* --- Maximum matching ------------------------------------------------- */
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- m = A->m ; n = A->n ;
- D = cs_dalloc (m, n) ; /* allocate result */
- if (!D) return (NULL) ;
- p = D->p ; q = D->q ; r = D->r ; s = D->s ; cc = D->cc ; rr = D->rr ;
- jmatch = cs_maxtrans (A, seed) ; /* max transversal */
- imatch = jmatch + m ; /* imatch = inverse of jmatch */
- if (!jmatch) return (cs_ddone (D, NULL, jmatch, 0)) ;
- /* --- Coarse decomposition --------------------------------------------- */
- wi = r ; wj = s ; /* use r and s as workspace */
- for (j = 0 ; j < n ; j++) wj [j] = -1 ; /* unmark all cols for bfs */
- for (i = 0 ; i < m ; i++) wi [i] = -1 ; /* unmark all rows for bfs */
- cs_bfs (A, n, wi, wj, q, imatch, jmatch, 1) ; /* find C1, R1 from C0*/
- ok = cs_bfs (A, m, wj, wi, p, jmatch, imatch, 3) ; /* find R3, C3 from R0*/
- if (!ok) return (cs_ddone (D, NULL, jmatch, 0)) ;
- cs_unmatched (n, wj, q, cc, 0) ; /* unmatched set C0 */
- cs_matched (n, wj, imatch, p, q, cc, rr, 1, 1) ; /* set R1 and C1 */
- cs_matched (n, wj, imatch, p, q, cc, rr, 2, -1) ; /* set R2 and C2 */
- cs_matched (n, wj, imatch, p, q, cc, rr, 3, 3) ; /* set R3 and C3 */
- cs_unmatched (m, wi, p, rr, 3) ; /* unmatched set R0 */
- cs_free (jmatch) ;
- /* --- Fine decomposition ----------------------------------------------- */
- pinv = cs_pinv (p, m) ; /* pinv=p' */
- if (!pinv) return (cs_ddone (D, NULL, NULL, 0)) ;
- C = cs_permute (A, pinv, q, 0) ;/* C=A(p,q) (it will hold A(R2,C2)) */
- cs_free (pinv) ;
- if (!C) return (cs_ddone (D, NULL, NULL, 0)) ;
- Cp = C->p ;
- nc = cc [3] - cc [2] ; /* delete cols C0, C1, and C3 from C */
- if (cc [2] > 0) for (j = cc [2] ; j <= cc [3] ; j++) Cp [j-cc[2]] = Cp [j] ;
- C->n = nc ;
- if (rr [2] - rr [1] < m) /* delete rows R0, R1, and R3 from C */
- {
- cs_fkeep (C, cs_rprune, rr) ;
- cnz = Cp [nc] ;
- Ci = C->i ;
- if (rr [1] > 0) for (k = 0 ; k < cnz ; k++) Ci [k] -= rr [1] ;
- }
- C->m = nc ;
- scc = cs_scc (C) ; /* find strongly connected components of C*/
- if (!scc) return (cs_ddone (D, C, NULL, 0)) ;
- /* --- Combine coarse and fine decompositions --------------------------- */
- ps = scc->p ; /* C(ps,ps) is the permuted matrix */
- rs = scc->r ; /* kth block is rs[k]..rs[k+1]-1 */
- nb1 = scc->nb ; /* # of blocks of A(R2,C2) */
- for (k = 0 ; k < nc ; k++) wj [k] = q [ps [k] + cc [2]] ;
- for (k = 0 ; k < nc ; k++) q [k + cc [2]] = wj [k] ;
- for (k = 0 ; k < nc ; k++) wi [k] = p [ps [k] + rr [1]] ;
- for (k = 0 ; k < nc ; k++) p [k + rr [1]] = wi [k] ;
- nb2 = 0 ; /* create the fine block partitions */
- r [0] = s [0] = 0 ;
- if (cc [2] > 0) nb2++ ; /* leading coarse block A (R1, [C0 C1]) */
- for (k = 0 ; k < nb1 ; k++) /* coarse block A (R2,C2) */
- {
- r [nb2] = rs [k] + rr [1] ; /* A (R2,C2) splits into nb1 fine blocks */
- s [nb2] = rs [k] + cc [2] ;
- nb2++ ;
- }
- if (rr [2] < m)
- {
- r [nb2] = rr [2] ; /* trailing coarse block A ([R3 R0], C3) */
- s [nb2] = cc [3] ;
- nb2++ ;
- }
- r [nb2] = m ;
- s [nb2] = n ;
- D->nb = nb2 ;
- cs_dfree (scc) ;
- return (cs_ddone (D, C, NULL, 1)) ;
-}
diff --git a/lib/csparse/cs_droptol.c b/lib/csparse/cs_droptol.c
deleted file mode 100644
index 2afb660..0000000
--- a/lib/csparse/cs_droptol.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "cs.h"
-static int cs_tol (int i, int j, double aij, void *tol)
-{
- return (fabs (aij) > *((double *) tol)) ;
-}
-int cs_droptol (cs *A, double tol)
-{
- return (cs_fkeep (A, &cs_tol, &tol)) ; /* keep all large entries */
-}
diff --git a/lib/csparse/cs_dropzeros.c b/lib/csparse/cs_dropzeros.c
deleted file mode 100644
index 441e54d..0000000
--- a/lib/csparse/cs_dropzeros.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "cs.h"
-static int cs_nonzero (int i, int j, double aij, void *other)
-{
- return (aij != 0) ;
-}
-int cs_dropzeros (cs *A)
-{
- return (cs_fkeep (A, &cs_nonzero, NULL)) ; /* keep all nonzero entries */
-}
diff --git a/lib/csparse/cs_dupl.c b/lib/csparse/cs_dupl.c
deleted file mode 100644
index 7a60d63..0000000
--- a/lib/csparse/cs_dupl.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "cs.h"
-/* remove duplicate entries from A */
-int cs_dupl (cs *A)
-{
- int i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ;
- double *Ax ;
- if (!CS_CSC (A)) return (0) ; /* check inputs */
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- w = cs_malloc (m, sizeof (int)) ; /* get workspace */
- if (!w) return (0) ; /* out of memory */
- for (i = 0 ; i < m ; i++) w [i] = -1 ; /* row i not yet seen */
- for (j = 0 ; j < n ; j++)
- {
- q = nz ; /* column j will start at q */
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ; /* A(i,j) is nonzero */
- if (w [i] >= q)
- {
- Ax [w [i]] += Ax [p] ; /* A(i,j) is a duplicate */
- }
- else
- {
- w [i] = nz ; /* record where row i occurs */
- Ai [nz] = i ; /* keep A(i,j) */
- Ax [nz++] = Ax [p] ;
- }
- }
- Ap [j] = q ; /* record start of column j */
- }
- Ap [n] = nz ; /* finalize A */
- cs_free (w) ; /* free workspace */
- return (cs_sprealloc (A, 0)) ; /* remove extra space from A */
-}
diff --git a/lib/csparse/cs_entry.c b/lib/csparse/cs_entry.c
deleted file mode 100644
index 98f6788..0000000
--- a/lib/csparse/cs_entry.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "cs.h"
-/* add an entry to a triplet matrix; return 1 if ok, 0 otherwise */
-int cs_entry (cs *T, int i, int j, double x)
-{
- if (!CS_TRIPLET (T) || i < 0 || j < 0) return (0) ; /* check inputs */
- if (T->nz >= T->nzmax && !cs_sprealloc (T,2*(T->nzmax))) return (0) ;
- if (T->x) T->x [T->nz] = x ;
- T->i [T->nz] = i ;
- T->p [T->nz++] = j ;
- T->m = CS_MAX (T->m, i+1) ;
- T->n = CS_MAX (T->n, j+1) ;
- return (1) ;
-}
diff --git a/lib/csparse/cs_ereach.c b/lib/csparse/cs_ereach.c
deleted file mode 100644
index c54213b..0000000
--- a/lib/csparse/cs_ereach.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "cs.h"
-/* find nonzero pattern of Cholesky L(k,1:k-1) using etree and triu(A(:,k)) */
-int cs_ereach (const cs *A, int k, const int *parent, int *s, int *w)
-{
- int i, p, n, len, top, *Ap, *Ai ;
- if (!CS_CSC (A) || !parent || !s || !w) return (-1) ; /* check inputs */
- top = n = A->n ; Ap = A->p ; Ai = A->i ;
- CS_MARK (w, k) ; /* mark node k as visited */
- for (p = Ap [k] ; p < Ap [k+1] ; p++)
- {
- i = Ai [p] ; /* A(i,k) is nonzero */
- if (i > k) continue ; /* only use upper triangular part of A */
- for (len = 0 ; !CS_MARKED (w,i) ; i = parent [i]) /* traverse up etree*/
- {
- s [len++] = i ; /* L(k,i) is nonzero */
- CS_MARK (w, i) ; /* mark i as visited */
- }
- while (len > 0) s [--top] = s [--len] ; /* push path onto stack */
- }
- for (p = top ; p < n ; p++) CS_MARK (w, s [p]) ; /* unmark all nodes */
- CS_MARK (w, k) ; /* unmark node k */
- return (top) ; /* s [top..n-1] contains pattern of L(k,:)*/
-}
diff --git a/lib/csparse/cs_etree.c b/lib/csparse/cs_etree.c
deleted file mode 100644
index 30712bc..0000000
--- a/lib/csparse/cs_etree.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "cs.h"
-/* compute the etree of A (using triu(A), or A'A without forming A'A */
-int *cs_etree (const cs *A, int ata)
-{
- int i, k, p, m, n, inext, *Ap, *Ai, *w, *parent, *ancestor, *prev ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ;
- parent = cs_malloc (n, sizeof (int)) ; /* allocate result */
- w = cs_malloc (n + (ata ? m : 0), sizeof (int)) ; /* get workspace */
- if (!w || !parent) return (cs_idone (parent, NULL, w, 0)) ;
- ancestor = w ; prev = w + n ;
- if (ata) for (i = 0 ; i < m ; i++) prev [i] = -1 ;
- for (k = 0 ; k < n ; k++)
- {
- parent [k] = -1 ; /* node k has no parent yet */
- ancestor [k] = -1 ; /* nor does k have an ancestor */
- for (p = Ap [k] ; p < Ap [k+1] ; p++)
- {
- i = ata ? (prev [Ai [p]]) : (Ai [p]) ;
- for ( ; i != -1 && i < k ; i = inext) /* traverse from i to k */
- {
- inext = ancestor [i] ; /* inext = ancestor of i */
- ancestor [i] = k ; /* path compression */
- if (inext == -1) parent [i] = k ; /* no anc., parent is k */
- }
- if (ata) prev [Ai [p]] = k ;
- }
- }
- return (cs_idone (parent, NULL, w, 1)) ;
-}
diff --git a/lib/csparse/cs_fkeep.c b/lib/csparse/cs_fkeep.c
deleted file mode 100644
index 0e32051..0000000
--- a/lib/csparse/cs_fkeep.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cs.h"
-/* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */
-int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other)
-{
- int j, p, nz = 0, n, *Ap, *Ai ;
- double *Ax ;
- if (!CS_CSC (A) || !fkeep) return (-1) ; /* check inputs */
- n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- for (j = 0 ; j < n ; j++)
- {
- p = Ap [j] ; /* get current location of col j */
- Ap [j] = nz ; /* record new location of col j */
- for ( ; p < Ap [j+1] ; p++)
- {
- if (fkeep (Ai [p], j, Ax ? Ax [p] : 1, other))
- {
- if (Ax) Ax [nz] = Ax [p] ; /* keep A(i,j) */
- Ai [nz++] = Ai [p] ;
- }
- }
- }
- Ap [n] = nz ; /* finalize A */
- cs_sprealloc (A, 0) ; /* remove extra space from A */
- return (nz) ;
-}
diff --git a/lib/csparse/cs_gaxpy.c b/lib/csparse/cs_gaxpy.c
deleted file mode 100644
index 580f600..0000000
--- a/lib/csparse/cs_gaxpy.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "cs.h"
-/* y = A*x+y */
-int cs_gaxpy (const cs *A, const double *x, double *y)
-{
- int p, j, n, *Ap, *Ai ;
- double *Ax ;
- if (!CS_CSC (A) || !x || !y) return (0) ; /* check inputs */
- n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- for (j = 0 ; j < n ; j++)
- {
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- y [Ai [p]] += Ax [p] * x [j] ;
- }
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_happly.c b/lib/csparse/cs_happly.c
deleted file mode 100644
index b2d4346..0000000
--- a/lib/csparse/cs_happly.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "cs.h"
-/* apply the ith Householder vector to x */
-int cs_happly (const cs *V, int i, double beta, double *x)
-{
- int p, *Vp, *Vi ;
- double *Vx, tau = 0 ;
- if (!CS_CSC (V) || !x) return (0) ; /* check inputs */
- Vp = V->p ; Vi = V->i ; Vx = V->x ;
- for (p = Vp [i] ; p < Vp [i+1] ; p++) /* tau = v'*x */
- {
- tau += Vx [p] * x [Vi [p]] ;
- }
- tau *= beta ; /* tau = beta*(v'*x) */
- for (p = Vp [i] ; p < Vp [i+1] ; p++) /* x = x - v*tau */
- {
- x [Vi [p]] -= Vx [p] * tau ;
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_house.c b/lib/csparse/cs_house.c
deleted file mode 100644
index 5935f4c..0000000
--- a/lib/csparse/cs_house.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "cs.h"
-/* create a Householder reflection [v,beta,s]=house(x), overwrite x with v,
- * where (I-beta*v*v')*x = s*e1. See Algo 5.1.1, Golub & Van Loan, 3rd ed. */
-double cs_house (double *x, double *beta, int n)
-{
- double s, sigma = 0 ;
- int i ;
- if (!x || !beta) return (-1) ; /* check inputs */
- for (i = 1 ; i < n ; i++) sigma += x [i] * x [i] ;
- if (sigma == 0)
- {
- s = fabs (x [0]) ; /* s = |x(0)| */
- (*beta) = (x [0] <= 0) ? 2 : 0 ;
- x [0] = 1 ;
- }
- else
- {
- s = sqrt (x [0] * x [0] + sigma) ; /* s = norm (x) */
- x [0] = (x [0] <= 0) ? (x [0] - s) : (-sigma / (x [0] + s)) ;
- (*beta) = -1. / (s * x [0]) ;
- }
- return (s) ;
-}
diff --git a/lib/csparse/cs_ipvec.c b/lib/csparse/cs_ipvec.c
deleted file mode 100644
index cb1e9a9..0000000
--- a/lib/csparse/cs_ipvec.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "cs.h"
-/* x(p) = b, for dense vectors x and b; p=NULL denotes identity */
-int cs_ipvec (const int *p, const double *b, double *x, int n)
-{
- int k ;
- if (!x || !b) return (0) ; /* check inputs */
- for (k = 0 ; k < n ; k++) x [p ? p [k] : k] = b [k] ;
- return (1) ;
-}
diff --git a/lib/csparse/cs_leaf.c b/lib/csparse/cs_leaf.c
deleted file mode 100644
index 1601cb9..0000000
--- a/lib/csparse/cs_leaf.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "cs.h"
-/* consider A(i,j), node j in ith row subtree and return lca(jprev,j) */
-int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf,
- int *ancestor, int *jleaf)
-{
- int q, s, sparent, jprev ;
- if (!first || !maxfirst || !prevleaf || !ancestor || !jleaf) return (-1) ;
- *jleaf = 0 ;
- if (i <= j || first [j] <= maxfirst [i]) return (-1) ; /* j not a leaf */
- maxfirst [i] = first [j] ; /* update max first[j] seen so far */
- jprev = prevleaf [i] ; /* jprev = previous leaf of ith subtree */
- prevleaf [i] = j ;
- *jleaf = (jprev == -1) ? 1: 2 ; /* j is first or subsequent leaf */
- if (*jleaf == 1) return (i) ; /* if 1st leaf, q = root of ith subtree */
- for (q = jprev ; q != ancestor [q] ; q = ancestor [q]) ;
- for (s = jprev ; s != q ; s = sparent)
- {
- sparent = ancestor [s] ; /* path compression */
- ancestor [s] = q ;
- }
- return (q) ; /* q = least common ancester (jprev,j) */
-}
diff --git a/lib/csparse/cs_load.c b/lib/csparse/cs_load.c
deleted file mode 100644
index e1e8719..0000000
--- a/lib/csparse/cs_load.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "cs.h"
-/* load a triplet matrix from a file */
-cs *cs_load (FILE *f)
-{
- int i, j ;
- double x ;
- cs *T ;
- if (!f) return (NULL) ; /* check inputs */
- T = cs_spalloc (0, 0, 1, 1, 1) ; /* allocate result */
- while (fscanf (f, "%d %d %lg\n", &i, &j, &x) == 3)
- {
- if (!cs_entry (T, i, j, x)) return (cs_spfree (T)) ;
- }
- return (T) ;
-}
diff --git a/lib/csparse/cs_lsolve.c b/lib/csparse/cs_lsolve.c
deleted file mode 100644
index 69376ac..0000000
--- a/lib/csparse/cs_lsolve.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "cs.h"
-/* solve Lx=b where x and b are dense. x=b on input, solution on output. */
-int cs_lsolve (const cs *L, double *x)
-{
- int p, j, n, *Lp, *Li ;
- double *Lx ;
- if (!CS_CSC (L) || !x) return (0) ; /* check inputs */
- n = L->n ; Lp = L->p ; Li = L->i ; Lx = L->x ;
- for (j = 0 ; j < n ; j++)
- {
- x [j] /= Lx [Lp [j]] ;
- for (p = Lp [j]+1 ; p < Lp [j+1] ; p++)
- {
- x [Li [p]] -= Lx [p] * x [j] ;
- }
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_ltsolve.c b/lib/csparse/cs_ltsolve.c
deleted file mode 100644
index fc2ee4f..0000000
--- a/lib/csparse/cs_ltsolve.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "cs.h"
-/* solve L'x=b where x and b are dense. x=b on input, solution on output. */
-int cs_ltsolve (const cs *L, double *x)
-{
- int p, j, n, *Lp, *Li ;
- double *Lx ;
- if (!CS_CSC (L) || !x) return (0) ; /* check inputs */
- n = L->n ; Lp = L->p ; Li = L->i ; Lx = L->x ;
- for (j = n-1 ; j >= 0 ; j--)
- {
- for (p = Lp [j]+1 ; p < Lp [j+1] ; p++)
- {
- x [j] -= Lx [p] * x [Li [p]] ;
- }
- x [j] /= Lx [Lp [j]] ;
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_lu.c b/lib/csparse/cs_lu.c
deleted file mode 100644
index c8883c6..0000000
--- a/lib/csparse/cs_lu.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include "cs.h"
-/* [L,U,pinv]=lu(A, [q lnz unz]). lnz and unz can be guess */
-csn *cs_lu (const cs *A, const css *S, double tol)
-{
- cs *L, *U ;
- csn *N ;
- double pivot, *Lx, *Ux, *x, a, t ;
- int *Lp, *Li, *Up, *Ui, *pinv, *xi, *q, n, ipiv, k, top, p, i, col, lnz,unz;
- if (!CS_CSC (A) || !S) return (NULL) ; /* check inputs */
- n = A->n ;
- q = S->q ; lnz = S->lnz ; unz = S->unz ;
- x = cs_malloc (n, sizeof (double)) ; /* get double workspace */
- xi = cs_malloc (2*n, sizeof (int)) ; /* get int workspace */
- N = cs_calloc (1, sizeof (csn)) ; /* allocate result */
- if (!x || !xi || !N) return (cs_ndone (N, NULL, xi, x, 0)) ;
- N->L = L = cs_spalloc (n, n, lnz, 1, 0) ; /* allocate result L */
- N->U = U = cs_spalloc (n, n, unz, 1, 0) ; /* allocate result U */
- N->pinv = pinv = cs_malloc (n, sizeof (int)) ; /* allocate result pinv */
- if (!L || !U || !pinv) return (cs_ndone (N, NULL, xi, x, 0)) ;
- Lp = L->p ; Up = U->p ;
- for (i = 0 ; i < n ; i++) x [i] = 0 ; /* clear workspace */
- for (i = 0 ; i < n ; i++) pinv [i] = -1 ; /* no rows pivotal yet */
- for (k = 0 ; k <= n ; k++) Lp [k] = 0 ; /* no cols of L yet */
- lnz = unz = 0 ;
- for (k = 0 ; k < n ; k++) /* compute L(:,k) and U(:,k) */
- {
- /* --- Triangular solve --------------------------------------------- */
- Lp [k] = lnz ; /* L(:,k) starts here */
- Up [k] = unz ; /* U(:,k) starts here */
- if ((lnz + n > L->nzmax && !cs_sprealloc (L, 2*L->nzmax + n)) ||
- (unz + n > U->nzmax && !cs_sprealloc (U, 2*U->nzmax + n)))
- {
- return (cs_ndone (N, NULL, xi, x, 0)) ;
- }
- Li = L->i ; Lx = L->x ; Ui = U->i ; Ux = U->x ;
- col = q ? (q [k]) : k ;
- top = cs_spsolve (L, A, col, xi, x, pinv, 1) ; /* x = L\A(:,col) */
- /* --- Find pivot --------------------------------------------------- */
- ipiv = -1 ;
- a = -1 ;
- for (p = top ; p < n ; p++)
- {
- i = xi [p] ; /* x(i) is nonzero */
- if (pinv [i] < 0) /* row i is not yet pivotal */
- {
- if ((t = fabs (x [i])) > a)
- {
- a = t ; /* largest pivot candidate so far */
- ipiv = i ;
- }
- }
- else /* x(i) is the entry U(pinv[i],k) */
- {
- Ui [unz] = pinv [i] ;
- Ux [unz++] = x [i] ;
- }
- }
- if (ipiv == -1 || a <= 0) return (cs_ndone (N, NULL, xi, x, 0)) ;
- if (pinv [col] < 0 && fabs (x [col]) >= a*tol) ipiv = col ;
- /* --- Divide by pivot ---------------------------------------------- */
- pivot = x [ipiv] ; /* the chosen pivot */
- Ui [unz] = k ; /* last entry in U(:,k) is U(k,k) */
- Ux [unz++] = pivot ;
- pinv [ipiv] = k ; /* ipiv is the kth pivot row */
- Li [lnz] = ipiv ; /* first entry in L(:,k) is L(k,k) = 1 */
- Lx [lnz++] = 1 ;
- for (p = top ; p < n ; p++) /* L(k+1:n,k) = x / pivot */
- {
- i = xi [p] ;
- if (pinv [i] < 0) /* x(i) is an entry in L(:,k) */
- {
- Li [lnz] = i ; /* save unpermuted row in L */
- Lx [lnz++] = x [i] / pivot ; /* scale pivot column */
- }
- x [i] = 0 ; /* x [0..n-1] = 0 for next k */
- }
- }
- /* --- Finalize L and U ------------------------------------------------- */
- Lp [n] = lnz ;
- Up [n] = unz ;
- Li = L->i ; /* fix row indices of L for final pinv */
- for (p = 0 ; p < lnz ; p++) Li [p] = pinv [Li [p]] ;
- cs_sprealloc (L, 0) ; /* remove extra space from L and U */
- cs_sprealloc (U, 0) ;
- return (cs_ndone (N, NULL, xi, x, 1)) ; /* success */
-}
diff --git a/lib/csparse/cs_lusol.c b/lib/csparse/cs_lusol.c
deleted file mode 100644
index e7d79a1..0000000
--- a/lib/csparse/cs_lusol.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "cs.h"
-/* x=A\b where A is unsymmetric; b overwritten with solution */
-int cs_lusol (int order, const cs *A, double *b, double tol)
-{
- double *x ;
- css *S ;
- csn *N ;
- int n, ok ;
- if (!CS_CSC (A) || !b) return (0) ; /* check inputs */
- n = A->n ;
- S = cs_sqr (order, A, 0) ; /* ordering and symbolic analysis */
- N = cs_lu (A, S, tol) ; /* numeric LU factorization */
- x = cs_malloc (n, sizeof (double)) ; /* get workspace */
- ok = (S && N && x) ;
- if (ok)
- {
- cs_ipvec (N->pinv, b, x, n) ; /* x = b(p) */
- cs_lsolve (N->L, x) ; /* x = L\x */
- cs_usolve (N->U, x) ; /* x = U\x */
- cs_ipvec (S->q, x, b, n) ; /* b(q) = x */
- }
- cs_free (x) ;
- cs_sfree (S) ;
- cs_nfree (N) ;
- return (ok) ;
-}
diff --git a/lib/csparse/cs_malloc.c b/lib/csparse/cs_malloc.c
deleted file mode 100644
index 4d8e2e1..0000000
--- a/lib/csparse/cs_malloc.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "cs.h"
-#ifdef MATLAB_MEX_FILE
-#define malloc mxMalloc
-#define free mxFree
-#define realloc mxRealloc
-#define calloc mxCalloc
-#endif
-
-/* wrapper for malloc */
-void *cs_malloc (int n, size_t size)
-{
- return (malloc (CS_MAX (n,1) * size)) ;
-}
-
-/* wrapper for calloc */
-void *cs_calloc (int n, size_t size)
-{
- return (calloc (CS_MAX (n,1), size)) ;
-}
-
-/* wrapper for free */
-void *cs_free (void *p)
-{
- if (p) free (p) ; /* free p if it is not already NULL */
- return (NULL) ; /* return NULL to simplify the use of cs_free */
-}
-
-/* wrapper for realloc */
-void *cs_realloc (void *p, int n, size_t size, int *ok)
-{
- void *pnew ;
- pnew = realloc (p, CS_MAX (n,1) * size) ; /* realloc the block */
- *ok = (pnew != NULL) ; /* realloc fails if pnew is NULL */
- return ((*ok) ? pnew : p) ; /* return original p if failure */
-}
diff --git a/lib/csparse/cs_maxtrans.c b/lib/csparse/cs_maxtrans.c
deleted file mode 100644
index 7c8ea65..0000000
--- a/lib/csparse/cs_maxtrans.c
+++ /dev/null
@@ -1,92 +0,0 @@
-#include "cs.h"
-/* find an augmenting path starting at column k and extend the match if found */
-static void cs_augment (int k, const cs *A, int *jmatch, int *cheap, int *w,
- int *js, int *is, int *ps)
-{
- int found = 0, p, i = -1, *Ap = A->p, *Ai = A->i, head = 0, j ;
- js [0] = k ; /* start with just node k in jstack */
- while (head >= 0)
- {
- /* --- Start (or continue) depth-first-search at node j ------------- */
- j = js [head] ; /* get j from top of jstack */
- if (w [j] != k) /* 1st time j visited for kth path */
- {
- w [j] = k ; /* mark j as visited for kth path */
- for (p = cheap [j] ; p < Ap [j+1] && !found ; p++)
- {
- i = Ai [p] ; /* try a cheap assignment (i,j) */
- found = (jmatch [i] == -1) ;
- }
- cheap [j] = p ; /* start here next time j is traversed*/
- if (found)
- {
- is [head] = i ; /* column j matched with row i */
- break ; /* end of augmenting path */
- }
- ps [head] = Ap [j] ; /* no cheap match: start dfs for j */
- }
- /* --- Depth-first-search of neighbors of j ------------------------- */
- for (p = ps [head] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ; /* consider row i */
- if (w [jmatch [i]] == k) continue ; /* skip jmatch [i] if marked */
- ps [head] = p + 1 ; /* pause dfs of node j */
- is [head] = i ; /* i will be matched with j if found */
- js [++head] = jmatch [i] ; /* start dfs at column jmatch [i] */
- break ;
- }
- if (p == Ap [j+1]) head-- ; /* node j is done; pop from stack */
- } /* augment the match if path found: */
- if (found) for (p = head ; p >= 0 ; p--) jmatch [is [p]] = js [p] ;
-}
-
-/* find a maximum transveral */
-int *cs_maxtrans (const cs *A, int seed) /*[jmatch [0..m-1]; imatch [0..n-1]]*/
-{
- int i, j, k, n, m, p, n2 = 0, m2 = 0, *Ap, *jimatch, *w, *cheap, *js, *is,
- *ps, *Ai, *Cp, *jmatch, *imatch, *q ;
- cs *C ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- n = A->n ; m = A->m ; Ap = A->p ; Ai = A->i ;
- w = jimatch = cs_calloc (m+n, sizeof (int)) ; /* allocate result */
- if (!jimatch) return (NULL) ;
- for (k = 0, j = 0 ; j < n ; j++) /* count nonempty rows and columns */
- {
- n2 += (Ap [j] < Ap [j+1]) ;
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- w [Ai [p]] = 1 ;
- k += (j == Ai [p]) ; /* count entries already on diagonal */
- }
- }
- if (k == CS_MIN (m,n)) /* quick return if diagonal zero-free */
- {
- jmatch = jimatch ; imatch = jimatch + m ;
- for (i = 0 ; i < k ; i++) jmatch [i] = i ;
- for ( ; i < m ; i++) jmatch [i] = -1 ;
- for (j = 0 ; j < k ; j++) imatch [j] = j ;
- for ( ; j < n ; j++) imatch [j] = -1 ;
- return (cs_idone (jimatch, NULL, NULL, 1)) ;
- }
- for (i = 0 ; i < m ; i++) m2 += w [i] ;
- C = (m2 < n2) ? cs_transpose (A,0) : ((cs *) A) ; /* transpose if needed */
- if (!C) return (cs_idone (jimatch, (m2 < n2) ? C : NULL, NULL, 0)) ;
- n = C->n ; m = C->m ; Cp = C->p ;
- jmatch = (m2 < n2) ? jimatch + n : jimatch ;
- imatch = (m2 < n2) ? jimatch : jimatch + m ;
- w = cs_malloc (5*n, sizeof (int)) ; /* get workspace */
- if (!w) return (cs_idone (jimatch, (m2 < n2) ? C : NULL, w, 0)) ;
- cheap = w + n ; js = w + 2*n ; is = w + 3*n ; ps = w + 4*n ;
- for (j = 0 ; j < n ; j++) cheap [j] = Cp [j] ; /* for cheap assignment */
- for (j = 0 ; j < n ; j++) w [j] = -1 ; /* all columns unflagged */
- for (i = 0 ; i < m ; i++) jmatch [i] = -1 ; /* nothing matched yet */
- q = cs_randperm (n, seed) ; /* q = random permutation */
- for (k = 0 ; k < n ; k++) /* augment, starting at column q[k] */
- {
- cs_augment (q ? q [k]: k, C, jmatch, cheap, w, js, is, ps) ;
- }
- cs_free (q) ;
- for (j = 0 ; j < n ; j++) imatch [j] = -1 ; /* find row match */
- for (i = 0 ; i < m ; i++) if (jmatch [i] >= 0) imatch [jmatch [i]] = i ;
- return (cs_idone (jimatch, (m2 < n2) ? C : NULL, w, 1)) ;
-}
diff --git a/lib/csparse/cs_multiply.c b/lib/csparse/cs_multiply.c
deleted file mode 100644
index c52ebea..0000000
--- a/lib/csparse/cs_multiply.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "cs.h"
-/* C = A*B */
-cs *cs_multiply (const cs *A, const cs *B)
-{
- int p, j, nz = 0, anz, *Cp, *Ci, *Bp, m, n, bnz, *w, values, *Bi ;
- double *x, *Bx, *Cx ;
- cs *C ;
- if (!CS_CSC (A) || !CS_CSC (B)) return (NULL) ; /* check inputs */
- if (A->n != B->m) return (NULL) ;
- m = A->m ; anz = A->p [A->n] ;
- n = B->n ; Bp = B->p ; Bi = B->i ; Bx = B->x ; bnz = Bp [n] ;
- w = cs_calloc (m, sizeof (int)) ; /* get workspace */
- values = (A->x != NULL) && (Bx != NULL) ;
- x = values ? cs_malloc (m, sizeof (double)) : NULL ; /* get workspace */
- C = cs_spalloc (m, n, anz + bnz, values, 0) ; /* allocate result */
- if (!C || !w || (values && !x)) return (cs_done (C, w, x, 0)) ;
- Cp = C->p ;
- for (j = 0 ; j < n ; j++)
- {
- if (nz + m > C->nzmax && !cs_sprealloc (C, 2*(C->nzmax)+m))
- {
- return (cs_done (C, w, x, 0)) ; /* out of memory */
- }
- Ci = C->i ; Cx = C->x ; /* C->i and C->x may be reallocated */
- Cp [j] = nz ; /* column j of C starts here */
- for (p = Bp [j] ; p < Bp [j+1] ; p++)
- {
- nz = cs_scatter (A, Bi [p], Bx ? Bx [p] : 1, w, x, j+1, C, nz) ;
- }
- if (values) for (p = Cp [j] ; p < nz ; p++) Cx [p] = x [Ci [p]] ;
- }
- Cp [n] = nz ; /* finalize the last column of C */
- cs_sprealloc (C, 0) ; /* remove extra space from C */
- return (cs_done (C, w, x, 1)) ; /* success; free workspace, return C */
-}
diff --git a/lib/csparse/cs_norm.c b/lib/csparse/cs_norm.c
deleted file mode 100644
index 24f8a2e..0000000
--- a/lib/csparse/cs_norm.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "cs.h"
-/* 1-norm of a sparse matrix = max (sum (abs (A))), largest column sum */
-double cs_norm (const cs *A)
-{
- int p, j, n, *Ap ;
- double *Ax, norm = 0, s ;
- if (!CS_CSC (A) || !A->x) return (-1) ; /* check inputs */
- n = A->n ; Ap = A->p ; Ax = A->x ;
- for (j = 0 ; j < n ; j++)
- {
- for (s = 0, p = Ap [j] ; p < Ap [j+1] ; p++) s += fabs (Ax [p]) ;
- norm = CS_MAX (norm, s) ;
- }
- return (norm) ;
-}
diff --git a/lib/csparse/cs_permute.c b/lib/csparse/cs_permute.c
deleted file mode 100644
index f08e4d1..0000000
--- a/lib/csparse/cs_permute.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cs.h"
-/* C = A(p,q) where p and q are permutations of 0..m-1 and 0..n-1. */
-cs *cs_permute (const cs *A, const int *pinv, const int *q, int values)
-{
- int t, j, k, nz = 0, m, n, *Ap, *Ai, *Cp, *Ci ;
- double *Cx, *Ax ;
- cs *C ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- C = cs_spalloc (m, n, Ap [n], values && Ax != NULL, 0) ; /* alloc result */
- if (!C) return (cs_done (C, NULL, NULL, 0)) ; /* out of memory */
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- for (k = 0 ; k < n ; k++)
- {
- Cp [k] = nz ; /* column k of C is column q[k] of A */
- j = q ? (q [k]) : k ;
- for (t = Ap [j] ; t < Ap [j+1] ; t++)
- {
- if (Cx) Cx [nz] = Ax [t] ; /* row i of A is row pinv[i] of C */
- Ci [nz++] = pinv ? (pinv [Ai [t]]) : Ai [t] ;
- }
- }
- Cp [n] = nz ; /* finalize the last column of C */
- return (cs_done (C, NULL, NULL, 1)) ;
-}
diff --git a/lib/csparse/cs_pinv.c b/lib/csparse/cs_pinv.c
deleted file mode 100644
index 0583e77..0000000
--- a/lib/csparse/cs_pinv.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "cs.h"
-/* pinv = p', or p = pinv' */
-int *cs_pinv (int const *p, int n)
-{
- int k, *pinv ;
- if (!p) return (NULL) ; /* p = NULL denotes identity */
- pinv = cs_malloc (n, sizeof (int)) ; /* allocate result */
- if (!pinv) return (NULL) ; /* out of memory */
- for (k = 0 ; k < n ; k++) pinv [p [k]] = k ;/* invert the permutation */
- return (pinv) ; /* return result */
-}
diff --git a/lib/csparse/cs_post.c b/lib/csparse/cs_post.c
deleted file mode 100644
index 80e66e6..0000000
--- a/lib/csparse/cs_post.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "cs.h"
-/* post order a forest */
-int *cs_post (const int *parent, int n)
-{
- int j, k = 0, *post, *w, *head, *next, *stack ;
- if (!parent) return (NULL) ; /* check inputs */
- post = cs_malloc (n, sizeof (int)) ; /* allocate result */
- w = cs_malloc (3*n, sizeof (int)) ; /* get workspace */
- if (!w || !post) return (cs_idone (post, NULL, w, 0)) ;
- head = w ; next = w + n ; stack = w + 2*n ;
- for (j = 0 ; j < n ; j++) head [j] = -1 ; /* empty linked lists */
- for (j = n-1 ; j >= 0 ; j--) /* traverse nodes in reverse order*/
- {
- if (parent [j] == -1) continue ; /* j is a root */
- next [j] = head [parent [j]] ; /* add j to list of its parent */
- head [parent [j]] = j ;
- }
- for (j = 0 ; j < n ; j++)
- {
- if (parent [j] != -1) continue ; /* skip j if it is not a root */
- k = cs_tdfs (j, k, head, next, post, stack) ;
- }
- return (cs_idone (post, NULL, w, 1)) ; /* success; free w, return post */
-}
diff --git a/lib/csparse/cs_print.c b/lib/csparse/cs_print.c
deleted file mode 100644
index 8e3f33e..0000000
--- a/lib/csparse/cs_print.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "cs.h"
-/* print a sparse matrix */
-int cs_print (const cs *A, int brief)
-{
- int p, j, m, n, nzmax, nz, *Ap, *Ai ;
- double *Ax ;
- if (!A) { printf ("(null)\n") ; return (0) ; }
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- nzmax = A->nzmax ; nz = A->nz ;
- printf ("CSparse Version %d.%d.%d, %s. %s\n", CS_VER, CS_SUBVER,
- CS_SUBSUB, CS_DATE, CS_COPYRIGHT) ;
- if (nz < 0)
- {
- printf ("%d-by-%d, nzmax: %d nnz: %d, 1-norm: %g\n", m, n, nzmax,
- Ap [n], cs_norm (A)) ;
- for (j = 0 ; j < n ; j++)
- {
- printf (" col %d : locations %d to %d\n", j, Ap [j], Ap [j+1]-1);
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- printf (" %d : %g\n", Ai [p], Ax ? Ax [p] : 1) ;
- if (brief && p > 20) { printf (" ...\n") ; return (1) ; }
- }
- }
- }
- else
- {
- printf ("triplet: %d-by-%d, nzmax: %d nnz: %d\n", m, n, nzmax, nz) ;
- for (p = 0 ; p < nz ; p++)
- {
- printf (" %d %d : %g\n", Ai [p], Ap [p], Ax ? Ax [p] : 1) ;
- if (brief && p > 20) { printf (" ...\n") ; return (1) ; }
- }
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_pvec.c b/lib/csparse/cs_pvec.c
deleted file mode 100644
index 03c3cc6..0000000
--- a/lib/csparse/cs_pvec.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "cs.h"
-/* x = b(p), for dense vectors x and b; p=NULL denotes identity */
-int cs_pvec (const int *p, const double *b, double *x, int n)
-{
- int k ;
- if (!x || !b) return (0) ; /* check inputs */
- for (k = 0 ; k < n ; k++) x [k] = b [p ? p [k] : k] ;
- return (1) ;
-}
diff --git a/lib/csparse/cs_qr.c b/lib/csparse/cs_qr.c
deleted file mode 100644
index eb1774d..0000000
--- a/lib/csparse/cs_qr.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "cs.h"
-/* sparse QR factorization [V,beta,pinv,R] = qr (A) */
-csn *cs_qr (const cs *A, const css *S)
-{
- double *Rx, *Vx, *Ax, *x, *Beta ;
- int i, k, p, m, n, vnz, p1, top, m2, len, col, rnz, *s, *leftmost, *Ap, *Ai,
- *parent, *Rp, *Ri, *Vp, *Vi, *w, *pinv, *q ;
- cs *R, *V ;
- csn *N ;
- if (!CS_CSC (A) || !S) return (NULL) ;
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- q = S->q ; parent = S->parent ; pinv = S->pinv ; m2 = S->m2 ;
- vnz = S->lnz ; rnz = S->unz ; leftmost = S->leftmost ;
- w = cs_malloc (m2+n, sizeof (int)) ; /* get int workspace */
- x = cs_malloc (m2, sizeof (double)) ; /* get double workspace */
- N = cs_calloc (1, sizeof (csn)) ; /* allocate result */
- if (!w || !x || !N) return (cs_ndone (N, NULL, w, x, 0)) ;
- s = w + m2 ; /* s is size n */
- for (k = 0 ; k < m2 ; k++) x [k] = 0 ; /* clear workspace x */
- N->L = V = cs_spalloc (m2, n, vnz, 1, 0) ; /* allocate result V */
- N->U = R = cs_spalloc (m2, n, rnz, 1, 0) ; /* allocate result R */
- N->B = Beta = cs_malloc (n, sizeof (double)) ; /* allocate result Beta */
- if (!R || !V || !Beta) return (cs_ndone (N, NULL, w, x, 0)) ;
- Rp = R->p ; Ri = R->i ; Rx = R->x ;
- Vp = V->p ; Vi = V->i ; Vx = V->x ;
- for (i = 0 ; i < m2 ; i++) w [i] = -1 ; /* clear w, to mark nodes */
- rnz = 0 ; vnz = 0 ;
- for (k = 0 ; k < n ; k++) /* compute V and R */
- {
- Rp [k] = rnz ; /* R(:,k) starts here */
- Vp [k] = p1 = vnz ; /* V(:,k) starts here */
- w [k] = k ; /* add V(k,k) to pattern of V */
- Vi [vnz++] = k ;
- top = n ;
- col = q ? q [k] : k ;
- for (p = Ap [col] ; p < Ap [col+1] ; p++) /* find R(:,k) pattern */
- {
- i = leftmost [Ai [p]] ; /* i = min(find(A(i,q))) */
- for (len = 0 ; w [i] != k ; i = parent [i]) /* traverse up to k */
- {
- s [len++] = i ;
- w [i] = k ;
- }
- while (len > 0) s [--top] = s [--len] ; /* push path on stack */
- i = pinv [Ai [p]] ; /* i = permuted row of A(:,col) */
- x [i] = Ax [p] ; /* x (i) = A(:,col) */
- if (i > k && w [i] < k) /* pattern of V(:,k) = x (k+1:m) */
- {
- Vi [vnz++] = i ; /* add i to pattern of V(:,k) */
- w [i] = k ;
- }
- }
- for (p = top ; p < n ; p++) /* for each i in pattern of R(:,k) */
- {
- i = s [p] ; /* R(i,k) is nonzero */
- cs_happly (V, i, Beta [i], x) ; /* apply (V(i),Beta(i)) to x */
- Ri [rnz] = i ; /* R(i,k) = x(i) */
- Rx [rnz++] = x [i] ;
- x [i] = 0 ;
- if (parent [i] == k) vnz = cs_scatter (V, i, 0, w, NULL, k, V, vnz);
- }
- for (p = p1 ; p < vnz ; p++) /* gather V(:,k) = x */
- {
- Vx [p] = x [Vi [p]] ;
- x [Vi [p]] = 0 ;
- }
- Ri [rnz] = k ; /* R(k,k) = norm (x) */
- Rx [rnz++] = cs_house (Vx+p1, Beta+k, vnz-p1) ; /* [v,beta]=house(x) */
- }
- Rp [n] = rnz ; /* finalize R */
- Vp [n] = vnz ; /* finalize V */
- return (cs_ndone (N, NULL, w, x, 1)) ; /* success */
-}
diff --git a/lib/csparse/cs_qrsol.c b/lib/csparse/cs_qrsol.c
deleted file mode 100644
index 7d07966..0000000
--- a/lib/csparse/cs_qrsol.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "cs.h"
-/* x=A\b where A can be rectangular; b overwritten with solution */
-int cs_qrsol (int order, const cs *A, double *b)
-{
- double *x ;
- css *S ;
- csn *N ;
- cs *AT = NULL ;
- int k, m, n, ok ;
- if (!CS_CSC (A) || !b) return (0) ; /* check inputs */
- n = A->n ;
- m = A->m ;
- if (m >= n)
- {
- S = cs_sqr (order, A, 1) ; /* ordering and symbolic analysis */
- N = cs_qr (A, S) ; /* numeric QR factorization */
- x = cs_calloc (S ? S->m2 : 1, sizeof (double)) ; /* get workspace */
- ok = (S && N && x) ;
- if (ok)
- {
- cs_ipvec (S->pinv, b, x, m) ; /* x(0:m-1) = b(p(0:m-1) */
- for (k = 0 ; k < n ; k++) /* apply Householder refl. to x */
- {
- cs_happly (N->L, k, N->B [k], x) ;
- }
- cs_usolve (N->U, x) ; /* x = R\x */
- cs_ipvec (S->q, x, b, n) ; /* b(q(0:n-1)) = x(0:n-1) */
- }
- }
- else
- {
- AT = cs_transpose (A, 1) ; /* Ax=b is underdetermined */
- S = cs_sqr (order, AT, 1) ; /* ordering and symbolic analysis */
- N = cs_qr (AT, S) ; /* numeric QR factorization of A' */
- x = cs_calloc (S ? S->m2 : 1, sizeof (double)) ; /* get workspace */
- ok = (AT && S && N && x) ;
- if (ok)
- {
- cs_pvec (S->q, b, x, m) ; /* x(q(0:m-1)) = b(0:m-1) */
- cs_utsolve (N->U, x) ; /* x = R'\x */
- for (k = m-1 ; k >= 0 ; k--) /* apply Householder refl. to x */
- {
- cs_happly (N->L, k, N->B [k], x) ;
- }
- cs_pvec (S->pinv, x, b, n) ; /* b(0:n-1) = x(p(0:n-1)) */
- }
- }
- cs_free (x) ;
- cs_sfree (S) ;
- cs_nfree (N) ;
- cs_spfree (AT) ;
- return (ok) ;
-}
diff --git a/lib/csparse/cs_randperm.c b/lib/csparse/cs_randperm.c
deleted file mode 100644
index de6b007..0000000
--- a/lib/csparse/cs_randperm.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "cs.h"
-/* return a random permutation vector, the identity perm, or p = n-1:-1:0.
- * seed = -1 means p = n-1:-1:0. seed = 0 means p = identity. otherwise
- * p = random permutation. */
-int *cs_randperm (int n, int seed)
-{
- int *p, k, j, t ;
- if (seed == 0) return (NULL) ; /* return p = NULL (identity) */
- p = cs_malloc (n, sizeof (int)) ; /* allocate result */
- if (!p) return (NULL) ; /* out of memory */
- for (k = 0 ; k < n ; k++) p [k] = n-k-1 ;
- if (seed == -1) return (p) ; /* return reverse permutation */
- srand (seed) ; /* get new random number seed */
- for (k = 0 ; k < n ; k++)
- {
- j = k + (rand ( ) % (n-k)) ; /* j = rand int in range k to n-1 */
- t = p [j] ; /* swap p[k] and p[j] */
- p [j] = p [k] ;
- p [k] = t ;
- }
- return (p) ;
-}
diff --git a/lib/csparse/cs_reach.c b/lib/csparse/cs_reach.c
deleted file mode 100644
index 29e8ca5..0000000
--- a/lib/csparse/cs_reach.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "cs.h"
-/* xi [top...n-1] = nodes reachable from graph of G*P' via nodes in B(:,k).
- * xi [n...2n-1] used as workspace */
-int cs_reach (cs *G, const cs *B, int k, int *xi, const int *pinv)
-{
- int p, n, top, *Bp, *Bi, *Gp ;
- if (!CS_CSC (G) || !CS_CSC (B) || !xi) return (-1) ; /* check inputs */
- n = G->n ; Bp = B->p ; Bi = B->i ; Gp = G->p ;
- top = n ;
- for (p = Bp [k] ; p < Bp [k+1] ; p++)
- {
- if (!CS_MARKED (Gp, Bi [p])) /* start a dfs at unmarked node i */
- {
- top = cs_dfs (Bi [p], G, top, xi, xi+n, pinv) ;
- }
- }
- for (p = top ; p < n ; p++) CS_MARK (Gp, xi [p]) ; /* restore G */
- return (top) ;
-}
diff --git a/lib/csparse/cs_scatter.c b/lib/csparse/cs_scatter.c
deleted file mode 100644
index 0077826..0000000
--- a/lib/csparse/cs_scatter.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "cs.h"
-/* x = x + beta * A(:,j), where x is a dense vector and A(:,j) is sparse */
-int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark,
- cs *C, int nz)
-{
- int i, p, *Ap, *Ai, *Ci ;
- double *Ax ;
- if (!CS_CSC (A) || !w || !CS_CSC (C)) return (-1) ; /* check inputs */
- Ap = A->p ; Ai = A->i ; Ax = A->x ; Ci = C->i ;
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ; /* A(i,j) is nonzero */
- if (w [i] < mark)
- {
- w [i] = mark ; /* i is new entry in column j */
- Ci [nz++] = i ; /* add i to pattern of C(:,j) */
- if (x) x [i] = beta * Ax [p] ; /* x(i) = beta*A(i,j) */
- }
- else if (x) x [i] += beta * Ax [p] ; /* i exists in C(:,j) already */
- }
- return (nz) ;
-}
diff --git a/lib/csparse/cs_scc.c b/lib/csparse/cs_scc.c
deleted file mode 100644
index e56d086..0000000
--- a/lib/csparse/cs_scc.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "cs.h"
-/* find the strongly connected components of a square matrix */
-csd *cs_scc (cs *A) /* matrix A temporarily modified, then restored */
-{
- int n, i, k, b, nb = 0, top, *xi, *pstack, *p, *r, *Ap, *ATp, *rcopy, *Blk ;
- cs *AT ;
- csd *D ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- n = A->n ; Ap = A->p ;
- D = cs_dalloc (n, 0) ; /* allocate result */
- AT = cs_transpose (A, 0) ; /* AT = A' */
- xi = cs_malloc (2*n+1, sizeof (int)) ; /* get workspace */
- if (!D || !AT || !xi) return (cs_ddone (D, AT, xi, 0)) ;
- Blk = xi ; rcopy = pstack = xi + n ;
- p = D->p ; r = D->r ; ATp = AT->p ;
- top = n ;
- for (i = 0 ; i < n ; i++) /* first dfs(A) to find finish times (xi) */
- {
- if (!CS_MARKED (Ap, i)) top = cs_dfs (i, A, top, xi, pstack, NULL) ;
- }
- for (i = 0 ; i < n ; i++) CS_MARK (Ap, i) ; /* restore A; unmark all nodes*/
- top = n ;
- nb = n ;
- for (k = 0 ; k < n ; k++) /* dfs(A') to find strongly connnected comp */
- {
- i = xi [k] ; /* get i in reverse order of finish times */
- if (CS_MARKED (ATp, i)) continue ; /* skip node i if already ordered */
- r [nb--] = top ; /* node i is the start of a component in p */
- top = cs_dfs (i, AT, top, p, pstack, NULL) ;
- }
- r [nb] = 0 ; /* first block starts at zero; shift r up */
- for (k = nb ; k <= n ; k++) r [k-nb] = r [k] ;
- D->nb = nb = n-nb ; /* nb = # of strongly connected components */
- for (b = 0 ; b < nb ; b++) /* sort each block in natural order */
- {
- for (k = r [b] ; k < r [b+1] ; k++) Blk [p [k]] = b ;
- }
- for (b = 0 ; b <= nb ; b++) rcopy [b] = r [b] ;
- for (i = 0 ; i < n ; i++) p [rcopy [Blk [i]]++] = i ;
- return (cs_ddone (D, AT, xi, 1)) ;
-}
diff --git a/lib/csparse/cs_schol.c b/lib/csparse/cs_schol.c
deleted file mode 100644
index 32c6734..0000000
--- a/lib/csparse/cs_schol.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "cs.h"
-/* ordering and symbolic analysis for a Cholesky factorization */
-css *cs_schol (int order, const cs *A)
-{
- int n, *c, *post, *P ;
- cs *C ;
- css *S ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- n = A->n ;
- S = cs_calloc (1, sizeof (css)) ; /* allocate result S */
- if (!S) return (NULL) ; /* out of memory */
- P = cs_amd (order, A) ; /* P = amd(A+A'), or natural */
- S->pinv = cs_pinv (P, n) ; /* find inverse permutation */
- cs_free (P) ;
- if (order && !S->pinv) return (cs_sfree (S)) ;
- C = cs_symperm (A, S->pinv, 0) ; /* C = spones(triu(A(P,P))) */
- S->parent = cs_etree (C, 0) ; /* find etree of C */
- post = cs_post (S->parent, n) ; /* postorder the etree */
- c = cs_counts (C, S->parent, post, 0) ; /* find column counts of chol(C) */
- cs_free (post) ;
- cs_spfree (C) ;
- S->cp = cs_malloc (n+1, sizeof (int)) ; /* allocate result S->cp */
- S->unz = S->lnz = cs_cumsum (S->cp, c, n) ; /* find column pointers for L */
- cs_free (c) ;
- return ((S->lnz >= 0) ? S : cs_sfree (S)) ;
-}
diff --git a/lib/csparse/cs_spsolve.c b/lib/csparse/cs_spsolve.c
deleted file mode 100644
index d004f9c..0000000
--- a/lib/csparse/cs_spsolve.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "cs.h"
-/* solve Gx=b(:,k), where G is either upper (lo=0) or lower (lo=1) triangular */
-int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x, const int *pinv,
- int lo)
-{
- int j, J, p, q, px, top, n, *Gp, *Gi, *Bp, *Bi ;
- double *Gx, *Bx ;
- if (!CS_CSC (G) || !CS_CSC (B) || !xi || !x) return (-1) ;
- Gp = G->p ; Gi = G->i ; Gx = G->x ; n = G->n ;
- Bp = B->p ; Bi = B->i ; Bx = B->x ;
- top = cs_reach (G, B, k, xi, pinv) ; /* xi[top..n-1]=Reach(B(:,k)) */
- for (p = top ; p < n ; p++) x [xi [p]] = 0 ; /* clear x */
- for (p = Bp [k] ; p < Bp [k+1] ; p++) x [Bi [p]] = Bx [p] ; /* scatter B */
- for (px = top ; px < n ; px++)
- {
- j = xi [px] ; /* x(j) is nonzero */
- J = pinv ? (pinv [j]) : j ; /* j maps to col J of G */
- if (J < 0) continue ; /* column J is empty */
- x [j] /= Gx [lo ? (Gp [J]) : (Gp [J+1]-1)] ;/* x(j) /= G(j,j) */
- p = lo ? (Gp [J]+1) : (Gp [J]) ; /* lo: L(j,j) 1st entry */
- q = lo ? (Gp [J+1]) : (Gp [J+1]-1) ; /* up: U(j,j) last entry */
- for ( ; p < q ; p++)
- {
- x [Gi [p]] -= Gx [p] * x [j] ; /* x(i) -= G(i,j) * x(j) */
- }
- }
- return (top) ; /* return top of stack */
-}
diff --git a/lib/csparse/cs_sqr.c b/lib/csparse/cs_sqr.c
deleted file mode 100644
index ad39bd2..0000000
--- a/lib/csparse/cs_sqr.c
+++ /dev/null
@@ -1,88 +0,0 @@
-#include "cs.h"
-/* compute nnz(V) = S->lnz, S->pinv, S->leftmost, S->m2 from A and S->parent */
-static int cs_vcount (const cs *A, css *S)
-{
- int i, k, p, pa, n = A->n, m = A->m, *Ap = A->p, *Ai = A->i, *next, *head,
- *tail, *nque, *pinv, *leftmost, *w, *parent = S->parent ;
- S->pinv = pinv = cs_malloc (m+n, sizeof (int)) ; /* allocate pinv, */
- S->leftmost = leftmost = cs_malloc (m, sizeof (int)) ; /* and leftmost */
- w = cs_malloc (m+3*n, sizeof (int)) ; /* get workspace */
- if (!pinv || !w || !leftmost)
- {
- cs_free (w) ; /* pinv and leftmost freed later */
- return (0) ; /* out of memory */
- }
- next = w ; head = w + m ; tail = w + m + n ; nque = w + m + 2*n ;
- for (k = 0 ; k < n ; k++) head [k] = -1 ; /* queue k is empty */
- for (k = 0 ; k < n ; k++) tail [k] = -1 ;
- for (k = 0 ; k < n ; k++) nque [k] = 0 ;
- for (i = 0 ; i < m ; i++) leftmost [i] = -1 ;
- for (k = n-1 ; k >= 0 ; k--)
- {
- for (p = Ap [k] ; p < Ap [k+1] ; p++)
- {
- leftmost [Ai [p]] = k ; /* leftmost[i] = min(find(A(i,:)))*/
- }
- }
- for (i = m-1 ; i >= 0 ; i--) /* scan rows in reverse order */
- {
- pinv [i] = -1 ; /* row i is not yet ordered */
- k = leftmost [i] ;
- if (k == -1) continue ; /* row i is empty */
- if (nque [k]++ == 0) tail [k] = i ; /* first row in queue k */
- next [i] = head [k] ; /* put i at head of queue k */
- head [k] = i ;
- }
- S->lnz = 0 ;
- S->m2 = m ;
- for (k = 0 ; k < n ; k++) /* find row permutation and nnz(V)*/
- {
- i = head [k] ; /* remove row i from queue k */
- S->lnz++ ; /* count V(k,k) as nonzero */
- if (i < 0) i = S->m2++ ; /* add a fictitious row */
- pinv [i] = k ; /* associate row i with V(:,k) */
- if (--nque [k] <= 0) continue ; /* skip if V(k+1:m,k) is empty */
- S->lnz += nque [k] ; /* nque [k] is nnz (V(k+1:m,k)) */
- if ((pa = parent [k]) != -1) /* move all rows to parent of k */
- {
- if (nque [pa] == 0) tail [pa] = tail [k] ;
- next [tail [k]] = head [pa] ;
- head [pa] = next [i] ;
- nque [pa] += nque [k] ;
- }
- }
- for (i = 0 ; i < m ; i++) if (pinv [i] < 0) pinv [i] = k++ ;
- cs_free (w) ;
- return (1) ;
-}
-
-/* symbolic ordering and analysis for QR or LU */
-css *cs_sqr (int order, const cs *A, int qr)
-{
- int n, k, ok = 1, *post ;
- css *S ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- n = A->n ;
- S = cs_calloc (1, sizeof (css)) ; /* allocate result S */
- if (!S) return (NULL) ; /* out of memory */
- S->q = cs_amd (order, A) ; /* fill-reducing ordering */
- if (order && !S->q) return (cs_sfree (S)) ;
- if (qr) /* QR symbolic analysis */
- {
- cs *C = order ? cs_permute (A, NULL, S->q, 0) : ((cs *) A) ;
- S->parent = cs_etree (C, 1) ; /* etree of C'*C, where C=A(:,q) */
- post = cs_post (S->parent, n) ;
- S->cp = cs_counts (C, S->parent, post, 1) ; /* col counts chol(C'*C) */
- cs_free (post) ;
- ok = C && S->parent && S->cp && cs_vcount (C, S) ;
- if (ok) for (S->unz = 0, k = 0 ; k < n ; k++) S->unz += S->cp [k] ;
- ok = ok && S->lnz >= 0 && S->unz >= 0 ; /* int overflow guard */
- if (order) cs_spfree (C) ;
- }
- else
- {
- S->unz = 4*(A->p [n]) + n ; /* for LU factorization only, */
- S->lnz = S->unz ; /* guess nnz(L) and nnz(U) */
- }
- return (ok ? S : cs_sfree (S)) ; /* return result S */
-}
diff --git a/lib/csparse/cs_symperm.c b/lib/csparse/cs_symperm.c
deleted file mode 100644
index 668526d..0000000
--- a/lib/csparse/cs_symperm.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "cs.h"
-/* C = A(p,p) where A and C are symmetric the upper part stored; pinv not p */
-cs *cs_symperm (const cs *A, const int *pinv, int values)
-{
- int i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w ;
- double *Cx, *Ax ;
- cs *C ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- C = cs_spalloc (n, n, Ap [n], values && (Ax != NULL), 0) ; /* alloc result*/
- w = cs_calloc (n, sizeof (int)) ; /* get workspace */
- if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- for (j = 0 ; j < n ; j++) /* count entries in each column of C */
- {
- j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ;
- if (i > j) continue ; /* skip lower triangular part of A */
- i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */
- w [CS_MAX (i2, j2)]++ ; /* column count of C */
- }
- }
- cs_cumsum (Cp, w, n) ; /* compute column pointers of C */
- for (j = 0 ; j < n ; j++)
- {
- j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- i = Ai [p] ;
- if (i > j) continue ; /* skip lower triangular part of A*/
- i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */
- Ci [q = w [CS_MAX (i2, j2)]++] = CS_MIN (i2, j2) ;
- if (Cx) Cx [q] = Ax [p] ;
- }
- }
- return (cs_done (C, w, NULL, 1)) ; /* success; free workspace, return C */
-}
diff --git a/lib/csparse/cs_tdfs.c b/lib/csparse/cs_tdfs.c
deleted file mode 100644
index ad19890..0000000
--- a/lib/csparse/cs_tdfs.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "cs.h"
-/* depth-first search and postorder of a tree rooted at node j */
-int cs_tdfs (int j, int k, int *head, const int *next, int *post, int *stack)
-{
- int i, p, top = 0 ;
- if (!head || !next || !post || !stack) return (-1) ; /* check inputs */
- stack [0] = j ; /* place j on the stack */
- while (top >= 0) /* while (stack is not empty) */
- {
- p = stack [top] ; /* p = top of stack */
- i = head [p] ; /* i = youngest child of p */
- if (i == -1)
- {
- top-- ; /* p has no unordered children left */
- post [k++] = p ; /* node p is the kth postordered node */
- }
- else
- {
- head [p] = next [i] ; /* remove i from children of p */
- stack [++top] = i ; /* start dfs on child node i */
- }
- }
- return (k) ;
-}
diff --git a/lib/csparse/cs_transpose.c b/lib/csparse/cs_transpose.c
deleted file mode 100644
index 9daa84d..0000000
--- a/lib/csparse/cs_transpose.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cs.h"
-/* C = A' */
-cs *cs_transpose (const cs *A, int values)
-{
- int p, q, j, *Cp, *Ci, n, m, *Ap, *Ai, *w ;
- double *Cx, *Ax ;
- cs *C ;
- if (!CS_CSC (A)) return (NULL) ; /* check inputs */
- m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
- C = cs_spalloc (n, m, Ap [n], values && Ax, 0) ; /* allocate result */
- w = cs_calloc (m, sizeof (int)) ; /* get workspace */
- if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- for (p = 0 ; p < Ap [n] ; p++) w [Ai [p]]++ ; /* row counts */
- cs_cumsum (Cp, w, m) ; /* row pointers */
- for (j = 0 ; j < n ; j++)
- {
- for (p = Ap [j] ; p < Ap [j+1] ; p++)
- {
- Ci [q = w [Ai [p]]++] = j ; /* place A(i,j) as entry C(j,i) */
- if (Cx) Cx [q] = Ax [p] ;
- }
- }
- return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */
-}
diff --git a/lib/csparse/cs_updown.c b/lib/csparse/cs_updown.c
deleted file mode 100644
index 90dc4cc..0000000
--- a/lib/csparse/cs_updown.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "cs.h"
-/* sparse Cholesky update/downdate, L*L' + sigma*w*w' (sigma = +1 or -1) */
-int cs_updown (cs *L, int sigma, const cs *C, const int *parent)
-{
- int n, p, f, j, *Lp, *Li, *Cp, *Ci ;
- double *Lx, *Cx, alpha, beta = 1, delta, gamma, w1, w2, *w, beta2 = 1 ;
- if (!CS_CSC (L) || !CS_CSC (C) || !parent) return (0) ; /* check inputs */
- Lp = L->p ; Li = L->i ; Lx = L->x ; n = L->n ;
- Cp = C->p ; Ci = C->i ; Cx = C->x ;
- if ((p = Cp [0]) >= Cp [1]) return (1) ; /* return if C empty */
- w = cs_malloc (n, sizeof (double)) ; /* get workspace */
- if (!w) return (0) ; /* out of memory */
- f = Ci [p] ;
- for ( ; p < Cp [1] ; p++) f = CS_MIN (f, Ci [p]) ; /* f = min (find (C)) */
- for (j = f ; j != -1 ; j = parent [j]) w [j] = 0 ; /* clear workspace w */
- for (p = Cp [0] ; p < Cp [1] ; p++) w [Ci [p]] = Cx [p] ; /* w = C */
- for (j = f ; j != -1 ; j = parent [j]) /* walk path f up to root */
- {
- p = Lp [j] ;
- alpha = w [j] / Lx [p] ; /* alpha = w(j) / L(j,j) */
- beta2 = beta*beta + sigma*alpha*alpha ;
- if (beta2 <= 0) break ; /* not positive definite */
- beta2 = sqrt (beta2) ;
- delta = (sigma > 0) ? (beta / beta2) : (beta2 / beta) ;
- gamma = sigma * alpha / (beta2 * beta) ;
- Lx [p] = delta * Lx [p] + ((sigma > 0) ? (gamma * w [j]) : 0) ;
- beta = beta2 ;
- for (p++ ; p < Lp [j+1] ; p++)
- {
- w1 = w [Li [p]] ;
- w [Li [p]] = w2 = w1 - alpha * Lx [p] ;
- Lx [p] = delta * Lx [p] + gamma * ((sigma > 0) ? w1 : w2) ;
- }
- }
- cs_free (w) ;
- return (beta2 > 0) ;
-}
diff --git a/lib/csparse/cs_usolve.c b/lib/csparse/cs_usolve.c
deleted file mode 100644
index 40e0892..0000000
--- a/lib/csparse/cs_usolve.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "cs.h"
-/* solve Ux=b where x and b are dense. x=b on input, solution on output. */
-int cs_usolve (const cs *U, double *x)
-{
- int p, j, n, *Up, *Ui ;
- double *Ux ;
- if (!CS_CSC (U) || !x) return (0) ; /* check inputs */
- n = U->n ; Up = U->p ; Ui = U->i ; Ux = U->x ;
- for (j = n-1 ; j >= 0 ; j--)
- {
- x [j] /= Ux [Up [j+1]-1] ;
- for (p = Up [j] ; p < Up [j+1]-1 ; p++)
- {
- x [Ui [p]] -= Ux [p] * x [j] ;
- }
- }
- return (1) ;
-}
diff --git a/lib/csparse/cs_util.c b/lib/csparse/cs_util.c
deleted file mode 100644
index 5684cd2..0000000
--- a/lib/csparse/cs_util.c
+++ /dev/null
@@ -1,119 +0,0 @@
-#include "cs.h"
-/* allocate a sparse matrix (triplet form or compressed-column form) */
-cs *cs_spalloc (int m, int n, int nzmax, int values, int triplet)
-{
- cs *A = cs_calloc (1, sizeof (cs)) ; /* allocate the cs struct */
- if (!A) return (NULL) ; /* out of memory */
- A->m = m ; /* define dimensions and nzmax */
- A->n = n ;
- A->nzmax = nzmax = CS_MAX (nzmax, 1) ;
- A->nz = triplet ? 0 : -1 ; /* allocate triplet or comp.col */
- A->p = cs_malloc (triplet ? nzmax : n+1, sizeof (int)) ;
- A->i = cs_malloc (nzmax, sizeof (int)) ;
- A->x = values ? cs_malloc (nzmax, sizeof (double)) : NULL ;
- return ((!A->p || !A->i || (values && !A->x)) ? cs_spfree (A) : A) ;
-}
-
-/* change the max # of entries sparse matrix */
-int cs_sprealloc (cs *A, int nzmax)
-{
- int ok, oki, okj = 1, okx = 1 ;
- if (!A) return (0) ;
- if (nzmax <= 0) nzmax = (CS_CSC (A)) ? (A->p [A->n]) : A->nz ;
- A->i = cs_realloc (A->i, nzmax, sizeof (int), &oki) ;
- if (CS_TRIPLET (A)) A->p = cs_realloc (A->p, nzmax, sizeof (int), &okj) ;
- if (A->x) A->x = cs_realloc (A->x, nzmax, sizeof (double), &okx) ;
- ok = (oki && okj && okx) ;
- if (ok) A->nzmax = nzmax ;
- return (ok) ;
-}
-
-/* free a sparse matrix */
-cs *cs_spfree (cs *A)
-{
- if (!A) return (NULL) ; /* do nothing if A already NULL */
- cs_free (A->p) ;
- cs_free (A->i) ;
- cs_free (A->x) ;
- return (cs_free (A)) ; /* free the cs struct and return NULL */
-}
-
-/* free a numeric factorization */
-csn *cs_nfree (csn *N)
-{
- if (!N) return (NULL) ; /* do nothing if N already NULL */
- cs_spfree (N->L) ;
- cs_spfree (N->U) ;
- cs_free (N->pinv) ;
- cs_free (N->B) ;
- return (cs_free (N)) ; /* free the csn struct and return NULL */
-}
-
-/* free a symbolic factorization */
-css *cs_sfree (css *S)
-{
- if (!S) return (NULL) ; /* do nothing if S already NULL */
- cs_free (S->pinv) ;
- cs_free (S->q) ;
- cs_free (S->parent) ;
- cs_free (S->cp) ;
- cs_free (S->leftmost) ;
- return (cs_free (S)) ; /* free the css struct and return NULL */
-}
-
-/* allocate a cs_dmperm or cs_scc result */
-csd *cs_dalloc (int m, int n)
-{
- csd *D ;
- D = cs_calloc (1, sizeof (csd)) ;
- if (!D) return (NULL) ;
- D->p = cs_malloc (m, sizeof (int)) ;
- D->r = cs_malloc (m+6, sizeof (int)) ;
- D->q = cs_malloc (n, sizeof (int)) ;
- D->s = cs_malloc (n+6, sizeof (int)) ;
- return ((!D->p || !D->r || !D->q || !D->s) ? cs_dfree (D) : D) ;
-}
-
-/* free a cs_dmperm or cs_scc result */
-csd *cs_dfree (csd *D)
-{
- if (!D) return (NULL) ; /* do nothing if D already NULL */
- cs_free (D->p) ;
- cs_free (D->q) ;
- cs_free (D->r) ;
- cs_free (D->s) ;
- return (cs_free (D)) ;
-}
-
-/* free workspace and return a sparse matrix result */
-cs *cs_done (cs *C, void *w, void *x, int ok)
-{
- cs_free (w) ; /* free workspace */
- cs_free (x) ;
- return (ok ? C : cs_spfree (C)) ; /* return result if OK, else free it */
-}
-
-/* free workspace and return int array result */
-int *cs_idone (int *p, cs *C, void *w, int ok)
-{
- cs_spfree (C) ; /* free temporary matrix */
- cs_free (w) ; /* free workspace */
- return (ok ? p : cs_free (p)) ; /* return result if OK, else free it */
-}
-
-/* free workspace and return a numeric factorization (Cholesky, LU, or QR) */
-csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok)
-{
- cs_spfree (C) ; /* free temporary matrix */
- cs_free (w) ; /* free workspace */
- cs_free (x) ;
- return (ok ? N : cs_nfree (N)) ; /* return result if OK, else free it */
-}
-
-/* free workspace and return a csd result */
-csd *cs_ddone (csd *D, cs *C, void *w, int ok)
-{
- cs_spfree (C) ; /* free temporary matrix */
- cs_free (w) ; /* free workspace */
- return (ok ? D : cs_dfree (D)) ; /* return result if OK, else free it */
-}
diff --git a/lib/csparse/cs_utsolve.c b/lib/csparse/cs_utsolve.c
deleted file mode 100644
index 9d6bf63..0000000
--- a/lib/csparse/cs_utsolve.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "cs.h"
-/* solve U'x=b where x and b are dense. x=b on input, solution on output. */
-int cs_utsolve (const cs *U, double *x)
-{
- int p, j, n, *Up, *Ui ;
- double *Ux ;
- if (!CS_CSC (U) || !x) return (0) ; /* check inputs */
- n = U->n ; Up = U->p ; Ui = U->i ; Ux = U->x ;
- for (j = 0 ; j < n ; j++)
- {
- for (p = Up [j] ; p < Up [j+1]-1 ; p++)
- {
- x [j] -= Ux [p] * x [Ui [p]] ;
- }
- x [j] /= Ux [Up [j+1]-1] ;
- }
- return (1) ;
-}
diff --git a/lib/lua/LICENSE b/lib/lua/LICENSE
deleted file mode 100644
index 3472ac6..0000000
--- a/lib/lua/LICENSE
+++ /dev/null
@@ -1,7 +0,0 @@
-Copyright © 1994-2007 Lua.org, PUC-Rio.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/lib/lua/Makefile b/lib/lua/Makefile
deleted file mode 100644
index 429f2b8..0000000
--- a/lib/lua/Makefile
+++ /dev/null
@@ -1,182 +0,0 @@
-# makefile for building Lua
-# see ../INSTALL for installation instructions
-# see ../Makefile and luaconf.h for further customization
-
-# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
-
-PLAT= posix
-
-CC= gcc
-CFLAGS= -O2 -Wall $(MYCFLAGS)
-AR= ar rcu
-RANLIB= ranlib
-RM= rm -f
-LIBS= -lm $(MYLIBS)
-
-MYCFLAGS=-DLUA_USE_POSIX
-MYLDFLAGS=
-MYLIBS=
-
-# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
-
-PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
-
-LUA_A= liblua.a
-CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
- lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
- lundump.o lvm.o lzio.o
-LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
- lstrlib.o loadlib.o linit.o
-
-LUA_T= lua
-LUA_O= lua.o
-
-LUAC_T= luac
-LUAC_O= luac.o print.o
-
-ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
-ALL_A= $(LUA_A)
-
-default: $(PLAT)
-
-all: $(ALL_T)
-
-o: $(ALL_O)
-
-a: $(ALL_A)
-
-$(LUA_A): $(CORE_O) $(LIB_O)
- $(AR) $@ $?
- $(RANLIB) $@
-
-$(LUA_T): $(LUA_O) $(LUA_A)
- @$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
-
-$(LUAC_T): $(LUAC_O) $(LUA_A)
- @$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
-
-clean:
- $(RM) $(ALL_T) $(ALL_O)
-
-depend:
- @$(CC) $(CFLAGS) -MM l*.c print.c
-
-echo:
- @echo "PLAT = $(PLAT)"
- @echo "CC = $(CC)"
- @echo "CFLAGS = $(CFLAGS)"
- @echo "AR = $(AR)"
- @echo "RANLIB = $(RANLIB)"
- @echo "RM = $(RM)"
- @echo "MYCFLAGS = $(MYCFLAGS)"
- @echo "MYLDFLAGS = $(MYLDFLAGS)"
- @echo "MYLIBS = $(MYLIBS)"
-
-# convenience targets for popular platforms
-
-none:
- @echo "Please choose a platform:"
- @echo " $(PLATS)"
-
-aix:
- $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
-
-ansi:
- $(MAKE) all MYCFLAGS=-DLUA_ANSI
-
-bsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
-
-freebsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
-
-generic:
- $(MAKE) all MYCFLAGS=
-
-linux:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
-
-macosx:
- $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
-# use this on Mac OS X 10.4
-# $(MAKE) all MYCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" MYLIBS="-lreadline"
-
-mingw:
- $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
- "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
- "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
- $(MAKE) "LUAC_T=luac.exe" luac.exe
-
-posix:
- $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
-
-solaris:
- $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
-
-# list targets that do not create files (but not all makes understand .PHONY)
-.PHONY: all $(PLATS) default o a clean depend echo none
-
-# DO NOT DELETE
-
-lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
- lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \
- lundump.h lvm.h
-lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
-lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
-lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
- lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
- ltable.h
-ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
-ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \
- llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
- lfunc.h lstring.h lgc.h ltable.h lvm.h
-ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \
- ltable.h lundump.h lvm.h
-ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
- lzio.h lmem.h lundump.h
-lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
- lstate.h ltm.h lzio.h
-lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
-linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
-liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
-llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
- lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
-lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
-lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h
-loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \
- lualib.h
-lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
- ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
-lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
-loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
-lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
- lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
- lfunc.h lstring.h lgc.h ltable.h
-lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
-lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
- ltm.h lzio.h lstring.h lgc.h
-lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
-ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h
-ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
-ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
- lmem.h lstring.h lgc.h ltable.h
-lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
-luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \
- lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
- lundump.h
-lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
- llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
-lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
-lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
- lzio.h
-print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h lopcodes.h lundump.h
-
-# (end of Makefile)
diff --git a/lib/lua/lapi.c b/lib/lua/lapi.c
deleted file mode 100644
index 5d5145d..0000000
--- a/lib/lua/lapi.c
+++ /dev/null
@@ -1,1087 +0,0 @@
-/*
-** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $
-** Lua API
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-
-#define lapi_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lapi.h"
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-#include "lundump.h"
-#include "lvm.h"
-
-
-
-const char lua_ident[] =
- "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n"
- "$Authors: " LUA_AUTHORS " $\n"
- "$URL: www.lua.org $\n";
-
-
-
-#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
-
-#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
-
-#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
-
-
-
-static TValue *index2adr (lua_State *L, int idx) {
- if (idx > 0) {
- TValue *o = L->base + (idx - 1);
- api_check(L, idx <= L->ci->top - L->base);
- if (o >= L->top) return cast(TValue *, luaO_nilobject);
- else return o;
- }
- else if (idx > LUA_REGISTRYINDEX) {
- api_check(L, idx != 0 && -idx <= L->top - L->base);
- return L->top + idx;
- }
- else switch (idx) { /* pseudo-indices */
- case LUA_REGISTRYINDEX: return registry(L);
- case LUA_ENVIRONINDEX: {
- Closure *func = curr_func(L);
- sethvalue(L, &L->env, func->c.env);
- return &L->env;
- }
- case LUA_GLOBALSINDEX: return gt(L);
- default: {
- Closure *func = curr_func(L);
- idx = LUA_GLOBALSINDEX - idx;
- return (idx <= func->c.nupvalues)
- ? &func->c.upvalue[idx-1]
- : cast(TValue *, luaO_nilobject);
- }
- }
-}
-
-
-static Table *getcurrenv (lua_State *L) {
- if (L->ci == L->base_ci) /* no enclosing function? */
- return hvalue(gt(L)); /* use global table as environment */
- else {
- Closure *func = curr_func(L);
- return func->c.env;
- }
-}
-
-
-void luaA_pushobject (lua_State *L, const TValue *o) {
- setobj2s(L, L->top, o);
- api_incr_top(L);
-}
-
-
-LUA_API int lua_checkstack (lua_State *L, int size) {
- int res = 1;
- lua_lock(L);
- if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
- res = 0; /* stack overflow */
- else if (size > 0) {
- luaD_checkstack(L, size);
- if (L->ci->top < L->top + size)
- L->ci->top = L->top + size;
- }
- lua_unlock(L);
- return res;
-}
-
-
-LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
- int i;
- if (from == to) return;
- lua_lock(to);
- api_checknelems(from, n);
- api_check(from, G(from) == G(to));
- api_check(from, to->ci->top - to->top >= n);
- from->top -= n;
- for (i = 0; i < n; i++) {
- setobj2s(to, to->top++, from->top + i);
- }
- lua_unlock(to);
-}
-
-
-LUA_API void lua_setlevel (lua_State *from, lua_State *to) {
- to->nCcalls = from->nCcalls;
-}
-
-
-LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
- lua_CFunction old;
- lua_lock(L);
- old = G(L)->panic;
- G(L)->panic = panicf;
- lua_unlock(L);
- return old;
-}
-
-
-LUA_API lua_State *lua_newthread (lua_State *L) {
- lua_State *L1;
- lua_lock(L);
- luaC_checkGC(L);
- L1 = luaE_newthread(L);
- setthvalue(L, L->top, L1);
- api_incr_top(L);
- lua_unlock(L);
- luai_userstatethread(L, L1);
- return L1;
-}
-
-
-
-/*
-** basic stack manipulation
-*/
-
-
-LUA_API int lua_gettop (lua_State *L) {
- return cast_int(L->top - L->base);
-}
-
-
-LUA_API void lua_settop (lua_State *L, int idx) {
- lua_lock(L);
- if (idx >= 0) {
- api_check(L, idx <= L->stack_last - L->base);
- while (L->top < L->base + idx)
- setnilvalue(L->top++);
- L->top = L->base + idx;
- }
- else {
- api_check(L, -(idx+1) <= (L->top - L->base));
- L->top += idx+1; /* `subtract' index (index is negative) */
- }
- lua_unlock(L);
-}
-
-
-LUA_API void lua_remove (lua_State *L, int idx) {
- StkId p;
- lua_lock(L);
- p = index2adr(L, idx);
- api_checkvalidindex(L, p);
- while (++p < L->top) setobjs2s(L, p-1, p);
- L->top--;
- lua_unlock(L);
-}
-
-
-LUA_API void lua_insert (lua_State *L, int idx) {
- StkId p;
- StkId q;
- lua_lock(L);
- p = index2adr(L, idx);
- api_checkvalidindex(L, p);
- for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
- setobjs2s(L, p, L->top);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_replace (lua_State *L, int idx) {
- StkId o;
- lua_lock(L);
- /* explicit test for incompatible code */
- if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
- luaG_runerror(L, "no calling environment");
- api_checknelems(L, 1);
- o = index2adr(L, idx);
- api_checkvalidindex(L, o);
- if (idx == LUA_ENVIRONINDEX) {
- Closure *func = curr_func(L);
- api_check(L, ttistable(L->top - 1));
- func->c.env = hvalue(L->top - 1);
- luaC_barrier(L, func, L->top - 1);
- }
- else {
- setobj(L, o, L->top - 1);
- if (idx < LUA_GLOBALSINDEX) /* function upvalue? */
- luaC_barrier(L, curr_func(L), L->top - 1);
- }
- L->top--;
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushvalue (lua_State *L, int idx) {
- lua_lock(L);
- setobj2s(L, L->top, index2adr(L, idx));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-
-/*
-** access functions (stack -> C)
-*/
-
-
-LUA_API int lua_type (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
-}
-
-
-LUA_API const char *lua_typename (lua_State *L, int t) {
- UNUSED(L);
- return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
-}
-
-
-LUA_API int lua_iscfunction (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- return iscfunction(o);
-}
-
-
-LUA_API int lua_isnumber (lua_State *L, int idx) {
- TValue n;
- const TValue *o = index2adr(L, idx);
- return tonumber(o, &n);
-}
-
-
-LUA_API int lua_isstring (lua_State *L, int idx) {
- int t = lua_type(L, idx);
- return (t == LUA_TSTRING || t == LUA_TNUMBER);
-}
-
-
-LUA_API int lua_isuserdata (lua_State *L, int idx) {
- const TValue *o = index2adr(L, idx);
- return (ttisuserdata(o) || ttislightuserdata(o));
-}
-
-
-LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
- StkId o1 = index2adr(L, index1);
- StkId o2 = index2adr(L, index2);
- return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
- : luaO_rawequalObj(o1, o2);
-}
-
-
-LUA_API int lua_equal (lua_State *L, int index1, int index2) {
- StkId o1, o2;
- int i;
- lua_lock(L); /* may call tag method */
- o1 = index2adr(L, index1);
- o2 = index2adr(L, index2);
- i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
- lua_unlock(L);
- return i;
-}
-
-
-LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
- StkId o1, o2;
- int i;
- lua_lock(L); /* may call tag method */
- o1 = index2adr(L, index1);
- o2 = index2adr(L, index2);
- i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
- : luaV_lessthan(L, o1, o2);
- lua_unlock(L);
- return i;
-}
-
-
-
-LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
- TValue n;
- const TValue *o = index2adr(L, idx);
- if (tonumber(o, &n))
- return nvalue(o);
- else
- return 0;
-}
-
-
-LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
- TValue n;
- const TValue *o = index2adr(L, idx);
- if (tonumber(o, &n)) {
- lua_Integer res;
- lua_Number num = nvalue(o);
- lua_number2integer(res, num);
- return res;
- }
- else
- return 0;
-}
-
-
-LUA_API int lua_toboolean (lua_State *L, int idx) {
- const TValue *o = index2adr(L, idx);
- return !l_isfalse(o);
-}
-
-
-LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
- StkId o = index2adr(L, idx);
- if (!ttisstring(o)) {
- lua_lock(L); /* `luaV_tostring' may create a new string */
- if (!luaV_tostring(L, o)) { /* conversion failed? */
- if (len != NULL) *len = 0;
- lua_unlock(L);
- return NULL;
- }
- luaC_checkGC(L);
- o = index2adr(L, idx); /* previous call may reallocate the stack */
- lua_unlock(L);
- }
- if (len != NULL) *len = tsvalue(o)->len;
- return svalue(o);
-}
-
-
-LUA_API size_t lua_objlen (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- switch (ttype(o)) {
- case LUA_TSTRING: return tsvalue(o)->len;
- case LUA_TUSERDATA: return uvalue(o)->len;
- case LUA_TTABLE: return luaH_getn(hvalue(o));
- case LUA_TNUMBER: {
- size_t l;
- lua_lock(L); /* `luaV_tostring' may create a new string */
- l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
- lua_unlock(L);
- return l;
- }
- default: return 0;
- }
-}
-
-
-LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
-}
-
-
-LUA_API void *lua_touserdata (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- switch (ttype(o)) {
- case LUA_TUSERDATA: return (rawuvalue(o) + 1);
- case LUA_TLIGHTUSERDATA: return pvalue(o);
- default: return NULL;
- }
-}
-
-
-LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- return (!ttisthread(o)) ? NULL : thvalue(o);
-}
-
-
-LUA_API const void *lua_topointer (lua_State *L, int idx) {
- StkId o = index2adr(L, idx);
- switch (ttype(o)) {
- case LUA_TTABLE: return hvalue(o);
- case LUA_TFUNCTION: return clvalue(o);
- case LUA_TTHREAD: return thvalue(o);
- case LUA_TUSERDATA:
- case LUA_TLIGHTUSERDATA:
- return lua_touserdata(L, idx);
- default: return NULL;
- }
-}
-
-
-
-/*
-** push functions (C -> stack)
-*/
-
-
-LUA_API void lua_pushnil (lua_State *L) {
- lua_lock(L);
- setnilvalue(L->top);
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
- lua_lock(L);
- setnvalue(L->top, n);
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
- lua_lock(L);
- setnvalue(L->top, cast_num(n));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
- lua_lock(L);
- luaC_checkGC(L);
- setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushstring (lua_State *L, const char *s) {
- if (s == NULL)
- lua_pushnil(L);
- else
- lua_pushlstring(L, s, strlen(s));
-}
-
-
-LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
- va_list argp) {
- const char *ret;
- lua_lock(L);
- luaC_checkGC(L);
- ret = luaO_pushvfstring(L, fmt, argp);
- lua_unlock(L);
- return ret;
-}
-
-
-LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
- const char *ret;
- va_list argp;
- lua_lock(L);
- luaC_checkGC(L);
- va_start(argp, fmt);
- ret = luaO_pushvfstring(L, fmt, argp);
- va_end(argp);
- lua_unlock(L);
- return ret;
-}
-
-
-LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
- Closure *cl;
- lua_lock(L);
- luaC_checkGC(L);
- api_checknelems(L, n);
- cl = luaF_newCclosure(L, n, getcurrenv(L));
- cl->c.f = fn;
- L->top -= n;
- while (n--)
- setobj2n(L, &cl->c.upvalue[n], L->top+n);
- setclvalue(L, L->top, cl);
- lua_assert(iswhite(obj2gco(cl)));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushboolean (lua_State *L, int b) {
- lua_lock(L);
- setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
- lua_lock(L);
- setpvalue(L->top, p);
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API int lua_pushthread (lua_State *L) {
- lua_lock(L);
- setthvalue(L, L->top, L);
- api_incr_top(L);
- lua_unlock(L);
- return (G(L)->mainthread == L);
-}
-
-
-
-/*
-** get functions (Lua -> stack)
-*/
-
-
-LUA_API void lua_gettable (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- t = index2adr(L, idx);
- api_checkvalidindex(L, t);
- luaV_gettable(L, t, L->top - 1, L->top - 1);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
- StkId t;
- TValue key;
- lua_lock(L);
- t = index2adr(L, idx);
- api_checkvalidindex(L, t);
- setsvalue(L, &key, luaS_new(L, k));
- luaV_gettable(L, t, &key, L->top);
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_rawget (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- t = index2adr(L, idx);
- api_check(L, ttistable(t));
- setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
- lua_unlock(L);
-}
-
-
-LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
- StkId o;
- lua_lock(L);
- o = index2adr(L, idx);
- api_check(L, ttistable(o));
- setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
- lua_lock(L);
- luaC_checkGC(L);
- sethvalue(L, L->top, luaH_new(L, narray, nrec));
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-LUA_API int lua_getmetatable (lua_State *L, int objindex) {
- const TValue *obj;
- Table *mt = NULL;
- int res;
- lua_lock(L);
- obj = index2adr(L, objindex);
- switch (ttype(obj)) {
- case LUA_TTABLE:
- mt = hvalue(obj)->metatable;
- break;
- case LUA_TUSERDATA:
- mt = uvalue(obj)->metatable;
- break;
- default:
- mt = G(L)->mt[ttype(obj)];
- break;
- }
- if (mt == NULL)
- res = 0;
- else {
- sethvalue(L, L->top, mt);
- api_incr_top(L);
- res = 1;
- }
- lua_unlock(L);
- return res;
-}
-
-
-LUA_API void lua_getfenv (lua_State *L, int idx) {
- StkId o;
- lua_lock(L);
- o = index2adr(L, idx);
- api_checkvalidindex(L, o);
- switch (ttype(o)) {
- case LUA_TFUNCTION:
- sethvalue(L, L->top, clvalue(o)->c.env);
- break;
- case LUA_TUSERDATA:
- sethvalue(L, L->top, uvalue(o)->env);
- break;
- case LUA_TTHREAD:
- setobj2s(L, L->top, gt(thvalue(o)));
- break;
- default:
- setnilvalue(L->top);
- break;
- }
- api_incr_top(L);
- lua_unlock(L);
-}
-
-
-/*
-** set functions (stack -> Lua)
-*/
-
-
-LUA_API void lua_settable (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 2);
- t = index2adr(L, idx);
- api_checkvalidindex(L, t);
- luaV_settable(L, t, L->top - 2, L->top - 1);
- L->top -= 2; /* pop index and value */
- lua_unlock(L);
-}
-
-
-LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
- StkId t;
- TValue key;
- lua_lock(L);
- api_checknelems(L, 1);
- t = index2adr(L, idx);
- api_checkvalidindex(L, t);
- setsvalue(L, &key, luaS_new(L, k));
- luaV_settable(L, t, &key, L->top - 1);
- L->top--; /* pop value */
- lua_unlock(L);
-}
-
-
-LUA_API void lua_rawset (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 2);
- t = index2adr(L, idx);
- api_check(L, ttistable(t));
- setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
- luaC_barriert(L, hvalue(t), L->top-1);
- L->top -= 2;
- lua_unlock(L);
-}
-
-
-LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
- StkId o;
- lua_lock(L);
- api_checknelems(L, 1);
- o = index2adr(L, idx);
- api_check(L, ttistable(o));
- setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
- luaC_barriert(L, hvalue(o), L->top-1);
- L->top--;
- lua_unlock(L);
-}
-
-
-LUA_API int lua_setmetatable (lua_State *L, int objindex) {
- TValue *obj;
- Table *mt;
- lua_lock(L);
- api_checknelems(L, 1);
- obj = index2adr(L, objindex);
- api_checkvalidindex(L, obj);
- if (ttisnil(L->top - 1))
- mt = NULL;
- else {
- api_check(L, ttistable(L->top - 1));
- mt = hvalue(L->top - 1);
- }
- switch (ttype(obj)) {
- case LUA_TTABLE: {
- hvalue(obj)->metatable = mt;
- if (mt)
- luaC_objbarriert(L, hvalue(obj), mt);
- break;
- }
- case LUA_TUSERDATA: {
- uvalue(obj)->metatable = mt;
- if (mt)
- luaC_objbarrier(L, rawuvalue(obj), mt);
- break;
- }
- default: {
- G(L)->mt[ttype(obj)] = mt;
- break;
- }
- }
- L->top--;
- lua_unlock(L);
- return 1;
-}
-
-
-LUA_API int lua_setfenv (lua_State *L, int idx) {
- StkId o;
- int res = 1;
- lua_lock(L);
- api_checknelems(L, 1);
- o = index2adr(L, idx);
- api_checkvalidindex(L, o);
- api_check(L, ttistable(L->top - 1));
- switch (ttype(o)) {
- case LUA_TFUNCTION:
- clvalue(o)->c.env = hvalue(L->top - 1);
- break;
- case LUA_TUSERDATA:
- uvalue(o)->env = hvalue(L->top - 1);
- break;
- case LUA_TTHREAD:
- sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));
- break;
- default:
- res = 0;
- break;
- }
- if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
- L->top--;
- lua_unlock(L);
- return res;
-}
-
-
-/*
-** `load' and `call' functions (run Lua code)
-*/
-
-
-#define adjustresults(L,nres) \
- { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
-
-
-#define checkresults(L,na,nr) \
- api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))
-
-
-LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
- StkId func;
- lua_lock(L);
- api_checknelems(L, nargs+1);
- checkresults(L, nargs, nresults);
- func = L->top - (nargs+1);
- luaD_call(L, func, nresults);
- adjustresults(L, nresults);
- lua_unlock(L);
-}
-
-
-
-/*
-** Execute a protected call.
-*/
-struct CallS { /* data to `f_call' */
- StkId func;
- int nresults;
-};
-
-
-static void f_call (lua_State *L, void *ud) {
- struct CallS *c = cast(struct CallS *, ud);
- luaD_call(L, c->func, c->nresults);
-}
-
-
-
-LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
- struct CallS c;
- int status;
- ptrdiff_t func;
- lua_lock(L);
- api_checknelems(L, nargs+1);
- checkresults(L, nargs, nresults);
- if (errfunc == 0)
- func = 0;
- else {
- StkId o = index2adr(L, errfunc);
- api_checkvalidindex(L, o);
- func = savestack(L, o);
- }
- c.func = L->top - (nargs+1); /* function to be called */
- c.nresults = nresults;
- status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
- adjustresults(L, nresults);
- lua_unlock(L);
- return status;
-}
-
-
-/*
-** Execute a protected C call.
-*/
-struct CCallS { /* data to `f_Ccall' */
- lua_CFunction func;
- void *ud;
-};
-
-
-static void f_Ccall (lua_State *L, void *ud) {
- struct CCallS *c = cast(struct CCallS *, ud);
- Closure *cl;
- cl = luaF_newCclosure(L, 0, getcurrenv(L));
- cl->c.f = c->func;
- setclvalue(L, L->top, cl); /* push function */
- api_incr_top(L);
- setpvalue(L->top, c->ud); /* push only argument */
- api_incr_top(L);
- luaD_call(L, L->top - 2, 0);
-}
-
-
-LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
- struct CCallS c;
- int status;
- lua_lock(L);
- c.func = func;
- c.ud = ud;
- status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);
- lua_unlock(L);
- return status;
-}
-
-
-LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
- const char *chunkname) {
- ZIO z;
- int status;
- lua_lock(L);
- if (!chunkname) chunkname = "?";
- luaZ_init(L, &z, reader, data);
- status = luaD_protectedparser(L, &z, chunkname);
- lua_unlock(L);
- return status;
-}
-
-
-LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
- int status;
- TValue *o;
- lua_lock(L);
- api_checknelems(L, 1);
- o = L->top - 1;
- if (isLfunction(o))
- status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
- else
- status = 1;
- lua_unlock(L);
- return status;
-}
-
-
-LUA_API int lua_status (lua_State *L) {
- return L->status;
-}
-
-
-/*
-** Garbage-collection function
-*/
-
-LUA_API int lua_gc (lua_State *L, int what, int data) {
- int res = 0;
- global_State *g;
- lua_lock(L);
- g = G(L);
- switch (what) {
- case LUA_GCSTOP: {
- g->GCthreshold = MAX_LUMEM;
- break;
- }
- case LUA_GCRESTART: {
- g->GCthreshold = g->totalbytes;
- break;
- }
- case LUA_GCCOLLECT: {
- luaC_fullgc(L);
- break;
- }
- case LUA_GCCOUNT: {
- /* GC values are expressed in Kbytes: #bytes/2^10 */
- res = cast_int(g->totalbytes >> 10);
- break;
- }
- case LUA_GCCOUNTB: {
- res = cast_int(g->totalbytes & 0x3ff);
- break;
- }
- case LUA_GCSTEP: {
- lu_mem a = (cast(lu_mem, data) << 10);
- if (a <= g->totalbytes)
- g->GCthreshold = g->totalbytes - a;
- else
- g->GCthreshold = 0;
- while (g->GCthreshold <= g->totalbytes) {
- luaC_step(L);
- if (g->gcstate == GCSpause) { /* end of cycle? */
- res = 1; /* signal it */
- break;
- }
- }
- break;
- }
- case LUA_GCSETPAUSE: {
- res = g->gcpause;
- g->gcpause = data;
- break;
- }
- case LUA_GCSETSTEPMUL: {
- res = g->gcstepmul;
- g->gcstepmul = data;
- break;
- }
- default: res = -1; /* invalid option */
- }
- lua_unlock(L);
- return res;
-}
-
-
-
-/*
-** miscellaneous functions
-*/
-
-
-LUA_API int lua_error (lua_State *L) {
- lua_lock(L);
- api_checknelems(L, 1);
- luaG_errormsg(L);
- lua_unlock(L);
- return 0; /* to avoid warnings */
-}
-
-
-LUA_API int lua_next (lua_State *L, int idx) {
- StkId t;
- int more;
- lua_lock(L);
- t = index2adr(L, idx);
- api_check(L, ttistable(t));
- more = luaH_next(L, hvalue(t), L->top - 1);
- if (more) {
- api_incr_top(L);
- }
- else /* no more elements */
- L->top -= 1; /* remove key */
- lua_unlock(L);
- return more;
-}
-
-
-LUA_API void lua_concat (lua_State *L, int n) {
- lua_lock(L);
- api_checknelems(L, n);
- if (n >= 2) {
- luaC_checkGC(L);
- luaV_concat(L, n, cast_int(L->top - L->base) - 1);
- L->top -= (n-1);
- }
- else if (n == 0) { /* push empty string */
- setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
- api_incr_top(L);
- }
- /* else n == 1; nothing to do */
- lua_unlock(L);
-}
-
-
-LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
- lua_Alloc f;
- lua_lock(L);
- if (ud) *ud = G(L)->ud;
- f = G(L)->frealloc;
- lua_unlock(L);
- return f;
-}
-
-
-LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
- lua_lock(L);
- G(L)->ud = ud;
- G(L)->frealloc = f;
- lua_unlock(L);
-}
-
-
-LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
- Udata *u;
- lua_lock(L);
- luaC_checkGC(L);
- u = luaS_newudata(L, size, getcurrenv(L));
- setuvalue(L, L->top, u);
- api_incr_top(L);
- lua_unlock(L);
- return u + 1;
-}
-
-
-
-
-static const char *aux_upvalue (StkId fi, int n, TValue **val) {
- Closure *f;
- if (!ttisfunction(fi)) return NULL;
- f = clvalue(fi);
- if (f->c.isC) {
- if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
- *val = &f->c.upvalue[n-1];
- return "";
- }
- else {
- Proto *p = f->l.p;
- if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
- *val = f->l.upvals[n-1]->v;
- return getstr(p->upvalues[n-1]);
- }
-}
-
-
-LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
- const char *name;
- TValue *val;
- lua_lock(L);
- name = aux_upvalue(index2adr(L, funcindex), n, &val);
- if (name) {
- setobj2s(L, L->top, val);
- api_incr_top(L);
- }
- lua_unlock(L);
- return name;
-}
-
-
-LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
- const char *name;
- TValue *val;
- StkId fi;
- lua_lock(L);
- fi = index2adr(L, funcindex);
- api_checknelems(L, 1);
- name = aux_upvalue(fi, n, &val);
- if (name) {
- L->top--;
- setobj(L, val, L->top);
- luaC_barrier(L, clvalue(fi), L->top);
- }
- lua_unlock(L);
- return name;
-}
-
diff --git a/lib/lua/lapi.h b/lib/lua/lapi.h
deleted file mode 100644
index 2c3fab2..0000000
--- a/lib/lua/lapi.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
-** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
-** Auxiliary functions from Lua API
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lapi_h
-#define lapi_h
-
-
-#include "lobject.h"
-
-
-LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
-
-#endif
diff --git a/lib/lua/lauxlib.c b/lib/lua/lauxlib.c
deleted file mode 100644
index 10f14e2..0000000
--- a/lib/lua/lauxlib.c
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
-** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $
-** Auxiliary functions for building Lua libraries
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-/* This file uses only the official API of Lua.
-** Any function declared here could be written as an application function.
-*/
-
-#define lauxlib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-
-
-#define FREELIST_REF 0 /* free list of references */
-
-
-/* convert a stack index to positive */
-#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
- lua_gettop(L) + (i) + 1)
-
-
-/*
-** {======================================================
-** Error-report functions
-** =======================================================
-*/
-
-
-LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
- lua_Debug ar;
- if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
- return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
- lua_getinfo(L, "n", &ar);
- if (strcmp(ar.namewhat, "method") == 0) {
- narg--; /* do not count `self' */
- if (narg == 0) /* error is in the self argument itself? */
- return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
- ar.name, extramsg);
- }
- if (ar.name == NULL)
- ar.name = "?";
- return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
- narg, ar.name, extramsg);
-}
-
-
-LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
- const char *msg = lua_pushfstring(L, "%s expected, got %s",
- tname, luaL_typename(L, narg));
- return luaL_argerror(L, narg, msg);
-}
-
-
-static void tag_error (lua_State *L, int narg, int tag) {
- luaL_typerror(L, narg, lua_typename(L, tag));
-}
-
-
-LUALIB_API void luaL_where (lua_State *L, int level) {
- lua_Debug ar;
- if (lua_getstack(L, level, &ar)) { /* check function at level */
- lua_getinfo(L, "Sl", &ar); /* get info about it */
- if (ar.currentline > 0) { /* is there info? */
- lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
- return;
- }
- }
- lua_pushliteral(L, ""); /* else, no information available... */
-}
-
-
-LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
- va_list argp;
- va_start(argp, fmt);
- luaL_where(L, 1);
- lua_pushvfstring(L, fmt, argp);
- va_end(argp);
- lua_concat(L, 2);
- return lua_error(L);
-}
-
-/* }====================================================== */
-
-
-LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
- const char *const lst[]) {
- const char *name = (def) ? luaL_optstring(L, narg, def) :
- luaL_checkstring(L, narg);
- int i;
- for (i=0; lst[i]; i++)
- if (strcmp(lst[i], name) == 0)
- return i;
- return luaL_argerror(L, narg,
- lua_pushfstring(L, "invalid option " LUA_QS, name));
-}
-
-
-LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
- lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */
- if (!lua_isnil(L, -1)) /* name already in use? */
- return 0; /* leave previous value on top, but return 0 */
- lua_pop(L, 1);
- lua_newtable(L); /* create metatable */
- lua_pushvalue(L, -1);
- lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
- return 1;
-}
-
-
-LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
- void *p = lua_touserdata(L, ud);
- if (p != NULL) { /* value is a userdata? */
- if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
- lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
- if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
- lua_pop(L, 2); /* remove both metatables */
- return p;
- }
- }
- }
- luaL_typerror(L, ud, tname); /* else error */
- return NULL; /* to avoid warnings */
-}
-
-
-LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
- if (!lua_checkstack(L, space))
- luaL_error(L, "stack overflow (%s)", mes);
-}
-
-
-LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
- if (lua_type(L, narg) != t)
- tag_error(L, narg, t);
-}
-
-
-LUALIB_API void luaL_checkany (lua_State *L, int narg) {
- if (lua_type(L, narg) == LUA_TNONE)
- luaL_argerror(L, narg, "value expected");
-}
-
-
-LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
- const char *s = lua_tolstring(L, narg, len);
- if (!s) tag_error(L, narg, LUA_TSTRING);
- return s;
-}
-
-
-LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
- const char *def, size_t *len) {
- if (lua_isnoneornil(L, narg)) {
- if (len)
- *len = (def ? strlen(def) : 0);
- return def;
- }
- else return luaL_checklstring(L, narg, len);
-}
-
-
-LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
- lua_Number d = lua_tonumber(L, narg);
- if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
- tag_error(L, narg, LUA_TNUMBER);
- return d;
-}
-
-
-LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
- return luaL_opt(L, luaL_checknumber, narg, def);
-}
-
-
-LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
- lua_Integer d = lua_tointeger(L, narg);
- if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
- tag_error(L, narg, LUA_TNUMBER);
- return d;
-}
-
-
-LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
- lua_Integer def) {
- return luaL_opt(L, luaL_checkinteger, narg, def);
-}
-
-
-LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
- if (!lua_getmetatable(L, obj)) /* no metatable? */
- return 0;
- lua_pushstring(L, event);
- lua_rawget(L, -2);
- if (lua_isnil(L, -1)) {
- lua_pop(L, 2); /* remove metatable and metafield */
- return 0;
- }
- else {
- lua_remove(L, -2); /* remove only metatable */
- return 1;
- }
-}
-
-
-LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
- obj = abs_index(L, obj);
- if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
- return 0;
- lua_pushvalue(L, obj);
- lua_call(L, 1, 1);
- return 1;
-}
-
-
-LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
- const luaL_Reg *l) {
- luaI_openlib(L, libname, l, 0);
-}
-
-
-static int libsize (const luaL_Reg *l) {
- int size = 0;
- for (; l->name; l++) size++;
- return size;
-}
-
-
-LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup) {
- if (libname) {
- int size = libsize(l);
- /* check whether lib already exists */
- luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
- lua_getfield(L, -1, libname); /* get _LOADED[libname] */
- if (!lua_istable(L, -1)) { /* not found? */
- lua_pop(L, 1); /* remove previous result */
- /* try global variable (and create one if it does not exist) */
- if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
- luaL_error(L, "name conflict for module " LUA_QS, libname);
- lua_pushvalue(L, -1);
- lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
- }
- lua_remove(L, -2); /* remove _LOADED table */
- lua_insert(L, -(nup+1)); /* move library table to below upvalues */
- }
- for (; l->name; l++) {
- int i;
- for (i=0; ifunc, nup);
- lua_setfield(L, -(nup+2), l->name);
- }
- lua_pop(L, nup); /* remove upvalues */
-}
-
-
-
-/*
-** {======================================================
-** getn-setn: size for arrays
-** =======================================================
-*/
-
-#if defined(LUA_COMPAT_GETN)
-
-static int checkint (lua_State *L, int topop) {
- int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;
- lua_pop(L, topop);
- return n;
-}
-
-
-static void getsizes (lua_State *L) {
- lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES");
- if (lua_isnil(L, -1)) { /* no `size' table? */
- lua_pop(L, 1); /* remove nil */
- lua_newtable(L); /* create it */
- lua_pushvalue(L, -1); /* `size' will be its own metatable */
- lua_setmetatable(L, -2);
- lua_pushliteral(L, "kv");
- lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */
- lua_pushvalue(L, -1);
- lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */
- }
-}
-
-
-LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
- t = abs_index(L, t);
- lua_pushliteral(L, "n");
- lua_rawget(L, t);
- if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
- lua_pushliteral(L, "n"); /* use it */
- lua_pushinteger(L, n);
- lua_rawset(L, t);
- }
- else { /* use `sizes' */
- getsizes(L);
- lua_pushvalue(L, t);
- lua_pushinteger(L, n);
- lua_rawset(L, -3); /* sizes[t] = n */
- lua_pop(L, 1); /* remove `sizes' */
- }
-}
-
-
-LUALIB_API int luaL_getn (lua_State *L, int t) {
- int n;
- t = abs_index(L, t);
- lua_pushliteral(L, "n"); /* try t.n */
- lua_rawget(L, t);
- if ((n = checkint(L, 1)) >= 0) return n;
- getsizes(L); /* else try sizes[t] */
- lua_pushvalue(L, t);
- lua_rawget(L, -2);
- if ((n = checkint(L, 2)) >= 0) return n;
- return (int)lua_objlen(L, t);
-}
-
-#endif
-
-/* }====================================================== */
-
-
-
-LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
- const char *r) {
- const char *wild;
- size_t l = strlen(p);
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- while ((wild = strstr(s, p)) != NULL) {
- luaL_addlstring(&b, s, wild - s); /* push prefix */
- luaL_addstring(&b, r); /* push replacement in place of pattern */
- s = wild + l; /* continue after `p' */
- }
- luaL_addstring(&b, s); /* push last suffix */
- luaL_pushresult(&b);
- return lua_tostring(L, -1);
-}
-
-
-LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
- const char *fname, int szhint) {
- const char *e;
- lua_pushvalue(L, idx);
- do {
- e = strchr(fname, '.');
- if (e == NULL) e = fname + strlen(fname);
- lua_pushlstring(L, fname, e - fname);
- lua_rawget(L, -2);
- if (lua_isnil(L, -1)) { /* no such field? */
- lua_pop(L, 1); /* remove this nil */
- lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
- lua_pushlstring(L, fname, e - fname);
- lua_pushvalue(L, -2);
- lua_settable(L, -4); /* set new table into field */
- }
- else if (!lua_istable(L, -1)) { /* field has a non-table value? */
- lua_pop(L, 2); /* remove table and value */
- return fname; /* return problematic part of the name */
- }
- lua_remove(L, -2); /* remove previous table */
- fname = e + 1;
- } while (*e == '.');
- return NULL;
-}
-
-
-
-/*
-** {======================================================
-** Generic Buffer manipulation
-** =======================================================
-*/
-
-
-#define bufflen(B) ((B)->p - (B)->buffer)
-#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
-
-#define LIMIT (LUA_MINSTACK/2)
-
-
-static int emptybuffer (luaL_Buffer *B) {
- size_t l = bufflen(B);
- if (l == 0) return 0; /* put nothing on stack */
- else {
- lua_pushlstring(B->L, B->buffer, l);
- B->p = B->buffer;
- B->lvl++;
- return 1;
- }
-}
-
-
-static void adjuststack (luaL_Buffer *B) {
- if (B->lvl > 1) {
- lua_State *L = B->L;
- int toget = 1; /* number of levels to concat */
- size_t toplen = lua_strlen(L, -1);
- do {
- size_t l = lua_strlen(L, -(toget+1));
- if (B->lvl - toget + 1 >= LIMIT || toplen > l) {
- toplen += l;
- toget++;
- }
- else break;
- } while (toget < B->lvl);
- lua_concat(L, toget);
- B->lvl = B->lvl - toget + 1;
- }
-}
-
-
-LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
- if (emptybuffer(B))
- adjuststack(B);
- return B->buffer;
-}
-
-
-LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
- while (l--)
- luaL_addchar(B, *s++);
-}
-
-
-LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
- luaL_addlstring(B, s, strlen(s));
-}
-
-
-LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
- emptybuffer(B);
- lua_concat(B->L, B->lvl);
- B->lvl = 1;
-}
-
-
-LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
- lua_State *L = B->L;
- size_t vl;
- const char *s = lua_tolstring(L, -1, &vl);
- if (vl <= bufffree(B)) { /* fit into buffer? */
- memcpy(B->p, s, vl); /* put it there */
- B->p += vl;
- lua_pop(L, 1); /* remove from stack */
- }
- else {
- if (emptybuffer(B))
- lua_insert(L, -2); /* put buffer before new value */
- B->lvl++; /* add new value into B stack */
- adjuststack(B);
- }
-}
-
-
-LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
- B->L = L;
- B->p = B->buffer;
- B->lvl = 0;
-}
-
-/* }====================================================== */
-
-
-LUALIB_API int luaL_ref (lua_State *L, int t) {
- int ref;
- t = abs_index(L, t);
- if (lua_isnil(L, -1)) {
- lua_pop(L, 1); /* remove from stack */
- return LUA_REFNIL; /* `nil' has a unique fixed reference */
- }
- lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
- ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
- lua_pop(L, 1); /* remove it from stack */
- if (ref != 0) { /* any free element? */
- lua_rawgeti(L, t, ref); /* remove it from list */
- lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
- }
- else { /* no free elements */
- ref = (int)lua_objlen(L, t);
- ref++; /* create new reference */
- }
- lua_rawseti(L, t, ref);
- return ref;
-}
-
-
-LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
- if (ref >= 0) {
- t = abs_index(L, t);
- lua_rawgeti(L, t, FREELIST_REF);
- lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
- lua_pushinteger(L, ref);
- lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
- }
-}
-
-
-
-/*
-** {======================================================
-** Load functions
-** =======================================================
-*/
-
-typedef struct LoadF {
- int extraline;
- FILE *f;
- char buff[LUAL_BUFFERSIZE];
-} LoadF;
-
-
-static const char *getF (lua_State *L, void *ud, size_t *size) {
- LoadF *lf = (LoadF *)ud;
- (void)L;
- if (lf->extraline) {
- lf->extraline = 0;
- *size = 1;
- return "\n";
- }
- if (feof(lf->f)) return NULL;
- *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
- return (*size > 0) ? lf->buff : NULL;
-}
-
-
-static int errfile (lua_State *L, const char *what, int fnameindex) {
- const char *serr = strerror(errno);
- const char *filename = lua_tostring(L, fnameindex) + 1;
- lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
- lua_remove(L, fnameindex);
- return LUA_ERRFILE;
-}
-
-
-LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
- LoadF lf;
- int status, readstatus;
- int c;
- int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
- lf.extraline = 0;
- if (filename == NULL) {
- lua_pushliteral(L, "=stdin");
- lf.f = stdin;
- }
- else {
- lua_pushfstring(L, "@%s", filename);
- lf.f = fopen(filename, "r");
- if (lf.f == NULL) return errfile(L, "open", fnameindex);
- }
- c = getc(lf.f);
- if (c == '#') { /* Unix exec. file? */
- lf.extraline = 1;
- while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
- if (c == '\n') c = getc(lf.f);
- }
- if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
- lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
- if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
- /* skip eventual `#!...' */
- while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
- lf.extraline = 0;
- }
- ungetc(c, lf.f);
- status = lua_load(L, getF, &lf, lua_tostring(L, -1));
- readstatus = ferror(lf.f);
- if (filename) fclose(lf.f); /* close file (even in case of errors) */
- if (readstatus) {
- lua_settop(L, fnameindex); /* ignore results from `lua_load' */
- return errfile(L, "read", fnameindex);
- }
- lua_remove(L, fnameindex);
- return status;
-}
-
-
-typedef struct LoadS {
- const char *s;
- size_t size;
-} LoadS;
-
-
-static const char *getS (lua_State *L, void *ud, size_t *size) {
- LoadS *ls = (LoadS *)ud;
- (void)L;
- if (ls->size == 0) return NULL;
- *size = ls->size;
- ls->size = 0;
- return ls->s;
-}
-
-
-LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,
- const char *name) {
- LoadS ls;
- ls.s = buff;
- ls.size = size;
- return lua_load(L, getS, &ls, name);
-}
-
-
-LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {
- return luaL_loadbuffer(L, s, strlen(s), s);
-}
-
-
-
-/* }====================================================== */
-
-
-static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
- (void)ud;
- (void)osize;
- if (nsize == 0) {
- free(ptr);
- return NULL;
- }
- else
- return realloc(ptr, nsize);
-}
-
-
-static int panic (lua_State *L) {
- (void)L; /* to avoid warnings */
- fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
- lua_tostring(L, -1));
- return 0;
-}
-
-
-LUALIB_API lua_State *luaL_newstate (void) {
- lua_State *L = lua_newstate(l_alloc, NULL);
- if (L) lua_atpanic(L, &panic);
- return L;
-}
-
diff --git a/lib/lua/lauxlib.h b/lib/lua/lauxlib.h
deleted file mode 100644
index 3425823..0000000
--- a/lib/lua/lauxlib.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
-** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
-** Auxiliary functions for building Lua libraries
-** See Copyright Notice in lua.h
-*/
-
-
-#ifndef lauxlib_h
-#define lauxlib_h
-
-
-#include
-#include
-
-#include "lua.h"
-
-
-#if defined(LUA_COMPAT_GETN)
-LUALIB_API int (luaL_getn) (lua_State *L, int t);
-LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
-#else
-#define luaL_getn(L,i) ((int)lua_objlen(L, i))
-#define luaL_setn(L,i,j) ((void)0) /* no op! */
-#endif
-
-#if defined(LUA_COMPAT_OPENLIB)
-#define luaI_openlib luaL_openlib
-#endif
-
-
-/* extra error code for `luaL_load' */
-#define LUA_ERRFILE (LUA_ERRERR+1)
-
-
-typedef struct luaL_Reg {
- const char *name;
- lua_CFunction func;
-} luaL_Reg;
-
-
-
-LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup);
-LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
- const luaL_Reg *l);
-LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
-LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
-LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
-LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
-LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
- size_t *l);
-LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
- const char *def, size_t *l);
-LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
-LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
-
-LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
-LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
- lua_Integer def);
-
-LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
-LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
-LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
-
-LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
-LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
-
-LUALIB_API void (luaL_where) (lua_State *L, int lvl);
-LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
-
-LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
- const char *const lst[]);
-
-LUALIB_API int (luaL_ref) (lua_State *L, int t);
-LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
-
-LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
-LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
- const char *name);
-LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
-
-LUALIB_API lua_State *(luaL_newstate) (void);
-
-
-LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
- const char *r);
-
-LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
- const char *fname, int szhint);
-
-
-
-
-/*
-** ===============================================================
-** some useful macros
-** ===============================================================
-*/
-
-#define luaL_argcheck(L, cond,numarg,extramsg) \
- ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
-#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
-#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
-#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
-#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
-#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
-#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
-
-#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
-
-#define luaL_dofile(L, fn) \
- (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
-
-#define luaL_dostring(L, s) \
- (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
-
-#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
-
-#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
-
-/*
-** {======================================================
-** Generic Buffer manipulation
-** =======================================================
-*/
-
-
-
-typedef struct luaL_Buffer {
- char *p; /* current position in buffer */
- int lvl; /* number of strings in the stack (level) */
- lua_State *L;
- char buffer[LUAL_BUFFERSIZE];
-} luaL_Buffer;
-
-#define luaL_addchar(B,c) \
- ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
- (*(B)->p++ = (char)(c)))
-
-/* compatibility only */
-#define luaL_putchar(B,c) luaL_addchar(B,c)
-
-#define luaL_addsize(B,n) ((B)->p += (n))
-
-LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
-LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
-LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
-LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
-LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
-LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
-
-
-/* }====================================================== */
-
-
-/* compatibility with ref system */
-
-/* pre-defined references */
-#define LUA_NOREF (-2)
-#define LUA_REFNIL (-1)
-
-#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
- (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
-
-#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
-
-#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
-
-
-#define luaL_reg luaL_Reg
-
-#endif
-
-
diff --git a/lib/lua/lbaselib.c b/lib/lua/lbaselib.c
deleted file mode 100644
index 2a4c079..0000000
--- a/lib/lua/lbaselib.c
+++ /dev/null
@@ -1,653 +0,0 @@
-/*
-** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $
-** Basic library
-** See Copyright Notice in lua.h
-*/
-
-
-
-#include
-#include
-#include
-#include
-
-#define lbaselib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-
-
-/*
-** If your system does not support `stdout', you can just remove this function.
-** If you need, you can define your own `print' function, following this
-** model but changing `fputs' to put the strings at a proper place
-** (a console window or a log file, for instance).
-*/
-static int luaB_print (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- int i;
- lua_getglobal(L, "tostring");
- for (i=1; i<=n; i++) {
- const char *s;
- lua_pushvalue(L, -1); /* function to be called */
- lua_pushvalue(L, i); /* value to print */
- lua_call(L, 1, 1);
- s = lua_tostring(L, -1); /* get result */
- if (s == NULL)
- return luaL_error(L, LUA_QL("tostring") " must return a string to "
- LUA_QL("print"));
- if (i>1) fputs("\t", stdout);
- fputs(s, stdout);
- lua_pop(L, 1); /* pop result */
- }
- fputs("\n", stdout);
- return 0;
-}
-
-
-static int luaB_tonumber (lua_State *L) {
- int base = luaL_optint(L, 2, 10);
- if (base == 10) { /* standard conversion */
- luaL_checkany(L, 1);
- if (lua_isnumber(L, 1)) {
- lua_pushnumber(L, lua_tonumber(L, 1));
- return 1;
- }
- }
- else {
- const char *s1 = luaL_checkstring(L, 1);
- char *s2;
- unsigned long n;
- luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
- n = strtoul(s1, &s2, base);
- if (s1 != s2) { /* at least one valid digit? */
- while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
- if (*s2 == '\0') { /* no invalid trailing characters? */
- lua_pushnumber(L, (lua_Number)n);
- return 1;
- }
- }
- }
- lua_pushnil(L); /* else not a number */
- return 1;
-}
-
-
-static int luaB_error (lua_State *L) {
- int level = luaL_optint(L, 2, 1);
- lua_settop(L, 1);
- if (lua_isstring(L, 1) && level > 0) { /* add extra information? */
- luaL_where(L, level);
- lua_pushvalue(L, 1);
- lua_concat(L, 2);
- }
- return lua_error(L);
-}
-
-
-static int luaB_getmetatable (lua_State *L) {
- luaL_checkany(L, 1);
- if (!lua_getmetatable(L, 1)) {
- lua_pushnil(L);
- return 1; /* no metatable */
- }
- luaL_getmetafield(L, 1, "__metatable");
- return 1; /* returns either __metatable field (if present) or metatable */
-}
-
-
-static int luaB_setmetatable (lua_State *L) {
- int t = lua_type(L, 2);
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
- "nil or table expected");
- if (luaL_getmetafield(L, 1, "__metatable"))
- luaL_error(L, "cannot change a protected metatable");
- lua_settop(L, 2);
- lua_setmetatable(L, 1);
- return 1;
-}
-
-
-static void getfunc (lua_State *L, int opt) {
- if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
- else {
- lua_Debug ar;
- int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
- luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
- if (lua_getstack(L, level, &ar) == 0)
- luaL_argerror(L, 1, "invalid level");
- lua_getinfo(L, "f", &ar);
- if (lua_isnil(L, -1))
- luaL_error(L, "no function environment for tail call at level %d",
- level);
- }
-}
-
-
-static int luaB_getfenv (lua_State *L) {
- getfunc(L, 1);
- if (lua_iscfunction(L, -1)) /* is a C function? */
- lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
- else
- lua_getfenv(L, -1);
- return 1;
-}
-
-
-static int luaB_setfenv (lua_State *L) {
- luaL_checktype(L, 2, LUA_TTABLE);
- getfunc(L, 0);
- lua_pushvalue(L, 2);
- if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
- /* change environment of current thread */
- lua_pushthread(L);
- lua_insert(L, -2);
- lua_setfenv(L, -2);
- return 0;
- }
- else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)
- luaL_error(L,
- LUA_QL("setfenv") " cannot change environment of given object");
- return 1;
-}
-
-
-static int luaB_rawequal (lua_State *L) {
- luaL_checkany(L, 1);
- luaL_checkany(L, 2);
- lua_pushboolean(L, lua_rawequal(L, 1, 2));
- return 1;
-}
-
-
-static int luaB_rawget (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_checkany(L, 2);
- lua_settop(L, 2);
- lua_rawget(L, 1);
- return 1;
-}
-
-static int luaB_rawset (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_checkany(L, 2);
- luaL_checkany(L, 3);
- lua_settop(L, 3);
- lua_rawset(L, 1);
- return 1;
-}
-
-
-static int luaB_gcinfo (lua_State *L) {
- lua_pushinteger(L, lua_getgccount(L));
- return 1;
-}
-
-
-static int luaB_collectgarbage (lua_State *L) {
- static const char *const opts[] = {"stop", "restart", "collect",
- "count", "step", "setpause", "setstepmul", NULL};
- static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
- LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
- int o = luaL_checkoption(L, 1, "collect", opts);
- int ex = luaL_optint(L, 2, 0);
- int res = lua_gc(L, optsnum[o], ex);
- switch (optsnum[o]) {
- case LUA_GCCOUNT: {
- int b = lua_gc(L, LUA_GCCOUNTB, 0);
- lua_pushnumber(L, res + ((lua_Number)b/1024));
- return 1;
- }
- case LUA_GCSTEP: {
- lua_pushboolean(L, res);
- return 1;
- }
- default: {
- lua_pushnumber(L, res);
- return 1;
- }
- }
-}
-
-
-static int luaB_type (lua_State *L) {
- luaL_checkany(L, 1);
- lua_pushstring(L, luaL_typename(L, 1));
- return 1;
-}
-
-
-static int luaB_next (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_settop(L, 2); /* create a 2nd argument if there isn't one */
- if (lua_next(L, 1))
- return 2;
- else {
- lua_pushnil(L);
- return 1;
- }
-}
-
-
-static int luaB_pairs (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
- lua_pushvalue(L, 1); /* state, */
- lua_pushnil(L); /* and initial value */
- return 3;
-}
-
-
-static int ipairsaux (lua_State *L) {
- int i = luaL_checkint(L, 2);
- luaL_checktype(L, 1, LUA_TTABLE);
- i++; /* next value */
- lua_pushinteger(L, i);
- lua_rawgeti(L, 1, i);
- return (lua_isnil(L, -1)) ? 0 : 2;
-}
-
-
-static int luaB_ipairs (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
- lua_pushvalue(L, 1); /* state, */
- lua_pushinteger(L, 0); /* and initial value */
- return 3;
-}
-
-
-static int load_aux (lua_State *L, int status) {
- if (status == 0) /* OK? */
- return 1;
- else {
- lua_pushnil(L);
- lua_insert(L, -2); /* put before error message */
- return 2; /* return nil plus error message */
- }
-}
-
-
-static int luaB_loadstring (lua_State *L) {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- const char *chunkname = luaL_optstring(L, 2, s);
- return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
-}
-
-
-static int luaB_loadfile (lua_State *L) {
- const char *fname = luaL_optstring(L, 1, NULL);
- return load_aux(L, luaL_loadfile(L, fname));
-}
-
-
-/*
-** Reader for generic `load' function: `lua_load' uses the
-** stack for internal stuff, so the reader cannot change the
-** stack top. Instead, it keeps its resulting string in a
-** reserved slot inside the stack.
-*/
-static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
- (void)ud; /* to avoid warnings */
- luaL_checkstack(L, 2, "too many nested functions");
- lua_pushvalue(L, 1); /* get function */
- lua_call(L, 0, 1); /* call it */
- if (lua_isnil(L, -1)) {
- *size = 0;
- return NULL;
- }
- else if (lua_isstring(L, -1)) {
- lua_replace(L, 3); /* save string in a reserved stack slot */
- return lua_tolstring(L, 3, size);
- }
- else luaL_error(L, "reader function must return a string");
- return NULL; /* to avoid warnings */
-}
-
-
-static int luaB_load (lua_State *L) {
- int status;
- const char *cname = luaL_optstring(L, 2, "=(load)");
- luaL_checktype(L, 1, LUA_TFUNCTION);
- lua_settop(L, 3); /* function, eventual name, plus one reserved slot */
- status = lua_load(L, generic_reader, NULL, cname);
- return load_aux(L, status);
-}
-
-
-static int luaB_dofile (lua_State *L) {
- const char *fname = luaL_optstring(L, 1, NULL);
- int n = lua_gettop(L);
- if (luaL_loadfile(L, fname) != 0) lua_error(L);
- lua_call(L, 0, LUA_MULTRET);
- return lua_gettop(L) - n;
-}
-
-
-static int luaB_assert (lua_State *L) {
- luaL_checkany(L, 1);
- if (!lua_toboolean(L, 1))
- return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
- return lua_gettop(L);
-}
-
-
-static int luaB_unpack (lua_State *L) {
- int i, e, n;
- luaL_checktype(L, 1, LUA_TTABLE);
- i = luaL_optint(L, 2, 1);
- e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
- if (i > e) return 0; /* empty range */
- n = e - i + 1; /* number of elements */
- if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
- return luaL_error(L, "too many results to unpack");
- lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
- while (i++ < e) /* push arg[i + 1...e] */
- lua_rawgeti(L, 1, i);
- return n;
-}
-
-
-static int luaB_select (lua_State *L) {
- int n = lua_gettop(L);
- if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
- lua_pushinteger(L, n-1);
- return 1;
- }
- else {
- int i = luaL_checkint(L, 1);
- if (i < 0) i = n + i;
- else if (i > n) i = n;
- luaL_argcheck(L, 1 <= i, 1, "index out of range");
- return n - i;
- }
-}
-
-
-static int luaB_pcall (lua_State *L) {
- int status;
- luaL_checkany(L, 1);
- status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
- lua_pushboolean(L, (status == 0));
- lua_insert(L, 1);
- return lua_gettop(L); /* return status + all results */
-}
-
-
-static int luaB_xpcall (lua_State *L) {
- int status;
- luaL_checkany(L, 2);
- lua_settop(L, 2);
- lua_insert(L, 1); /* put error function under function to be called */
- status = lua_pcall(L, 0, LUA_MULTRET, 1);
- lua_pushboolean(L, (status == 0));
- lua_replace(L, 1);
- return lua_gettop(L); /* return status + all results */
-}
-
-
-static int luaB_tostring (lua_State *L) {
- luaL_checkany(L, 1);
- if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
- return 1; /* use its value */
- switch (lua_type(L, 1)) {
- case LUA_TNUMBER:
- lua_pushstring(L, lua_tostring(L, 1));
- break;
- case LUA_TSTRING:
- lua_pushvalue(L, 1);
- break;
- case LUA_TBOOLEAN:
- lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false"));
- break;
- case LUA_TNIL:
- lua_pushliteral(L, "nil");
- break;
- default:
- lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1));
- break;
- }
- return 1;
-}
-
-
-static int luaB_newproxy (lua_State *L) {
- lua_settop(L, 1);
- lua_newuserdata(L, 0); /* create proxy */
- if (lua_toboolean(L, 1) == 0)
- return 1; /* no metatable */
- else if (lua_isboolean(L, 1)) {
- lua_newtable(L); /* create a new metatable `m' ... */
- lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
- lua_pushboolean(L, 1);
- lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
- }
- else {
- int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
- if (lua_getmetatable(L, 1)) {
- lua_rawget(L, lua_upvalueindex(1));
- validproxy = lua_toboolean(L, -1);
- lua_pop(L, 1); /* remove value */
- }
- luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
- lua_getmetatable(L, 1); /* metatable is valid; get it */
- }
- lua_setmetatable(L, 2);
- return 1;
-}
-
-
-static const luaL_Reg base_funcs[] = {
- {"assert", luaB_assert},
- {"collectgarbage", luaB_collectgarbage},
- {"dofile", luaB_dofile},
- {"error", luaB_error},
- {"gcinfo", luaB_gcinfo},
- {"getfenv", luaB_getfenv},
- {"getmetatable", luaB_getmetatable},
- {"loadfile", luaB_loadfile},
- {"load", luaB_load},
- {"loadstring", luaB_loadstring},
- {"next", luaB_next},
- {"pcall", luaB_pcall},
- {"print", luaB_print},
- {"rawequal", luaB_rawequal},
- {"rawget", luaB_rawget},
- {"rawset", luaB_rawset},
- {"select", luaB_select},
- {"setfenv", luaB_setfenv},
- {"setmetatable", luaB_setmetatable},
- {"tonumber", luaB_tonumber},
- {"tostring", luaB_tostring},
- {"type", luaB_type},
- {"unpack", luaB_unpack},
- {"xpcall", luaB_xpcall},
- {NULL, NULL}
-};
-
-
-/*
-** {======================================================
-** Coroutine library
-** =======================================================
-*/
-
-#define CO_RUN 0 /* running */
-#define CO_SUS 1 /* suspended */
-#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */
-#define CO_DEAD 3
-
-static const char *const statnames[] =
- {"running", "suspended", "normal", "dead"};
-
-static int costatus (lua_State *L, lua_State *co) {
- if (L == co) return CO_RUN;
- switch (lua_status(co)) {
- case LUA_YIELD:
- return CO_SUS;
- case 0: {
- lua_Debug ar;
- if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
- return CO_NOR; /* it is running */
- else if (lua_gettop(co) == 0)
- return CO_DEAD;
- else
- return CO_SUS; /* initial state */
- }
- default: /* some error occured */
- return CO_DEAD;
- }
-}
-
-
-static int luaB_costatus (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- luaL_argcheck(L, co, 1, "coroutine expected");
- lua_pushstring(L, statnames[costatus(L, co)]);
- return 1;
-}
-
-
-static int auxresume (lua_State *L, lua_State *co, int narg) {
- int status = costatus(L, co);
- if (!lua_checkstack(co, narg))
- luaL_error(L, "too many arguments to resume");
- if (status != CO_SUS) {
- lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]);
- return -1; /* error flag */
- }
- lua_xmove(L, co, narg);
- lua_setlevel(L, co);
- status = lua_resume(co, narg);
- if (status == 0 || status == LUA_YIELD) {
- int nres = lua_gettop(co);
- if (!lua_checkstack(L, nres + 1))
- luaL_error(L, "too many results to resume");
- lua_xmove(co, L, nres); /* move yielded values */
- return nres;
- }
- else {
- lua_xmove(co, L, 1); /* move error message */
- return -1; /* error flag */
- }
-}
-
-
-static int luaB_coresume (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- int r;
- luaL_argcheck(L, co, 1, "coroutine expected");
- r = auxresume(L, co, lua_gettop(L) - 1);
- if (r < 0) {
- lua_pushboolean(L, 0);
- lua_insert(L, -2);
- return 2; /* return false + error message */
- }
- else {
- lua_pushboolean(L, 1);
- lua_insert(L, -(r + 1));
- return r + 1; /* return true + `resume' returns */
- }
-}
-
-
-static int luaB_auxwrap (lua_State *L) {
- lua_State *co = lua_tothread(L, lua_upvalueindex(1));
- int r = auxresume(L, co, lua_gettop(L));
- if (r < 0) {
- if (lua_isstring(L, -1)) { /* error object is a string? */
- luaL_where(L, 1); /* add extra info */
- lua_insert(L, -2);
- lua_concat(L, 2);
- }
- lua_error(L); /* propagate error */
- }
- return r;
-}
-
-
-static int luaB_cocreate (lua_State *L) {
- lua_State *NL = lua_newthread(L);
- luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
- "Lua function expected");
- lua_pushvalue(L, 1); /* move function to top */
- lua_xmove(L, NL, 1); /* move function from L to NL */
- return 1;
-}
-
-
-static int luaB_cowrap (lua_State *L) {
- luaB_cocreate(L);
- lua_pushcclosure(L, luaB_auxwrap, 1);
- return 1;
-}
-
-
-static int luaB_yield (lua_State *L) {
- return lua_yield(L, lua_gettop(L));
-}
-
-
-static int luaB_corunning (lua_State *L) {
- if (lua_pushthread(L))
- lua_pushnil(L); /* main thread is not a coroutine */
- return 1;
-}
-
-
-static const luaL_Reg co_funcs[] = {
- {"create", luaB_cocreate},
- {"resume", luaB_coresume},
- {"running", luaB_corunning},
- {"status", luaB_costatus},
- {"wrap", luaB_cowrap},
- {"yield", luaB_yield},
- {NULL, NULL}
-};
-
-/* }====================================================== */
-
-
-static void auxopen (lua_State *L, const char *name,
- lua_CFunction f, lua_CFunction u) {
- lua_pushcfunction(L, u);
- lua_pushcclosure(L, f, 1);
- lua_setfield(L, -2, name);
-}
-
-
-static void base_open (lua_State *L) {
- /* set global _G */
- lua_pushvalue(L, LUA_GLOBALSINDEX);
- lua_setglobal(L, "_G");
- /* open lib into global table */
- luaL_register(L, "_G", base_funcs);
- lua_pushliteral(L, LUA_VERSION);
- lua_setglobal(L, "_VERSION"); /* set global _VERSION */
- /* `ipairs' and `pairs' need auxliliary functions as upvalues */
- auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
- auxopen(L, "pairs", luaB_pairs, luaB_next);
- /* `newproxy' needs a weaktable as upvalue */
- lua_createtable(L, 0, 1); /* new table `w' */
- lua_pushvalue(L, -1); /* `w' will be its own metatable */
- lua_setmetatable(L, -2);
- lua_pushliteral(L, "kv");
- lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
- lua_pushcclosure(L, luaB_newproxy, 1);
- lua_setglobal(L, "newproxy"); /* set global `newproxy' */
-}
-
-
-LUALIB_API int luaopen_base (lua_State *L) {
- base_open(L);
- luaL_register(L, LUA_COLIBNAME, co_funcs);
- return 2;
-}
-
diff --git a/lib/lua/lcode.c b/lib/lua/lcode.c
deleted file mode 100644
index cff626b..0000000
--- a/lib/lua/lcode.c
+++ /dev/null
@@ -1,839 +0,0 @@
-/*
-** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
-** Code generator for Lua
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lcode_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lcode.h"
-#include "ldebug.h"
-#include "ldo.h"
-#include "lgc.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lparser.h"
-#include "ltable.h"
-
-
-#define hasjumps(e) ((e)->t != (e)->f)
-
-
-static int isnumeral(expdesc *e) {
- return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
-}
-
-
-void luaK_nil (FuncState *fs, int from, int n) {
- Instruction *previous;
- if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
- if (fs->pc == 0) { /* function start? */
- if (from >= fs->nactvar)
- return; /* positions are already clean */
- }
- else {
- previous = &fs->f->code[fs->pc-1];
- if (GET_OPCODE(*previous) == OP_LOADNIL) {
- int pfrom = GETARG_A(*previous);
- int pto = GETARG_B(*previous);
- if (pfrom <= from && from <= pto+1) { /* can connect both? */
- if (from+n-1 > pto)
- SETARG_B(*previous, from+n-1);
- return;
- }
- }
- }
- }
- luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
-}
-
-
-int luaK_jump (FuncState *fs) {
- int jpc = fs->jpc; /* save list of jumps to here */
- int j;
- fs->jpc = NO_JUMP;
- j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
- luaK_concat(fs, &j, jpc); /* keep them on hold */
- return j;
-}
-
-
-void luaK_ret (FuncState *fs, int first, int nret) {
- luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
-}
-
-
-static int condjump (FuncState *fs, OpCode op, int A, int B, int C) {
- luaK_codeABC(fs, op, A, B, C);
- return luaK_jump(fs);
-}
-
-
-static void fixjump (FuncState *fs, int pc, int dest) {
- Instruction *jmp = &fs->f->code[pc];
- int offset = dest-(pc+1);
- lua_assert(dest != NO_JUMP);
- if (abs(offset) > MAXARG_sBx)
- luaX_syntaxerror(fs->ls, "control structure too long");
- SETARG_sBx(*jmp, offset);
-}
-
-
-/*
-** returns current `pc' and marks it as a jump target (to avoid wrong
-** optimizations with consecutive instructions not in the same basic block).
-*/
-int luaK_getlabel (FuncState *fs) {
- fs->lasttarget = fs->pc;
- return fs->pc;
-}
-
-
-static int getjump (FuncState *fs, int pc) {
- int offset = GETARG_sBx(fs->f->code[pc]);
- if (offset == NO_JUMP) /* point to itself represents end of list */
- return NO_JUMP; /* end of list */
- else
- return (pc+1)+offset; /* turn offset into absolute position */
-}
-
-
-static Instruction *getjumpcontrol (FuncState *fs, int pc) {
- Instruction *pi = &fs->f->code[pc];
- if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
- return pi-1;
- else
- return pi;
-}
-
-
-/*
-** check whether list has any jump that do not produce a value
-** (or produce an inverted value)
-*/
-static int need_value (FuncState *fs, int list) {
- for (; list != NO_JUMP; list = getjump(fs, list)) {
- Instruction i = *getjumpcontrol(fs, list);
- if (GET_OPCODE(i) != OP_TESTSET) return 1;
- }
- return 0; /* not found */
-}
-
-
-static int patchtestreg (FuncState *fs, int node, int reg) {
- Instruction *i = getjumpcontrol(fs, node);
- if (GET_OPCODE(*i) != OP_TESTSET)
- return 0; /* cannot patch other instructions */
- if (reg != NO_REG && reg != GETARG_B(*i))
- SETARG_A(*i, reg);
- else /* no register to put value or register already has the value */
- *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
-
- return 1;
-}
-
-
-static void removevalues (FuncState *fs, int list) {
- for (; list != NO_JUMP; list = getjump(fs, list))
- patchtestreg(fs, list, NO_REG);
-}
-
-
-static void patchlistaux (FuncState *fs, int list, int vtarget, int reg,
- int dtarget) {
- while (list != NO_JUMP) {
- int next = getjump(fs, list);
- if (patchtestreg(fs, list, reg))
- fixjump(fs, list, vtarget);
- else
- fixjump(fs, list, dtarget); /* jump to default target */
- list = next;
- }
-}
-
-
-static void dischargejpc (FuncState *fs) {
- patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
- fs->jpc = NO_JUMP;
-}
-
-
-void luaK_patchlist (FuncState *fs, int list, int target) {
- if (target == fs->pc)
- luaK_patchtohere(fs, list);
- else {
- lua_assert(target < fs->pc);
- patchlistaux(fs, list, target, NO_REG, target);
- }
-}
-
-
-void luaK_patchtohere (FuncState *fs, int list) {
- luaK_getlabel(fs);
- luaK_concat(fs, &fs->jpc, list);
-}
-
-
-void luaK_concat (FuncState *fs, int *l1, int l2) {
- if (l2 == NO_JUMP) return;
- else if (*l1 == NO_JUMP)
- *l1 = l2;
- else {
- int list = *l1;
- int next;
- while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
- list = next;
- fixjump(fs, list, l2);
- }
-}
-
-
-void luaK_checkstack (FuncState *fs, int n) {
- int newstack = fs->freereg + n;
- if (newstack > fs->f->maxstacksize) {
- if (newstack >= MAXSTACK)
- luaX_syntaxerror(fs->ls, "function or expression too complex");
- fs->f->maxstacksize = cast_byte(newstack);
- }
-}
-
-
-void luaK_reserveregs (FuncState *fs, int n) {
- luaK_checkstack(fs, n);
- fs->freereg += n;
-}
-
-
-static void freereg (FuncState *fs, int reg) {
- if (!ISK(reg) && reg >= fs->nactvar) {
- fs->freereg--;
- lua_assert(reg == fs->freereg);
- }
-}
-
-
-static void freeexp (FuncState *fs, expdesc *e) {
- if (e->k == VNONRELOC)
- freereg(fs, e->u.s.info);
-}
-
-
-static int addk (FuncState *fs, TValue *k, TValue *v) {
- lua_State *L = fs->L;
- TValue *idx = luaH_set(L, fs->h, k);
- Proto *f = fs->f;
- int oldsize = f->sizek;
- if (ttisnumber(idx)) {
- lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
- return cast_int(nvalue(idx));
- }
- else { /* constant not found; create a new entry */
- setnvalue(idx, cast_num(fs->nk));
- luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
- MAXARG_Bx, "constant table overflow");
- while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
- setobj(L, &f->k[fs->nk], v);
- luaC_barrier(L, f, v);
- return fs->nk++;
- }
-}
-
-
-int luaK_stringK (FuncState *fs, TString *s) {
- TValue o;
- setsvalue(fs->L, &o, s);
- return addk(fs, &o, &o);
-}
-
-
-int luaK_numberK (FuncState *fs, lua_Number r) {
- TValue o;
- setnvalue(&o, r);
- return addk(fs, &o, &o);
-}
-
-
-static int boolK (FuncState *fs, int b) {
- TValue o;
- setbvalue(&o, b);
- return addk(fs, &o, &o);
-}
-
-
-static int nilK (FuncState *fs) {
- TValue k, v;
- setnilvalue(&v);
- /* cannot use nil as key; instead use table itself to represent nil */
- sethvalue(fs->L, &k, fs->h);
- return addk(fs, &k, &v);
-}
-
-
-void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
- if (e->k == VCALL) { /* expression is an open function call? */
- SETARG_C(getcode(fs, e), nresults+1);
- }
- else if (e->k == VVARARG) {
- SETARG_B(getcode(fs, e), nresults+1);
- SETARG_A(getcode(fs, e), fs->freereg);
- luaK_reserveregs(fs, 1);
- }
-}
-
-
-void luaK_setoneret (FuncState *fs, expdesc *e) {
- if (e->k == VCALL) { /* expression is an open function call? */
- e->k = VNONRELOC;
- e->u.s.info = GETARG_A(getcode(fs, e));
- }
- else if (e->k == VVARARG) {
- SETARG_B(getcode(fs, e), 2);
- e->k = VRELOCABLE; /* can relocate its simple result */
- }
-}
-
-
-void luaK_dischargevars (FuncState *fs, expdesc *e) {
- switch (e->k) {
- case VLOCAL: {
- e->k = VNONRELOC;
- break;
- }
- case VUPVAL: {
- e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
- e->k = VRELOCABLE;
- break;
- }
- case VGLOBAL: {
- e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
- e->k = VRELOCABLE;
- break;
- }
- case VINDEXED: {
- freereg(fs, e->u.s.aux);
- freereg(fs, e->u.s.info);
- e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
- e->k = VRELOCABLE;
- break;
- }
- case VVARARG:
- case VCALL: {
- luaK_setoneret(fs, e);
- break;
- }
- default: break; /* there is one value available (somewhere) */
- }
-}
-
-
-static int code_label (FuncState *fs, int A, int b, int jump) {
- luaK_getlabel(fs); /* those instructions may be jump targets */
- return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
-}
-
-
-static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VNIL: {
- luaK_nil(fs, reg, 1);
- break;
- }
- case VFALSE: case VTRUE: {
- luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
- break;
- }
- case VK: {
- luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);
- break;
- }
- case VKNUM: {
- luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));
- break;
- }
- case VRELOCABLE: {
- Instruction *pc = &getcode(fs, e);
- SETARG_A(*pc, reg);
- break;
- }
- case VNONRELOC: {
- if (reg != e->u.s.info)
- luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
- break;
- }
- default: {
- lua_assert(e->k == VVOID || e->k == VJMP);
- return; /* nothing to do... */
- }
- }
- e->u.s.info = reg;
- e->k = VNONRELOC;
-}
-
-
-static void discharge2anyreg (FuncState *fs, expdesc *e) {
- if (e->k != VNONRELOC) {
- luaK_reserveregs(fs, 1);
- discharge2reg(fs, e, fs->freereg-1);
- }
-}
-
-
-static void exp2reg (FuncState *fs, expdesc *e, int reg) {
- discharge2reg(fs, e, reg);
- if (e->k == VJMP)
- luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */
- if (hasjumps(e)) {
- int final; /* position after whole expression */
- int p_f = NO_JUMP; /* position of an eventual LOAD false */
- int p_t = NO_JUMP; /* position of an eventual LOAD true */
- if (need_value(fs, e->t) || need_value(fs, e->f)) {
- int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
- p_f = code_label(fs, reg, 0, 1);
- p_t = code_label(fs, reg, 1, 0);
- luaK_patchtohere(fs, fj);
- }
- final = luaK_getlabel(fs);
- patchlistaux(fs, e->f, final, reg, p_f);
- patchlistaux(fs, e->t, final, reg, p_t);
- }
- e->f = e->t = NO_JUMP;
- e->u.s.info = reg;
- e->k = VNONRELOC;
-}
-
-
-void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- freeexp(fs, e);
- luaK_reserveregs(fs, 1);
- exp2reg(fs, e, fs->freereg - 1);
-}
-
-
-int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- if (e->k == VNONRELOC) {
- if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
- if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
- exp2reg(fs, e, e->u.s.info); /* put value on it */
- return e->u.s.info;
- }
- }
- luaK_exp2nextreg(fs, e); /* default */
- return e->u.s.info;
-}
-
-
-void luaK_exp2val (FuncState *fs, expdesc *e) {
- if (hasjumps(e))
- luaK_exp2anyreg(fs, e);
- else
- luaK_dischargevars(fs, e);
-}
-
-
-int luaK_exp2RK (FuncState *fs, expdesc *e) {
- luaK_exp2val(fs, e);
- switch (e->k) {
- case VKNUM:
- case VTRUE:
- case VFALSE:
- case VNIL: {
- if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
- e->u.s.info = (e->k == VNIL) ? nilK(fs) :
- (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
- boolK(fs, (e->k == VTRUE));
- e->k = VK;
- return RKASK(e->u.s.info);
- }
- else break;
- }
- case VK: {
- if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
- return RKASK(e->u.s.info);
- else break;
- }
- default: break;
- }
- /* not a constant in the right range: put it in a register */
- return luaK_exp2anyreg(fs, e);
-}
-
-
-void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
- switch (var->k) {
- case VLOCAL: {
- freeexp(fs, ex);
- exp2reg(fs, ex, var->u.s.info);
- return;
- }
- case VUPVAL: {
- int e = luaK_exp2anyreg(fs, ex);
- luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
- break;
- }
- case VGLOBAL: {
- int e = luaK_exp2anyreg(fs, ex);
- luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
- break;
- }
- case VINDEXED: {
- int e = luaK_exp2RK(fs, ex);
- luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
- break;
- }
- default: {
- lua_assert(0); /* invalid var kind to store */
- break;
- }
- }
- freeexp(fs, ex);
-}
-
-
-void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
- int func;
- luaK_exp2anyreg(fs, e);
- freeexp(fs, e);
- func = fs->freereg;
- luaK_reserveregs(fs, 2);
- luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
- freeexp(fs, key);
- e->u.s.info = func;
- e->k = VNONRELOC;
-}
-
-
-static void invertjump (FuncState *fs, expdesc *e) {
- Instruction *pc = getjumpcontrol(fs, e->u.s.info);
- lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
- GET_OPCODE(*pc) != OP_TEST);
- SETARG_A(*pc, !(GETARG_A(*pc)));
-}
-
-
-static int jumponcond (FuncState *fs, expdesc *e, int cond) {
- if (e->k == VRELOCABLE) {
- Instruction ie = getcode(fs, e);
- if (GET_OPCODE(ie) == OP_NOT) {
- fs->pc--; /* remove previous OP_NOT */
- return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
- }
- /* else go through */
- }
- discharge2anyreg(fs, e);
- freeexp(fs, e);
- return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
-}
-
-
-void luaK_goiftrue (FuncState *fs, expdesc *e) {
- int pc; /* pc of last jump */
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VK: case VKNUM: case VTRUE: {
- pc = NO_JUMP; /* always true; do nothing */
- break;
- }
- case VFALSE: {
- pc = luaK_jump(fs); /* always jump */
- break;
- }
- case VJMP: {
- invertjump(fs, e);
- pc = e->u.s.info;
- break;
- }
- default: {
- pc = jumponcond(fs, e, 0);
- break;
- }
- }
- luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
- luaK_patchtohere(fs, e->t);
- e->t = NO_JUMP;
-}
-
-
-static void luaK_goiffalse (FuncState *fs, expdesc *e) {
- int pc; /* pc of last jump */
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VNIL: case VFALSE: {
- pc = NO_JUMP; /* always false; do nothing */
- break;
- }
- case VTRUE: {
- pc = luaK_jump(fs); /* always jump */
- break;
- }
- case VJMP: {
- pc = e->u.s.info;
- break;
- }
- default: {
- pc = jumponcond(fs, e, 1);
- break;
- }
- }
- luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
- luaK_patchtohere(fs, e->f);
- e->f = NO_JUMP;
-}
-
-
-static void codenot (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VNIL: case VFALSE: {
- e->k = VTRUE;
- break;
- }
- case VK: case VKNUM: case VTRUE: {
- e->k = VFALSE;
- break;
- }
- case VJMP: {
- invertjump(fs, e);
- break;
- }
- case VRELOCABLE:
- case VNONRELOC: {
- discharge2anyreg(fs, e);
- freeexp(fs, e);
- e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
- e->k = VRELOCABLE;
- break;
- }
- default: {
- lua_assert(0); /* cannot happen */
- break;
- }
- }
- /* interchange true and false lists */
- { int temp = e->f; e->f = e->t; e->t = temp; }
- removevalues(fs, e->f);
- removevalues(fs, e->t);
-}
-
-
-void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
- t->u.s.aux = luaK_exp2RK(fs, k);
- t->k = VINDEXED;
-}
-
-
-static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
- lua_Number v1, v2, r;
- if (!isnumeral(e1) || !isnumeral(e2)) return 0;
- v1 = e1->u.nval;
- v2 = e2->u.nval;
- switch (op) {
- case OP_ADD: r = luai_numadd(v1, v2); break;
- case OP_SUB: r = luai_numsub(v1, v2); break;
- case OP_MUL: r = luai_nummul(v1, v2); break;
- case OP_DIV:
- if (v2 == 0) return 0; /* do not attempt to divide by 0 */
- r = luai_numdiv(v1, v2); break;
- case OP_MOD:
- if (v2 == 0) return 0; /* do not attempt to divide by 0 */
- r = luai_nummod(v1, v2); break;
- case OP_POW: r = luai_numpow(v1, v2); break;
- case OP_UNM: r = luai_numunm(v1); break;
- case OP_LEN: return 0; /* no constant folding for 'len' */
- default: lua_assert(0); r = 0; break;
- }
- if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
- e1->u.nval = r;
- return 1;
-}
-
-
-static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
- if (constfolding(op, e1, e2))
- return;
- else {
- int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
- int o1 = luaK_exp2RK(fs, e1);
- if (o1 > o2) {
- freeexp(fs, e1);
- freeexp(fs, e2);
- }
- else {
- freeexp(fs, e2);
- freeexp(fs, e1);
- }
- e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
- e1->k = VRELOCABLE;
- }
-}
-
-
-static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
- expdesc *e2) {
- int o1 = luaK_exp2RK(fs, e1);
- int o2 = luaK_exp2RK(fs, e2);
- freeexp(fs, e2);
- freeexp(fs, e1);
- if (cond == 0 && op != OP_EQ) {
- int temp; /* exchange args to replace by `<' or `<=' */
- temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
- cond = 1;
- }
- e1->u.s.info = condjump(fs, op, cond, o1, o2);
- e1->k = VJMP;
-}
-
-
-void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
- expdesc e2;
- e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
- switch (op) {
- case OPR_MINUS: {
- if (!isnumeral(e))
- luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
- codearith(fs, OP_UNM, e, &e2);
- break;
- }
- case OPR_NOT: codenot(fs, e); break;
- case OPR_LEN: {
- luaK_exp2anyreg(fs, e); /* cannot operate on constants */
- codearith(fs, OP_LEN, e, &e2);
- break;
- }
- default: lua_assert(0);
- }
-}
-
-
-void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
- switch (op) {
- case OPR_AND: {
- luaK_goiftrue(fs, v);
- break;
- }
- case OPR_OR: {
- luaK_goiffalse(fs, v);
- break;
- }
- case OPR_CONCAT: {
- luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
- break;
- }
- case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
- case OPR_MOD: case OPR_POW: {
- if (!isnumeral(v)) luaK_exp2RK(fs, v);
- break;
- }
- default: {
- luaK_exp2RK(fs, v);
- break;
- }
- }
-}
-
-
-void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
- switch (op) {
- case OPR_AND: {
- lua_assert(e1->t == NO_JUMP); /* list must be closed */
- luaK_dischargevars(fs, e2);
- luaK_concat(fs, &e2->f, e1->f);
- *e1 = *e2;
- break;
- }
- case OPR_OR: {
- lua_assert(e1->f == NO_JUMP); /* list must be closed */
- luaK_dischargevars(fs, e2);
- luaK_concat(fs, &e2->t, e1->t);
- *e1 = *e2;
- break;
- }
- case OPR_CONCAT: {
- luaK_exp2val(fs, e2);
- if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
- lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
- freeexp(fs, e1);
- SETARG_B(getcode(fs, e2), e1->u.s.info);
- e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
- }
- else {
- luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
- codearith(fs, OP_CONCAT, e1, e2);
- }
- break;
- }
- case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
- case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
- case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
- case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
- case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
- case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
- case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
- case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
- case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
- case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
- case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
- case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
- default: lua_assert(0);
- }
-}
-
-
-void luaK_fixline (FuncState *fs, int line) {
- fs->f->lineinfo[fs->pc - 1] = line;
-}
-
-
-static int luaK_code (FuncState *fs, Instruction i, int line) {
- Proto *f = fs->f;
- dischargejpc(fs); /* `pc' will change */
- /* put new instruction in code array */
- luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
- MAX_INT, "code size overflow");
- f->code[fs->pc] = i;
- /* save corresponding line information */
- luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
- MAX_INT, "code size overflow");
- f->lineinfo[fs->pc] = line;
- return fs->pc++;
-}
-
-
-int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
- lua_assert(getOpMode(o) == iABC);
- lua_assert(getBMode(o) != OpArgN || b == 0);
- lua_assert(getCMode(o) != OpArgN || c == 0);
- return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
-}
-
-
-int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
- lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
- lua_assert(getCMode(o) == OpArgN);
- return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
-}
-
-
-void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
- int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
- int b = (tostore == LUA_MULTRET) ? 0 : tostore;
- lua_assert(tostore != 0);
- if (c <= MAXARG_C)
- luaK_codeABC(fs, OP_SETLIST, base, b, c);
- else {
- luaK_codeABC(fs, OP_SETLIST, base, b, 0);
- luaK_code(fs, cast(Instruction, c), fs->ls->lastline);
- }
- fs->freereg = base + 1; /* free registers with list values */
-}
-
diff --git a/lib/lua/lcode.h b/lib/lua/lcode.h
deleted file mode 100644
index b941c60..0000000
--- a/lib/lua/lcode.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
-** Code generator for Lua
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lcode_h
-#define lcode_h
-
-#include "llex.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lparser.h"
-
-
-/*
-** Marks the end of a patch list. It is an invalid value both as an absolute
-** address, and as a list link (would link an element to itself).
-*/
-#define NO_JUMP (-1)
-
-
-/*
-** grep "ORDER OPR" if you change these enums
-*/
-typedef enum BinOpr {
- OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
- OPR_CONCAT,
- OPR_NE, OPR_EQ,
- OPR_LT, OPR_LE, OPR_GT, OPR_GE,
- OPR_AND, OPR_OR,
- OPR_NOBINOPR
-} BinOpr;
-
-
-typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
-
-
-#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
-
-#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
-
-#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
-
-LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
-LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
-LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
-LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
-LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
-LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
-LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
-LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);
-LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
-LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
-LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
-LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
-LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
-LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
-LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
-LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
-LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
-LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
-LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
-LUAI_FUNC int luaK_jump (FuncState *fs);
-LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
-LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
-LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
-LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
-LUAI_FUNC int luaK_getlabel (FuncState *fs);
-LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
-LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
-LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
-LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
-
-
-#endif
diff --git a/lib/lua/ldblib.c b/lib/lua/ldblib.c
deleted file mode 100644
index 67de122..0000000
--- a/lib/lua/ldblib.c
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
-** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $
-** Interface from Lua to its debug API
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-
-#define ldblib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-
-static int db_getregistry (lua_State *L) {
- lua_pushvalue(L, LUA_REGISTRYINDEX);
- return 1;
-}
-
-
-static int db_getmetatable (lua_State *L) {
- luaL_checkany(L, 1);
- if (!lua_getmetatable(L, 1)) {
- lua_pushnil(L); /* no metatable */
- }
- return 1;
-}
-
-
-static int db_setmetatable (lua_State *L) {
- int t = lua_type(L, 2);
- luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
- "nil or table expected");
- lua_settop(L, 2);
- lua_pushboolean(L, lua_setmetatable(L, 1));
- return 1;
-}
-
-
-static int db_getfenv (lua_State *L) {
- lua_getfenv(L, 1);
- return 1;
-}
-
-
-static int db_setfenv (lua_State *L) {
- luaL_checktype(L, 2, LUA_TTABLE);
- lua_settop(L, 2);
- if (lua_setfenv(L, 1) == 0)
- luaL_error(L, LUA_QL("setfenv")
- " cannot change environment of given object");
- return 1;
-}
-
-
-static void settabss (lua_State *L, const char *i, const char *v) {
- lua_pushstring(L, v);
- lua_setfield(L, -2, i);
-}
-
-
-static void settabsi (lua_State *L, const char *i, int v) {
- lua_pushinteger(L, v);
- lua_setfield(L, -2, i);
-}
-
-
-static lua_State *getthread (lua_State *L, int *arg) {
- if (lua_isthread(L, 1)) {
- *arg = 1;
- return lua_tothread(L, 1);
- }
- else {
- *arg = 0;
- return L;
- }
-}
-
-
-static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
- if (L == L1) {
- lua_pushvalue(L, -2);
- lua_remove(L, -3);
- }
- else
- lua_xmove(L1, L, 1);
- lua_setfield(L, -2, fname);
-}
-
-
-static int db_getinfo (lua_State *L) {
- lua_Debug ar;
- int arg;
- lua_State *L1 = getthread(L, &arg);
- const char *options = luaL_optstring(L, arg+2, "flnSu");
- if (lua_isnumber(L, arg+1)) {
- if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
- lua_pushnil(L); /* level out of range */
- return 1;
- }
- }
- else if (lua_isfunction(L, arg+1)) {
- lua_pushfstring(L, ">%s", options);
- options = lua_tostring(L, -1);
- lua_pushvalue(L, arg+1);
- lua_xmove(L, L1, 1);
- }
- else
- return luaL_argerror(L, arg+1, "function or level expected");
- if (!lua_getinfo(L1, options, &ar))
- return luaL_argerror(L, arg+2, "invalid option");
- lua_createtable(L, 0, 2);
- if (strchr(options, 'S')) {
- settabss(L, "source", ar.source);
- settabss(L, "short_src", ar.short_src);
- settabsi(L, "linedefined", ar.linedefined);
- settabsi(L, "lastlinedefined", ar.lastlinedefined);
- settabss(L, "what", ar.what);
- }
- if (strchr(options, 'l'))
- settabsi(L, "currentline", ar.currentline);
- if (strchr(options, 'u'))
- settabsi(L, "nups", ar.nups);
- if (strchr(options, 'n')) {
- settabss(L, "name", ar.name);
- settabss(L, "namewhat", ar.namewhat);
- }
- if (strchr(options, 'L'))
- treatstackoption(L, L1, "activelines");
- if (strchr(options, 'f'))
- treatstackoption(L, L1, "func");
- return 1; /* return table */
-}
-
-
-static int db_getlocal (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- lua_Debug ar;
- const char *name;
- if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
- return luaL_argerror(L, arg+1, "level out of range");
- name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2));
- if (name) {
- lua_xmove(L1, L, 1);
- lua_pushstring(L, name);
- lua_pushvalue(L, -2);
- return 2;
- }
- else {
- lua_pushnil(L);
- return 1;
- }
-}
-
-
-static int db_setlocal (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- lua_Debug ar;
- if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
- return luaL_argerror(L, arg+1, "level out of range");
- luaL_checkany(L, arg+3);
- lua_settop(L, arg+3);
- lua_xmove(L, L1, 1);
- lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
- return 1;
-}
-
-
-static int auxupvalue (lua_State *L, int get) {
- const char *name;
- int n = luaL_checkint(L, 2);
- luaL_checktype(L, 1, LUA_TFUNCTION);
- if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */
- name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
- if (name == NULL) return 0;
- lua_pushstring(L, name);
- lua_insert(L, -(get+1));
- return get + 1;
-}
-
-
-static int db_getupvalue (lua_State *L) {
- return auxupvalue(L, 1);
-}
-
-
-static int db_setupvalue (lua_State *L) {
- luaL_checkany(L, 3);
- return auxupvalue(L, 0);
-}
-
-
-
-static const char KEY_HOOK = 'h';
-
-
-static void hookf (lua_State *L, lua_Debug *ar) {
- static const char *const hooknames[] =
- {"call", "return", "line", "count", "tail return"};
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
- lua_pushlightuserdata(L, L);
- lua_rawget(L, -2);
- if (lua_isfunction(L, -1)) {
- lua_pushstring(L, hooknames[(int)ar->event]);
- if (ar->currentline >= 0)
- lua_pushinteger(L, ar->currentline);
- else lua_pushnil(L);
- lua_assert(lua_getinfo(L, "lS", ar));
- lua_call(L, 2, 0);
- }
-}
-
-
-static int makemask (const char *smask, int count) {
- int mask = 0;
- if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
- if (strchr(smask, 'r')) mask |= LUA_MASKRET;
- if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
- if (count > 0) mask |= LUA_MASKCOUNT;
- return mask;
-}
-
-
-static char *unmakemask (int mask, char *smask) {
- int i = 0;
- if (mask & LUA_MASKCALL) smask[i++] = 'c';
- if (mask & LUA_MASKRET) smask[i++] = 'r';
- if (mask & LUA_MASKLINE) smask[i++] = 'l';
- smask[i] = '\0';
- return smask;
-}
-
-
-static void gethooktable (lua_State *L) {
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- lua_createtable(L, 0, 1);
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_pushvalue(L, -2);
- lua_rawset(L, LUA_REGISTRYINDEX);
- }
-}
-
-
-static int db_sethook (lua_State *L) {
- int arg, mask, count;
- lua_Hook func;
- lua_State *L1 = getthread(L, &arg);
- if (lua_isnoneornil(L, arg+1)) {
- lua_settop(L, arg+1);
- func = NULL; mask = 0; count = 0; /* turn off hooks */
- }
- else {
- const char *smask = luaL_checkstring(L, arg+2);
- luaL_checktype(L, arg+1, LUA_TFUNCTION);
- count = luaL_optint(L, arg+3, 0);
- func = hookf; mask = makemask(smask, count);
- }
- gethooktable(L);
- lua_pushlightuserdata(L, L1);
- lua_pushvalue(L, arg+1);
- lua_rawset(L, -3); /* set new hook */
- lua_pop(L, 1); /* remove hook table */
- lua_sethook(L1, func, mask, count); /* set hooks */
- return 0;
-}
-
-
-static int db_gethook (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- char buff[5];
- int mask = lua_gethookmask(L1);
- lua_Hook hook = lua_gethook(L1);
- if (hook != NULL && hook != hookf) /* external hook? */
- lua_pushliteral(L, "external hook");
- else {
- gethooktable(L);
- lua_pushlightuserdata(L, L1);
- lua_rawget(L, -2); /* get hook */
- lua_remove(L, -2); /* remove hook table */
- }
- lua_pushstring(L, unmakemask(mask, buff));
- lua_pushinteger(L, lua_gethookcount(L1));
- return 3;
-}
-
-
-static int db_debug (lua_State *L) {
- for (;;) {
- char buffer[250];
- fputs("lua_debug> ", stderr);
- if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
- strcmp(buffer, "cont\n") == 0)
- return 0;
- if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
- lua_pcall(L, 0, 0, 0)) {
- fputs(lua_tostring(L, -1), stderr);
- fputs("\n", stderr);
- }
- lua_settop(L, 0); /* remove eventual returns */
- }
-}
-
-
-#define LEVELS1 12 /* size of the first part of the stack */
-#define LEVELS2 10 /* size of the second part of the stack */
-
-static int db_errorfb (lua_State *L) {
- int level;
- int firstpart = 1; /* still before eventual `...' */
- int arg;
- lua_State *L1 = getthread(L, &arg);
- lua_Debug ar;
- if (lua_isnumber(L, arg+2)) {
- level = (int)lua_tointeger(L, arg+2);
- lua_pop(L, 1);
- }
- else
- level = (L == L1) ? 1 : 0; /* level 0 may be this own function */
- if (lua_gettop(L) == arg)
- lua_pushliteral(L, "");
- else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */
- else lua_pushliteral(L, "\n");
- lua_pushliteral(L, "stack traceback:");
- while (lua_getstack(L1, level++, &ar)) {
- if (level > LEVELS1 && firstpart) {
- /* no more than `LEVELS2' more levels? */
- if (!lua_getstack(L1, level+LEVELS2, &ar))
- level--; /* keep going */
- else {
- lua_pushliteral(L, "\n\t..."); /* too many levels */
- while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */
- level++;
- }
- firstpart = 0;
- continue;
- }
- lua_pushliteral(L, "\n\t");
- lua_getinfo(L1, "Snl", &ar);
- lua_pushfstring(L, "%s:", ar.short_src);
- if (ar.currentline > 0)
- lua_pushfstring(L, "%d:", ar.currentline);
- if (*ar.namewhat != '\0') /* is there a name? */
- lua_pushfstring(L, " in function " LUA_QS, ar.name);
- else {
- if (*ar.what == 'm') /* main? */
- lua_pushfstring(L, " in main chunk");
- else if (*ar.what == 'C' || *ar.what == 't')
- lua_pushliteral(L, " ?"); /* C function or tail call */
- else
- lua_pushfstring(L, " in function <%s:%d>",
- ar.short_src, ar.linedefined);
- }
- lua_concat(L, lua_gettop(L) - arg);
- }
- lua_concat(L, lua_gettop(L) - arg);
- return 1;
-}
-
-
-static const luaL_Reg dblib[] = {
- {"debug", db_debug},
- {"getfenv", db_getfenv},
- {"gethook", db_gethook},
- {"getinfo", db_getinfo},
- {"getlocal", db_getlocal},
- {"getregistry", db_getregistry},
- {"getmetatable", db_getmetatable},
- {"getupvalue", db_getupvalue},
- {"setfenv", db_setfenv},
- {"sethook", db_sethook},
- {"setlocal", db_setlocal},
- {"setmetatable", db_setmetatable},
- {"setupvalue", db_setupvalue},
- {"traceback", db_errorfb},
- {NULL, NULL}
-};
-
-
-LUALIB_API int luaopen_debug (lua_State *L) {
- luaL_register(L, LUA_DBLIBNAME, dblib);
- return 1;
-}
-
diff --git a/lib/lua/ldebug.c b/lib/lua/ldebug.c
deleted file mode 100644
index 50ad3d3..0000000
--- a/lib/lua/ldebug.c
+++ /dev/null
@@ -1,638 +0,0 @@
-/*
-** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $
-** Debug Interface
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-
-
-#define ldebug_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lapi.h"
-#include "lcode.h"
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-#include "lvm.h"
-
-
-
-static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
-
-
-static int currentpc (lua_State *L, CallInfo *ci) {
- if (!isLua(ci)) return -1; /* function is not a Lua function? */
- if (ci == L->ci)
- ci->savedpc = L->savedpc;
- return pcRel(ci->savedpc, ci_func(ci)->l.p);
-}
-
-
-static int currentline (lua_State *L, CallInfo *ci) {
- int pc = currentpc(L, ci);
- if (pc < 0)
- return -1; /* only active lua functions have current-line information */
- else
- return getline(ci_func(ci)->l.p, pc);
-}
-
-
-/*
-** this function can be called asynchronous (e.g. during a signal)
-*/
-LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
- if (func == NULL || mask == 0) { /* turn off hooks? */
- mask = 0;
- func = NULL;
- }
- L->hook = func;
- L->basehookcount = count;
- resethookcount(L);
- L->hookmask = cast_byte(mask);
- return 1;
-}
-
-
-LUA_API lua_Hook lua_gethook (lua_State *L) {
- return L->hook;
-}
-
-
-LUA_API int lua_gethookmask (lua_State *L) {
- return L->hookmask;
-}
-
-
-LUA_API int lua_gethookcount (lua_State *L) {
- return L->basehookcount;
-}
-
-
-LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
- int status;
- CallInfo *ci;
- lua_lock(L);
- for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
- level--;
- if (f_isLua(ci)) /* Lua function? */
- level -= ci->tailcalls; /* skip lost tail calls */
- }
- if (level == 0 && ci > L->base_ci) { /* level found? */
- status = 1;
- ar->i_ci = cast_int(ci - L->base_ci);
- }
- else if (level < 0) { /* level is of a lost tail call? */
- status = 1;
- ar->i_ci = 0;
- }
- else status = 0; /* no such level */
- lua_unlock(L);
- return status;
-}
-
-
-static Proto *getluaproto (CallInfo *ci) {
- return (isLua(ci) ? ci_func(ci)->l.p : NULL);
-}
-
-
-static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
- const char *name;
- Proto *fp = getluaproto(ci);
- if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
- return name; /* is a local variable in a Lua function */
- else {
- StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
- if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */
- return "(*temporary)";
- else
- return NULL;
- }
-}
-
-
-LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
- CallInfo *ci = L->base_ci + ar->i_ci;
- const char *name = findlocal(L, ci, n);
- lua_lock(L);
- if (name)
- luaA_pushobject(L, ci->base + (n - 1));
- lua_unlock(L);
- return name;
-}
-
-
-LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
- CallInfo *ci = L->base_ci + ar->i_ci;
- const char *name = findlocal(L, ci, n);
- lua_lock(L);
- if (name)
- setobjs2s(L, ci->base + (n - 1), L->top - 1);
- L->top--; /* pop value */
- lua_unlock(L);
- return name;
-}
-
-
-static void funcinfo (lua_Debug *ar, Closure *cl) {
- if (cl->c.isC) {
- ar->source = "=[C]";
- ar->linedefined = -1;
- ar->lastlinedefined = -1;
- ar->what = "C";
- }
- else {
- ar->source = getstr(cl->l.p->source);
- ar->linedefined = cl->l.p->linedefined;
- ar->lastlinedefined = cl->l.p->lastlinedefined;
- ar->what = (ar->linedefined == 0) ? "main" : "Lua";
- }
- luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
-}
-
-
-static void info_tailcall (lua_Debug *ar) {
- ar->name = ar->namewhat = "";
- ar->what = "tail";
- ar->lastlinedefined = ar->linedefined = ar->currentline = -1;
- ar->source = "=(tail call)";
- luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
- ar->nups = 0;
-}
-
-
-static void collectvalidlines (lua_State *L, Closure *f) {
- if (f == NULL || f->c.isC) {
- setnilvalue(L->top);
- }
- else {
- Table *t = luaH_new(L, 0, 0);
- int *lineinfo = f->l.p->lineinfo;
- int i;
- for (i=0; il.p->sizelineinfo; i++)
- setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);
- sethvalue(L, L->top, t);
- }
- incr_top(L);
-}
-
-
-static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
- Closure *f, CallInfo *ci) {
- int status = 1;
- if (f == NULL) {
- info_tailcall(ar);
- return status;
- }
- for (; *what; what++) {
- switch (*what) {
- case 'S': {
- funcinfo(ar, f);
- break;
- }
- case 'l': {
- ar->currentline = (ci) ? currentline(L, ci) : -1;
- break;
- }
- case 'u': {
- ar->nups = f->c.nupvalues;
- break;
- }
- case 'n': {
- ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
- if (ar->namewhat == NULL) {
- ar->namewhat = ""; /* not found */
- ar->name = NULL;
- }
- break;
- }
- case 'L':
- case 'f': /* handled by lua_getinfo */
- break;
- default: status = 0; /* invalid option */
- }
- }
- return status;
-}
-
-
-LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
- int status;
- Closure *f = NULL;
- CallInfo *ci = NULL;
- lua_lock(L);
- if (*what == '>') {
- StkId func = L->top - 1;
- luai_apicheck(L, ttisfunction(func));
- what++; /* skip the '>' */
- f = clvalue(func);
- L->top--; /* pop function */
- }
- else if (ar->i_ci != 0) { /* no tail call? */
- ci = L->base_ci + ar->i_ci;
- lua_assert(ttisfunction(ci->func));
- f = clvalue(ci->func);
- }
- status = auxgetinfo(L, what, ar, f, ci);
- if (strchr(what, 'f')) {
- if (f == NULL) setnilvalue(L->top);
- else setclvalue(L, L->top, f);
- incr_top(L);
- }
- if (strchr(what, 'L'))
- collectvalidlines(L, f);
- lua_unlock(L);
- return status;
-}
-
-
-/*
-** {======================================================
-** Symbolic Execution and code checker
-** =======================================================
-*/
-
-#define check(x) if (!(x)) return 0;
-
-#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode)
-
-#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize)
-
-
-
-static int precheck (const Proto *pt) {
- check(pt->maxstacksize <= MAXSTACK);
- check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
- check(!(pt->is_vararg & VARARG_NEEDSARG) ||
- (pt->is_vararg & VARARG_HASARG));
- check(pt->sizeupvalues <= pt->nups);
- check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
- check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
- return 1;
-}
-
-
-#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1])
-
-int luaG_checkopenop (Instruction i) {
- switch (GET_OPCODE(i)) {
- case OP_CALL:
- case OP_TAILCALL:
- case OP_RETURN:
- case OP_SETLIST: {
- check(GETARG_B(i) == 0);
- return 1;
- }
- default: return 0; /* invalid instruction after an open call */
- }
-}
-
-
-static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) {
- switch (mode) {
- case OpArgN: check(r == 0); break;
- case OpArgU: break;
- case OpArgR: checkreg(pt, r); break;
- case OpArgK:
- check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize);
- break;
- }
- return 1;
-}
-
-
-static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
- int pc;
- int last; /* stores position of last instruction that changed `reg' */
- last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */
- check(precheck(pt));
- for (pc = 0; pc < lastpc; pc++) {
- Instruction i = pt->code[pc];
- OpCode op = GET_OPCODE(i);
- int a = GETARG_A(i);
- int b = 0;
- int c = 0;
- check(op < NUM_OPCODES);
- checkreg(pt, a);
- switch (getOpMode(op)) {
- case iABC: {
- b = GETARG_B(i);
- c = GETARG_C(i);
- check(checkArgMode(pt, b, getBMode(op)));
- check(checkArgMode(pt, c, getCMode(op)));
- break;
- }
- case iABx: {
- b = GETARG_Bx(i);
- if (getBMode(op) == OpArgK) check(b < pt->sizek);
- break;
- }
- case iAsBx: {
- b = GETARG_sBx(i);
- if (getBMode(op) == OpArgR) {
- int dest = pc+1+b;
- check(0 <= dest && dest < pt->sizecode);
- if (dest > 0) {
- int j;
- /* check that it does not jump to a setlist count; this
- is tricky, because the count from a previous setlist may
- have the same value of an invalid setlist; so, we must
- go all the way back to the first of them (if any) */
- for (j = 0; j < dest; j++) {
- Instruction d = pt->code[dest-1-j];
- if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
- }
- /* if 'j' is even, previous value is not a setlist (even if
- it looks like one) */
- check((j&1) == 0);
- }
- }
- break;
- }
- }
- if (testAMode(op)) {
- if (a == reg) last = pc; /* change register `a' */
- }
- if (testTMode(op)) {
- check(pc+2 < pt->sizecode); /* check skip */
- check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);
- }
- switch (op) {
- case OP_LOADBOOL: {
- if (c == 1) { /* does it jump? */
- check(pc+2 < pt->sizecode); /* check its jump */
- check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||
- GETARG_C(pt->code[pc+1]) != 0);
- }
- break;
- }
- case OP_LOADNIL: {
- if (a <= reg && reg <= b)
- last = pc; /* set registers from `a' to `b' */
- break;
- }
- case OP_GETUPVAL:
- case OP_SETUPVAL: {
- check(b < pt->nups);
- break;
- }
- case OP_GETGLOBAL:
- case OP_SETGLOBAL: {
- check(ttisstring(&pt->k[b]));
- break;
- }
- case OP_SELF: {
- checkreg(pt, a+1);
- if (reg == a+1) last = pc;
- break;
- }
- case OP_CONCAT: {
- check(b < c); /* at least two operands */
- break;
- }
- case OP_TFORLOOP: {
- check(c >= 1); /* at least one result (control variable) */
- checkreg(pt, a+2+c); /* space for results */
- if (reg >= a+2) last = pc; /* affect all regs above its base */
- break;
- }
- case OP_FORLOOP:
- case OP_FORPREP:
- checkreg(pt, a+3);
- /* go through */
- case OP_JMP: {
- int dest = pc+1+b;
- /* not full check and jump is forward and do not skip `lastpc'? */
- if (reg != NO_REG && pc < dest && dest <= lastpc)
- pc += b; /* do the jump */
- break;
- }
- case OP_CALL:
- case OP_TAILCALL: {
- if (b != 0) {
- checkreg(pt, a+b-1);
- }
- c--; /* c = num. returns */
- if (c == LUA_MULTRET) {
- check(checkopenop(pt, pc));
- }
- else if (c != 0)
- checkreg(pt, a+c-1);
- if (reg >= a) last = pc; /* affect all registers above base */
- break;
- }
- case OP_RETURN: {
- b--; /* b = num. returns */
- if (b > 0) checkreg(pt, a+b-1);
- break;
- }
- case OP_SETLIST: {
- if (b > 0) checkreg(pt, a + b);
- if (c == 0) {
- pc++;
- check(pc < pt->sizecode - 1);
- }
- break;
- }
- case OP_CLOSURE: {
- int nup, j;
- check(b < pt->sizep);
- nup = pt->p[b]->nups;
- check(pc + nup < pt->sizecode);
- for (j = 1; j <= nup; j++) {
- OpCode op1 = GET_OPCODE(pt->code[pc + j]);
- check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
- }
- if (reg != NO_REG) /* tracing? */
- pc += nup; /* do not 'execute' these pseudo-instructions */
- break;
- }
- case OP_VARARG: {
- check((pt->is_vararg & VARARG_ISVARARG) &&
- !(pt->is_vararg & VARARG_NEEDSARG));
- b--;
- if (b == LUA_MULTRET) check(checkopenop(pt, pc));
- checkreg(pt, a+b-1);
- break;
- }
- default: break;
- }
- }
- return pt->code[last];
-}
-
-#undef check
-#undef checkjump
-#undef checkreg
-
-/* }====================================================== */
-
-
-int luaG_checkcode (const Proto *pt) {
- return (symbexec(pt, pt->sizecode, NO_REG) != 0);
-}
-
-
-static const char *kname (Proto *p, int c) {
- if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))
- return svalue(&p->k[INDEXK(c)]);
- else
- return "?";
-}
-
-
-static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
- const char **name) {
- if (isLua(ci)) { /* a Lua function? */
- Proto *p = ci_func(ci)->l.p;
- int pc = currentpc(L, ci);
- Instruction i;
- *name = luaF_getlocalname(p, stackpos+1, pc);
- if (*name) /* is a local? */
- return "local";
- i = symbexec(p, pc, stackpos); /* try symbolic execution */
- lua_assert(pc != -1);
- switch (GET_OPCODE(i)) {
- case OP_GETGLOBAL: {
- int g = GETARG_Bx(i); /* global index */
- lua_assert(ttisstring(&p->k[g]));
- *name = svalue(&p->k[g]);
- return "global";
- }
- case OP_MOVE: {
- int a = GETARG_A(i);
- int b = GETARG_B(i); /* move from `b' to `a' */
- if (b < a)
- return getobjname(L, ci, b, name); /* get name for `b' */
- break;
- }
- case OP_GETTABLE: {
- int k = GETARG_C(i); /* key index */
- *name = kname(p, k);
- return "field";
- }
- case OP_GETUPVAL: {
- int u = GETARG_B(i); /* upvalue index */
- *name = p->upvalues ? getstr(p->upvalues[u]) : "?";
- return "upvalue";
- }
- case OP_SELF: {
- int k = GETARG_C(i); /* key index */
- *name = kname(p, k);
- return "method";
- }
- default: break;
- }
- }
- return NULL; /* no useful name found */
-}
-
-
-static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
- Instruction i;
- if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
- return NULL; /* calling function is not Lua (or is unknown) */
- ci--; /* calling function */
- i = ci_func(ci)->l.p->code[currentpc(L, ci)];
- if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
- GET_OPCODE(i) == OP_TFORLOOP)
- return getobjname(L, ci, GETARG_A(i), name);
- else
- return NULL; /* no useful name can be found */
-}
-
-
-/* only ANSI way to check whether a pointer points to an array */
-static int isinstack (CallInfo *ci, const TValue *o) {
- StkId p;
- for (p = ci->base; p < ci->top; p++)
- if (o == p) return 1;
- return 0;
-}
-
-
-void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
- const char *name = NULL;
- const char *t = luaT_typenames[ttype(o)];
- const char *kind = (isinstack(L->ci, o)) ?
- getobjname(L, L->ci, cast_int(o - L->base), &name) :
- NULL;
- if (kind)
- luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
- op, kind, name, t);
- else
- luaG_runerror(L, "attempt to %s a %s value", op, t);
-}
-
-
-void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
- if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
- lua_assert(!ttisstring(p1) && !ttisnumber(p1));
- luaG_typeerror(L, p1, "concatenate");
-}
-
-
-void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
- TValue temp;
- if (luaV_tonumber(p1, &temp) == NULL)
- p2 = p1; /* first operand is wrong */
- luaG_typeerror(L, p2, "perform arithmetic on");
-}
-
-
-int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
- const char *t1 = luaT_typenames[ttype(p1)];
- const char *t2 = luaT_typenames[ttype(p2)];
- if (t1[2] == t2[2])
- luaG_runerror(L, "attempt to compare two %s values", t1);
- else
- luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
- return 0;
-}
-
-
-static void addinfo (lua_State *L, const char *msg) {
- CallInfo *ci = L->ci;
- if (isLua(ci)) { /* is Lua code? */
- char buff[LUA_IDSIZE]; /* add file:line information */
- int line = currentline(L, ci);
- luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
- luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
- }
-}
-
-
-void luaG_errormsg (lua_State *L) {
- if (L->errfunc != 0) { /* is there an error handling function? */
- StkId errfunc = restorestack(L, L->errfunc);
- if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
- setobjs2s(L, L->top, L->top - 1); /* move argument */
- setobjs2s(L, L->top - 1, errfunc); /* push function */
- incr_top(L);
- luaD_call(L, L->top - 2, 1); /* call it */
- }
- luaD_throw(L, LUA_ERRRUN);
-}
-
-
-void luaG_runerror (lua_State *L, const char *fmt, ...) {
- va_list argp;
- va_start(argp, fmt);
- addinfo(L, luaO_pushvfstring(L, fmt, argp));
- va_end(argp);
- luaG_errormsg(L);
-}
-
diff --git a/lib/lua/ldebug.h b/lib/lua/ldebug.h
deleted file mode 100644
index ba28a97..0000000
--- a/lib/lua/ldebug.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
-** Auxiliary functions from Debug Interface module
-** See Copyright Notice in lua.h
-*/
-
-#ifndef ldebug_h
-#define ldebug_h
-
-
-#include "lstate.h"
-
-
-#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
-
-#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
-
-#define resethookcount(L) (L->hookcount = L->basehookcount)
-
-
-LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
- const char *opname);
-LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
-LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
- const TValue *p2);
-LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
- const TValue *p2);
-LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
-LUAI_FUNC void luaG_errormsg (lua_State *L);
-LUAI_FUNC int luaG_checkcode (const Proto *pt);
-LUAI_FUNC int luaG_checkopenop (Instruction i);
-
-#endif
diff --git a/lib/lua/ldo.c b/lib/lua/ldo.c
deleted file mode 100644
index 8de05f7..0000000
--- a/lib/lua/ldo.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
-** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $
-** Stack and Call structure of Lua
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-
-#define ldo_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lparser.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-#include "lundump.h"
-#include "lvm.h"
-#include "lzio.h"
-
-
-
-
-/*
-** {======================================================
-** Error-recovery functions
-** =======================================================
-*/
-
-
-/* chain list of long jump buffers */
-struct lua_longjmp {
- struct lua_longjmp *previous;
- luai_jmpbuf b;
- volatile int status; /* error code */
-};
-
-
-void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
- switch (errcode) {
- case LUA_ERRMEM: {
- setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
- break;
- }
- case LUA_ERRERR: {
- setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
- break;
- }
- case LUA_ERRSYNTAX:
- case LUA_ERRRUN: {
- setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
- break;
- }
- }
- L->top = oldtop + 1;
-}
-
-
-static void restore_stack_limit (lua_State *L) {
- lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
- if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
- int inuse = cast_int(L->ci - L->base_ci);
- if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
- luaD_reallocCI(L, LUAI_MAXCALLS);
- }
-}
-
-
-static void resetstack (lua_State *L, int status) {
- L->ci = L->base_ci;
- L->base = L->ci->base;
- luaF_close(L, L->base); /* close eventual pending closures */
- luaD_seterrorobj(L, status, L->base);
- L->nCcalls = L->baseCcalls;
- L->allowhook = 1;
- restore_stack_limit(L);
- L->errfunc = 0;
- L->errorJmp = NULL;
-}
-
-
-void luaD_throw (lua_State *L, int errcode) {
- if (L->errorJmp) {
- L->errorJmp->status = errcode;
- LUAI_THROW(L, L->errorJmp);
- }
- else {
- L->status = cast_byte(errcode);
- if (G(L)->panic) {
- resetstack(L, errcode);
- lua_unlock(L);
- G(L)->panic(L);
- }
- exit(EXIT_FAILURE);
- }
-}
-
-
-int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
- struct lua_longjmp lj;
- lj.status = 0;
- lj.previous = L->errorJmp; /* chain new error handler */
- L->errorJmp = &lj;
- LUAI_TRY(L, &lj,
- (*f)(L, ud);
- );
- L->errorJmp = lj.previous; /* restore old error handler */
- return lj.status;
-}
-
-/* }====================================================== */
-
-
-static void correctstack (lua_State *L, TValue *oldstack) {
- CallInfo *ci;
- GCObject *up;
- L->top = (L->top - oldstack) + L->stack;
- for (up = L->openupval; up != NULL; up = up->gch.next)
- gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;
- for (ci = L->base_ci; ci <= L->ci; ci++) {
- ci->top = (ci->top - oldstack) + L->stack;
- ci->base = (ci->base - oldstack) + L->stack;
- ci->func = (ci->func - oldstack) + L->stack;
- }
- L->base = (L->base - oldstack) + L->stack;
-}
-
-
-void luaD_reallocstack (lua_State *L, int newsize) {
- TValue *oldstack = L->stack;
- int realsize = newsize + 1 + EXTRA_STACK;
- lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
- luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);
- L->stacksize = realsize;
- L->stack_last = L->stack+newsize;
- correctstack(L, oldstack);
-}
-
-
-void luaD_reallocCI (lua_State *L, int newsize) {
- CallInfo *oldci = L->base_ci;
- luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);
- L->size_ci = newsize;
- L->ci = (L->ci - oldci) + L->base_ci;
- L->end_ci = L->base_ci + L->size_ci - 1;
-}
-
-
-void luaD_growstack (lua_State *L, int n) {
- if (n <= L->stacksize) /* double size is enough? */
- luaD_reallocstack(L, 2*L->stacksize);
- else
- luaD_reallocstack(L, L->stacksize + n);
-}
-
-
-static CallInfo *growCI (lua_State *L) {
- if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */
- luaD_throw(L, LUA_ERRERR);
- else {
- luaD_reallocCI(L, 2*L->size_ci);
- if (L->size_ci > LUAI_MAXCALLS)
- luaG_runerror(L, "stack overflow");
- }
- return ++L->ci;
-}
-
-
-void luaD_callhook (lua_State *L, int event, int line) {
- lua_Hook hook = L->hook;
- if (hook && L->allowhook) {
- ptrdiff_t top = savestack(L, L->top);
- ptrdiff_t ci_top = savestack(L, L->ci->top);
- lua_Debug ar;
- ar.event = event;
- ar.currentline = line;
- if (event == LUA_HOOKTAILRET)
- ar.i_ci = 0; /* tail call; no debug information about it */
- else
- ar.i_ci = cast_int(L->ci - L->base_ci);
- luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
- L->ci->top = L->top + LUA_MINSTACK;
- lua_assert(L->ci->top <= L->stack_last);
- L->allowhook = 0; /* cannot call hooks inside a hook */
- lua_unlock(L);
- (*hook)(L, &ar);
- lua_lock(L);
- lua_assert(!L->allowhook);
- L->allowhook = 1;
- L->ci->top = restorestack(L, ci_top);
- L->top = restorestack(L, top);
- }
-}
-
-
-static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
- int i;
- int nfixargs = p->numparams;
- Table *htab = NULL;
- StkId base, fixed;
- for (; actual < nfixargs; ++actual)
- setnilvalue(L->top++);
-#if defined(LUA_COMPAT_VARARG)
- if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */
- int nvar = actual - nfixargs; /* number of extra arguments */
- lua_assert(p->is_vararg & VARARG_HASARG);
- luaC_checkGC(L);
- htab = luaH_new(L, nvar, 1); /* create `arg' table */
- for (i=0; itop - nvar + i);
- /* store counter in field `n' */
- setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
- }
-#endif
- /* move fixed parameters to final position */
- fixed = L->top - actual; /* first fixed argument */
- base = L->top; /* final position of first argument */
- for (i=0; itop++, fixed+i);
- setnilvalue(fixed+i);
- }
- /* add `arg' parameter */
- if (htab) {
- sethvalue(L, L->top++, htab);
- lua_assert(iswhite(obj2gco(htab)));
- }
- return base;
-}
-
-
-static StkId tryfuncTM (lua_State *L, StkId func) {
- const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
- StkId p;
- ptrdiff_t funcr = savestack(L, func);
- if (!ttisfunction(tm))
- luaG_typeerror(L, func, "call");
- /* Open a hole inside the stack at `func' */
- for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
- incr_top(L);
- func = restorestack(L, funcr); /* previous call may change stack */
- setobj2s(L, func, tm); /* tag method is the new function to be called */
- return func;
-}
-
-
-
-#define inc_ci(L) \
- ((L->ci == L->end_ci) ? growCI(L) : \
- (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))
-
-
-int luaD_precall (lua_State *L, StkId func, int nresults) {
- LClosure *cl;
- ptrdiff_t funcr;
- if (!ttisfunction(func)) /* `func' is not a function? */
- func = tryfuncTM(L, func); /* check the `function' tag method */
- funcr = savestack(L, func);
- cl = &clvalue(func)->l;
- L->ci->savedpc = L->savedpc;
- if (!cl->isC) { /* Lua function? prepare its call */
- CallInfo *ci;
- StkId st, base;
- Proto *p = cl->p;
- luaD_checkstack(L, p->maxstacksize);
- func = restorestack(L, funcr);
- if (!p->is_vararg) { /* no varargs? */
- base = func + 1;
- if (L->top > base + p->numparams)
- L->top = base + p->numparams;
- }
- else { /* vararg function */
- int nargs = cast_int(L->top - func) - 1;
- base = adjust_varargs(L, p, nargs);
- func = restorestack(L, funcr); /* previous call may change the stack */
- }
- ci = inc_ci(L); /* now `enter' new function */
- ci->func = func;
- L->base = ci->base = base;
- ci->top = L->base + p->maxstacksize;
- lua_assert(ci->top <= L->stack_last);
- L->savedpc = p->code; /* starting point */
- ci->tailcalls = 0;
- ci->nresults = nresults;
- for (st = L->top; st < ci->top; st++)
- setnilvalue(st);
- L->top = ci->top;
- if (L->hookmask & LUA_MASKCALL) {
- L->savedpc++; /* hooks assume 'pc' is already incremented */
- luaD_callhook(L, LUA_HOOKCALL, -1);
- L->savedpc--; /* correct 'pc' */
- }
- return PCRLUA;
- }
- else { /* if is a C function, call it */
- CallInfo *ci;
- int n;
- luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
- ci = inc_ci(L); /* now `enter' new function */
- ci->func = restorestack(L, funcr);
- L->base = ci->base = ci->func + 1;
- ci->top = L->top + LUA_MINSTACK;
- lua_assert(ci->top <= L->stack_last);
- ci->nresults = nresults;
- if (L->hookmask & LUA_MASKCALL)
- luaD_callhook(L, LUA_HOOKCALL, -1);
- lua_unlock(L);
- n = (*curr_func(L)->c.f)(L); /* do the actual call */
- lua_lock(L);
- if (n < 0) /* yielding? */
- return PCRYIELD;
- else {
- luaD_poscall(L, L->top - n);
- return PCRC;
- }
- }
-}
-
-
-static StkId callrethooks (lua_State *L, StkId firstResult) {
- ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
- luaD_callhook(L, LUA_HOOKRET, -1);
- if (f_isLua(L->ci)) { /* Lua function? */
- while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
- luaD_callhook(L, LUA_HOOKTAILRET, -1);
- }
- return restorestack(L, fr);
-}
-
-
-int luaD_poscall (lua_State *L, StkId firstResult) {
- StkId res;
- int wanted, i;
- CallInfo *ci;
- if (L->hookmask & LUA_MASKRET)
- firstResult = callrethooks(L, firstResult);
- ci = L->ci--;
- res = ci->func; /* res == final position of 1st result */
- wanted = ci->nresults;
- L->base = (ci - 1)->base; /* restore base */
- L->savedpc = (ci - 1)->savedpc; /* restore savedpc */
- /* move results to correct place */
- for (i = wanted; i != 0 && firstResult < L->top; i--)
- setobjs2s(L, res++, firstResult++);
- while (i-- > 0)
- setnilvalue(res++);
- L->top = res;
- return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */
-}
-
-
-/*
-** Call a function (C or Lua). The function to be called is at *func.
-** The arguments are on the stack, right after the function.
-** When returns, all the results are on the stack, starting at the original
-** function position.
-*/
-void luaD_call (lua_State *L, StkId func, int nResults) {
- if (++L->nCcalls >= LUAI_MAXCCALLS) {
- if (L->nCcalls == LUAI_MAXCCALLS)
- luaG_runerror(L, "C stack overflow");
- else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
- luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
- }
- if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */
- luaV_execute(L, 1); /* call it */
- L->nCcalls--;
- luaC_checkGC(L);
-}
-
-
-static void resume (lua_State *L, void *ud) {
- StkId firstArg = cast(StkId, ud);
- CallInfo *ci = L->ci;
- if (L->status == 0) { /* start coroutine? */
- lua_assert(ci == L->base_ci && firstArg > L->base);
- if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)
- return;
- }
- else { /* resuming from previous yield */
- lua_assert(L->status == LUA_YIELD);
- L->status = 0;
- if (!f_isLua(ci)) { /* `common' yield? */
- /* finish interrupted execution of `OP_CALL' */
- lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
- GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);
- if (luaD_poscall(L, firstArg)) /* complete it... */
- L->top = L->ci->top; /* and correct top if not multiple results */
- }
- else /* yielded inside a hook: just continue its execution */
- L->base = L->ci->base;
- }
- luaV_execute(L, cast_int(L->ci - L->base_ci));
-}
-
-
-static int resume_error (lua_State *L, const char *msg) {
- L->top = L->ci->base;
- setsvalue2s(L, L->top, luaS_new(L, msg));
- incr_top(L);
- lua_unlock(L);
- return LUA_ERRRUN;
-}
-
-
-LUA_API int lua_resume (lua_State *L, int nargs) {
- int status;
- lua_lock(L);
- if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
- return resume_error(L, "cannot resume non-suspended coroutine");
- if (L->nCcalls >= LUAI_MAXCCALLS)
- return resume_error(L, "C stack overflow");
- luai_userstateresume(L, nargs);
- lua_assert(L->errfunc == 0);
- L->baseCcalls = ++L->nCcalls;
- status = luaD_rawrunprotected(L, resume, L->top - nargs);
- if (status != 0) { /* error? */
- L->status = cast_byte(status); /* mark thread as `dead' */
- luaD_seterrorobj(L, status, L->top);
- L->ci->top = L->top;
- }
- else {
- lua_assert(L->nCcalls == L->baseCcalls);
- status = L->status;
- }
- --L->nCcalls;
- lua_unlock(L);
- return status;
-}
-
-
-LUA_API int lua_yield (lua_State *L, int nresults) {
- luai_userstateyield(L, nresults);
- lua_lock(L);
- if (L->nCcalls > L->baseCcalls)
- luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
- L->base = L->top - nresults; /* protect stack slots below */
- L->status = LUA_YIELD;
- lua_unlock(L);
- return -1;
-}
-
-
-int luaD_pcall (lua_State *L, Pfunc func, void *u,
- ptrdiff_t old_top, ptrdiff_t ef) {
- int status;
- unsigned short oldnCcalls = L->nCcalls;
- ptrdiff_t old_ci = saveci(L, L->ci);
- lu_byte old_allowhooks = L->allowhook;
- ptrdiff_t old_errfunc = L->errfunc;
- L->errfunc = ef;
- status = luaD_rawrunprotected(L, func, u);
- if (status != 0) { /* an error occurred? */
- StkId oldtop = restorestack(L, old_top);
- luaF_close(L, oldtop); /* close eventual pending closures */
- luaD_seterrorobj(L, status, oldtop);
- L->nCcalls = oldnCcalls;
- L->ci = restoreci(L, old_ci);
- L->base = L->ci->base;
- L->savedpc = L->ci->savedpc;
- L->allowhook = old_allowhooks;
- restore_stack_limit(L);
- }
- L->errfunc = old_errfunc;
- return status;
-}
-
-
-
-/*
-** Execute a protected parser.
-*/
-struct SParser { /* data to `f_parser' */
- ZIO *z;
- Mbuffer buff; /* buffer to be used by the scanner */
- const char *name;
-};
-
-static void f_parser (lua_State *L, void *ud) {
- int i;
- Proto *tf;
- Closure *cl;
- struct SParser *p = cast(struct SParser *, ud);
- int c = luaZ_lookahead(p->z);
- luaC_checkGC(L);
- tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,
- &p->buff, p->name);
- cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));
- cl->l.p = tf;
- for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */
- cl->l.upvals[i] = luaF_newupval(L);
- setclvalue(L, L->top, cl);
- incr_top(L);
-}
-
-
-int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
- struct SParser p;
- int status;
- p.z = z; p.name = name;
- luaZ_initbuffer(L, &p.buff);
- status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
- luaZ_freebuffer(L, &p.buff);
- return status;
-}
-
-
diff --git a/lib/lua/ldo.h b/lib/lua/ldo.h
deleted file mode 100644
index 98fddac..0000000
--- a/lib/lua/ldo.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
-** Stack and Call structure of Lua
-** See Copyright Notice in lua.h
-*/
-
-#ifndef ldo_h
-#define ldo_h
-
-
-#include "lobject.h"
-#include "lstate.h"
-#include "lzio.h"
-
-
-#define luaD_checkstack(L,n) \
- if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
- luaD_growstack(L, n); \
- else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
-
-
-#define incr_top(L) {luaD_checkstack(L,1); L->top++;}
-
-#define savestack(L,p) ((char *)(p) - (char *)L->stack)
-#define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
-
-#define saveci(L,p) ((char *)(p) - (char *)L->base_ci)
-#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n)))
-
-
-/* results from luaD_precall */
-#define PCRLUA 0 /* initiated a call to a Lua function */
-#define PCRC 1 /* did a call to a C function */
-#define PCRYIELD 2 /* C funtion yielded */
-
-
-/* type of protected functions, to be ran by `runprotected' */
-typedef void (*Pfunc) (lua_State *L, void *ud);
-
-LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
-LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);
-LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
-LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
-LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
- ptrdiff_t oldtop, ptrdiff_t ef);
-LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
-LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
-LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
-LUAI_FUNC void luaD_growstack (lua_State *L, int n);
-
-LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
-LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
-
-LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
-
-#endif
-
diff --git a/lib/lua/ldump.c b/lib/lua/ldump.c
deleted file mode 100644
index c9d3d48..0000000
--- a/lib/lua/ldump.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
-** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
-** save precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#include
-
-#define ldump_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lobject.h"
-#include "lstate.h"
-#include "lundump.h"
-
-typedef struct {
- lua_State* L;
- lua_Writer writer;
- void* data;
- int strip;
- int status;
-} DumpState;
-
-#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
-#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
-
-static void DumpBlock(const void* b, size_t size, DumpState* D)
-{
- if (D->status==0)
- {
- lua_unlock(D->L);
- D->status=(*D->writer)(D->L,b,size,D->data);
- lua_lock(D->L);
- }
-}
-
-static void DumpChar(int y, DumpState* D)
-{
- char x=(char)y;
- DumpVar(x,D);
-}
-
-static void DumpInt(int x, DumpState* D)
-{
- DumpVar(x,D);
-}
-
-static void DumpNumber(lua_Number x, DumpState* D)
-{
- DumpVar(x,D);
-}
-
-static void DumpVector(const void* b, int n, size_t size, DumpState* D)
-{
- DumpInt(n,D);
- DumpMem(b,n,size,D);
-}
-
-static void DumpString(const TString* s, DumpState* D)
-{
- if (s==NULL || getstr(s)==NULL)
- {
- size_t size=0;
- DumpVar(size,D);
- }
- else
- {
- size_t size=s->tsv.len+1; /* include trailing '\0' */
- DumpVar(size,D);
- DumpBlock(getstr(s),size,D);
- }
-}
-
-#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
-
-static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
-
-static void DumpConstants(const Proto* f, DumpState* D)
-{
- int i,n=f->sizek;
- DumpInt(n,D);
- for (i=0; ik[i];
- DumpChar(ttype(o),D);
- switch (ttype(o))
- {
- case LUA_TNIL:
- break;
- case LUA_TBOOLEAN:
- DumpChar(bvalue(o),D);
- break;
- case LUA_TNUMBER:
- DumpNumber(nvalue(o),D);
- break;
- case LUA_TSTRING:
- DumpString(rawtsvalue(o),D);
- break;
- default:
- lua_assert(0); /* cannot happen */
- break;
- }
- }
- n=f->sizep;
- DumpInt(n,D);
- for (i=0; ip[i],f->source,D);
-}
-
-static void DumpDebug(const Proto* f, DumpState* D)
-{
- int i,n;
- n= (D->strip) ? 0 : f->sizelineinfo;
- DumpVector(f->lineinfo,n,sizeof(int),D);
- n= (D->strip) ? 0 : f->sizelocvars;
- DumpInt(n,D);
- for (i=0; ilocvars[i].varname,D);
- DumpInt(f->locvars[i].startpc,D);
- DumpInt(f->locvars[i].endpc,D);
- }
- n= (D->strip) ? 0 : f->sizeupvalues;
- DumpInt(n,D);
- for (i=0; iupvalues[i],D);
-}
-
-static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
-{
- DumpString((f->source==p || D->strip) ? NULL : f->source,D);
- DumpInt(f->linedefined,D);
- DumpInt(f->lastlinedefined,D);
- DumpChar(f->nups,D);
- DumpChar(f->numparams,D);
- DumpChar(f->is_vararg,D);
- DumpChar(f->maxstacksize,D);
- DumpCode(f,D);
- DumpConstants(f,D);
- DumpDebug(f,D);
-}
-
-static void DumpHeader(DumpState* D)
-{
- char h[LUAC_HEADERSIZE];
- luaU_header(h);
- DumpBlock(h,LUAC_HEADERSIZE,D);
-}
-
-/*
-** dump Lua function as precompiled chunk
-*/
-int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
-{
- DumpState D;
- D.L=L;
- D.writer=w;
- D.data=data;
- D.strip=strip;
- D.status=0;
- DumpHeader(&D);
- DumpFunction(f,NULL,&D);
- return D.status;
-}
diff --git a/lib/lua/lfunc.c b/lib/lua/lfunc.c
deleted file mode 100644
index 813e88f..0000000
--- a/lib/lua/lfunc.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
-** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
-** Auxiliary functions to manipulate prototypes and closures
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lfunc_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lfunc.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-
-
-
-Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
- Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
- luaC_link(L, obj2gco(c), LUA_TFUNCTION);
- c->c.isC = 1;
- c->c.env = e;
- c->c.nupvalues = cast_byte(nelems);
- return c;
-}
-
-
-Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
- Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
- luaC_link(L, obj2gco(c), LUA_TFUNCTION);
- c->l.isC = 0;
- c->l.env = e;
- c->l.nupvalues = cast_byte(nelems);
- while (nelems--) c->l.upvals[nelems] = NULL;
- return c;
-}
-
-
-UpVal *luaF_newupval (lua_State *L) {
- UpVal *uv = luaM_new(L, UpVal);
- luaC_link(L, obj2gco(uv), LUA_TUPVAL);
- uv->v = &uv->u.value;
- setnilvalue(uv->v);
- return uv;
-}
-
-
-UpVal *luaF_findupval (lua_State *L, StkId level) {
- global_State *g = G(L);
- GCObject **pp = &L->openupval;
- UpVal *p;
- UpVal *uv;
- while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
- lua_assert(p->v != &p->u.value);
- if (p->v == level) { /* found a corresponding upvalue? */
- if (isdead(g, obj2gco(p))) /* is it dead? */
- changewhite(obj2gco(p)); /* ressurect it */
- return p;
- }
- pp = &p->next;
- }
- uv = luaM_new(L, UpVal); /* not found: create a new one */
- uv->tt = LUA_TUPVAL;
- uv->marked = luaC_white(g);
- uv->v = level; /* current value lives in the stack */
- uv->next = *pp; /* chain it in the proper position */
- *pp = obj2gco(uv);
- uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
- uv->u.l.next = g->uvhead.u.l.next;
- uv->u.l.next->u.l.prev = uv;
- g->uvhead.u.l.next = uv;
- lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
- return uv;
-}
-
-
-static void unlinkupval (UpVal *uv) {
- lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
- uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */
- uv->u.l.prev->u.l.next = uv->u.l.next;
-}
-
-
-void luaF_freeupval (lua_State *L, UpVal *uv) {
- if (uv->v != &uv->u.value) /* is it open? */
- unlinkupval(uv); /* remove from open list */
- luaM_free(L, uv); /* free upvalue */
-}
-
-
-void luaF_close (lua_State *L, StkId level) {
- UpVal *uv;
- global_State *g = G(L);
- while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
- GCObject *o = obj2gco(uv);
- lua_assert(!isblack(o) && uv->v != &uv->u.value);
- L->openupval = uv->next; /* remove from `open' list */
- if (isdead(g, o))
- luaF_freeupval(L, uv); /* free upvalue */
- else {
- unlinkupval(uv);
- setobj(L, &uv->u.value, uv->v);
- uv->v = &uv->u.value; /* now current value lives here */
- luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */
- }
- }
-}
-
-
-Proto *luaF_newproto (lua_State *L) {
- Proto *f = luaM_new(L, Proto);
- luaC_link(L, obj2gco(f), LUA_TPROTO);
- f->k = NULL;
- f->sizek = 0;
- f->p = NULL;
- f->sizep = 0;
- f->code = NULL;
- f->sizecode = 0;
- f->sizelineinfo = 0;
- f->sizeupvalues = 0;
- f->nups = 0;
- f->upvalues = NULL;
- f->numparams = 0;
- f->is_vararg = 0;
- f->maxstacksize = 0;
- f->lineinfo = NULL;
- f->sizelocvars = 0;
- f->locvars = NULL;
- f->linedefined = 0;
- f->lastlinedefined = 0;
- f->source = NULL;
- return f;
-}
-
-
-void luaF_freeproto (lua_State *L, Proto *f) {
- luaM_freearray(L, f->code, f->sizecode, Instruction);
- luaM_freearray(L, f->p, f->sizep, Proto *);
- luaM_freearray(L, f->k, f->sizek, TValue);
- luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
- luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
- luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
- luaM_free(L, f);
-}
-
-
-void luaF_freeclosure (lua_State *L, Closure *c) {
- int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
- sizeLclosure(c->l.nupvalues);
- luaM_freemem(L, c, size);
-}
-
-
-/*
-** Look for n-th local variable at line `line' in function `func'.
-** Returns NULL if not found.
-*/
-const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
- int i;
- for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) {
- if (pc < f->locvars[i].endpc) { /* is variable active? */
- local_number--;
- if (local_number == 0)
- return getstr(f->locvars[i].varname);
- }
- }
- return NULL; /* not found */
-}
-
diff --git a/lib/lua/lfunc.h b/lib/lua/lfunc.h
deleted file mode 100644
index a68cf51..0000000
--- a/lib/lua/lfunc.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
-** Auxiliary functions to manipulate prototypes and closures
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lfunc_h
-#define lfunc_h
-
-
-#include "lobject.h"
-
-
-#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
- cast(int, sizeof(TValue)*((n)-1)))
-
-#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
- cast(int, sizeof(TValue *)*((n)-1)))
-
-
-LUAI_FUNC Proto *luaF_newproto (lua_State *L);
-LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
-LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
-LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
-LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
-LUAI_FUNC void luaF_close (lua_State *L, StkId level);
-LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
-LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
-LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
-LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
- int pc);
-
-
-#endif
diff --git a/lib/lua/lgc.c b/lib/lua/lgc.c
deleted file mode 100644
index d9e0b78..0000000
--- a/lib/lua/lgc.c
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
-** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $
-** Garbage Collector
-** See Copyright Notice in lua.h
-*/
-
-#include
-
-#define lgc_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-
-
-#define GCSTEPSIZE 1024u
-#define GCSWEEPMAX 40
-#define GCSWEEPCOST 10
-#define GCFINALIZECOST 100
-
-
-#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
-
-#define makewhite(g,x) \
- ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
-
-#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
-#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
-
-#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
-
-
-#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT)
-#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT)
-
-
-#define KEYWEAK bitmask(KEYWEAKBIT)
-#define VALUEWEAK bitmask(VALUEWEAKBIT)
-
-
-
-#define markvalue(g,o) { checkconsistency(o); \
- if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }
-
-#define markobject(g,t) { if (iswhite(obj2gco(t))) \
- reallymarkobject(g, obj2gco(t)); }
-
-
-#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause)
-
-
-static void removeentry (Node *n) {
- lua_assert(ttisnil(gval(n)));
- if (iscollectable(gkey(n)))
- setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */
-}
-
-
-static void reallymarkobject (global_State *g, GCObject *o) {
- lua_assert(iswhite(o) && !isdead(g, o));
- white2gray(o);
- switch (o->gch.tt) {
- case LUA_TSTRING: {
- return;
- }
- case LUA_TUSERDATA: {
- Table *mt = gco2u(o)->metatable;
- gray2black(o); /* udata are never gray */
- if (mt) markobject(g, mt);
- markobject(g, gco2u(o)->env);
- return;
- }
- case LUA_TUPVAL: {
- UpVal *uv = gco2uv(o);
- markvalue(g, uv->v);
- if (uv->v == &uv->u.value) /* closed? */
- gray2black(o); /* open upvalues are never black */
- return;
- }
- case LUA_TFUNCTION: {
- gco2cl(o)->c.gclist = g->gray;
- g->gray = o;
- break;
- }
- case LUA_TTABLE: {
- gco2h(o)->gclist = g->gray;
- g->gray = o;
- break;
- }
- case LUA_TTHREAD: {
- gco2th(o)->gclist = g->gray;
- g->gray = o;
- break;
- }
- case LUA_TPROTO: {
- gco2p(o)->gclist = g->gray;
- g->gray = o;
- break;
- }
- default: lua_assert(0);
- }
-}
-
-
-static void marktmu (global_State *g) {
- GCObject *u = g->tmudata;
- if (u) {
- do {
- u = u->gch.next;
- makewhite(g, u); /* may be marked, if left from previous GC */
- reallymarkobject(g, u);
- } while (u != g->tmudata);
- }
-}
-
-
-/* move `dead' udata that need finalization to list `tmudata' */
-size_t luaC_separateudata (lua_State *L, int all) {
- global_State *g = G(L);
- size_t deadmem = 0;
- GCObject **p = &g->mainthread->next;
- GCObject *curr;
- while ((curr = *p) != NULL) {
- if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))
- p = &curr->gch.next; /* don't bother with them */
- else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {
- markfinalized(gco2u(curr)); /* don't need finalization */
- p = &curr->gch.next;
- }
- else { /* must call its gc method */
- deadmem += sizeudata(gco2u(curr));
- markfinalized(gco2u(curr));
- *p = curr->gch.next;
- /* link `curr' at the end of `tmudata' list */
- if (g->tmudata == NULL) /* list is empty? */
- g->tmudata = curr->gch.next = curr; /* creates a circular list */
- else {
- curr->gch.next = g->tmudata->gch.next;
- g->tmudata->gch.next = curr;
- g->tmudata = curr;
- }
- }
- }
- return deadmem;
-}
-
-
-static int traversetable (global_State *g, Table *h) {
- int i;
- int weakkey = 0;
- int weakvalue = 0;
- const TValue *mode;
- if (h->metatable)
- markobject(g, h->metatable);
- mode = gfasttm(g, h->metatable, TM_MODE);
- if (mode && ttisstring(mode)) { /* is there a weak mode? */
- weakkey = (strchr(svalue(mode), 'k') != NULL);
- weakvalue = (strchr(svalue(mode), 'v') != NULL);
- if (weakkey || weakvalue) { /* is really weak? */
- h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
- h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
- (weakvalue << VALUEWEAKBIT));
- h->gclist = g->weak; /* must be cleared after GC, ... */
- g->weak = obj2gco(h); /* ... so put in the appropriate list */
- }
- }
- if (weakkey && weakvalue) return 1;
- if (!weakvalue) {
- i = h->sizearray;
- while (i--)
- markvalue(g, &h->array[i]);
- }
- i = sizenode(h);
- while (i--) {
- Node *n = gnode(h, i);
- lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));
- if (ttisnil(gval(n)))
- removeentry(n); /* remove empty entries */
- else {
- lua_assert(!ttisnil(gkey(n)));
- if (!weakkey) markvalue(g, gkey(n));
- if (!weakvalue) markvalue(g, gval(n));
- }
- }
- return weakkey || weakvalue;
-}
-
-
-/*
-** All marks are conditional because a GC may happen while the
-** prototype is still being created
-*/
-static void traverseproto (global_State *g, Proto *f) {
- int i;
- if (f->source) stringmark(f->source);
- for (i=0; isizek; i++) /* mark literals */
- markvalue(g, &f->k[i]);
- for (i=0; isizeupvalues; i++) { /* mark upvalue names */
- if (f->upvalues[i])
- stringmark(f->upvalues[i]);
- }
- for (i=0; isizep; i++) { /* mark nested protos */
- if (f->p[i])
- markobject(g, f->p[i]);
- }
- for (i=0; isizelocvars; i++) { /* mark local-variable names */
- if (f->locvars[i].varname)
- stringmark(f->locvars[i].varname);
- }
-}
-
-
-
-static void traverseclosure (global_State *g, Closure *cl) {
- markobject(g, cl->c.env);
- if (cl->c.isC) {
- int i;
- for (i=0; ic.nupvalues; i++) /* mark its upvalues */
- markvalue(g, &cl->c.upvalue[i]);
- }
- else {
- int i;
- lua_assert(cl->l.nupvalues == cl->l.p->nups);
- markobject(g, cl->l.p);
- for (i=0; il.nupvalues; i++) /* mark its upvalues */
- markobject(g, cl->l.upvals[i]);
- }
-}
-
-
-static void checkstacksizes (lua_State *L, StkId max) {
- int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
- int s_used = cast_int(max - L->stack); /* part of stack in use */
- if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
- return; /* do not touch the stacks */
- if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
- luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
- condhardstacktests(luaD_reallocCI(L, ci_used + 1));
- if (4*s_used < L->stacksize &&
- 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
- luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
- condhardstacktests(luaD_reallocstack(L, s_used));
-}
-
-
-static void traversestack (global_State *g, lua_State *l) {
- StkId o, lim;
- CallInfo *ci;
- markvalue(g, gt(l));
- lim = l->top;
- for (ci = l->base_ci; ci <= l->ci; ci++) {
- lua_assert(ci->top <= l->stack_last);
- if (lim < ci->top) lim = ci->top;
- }
- for (o = l->stack; o < l->top; o++)
- markvalue(g, o);
- for (; o <= lim; o++)
- setnilvalue(o);
- checkstacksizes(l, lim);
-}
-
-
-/*
-** traverse one gray object, turning it to black.
-** Returns `quantity' traversed.
-*/
-static l_mem propagatemark (global_State *g) {
- GCObject *o = g->gray;
- lua_assert(isgray(o));
- gray2black(o);
- switch (o->gch.tt) {
- case LUA_TTABLE: {
- Table *h = gco2h(o);
- g->gray = h->gclist;
- if (traversetable(g, h)) /* table is weak? */
- black2gray(o); /* keep it gray */
- return sizeof(Table) + sizeof(TValue) * h->sizearray +
- sizeof(Node) * sizenode(h);
- }
- case LUA_TFUNCTION: {
- Closure *cl = gco2cl(o);
- g->gray = cl->c.gclist;
- traverseclosure(g, cl);
- return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
- sizeLclosure(cl->l.nupvalues);
- }
- case LUA_TTHREAD: {
- lua_State *th = gco2th(o);
- g->gray = th->gclist;
- th->gclist = g->grayagain;
- g->grayagain = o;
- black2gray(o);
- traversestack(g, th);
- return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
- sizeof(CallInfo) * th->size_ci;
- }
- case LUA_TPROTO: {
- Proto *p = gco2p(o);
- g->gray = p->gclist;
- traverseproto(g, p);
- return sizeof(Proto) + sizeof(Instruction) * p->sizecode +
- sizeof(Proto *) * p->sizep +
- sizeof(TValue) * p->sizek +
- sizeof(int) * p->sizelineinfo +
- sizeof(LocVar) * p->sizelocvars +
- sizeof(TString *) * p->sizeupvalues;
- }
- default: lua_assert(0); return 0;
- }
-}
-
-
-static size_t propagateall (global_State *g) {
- size_t m = 0;
- while (g->gray) m += propagatemark(g);
- return m;
-}
-
-
-/*
-** The next function tells whether a key or value can be cleared from
-** a weak table. Non-collectable objects are never removed from weak
-** tables. Strings behave as `values', so are never removed too. for
-** other objects: if really collected, cannot keep them; for userdata
-** being finalized, keep them in keys, but not in values
-*/
-static int iscleared (const TValue *o, int iskey) {
- if (!iscollectable(o)) return 0;
- if (ttisstring(o)) {
- stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
- return 0;
- }
- return iswhite(gcvalue(o)) ||
- (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
-}
-
-
-/*
-** clear collected entries from weaktables
-*/
-static void cleartable (GCObject *l) {
- while (l) {
- Table *h = gco2h(l);
- int i = h->sizearray;
- lua_assert(testbit(h->marked, VALUEWEAKBIT) ||
- testbit(h->marked, KEYWEAKBIT));
- if (testbit(h->marked, VALUEWEAKBIT)) {
- while (i--) {
- TValue *o = &h->array[i];
- if (iscleared(o, 0)) /* value was collected? */
- setnilvalue(o); /* remove value */
- }
- }
- i = sizenode(h);
- while (i--) {
- Node *n = gnode(h, i);
- if (!ttisnil(gval(n)) && /* non-empty entry? */
- (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {
- setnilvalue(gval(n)); /* remove value ... */
- removeentry(n); /* remove entry from table */
- }
- }
- l = h->gclist;
- }
-}
-
-
-static void freeobj (lua_State *L, GCObject *o) {
- switch (o->gch.tt) {
- case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
- case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
- case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
- case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
- case LUA_TTHREAD: {
- lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);
- luaE_freethread(L, gco2th(o));
- break;
- }
- case LUA_TSTRING: {
- G(L)->strt.nuse--;
- luaM_freemem(L, o, sizestring(gco2ts(o)));
- break;
- }
- case LUA_TUSERDATA: {
- luaM_freemem(L, o, sizeudata(gco2u(o)));
- break;
- }
- default: lua_assert(0);
- }
-}
-
-
-
-#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM)
-
-
-static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
- GCObject *curr;
- global_State *g = G(L);
- int deadmask = otherwhite(g);
- while ((curr = *p) != NULL && count-- > 0) {
- if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */
- sweepwholelist(L, &gco2th(curr)->openupval);
- if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */
- lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT));
- makewhite(g, curr); /* make it white (for next cycle) */
- p = &curr->gch.next;
- }
- else { /* must erase `curr' */
- lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT));
- *p = curr->gch.next;
- if (curr == g->rootgc) /* is the first element of the list? */
- g->rootgc = curr->gch.next; /* adjust first */
- freeobj(L, curr);
- }
- }
- return p;
-}
-
-
-static void checkSizes (lua_State *L) {
- global_State *g = G(L);
- /* check size of string hash */
- if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&
- g->strt.size > MINSTRTABSIZE*2)
- luaS_resize(L, g->strt.size/2); /* table is too big */
- /* check size of buffer */
- if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */
- size_t newsize = luaZ_sizebuffer(&g->buff) / 2;
- luaZ_resizebuffer(L, &g->buff, newsize);
- }
-}
-
-
-static void GCTM (lua_State *L) {
- global_State *g = G(L);
- GCObject *o = g->tmudata->gch.next; /* get first element */
- Udata *udata = rawgco2u(o);
- const TValue *tm;
- /* remove udata from `tmudata' */
- if (o == g->tmudata) /* last element? */
- g->tmudata = NULL;
- else
- g->tmudata->gch.next = udata->uv.next;
- udata->uv.next = g->mainthread->next; /* return it to `root' list */
- g->mainthread->next = o;
- makewhite(g, o);
- tm = fasttm(L, udata->uv.metatable, TM_GC);
- if (tm != NULL) {
- lu_byte oldah = L->allowhook;
- lu_mem oldt = g->GCthreshold;
- L->allowhook = 0; /* stop debug hooks during GC tag method */
- g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */
- setobj2s(L, L->top, tm);
- setuvalue(L, L->top+1, udata);
- L->top += 2;
- luaD_call(L, L->top - 2, 0);
- L->allowhook = oldah; /* restore hooks */
- g->GCthreshold = oldt; /* restore threshold */
- }
-}
-
-
-/*
-** Call all GC tag methods
-*/
-void luaC_callGCTM (lua_State *L) {
- while (G(L)->tmudata)
- GCTM(L);
-}
-
-
-void luaC_freeall (lua_State *L) {
- global_State *g = G(L);
- int i;
- g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */
- sweepwholelist(L, &g->rootgc);
- for (i = 0; i < g->strt.size; i++) /* free all string lists */
- sweepwholelist(L, &g->strt.hash[i]);
-}
-
-
-static void markmt (global_State *g) {
- int i;
- for (i=0; imt[i]) markobject(g, g->mt[i]);
-}
-
-
-/* mark root set */
-static void markroot (lua_State *L) {
- global_State *g = G(L);
- g->gray = NULL;
- g->grayagain = NULL;
- g->weak = NULL;
- markobject(g, g->mainthread);
- /* make global table be traversed before main stack */
- markvalue(g, gt(g->mainthread));
- markvalue(g, registry(L));
- markmt(g);
- g->gcstate = GCSpropagate;
-}
-
-
-static void remarkupvals (global_State *g) {
- UpVal *uv;
- for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {
- lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
- if (isgray(obj2gco(uv)))
- markvalue(g, uv->v);
- }
-}
-
-
-static void atomic (lua_State *L) {
- global_State *g = G(L);
- size_t udsize; /* total size of userdata to be finalized */
- /* remark occasional upvalues of (maybe) dead threads */
- remarkupvals(g);
- /* traverse objects cautch by write barrier and by 'remarkupvals' */
- propagateall(g);
- /* remark weak tables */
- g->gray = g->weak;
- g->weak = NULL;
- lua_assert(!iswhite(obj2gco(g->mainthread)));
- markobject(g, L); /* mark running thread */
- markmt(g); /* mark basic metatables (again) */
- propagateall(g);
- /* remark gray again */
- g->gray = g->grayagain;
- g->grayagain = NULL;
- propagateall(g);
- udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
- marktmu(g); /* mark `preserved' userdata */
- udsize += propagateall(g); /* remark, to propagate `preserveness' */
- cleartable(g->weak); /* remove collected objects from weak tables */
- /* flip current white */
- g->currentwhite = cast_byte(otherwhite(g));
- g->sweepstrgc = 0;
- g->sweepgc = &g->rootgc;
- g->gcstate = GCSsweepstring;
- g->estimate = g->totalbytes - udsize; /* first estimate */
-}
-
-
-static l_mem singlestep (lua_State *L) {
- global_State *g = G(L);
- /*lua_checkmemory(L);*/
- switch (g->gcstate) {
- case GCSpause: {
- markroot(L); /* start a new collection */
- return 0;
- }
- case GCSpropagate: {
- if (g->gray)
- return propagatemark(g);
- else { /* no more `gray' objects */
- atomic(L); /* finish mark phase */
- return 0;
- }
- }
- case GCSsweepstring: {
- lu_mem old = g->totalbytes;
- sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
- if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */
- g->gcstate = GCSsweep; /* end sweep-string phase */
- lua_assert(old >= g->totalbytes);
- g->estimate -= old - g->totalbytes;
- return GCSWEEPCOST;
- }
- case GCSsweep: {
- lu_mem old = g->totalbytes;
- g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
- if (*g->sweepgc == NULL) { /* nothing more to sweep? */
- checkSizes(L);
- g->gcstate = GCSfinalize; /* end sweep phase */
- }
- lua_assert(old >= g->totalbytes);
- g->estimate -= old - g->totalbytes;
- return GCSWEEPMAX*GCSWEEPCOST;
- }
- case GCSfinalize: {
- if (g->tmudata) {
- GCTM(L);
- if (g->estimate > GCFINALIZECOST)
- g->estimate -= GCFINALIZECOST;
- return GCFINALIZECOST;
- }
- else {
- g->gcstate = GCSpause; /* end collection */
- g->gcdept = 0;
- return 0;
- }
- }
- default: lua_assert(0); return 0;
- }
-}
-
-
-void luaC_step (lua_State *L) {
- global_State *g = G(L);
- l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
- if (lim == 0)
- lim = (MAX_LUMEM-1)/2; /* no limit */
- g->gcdept += g->totalbytes - g->GCthreshold;
- do {
- lim -= singlestep(L);
- if (g->gcstate == GCSpause)
- break;
- } while (lim > 0);
- if (g->gcstate != GCSpause) {
- if (g->gcdept < GCSTEPSIZE)
- g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/
- else {
- g->gcdept -= GCSTEPSIZE;
- g->GCthreshold = g->totalbytes;
- }
- }
- else {
- lua_assert(g->totalbytes >= g->estimate);
- setthreshold(g);
- }
-}
-
-
-void luaC_fullgc (lua_State *L) {
- global_State *g = G(L);
- if (g->gcstate <= GCSpropagate) {
- /* reset sweep marks to sweep all elements (returning them to white) */
- g->sweepstrgc = 0;
- g->sweepgc = &g->rootgc;
- /* reset other collector lists */
- g->gray = NULL;
- g->grayagain = NULL;
- g->weak = NULL;
- g->gcstate = GCSsweepstring;
- }
- lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate);
- /* finish any pending sweep phase */
- while (g->gcstate != GCSfinalize) {
- lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep);
- singlestep(L);
- }
- markroot(L);
- while (g->gcstate != GCSpause) {
- singlestep(L);
- }
- setthreshold(g);
-}
-
-
-void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
- global_State *g = G(L);
- lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
- lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
- lua_assert(ttype(&o->gch) != LUA_TTABLE);
- /* must keep invariant? */
- if (g->gcstate == GCSpropagate)
- reallymarkobject(g, v); /* restore invariant */
- else /* don't mind */
- makewhite(g, o); /* mark as white just to avoid other barriers */
-}
-
-
-void luaC_barrierback (lua_State *L, Table *t) {
- global_State *g = G(L);
- GCObject *o = obj2gco(t);
- lua_assert(isblack(o) && !isdead(g, o));
- lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
- black2gray(o); /* make table gray (again) */
- t->gclist = g->grayagain;
- g->grayagain = o;
-}
-
-
-void luaC_link (lua_State *L, GCObject *o, lu_byte tt) {
- global_State *g = G(L);
- o->gch.next = g->rootgc;
- g->rootgc = o;
- o->gch.marked = luaC_white(g);
- o->gch.tt = tt;
-}
-
-
-void luaC_linkupval (lua_State *L, UpVal *uv) {
- global_State *g = G(L);
- GCObject *o = obj2gco(uv);
- o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */
- g->rootgc = o;
- if (isgray(o)) {
- if (g->gcstate == GCSpropagate) {
- gray2black(o); /* closed upvalues need barrier */
- luaC_barrier(L, uv, uv->v);
- }
- else { /* sweep phase: sweep it (turning it into white) */
- makewhite(g, o);
- lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
- }
- }
-}
-
diff --git a/lib/lua/lgc.h b/lib/lua/lgc.h
deleted file mode 100644
index 5a8dc60..0000000
--- a/lib/lua/lgc.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
-** Garbage Collector
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lgc_h
-#define lgc_h
-
-
-#include "lobject.h"
-
-
-/*
-** Possible states of the Garbage Collector
-*/
-#define GCSpause 0
-#define GCSpropagate 1
-#define GCSsweepstring 2
-#define GCSsweep 3
-#define GCSfinalize 4
-
-
-/*
-** some userful bit tricks
-*/
-#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
-#define setbits(x,m) ((x) |= (m))
-#define testbits(x,m) ((x) & (m))
-#define bitmask(b) (1<<(b))
-#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
-#define l_setbit(x,b) setbits(x, bitmask(b))
-#define resetbit(x,b) resetbits(x, bitmask(b))
-#define testbit(x,b) testbits(x, bitmask(b))
-#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
-#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
-#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
-
-
-
-/*
-** Layout for bit use in `marked' field:
-** bit 0 - object is white (type 0)
-** bit 1 - object is white (type 1)
-** bit 2 - object is black
-** bit 3 - for userdata: has been finalized
-** bit 3 - for tables: has weak keys
-** bit 4 - for tables: has weak values
-** bit 5 - object is fixed (should not be collected)
-** bit 6 - object is "super" fixed (only the main thread)
-*/
-
-
-#define WHITE0BIT 0
-#define WHITE1BIT 1
-#define BLACKBIT 2
-#define FINALIZEDBIT 3
-#define KEYWEAKBIT 3
-#define VALUEWEAKBIT 4
-#define FIXEDBIT 5
-#define SFIXEDBIT 6
-#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
-
-
-#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
-#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
-#define isgray(x) (!isblack(x) && !iswhite(x))
-
-#define otherwhite(g) (g->currentwhite ^ WHITEBITS)
-#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
-
-#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
-#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
-
-#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
-
-#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
-
-
-#define luaC_checkGC(L) { \
- condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
- if (G(L)->totalbytes >= G(L)->GCthreshold) \
- luaC_step(L); }
-
-
-#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
- luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
-
-#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
- luaC_barrierback(L,t); }
-
-#define luaC_objbarrier(L,p,o) \
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
- luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
-
-#define luaC_objbarriert(L,t,o) \
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
-
-LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
-LUAI_FUNC void luaC_callGCTM (lua_State *L);
-LUAI_FUNC void luaC_freeall (lua_State *L);
-LUAI_FUNC void luaC_step (lua_State *L);
-LUAI_FUNC void luaC_fullgc (lua_State *L);
-LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
-LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
-LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
-LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
-
-
-#endif
diff --git a/lib/lua/linit.c b/lib/lua/linit.c
deleted file mode 100644
index c1f90df..0000000
--- a/lib/lua/linit.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
-** Initialization of libraries for lua.c
-** See Copyright Notice in lua.h
-*/
-
-
-#define linit_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lualib.h"
-#include "lauxlib.h"
-
-
-static const luaL_Reg lualibs[] = {
- {"", luaopen_base},
- {LUA_LOADLIBNAME, luaopen_package},
- {LUA_TABLIBNAME, luaopen_table},
- {LUA_IOLIBNAME, luaopen_io},
- {LUA_OSLIBNAME, luaopen_os},
- {LUA_STRLIBNAME, luaopen_string},
- {LUA_MATHLIBNAME, luaopen_math},
- {LUA_DBLIBNAME, luaopen_debug},
- {NULL, NULL}
-};
-
-
-LUALIB_API void luaL_openlibs (lua_State *L) {
- const luaL_Reg *lib = lualibs;
- for (; lib->func; lib++) {
- lua_pushcfunction(L, lib->func);
- lua_pushstring(L, lib->name);
- lua_call(L, 1, 0);
- }
-}
-
diff --git a/lib/lua/liolib.c b/lib/lua/liolib.c
deleted file mode 100644
index e79ed1c..0000000
--- a/lib/lua/liolib.c
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
-** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $
-** Standard I/O (and system) library
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-
-#define liolib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-
-#define IO_INPUT 1
-#define IO_OUTPUT 2
-
-
-static const char *const fnames[] = {"input", "output"};
-
-
-static int pushresult (lua_State *L, int i, const char *filename) {
- int en = errno; /* calls to Lua API may change this value */
- if (i) {
- lua_pushboolean(L, 1);
- return 1;
- }
- else {
- lua_pushnil(L);
- if (filename)
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
- else
- lua_pushfstring(L, "%s", strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
-}
-
-
-static void fileerror (lua_State *L, int arg, const char *filename) {
- lua_pushfstring(L, "%s: %s", filename, strerror(errno));
- luaL_argerror(L, arg, lua_tostring(L, -1));
-}
-
-
-#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
-
-
-static int io_type (lua_State *L) {
- void *ud;
- luaL_checkany(L, 1);
- ud = lua_touserdata(L, 1);
- lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
- if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))
- lua_pushnil(L); /* not a file */
- else if (*((FILE **)ud) == NULL)
- lua_pushliteral(L, "closed file");
- else
- lua_pushliteral(L, "file");
- return 1;
-}
-
-
-static FILE *tofile (lua_State *L) {
- FILE **f = tofilep(L);
- if (*f == NULL)
- luaL_error(L, "attempt to use a closed file");
- return *f;
-}
-
-
-
-/*
-** When creating file handles, always creates a `closed' file handle
-** before opening the actual file; so, if there is a memory error, the
-** file is not left opened.
-*/
-static FILE **newfile (lua_State *L) {
- FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
- *pf = NULL; /* file handle is currently `closed' */
- luaL_getmetatable(L, LUA_FILEHANDLE);
- lua_setmetatable(L, -2);
- return pf;
-}
-
-
-/*
-** function to (not) close the standard files stdin, stdout, and stderr
-*/
-static int io_noclose (lua_State *L) {
- lua_pushnil(L);
- lua_pushliteral(L, "cannot close standard file");
- return 2;
-}
-
-
-/*
-** function to close 'popen' files
-*/
-static int io_pclose (lua_State *L) {
- FILE **p = tofilep(L);
- int ok = lua_pclose(L, *p);
- *p = NULL;
- return pushresult(L, ok, NULL);
-}
-
-
-/*
-** function to close regular files
-*/
-static int io_fclose (lua_State *L) {
- FILE **p = tofilep(L);
- int ok = (fclose(*p) == 0);
- *p = NULL;
- return pushresult(L, ok, NULL);
-}
-
-
-static int aux_close (lua_State *L) {
- lua_getfenv(L, 1);
- lua_getfield(L, -1, "__close");
- return (lua_tocfunction(L, -1))(L);
-}
-
-
-static int io_close (lua_State *L) {
- if (lua_isnone(L, 1))
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
- tofile(L); /* make sure argument is a file */
- return aux_close(L);
-}
-
-
-static int io_gc (lua_State *L) {
- FILE *f = *tofilep(L);
- /* ignore closed files */
- if (f != NULL)
- aux_close(L);
- return 0;
-}
-
-
-static int io_tostring (lua_State *L) {
- FILE *f = *tofilep(L);
- if (f == NULL)
- lua_pushliteral(L, "file (closed)");
- else
- lua_pushfstring(L, "file (%p)", f);
- return 1;
-}
-
-
-static int io_open (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
- FILE **pf = newfile(L);
- *pf = fopen(filename, mode);
- return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
-}
-
-
-/*
-** this function has a separated environment, which defines the
-** correct __close for 'popen' files
-*/
-static int io_popen (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
- FILE **pf = newfile(L);
- *pf = lua_popen(L, filename, mode);
- return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
-}
-
-
-static int io_tmpfile (lua_State *L) {
- FILE **pf = newfile(L);
- *pf = tmpfile();
- return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
-}
-
-
-static FILE *getiofile (lua_State *L, int findex) {
- FILE *f;
- lua_rawgeti(L, LUA_ENVIRONINDEX, findex);
- f = *(FILE **)lua_touserdata(L, -1);
- if (f == NULL)
- luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
- return f;
-}
-
-
-static int g_iofile (lua_State *L, int f, const char *mode) {
- if (!lua_isnoneornil(L, 1)) {
- const char *filename = lua_tostring(L, 1);
- if (filename) {
- FILE **pf = newfile(L);
- *pf = fopen(filename, mode);
- if (*pf == NULL)
- fileerror(L, 1, filename);
- }
- else {
- tofile(L); /* check that it's a valid file handle */
- lua_pushvalue(L, 1);
- }
- lua_rawseti(L, LUA_ENVIRONINDEX, f);
- }
- /* return current value */
- lua_rawgeti(L, LUA_ENVIRONINDEX, f);
- return 1;
-}
-
-
-static int io_input (lua_State *L) {
- return g_iofile(L, IO_INPUT, "r");
-}
-
-
-static int io_output (lua_State *L) {
- return g_iofile(L, IO_OUTPUT, "w");
-}
-
-
-static int io_readline (lua_State *L);
-
-
-static void aux_lines (lua_State *L, int idx, int toclose) {
- lua_pushvalue(L, idx);
- lua_pushboolean(L, toclose); /* close/not close file when finished */
- lua_pushcclosure(L, io_readline, 2);
-}
-
-
-static int f_lines (lua_State *L) {
- tofile(L); /* check that it's a valid file handle */
- aux_lines(L, 1, 0);
- return 1;
-}
-
-
-static int io_lines (lua_State *L) {
- if (lua_isnoneornil(L, 1)) { /* no arguments? */
- /* will iterate over default input */
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
- return f_lines(L);
- }
- else {
- const char *filename = luaL_checkstring(L, 1);
- FILE **pf = newfile(L);
- *pf = fopen(filename, "r");
- if (*pf == NULL)
- fileerror(L, 1, filename);
- aux_lines(L, lua_gettop(L), 1);
- return 1;
- }
-}
-
-
-/*
-** {======================================================
-** READ
-** =======================================================
-*/
-
-
-static int read_number (lua_State *L, FILE *f) {
- lua_Number d;
- if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
- lua_pushnumber(L, d);
- return 1;
- }
- else return 0; /* read fails */
-}
-
-
-static int test_eof (lua_State *L, FILE *f) {
- int c = getc(f);
- ungetc(c, f);
- lua_pushlstring(L, NULL, 0);
- return (c != EOF);
-}
-
-
-static int read_line (lua_State *L, FILE *f) {
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- for (;;) {
- size_t l;
- char *p = luaL_prepbuffer(&b);
- if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
- luaL_pushresult(&b); /* close buffer */
- return (lua_objlen(L, -1) > 0); /* check whether read something */
- }
- l = strlen(p);
- if (l == 0 || p[l-1] != '\n')
- luaL_addsize(&b, l);
- else {
- luaL_addsize(&b, l - 1); /* do not include `eol' */
- luaL_pushresult(&b); /* close buffer */
- return 1; /* read at least an `eol' */
- }
- }
-}
-
-
-static int read_chars (lua_State *L, FILE *f, size_t n) {
- size_t rlen; /* how much to read */
- size_t nr; /* number of chars actually read */
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
- do {
- char *p = luaL_prepbuffer(&b);
- if (rlen > n) rlen = n; /* cannot read more than asked */
- nr = fread(p, sizeof(char), rlen, f);
- luaL_addsize(&b, nr);
- n -= nr; /* still have to read `n' chars */
- } while (n > 0 && nr == rlen); /* until end of count or eof */
- luaL_pushresult(&b); /* close buffer */
- return (n == 0 || lua_objlen(L, -1) > 0);
-}
-
-
-static int g_read (lua_State *L, FILE *f, int first) {
- int nargs = lua_gettop(L) - 1;
- int success;
- int n;
- clearerr(f);
- if (nargs == 0) { /* no arguments? */
- success = read_line(L, f);
- n = first+1; /* to return 1 result */
- }
- else { /* ensure stack space for all results and for auxlib's buffer */
- luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
- success = 1;
- for (n = first; nargs-- && success; n++) {
- if (lua_type(L, n) == LUA_TNUMBER) {
- size_t l = (size_t)lua_tointeger(L, n);
- success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
- }
- else {
- const char *p = lua_tostring(L, n);
- luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
- switch (p[1]) {
- case 'n': /* number */
- success = read_number(L, f);
- break;
- case 'l': /* line */
- success = read_line(L, f);
- break;
- case 'a': /* file */
- read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
- success = 1; /* always success */
- break;
- default:
- return luaL_argerror(L, n, "invalid format");
- }
- }
- }
- }
- if (ferror(f))
- return pushresult(L, 0, NULL);
- if (!success) {
- lua_pop(L, 1); /* remove last result */
- lua_pushnil(L); /* push nil instead */
- }
- return n - first;
-}
-
-
-static int io_read (lua_State *L) {
- return g_read(L, getiofile(L, IO_INPUT), 1);
-}
-
-
-static int f_read (lua_State *L) {
- return g_read(L, tofile(L), 2);
-}
-
-
-static int io_readline (lua_State *L) {
- FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
- int sucess;
- if (f == NULL) /* file is already closed? */
- luaL_error(L, "file is already closed");
- sucess = read_line(L, f);
- if (ferror(f))
- return luaL_error(L, "%s", strerror(errno));
- if (sucess) return 1;
- else { /* EOF */
- if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */
- lua_settop(L, 0);
- lua_pushvalue(L, lua_upvalueindex(1));
- aux_close(L); /* close it */
- }
- return 0;
- }
-}
-
-/* }====================================================== */
-
-
-static int g_write (lua_State *L, FILE *f, int arg) {
- int nargs = lua_gettop(L) - 1;
- int status = 1;
- for (; nargs--; arg++) {
- if (lua_type(L, arg) == LUA_TNUMBER) {
- /* optimization: could be done exactly as for strings */
- status = status &&
- fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
- }
- else {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- status = status && (fwrite(s, sizeof(char), l, f) == l);
- }
- }
- return pushresult(L, status, NULL);
-}
-
-
-static int io_write (lua_State *L) {
- return g_write(L, getiofile(L, IO_OUTPUT), 1);
-}
-
-
-static int f_write (lua_State *L) {
- return g_write(L, tofile(L), 2);
-}
-
-
-static int f_seek (lua_State *L) {
- static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
- static const char *const modenames[] = {"set", "cur", "end", NULL};
- FILE *f = tofile(L);
- int op = luaL_checkoption(L, 2, "cur", modenames);
- long offset = luaL_optlong(L, 3, 0);
- op = fseek(f, offset, mode[op]);
- if (op)
- return pushresult(L, 0, NULL); /* error */
- else {
- lua_pushinteger(L, ftell(f));
- return 1;
- }
-}
-
-
-static int f_setvbuf (lua_State *L) {
- static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
- static const char *const modenames[] = {"no", "full", "line", NULL};
- FILE *f = tofile(L);
- int op = luaL_checkoption(L, 2, NULL, modenames);
- lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
- int res = setvbuf(f, NULL, mode[op], sz);
- return pushresult(L, res == 0, NULL);
-}
-
-
-
-static int io_flush (lua_State *L) {
- return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
-}
-
-
-static int f_flush (lua_State *L) {
- return pushresult(L, fflush(tofile(L)) == 0, NULL);
-}
-
-
-static const luaL_Reg iolib[] = {
- {"close", io_close},
- {"flush", io_flush},
- {"input", io_input},
- {"lines", io_lines},
- {"open", io_open},
- {"output", io_output},
- {"popen", io_popen},
- {"read", io_read},
- {"tmpfile", io_tmpfile},
- {"type", io_type},
- {"write", io_write},
- {NULL, NULL}
-};
-
-
-static const luaL_Reg flib[] = {
- {"close", io_close},
- {"flush", f_flush},
- {"lines", f_lines},
- {"read", f_read},
- {"seek", f_seek},
- {"setvbuf", f_setvbuf},
- {"write", f_write},
- {"__gc", io_gc},
- {"__tostring", io_tostring},
- {NULL, NULL}
-};
-
-
-static void createmeta (lua_State *L) {
- luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
- lua_pushvalue(L, -1); /* push metatable */
- lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
- luaL_register(L, NULL, flib); /* file methods */
-}
-
-
-static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
- *newfile(L) = f;
- if (k > 0) {
- lua_pushvalue(L, -1);
- lua_rawseti(L, LUA_ENVIRONINDEX, k);
- }
- lua_pushvalue(L, -2); /* copy environment */
- lua_setfenv(L, -2); /* set it */
- lua_setfield(L, -3, fname);
-}
-
-
-static void newfenv (lua_State *L, lua_CFunction cls) {
- lua_createtable(L, 0, 1);
- lua_pushcfunction(L, cls);
- lua_setfield(L, -2, "__close");
-}
-
-
-LUALIB_API int luaopen_io (lua_State *L) {
- createmeta(L);
- /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
- newfenv(L, io_fclose);
- lua_replace(L, LUA_ENVIRONINDEX);
- /* open library */
- luaL_register(L, LUA_IOLIBNAME, iolib);
- /* create (and set) default files */
- newfenv(L, io_noclose); /* close function for default files */
- createstdfile(L, stdin, IO_INPUT, "stdin");
- createstdfile(L, stdout, IO_OUTPUT, "stdout");
- createstdfile(L, stderr, 0, "stderr");
- lua_pop(L, 1); /* pop environment for default files */
- lua_getfield(L, -1, "popen");
- newfenv(L, io_pclose); /* create environment for 'popen' */
- lua_setfenv(L, -2); /* set fenv for 'popen' */
- lua_pop(L, 1); /* pop 'popen' */
- return 1;
-}
-
diff --git a/lib/lua/llex.c b/lib/lua/llex.c
deleted file mode 100644
index 6dc3193..0000000
--- a/lib/lua/llex.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
-** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lexical Analyzer
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-
-#define llex_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldo.h"
-#include "llex.h"
-#include "lobject.h"
-#include "lparser.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "lzio.h"
-
-
-
-#define next(ls) (ls->current = zgetc(ls->z))
-
-
-
-
-#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
-
-
-/* ORDER RESERVED */
-const char *const luaX_tokens [] = {
- "and", "break", "do", "else", "elseif",
- "end", "false", "for", "function", "if",
- "in", "local", "nil", "not", "or", "repeat",
- "return", "then", "true", "until", "while",
- "..", "...", "==", ">=", "<=", "~=",
- "", "", "", "",
- NULL
-};
-
-
-#define save_and_next(ls) (save(ls, ls->current), next(ls))
-
-
-static void save (LexState *ls, int c) {
- Mbuffer *b = ls->buff;
- if (b->n + 1 > b->buffsize) {
- size_t newsize;
- if (b->buffsize >= MAX_SIZET/2)
- luaX_lexerror(ls, "lexical element too long", 0);
- newsize = b->buffsize * 2;
- luaZ_resizebuffer(ls->L, b, newsize);
- }
- b->buffer[b->n++] = cast(char, c);
-}
-
-
-void luaX_init (lua_State *L) {
- int i;
- for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */
- }
-}
-
-
-#define MAXSRC 80
-
-
-const char *luaX_token2str (LexState *ls, int token) {
- if (token < FIRST_RESERVED) {
- lua_assert(token == cast(unsigned char, token));
- return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
- luaO_pushfstring(ls->L, "%c", token);
- }
- else
- return luaX_tokens[token-FIRST_RESERVED];
-}
-
-
-static const char *txtToken (LexState *ls, int token) {
- switch (token) {
- case TK_NAME:
- case TK_STRING:
- case TK_NUMBER:
- save(ls, '\0');
- return luaZ_buffer(ls->buff);
- default:
- return luaX_token2str(ls, token);
- }
-}
-
-
-void luaX_lexerror (LexState *ls, const char *msg, int token) {
- char buff[MAXSRC];
- luaO_chunkid(buff, getstr(ls->source), MAXSRC);
- msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
- if (token)
- luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
- luaD_throw(ls->L, LUA_ERRSYNTAX);
-}
-
-
-void luaX_syntaxerror (LexState *ls, const char *msg) {
- luaX_lexerror(ls, msg, ls->t.token);
-}
-
-
-TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
- lua_State *L = ls->L;
- TString *ts = luaS_newlstr(L, str, l);
- TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
- if (ttisnil(o))
- setbvalue(o, 1); /* make sure `str' will not be collected */
- return ts;
-}
-
-
-static void inclinenumber (LexState *ls) {
- int old = ls->current;
- lua_assert(currIsNewline(ls));
- next(ls); /* skip `\n' or `\r' */
- if (currIsNewline(ls) && ls->current != old)
- next(ls); /* skip `\n\r' or `\r\n' */
- if (++ls->linenumber >= MAX_INT)
- luaX_syntaxerror(ls, "chunk has too many lines");
-}
-
-
-void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
- ls->decpoint = '.';
- ls->L = L;
- ls->lookahead.token = TK_EOS; /* no look-ahead token */
- ls->z = z;
- ls->fs = NULL;
- ls->linenumber = 1;
- ls->lastline = 1;
- ls->source = source;
- luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
- next(ls); /* read first char */
-}
-
-
-
-/*
-** =======================================================
-** LEXICAL ANALYZER
-** =======================================================
-*/
-
-
-
-static int check_next (LexState *ls, const char *set) {
- if (!strchr(set, ls->current))
- return 0;
- save_and_next(ls);
- return 1;
-}
-
-
-static void buffreplace (LexState *ls, char from, char to) {
- size_t n = luaZ_bufflen(ls->buff);
- char *p = luaZ_buffer(ls->buff);
- while (n--)
- if (p[n] == from) p[n] = to;
-}
-
-
-static void trydecpoint (LexState *ls, SemInfo *seminfo) {
- /* format error: try to update decimal point separator */
- struct lconv *cv = localeconv();
- char old = ls->decpoint;
- ls->decpoint = (cv ? cv->decimal_point[0] : '.');
- buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
- if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
- /* format error with correct decimal point: no more options */
- buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
- luaX_lexerror(ls, "malformed number", TK_NUMBER);
- }
-}
-
-
-/* LUA_NUMBER */
-static void read_numeral (LexState *ls, SemInfo *seminfo) {
- lua_assert(isdigit(ls->current));
- do {
- save_and_next(ls);
- } while (isdigit(ls->current) || ls->current == '.');
- if (check_next(ls, "Ee")) /* `E'? */
- check_next(ls, "+-"); /* optional exponent sign */
- while (isalnum(ls->current) || ls->current == '_')
- save_and_next(ls);
- save(ls, '\0');
- buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
- if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
- trydecpoint(ls, seminfo); /* try to update decimal point separator */
-}
-
-
-static int skip_sep (LexState *ls) {
- int count = 0;
- int s = ls->current;
- lua_assert(s == '[' || s == ']');
- save_and_next(ls);
- while (ls->current == '=') {
- save_and_next(ls);
- count++;
- }
- return (ls->current == s) ? count : (-count) - 1;
-}
-
-
-static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
- int cont = 0;
- (void)(cont); /* avoid warnings when `cont' is not used */
- save_and_next(ls); /* skip 2nd `[' */
- if (currIsNewline(ls)) /* string starts with a newline? */
- inclinenumber(ls); /* skip it */
- for (;;) {
- switch (ls->current) {
- case EOZ:
- luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
- "unfinished long comment", TK_EOS);
- break; /* to avoid warnings */
-#if defined(LUA_COMPAT_LSTR)
- case '[': {
- if (skip_sep(ls) == sep) {
- save_and_next(ls); /* skip 2nd `[' */
- cont++;
-#if LUA_COMPAT_LSTR == 1
- if (sep == 0)
- luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
-#endif
- }
- break;
- }
-#endif
- case ']': {
- if (skip_sep(ls) == sep) {
- save_and_next(ls); /* skip 2nd `]' */
-#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
- cont--;
- if (sep == 0 && cont >= 0) break;
-#endif
- goto endloop;
- }
- break;
- }
- case '\n':
- case '\r': {
- save(ls, '\n');
- inclinenumber(ls);
- if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
- break;
- }
- default: {
- if (seminfo) save_and_next(ls);
- else next(ls);
- }
- }
- } endloop:
- if (seminfo)
- seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
- luaZ_bufflen(ls->buff) - 2*(2 + sep));
-}
-
-
-static void read_string (LexState *ls, int del, SemInfo *seminfo) {
- save_and_next(ls);
- while (ls->current != del) {
- switch (ls->current) {
- case EOZ:
- luaX_lexerror(ls, "unfinished string", TK_EOS);
- continue; /* to avoid warnings */
- case '\n':
- case '\r':
- luaX_lexerror(ls, "unfinished string", TK_STRING);
- continue; /* to avoid warnings */
- case '\\': {
- int c;
- next(ls); /* do not save the `\' */
- switch (ls->current) {
- case 'a': c = '\a'; break;
- case 'b': c = '\b'; break;
- case 'f': c = '\f'; break;
- case 'n': c = '\n'; break;
- case 'r': c = '\r'; break;
- case 't': c = '\t'; break;
- case 'v': c = '\v'; break;
- case '\n': /* go through */
- case '\r': save(ls, '\n'); inclinenumber(ls); continue;
- case EOZ: continue; /* will raise an error next loop */
- default: {
- if (!isdigit(ls->current))
- save_and_next(ls); /* handles \\, \", \', and \? */
- else { /* \xxx */
- int i = 0;
- c = 0;
- do {
- c = 10*c + (ls->current-'0');
- next(ls);
- } while (++i<3 && isdigit(ls->current));
- if (c > UCHAR_MAX)
- luaX_lexerror(ls, "escape sequence too large", TK_STRING);
- save(ls, c);
- }
- continue;
- }
- }
- save(ls, c);
- next(ls);
- continue;
- }
- default:
- save_and_next(ls);
- }
- }
- save_and_next(ls); /* skip delimiter */
- seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
- luaZ_bufflen(ls->buff) - 2);
-}
-
-
-static int llex (LexState *ls, SemInfo *seminfo) {
- luaZ_resetbuffer(ls->buff);
- for (;;) {
- switch (ls->current) {
- case '\n':
- case '\r': {
- inclinenumber(ls);
- continue;
- }
- case '-': {
- next(ls);
- if (ls->current != '-') return '-';
- /* else is a comment */
- next(ls);
- if (ls->current == '[') {
- int sep = skip_sep(ls);
- luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
- if (sep >= 0) {
- read_long_string(ls, NULL, sep); /* long comment */
- luaZ_resetbuffer(ls->buff);
- continue;
- }
- }
- /* else short comment */
- while (!currIsNewline(ls) && ls->current != EOZ)
- next(ls);
- continue;
- }
- case '[': {
- int sep = skip_sep(ls);
- if (sep >= 0) {
- read_long_string(ls, seminfo, sep);
- return TK_STRING;
- }
- else if (sep == -1) return '[';
- else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
- }
- case '=': {
- next(ls);
- if (ls->current != '=') return '=';
- else { next(ls); return TK_EQ; }
- }
- case '<': {
- next(ls);
- if (ls->current != '=') return '<';
- else { next(ls); return TK_LE; }
- }
- case '>': {
- next(ls);
- if (ls->current != '=') return '>';
- else { next(ls); return TK_GE; }
- }
- case '~': {
- next(ls);
- if (ls->current != '=') return '~';
- else { next(ls); return TK_NE; }
- }
- case '"':
- case '\'': {
- read_string(ls, ls->current, seminfo);
- return TK_STRING;
- }
- case '.': {
- save_and_next(ls);
- if (check_next(ls, ".")) {
- if (check_next(ls, "."))
- return TK_DOTS; /* ... */
- else return TK_CONCAT; /* .. */
- }
- else if (!isdigit(ls->current)) return '.';
- else {
- read_numeral(ls, seminfo);
- return TK_NUMBER;
- }
- }
- case EOZ: {
- return TK_EOS;
- }
- default: {
- if (isspace(ls->current)) {
- lua_assert(!currIsNewline(ls));
- next(ls);
- continue;
- }
- else if (isdigit(ls->current)) {
- read_numeral(ls, seminfo);
- return TK_NUMBER;
- }
- else if (isalpha(ls->current) || ls->current == '_') {
- /* identifier or reserved word */
- TString *ts;
- do {
- save_and_next(ls);
- } while (isalnum(ls->current) || ls->current == '_');
- ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
- luaZ_bufflen(ls->buff));
- if (ts->tsv.reserved > 0) /* reserved word? */
- return ts->tsv.reserved - 1 + FIRST_RESERVED;
- else {
- seminfo->ts = ts;
- return TK_NAME;
- }
- }
- else {
- int c = ls->current;
- next(ls);
- return c; /* single-char tokens (+ - / ...) */
- }
- }
- }
- }
-}
-
-
-void luaX_next (LexState *ls) {
- ls->lastline = ls->linenumber;
- if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
- ls->t = ls->lookahead; /* use this one */
- ls->lookahead.token = TK_EOS; /* and discharge it */
- }
- else
- ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
-}
-
-
-void luaX_lookahead (LexState *ls) {
- lua_assert(ls->lookahead.token == TK_EOS);
- ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
-}
-
diff --git a/lib/lua/llex.h b/lib/lua/llex.h
deleted file mode 100644
index a9201ce..0000000
--- a/lib/lua/llex.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
-** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lexical Analyzer
-** See Copyright Notice in lua.h
-*/
-
-#ifndef llex_h
-#define llex_h
-
-#include "lobject.h"
-#include "lzio.h"
-
-
-#define FIRST_RESERVED 257
-
-/* maximum length of a reserved word */
-#define TOKEN_LEN (sizeof("function")/sizeof(char))
-
-
-/*
-* WARNING: if you change the order of this enumeration,
-* grep "ORDER RESERVED"
-*/
-enum RESERVED {
- /* terminal symbols denoted by reserved words */
- TK_AND = FIRST_RESERVED, TK_BREAK,
- TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
- TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
- TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
- /* other terminal symbols */
- TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
- TK_NAME, TK_STRING, TK_EOS
-};
-
-/* number of reserved words */
-#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
-
-
-/* array with token `names' */
-LUAI_DATA const char *const luaX_tokens [];
-
-
-typedef union {
- lua_Number r;
- TString *ts;
-} SemInfo; /* semantics information */
-
-
-typedef struct Token {
- int token;
- SemInfo seminfo;
-} Token;
-
-
-typedef struct LexState {
- int current; /* current character (charint) */
- int linenumber; /* input line counter */
- int lastline; /* line of last token `consumed' */
- Token t; /* current token */
- Token lookahead; /* look ahead token */
- struct FuncState *fs; /* `FuncState' is private to the parser */
- struct lua_State *L;
- ZIO *z; /* input stream */
- Mbuffer *buff; /* buffer for tokens */
- TString *source; /* current source name */
- char decpoint; /* locale decimal point */
-} LexState;
-
-
-LUAI_FUNC void luaX_init (lua_State *L);
-LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
- TString *source);
-LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
-LUAI_FUNC void luaX_next (LexState *ls);
-LUAI_FUNC void luaX_lookahead (LexState *ls);
-LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
-LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
-LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
-
-
-#endif
diff --git a/lib/lua/llimits.h b/lib/lua/llimits.h
deleted file mode 100644
index ca8dcb7..0000000
--- a/lib/lua/llimits.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
-** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
-** Limits, basic types, and some other `installation-dependent' definitions
-** See Copyright Notice in lua.h
-*/
-
-#ifndef llimits_h
-#define llimits_h
-
-
-#include
-#include
-
-
-#include "lua.h"
-
-
-typedef LUAI_UINT32 lu_int32;
-
-typedef LUAI_UMEM lu_mem;
-
-typedef LUAI_MEM l_mem;
-
-
-
-/* chars used as small naturals (so that `char' is reserved for characters) */
-typedef unsigned char lu_byte;
-
-
-#define MAX_SIZET ((size_t)(~(size_t)0)-2)
-
-#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
-
-
-#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
-
-/*
-** conversion of pointer to integer
-** this is for hashing only; there is no problem if the integer
-** cannot hold the whole pointer value
-*/
-#define IntPoint(p) ((unsigned int)(lu_mem)(p))
-
-
-
-/* type to ensure maximum alignment */
-typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
-
-
-/* result of a `usual argument conversion' over lua_Number */
-typedef LUAI_UACNUMBER l_uacNumber;
-
-
-/* internal assertions for in-house debugging */
-#ifdef lua_assert
-
-#define check_exp(c,e) (lua_assert(c), (e))
-#define api_check(l,e) lua_assert(e)
-
-#else
-
-#define lua_assert(c) ((void)0)
-#define check_exp(c,e) (e)
-#define api_check luai_apicheck
-
-#endif
-
-
-#ifndef UNUSED
-#define UNUSED(x) ((void)(x)) /* to avoid warnings */
-#endif
-
-
-#ifndef cast
-#define cast(t, exp) ((t)(exp))
-#endif
-
-#define cast_byte(i) cast(lu_byte, (i))
-#define cast_num(i) cast(lua_Number, (i))
-#define cast_int(i) cast(int, (i))
-
-
-
-/*
-** type for virtual-machine instructions
-** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
-*/
-typedef lu_int32 Instruction;
-
-
-
-/* maximum stack for a Lua function */
-#define MAXSTACK 250
-
-
-
-/* minimum size for the string table (must be power of 2) */
-#ifndef MINSTRTABSIZE
-#define MINSTRTABSIZE 32
-#endif
-
-
-/* minimum size for string buffer */
-#ifndef LUA_MINBUFFER
-#define LUA_MINBUFFER 32
-#endif
-
-
-#ifndef lua_lock
-#define lua_lock(L) ((void) 0)
-#define lua_unlock(L) ((void) 0)
-#endif
-
-#ifndef luai_threadyield
-#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
-#endif
-
-
-/*
-** macro to control inclusion of some hard tests on stack reallocation
-*/
-#ifndef HARDSTACKTESTS
-#define condhardstacktests(x) ((void)0)
-#else
-#define condhardstacktests(x) x
-#endif
-
-#endif
diff --git a/lib/lua/lmathlib.c b/lib/lua/lmathlib.c
deleted file mode 100644
index 441fbf7..0000000
--- a/lib/lua/lmathlib.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
-** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
-** Standard mathematical library
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-
-#define lmathlib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-#undef PI
-#define PI (3.14159265358979323846)
-#define RADIANS_PER_DEGREE (PI/180.0)
-
-
-
-static int math_abs (lua_State *L) {
- lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_sin (lua_State *L) {
- lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_sinh (lua_State *L) {
- lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_cos (lua_State *L) {
- lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_cosh (lua_State *L) {
- lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_tan (lua_State *L) {
- lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_tanh (lua_State *L) {
- lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_asin (lua_State *L) {
- lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_acos (lua_State *L) {
- lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_atan (lua_State *L) {
- lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_atan2 (lua_State *L) {
- lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
- return 1;
-}
-
-static int math_ceil (lua_State *L) {
- lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_floor (lua_State *L) {
- lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_fmod (lua_State *L) {
- lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
- return 1;
-}
-
-static int math_modf (lua_State *L) {
- double ip;
- double fp = modf(luaL_checknumber(L, 1), &ip);
- lua_pushnumber(L, ip);
- lua_pushnumber(L, fp);
- return 2;
-}
-
-static int math_sqrt (lua_State *L) {
- lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_pow (lua_State *L) {
- lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
- return 1;
-}
-
-static int math_log (lua_State *L) {
- lua_pushnumber(L, log(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_log10 (lua_State *L) {
- lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_exp (lua_State *L) {
- lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
- return 1;
-}
-
-static int math_deg (lua_State *L) {
- lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
- return 1;
-}
-
-static int math_rad (lua_State *L) {
- lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
- return 1;
-}
-
-static int math_frexp (lua_State *L) {
- int e;
- lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
- lua_pushinteger(L, e);
- return 2;
-}
-
-static int math_ldexp (lua_State *L) {
- lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
- return 1;
-}
-
-
-
-static int math_min (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- lua_Number dmin = luaL_checknumber(L, 1);
- int i;
- for (i=2; i<=n; i++) {
- lua_Number d = luaL_checknumber(L, i);
- if (d < dmin)
- dmin = d;
- }
- lua_pushnumber(L, dmin);
- return 1;
-}
-
-
-static int math_max (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- lua_Number dmax = luaL_checknumber(L, 1);
- int i;
- for (i=2; i<=n; i++) {
- lua_Number d = luaL_checknumber(L, i);
- if (d > dmax)
- dmax = d;
- }
- lua_pushnumber(L, dmax);
- return 1;
-}
-
-
-static int math_random (lua_State *L) {
- /* the `%' avoids the (rare) case of r==1, and is needed also because on
- some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
- lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
- switch (lua_gettop(L)) { /* check number of arguments */
- case 0: { /* no arguments */
- lua_pushnumber(L, r); /* Number between 0 and 1 */
- break;
- }
- case 1: { /* only upper limit */
- int u = luaL_checkint(L, 1);
- luaL_argcheck(L, 1<=u, 1, "interval is empty");
- lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
- break;
- }
- case 2: { /* lower and upper limits */
- int l = luaL_checkint(L, 1);
- int u = luaL_checkint(L, 2);
- luaL_argcheck(L, l<=u, 2, "interval is empty");
- lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
- break;
- }
- default: return luaL_error(L, "wrong number of arguments");
- }
- return 1;
-}
-
-
-static int math_randomseed (lua_State *L) {
- srand(luaL_checkint(L, 1));
- return 0;
-}
-
-
-static const luaL_Reg mathlib[] = {
- {"abs", math_abs},
- {"acos", math_acos},
- {"asin", math_asin},
- {"atan2", math_atan2},
- {"atan", math_atan},
- {"ceil", math_ceil},
- {"cosh", math_cosh},
- {"cos", math_cos},
- {"deg", math_deg},
- {"exp", math_exp},
- {"floor", math_floor},
- {"fmod", math_fmod},
- {"frexp", math_frexp},
- {"ldexp", math_ldexp},
- {"log10", math_log10},
- {"log", math_log},
- {"max", math_max},
- {"min", math_min},
- {"modf", math_modf},
- {"pow", math_pow},
- {"rad", math_rad},
- {"random", math_random},
- {"randomseed", math_randomseed},
- {"sinh", math_sinh},
- {"sin", math_sin},
- {"sqrt", math_sqrt},
- {"tanh", math_tanh},
- {"tan", math_tan},
- {NULL, NULL}
-};
-
-
-/*
-** Open math library
-*/
-LUALIB_API int luaopen_math (lua_State *L) {
- luaL_register(L, LUA_MATHLIBNAME, mathlib);
- lua_pushnumber(L, PI);
- lua_setfield(L, -2, "pi");
- lua_pushnumber(L, HUGE_VAL);
- lua_setfield(L, -2, "huge");
-#if defined(LUA_COMPAT_MOD)
- lua_getfield(L, -1, "fmod");
- lua_setfield(L, -2, "mod");
-#endif
- return 1;
-}
-
diff --git a/lib/lua/lmem.c b/lib/lua/lmem.c
deleted file mode 100644
index ae7d8c9..0000000
--- a/lib/lua/lmem.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
-** Interface to Memory Manager
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lmem_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-
-
-
-/*
-** About the realloc function:
-** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
-** (`osize' is the old size, `nsize' is the new size)
-**
-** Lua ensures that (ptr == NULL) iff (osize == 0).
-**
-** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
-**
-** * frealloc(ud, p, x, 0) frees the block `p'
-** (in this specific case, frealloc must return NULL).
-** particularly, frealloc(ud, NULL, 0, 0) does nothing
-** (which is equivalent to free(NULL) in ANSI C)
-**
-** frealloc returns NULL if it cannot create or reallocate the area
-** (any reallocation to an equal or smaller size cannot fail!)
-*/
-
-
-
-#define MINSIZEARRAY 4
-
-
-void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
- int limit, const char *errormsg) {
- void *newblock;
- int newsize;
- if (*size >= limit/2) { /* cannot double it? */
- if (*size >= limit) /* cannot grow even a little? */
- luaG_runerror(L, errormsg);
- newsize = limit; /* still have at least one free place */
- }
- else {
- newsize = (*size)*2;
- if (newsize < MINSIZEARRAY)
- newsize = MINSIZEARRAY; /* minimum size */
- }
- newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
- *size = newsize; /* update only when everything else is OK */
- return newblock;
-}
-
-
-void *luaM_toobig (lua_State *L) {
- luaG_runerror(L, "memory allocation error: block too big");
- return NULL; /* to avoid warnings */
-}
-
-
-
-/*
-** generic allocation routine.
-*/
-void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
- global_State *g = G(L);
- lua_assert((osize == 0) == (block == NULL));
- block = (*g->frealloc)(g->ud, block, osize, nsize);
- if (block == NULL && nsize > 0)
- luaD_throw(L, LUA_ERRMEM);
- lua_assert((nsize == 0) == (block == NULL));
- g->totalbytes = (g->totalbytes - osize) + nsize;
- return block;
-}
-
diff --git a/lib/lua/lmem.h b/lib/lua/lmem.h
deleted file mode 100644
index 7c2dcb3..0000000
--- a/lib/lua/lmem.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
-** Interface to Memory Manager
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lmem_h
-#define lmem_h
-
-
-#include
-
-#include "llimits.h"
-#include "lua.h"
-
-#define MEMERRMSG "not enough memory"
-
-
-#define luaM_reallocv(L,b,on,n,e) \
- ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
- luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
- luaM_toobig(L))
-
-#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
-#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
-#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
-
-#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
-#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
-#define luaM_newvector(L,n,t) \
- cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
-
-#define luaM_growvector(L,v,nelems,size,t,limit,e) \
- if ((nelems)+1 > (size)) \
- ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
-
-#define luaM_reallocvector(L, v,oldn,n,t) \
- ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
-
-
-LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
- size_t size);
-LUAI_FUNC void *luaM_toobig (lua_State *L);
-LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
- size_t size_elem, int limit,
- const char *errormsg);
-
-#endif
-
diff --git a/lib/lua/loadlib.c b/lib/lua/loadlib.c
deleted file mode 100644
index 0d401eb..0000000
--- a/lib/lua/loadlib.c
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
-** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $
-** Dynamic library loader for Lua
-** See Copyright Notice in lua.h
-**
-** This module contains an implementation of loadlib for Unix systems
-** that have dlfcn, an implementation for Darwin (Mac OS X), an
-** implementation for Windows, and a stub for other systems.
-*/
-
-
-#include
-#include
-
-
-#define loadlib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-/* prefix for open functions in C libraries */
-#define LUA_POF "luaopen_"
-
-/* separator for open functions in C libraries */
-#define LUA_OFSEP "_"
-
-
-#define LIBPREFIX "LOADLIB: "
-
-#define POF LUA_POF
-#define LIB_FAIL "open"
-
-
-/* error codes for ll_loadfunc */
-#define ERRLIB 1
-#define ERRFUNC 2
-
-#define setprogdir(L) ((void)0)
-
-
-static void ll_unloadlib (void *lib);
-static void *ll_load (lua_State *L, const char *path);
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
-
-
-
-#if defined(LUA_DL_DLOPEN)
-/*
-** {========================================================================
-** This is an implementation of loadlib based on the dlfcn interface.
-** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
-** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
-** as an emulation layer on top of native functions.
-** =========================================================================
-*/
-
-#include
-
-static void ll_unloadlib (void *lib) {
- dlclose(lib);
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- void *lib = dlopen(path, RTLD_NOW);
- if (lib == NULL) lua_pushstring(L, dlerror());
- return lib;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
- if (f == NULL) lua_pushstring(L, dlerror());
- return f;
-}
-
-/* }====================================================== */
-
-
-
-#elif defined(LUA_DL_DLL)
-/*
-** {======================================================================
-** This is an implementation of loadlib for Windows using native functions.
-** =======================================================================
-*/
-
-#include
-
-
-#undef setprogdir
-
-static void setprogdir (lua_State *L) {
- char buff[MAX_PATH + 1];
- char *lb;
- DWORD nsize = sizeof(buff)/sizeof(char);
- DWORD n = GetModuleFileNameA(NULL, buff, nsize);
- if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
- luaL_error(L, "unable to get ModuleFileName");
- else {
- *lb = '\0';
- luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
- lua_remove(L, -2); /* remove original string */
- }
-}
-
-
-static void pusherror (lua_State *L) {
- int error = GetLastError();
- char buffer[128];
- if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, error, 0, buffer, sizeof(buffer), NULL))
- lua_pushstring(L, buffer);
- else
- lua_pushfstring(L, "system error %d\n", error);
-}
-
-static void ll_unloadlib (void *lib) {
- FreeLibrary((HINSTANCE)lib);
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- HINSTANCE lib = LoadLibraryA(path);
- if (lib == NULL) pusherror(L);
- return lib;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
- if (f == NULL) pusherror(L);
- return f;
-}
-
-/* }====================================================== */
-
-
-
-#elif defined(LUA_DL_DYLD)
-/*
-** {======================================================================
-** Native Mac OS X / Darwin Implementation
-** =======================================================================
-*/
-
-#include
-
-
-/* Mac appends a `_' before C function names */
-#undef POF
-#define POF "_" LUA_POF
-
-
-static void pusherror (lua_State *L) {
- const char *err_str;
- const char *err_file;
- NSLinkEditErrors err;
- int err_num;
- NSLinkEditError(&err, &err_num, &err_file, &err_str);
- lua_pushstring(L, err_str);
-}
-
-
-static const char *errorfromcode (NSObjectFileImageReturnCode ret) {
- switch (ret) {
- case NSObjectFileImageInappropriateFile:
- return "file is not a bundle";
- case NSObjectFileImageArch:
- return "library is for wrong CPU type";
- case NSObjectFileImageFormat:
- return "bad format";
- case NSObjectFileImageAccess:
- return "cannot access file";
- case NSObjectFileImageFailure:
- default:
- return "unable to load library";
- }
-}
-
-
-static void ll_unloadlib (void *lib) {
- NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- NSObjectFileImage img;
- NSObjectFileImageReturnCode ret;
- /* this would be a rare case, but prevents crashing if it happens */
- if(!_dyld_present()) {
- lua_pushliteral(L, "dyld not present");
- return NULL;
- }
- ret = NSCreateObjectFileImageFromFile(path, &img);
- if (ret == NSObjectFileImageSuccess) {
- NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE |
- NSLINKMODULE_OPTION_RETURN_ON_ERROR);
- NSDestroyObjectFileImage(img);
- if (mod == NULL) pusherror(L);
- return mod;
- }
- lua_pushstring(L, errorfromcode(ret));
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);
- if (nss == NULL) {
- lua_pushfstring(L, "symbol " LUA_QS " not found", sym);
- return NULL;
- }
- return (lua_CFunction)NSAddressOfSymbol(nss);
-}
-
-/* }====================================================== */
-
-
-
-#else
-/*
-** {======================================================
-** Fallback for other systems
-** =======================================================
-*/
-
-#undef LIB_FAIL
-#define LIB_FAIL "absent"
-
-
-#define DLMSG "dynamic libraries not enabled; check your Lua installation"
-
-
-static void ll_unloadlib (void *lib) {
- (void)lib; /* to avoid warnings */
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- (void)path; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- (void)lib; (void)sym; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
-/* }====================================================== */
-#endif
-
-
-
-static void **ll_register (lua_State *L, const char *path) {
- void **plib;
- lua_pushfstring(L, "%s%s", LIBPREFIX, path);
- lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
- if (!lua_isnil(L, -1)) /* is there an entry? */
- plib = (void **)lua_touserdata(L, -1);
- else { /* no entry yet; create one */
- lua_pop(L, 1);
- plib = (void **)lua_newuserdata(L, sizeof(const void *));
- *plib = NULL;
- luaL_getmetatable(L, "_LOADLIB");
- lua_setmetatable(L, -2);
- lua_pushfstring(L, "%s%s", LIBPREFIX, path);
- lua_pushvalue(L, -2);
- lua_settable(L, LUA_REGISTRYINDEX);
- }
- return plib;
-}
-
-
-/*
-** __gc tag method: calls library's `ll_unloadlib' function with the lib
-** handle
-*/
-static int gctm (lua_State *L) {
- void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
- if (*lib) ll_unloadlib(*lib);
- *lib = NULL; /* mark library as closed */
- return 0;
-}
-
-
-static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
- void **reg = ll_register(L, path);
- if (*reg == NULL) *reg = ll_load(L, path);
- if (*reg == NULL)
- return ERRLIB; /* unable to load library */
- else {
- lua_CFunction f = ll_sym(L, *reg, sym);
- if (f == NULL)
- return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f);
- return 0; /* return function */
- }
-}
-
-
-static int ll_loadlib (lua_State *L) {
- const char *path = luaL_checkstring(L, 1);
- const char *init = luaL_checkstring(L, 2);
- int stat = ll_loadfunc(L, path, init);
- if (stat == 0) /* no errors? */
- return 1; /* return the loaded function */
- else { /* error; error message is on stack top */
- lua_pushnil(L);
- lua_insert(L, -2);
- lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init");
- return 3; /* return nil, error message, and where */
- }
-}
-
-
-
-/*
-** {======================================================
-** 'require' function
-** =======================================================
-*/
-
-
-static int readable (const char *filename) {
- FILE *f = fopen(filename, "r"); /* try to open file */
- if (f == NULL) return 0; /* open failed */
- fclose(f);
- return 1;
-}
-
-
-static const char *pushnexttemplate (lua_State *L, const char *path) {
- const char *l;
- while (*path == *LUA_PATHSEP) path++; /* skip separators */
- if (*path == '\0') return NULL; /* no more templates */
- l = strchr(path, *LUA_PATHSEP); /* find next separator */
- if (l == NULL) l = path + strlen(path);
- lua_pushlstring(L, path, l - path); /* template */
- return l;
-}
-
-
-static const char *findfile (lua_State *L, const char *name,
- const char *pname) {
- const char *path;
- name = luaL_gsub(L, name, ".", LUA_DIRSEP);
- lua_getfield(L, LUA_ENVIRONINDEX, pname);
- path = lua_tostring(L, -1);
- if (path == NULL)
- luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
- lua_pushliteral(L, ""); /* error accumulator */
- while ((path = pushnexttemplate(L, path)) != NULL) {
- const char *filename;
- filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
- lua_remove(L, -2); /* remove path template */
- if (readable(filename)) /* does file exist and is readable? */
- return filename; /* return that file name */
- lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
- lua_remove(L, -2); /* remove file name */
- lua_concat(L, 2); /* add entry to possible error message */
- }
- return NULL; /* not found */
-}
-
-
-static void loaderror (lua_State *L, const char *filename) {
- luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
- lua_tostring(L, 1), filename, lua_tostring(L, -1));
-}
-
-
-static int loader_Lua (lua_State *L) {
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- filename = findfile(L, name, "path");
- if (filename == NULL) return 1; /* library not found in this path */
- if (luaL_loadfile(L, filename) != 0)
- loaderror(L, filename);
- return 1; /* library loaded successfully */
-}
-
-
-static const char *mkfuncname (lua_State *L, const char *modname) {
- const char *funcname;
- const char *mark = strchr(modname, *LUA_IGMARK);
- if (mark) modname = mark + 1;
- funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
- funcname = lua_pushfstring(L, POF"%s", funcname);
- lua_remove(L, -2); /* remove 'gsub' result */
- return funcname;
-}
-
-
-static int loader_C (lua_State *L) {
- const char *funcname;
- const char *name = luaL_checkstring(L, 1);
- const char *filename = findfile(L, name, "cpath");
- if (filename == NULL) return 1; /* library not found in this path */
- funcname = mkfuncname(L, name);
- if (ll_loadfunc(L, filename, funcname) != 0)
- loaderror(L, filename);
- return 1; /* library loaded successfully */
-}
-
-
-static int loader_Croot (lua_State *L) {
- const char *funcname;
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- const char *p = strchr(name, '.');
- int stat;
- if (p == NULL) return 0; /* is root */
- lua_pushlstring(L, name, p - name);
- filename = findfile(L, lua_tostring(L, -1), "cpath");
- if (filename == NULL) return 1; /* root not found */
- funcname = mkfuncname(L, name);
- if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
- if (stat != ERRFUNC) loaderror(L, filename); /* real error */
- lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
- name, filename);
- return 1; /* function not found */
- }
- return 1;
-}
-
-
-static int loader_preload (lua_State *L) {
- const char *name = luaL_checkstring(L, 1);
- lua_getfield(L, LUA_ENVIRONINDEX, "preload");
- if (!lua_istable(L, -1))
- luaL_error(L, LUA_QL("package.preload") " must be a table");
- lua_getfield(L, -1, name);
- if (lua_isnil(L, -1)) /* not found? */
- lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
- return 1;
-}
-
-
-static const int sentinel_ = 0;
-#define sentinel ((void *)&sentinel_)
-
-
-static int ll_require (lua_State *L) {
- const char *name = luaL_checkstring(L, 1);
- int i;
- lua_settop(L, 1); /* _LOADED table will be at index 2 */
- lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_getfield(L, 2, name);
- if (lua_toboolean(L, -1)) { /* is it there? */
- if (lua_touserdata(L, -1) == sentinel) /* check loops */
- luaL_error(L, "loop or previous error loading module " LUA_QS, name);
- return 1; /* package is already loaded */
- }
- /* else must load it; iterate over available loaders */
- lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
- if (!lua_istable(L, -1))
- luaL_error(L, LUA_QL("package.loaders") " must be a table");
- lua_pushliteral(L, ""); /* error message accumulator */
- for (i=1; ; i++) {
- lua_rawgeti(L, -2, i); /* get a loader */
- if (lua_isnil(L, -1))
- luaL_error(L, "module " LUA_QS " not found:%s",
- name, lua_tostring(L, -2));
- lua_pushstring(L, name);
- lua_call(L, 1, 1); /* call it */
- if (lua_isfunction(L, -1)) /* did it find module? */
- break; /* module loaded successfully */
- else if (lua_isstring(L, -1)) /* loader returned error message? */
- lua_concat(L, 2); /* accumulate it */
- else
- lua_pop(L, 1);
- }
- lua_pushlightuserdata(L, sentinel);
- lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
- lua_pushstring(L, name); /* pass name as argument to module */
- lua_call(L, 1, 1); /* run loaded module */
- if (!lua_isnil(L, -1)) /* non-nil return? */
- lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
- lua_getfield(L, 2, name);
- if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
- lua_pushboolean(L, 1); /* use true as result */
- lua_pushvalue(L, -1); /* extra copy to be returned */
- lua_setfield(L, 2, name); /* _LOADED[name] = true */
- }
- return 1;
-}
-
-/* }====================================================== */
-
-
-
-/*
-** {======================================================
-** 'module' function
-** =======================================================
-*/
-
-
-static void setfenv (lua_State *L) {
- lua_Debug ar;
- if (lua_getstack(L, 1, &ar) == 0 ||
- lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
- lua_iscfunction(L, -1))
- luaL_error(L, LUA_QL("module") " not called from a Lua function");
- lua_pushvalue(L, -2);
- lua_setfenv(L, -2);
- lua_pop(L, 1);
-}
-
-
-static void dooptions (lua_State *L, int n) {
- int i;
- for (i = 2; i <= n; i++) {
- lua_pushvalue(L, i); /* get option (a function) */
- lua_pushvalue(L, -2); /* module */
- lua_call(L, 1, 0);
- }
-}
-
-
-static void modinit (lua_State *L, const char *modname) {
- const char *dot;
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "_M"); /* module._M = module */
- lua_pushstring(L, modname);
- lua_setfield(L, -2, "_NAME");
- dot = strrchr(modname, '.'); /* look for last dot in module name */
- if (dot == NULL) dot = modname;
- else dot++;
- /* set _PACKAGE as package name (full module name minus last part) */
- lua_pushlstring(L, modname, dot - modname);
- lua_setfield(L, -2, "_PACKAGE");
-}
-
-
-static int ll_module (lua_State *L) {
- const char *modname = luaL_checkstring(L, 1);
- int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
- lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
- if (!lua_istable(L, -1)) { /* not found? */
- lua_pop(L, 1); /* remove previous result */
- /* try global variable (and create one if it does not exist) */
- if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
- return luaL_error(L, "name conflict for module " LUA_QS, modname);
- lua_pushvalue(L, -1);
- lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
- }
- /* check whether table already has a _NAME field */
- lua_getfield(L, -1, "_NAME");
- if (!lua_isnil(L, -1)) /* is table an initialized module? */
- lua_pop(L, 1);
- else { /* no; initialize it */
- lua_pop(L, 1);
- modinit(L, modname);
- }
- lua_pushvalue(L, -1);
- setfenv(L);
- dooptions(L, loaded - 1);
- return 0;
-}
-
-
-static int ll_seeall (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- if (!lua_getmetatable(L, 1)) {
- lua_createtable(L, 0, 1); /* create new metatable */
- lua_pushvalue(L, -1);
- lua_setmetatable(L, 1);
- }
- lua_pushvalue(L, LUA_GLOBALSINDEX);
- lua_setfield(L, -2, "__index"); /* mt.__index = _G */
- return 0;
-}
-
-
-/* }====================================================== */
-
-
-
-/* auxiliary mark (for internal use) */
-#define AUXMARK "\1"
-
-static void setpath (lua_State *L, const char *fieldname, const char *envname,
- const char *def) {
- const char *path = getenv(envname);
- if (path == NULL) /* no environment variable? */
- lua_pushstring(L, def); /* use default */
- else {
- /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
- path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
- LUA_PATHSEP AUXMARK LUA_PATHSEP);
- luaL_gsub(L, path, AUXMARK, def);
- lua_remove(L, -2);
- }
- setprogdir(L);
- lua_setfield(L, -2, fieldname);
-}
-
-
-static const luaL_Reg pk_funcs[] = {
- {"loadlib", ll_loadlib},
- {"seeall", ll_seeall},
- {NULL, NULL}
-};
-
-
-static const luaL_Reg ll_funcs[] = {
- {"module", ll_module},
- {"require", ll_require},
- {NULL, NULL}
-};
-
-
-static const lua_CFunction loaders[] =
- {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
-
-
-LUALIB_API int luaopen_package (lua_State *L) {
- int i;
- /* create new type _LOADLIB */
- luaL_newmetatable(L, "_LOADLIB");
- lua_pushcfunction(L, gctm);
- lua_setfield(L, -2, "__gc");
- /* create `package' table */
- luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
-#if defined(LUA_COMPAT_LOADLIB)
- lua_getfield(L, -1, "loadlib");
- lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
-#endif
- lua_pushvalue(L, -1);
- lua_replace(L, LUA_ENVIRONINDEX);
- /* create `loaders' table */
- lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
- /* fill it with pre-defined loaders */
- for (i=0; loaders[i] != NULL; i++) {
- lua_pushcfunction(L, loaders[i]);
- lua_rawseti(L, -2, i+1);
- }
- lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
- setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
- setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
- /* store config information */
- lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
- LUA_EXECDIR "\n" LUA_IGMARK);
- lua_setfield(L, -2, "config");
- /* set field `loaded' */
- luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
- lua_setfield(L, -2, "loaded");
- /* set field `preload' */
- lua_newtable(L);
- lua_setfield(L, -2, "preload");
- lua_pushvalue(L, LUA_GLOBALSINDEX);
- luaL_register(L, NULL, ll_funcs); /* open lib into global table */
- lua_pop(L, 1);
- return 1; /* return 'package' table */
-}
-
diff --git a/lib/lua/lobject.c b/lib/lua/lobject.c
deleted file mode 100644
index 4ff5073..0000000
--- a/lib/lua/lobject.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
-** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
-** Some generic functions over Lua objects
-** See Copyright Notice in lua.h
-*/
-
-#include
-#include
-#include
-#include
-#include
-
-#define lobject_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldo.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "lvm.h"
-
-
-
-const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
-
-
-/*
-** converts an integer to a "floating point byte", represented as
-** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
-** eeeee != 0 and (xxx) otherwise.
-*/
-int luaO_int2fb (unsigned int x) {
- int e = 0; /* expoent */
- while (x >= 16) {
- x = (x+1) >> 1;
- e++;
- }
- if (x < 8) return x;
- else return ((e+1) << 3) | (cast_int(x) - 8);
-}
-
-
-/* converts back */
-int luaO_fb2int (int x) {
- int e = (x >> 3) & 31;
- if (e == 0) return x;
- else return ((x & 7)+8) << (e - 1);
-}
-
-
-int luaO_log2 (unsigned int x) {
- static const lu_byte log_2[256] = {
- 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
- };
- int l = -1;
- while (x >= 256) { l += 8; x >>= 8; }
- return l + log_2[x];
-
-}
-
-
-int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
- if (ttype(t1) != ttype(t2)) return 0;
- else switch (ttype(t1)) {
- case LUA_TNIL:
- return 1;
- case LUA_TNUMBER:
- return luai_numeq(nvalue(t1), nvalue(t2));
- case LUA_TBOOLEAN:
- return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
- case LUA_TLIGHTUSERDATA:
- return pvalue(t1) == pvalue(t2);
- default:
- lua_assert(iscollectable(t1));
- return gcvalue(t1) == gcvalue(t2);
- }
-}
-
-
-int luaO_str2d (const char *s, lua_Number *result) {
- char *endptr;
- *result = lua_str2number(s, &endptr);
- if (endptr == s) return 0; /* conversion failed */
- if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
- *result = cast_num(strtoul(s, &endptr, 16));
- if (*endptr == '\0') return 1; /* most common case */
- while (isspace(cast(unsigned char, *endptr))) endptr++;
- if (*endptr != '\0') return 0; /* invalid trailing characters? */
- return 1;
-}
-
-
-
-static void pushstr (lua_State *L, const char *str) {
- setsvalue2s(L, L->top, luaS_new(L, str));
- incr_top(L);
-}
-
-
-/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
-const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
- int n = 1;
- pushstr(L, "");
- for (;;) {
- const char *e = strchr(fmt, '%');
- if (e == NULL) break;
- setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
- incr_top(L);
- switch (*(e+1)) {
- case 's': {
- const char *s = va_arg(argp, char *);
- if (s == NULL) s = "(null)";
- pushstr(L, s);
- break;
- }
- case 'c': {
- char buff[2];
- buff[0] = cast(char, va_arg(argp, int));
- buff[1] = '\0';
- pushstr(L, buff);
- break;
- }
- case 'd': {
- setnvalue(L->top, cast_num(va_arg(argp, int)));
- incr_top(L);
- break;
- }
- case 'f': {
- setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
- incr_top(L);
- break;
- }
- case 'p': {
- char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
- sprintf(buff, "%p", va_arg(argp, void *));
- pushstr(L, buff);
- break;
- }
- case '%': {
- pushstr(L, "%");
- break;
- }
- default: {
- char buff[3];
- buff[0] = '%';
- buff[1] = *(e+1);
- buff[2] = '\0';
- pushstr(L, buff);
- break;
- }
- }
- n += 2;
- fmt = e+2;
- }
- pushstr(L, fmt);
- luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
- L->top -= n;
- return svalue(L->top - 1);
-}
-
-
-const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
- const char *msg;
- va_list argp;
- va_start(argp, fmt);
- msg = luaO_pushvfstring(L, fmt, argp);
- va_end(argp);
- return msg;
-}
-
-
-void luaO_chunkid (char *out, const char *source, size_t bufflen) {
- if (*source == '=') {
- strncpy(out, source+1, bufflen); /* remove first char */
- out[bufflen-1] = '\0'; /* ensures null termination */
- }
- else { /* out = "source", or "...source" */
- if (*source == '@') {
- size_t l;
- source++; /* skip the `@' */
- bufflen -= sizeof(" '...' ");
- l = strlen(source);
- strcpy(out, "");
- if (l > bufflen) {
- source += (l-bufflen); /* get last part of file name */
- strcat(out, "...");
- }
- strcat(out, source);
- }
- else { /* out = [string "string"] */
- size_t len = strcspn(source, "\n\r"); /* stop at first newline */
- bufflen -= sizeof(" [string \"...\"] ");
- if (len > bufflen) len = bufflen;
- strcpy(out, "[string \"");
- if (source[len] != '\0') { /* must truncate? */
- strncat(out, source, len);
- strcat(out, "...");
- }
- else
- strcat(out, source);
- strcat(out, "\"]");
- }
- }
-}
diff --git a/lib/lua/lobject.h b/lib/lua/lobject.h
deleted file mode 100644
index f1e447e..0000000
--- a/lib/lua/lobject.h
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
-** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $
-** Type definitions for Lua objects
-** See Copyright Notice in lua.h
-*/
-
-
-#ifndef lobject_h
-#define lobject_h
-
-
-#include
-
-
-#include "llimits.h"
-#include "lua.h"
-
-
-/* tags for values visible from Lua */
-#define LAST_TAG LUA_TTHREAD
-
-#define NUM_TAGS (LAST_TAG+1)
-
-
-/*
-** Extra tags for non-values
-*/
-#define LUA_TPROTO (LAST_TAG+1)
-#define LUA_TUPVAL (LAST_TAG+2)
-#define LUA_TDEADKEY (LAST_TAG+3)
-
-
-/*
-** Union of all collectable objects
-*/
-typedef union GCObject GCObject;
-
-
-/*
-** Common Header for all collectable objects (in macro form, to be
-** included in other objects)
-*/
-#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
-
-
-/*
-** Common header in struct form
-*/
-typedef struct GCheader {
- CommonHeader;
-} GCheader;
-
-
-
-
-/*
-** Union of all Lua values
-*/
-typedef union {
- GCObject *gc;
- void *p;
- lua_Number n;
- int b;
-} Value;
-
-
-/*
-** Tagged Values
-*/
-
-#define TValuefields Value value; int tt
-
-typedef struct lua_TValue {
- TValuefields;
-} TValue;
-
-
-/* Macros to test type */
-#define ttisnil(o) (ttype(o) == LUA_TNIL)
-#define ttisnumber(o) (ttype(o) == LUA_TNUMBER)
-#define ttisstring(o) (ttype(o) == LUA_TSTRING)
-#define ttistable(o) (ttype(o) == LUA_TTABLE)
-#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
-#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
-#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
-#define ttisthread(o) (ttype(o) == LUA_TTHREAD)
-#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
-
-/* Macros to access values */
-#define ttype(o) ((o)->tt)
-#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
-#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
-#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
-#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
-#define tsvalue(o) (&rawtsvalue(o)->tsv)
-#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
-#define uvalue(o) (&rawuvalue(o)->uv)
-#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
-#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
-#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
-#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th)
-
-#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
-
-/*
-** for internal debug only
-*/
-#define checkconsistency(obj) \
- lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
-
-#define checkliveness(g,obj) \
- lua_assert(!iscollectable(obj) || \
- ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))
-
-
-/* Macros to set values */
-#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
-
-#define setnvalue(obj,x) \
- { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
-
-#define setpvalue(obj,x) \
- { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
-
-#define setbvalue(obj,x) \
- { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
-
-#define setsvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
- checkliveness(G(L),i_o); }
-
-#define setuvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
- checkliveness(G(L),i_o); }
-
-#define setthvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
- checkliveness(G(L),i_o); }
-
-#define setclvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
- checkliveness(G(L),i_o); }
-
-#define sethvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
- checkliveness(G(L),i_o); }
-
-#define setptvalue(L,obj,x) \
- { TValue *i_o=(obj); \
- i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
- checkliveness(G(L),i_o); }
-
-
-
-
-#define setobj(L,obj1,obj2) \
- { const TValue *o2=(obj2); TValue *o1=(obj1); \
- o1->value = o2->value; o1->tt=o2->tt; \
- checkliveness(G(L),o1); }
-
-
-/*
-** different types of sets, according to destination
-*/
-
-/* from stack to (same) stack */
-#define setobjs2s setobj
-/* to stack (not from same stack) */
-#define setobj2s setobj
-#define setsvalue2s setsvalue
-#define sethvalue2s sethvalue
-#define setptvalue2s setptvalue
-/* from table to same table */
-#define setobjt2t setobj
-/* to table */
-#define setobj2t setobj
-/* to new object */
-#define setobj2n setobj
-#define setsvalue2n setsvalue
-
-#define setttype(obj, tt) (ttype(obj) = (tt))
-
-
-#define iscollectable(o) (ttype(o) >= LUA_TSTRING)
-
-
-
-typedef TValue *StkId; /* index to stack elements */
-
-
-/*
-** String headers for string table
-*/
-typedef union TString {
- L_Umaxalign dummy; /* ensures maximum alignment for strings */
- struct {
- CommonHeader;
- lu_byte reserved;
- unsigned int hash;
- size_t len;
- } tsv;
-} TString;
-
-
-#define getstr(ts) cast(const char *, (ts) + 1)
-#define svalue(o) getstr(rawtsvalue(o))
-
-
-
-typedef union Udata {
- L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
- struct {
- CommonHeader;
- struct Table *metatable;
- struct Table *env;
- size_t len;
- } uv;
-} Udata;
-
-
-
-
-/*
-** Function Prototypes
-*/
-typedef struct Proto {
- CommonHeader;
- TValue *k; /* constants used by the function */
- Instruction *code;
- struct Proto **p; /* functions defined inside the function */
- int *lineinfo; /* map from opcodes to source lines */
- struct LocVar *locvars; /* information about local variables */
- TString **upvalues; /* upvalue names */
- TString *source;
- int sizeupvalues;
- int sizek; /* size of `k' */
- int sizecode;
- int sizelineinfo;
- int sizep; /* size of `p' */
- int sizelocvars;
- int linedefined;
- int lastlinedefined;
- GCObject *gclist;
- lu_byte nups; /* number of upvalues */
- lu_byte numparams;
- lu_byte is_vararg;
- lu_byte maxstacksize;
-} Proto;
-
-
-/* masks for new-style vararg */
-#define VARARG_HASARG 1
-#define VARARG_ISVARARG 2
-#define VARARG_NEEDSARG 4
-
-
-typedef struct LocVar {
- TString *varname;
- int startpc; /* first point where variable is active */
- int endpc; /* first point where variable is dead */
-} LocVar;
-
-
-
-/*
-** Upvalues
-*/
-
-typedef struct UpVal {
- CommonHeader;
- TValue *v; /* points to stack or to its own value */
- union {
- TValue value; /* the value (when closed) */
- struct { /* double linked list (when open) */
- struct UpVal *prev;
- struct UpVal *next;
- } l;
- } u;
-} UpVal;
-
-
-/*
-** Closures
-*/
-
-#define ClosureHeader \
- CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
- struct Table *env
-
-typedef struct CClosure {
- ClosureHeader;
- lua_CFunction f;
- TValue upvalue[1];
-} CClosure;
-
-
-typedef struct LClosure {
- ClosureHeader;
- struct Proto *p;
- UpVal *upvals[1];
-} LClosure;
-
-
-typedef union Closure {
- CClosure c;
- LClosure l;
-} Closure;
-
-
-#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
-#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
-
-
-/*
-** Tables
-*/
-
-typedef union TKey {
- struct {
- TValuefields;
- struct Node *next; /* for chaining */
- } nk;
- TValue tvk;
-} TKey;
-
-
-typedef struct Node {
- TValue i_val;
- TKey i_key;
-} Node;
-
-
-typedef struct Table {
- CommonHeader;
- lu_byte flags; /* 1<lsizenode))
-
-
-#define luaO_nilobject (&luaO_nilobject_)
-
-LUAI_DATA const TValue luaO_nilobject_;
-
-#define ceillog2(x) (luaO_log2((x)-1) + 1)
-
-LUAI_FUNC int luaO_log2 (unsigned int x);
-LUAI_FUNC int luaO_int2fb (unsigned int x);
-LUAI_FUNC int luaO_fb2int (int x);
-LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
-LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
-LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
- va_list argp);
-LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
-LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
-
-
-#endif
-
diff --git a/lib/lua/lopcodes.c b/lib/lua/lopcodes.c
deleted file mode 100644
index 4cc7452..0000000
--- a/lib/lua/lopcodes.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
-** See Copyright Notice in lua.h
-*/
-
-
-#define lopcodes_c
-#define LUA_CORE
-
-
-#include "lopcodes.h"
-
-
-/* ORDER OP */
-
-const char *const luaP_opnames[NUM_OPCODES+1] = {
- "MOVE",
- "LOADK",
- "LOADBOOL",
- "LOADNIL",
- "GETUPVAL",
- "GETGLOBAL",
- "GETTABLE",
- "SETGLOBAL",
- "SETUPVAL",
- "SETTABLE",
- "NEWTABLE",
- "SELF",
- "ADD",
- "SUB",
- "MUL",
- "DIV",
- "MOD",
- "POW",
- "UNM",
- "NOT",
- "LEN",
- "CONCAT",
- "JMP",
- "EQ",
- "LT",
- "LE",
- "TEST",
- "TESTSET",
- "CALL",
- "TAILCALL",
- "RETURN",
- "FORLOOP",
- "FORPREP",
- "TFORLOOP",
- "SETLIST",
- "CLOSE",
- "CLOSURE",
- "VARARG",
- NULL
-};
-
-
-#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
-
-const lu_byte luaP_opmodes[NUM_OPCODES] = {
-/* T A B C mode opcode */
- opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
- ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */
- ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
- ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */
- ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
- ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */
- ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
- ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
- ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
- ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
- ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
- ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */
- ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
- ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
- ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */
- ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
- ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
- ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
- ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
-};
-
diff --git a/lib/lua/lopcodes.h b/lib/lua/lopcodes.h
deleted file mode 100644
index 41224d6..0000000
--- a/lib/lua/lopcodes.h
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
-** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
-** Opcodes for Lua virtual machine
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lopcodes_h
-#define lopcodes_h
-
-#include "llimits.h"
-
-
-/*===========================================================================
- We assume that instructions are unsigned numbers.
- All instructions have an opcode in the first 6 bits.
- Instructions can have the following fields:
- `A' : 8 bits
- `B' : 9 bits
- `C' : 9 bits
- `Bx' : 18 bits (`B' and `C' together)
- `sBx' : signed Bx
-
- A signed argument is represented in excess K; that is, the number
- value is the unsigned value minus K. K is exactly the maximum value
- for that argument (so that -max is represented by 0, and +max is
- represented by 2*max), which is half the maximum for the corresponding
- unsigned argument.
-===========================================================================*/
-
-
-enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
-
-
-/*
-** size and position of opcode arguments.
-*/
-#define SIZE_C 9
-#define SIZE_B 9
-#define SIZE_Bx (SIZE_C + SIZE_B)
-#define SIZE_A 8
-
-#define SIZE_OP 6
-
-#define POS_OP 0
-#define POS_A (POS_OP + SIZE_OP)
-#define POS_C (POS_A + SIZE_A)
-#define POS_B (POS_C + SIZE_C)
-#define POS_Bx POS_C
-
-
-/*
-** limits for opcode arguments.
-** we use (signed) int to manipulate most arguments,
-** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
-*/
-#if SIZE_Bx < LUAI_BITSINT-1
-#define MAXARG_Bx ((1<>1) /* `sBx' is signed */
-#else
-#define MAXARG_Bx MAX_INT
-#define MAXARG_sBx MAX_INT
-#endif
-
-
-#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0)))
-#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
- ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0)))
-#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
- ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0)))
-#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
- ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0)))
-#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
- ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0)))
-#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
- ((cast(Instruction, b)< C) then pc++ */
-OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
-
-OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
-OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
-OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
-
-OP_FORLOOP,/* A sBx R(A)+=R(A+2);
- if R(A) = R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
-OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
-
-OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
- if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */
-OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
-
-OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
-OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */
-
-OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
-} OpCode;
-
-
-#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
-
-
-
-/*===========================================================================
- Notes:
- (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
- and can be 0: OP_CALL then sets `top' to last_result+1, so
- next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
-
- (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
- set top (like in OP_CALL with C == 0).
-
- (*) In OP_RETURN, if (B == 0) then return up to `top'
-
- (*) In OP_SETLIST, if (B == 0) then B = `top';
- if (C == 0) then next `instruction' is real C
-
- (*) For comparisons, A specifies what condition the test should accept
- (true or false).
-
- (*) All `skips' (pc++) assume that next instruction is a jump
-===========================================================================*/
-
-
-/*
-** masks for instruction properties. The format is:
-** bits 0-1: op mode
-** bits 2-3: C arg mode
-** bits 4-5: B arg mode
-** bit 6: instruction set register A
-** bit 7: operator is a test
-*/
-
-enum OpArgMask {
- OpArgN, /* argument is not used */
- OpArgU, /* argument is used */
- OpArgR, /* argument is a register or a jump offset */
- OpArgK /* argument is a constant or register/constant */
-};
-
-LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
-
-#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
-#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
-#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
-#define testAMode(m) (luaP_opmodes[m] & (1 << 6))
-#define testTMode(m) (luaP_opmodes[m] & (1 << 7))
-
-
-LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
-
-
-/* number of list items to accumulate before a SETLIST instruction */
-#define LFIELDS_PER_FLUSH 50
-
-
-#endif
diff --git a/lib/lua/loslib.c b/lib/lua/loslib.c
deleted file mode 100644
index da06a57..0000000
--- a/lib/lua/loslib.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
-** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $
-** Standard Operating System library
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-#include
-
-#define loslib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-static int os_pushresult (lua_State *L, int i, const char *filename) {
- int en = errno; /* calls to Lua API may change this value */
- if (i) {
- lua_pushboolean(L, 1);
- return 1;
- }
- else {
- lua_pushnil(L);
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
-}
-
-
-static int os_execute (lua_State *L) {
- lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
- return 1;
-}
-
-
-static int os_remove (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- return os_pushresult(L, remove(filename) == 0, filename);
-}
-
-
-static int os_rename (lua_State *L) {
- const char *fromname = luaL_checkstring(L, 1);
- const char *toname = luaL_checkstring(L, 2);
- return os_pushresult(L, rename(fromname, toname) == 0, fromname);
-}
-
-
-static int os_tmpname (lua_State *L) {
- char buff[LUA_TMPNAMBUFSIZE];
- int err;
- lua_tmpnam(buff, err);
- if (err)
- return luaL_error(L, "unable to generate a unique filename");
- lua_pushstring(L, buff);
- return 1;
-}
-
-
-static int os_getenv (lua_State *L) {
- lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
- return 1;
-}
-
-
-static int os_clock (lua_State *L) {
- lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
- return 1;
-}
-
-
-/*
-** {======================================================
-** Time/Date operations
-** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
-** wday=%w+1, yday=%j, isdst=? }
-** =======================================================
-*/
-
-static void setfield (lua_State *L, const char *key, int value) {
- lua_pushinteger(L, value);
- lua_setfield(L, -2, key);
-}
-
-static void setboolfield (lua_State *L, const char *key, int value) {
- if (value < 0) /* undefined? */
- return; /* does not set field */
- lua_pushboolean(L, value);
- lua_setfield(L, -2, key);
-}
-
-static int getboolfield (lua_State *L, const char *key) {
- int res;
- lua_getfield(L, -1, key);
- res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
- lua_pop(L, 1);
- return res;
-}
-
-
-static int getfield (lua_State *L, const char *key, int d) {
- int res;
- lua_getfield(L, -1, key);
- if (lua_isnumber(L, -1))
- res = (int)lua_tointeger(L, -1);
- else {
- if (d < 0)
- return luaL_error(L, "field " LUA_QS " missing in date table", key);
- res = d;
- }
- lua_pop(L, 1);
- return res;
-}
-
-
-static int os_date (lua_State *L) {
- const char *s = luaL_optstring(L, 1, "%c");
- time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
- struct tm *stm;
- if (*s == '!') { /* UTC? */
- stm = gmtime(&t);
- s++; /* skip `!' */
- }
- else
- stm = localtime(&t);
- if (stm == NULL) /* invalid date? */
- lua_pushnil(L);
- else if (strcmp(s, "*t") == 0) {
- lua_createtable(L, 0, 9); /* 9 = number of fields */
- setfield(L, "sec", stm->tm_sec);
- setfield(L, "min", stm->tm_min);
- setfield(L, "hour", stm->tm_hour);
- setfield(L, "day", stm->tm_mday);
- setfield(L, "month", stm->tm_mon+1);
- setfield(L, "year", stm->tm_year+1900);
- setfield(L, "wday", stm->tm_wday+1);
- setfield(L, "yday", stm->tm_yday+1);
- setboolfield(L, "isdst", stm->tm_isdst);
- }
- else {
- char cc[3];
- luaL_Buffer b;
- cc[0] = '%'; cc[2] = '\0';
- luaL_buffinit(L, &b);
- for (; *s; s++) {
- if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
- luaL_addchar(&b, *s);
- else {
- size_t reslen;
- char buff[200]; /* should be big enough for any conversion result */
- cc[1] = *(++s);
- reslen = strftime(buff, sizeof(buff), cc, stm);
- luaL_addlstring(&b, buff, reslen);
- }
- }
- luaL_pushresult(&b);
- }
- return 1;
-}
-
-
-static int os_time (lua_State *L) {
- time_t t;
- if (lua_isnoneornil(L, 1)) /* called without args? */
- t = time(NULL); /* get current time */
- else {
- struct tm ts;
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_settop(L, 1); /* make sure table is at the top */
- ts.tm_sec = getfield(L, "sec", 0);
- ts.tm_min = getfield(L, "min", 0);
- ts.tm_hour = getfield(L, "hour", 12);
- ts.tm_mday = getfield(L, "day", -1);
- ts.tm_mon = getfield(L, "month", -1) - 1;
- ts.tm_year = getfield(L, "year", -1) - 1900;
- ts.tm_isdst = getboolfield(L, "isdst");
- t = mktime(&ts);
- }
- if (t == (time_t)(-1))
- lua_pushnil(L);
- else
- lua_pushnumber(L, (lua_Number)t);
- return 1;
-}
-
-
-static int os_difftime (lua_State *L) {
- lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
- (time_t)(luaL_optnumber(L, 2, 0))));
- return 1;
-}
-
-/* }====================================================== */
-
-
-static int os_setlocale (lua_State *L) {
- static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
- LC_NUMERIC, LC_TIME};
- static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
- "numeric", "time", NULL};
- const char *l = luaL_optstring(L, 1, NULL);
- int op = luaL_checkoption(L, 2, "all", catnames);
- lua_pushstring(L, setlocale(cat[op], l));
- return 1;
-}
-
-
-static int os_exit (lua_State *L) {
- exit(luaL_optint(L, 1, EXIT_SUCCESS));
-}
-
-static const luaL_Reg syslib[] = {
- {"clock", os_clock},
- {"date", os_date},
- {"difftime", os_difftime},
- {"execute", os_execute},
- {"exit", os_exit},
- {"getenv", os_getenv},
- {"remove", os_remove},
- {"rename", os_rename},
- {"setlocale", os_setlocale},
- {"time", os_time},
- {"tmpname", os_tmpname},
- {NULL, NULL}
-};
-
-/* }====================================================== */
-
-
-
-LUALIB_API int luaopen_os (lua_State *L) {
- luaL_register(L, LUA_OSLIBNAME, syslib);
- return 1;
-}
-
diff --git a/lib/lua/lparser.c b/lib/lua/lparser.c
deleted file mode 100644
index 1e2a9a8..0000000
--- a/lib/lua/lparser.c
+++ /dev/null
@@ -1,1339 +0,0 @@
-/*
-** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $
-** Lua Parser
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lparser_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lcode.h"
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lparser.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-
-
-
-#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
-
-#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]])
-
-#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
-
-
-/*
-** nodes for block list (list of active blocks)
-*/
-typedef struct BlockCnt {
- struct BlockCnt *previous; /* chain */
- int breaklist; /* list of jumps out of this loop */
- lu_byte nactvar; /* # active locals outside the breakable structure */
- lu_byte upval; /* true if some variable in the block is an upvalue */
- lu_byte isbreakable; /* true if `block' is a loop */
-} BlockCnt;
-
-
-
-/*
-** prototypes for recursive non-terminal functions
-*/
-static void chunk (LexState *ls);
-static void expr (LexState *ls, expdesc *v);
-
-
-static void anchor_token (LexState *ls) {
- if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
- TString *ts = ls->t.seminfo.ts;
- luaX_newstring(ls, getstr(ts), ts->tsv.len);
- }
-}
-
-
-static void error_expected (LexState *ls, int token) {
- luaX_syntaxerror(ls,
- luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token)));
-}
-
-
-static void errorlimit (FuncState *fs, int limit, const char *what) {
- const char *msg = (fs->f->linedefined == 0) ?
- luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
- luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
- fs->f->linedefined, limit, what);
- luaX_lexerror(fs->ls, msg, 0);
-}
-
-
-static int testnext (LexState *ls, int c) {
- if (ls->t.token == c) {
- luaX_next(ls);
- return 1;
- }
- else return 0;
-}
-
-
-static void check (LexState *ls, int c) {
- if (ls->t.token != c)
- error_expected(ls, c);
-}
-
-static void checknext (LexState *ls, int c) {
- check(ls, c);
- luaX_next(ls);
-}
-
-
-#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
-
-
-
-static void check_match (LexState *ls, int what, int who, int where) {
- if (!testnext(ls, what)) {
- if (where == ls->linenumber)
- error_expected(ls, what);
- else {
- luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
- LUA_QS " expected (to close " LUA_QS " at line %d)",
- luaX_token2str(ls, what), luaX_token2str(ls, who), where));
- }
- }
-}
-
-
-static TString *str_checkname (LexState *ls) {
- TString *ts;
- check(ls, TK_NAME);
- ts = ls->t.seminfo.ts;
- luaX_next(ls);
- return ts;
-}
-
-
-static void init_exp (expdesc *e, expkind k, int i) {
- e->f = e->t = NO_JUMP;
- e->k = k;
- e->u.s.info = i;
-}
-
-
-static void codestring (LexState *ls, expdesc *e, TString *s) {
- init_exp(e, VK, luaK_stringK(ls->fs, s));
-}
-
-
-static void checkname(LexState *ls, expdesc *e) {
- codestring(ls, e, str_checkname(ls));
-}
-
-
-static int registerlocalvar (LexState *ls, TString *varname) {
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- int oldsize = f->sizelocvars;
- luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
- LocVar, SHRT_MAX, "too many local variables");
- while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
- f->locvars[fs->nlocvars].varname = varname;
- luaC_objbarrier(ls->L, f, varname);
- return fs->nlocvars++;
-}
-
-
-#define new_localvarliteral(ls,v,n) \
- new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n)
-
-
-static void new_localvar (LexState *ls, TString *name, int n) {
- FuncState *fs = ls->fs;
- luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
- fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
-}
-
-
-static void adjustlocalvars (LexState *ls, int nvars) {
- FuncState *fs = ls->fs;
- fs->nactvar = cast_byte(fs->nactvar + nvars);
- for (; nvars; nvars--) {
- getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
- }
-}
-
-
-static void removevars (LexState *ls, int tolevel) {
- FuncState *fs = ls->fs;
- while (fs->nactvar > tolevel)
- getlocvar(fs, --fs->nactvar).endpc = fs->pc;
-}
-
-
-static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
- int i;
- Proto *f = fs->f;
- int oldsize = f->sizeupvalues;
- for (i=0; inups; i++) {
- if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
- lua_assert(f->upvalues[i] == name);
- return i;
- }
- }
- /* new one */
- luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues");
- luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues,
- TString *, MAX_INT, "");
- while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;
- f->upvalues[f->nups] = name;
- luaC_objbarrier(fs->L, f, name);
- lua_assert(v->k == VLOCAL || v->k == VUPVAL);
- fs->upvalues[f->nups].k = cast_byte(v->k);
- fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
- return f->nups++;
-}
-
-
-static int searchvar (FuncState *fs, TString *n) {
- int i;
- for (i=fs->nactvar-1; i >= 0; i--) {
- if (n == getlocvar(fs, i).varname)
- return i;
- }
- return -1; /* not found */
-}
-
-
-static void markupval (FuncState *fs, int level) {
- BlockCnt *bl = fs->bl;
- while (bl && bl->nactvar > level) bl = bl->previous;
- if (bl) bl->upval = 1;
-}
-
-
-static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
- if (fs == NULL) { /* no more levels? */
- init_exp(var, VGLOBAL, NO_REG); /* default is global variable */
- return VGLOBAL;
- }
- else {
- int v = searchvar(fs, n); /* look up at current level */
- if (v >= 0) {
- init_exp(var, VLOCAL, v);
- if (!base)
- markupval(fs, v); /* local will be used as an upval */
- return VLOCAL;
- }
- else { /* not found at current level; try upper one */
- if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
- return VGLOBAL;
- var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
- var->k = VUPVAL; /* upvalue in this level */
- return VUPVAL;
- }
- }
-}
-
-
-static void singlevar (LexState *ls, expdesc *var) {
- TString *varname = str_checkname(ls);
- FuncState *fs = ls->fs;
- if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
- var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */
-}
-
-
-static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
- FuncState *fs = ls->fs;
- int extra = nvars - nexps;
- if (hasmultret(e->k)) {
- extra++; /* includes call itself */
- if (extra < 0) extra = 0;
- luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
- if (extra > 1) luaK_reserveregs(fs, extra-1);
- }
- else {
- if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
- if (extra > 0) {
- int reg = fs->freereg;
- luaK_reserveregs(fs, extra);
- luaK_nil(fs, reg, extra);
- }
- }
-}
-
-
-static void enterlevel (LexState *ls) {
- if (++ls->L->nCcalls > LUAI_MAXCCALLS)
- luaX_lexerror(ls, "chunk has too many syntax levels", 0);
-}
-
-
-#define leavelevel(ls) ((ls)->L->nCcalls--)
-
-
-static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) {
- bl->breaklist = NO_JUMP;
- bl->isbreakable = isbreakable;
- bl->nactvar = fs->nactvar;
- bl->upval = 0;
- bl->previous = fs->bl;
- fs->bl = bl;
- lua_assert(fs->freereg == fs->nactvar);
-}
-
-
-static void leaveblock (FuncState *fs) {
- BlockCnt *bl = fs->bl;
- fs->bl = bl->previous;
- removevars(fs->ls, bl->nactvar);
- if (bl->upval)
- luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
- /* a block either controls scope or breaks (never both) */
- lua_assert(!bl->isbreakable || !bl->upval);
- lua_assert(bl->nactvar == fs->nactvar);
- fs->freereg = fs->nactvar; /* free registers */
- luaK_patchtohere(fs, bl->breaklist);
-}
-
-
-static void pushclosure (LexState *ls, FuncState *func, expdesc *v) {
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- int oldsize = f->sizep;
- int i;
- luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
- MAXARG_Bx, "constant table overflow");
- while (oldsize < f->sizep) f->p[oldsize++] = NULL;
- f->p[fs->np++] = func->f;
- luaC_objbarrier(ls->L, f, func->f);
- init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
- for (i=0; if->nups; i++) {
- OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
- luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);
- }
-}
-
-
-static void open_func (LexState *ls, FuncState *fs) {
- lua_State *L = ls->L;
- Proto *f = luaF_newproto(L);
- fs->f = f;
- fs->prev = ls->fs; /* linked list of funcstates */
- fs->ls = ls;
- fs->L = L;
- ls->fs = fs;
- fs->pc = 0;
- fs->lasttarget = -1;
- fs->jpc = NO_JUMP;
- fs->freereg = 0;
- fs->nk = 0;
- fs->np = 0;
- fs->nlocvars = 0;
- fs->nactvar = 0;
- fs->bl = NULL;
- f->source = ls->source;
- f->maxstacksize = 2; /* registers 0/1 are always valid */
- fs->h = luaH_new(L, 0, 0);
- /* anchor table of constants and prototype (to avoid being collected) */
- sethvalue2s(L, L->top, fs->h);
- incr_top(L);
- setptvalue2s(L, L->top, f);
- incr_top(L);
-}
-
-
-static void close_func (LexState *ls) {
- lua_State *L = ls->L;
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- removevars(ls, 0);
- luaK_ret(fs, 0, 0); /* final return */
- luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
- f->sizecode = fs->pc;
- luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
- f->sizelineinfo = fs->pc;
- luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
- f->sizek = fs->nk;
- luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
- f->sizep = fs->np;
- luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
- f->sizelocvars = fs->nlocvars;
- luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
- f->sizeupvalues = f->nups;
- lua_assert(luaG_checkcode(f));
- lua_assert(fs->bl == NULL);
- ls->fs = fs->prev;
- L->top -= 2; /* remove table and prototype from the stack */
- /* last token read was anchored in defunct function; must reanchor it */
- if (fs) anchor_token(ls);
-}
-
-
-Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
- struct LexState lexstate;
- struct FuncState funcstate;
- lexstate.buff = buff;
- luaX_setinput(L, &lexstate, z, luaS_new(L, name));
- open_func(&lexstate, &funcstate);
- funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
- luaX_next(&lexstate); /* read first token */
- chunk(&lexstate);
- check(&lexstate, TK_EOS);
- close_func(&lexstate);
- lua_assert(funcstate.prev == NULL);
- lua_assert(funcstate.f->nups == 0);
- lua_assert(lexstate.fs == NULL);
- return funcstate.f;
-}
-
-
-
-/*============================================================*/
-/* GRAMMAR RULES */
-/*============================================================*/
-
-
-static void field (LexState *ls, expdesc *v) {
- /* field -> ['.' | ':'] NAME */
- FuncState *fs = ls->fs;
- expdesc key;
- luaK_exp2anyreg(fs, v);
- luaX_next(ls); /* skip the dot or colon */
- checkname(ls, &key);
- luaK_indexed(fs, v, &key);
-}
-
-
-static void yindex (LexState *ls, expdesc *v) {
- /* index -> '[' expr ']' */
- luaX_next(ls); /* skip the '[' */
- expr(ls, v);
- luaK_exp2val(ls->fs, v);
- checknext(ls, ']');
-}
-
-
-/*
-** {======================================================================
-** Rules for Constructors
-** =======================================================================
-*/
-
-
-struct ConsControl {
- expdesc v; /* last list item read */
- expdesc *t; /* table descriptor */
- int nh; /* total number of `record' elements */
- int na; /* total number of array elements */
- int tostore; /* number of array elements pending to be stored */
-};
-
-
-static void recfield (LexState *ls, struct ConsControl *cc) {
- /* recfield -> (NAME | `['exp1`]') = exp1 */
- FuncState *fs = ls->fs;
- int reg = ls->fs->freereg;
- expdesc key, val;
- int rkkey;
- if (ls->t.token == TK_NAME) {
- luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
- checkname(ls, &key);
- }
- else /* ls->t.token == '[' */
- yindex(ls, &key);
- cc->nh++;
- checknext(ls, '=');
- rkkey = luaK_exp2RK(fs, &key);
- expr(ls, &val);
- luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
- fs->freereg = reg; /* free registers */
-}
-
-
-static void closelistfield (FuncState *fs, struct ConsControl *cc) {
- if (cc->v.k == VVOID) return; /* there is no list item */
- luaK_exp2nextreg(fs, &cc->v);
- cc->v.k = VVOID;
- if (cc->tostore == LFIELDS_PER_FLUSH) {
- luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
- cc->tostore = 0; /* no more items pending */
- }
-}
-
-
-static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
- if (cc->tostore == 0) return;
- if (hasmultret(cc->v.k)) {
- luaK_setmultret(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
- cc->na--; /* do not count last expression (unknown number of elements) */
- }
- else {
- if (cc->v.k != VVOID)
- luaK_exp2nextreg(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
- }
-}
-
-
-static void listfield (LexState *ls, struct ConsControl *cc) {
- expr(ls, &cc->v);
- luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
- cc->na++;
- cc->tostore++;
-}
-
-
-static void constructor (LexState *ls, expdesc *t) {
- /* constructor -> ?? */
- FuncState *fs = ls->fs;
- int line = ls->linenumber;
- int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
- struct ConsControl cc;
- cc.na = cc.nh = cc.tostore = 0;
- cc.t = t;
- init_exp(t, VRELOCABLE, pc);
- init_exp(&cc.v, VVOID, 0); /* no value (yet) */
- luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */
- checknext(ls, '{');
- do {
- lua_assert(cc.v.k == VVOID || cc.tostore > 0);
- if (ls->t.token == '}') break;
- closelistfield(fs, &cc);
- switch(ls->t.token) {
- case TK_NAME: { /* may be listfields or recfields */
- luaX_lookahead(ls);
- if (ls->lookahead.token != '=') /* expression? */
- listfield(ls, &cc);
- else
- recfield(ls, &cc);
- break;
- }
- case '[': { /* constructor_item -> recfield */
- recfield(ls, &cc);
- break;
- }
- default: { /* constructor_part -> listfield */
- listfield(ls, &cc);
- break;
- }
- }
- } while (testnext(ls, ',') || testnext(ls, ';'));
- check_match(ls, '}', '{', line);
- lastlistfield(fs, &cc);
- SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
- SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
-}
-
-/* }====================================================================== */
-
-
-
-static void parlist (LexState *ls) {
- /* parlist -> [ param { `,' param } ] */
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- int nparams = 0;
- f->is_vararg = 0;
- if (ls->t.token != ')') { /* is `parlist' not empty? */
- do {
- switch (ls->t.token) {
- case TK_NAME: { /* param -> NAME */
- new_localvar(ls, str_checkname(ls), nparams++);
- break;
- }
- case TK_DOTS: { /* param -> `...' */
- luaX_next(ls);
-#if defined(LUA_COMPAT_VARARG)
- /* use `arg' as default name */
- new_localvarliteral(ls, "arg", nparams++);
- f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG;
-#endif
- f->is_vararg |= VARARG_ISVARARG;
- break;
- }
- default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected");
- }
- } while (!f->is_vararg && testnext(ls, ','));
- }
- adjustlocalvars(ls, nparams);
- f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
- luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
-}
-
-
-static void body (LexState *ls, expdesc *e, int needself, int line) {
- /* body -> `(' parlist `)' chunk END */
- FuncState new_fs;
- open_func(ls, &new_fs);
- new_fs.f->linedefined = line;
- checknext(ls, '(');
- if (needself) {
- new_localvarliteral(ls, "self", 0);
- adjustlocalvars(ls, 1);
- }
- parlist(ls);
- checknext(ls, ')');
- chunk(ls);
- new_fs.f->lastlinedefined = ls->linenumber;
- check_match(ls, TK_END, TK_FUNCTION, line);
- close_func(ls);
- pushclosure(ls, &new_fs, e);
-}
-
-
-static int explist1 (LexState *ls, expdesc *v) {
- /* explist1 -> expr { `,' expr } */
- int n = 1; /* at least one expression */
- expr(ls, v);
- while (testnext(ls, ',')) {
- luaK_exp2nextreg(ls->fs, v);
- expr(ls, v);
- n++;
- }
- return n;
-}
-
-
-static void funcargs (LexState *ls, expdesc *f) {
- FuncState *fs = ls->fs;
- expdesc args;
- int base, nparams;
- int line = ls->linenumber;
- switch (ls->t.token) {
- case '(': { /* funcargs -> `(' [ explist1 ] `)' */
- if (line != ls->lastline)
- luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
- luaX_next(ls);
- if (ls->t.token == ')') /* arg list is empty? */
- args.k = VVOID;
- else {
- explist1(ls, &args);
- luaK_setmultret(fs, &args);
- }
- check_match(ls, ')', '(', line);
- break;
- }
- case '{': { /* funcargs -> constructor */
- constructor(ls, &args);
- break;
- }
- case TK_STRING: { /* funcargs -> STRING */
- codestring(ls, &args, ls->t.seminfo.ts);
- luaX_next(ls); /* must use `seminfo' before `next' */
- break;
- }
- default: {
- luaX_syntaxerror(ls, "function arguments expected");
- return;
- }
- }
- lua_assert(f->k == VNONRELOC);
- base = f->u.s.info; /* base register for call */
- if (hasmultret(args.k))
- nparams = LUA_MULTRET; /* open call */
- else {
- if (args.k != VVOID)
- luaK_exp2nextreg(fs, &args); /* close last argument */
- nparams = fs->freereg - (base+1);
- }
- init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
- luaK_fixline(fs, line);
- fs->freereg = base+1; /* call remove function and arguments and leaves
- (unless changed) one result */
-}
-
-
-
-
-/*
-** {======================================================================
-** Expression parsing
-** =======================================================================
-*/
-
-
-static void prefixexp (LexState *ls, expdesc *v) {
- /* prefixexp -> NAME | '(' expr ')' */
- switch (ls->t.token) {
- case '(': {
- int line = ls->linenumber;
- luaX_next(ls);
- expr(ls, v);
- check_match(ls, ')', '(', line);
- luaK_dischargevars(ls->fs, v);
- return;
- }
- case TK_NAME: {
- singlevar(ls, v);
- return;
- }
- default: {
- luaX_syntaxerror(ls, "unexpected symbol");
- return;
- }
- }
-}
-
-
-static void primaryexp (LexState *ls, expdesc *v) {
- /* primaryexp ->
- prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
- FuncState *fs = ls->fs;
- prefixexp(ls, v);
- for (;;) {
- switch (ls->t.token) {
- case '.': { /* field */
- field(ls, v);
- break;
- }
- case '[': { /* `[' exp1 `]' */
- expdesc key;
- luaK_exp2anyreg(fs, v);
- yindex(ls, &key);
- luaK_indexed(fs, v, &key);
- break;
- }
- case ':': { /* `:' NAME funcargs */
- expdesc key;
- luaX_next(ls);
- checkname(ls, &key);
- luaK_self(fs, v, &key);
- funcargs(ls, v);
- break;
- }
- case '(': case TK_STRING: case '{': { /* funcargs */
- luaK_exp2nextreg(fs, v);
- funcargs(ls, v);
- break;
- }
- default: return;
- }
- }
-}
-
-
-static void simpleexp (LexState *ls, expdesc *v) {
- /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
- constructor | FUNCTION body | primaryexp */
- switch (ls->t.token) {
- case TK_NUMBER: {
- init_exp(v, VKNUM, 0);
- v->u.nval = ls->t.seminfo.r;
- break;
- }
- case TK_STRING: {
- codestring(ls, v, ls->t.seminfo.ts);
- break;
- }
- case TK_NIL: {
- init_exp(v, VNIL, 0);
- break;
- }
- case TK_TRUE: {
- init_exp(v, VTRUE, 0);
- break;
- }
- case TK_FALSE: {
- init_exp(v, VFALSE, 0);
- break;
- }
- case TK_DOTS: { /* vararg */
- FuncState *fs = ls->fs;
- check_condition(ls, fs->f->is_vararg,
- "cannot use " LUA_QL("...") " outside a vararg function");
- fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */
- init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
- break;
- }
- case '{': { /* constructor */
- constructor(ls, v);
- return;
- }
- case TK_FUNCTION: {
- luaX_next(ls);
- body(ls, v, 0, ls->linenumber);
- return;
- }
- default: {
- primaryexp(ls, v);
- return;
- }
- }
- luaX_next(ls);
-}
-
-
-static UnOpr getunopr (int op) {
- switch (op) {
- case TK_NOT: return OPR_NOT;
- case '-': return OPR_MINUS;
- case '#': return OPR_LEN;
- default: return OPR_NOUNOPR;
- }
-}
-
-
-static BinOpr getbinopr (int op) {
- switch (op) {
- case '+': return OPR_ADD;
- case '-': return OPR_SUB;
- case '*': return OPR_MUL;
- case '/': return OPR_DIV;
- case '%': return OPR_MOD;
- case '^': return OPR_POW;
- case TK_CONCAT: return OPR_CONCAT;
- case TK_NE: return OPR_NE;
- case TK_EQ: return OPR_EQ;
- case '<': return OPR_LT;
- case TK_LE: return OPR_LE;
- case '>': return OPR_GT;
- case TK_GE: return OPR_GE;
- case TK_AND: return OPR_AND;
- case TK_OR: return OPR_OR;
- default: return OPR_NOBINOPR;
- }
-}
-
-
-static const struct {
- lu_byte left; /* left priority for each binary operator */
- lu_byte right; /* right priority */
-} priority[] = { /* ORDER OPR */
- {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */
- {10, 9}, {5, 4}, /* power and concat (right associative) */
- {3, 3}, {3, 3}, /* equality and inequality */
- {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
- {2, 2}, {1, 1} /* logical (and/or) */
-};
-
-#define UNARY_PRIORITY 8 /* priority for unary operators */
-
-
-/*
-** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
-** where `binop' is any binary operator with a priority higher than `limit'
-*/
-static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
- BinOpr op;
- UnOpr uop;
- enterlevel(ls);
- uop = getunopr(ls->t.token);
- if (uop != OPR_NOUNOPR) {
- luaX_next(ls);
- subexpr(ls, v, UNARY_PRIORITY);
- luaK_prefix(ls->fs, uop, v);
- }
- else simpleexp(ls, v);
- /* expand while operators have priorities higher than `limit' */
- op = getbinopr(ls->t.token);
- while (op != OPR_NOBINOPR && priority[op].left > limit) {
- expdesc v2;
- BinOpr nextop;
- luaX_next(ls);
- luaK_infix(ls->fs, op, v);
- /* read sub-expression with higher priority */
- nextop = subexpr(ls, &v2, priority[op].right);
- luaK_posfix(ls->fs, op, v, &v2);
- op = nextop;
- }
- leavelevel(ls);
- return op; /* return first untreated operator */
-}
-
-
-static void expr (LexState *ls, expdesc *v) {
- subexpr(ls, v, 0);
-}
-
-/* }==================================================================== */
-
-
-
-/*
-** {======================================================================
-** Rules for Statements
-** =======================================================================
-*/
-
-
-static int block_follow (int token) {
- switch (token) {
- case TK_ELSE: case TK_ELSEIF: case TK_END:
- case TK_UNTIL: case TK_EOS:
- return 1;
- default: return 0;
- }
-}
-
-
-static void block (LexState *ls) {
- /* block -> chunk */
- FuncState *fs = ls->fs;
- BlockCnt bl;
- enterblock(fs, &bl, 0);
- chunk(ls);
- lua_assert(bl.breaklist == NO_JUMP);
- leaveblock(fs);
-}
-
-
-/*
-** structure to chain all variables in the left-hand side of an
-** assignment
-*/
-struct LHS_assign {
- struct LHS_assign *prev;
- expdesc v; /* variable (global, local, upvalue, or indexed) */
-};
-
-
-/*
-** check whether, in an assignment to a local variable, the local variable
-** is needed in a previous assignment (to a table). If so, save original
-** local value in a safe place and use this safe copy in the previous
-** assignment.
-*/
-static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
- FuncState *fs = ls->fs;
- int extra = fs->freereg; /* eventual position to save local variable */
- int conflict = 0;
- for (; lh; lh = lh->prev) {
- if (lh->v.k == VINDEXED) {
- if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
- conflict = 1;
- lh->v.u.s.info = extra; /* previous assignment will use safe copy */
- }
- if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */
- conflict = 1;
- lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
- }
- }
- }
- if (conflict) {
- luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */
- luaK_reserveregs(fs, 1);
- }
-}
-
-
-static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
- expdesc e;
- check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
- "syntax error");
- if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */
- struct LHS_assign nv;
- nv.prev = lh;
- primaryexp(ls, &nv.v);
- if (nv.v.k == VLOCAL)
- check_conflict(ls, lh, &nv.v);
- luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
- "variables in assignment");
- assignment(ls, &nv, nvars+1);
- }
- else { /* assignment -> `=' explist1 */
- int nexps;
- checknext(ls, '=');
- nexps = explist1(ls, &e);
- if (nexps != nvars) {
- adjust_assign(ls, nvars, nexps, &e);
- if (nexps > nvars)
- ls->fs->freereg -= nexps - nvars; /* remove extra values */
- }
- else {
- luaK_setoneret(ls->fs, &e); /* close last expression */
- luaK_storevar(ls->fs, &lh->v, &e);
- return; /* avoid default */
- }
- }
- init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
- luaK_storevar(ls->fs, &lh->v, &e);
-}
-
-
-static int cond (LexState *ls) {
- /* cond -> exp */
- expdesc v;
- expr(ls, &v); /* read condition */
- if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
- luaK_goiftrue(ls->fs, &v);
- return v.f;
-}
-
-
-static void breakstat (LexState *ls) {
- FuncState *fs = ls->fs;
- BlockCnt *bl = fs->bl;
- int upval = 0;
- while (bl && !bl->isbreakable) {
- upval |= bl->upval;
- bl = bl->previous;
- }
- if (!bl)
- luaX_syntaxerror(ls, "no loop to break");
- if (upval)
- luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
- luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
-}
-
-
-static void whilestat (LexState *ls, int line) {
- /* whilestat -> WHILE cond DO block END */
- FuncState *fs = ls->fs;
- int whileinit;
- int condexit;
- BlockCnt bl;
- luaX_next(ls); /* skip WHILE */
- whileinit = luaK_getlabel(fs);
- condexit = cond(ls);
- enterblock(fs, &bl, 1);
- checknext(ls, TK_DO);
- block(ls);
- luaK_patchlist(fs, luaK_jump(fs), whileinit);
- check_match(ls, TK_END, TK_WHILE, line);
- leaveblock(fs);
- luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
-}
-
-
-static void repeatstat (LexState *ls, int line) {
- /* repeatstat -> REPEAT block UNTIL cond */
- int condexit;
- FuncState *fs = ls->fs;
- int repeat_init = luaK_getlabel(fs);
- BlockCnt bl1, bl2;
- enterblock(fs, &bl1, 1); /* loop block */
- enterblock(fs, &bl2, 0); /* scope block */
- luaX_next(ls); /* skip REPEAT */
- chunk(ls);
- check_match(ls, TK_UNTIL, TK_REPEAT, line);
- condexit = cond(ls); /* read condition (inside scope block) */
- if (!bl2.upval) { /* no upvalues? */
- leaveblock(fs); /* finish scope */
- luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */
- }
- else { /* complete semantics when there are upvalues */
- breakstat(ls); /* if condition then break */
- luaK_patchtohere(ls->fs, condexit); /* else... */
- leaveblock(fs); /* finish scope... */
- luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */
- }
- leaveblock(fs); /* finish loop */
-}
-
-
-static int exp1 (LexState *ls) {
- expdesc e;
- int k;
- expr(ls, &e);
- k = e.k;
- luaK_exp2nextreg(ls->fs, &e);
- return k;
-}
-
-
-static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
- /* forbody -> DO block */
- BlockCnt bl;
- FuncState *fs = ls->fs;
- int prep, endfor;
- adjustlocalvars(ls, 3); /* control variables */
- checknext(ls, TK_DO);
- prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
- enterblock(fs, &bl, 0); /* scope for declared variables */
- adjustlocalvars(ls, nvars);
- luaK_reserveregs(fs, nvars);
- block(ls);
- leaveblock(fs); /* end of scope for declared variables */
- luaK_patchtohere(fs, prep);
- endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :
- luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
- luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */
- luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);
-}
-
-
-static void fornum (LexState *ls, TString *varname, int line) {
- /* fornum -> NAME = exp1,exp1[,exp1] forbody */
- FuncState *fs = ls->fs;
- int base = fs->freereg;
- new_localvarliteral(ls, "(for index)", 0);
- new_localvarliteral(ls, "(for limit)", 1);
- new_localvarliteral(ls, "(for step)", 2);
- new_localvar(ls, varname, 3);
- checknext(ls, '=');
- exp1(ls); /* initial value */
- checknext(ls, ',');
- exp1(ls); /* limit */
- if (testnext(ls, ','))
- exp1(ls); /* optional step */
- else { /* default step = 1 */
- luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));
- luaK_reserveregs(fs, 1);
- }
- forbody(ls, base, line, 1, 1);
-}
-
-
-static void forlist (LexState *ls, TString *indexname) {
- /* forlist -> NAME {,NAME} IN explist1 forbody */
- FuncState *fs = ls->fs;
- expdesc e;
- int nvars = 0;
- int line;
- int base = fs->freereg;
- /* create control variables */
- new_localvarliteral(ls, "(for generator)", nvars++);
- new_localvarliteral(ls, "(for state)", nvars++);
- new_localvarliteral(ls, "(for control)", nvars++);
- /* create declared variables */
- new_localvar(ls, indexname, nvars++);
- while (testnext(ls, ','))
- new_localvar(ls, str_checkname(ls), nvars++);
- checknext(ls, TK_IN);
- line = ls->linenumber;
- adjust_assign(ls, 3, explist1(ls, &e), &e);
- luaK_checkstack(fs, 3); /* extra space to call generator */
- forbody(ls, base, line, nvars - 3, 0);
-}
-
-
-static void forstat (LexState *ls, int line) {
- /* forstat -> FOR (fornum | forlist) END */
- FuncState *fs = ls->fs;
- TString *varname;
- BlockCnt bl;
- enterblock(fs, &bl, 1); /* scope for loop and control variables */
- luaX_next(ls); /* skip `for' */
- varname = str_checkname(ls); /* first variable name */
- switch (ls->t.token) {
- case '=': fornum(ls, varname, line); break;
- case ',': case TK_IN: forlist(ls, varname); break;
- default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
- }
- check_match(ls, TK_END, TK_FOR, line);
- leaveblock(fs); /* loop scope (`break' jumps to this point) */
-}
-
-
-static int test_then_block (LexState *ls) {
- /* test_then_block -> [IF | ELSEIF] cond THEN block */
- int condexit;
- luaX_next(ls); /* skip IF or ELSEIF */
- condexit = cond(ls);
- checknext(ls, TK_THEN);
- block(ls); /* `then' part */
- return condexit;
-}
-
-
-static void ifstat (LexState *ls, int line) {
- /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
- FuncState *fs = ls->fs;
- int flist;
- int escapelist = NO_JUMP;
- flist = test_then_block(ls); /* IF cond THEN block */
- while (ls->t.token == TK_ELSEIF) {
- luaK_concat(fs, &escapelist, luaK_jump(fs));
- luaK_patchtohere(fs, flist);
- flist = test_then_block(ls); /* ELSEIF cond THEN block */
- }
- if (ls->t.token == TK_ELSE) {
- luaK_concat(fs, &escapelist, luaK_jump(fs));
- luaK_patchtohere(fs, flist);
- luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
- block(ls); /* `else' part */
- }
- else
- luaK_concat(fs, &escapelist, flist);
- luaK_patchtohere(fs, escapelist);
- check_match(ls, TK_END, TK_IF, line);
-}
-
-
-static void localfunc (LexState *ls) {
- expdesc v, b;
- FuncState *fs = ls->fs;
- new_localvar(ls, str_checkname(ls), 0);
- init_exp(&v, VLOCAL, fs->freereg);
- luaK_reserveregs(fs, 1);
- adjustlocalvars(ls, 1);
- body(ls, &b, 0, ls->linenumber);
- luaK_storevar(fs, &v, &b);
- /* debug information will only see the variable after this point! */
- getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
-}
-
-
-static void localstat (LexState *ls) {
- /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */
- int nvars = 0;
- int nexps;
- expdesc e;
- do {
- new_localvar(ls, str_checkname(ls), nvars++);
- } while (testnext(ls, ','));
- if (testnext(ls, '='))
- nexps = explist1(ls, &e);
- else {
- e.k = VVOID;
- nexps = 0;
- }
- adjust_assign(ls, nvars, nexps, &e);
- adjustlocalvars(ls, nvars);
-}
-
-
-static int funcname (LexState *ls, expdesc *v) {
- /* funcname -> NAME {field} [`:' NAME] */
- int needself = 0;
- singlevar(ls, v);
- while (ls->t.token == '.')
- field(ls, v);
- if (ls->t.token == ':') {
- needself = 1;
- field(ls, v);
- }
- return needself;
-}
-
-
-static void funcstat (LexState *ls, int line) {
- /* funcstat -> FUNCTION funcname body */
- int needself;
- expdesc v, b;
- luaX_next(ls); /* skip FUNCTION */
- needself = funcname(ls, &v);
- body(ls, &b, needself, line);
- luaK_storevar(ls->fs, &v, &b);
- luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
-}
-
-
-static void exprstat (LexState *ls) {
- /* stat -> func | assignment */
- FuncState *fs = ls->fs;
- struct LHS_assign v;
- primaryexp(ls, &v.v);
- if (v.v.k == VCALL) /* stat -> func */
- SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
- else { /* stat -> assignment */
- v.prev = NULL;
- assignment(ls, &v, 1);
- }
-}
-
-
-static void retstat (LexState *ls) {
- /* stat -> RETURN explist */
- FuncState *fs = ls->fs;
- expdesc e;
- int first, nret; /* registers with returned values */
- luaX_next(ls); /* skip RETURN */
- if (block_follow(ls->t.token) || ls->t.token == ';')
- first = nret = 0; /* return no values */
- else {
- nret = explist1(ls, &e); /* optional return values */
- if (hasmultret(e.k)) {
- luaK_setmultret(fs, &e);
- if (e.k == VCALL && nret == 1) { /* tail call? */
- SET_OPCODE(getcode(fs,&e), OP_TAILCALL);
- lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
- }
- first = fs->nactvar;
- nret = LUA_MULTRET; /* return all values */
- }
- else {
- if (nret == 1) /* only one single value? */
- first = luaK_exp2anyreg(fs, &e);
- else {
- luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
- first = fs->nactvar; /* return all `active' values */
- lua_assert(nret == fs->freereg - first);
- }
- }
- }
- luaK_ret(fs, first, nret);
-}
-
-
-static int statement (LexState *ls) {
- int line = ls->linenumber; /* may be needed for error messages */
- switch (ls->t.token) {
- case TK_IF: { /* stat -> ifstat */
- ifstat(ls, line);
- return 0;
- }
- case TK_WHILE: { /* stat -> whilestat */
- whilestat(ls, line);
- return 0;
- }
- case TK_DO: { /* stat -> DO block END */
- luaX_next(ls); /* skip DO */
- block(ls);
- check_match(ls, TK_END, TK_DO, line);
- return 0;
- }
- case TK_FOR: { /* stat -> forstat */
- forstat(ls, line);
- return 0;
- }
- case TK_REPEAT: { /* stat -> repeatstat */
- repeatstat(ls, line);
- return 0;
- }
- case TK_FUNCTION: {
- funcstat(ls, line); /* stat -> funcstat */
- return 0;
- }
- case TK_LOCAL: { /* stat -> localstat */
- luaX_next(ls); /* skip LOCAL */
- if (testnext(ls, TK_FUNCTION)) /* local function? */
- localfunc(ls);
- else
- localstat(ls);
- return 0;
- }
- case TK_RETURN: { /* stat -> retstat */
- retstat(ls);
- return 1; /* must be last statement */
- }
- case TK_BREAK: { /* stat -> breakstat */
- luaX_next(ls); /* skip BREAK */
- breakstat(ls);
- return 1; /* must be last statement */
- }
- default: {
- exprstat(ls);
- return 0; /* to avoid warnings */
- }
- }
-}
-
-
-static void chunk (LexState *ls) {
- /* chunk -> { stat [`;'] } */
- int islast = 0;
- enterlevel(ls);
- while (!islast && !block_follow(ls->t.token)) {
- islast = statement(ls);
- testnext(ls, ';');
- lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
- ls->fs->freereg >= ls->fs->nactvar);
- ls->fs->freereg = ls->fs->nactvar; /* free registers */
- }
- leavelevel(ls);
-}
-
-/* }====================================================================== */
diff --git a/lib/lua/lparser.h b/lib/lua/lparser.h
deleted file mode 100644
index 18836af..0000000
--- a/lib/lua/lparser.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
-** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lua Parser
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lparser_h
-#define lparser_h
-
-#include "llimits.h"
-#include "lobject.h"
-#include "lzio.h"
-
-
-/*
-** Expression descriptor
-*/
-
-typedef enum {
- VVOID, /* no value */
- VNIL,
- VTRUE,
- VFALSE,
- VK, /* info = index of constant in `k' */
- VKNUM, /* nval = numerical value */
- VLOCAL, /* info = local register */
- VUPVAL, /* info = index of upvalue in `upvalues' */
- VGLOBAL, /* info = index of table; aux = index of global name in `k' */
- VINDEXED, /* info = table register; aux = index register (or `k') */
- VJMP, /* info = instruction pc */
- VRELOCABLE, /* info = instruction pc */
- VNONRELOC, /* info = result register */
- VCALL, /* info = instruction pc */
- VVARARG /* info = instruction pc */
-} expkind;
-
-typedef struct expdesc {
- expkind k;
- union {
- struct { int info, aux; } s;
- lua_Number nval;
- } u;
- int t; /* patch list of `exit when true' */
- int f; /* patch list of `exit when false' */
-} expdesc;
-
-
-typedef struct upvaldesc {
- lu_byte k;
- lu_byte info;
-} upvaldesc;
-
-
-struct BlockCnt; /* defined in lparser.c */
-
-
-/* state needed to generate code for a given function */
-typedef struct FuncState {
- Proto *f; /* current function header */
- Table *h; /* table to find (and reuse) elements in `k' */
- struct FuncState *prev; /* enclosing function */
- struct LexState *ls; /* lexical state */
- struct lua_State *L; /* copy of the Lua state */
- struct BlockCnt *bl; /* chain of current blocks */
- int pc; /* next position to code (equivalent to `ncode') */
- int lasttarget; /* `pc' of last `jump target' */
- int jpc; /* list of pending jumps to `pc' */
- int freereg; /* first free register */
- int nk; /* number of elements in `k' */
- int np; /* number of elements in `p' */
- short nlocvars; /* number of elements in `locvars' */
- lu_byte nactvar; /* number of active local variables */
- upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
- unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
-} FuncState;
-
-
-LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
- const char *name);
-
-
-#endif
diff --git a/lib/lua/lstate.c b/lib/lua/lstate.c
deleted file mode 100644
index 4313b83..0000000
--- a/lib/lua/lstate.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
-** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
-** Global State
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lstate_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-
-
-#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
-#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
-#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
-
-
-/*
-** Main thread combines a thread state and the global state
-*/
-typedef struct LG {
- lua_State l;
- global_State g;
-} LG;
-
-
-
-static void stack_init (lua_State *L1, lua_State *L) {
- /* initialize CallInfo array */
- L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
- L1->ci = L1->base_ci;
- L1->size_ci = BASIC_CI_SIZE;
- L1->end_ci = L1->base_ci + L1->size_ci - 1;
- /* initialize stack array */
- L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
- L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
- L1->top = L1->stack;
- L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
- /* initialize first ci */
- L1->ci->func = L1->top;
- setnilvalue(L1->top++); /* `function' entry for this `ci' */
- L1->base = L1->ci->base = L1->top;
- L1->ci->top = L1->top + LUA_MINSTACK;
-}
-
-
-static void freestack (lua_State *L, lua_State *L1) {
- luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
- luaM_freearray(L, L1->stack, L1->stacksize, TValue);
-}
-
-
-/*
-** open parts that may cause memory-allocation errors
-*/
-static void f_luaopen (lua_State *L, void *ud) {
- global_State *g = G(L);
- UNUSED(ud);
- stack_init(L, L); /* init stack */
- sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
- sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
- luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
- luaT_init(L);
- luaX_init(L);
- luaS_fix(luaS_newliteral(L, MEMERRMSG));
- g->GCthreshold = 4*g->totalbytes;
-}
-
-
-static void preinit_state (lua_State *L, global_State *g) {
- G(L) = g;
- L->stack = NULL;
- L->stacksize = 0;
- L->errorJmp = NULL;
- L->hook = NULL;
- L->hookmask = 0;
- L->basehookcount = 0;
- L->allowhook = 1;
- resethookcount(L);
- L->openupval = NULL;
- L->size_ci = 0;
- L->nCcalls = L->baseCcalls = 0;
- L->status = 0;
- L->base_ci = L->ci = NULL;
- L->savedpc = NULL;
- L->errfunc = 0;
- setnilvalue(gt(L));
-}
-
-
-static void close_state (lua_State *L) {
- global_State *g = G(L);
- luaF_close(L, L->stack); /* close all upvalues for this thread */
- luaC_freeall(L); /* collect all objects */
- lua_assert(g->rootgc == obj2gco(L));
- lua_assert(g->strt.nuse == 0);
- luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
- luaZ_freebuffer(L, &g->buff);
- freestack(L, L);
- lua_assert(g->totalbytes == sizeof(LG));
- (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
-}
-
-
-lua_State *luaE_newthread (lua_State *L) {
- lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
- luaC_link(L, obj2gco(L1), LUA_TTHREAD);
- preinit_state(L1, G(L));
- stack_init(L1, L); /* init stack */
- setobj2n(L, gt(L1), gt(L)); /* share table of globals */
- L1->hookmask = L->hookmask;
- L1->basehookcount = L->basehookcount;
- L1->hook = L->hook;
- resethookcount(L1);
- lua_assert(iswhite(obj2gco(L1)));
- return L1;
-}
-
-
-void luaE_freethread (lua_State *L, lua_State *L1) {
- luaF_close(L1, L1->stack); /* close all upvalues for this thread */
- lua_assert(L1->openupval == NULL);
- luai_userstatefree(L1);
- freestack(L, L1);
- luaM_freemem(L, fromstate(L1), state_size(lua_State));
-}
-
-
-LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
- int i;
- lua_State *L;
- global_State *g;
- void *l = (*f)(ud, NULL, 0, state_size(LG));
- if (l == NULL) return NULL;
- L = tostate(l);
- g = &((LG *)L)->g;
- L->next = NULL;
- L->tt = LUA_TTHREAD;
- g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
- L->marked = luaC_white(g);
- set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
- preinit_state(L, g);
- g->frealloc = f;
- g->ud = ud;
- g->mainthread = L;
- g->uvhead.u.l.prev = &g->uvhead;
- g->uvhead.u.l.next = &g->uvhead;
- g->GCthreshold = 0; /* mark it as unfinished state */
- g->strt.size = 0;
- g->strt.nuse = 0;
- g->strt.hash = NULL;
- setnilvalue(registry(L));
- luaZ_initbuffer(L, &g->buff);
- g->panic = NULL;
- g->gcstate = GCSpause;
- g->rootgc = obj2gco(L);
- g->sweepstrgc = 0;
- g->sweepgc = &g->rootgc;
- g->gray = NULL;
- g->grayagain = NULL;
- g->weak = NULL;
- g->tmudata = NULL;
- g->totalbytes = sizeof(LG);
- g->gcpause = LUAI_GCPAUSE;
- g->gcstepmul = LUAI_GCMUL;
- g->gcdept = 0;
- for (i=0; imt[i] = NULL;
- if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
- /* memory allocation error: free partial state */
- close_state(L);
- L = NULL;
- }
- else
- luai_userstateopen(L);
- return L;
-}
-
-
-static void callallgcTM (lua_State *L, void *ud) {
- UNUSED(ud);
- luaC_callGCTM(L); /* call GC metamethods for all udata */
-}
-
-
-LUA_API void lua_close (lua_State *L) {
- L = G(L)->mainthread; /* only the main thread can be closed */
- lua_lock(L);
- luaF_close(L, L->stack); /* close all upvalues for this thread */
- luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
- L->errfunc = 0; /* no error function during GC metamethods */
- do { /* repeat until no more errors */
- L->ci = L->base_ci;
- L->base = L->top = L->ci->base;
- L->nCcalls = L->baseCcalls = 0;
- } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
- lua_assert(G(L)->tmudata == NULL);
- luai_userstateclose(L);
- close_state(L);
-}
-
diff --git a/lib/lua/lstate.h b/lib/lua/lstate.h
deleted file mode 100644
index 3bc575b..0000000
--- a/lib/lua/lstate.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
-** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
-** Global State
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lstate_h
-#define lstate_h
-
-#include "lua.h"
-
-#include "lobject.h"
-#include "ltm.h"
-#include "lzio.h"
-
-
-
-struct lua_longjmp; /* defined in ldo.c */
-
-
-/* table of globals */
-#define gt(L) (&L->l_gt)
-
-/* registry */
-#define registry(L) (&G(L)->l_registry)
-
-
-/* extra stack space to handle TM calls and some other extras */
-#define EXTRA_STACK 5
-
-
-#define BASIC_CI_SIZE 8
-
-#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
-
-
-
-typedef struct stringtable {
- GCObject **hash;
- lu_int32 nuse; /* number of elements */
- int size;
-} stringtable;
-
-
-/*
-** informations about a call
-*/
-typedef struct CallInfo {
- StkId base; /* base for this function */
- StkId func; /* function index in the stack */
- StkId top; /* top for this function */
- const Instruction *savedpc;
- int nresults; /* expected number of results from this function */
- int tailcalls; /* number of tail calls lost under this entry */
-} CallInfo;
-
-
-
-#define curr_func(L) (clvalue(L->ci->func))
-#define ci_func(ci) (clvalue((ci)->func))
-#define f_isLua(ci) (!ci_func(ci)->c.isC)
-#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
-
-
-/*
-** `global state', shared by all threads of this state
-*/
-typedef struct global_State {
- stringtable strt; /* hash table for strings */
- lua_Alloc frealloc; /* function to reallocate memory */
- void *ud; /* auxiliary data to `frealloc' */
- lu_byte currentwhite;
- lu_byte gcstate; /* state of garbage collector */
- int sweepstrgc; /* position of sweep in `strt' */
- GCObject *rootgc; /* list of all collectable objects */
- GCObject **sweepgc; /* position of sweep in `rootgc' */
- GCObject *gray; /* list of gray objects */
- GCObject *grayagain; /* list of objects to be traversed atomically */
- GCObject *weak; /* list of weak tables (to be cleared) */
- GCObject *tmudata; /* last element of list of userdata to be GC */
- Mbuffer buff; /* temporary buffer for string concatentation */
- lu_mem GCthreshold;
- lu_mem totalbytes; /* number of bytes currently allocated */
- lu_mem estimate; /* an estimate of number of bytes actually in use */
- lu_mem gcdept; /* how much GC is `behind schedule' */
- int gcpause; /* size of pause between successive GCs */
- int gcstepmul; /* GC `granularity' */
- lua_CFunction panic; /* to be called in unprotected errors */
- TValue l_registry;
- struct lua_State *mainthread;
- UpVal uvhead; /* head of double-linked list of all open upvalues */
- struct Table *mt[NUM_TAGS]; /* metatables for basic types */
- TString *tmname[TM_N]; /* array with tag-method names */
-} global_State;
-
-
-/*
-** `per thread' state
-*/
-struct lua_State {
- CommonHeader;
- lu_byte status;
- StkId top; /* first free slot in the stack */
- StkId base; /* base of current function */
- global_State *l_G;
- CallInfo *ci; /* call info for current function */
- const Instruction *savedpc; /* `savedpc' of current function */
- StkId stack_last; /* last free slot in the stack */
- StkId stack; /* stack base */
- CallInfo *end_ci; /* points after end of ci array*/
- CallInfo *base_ci; /* array of CallInfo's */
- int stacksize;
- int size_ci; /* size of array `base_ci' */
- unsigned short nCcalls; /* number of nested C calls */
- unsigned short baseCcalls; /* nested C calls when resuming coroutine */
- lu_byte hookmask;
- lu_byte allowhook;
- int basehookcount;
- int hookcount;
- lua_Hook hook;
- TValue l_gt; /* table of globals */
- TValue env; /* temporary place for environments */
- GCObject *openupval; /* list of open upvalues in this stack */
- GCObject *gclist;
- struct lua_longjmp *errorJmp; /* current error recover point */
- ptrdiff_t errfunc; /* current error handling function (stack index) */
-};
-
-
-#define G(L) (L->l_G)
-
-
-/*
-** Union of all collectable objects
-*/
-union GCObject {
- GCheader gch;
- union TString ts;
- union Udata u;
- union Closure cl;
- struct Table h;
- struct Proto p;
- struct UpVal uv;
- struct lua_State th; /* thread */
-};
-
-
-/* macros to convert a GCObject into a specific value */
-#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
-#define gco2ts(o) (&rawgco2ts(o)->tsv)
-#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
-#define gco2u(o) (&rawgco2u(o)->uv)
-#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
-#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
-#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
-#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
-#define ngcotouv(o) \
- check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
-#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
-
-/* macro to convert any Lua object into a GCObject */
-#define obj2gco(v) (cast(GCObject *, (v)))
-
-
-LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
-LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
-
-#endif
-
diff --git a/lib/lua/lstring.c b/lib/lua/lstring.c
deleted file mode 100644
index 4911315..0000000
--- a/lib/lua/lstring.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
-** String table (keeps all strings handled by Lua)
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lstring_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-
-
-
-void luaS_resize (lua_State *L, int newsize) {
- GCObject **newhash;
- stringtable *tb;
- int i;
- if (G(L)->gcstate == GCSsweepstring)
- return; /* cannot resize during GC traverse */
- newhash = luaM_newvector(L, newsize, GCObject *);
- tb = &G(L)->strt;
- for (i=0; isize; i++) {
- GCObject *p = tb->hash[i];
- while (p) { /* for each node in the list */
- GCObject *next = p->gch.next; /* save next */
- unsigned int h = gco2ts(p)->hash;
- int h1 = lmod(h, newsize); /* new position */
- lua_assert(cast_int(h%newsize) == lmod(h, newsize));
- p->gch.next = newhash[h1]; /* chain it */
- newhash[h1] = p;
- p = next;
- }
- }
- luaM_freearray(L, tb->hash, tb->size, TString *);
- tb->size = newsize;
- tb->hash = newhash;
-}
-
-
-static TString *newlstr (lua_State *L, const char *str, size_t l,
- unsigned int h) {
- TString *ts;
- stringtable *tb;
- if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
- luaM_toobig(L);
- ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
- ts->tsv.len = l;
- ts->tsv.hash = h;
- ts->tsv.marked = luaC_white(G(L));
- ts->tsv.tt = LUA_TSTRING;
- ts->tsv.reserved = 0;
- memcpy(ts+1, str, l*sizeof(char));
- ((char *)(ts+1))[l] = '\0'; /* ending 0 */
- tb = &G(L)->strt;
- h = lmod(h, tb->size);
- ts->tsv.next = tb->hash[h]; /* chain new entry */
- tb->hash[h] = obj2gco(ts);
- tb->nuse++;
- if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
- luaS_resize(L, tb->size*2); /* too crowded */
- return ts;
-}
-
-
-TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
- GCObject *o;
- unsigned int h = cast(unsigned int, l); /* seed */
- size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
- size_t l1;
- for (l1=l; l1>=step; l1-=step) /* compute hash */
- h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
- for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
- o != NULL;
- o = o->gch.next) {
- TString *ts = rawgco2ts(o);
- if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
- /* string may be dead */
- if (isdead(G(L), o)) changewhite(o);
- return ts;
- }
- }
- return newlstr(L, str, l, h); /* not found */
-}
-
-
-Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
- Udata *u;
- if (s > MAX_SIZET - sizeof(Udata))
- luaM_toobig(L);
- u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
- u->uv.marked = luaC_white(G(L)); /* is not finalized */
- u->uv.tt = LUA_TUSERDATA;
- u->uv.len = s;
- u->uv.metatable = NULL;
- u->uv.env = e;
- /* chain it on udata list (after main thread) */
- u->uv.next = G(L)->mainthread->next;
- G(L)->mainthread->next = obj2gco(u);
- return u;
-}
-
diff --git a/lib/lua/lstring.h b/lib/lua/lstring.h
deleted file mode 100644
index 73a2ff8..0000000
--- a/lib/lua/lstring.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
-** String table (keep all strings handled by Lua)
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lstring_h
-#define lstring_h
-
-
-#include "lgc.h"
-#include "lobject.h"
-#include "lstate.h"
-
-
-#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
-
-#define sizeudata(u) (sizeof(union Udata)+(u)->len)
-
-#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
-#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
- (sizeof(s)/sizeof(char))-1))
-
-#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
-
-LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
-LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
-LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
-
-
-#endif
diff --git a/lib/lua/lstrlib.c b/lib/lua/lstrlib.c
deleted file mode 100644
index 1b4763d..0000000
--- a/lib/lua/lstrlib.c
+++ /dev/null
@@ -1,869 +0,0 @@
-/*
-** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $
-** Standard library for string operations and pattern-matching
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-#include
-
-#define lstrlib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-/* macro to `unsign' a character */
-#define uchar(c) ((unsigned char)(c))
-
-
-
-static int str_len (lua_State *L) {
- size_t l;
- luaL_checklstring(L, 1, &l);
- lua_pushinteger(L, l);
- return 1;
-}
-
-
-static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
- /* relative string position: negative means back from end */
- if (pos < 0) pos += (ptrdiff_t)len + 1;
- return (pos >= 0) ? pos : 0;
-}
-
-
-static int str_sub (lua_State *L) {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);
- ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);
- if (start < 1) start = 1;
- if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
- if (start <= end)
- lua_pushlstring(L, s+start-1, end-start+1);
- else lua_pushliteral(L, "");
- return 1;
-}
-
-
-static int str_reverse (lua_State *L) {
- size_t l;
- luaL_Buffer b;
- const char *s = luaL_checklstring(L, 1, &l);
- luaL_buffinit(L, &b);
- while (l--) luaL_addchar(&b, s[l]);
- luaL_pushresult(&b);
- return 1;
-}
-
-
-static int str_lower (lua_State *L) {
- size_t l;
- size_t i;
- luaL_Buffer b;
- const char *s = luaL_checklstring(L, 1, &l);
- luaL_buffinit(L, &b);
- for (i=0; i 0)
- luaL_addlstring(&b, s, l);
- luaL_pushresult(&b);
- return 1;
-}
-
-
-static int str_byte (lua_State *L) {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
- ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
- int n, i;
- if (posi <= 0) posi = 1;
- if ((size_t)pose > l) pose = l;
- if (posi > pose) return 0; /* empty interval; return no values */
- n = (int)(pose - posi + 1);
- if (posi + n <= pose) /* overflow? */
- luaL_error(L, "string slice too long");
- luaL_checkstack(L, n, "string slice too long");
- for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED)
- return luaL_error(ms->L, "invalid capture index");
- return l;
-}
-
-
-static int capture_to_close (MatchState *ms) {
- int level = ms->level;
- for (level--; level>=0; level--)
- if (ms->capture[level].len == CAP_UNFINISHED) return level;
- return luaL_error(ms->L, "invalid pattern capture");
-}
-
-
-static const char *classend (MatchState *ms, const char *p) {
- switch (*p++) {
- case L_ESC: {
- if (*p == '\0')
- luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
- return p+1;
- }
- case '[': {
- if (*p == '^') p++;
- do { /* look for a `]' */
- if (*p == '\0')
- luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
- if (*(p++) == L_ESC && *p != '\0')
- p++; /* skip escapes (e.g. `%]') */
- } while (*p != ']');
- return p+1;
- }
- default: {
- return p;
- }
- }
-}
-
-
-static int match_class (int c, int cl) {
- int res;
- switch (tolower(cl)) {
- case 'a' : res = isalpha(c); break;
- case 'c' : res = iscntrl(c); break;
- case 'd' : res = isdigit(c); break;
- case 'l' : res = islower(c); break;
- case 'p' : res = ispunct(c); break;
- case 's' : res = isspace(c); break;
- case 'u' : res = isupper(c); break;
- case 'w' : res = isalnum(c); break;
- case 'x' : res = isxdigit(c); break;
- case 'z' : res = (c == 0); break;
- default: return (cl == c);
- }
- return (islower(cl) ? res : !res);
-}
-
-
-static int matchbracketclass (int c, const char *p, const char *ec) {
- int sig = 1;
- if (*(p+1) == '^') {
- sig = 0;
- p++; /* skip the `^' */
- }
- while (++p < ec) {
- if (*p == L_ESC) {
- p++;
- if (match_class(c, uchar(*p)))
- return sig;
- }
- else if ((*(p+1) == '-') && (p+2 < ec)) {
- p+=2;
- if (uchar(*(p-2)) <= c && c <= uchar(*p))
- return sig;
- }
- else if (uchar(*p) == c) return sig;
- }
- return !sig;
-}
-
-
-static int singlematch (int c, const char *p, const char *ep) {
- switch (*p) {
- case '.': return 1; /* matches any char */
- case L_ESC: return match_class(c, uchar(*(p+1)));
- case '[': return matchbracketclass(c, p, ep-1);
- default: return (uchar(*p) == c);
- }
-}
-
-
-static const char *match (MatchState *ms, const char *s, const char *p);
-
-
-static const char *matchbalance (MatchState *ms, const char *s,
- const char *p) {
- if (*p == 0 || *(p+1) == 0)
- luaL_error(ms->L, "unbalanced pattern");
- if (*s != *p) return NULL;
- else {
- int b = *p;
- int e = *(p+1);
- int cont = 1;
- while (++s < ms->src_end) {
- if (*s == e) {
- if (--cont == 0) return s+1;
- }
- else if (*s == b) cont++;
- }
- }
- return NULL; /* string ends out of balance */
-}
-
-
-static const char *max_expand (MatchState *ms, const char *s,
- const char *p, const char *ep) {
- ptrdiff_t i = 0; /* counts maximum expand for item */
- while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep))
- i++;
- /* keeps trying to match with the maximum repetitions */
- while (i>=0) {
- const char *res = match(ms, (s+i), ep+1);
- if (res) return res;
- i--; /* else didn't match; reduce 1 repetition to try again */
- }
- return NULL;
-}
-
-
-static const char *min_expand (MatchState *ms, const char *s,
- const char *p, const char *ep) {
- for (;;) {
- const char *res = match(ms, s, ep+1);
- if (res != NULL)
- return res;
- else if (ssrc_end && singlematch(uchar(*s), p, ep))
- s++; /* try with one more repetition */
- else return NULL;
- }
-}
-
-
-static const char *start_capture (MatchState *ms, const char *s,
- const char *p, int what) {
- const char *res;
- int level = ms->level;
- if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
- ms->capture[level].init = s;
- ms->capture[level].len = what;
- ms->level = level+1;
- if ((res=match(ms, s, p)) == NULL) /* match failed? */
- ms->level--; /* undo capture */
- return res;
-}
-
-
-static const char *end_capture (MatchState *ms, const char *s,
- const char *p) {
- int l = capture_to_close(ms);
- const char *res;
- ms->capture[l].len = s - ms->capture[l].init; /* close capture */
- if ((res = match(ms, s, p)) == NULL) /* match failed? */
- ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
- return res;
-}
-
-
-static const char *match_capture (MatchState *ms, const char *s, int l) {
- size_t len;
- l = check_capture(ms, l);
- len = ms->capture[l].len;
- if ((size_t)(ms->src_end-s) >= len &&
- memcmp(ms->capture[l].init, s, len) == 0)
- return s+len;
- else return NULL;
-}
-
-
-static const char *match (MatchState *ms, const char *s, const char *p) {
- init: /* using goto's to optimize tail recursion */
- switch (*p) {
- case '(': { /* start capture */
- if (*(p+1) == ')') /* position capture? */
- return start_capture(ms, s, p+2, CAP_POSITION);
- else
- return start_capture(ms, s, p+1, CAP_UNFINISHED);
- }
- case ')': { /* end capture */
- return end_capture(ms, s, p+1);
- }
- case L_ESC: {
- switch (*(p+1)) {
- case 'b': { /* balanced string? */
- s = matchbalance(ms, s, p+2);
- if (s == NULL) return NULL;
- p+=4; goto init; /* else return match(ms, s, p+4); */
- }
- case 'f': { /* frontier? */
- const char *ep; char previous;
- p += 2;
- if (*p != '[')
- luaL_error(ms->L, "missing " LUA_QL("[") " after "
- LUA_QL("%%f") " in pattern");
- ep = classend(ms, p); /* points to what is next */
- previous = (s == ms->src_init) ? '\0' : *(s-1);
- if (matchbracketclass(uchar(previous), p, ep-1) ||
- !matchbracketclass(uchar(*s), p, ep-1)) return NULL;
- p=ep; goto init; /* else return match(ms, s, ep); */
- }
- default: {
- if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
- s = match_capture(ms, s, uchar(*(p+1)));
- if (s == NULL) return NULL;
- p+=2; goto init; /* else return match(ms, s, p+2) */
- }
- goto dflt; /* case default */
- }
- }
- }
- case '\0': { /* end of pattern */
- return s; /* match succeeded */
- }
- case '$': {
- if (*(p+1) == '\0') /* is the `$' the last char in pattern? */
- return (s == ms->src_end) ? s : NULL; /* check end of string */
- else goto dflt;
- }
- default: dflt: { /* it is a pattern item */
- const char *ep = classend(ms, p); /* points to what is next */
- int m = ssrc_end && singlematch(uchar(*s), p, ep);
- switch (*ep) {
- case '?': { /* optional */
- const char *res;
- if (m && ((res=match(ms, s+1, ep+1)) != NULL))
- return res;
- p=ep+1; goto init; /* else return match(ms, s, ep+1); */
- }
- case '*': { /* 0 or more repetitions */
- return max_expand(ms, s, p, ep);
- }
- case '+': { /* 1 or more repetitions */
- return (m ? max_expand(ms, s+1, p, ep) : NULL);
- }
- case '-': { /* 0 or more repetitions (minimum) */
- return min_expand(ms, s, p, ep);
- }
- default: {
- if (!m) return NULL;
- s++; p=ep; goto init; /* else return match(ms, s+1, ep); */
- }
- }
- }
- }
-}
-
-
-
-static const char *lmemfind (const char *s1, size_t l1,
- const char *s2, size_t l2) {
- if (l2 == 0) return s1; /* empty strings are everywhere */
- else if (l2 > l1) return NULL; /* avoids a negative `l1' */
- else {
- const char *init; /* to search for a `*s2' inside `s1' */
- l2--; /* 1st char will be checked by `memchr' */
- l1 = l1-l2; /* `s2' cannot be found after that */
- while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
- init++; /* 1st char is already checked */
- if (memcmp(init, s2+1, l2) == 0)
- return init-1;
- else { /* correct `l1' and `s1' to try again */
- l1 -= init-s1;
- s1 = init;
- }
- }
- return NULL; /* not found */
- }
-}
-
-
-static void push_onecapture (MatchState *ms, int i, const char *s,
- const char *e) {
- if (i >= ms->level) {
- if (i == 0) /* ms->level == 0, too */
- lua_pushlstring(ms->L, s, e - s); /* add whole match */
- else
- luaL_error(ms->L, "invalid capture index");
- }
- else {
- ptrdiff_t l = ms->capture[i].len;
- if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
- if (l == CAP_POSITION)
- lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
- else
- lua_pushlstring(ms->L, ms->capture[i].init, l);
- }
-}
-
-
-static int push_captures (MatchState *ms, const char *s, const char *e) {
- int i;
- int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
- luaL_checkstack(ms->L, nlevels, "too many captures");
- for (i = 0; i < nlevels; i++)
- push_onecapture(ms, i, s, e);
- return nlevels; /* number of strings pushed */
-}
-
-
-static int str_find_aux (lua_State *L, int find) {
- size_t l1, l2;
- const char *s = luaL_checklstring(L, 1, &l1);
- const char *p = luaL_checklstring(L, 2, &l2);
- ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
- if (init < 0) init = 0;
- else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
- if (find && (lua_toboolean(L, 4) || /* explicit request? */
- strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
- /* do a plain search */
- const char *s2 = lmemfind(s+init, l1-init, p, l2);
- if (s2) {
- lua_pushinteger(L, s2-s+1);
- lua_pushinteger(L, s2-s+l2);
- return 2;
- }
- }
- else {
- MatchState ms;
- int anchor = (*p == '^') ? (p++, 1) : 0;
- const char *s1=s+init;
- ms.L = L;
- ms.src_init = s;
- ms.src_end = s+l1;
- do {
- const char *res;
- ms.level = 0;
- if ((res=match(&ms, s1, p)) != NULL) {
- if (find) {
- lua_pushinteger(L, s1-s+1); /* start */
- lua_pushinteger(L, res-s); /* end */
- return push_captures(&ms, NULL, 0) + 2;
- }
- else
- return push_captures(&ms, s1, res);
- }
- } while (s1++ < ms.src_end && !anchor);
- }
- lua_pushnil(L); /* not found */
- return 1;
-}
-
-
-static int str_find (lua_State *L) {
- return str_find_aux(L, 1);
-}
-
-
-static int str_match (lua_State *L) {
- return str_find_aux(L, 0);
-}
-
-
-static int gmatch_aux (lua_State *L) {
- MatchState ms;
- size_t ls;
- const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
- const char *p = lua_tostring(L, lua_upvalueindex(2));
- const char *src;
- ms.L = L;
- ms.src_init = s;
- ms.src_end = s+ls;
- for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
- src <= ms.src_end;
- src++) {
- const char *e;
- ms.level = 0;
- if ((e = match(&ms, src, p)) != NULL) {
- lua_Integer newstart = e-s;
- if (e == src) newstart++; /* empty match? go at least one position */
- lua_pushinteger(L, newstart);
- lua_replace(L, lua_upvalueindex(3));
- return push_captures(&ms, src, e);
- }
- }
- return 0; /* not found */
-}
-
-
-static int gmatch (lua_State *L) {
- luaL_checkstring(L, 1);
- luaL_checkstring(L, 2);
- lua_settop(L, 2);
- lua_pushinteger(L, 0);
- lua_pushcclosure(L, gmatch_aux, 3);
- return 1;
-}
-
-
-static int gfind_nodef (lua_State *L) {
- return luaL_error(L, LUA_QL("string.gfind") " was renamed to "
- LUA_QL("string.gmatch"));
-}
-
-
-static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
- const char *e) {
- size_t l, i;
- const char *news = lua_tolstring(ms->L, 3, &l);
- for (i = 0; i < l; i++) {
- if (news[i] != L_ESC)
- luaL_addchar(b, news[i]);
- else {
- i++; /* skip ESC */
- if (!isdigit(uchar(news[i])))
- luaL_addchar(b, news[i]);
- else if (news[i] == '0')
- luaL_addlstring(b, s, e - s);
- else {
- push_onecapture(ms, news[i] - '1', s, e);
- luaL_addvalue(b); /* add capture to accumulated result */
- }
- }
- }
-}
-
-
-static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
- const char *e) {
- lua_State *L = ms->L;
- switch (lua_type(L, 3)) {
- case LUA_TNUMBER:
- case LUA_TSTRING: {
- add_s(ms, b, s, e);
- return;
- }
- case LUA_TFUNCTION: {
- int n;
- lua_pushvalue(L, 3);
- n = push_captures(ms, s, e);
- lua_call(L, n, 1);
- break;
- }
- case LUA_TTABLE: {
- push_onecapture(ms, 0, s, e);
- lua_gettable(L, 3);
- break;
- }
- }
- if (!lua_toboolean(L, -1)) { /* nil or false? */
- lua_pop(L, 1);
- lua_pushlstring(L, s, e - s); /* keep original text */
- }
- else if (!lua_isstring(L, -1))
- luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
- luaL_addvalue(b); /* add result to accumulator */
-}
-
-
-static int str_gsub (lua_State *L) {
- size_t srcl;
- const char *src = luaL_checklstring(L, 1, &srcl);
- const char *p = luaL_checkstring(L, 2);
- int tr = lua_type(L, 3);
- int max_s = luaL_optint(L, 4, srcl+1);
- int anchor = (*p == '^') ? (p++, 1) : 0;
- int n = 0;
- MatchState ms;
- luaL_Buffer b;
- luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
- tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
- "string/function/table expected");
- luaL_buffinit(L, &b);
- ms.L = L;
- ms.src_init = src;
- ms.src_end = src+srcl;
- while (n < max_s) {
- const char *e;
- ms.level = 0;
- e = match(&ms, src, p);
- if (e) {
- n++;
- add_value(&ms, &b, src, e);
- }
- if (e && e>src) /* non empty match? */
- src = e; /* skip it */
- else if (src < ms.src_end)
- luaL_addchar(&b, *src++);
- else break;
- if (anchor) break;
- }
- luaL_addlstring(&b, src, ms.src_end-src);
- luaL_pushresult(&b);
- lua_pushinteger(L, n); /* number of substitutions */
- return 2;
-}
-
-/* }====================================================== */
-
-
-/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
-#define MAX_ITEM 512
-/* valid flags in a format specification */
-#define FLAGS "-+ #0"
-/*
-** maximum size of each format specification (such as '%-099.99d')
-** (+10 accounts for %99.99x plus margin of error)
-*/
-#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
-
-
-static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- luaL_addchar(b, '"');
- while (l--) {
- switch (*s) {
- case '"': case '\\': case '\n': {
- luaL_addchar(b, '\\');
- luaL_addchar(b, *s);
- break;
- }
- case '\r': {
- luaL_addlstring(b, "\\r", 2);
- break;
- }
- case '\0': {
- luaL_addlstring(b, "\\000", 4);
- break;
- }
- default: {
- luaL_addchar(b, *s);
- break;
- }
- }
- s++;
- }
- luaL_addchar(b, '"');
-}
-
-static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
- const char *p = strfrmt;
- while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
- if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
- luaL_error(L, "invalid format (repeated flags)");
- if (isdigit(uchar(*p))) p++; /* skip width */
- if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
- if (*p == '.') {
- p++;
- if (isdigit(uchar(*p))) p++; /* skip precision */
- if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
- }
- if (isdigit(uchar(*p)))
- luaL_error(L, "invalid format (width or precision too long)");
- *(form++) = '%';
- strncpy(form, strfrmt, p - strfrmt + 1);
- form += p - strfrmt + 1;
- *form = '\0';
- return p;
-}
-
-
-static void addintlen (char *form) {
- size_t l = strlen(form);
- char spec = form[l - 1];
- strcpy(form + l - 1, LUA_INTFRMLEN);
- form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
- form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
-}
-
-
-static int str_format (lua_State *L) {
- int arg = 1;
- size_t sfl;
- const char *strfrmt = luaL_checklstring(L, arg, &sfl);
- const char *strfrmt_end = strfrmt+sfl;
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- while (strfrmt < strfrmt_end) {
- if (*strfrmt != L_ESC)
- luaL_addchar(&b, *strfrmt++);
- else if (*++strfrmt == L_ESC)
- luaL_addchar(&b, *strfrmt++); /* %% */
- else { /* format item */
- char form[MAX_FORMAT]; /* to store the format (`%...') */
- char buff[MAX_ITEM]; /* to store the formatted item */
- arg++;
- strfrmt = scanformat(L, strfrmt, form);
- switch (*strfrmt++) {
- case 'c': {
- sprintf(buff, form, (int)luaL_checknumber(L, arg));
- break;
- }
- case 'd': case 'i': {
- addintlen(form);
- sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
- break;
- }
- case 'o': case 'u': case 'x': case 'X': {
- addintlen(form);
- sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
- break;
- }
- case 'e': case 'E': case 'f':
- case 'g': case 'G': {
- sprintf(buff, form, (double)luaL_checknumber(L, arg));
- break;
- }
- case 'q': {
- addquoted(L, &b, arg);
- continue; /* skip the 'addsize' at the end */
- }
- case 's': {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- if (!strchr(form, '.') && l >= 100) {
- /* no precision and string is too long to be formatted;
- keep original string */
- lua_pushvalue(L, arg);
- luaL_addvalue(&b);
- continue; /* skip the `addsize' at the end */
- }
- else {
- sprintf(buff, form, s);
- break;
- }
- }
- default: { /* also treat cases `pnLlh' */
- return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
- LUA_QL("format"), *(strfrmt - 1));
- }
- }
- luaL_addlstring(&b, buff, strlen(buff));
- }
- }
- luaL_pushresult(&b);
- return 1;
-}
-
-
-static const luaL_Reg strlib[] = {
- {"byte", str_byte},
- {"char", str_char},
- {"dump", str_dump},
- {"find", str_find},
- {"format", str_format},
- {"gfind", gfind_nodef},
- {"gmatch", gmatch},
- {"gsub", str_gsub},
- {"len", str_len},
- {"lower", str_lower},
- {"match", str_match},
- {"rep", str_rep},
- {"reverse", str_reverse},
- {"sub", str_sub},
- {"upper", str_upper},
- {NULL, NULL}
-};
-
-
-static void createmetatable (lua_State *L) {
- lua_createtable(L, 0, 1); /* create metatable for strings */
- lua_pushliteral(L, ""); /* dummy string */
- lua_pushvalue(L, -2);
- lua_setmetatable(L, -2); /* set string metatable */
- lua_pop(L, 1); /* pop dummy string */
- lua_pushvalue(L, -2); /* string library... */
- lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */
- lua_pop(L, 1); /* pop metatable */
-}
-
-
-/*
-** Open string library
-*/
-LUALIB_API int luaopen_string (lua_State *L) {
- luaL_register(L, LUA_STRLIBNAME, strlib);
-#if defined(LUA_COMPAT_GFIND)
- lua_getfield(L, -1, "gmatch");
- lua_setfield(L, -2, "gfind");
-#endif
- createmetatable(L);
- return 1;
-}
-
diff --git a/lib/lua/ltable.c b/lib/lua/ltable.c
deleted file mode 100644
index ec84f4f..0000000
--- a/lib/lua/ltable.c
+++ /dev/null
@@ -1,588 +0,0 @@
-/*
-** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $
-** Lua tables (hash)
-** See Copyright Notice in lua.h
-*/
-
-
-/*
-** Implementation of tables (aka arrays, objects, or hash tables).
-** Tables keep its elements in two parts: an array part and a hash part.
-** Non-negative integer keys are all candidates to be kept in the array
-** part. The actual size of the array is the largest `n' such that at
-** least half the slots between 0 and n are in use.
-** Hash uses a mix of chained scatter table with Brent's variation.
-** A main invariant of these tables is that, if an element is not
-** in its main position (i.e. the `original' position that its hash gives
-** to it), then the colliding element is in its own main position.
-** Hence even when the load factor reaches 100%, performance remains good.
-*/
-
-#include
-#include
-
-#define ltable_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "ltable.h"
-
-
-/*
-** max size of array part is 2^MAXBITS
-*/
-#if LUAI_BITSINT > 26
-#define MAXBITS 26
-#else
-#define MAXBITS (LUAI_BITSINT-2)
-#endif
-
-#define MAXASIZE (1 << MAXBITS)
-
-
-#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
-
-#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
-#define hashboolean(t,p) hashpow2(t, p)
-
-
-/*
-** for some types, it is better to avoid modulus by power of 2, as
-** they tend to have many 2 factors.
-*/
-#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
-
-
-#define hashpointer(t,p) hashmod(t, IntPoint(p))
-
-
-/*
-** number of ints inside a lua_Number
-*/
-#define numints cast_int(sizeof(lua_Number)/sizeof(int))
-
-
-
-#define dummynode (&dummynode_)
-
-static const Node dummynode_ = {
- {{NULL}, LUA_TNIL}, /* value */
- {{{NULL}, LUA_TNIL, NULL}} /* key */
-};
-
-
-/*
-** hash for lua_Numbers
-*/
-static Node *hashnum (const Table *t, lua_Number n) {
- unsigned int a[numints];
- int i;
- if (luai_numeq(n, 0)) /* avoid problems with -0 */
- return gnode(t, 0);
- memcpy(a, &n, sizeof(a));
- for (i = 1; i < numints; i++) a[0] += a[i];
- return hashmod(t, a[0]);
-}
-
-
-
-/*
-** returns the `main' position of an element in a table (that is, the index
-** of its hash value)
-*/
-static Node *mainposition (const Table *t, const TValue *key) {
- switch (ttype(key)) {
- case LUA_TNUMBER:
- return hashnum(t, nvalue(key));
- case LUA_TSTRING:
- return hashstr(t, rawtsvalue(key));
- case LUA_TBOOLEAN:
- return hashboolean(t, bvalue(key));
- case LUA_TLIGHTUSERDATA:
- return hashpointer(t, pvalue(key));
- default:
- return hashpointer(t, gcvalue(key));
- }
-}
-
-
-/*
-** returns the index for `key' if `key' is an appropriate key to live in
-** the array part of the table, -1 otherwise.
-*/
-static int arrayindex (const TValue *key) {
- if (ttisnumber(key)) {
- lua_Number n = nvalue(key);
- int k;
- lua_number2int(k, n);
- if (luai_numeq(cast_num(k), n))
- return k;
- }
- return -1; /* `key' did not match some condition */
-}
-
-
-/*
-** returns the index of a `key' for table traversals. First goes all
-** elements in the array part, then elements in the hash part. The
-** beginning of a traversal is signalled by -1.
-*/
-static int findindex (lua_State *L, Table *t, StkId key) {
- int i;
- if (ttisnil(key)) return -1; /* first iteration */
- i = arrayindex(key);
- if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
- return i-1; /* yes; that's the index (corrected to C) */
- else {
- Node *n = mainposition(t, key);
- do { /* check whether `key' is somewhere in the chain */
- /* key may be dead already, but it is ok to use it in `next' */
- if (luaO_rawequalObj(key2tval(n), key) ||
- (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
- gcvalue(gkey(n)) == gcvalue(key))) {
- i = cast_int(n - gnode(t, 0)); /* key index in hash table */
- /* hash elements are numbered after array ones */
- return i + t->sizearray;
- }
- else n = gnext(n);
- } while (n);
- luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
- return 0; /* to avoid warnings */
- }
-}
-
-
-int luaH_next (lua_State *L, Table *t, StkId key) {
- int i = findindex(L, t, key); /* find original element */
- for (i++; i < t->sizearray; i++) { /* try first array part */
- if (!ttisnil(&t->array[i])) { /* a non-nil value? */
- setnvalue(key, cast_num(i+1));
- setobj2s(L, key+1, &t->array[i]);
- return 1;
- }
- }
- for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
- if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
- setobj2s(L, key, key2tval(gnode(t, i)));
- setobj2s(L, key+1, gval(gnode(t, i)));
- return 1;
- }
- }
- return 0; /* no more elements */
-}
-
-
-/*
-** {=============================================================
-** Rehash
-** ==============================================================
-*/
-
-
-static int computesizes (int nums[], int *narray) {
- int i;
- int twotoi; /* 2^i */
- int a = 0; /* number of elements smaller than 2^i */
- int na = 0; /* number of elements to go to array part */
- int n = 0; /* optimal size for array part */
- for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
- if (nums[i] > 0) {
- a += nums[i];
- if (a > twotoi/2) { /* more than half elements present? */
- n = twotoi; /* optimal size (till now) */
- na = a; /* all elements smaller than n will go to array part */
- }
- }
- if (a == *narray) break; /* all elements already counted */
- }
- *narray = n;
- lua_assert(*narray/2 <= na && na <= *narray);
- return na;
-}
-
-
-static int countint (const TValue *key, int *nums) {
- int k = arrayindex(key);
- if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
- nums[ceillog2(k)]++; /* count as such */
- return 1;
- }
- else
- return 0;
-}
-
-
-static int numusearray (const Table *t, int *nums) {
- int lg;
- int ttlg; /* 2^lg */
- int ause = 0; /* summation of `nums' */
- int i = 1; /* count to traverse all array keys */
- for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
- int lc = 0; /* counter */
- int lim = ttlg;
- if (lim > t->sizearray) {
- lim = t->sizearray; /* adjust upper limit */
- if (i > lim)
- break; /* no more elements to count */
- }
- /* count elements in range (2^(lg-1), 2^lg] */
- for (; i <= lim; i++) {
- if (!ttisnil(&t->array[i-1]))
- lc++;
- }
- nums[lg] += lc;
- ause += lc;
- }
- return ause;
-}
-
-
-static int numusehash (const Table *t, int *nums, int *pnasize) {
- int totaluse = 0; /* total number of elements */
- int ause = 0; /* summation of `nums' */
- int i = sizenode(t);
- while (i--) {
- Node *n = &t->node[i];
- if (!ttisnil(gval(n))) {
- ause += countint(key2tval(n), nums);
- totaluse++;
- }
- }
- *pnasize += ause;
- return totaluse;
-}
-
-
-static void setarrayvector (lua_State *L, Table *t, int size) {
- int i;
- luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
- for (i=t->sizearray; iarray[i]);
- t->sizearray = size;
-}
-
-
-static void setnodevector (lua_State *L, Table *t, int size) {
- int lsize;
- if (size == 0) { /* no elements to hash part? */
- t->node = cast(Node *, dummynode); /* use common `dummynode' */
- lsize = 0;
- }
- else {
- int i;
- lsize = ceillog2(size);
- if (lsize > MAXBITS)
- luaG_runerror(L, "table overflow");
- size = twoto(lsize);
- t->node = luaM_newvector(L, size, Node);
- for (i=0; ilsizenode = cast_byte(lsize);
- t->lastfree = gnode(t, size); /* all positions are free */
-}
-
-
-static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
- int i;
- int oldasize = t->sizearray;
- int oldhsize = t->lsizenode;
- Node *nold = t->node; /* save old hash ... */
- if (nasize > oldasize) /* array part must grow? */
- setarrayvector(L, t, nasize);
- /* create new hash part with appropriate size */
- setnodevector(L, t, nhsize);
- if (nasize < oldasize) { /* array part must shrink? */
- t->sizearray = nasize;
- /* re-insert elements from vanishing slice */
- for (i=nasize; iarray[i]))
- setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
- }
- /* shrink array */
- luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
- }
- /* re-insert elements from hash part */
- for (i = twoto(oldhsize) - 1; i >= 0; i--) {
- Node *old = nold+i;
- if (!ttisnil(gval(old)))
- setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
- }
- if (nold != dummynode)
- luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
-}
-
-
-void luaH_resizearray (lua_State *L, Table *t, int nasize) {
- int nsize = (t->node == dummynode) ? 0 : sizenode(t);
- resize(L, t, nasize, nsize);
-}
-
-
-static void rehash (lua_State *L, Table *t, const TValue *ek) {
- int nasize, na;
- int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */
- int i;
- int totaluse;
- for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */
- nasize = numusearray(t, nums); /* count keys in array part */
- totaluse = nasize; /* all those keys are integer keys */
- totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
- /* count extra key */
- nasize += countint(ek, nums);
- totaluse++;
- /* compute new size for array part */
- na = computesizes(nums, &nasize);
- /* resize the table to new computed sizes */
- resize(L, t, nasize, totaluse - na);
-}
-
-
-
-/*
-** }=============================================================
-*/
-
-
-Table *luaH_new (lua_State *L, int narray, int nhash) {
- Table *t = luaM_new(L, Table);
- luaC_link(L, obj2gco(t), LUA_TTABLE);
- t->metatable = NULL;
- t->flags = cast_byte(~0);
- /* temporary values (kept only if some malloc fails) */
- t->array = NULL;
- t->sizearray = 0;
- t->lsizenode = 0;
- t->node = cast(Node *, dummynode);
- setarrayvector(L, t, narray);
- setnodevector(L, t, nhash);
- return t;
-}
-
-
-void luaH_free (lua_State *L, Table *t) {
- if (t->node != dummynode)
- luaM_freearray(L, t->node, sizenode(t), Node);
- luaM_freearray(L, t->array, t->sizearray, TValue);
- luaM_free(L, t);
-}
-
-
-static Node *getfreepos (Table *t) {
- while (t->lastfree-- > t->node) {
- if (ttisnil(gkey(t->lastfree)))
- return t->lastfree;
- }
- return NULL; /* could not find a free place */
-}
-
-
-
-/*
-** inserts a new key into a hash table; first, check whether key's main
-** position is free. If not, check whether colliding node is in its main
-** position or not: if it is not, move colliding node to an empty place and
-** put new key in its main position; otherwise (colliding node is in its main
-** position), new key goes to an empty position.
-*/
-static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
- Node *mp = mainposition(t, key);
- if (!ttisnil(gval(mp)) || mp == dummynode) {
- Node *othern;
- Node *n = getfreepos(t); /* get a free place */
- if (n == NULL) { /* cannot find a free place? */
- rehash(L, t, key); /* grow table */
- return luaH_set(L, t, key); /* re-insert key into grown table */
- }
- lua_assert(n != dummynode);
- othern = mainposition(t, key2tval(mp));
- if (othern != mp) { /* is colliding node out of its main position? */
- /* yes; move colliding node into free position */
- while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
- gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
- *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
- gnext(mp) = NULL; /* now `mp' is free */
- setnilvalue(gval(mp));
- }
- else { /* colliding node is in its own main position */
- /* new node will go into free position */
- gnext(n) = gnext(mp); /* chain new position */
- gnext(mp) = n;
- mp = n;
- }
- }
- gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;
- luaC_barriert(L, t, key);
- lua_assert(ttisnil(gval(mp)));
- return gval(mp);
-}
-
-
-/*
-** search function for integers
-*/
-const TValue *luaH_getnum (Table *t, int key) {
- /* (1 <= key && key <= t->sizearray) */
- if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
- return &t->array[key-1];
- else {
- lua_Number nk = cast_num(key);
- Node *n = hashnum(t, nk);
- do { /* check whether `key' is somewhere in the chain */
- if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
- }
-}
-
-
-/*
-** search function for strings
-*/
-const TValue *luaH_getstr (Table *t, TString *key) {
- Node *n = hashstr(t, key);
- do { /* check whether `key' is somewhere in the chain */
- if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
-}
-
-
-/*
-** main search function
-*/
-const TValue *luaH_get (Table *t, const TValue *key) {
- switch (ttype(key)) {
- case LUA_TNIL: return luaO_nilobject;
- case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
- case LUA_TNUMBER: {
- int k;
- lua_Number n = nvalue(key);
- lua_number2int(k, n);
- if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
- return luaH_getnum(t, k); /* use specialized version */
- /* else go through */
- }
- default: {
- Node *n = mainposition(t, key);
- do { /* check whether `key' is somewhere in the chain */
- if (luaO_rawequalObj(key2tval(n), key))
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
- }
- }
-}
-
-
-TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
- const TValue *p = luaH_get(t, key);
- t->flags = 0;
- if (p != luaO_nilobject)
- return cast(TValue *, p);
- else {
- if (ttisnil(key)) luaG_runerror(L, "table index is nil");
- else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
- luaG_runerror(L, "table index is NaN");
- return newkey(L, t, key);
- }
-}
-
-
-TValue *luaH_setnum (lua_State *L, Table *t, int key) {
- const TValue *p = luaH_getnum(t, key);
- if (p != luaO_nilobject)
- return cast(TValue *, p);
- else {
- TValue k;
- setnvalue(&k, cast_num(key));
- return newkey(L, t, &k);
- }
-}
-
-
-TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
- const TValue *p = luaH_getstr(t, key);
- if (p != luaO_nilobject)
- return cast(TValue *, p);
- else {
- TValue k;
- setsvalue(L, &k, key);
- return newkey(L, t, &k);
- }
-}
-
-
-static int unbound_search (Table *t, unsigned int j) {
- unsigned int i = j; /* i is zero or a present index */
- j++;
- /* find `i' and `j' such that i is present and j is not */
- while (!ttisnil(luaH_getnum(t, j))) {
- i = j;
- j *= 2;
- if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
- /* table was built with bad purposes: resort to linear search */
- i = 1;
- while (!ttisnil(luaH_getnum(t, i))) i++;
- return i - 1;
- }
- }
- /* now do a binary search between them */
- while (j - i > 1) {
- unsigned int m = (i+j)/2;
- if (ttisnil(luaH_getnum(t, m))) j = m;
- else i = m;
- }
- return i;
-}
-
-
-/*
-** Try to find a boundary in table `t'. A `boundary' is an integer index
-** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
-*/
-int luaH_getn (Table *t) {
- unsigned int j = t->sizearray;
- if (j > 0 && ttisnil(&t->array[j - 1])) {
- /* there is a boundary in the array part: (binary) search for it */
- unsigned int i = 0;
- while (j - i > 1) {
- unsigned int m = (i+j)/2;
- if (ttisnil(&t->array[m - 1])) j = m;
- else i = m;
- }
- return i;
- }
- /* else must find a boundary in hash part */
- else if (t->node == dummynode) /* hash part is empty? */
- return j; /* that is easy... */
- else return unbound_search(t, j);
-}
-
-
-
-#if defined(LUA_DEBUG)
-
-Node *luaH_mainposition (const Table *t, const TValue *key) {
- return mainposition(t, key);
-}
-
-int luaH_isdummy (Node *n) { return n == dummynode; }
-
-#endif
diff --git a/lib/lua/ltable.h b/lib/lua/ltable.h
deleted file mode 100644
index f5b9d5e..0000000
--- a/lib/lua/ltable.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lua tables (hash)
-** See Copyright Notice in lua.h
-*/
-
-#ifndef ltable_h
-#define ltable_h
-
-#include "lobject.h"
-
-
-#define gnode(t,i) (&(t)->node[i])
-#define gkey(n) (&(n)->i_key.nk)
-#define gval(n) (&(n)->i_val)
-#define gnext(n) ((n)->i_key.nk.next)
-
-#define key2tval(n) (&(n)->i_key.tvk)
-
-
-LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
-LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
-LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
-LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
-LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
-LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
-LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);
-LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
-LUAI_FUNC void luaH_free (lua_State *L, Table *t);
-LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
-LUAI_FUNC int luaH_getn (Table *t);
-
-
-#if defined(LUA_DEBUG)
-LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
-LUAI_FUNC int luaH_isdummy (Node *n);
-#endif
-
-
-#endif
diff --git a/lib/lua/ltablib.c b/lib/lua/ltablib.c
deleted file mode 100644
index b6d9cb4..0000000
--- a/lib/lua/ltablib.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
-** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $
-** Library for Table Manipulation
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define ltablib_c
-#define LUA_LIB
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
-
-
-static int foreachi (lua_State *L) {
- int i;
- int n = aux_getn(L, 1);
- luaL_checktype(L, 2, LUA_TFUNCTION);
- for (i=1; i <= n; i++) {
- lua_pushvalue(L, 2); /* function */
- lua_pushinteger(L, i); /* 1st argument */
- lua_rawgeti(L, 1, i); /* 2nd argument */
- lua_call(L, 2, 1);
- if (!lua_isnil(L, -1))
- return 1;
- lua_pop(L, 1); /* remove nil result */
- }
- return 0;
-}
-
-
-static int foreach (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_checktype(L, 2, LUA_TFUNCTION);
- lua_pushnil(L); /* first key */
- while (lua_next(L, 1)) {
- lua_pushvalue(L, 2); /* function */
- lua_pushvalue(L, -3); /* key */
- lua_pushvalue(L, -3); /* value */
- lua_call(L, 2, 1);
- if (!lua_isnil(L, -1))
- return 1;
- lua_pop(L, 2); /* remove value and result */
- }
- return 0;
-}
-
-
-static int maxn (lua_State *L) {
- lua_Number max = 0;
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_pushnil(L); /* first key */
- while (lua_next(L, 1)) {
- lua_pop(L, 1); /* remove value */
- if (lua_type(L, -1) == LUA_TNUMBER) {
- lua_Number v = lua_tonumber(L, -1);
- if (v > max) max = v;
- }
- }
- lua_pushnumber(L, max);
- return 1;
-}
-
-
-static int getn (lua_State *L) {
- lua_pushinteger(L, aux_getn(L, 1));
- return 1;
-}
-
-
-static int setn (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
-#ifndef luaL_setn
- luaL_setn(L, 1, luaL_checkint(L, 2));
-#else
- luaL_error(L, LUA_QL("setn") " is obsolete");
-#endif
- lua_pushvalue(L, 1);
- return 1;
-}
-
-
-static int tinsert (lua_State *L) {
- int e = aux_getn(L, 1) + 1; /* first empty element */
- int pos; /* where to insert new element */
- switch (lua_gettop(L)) {
- case 2: { /* called with only 2 arguments */
- pos = e; /* insert new element at the end */
- break;
- }
- case 3: {
- int i;
- pos = luaL_checkint(L, 2); /* 2nd argument is the position */
- if (pos > e) e = pos; /* `grow' array if necessary */
- for (i = e; i > pos; i--) { /* move up elements */
- lua_rawgeti(L, 1, i-1);
- lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
- }
- break;
- }
- default: {
- return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
- }
- }
- luaL_setn(L, 1, e); /* new size */
- lua_rawseti(L, 1, pos); /* t[pos] = v */
- return 0;
-}
-
-
-static int tremove (lua_State *L) {
- int e = aux_getn(L, 1);
- int pos = luaL_optint(L, 2, e);
- if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
- return 0; /* nothing to remove */
- luaL_setn(L, 1, e - 1); /* t.n = n-1 */
- lua_rawgeti(L, 1, pos); /* result = t[pos] */
- for ( ;pos= P */
- while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
- if (i>u) luaL_error(L, "invalid order function for sorting");
- lua_pop(L, 1); /* remove a[i] */
- }
- /* repeat --j until a[j] <= P */
- while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
- if (j
-
-#define ltm_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-
-
-
-const char *const luaT_typenames[] = {
- "nil", "boolean", "userdata", "number",
- "string", "table", "function", "userdata", "thread",
- "proto", "upval"
-};
-
-
-void luaT_init (lua_State *L) {
- static const char *const luaT_eventname[] = { /* ORDER TM */
- "__index", "__newindex",
- "__gc", "__mode", "__eq",
- "__add", "__sub", "__mul", "__div", "__mod",
- "__pow", "__unm", "__len", "__lt", "__le",
- "__concat", "__call"
- };
- int i;
- for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]);
- luaS_fix(G(L)->tmname[i]); /* never collect these names */
- }
-}
-
-
-/*
-** function to be used with macro "fasttm": optimized for absence of
-** tag methods
-*/
-const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
- const TValue *tm = luaH_getstr(events, ename);
- lua_assert(event <= TM_EQ);
- if (ttisnil(tm)) { /* no tag method? */
- events->flags |= cast_byte(1u<metatable;
- break;
- case LUA_TUSERDATA:
- mt = uvalue(o)->metatable;
- break;
- default:
- mt = G(L)->mt[ttype(o)];
- }
- return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
-}
-
diff --git a/lib/lua/ltm.h b/lib/lua/ltm.h
deleted file mode 100644
index 64343b7..0000000
--- a/lib/lua/ltm.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
-** Tag methods
-** See Copyright Notice in lua.h
-*/
-
-#ifndef ltm_h
-#define ltm_h
-
-
-#include "lobject.h"
-
-
-/*
-* WARNING: if you change the order of this enumeration,
-* grep "ORDER TM"
-*/
-typedef enum {
- TM_INDEX,
- TM_NEWINDEX,
- TM_GC,
- TM_MODE,
- TM_EQ, /* last tag method with `fast' access */
- TM_ADD,
- TM_SUB,
- TM_MUL,
- TM_DIV,
- TM_MOD,
- TM_POW,
- TM_UNM,
- TM_LEN,
- TM_LT,
- TM_LE,
- TM_CONCAT,
- TM_CALL,
- TM_N /* number of elements in the enum */
-} TMS;
-
-
-
-#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
- ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
-
-#define fasttm(l,et,e) gfasttm(G(l), et, e)
-
-LUAI_DATA const char *const luaT_typenames[];
-
-
-LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
-LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
- TMS event);
-LUAI_FUNC void luaT_init (lua_State *L);
-
-#endif
diff --git a/lib/lua/lua.c b/lib/lua/lua.c
deleted file mode 100644
index 3a46609..0000000
--- a/lib/lua/lua.c
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
-** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
-** Lua stand-alone interpreter
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-#include
-
-#define lua_c
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-
-
-static lua_State *globalL = NULL;
-
-static const char *progname = LUA_PROGNAME;
-
-
-
-static void lstop (lua_State *L, lua_Debug *ar) {
- (void)ar; /* unused arg. */
- lua_sethook(L, NULL, 0, 0);
- luaL_error(L, "interrupted!");
-}
-
-
-static void laction (int i) {
- signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
- terminate process (default action) */
- lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
-}
-
-
-static void print_usage (void) {
- fprintf(stderr,
- "usage: %s [options] [script [args]].\n"
- "Available options are:\n"
- " -e stat execute string " LUA_QL("stat") "\n"
- " -l name require library " LUA_QL("name") "\n"
- " -i enter interactive mode after executing " LUA_QL("script") "\n"
- " -v show version information\n"
- " -- stop handling options\n"
- " - execute stdin and stop handling options\n"
- ,
- progname);
- fflush(stderr);
-}
-
-
-static void l_message (const char *pname, const char *msg) {
- if (pname) fprintf(stderr, "%s: ", pname);
- fprintf(stderr, "%s\n", msg);
- fflush(stderr);
-}
-
-
-static int report (lua_State *L, int status) {
- if (status && !lua_isnil(L, -1)) {
- const char *msg = lua_tostring(L, -1);
- if (msg == NULL) msg = "(error object is not a string)";
- l_message(progname, msg);
- lua_pop(L, 1);
- }
- return status;
-}
-
-
-static int traceback (lua_State *L) {
- if (!lua_isstring(L, 1)) /* 'message' not a string? */
- return 1; /* keep it intact */
- lua_getfield(L, LUA_GLOBALSINDEX, "debug");
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- return 1;
- }
- lua_getfield(L, -1, "traceback");
- if (!lua_isfunction(L, -1)) {
- lua_pop(L, 2);
- return 1;
- }
- lua_pushvalue(L, 1); /* pass error message */
- lua_pushinteger(L, 2); /* skip this function and traceback */
- lua_call(L, 2, 1); /* call debug.traceback */
- return 1;
-}
-
-
-static int docall (lua_State *L, int narg, int clear) {
- int status;
- int base = lua_gettop(L) - narg; /* function index */
- lua_pushcfunction(L, traceback); /* push traceback function */
- lua_insert(L, base); /* put it under chunk and args */
- signal(SIGINT, laction);
- status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
- signal(SIGINT, SIG_DFL);
- lua_remove(L, base); /* remove traceback function */
- /* force a complete garbage collection in case of errors */
- if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
- return status;
-}
-
-
-static void print_version (void) {
- l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
-}
-
-
-static int getargs (lua_State *L, char **argv, int n) {
- int narg;
- int i;
- int argc = 0;
- while (argv[argc]) argc++; /* count total number of arguments */
- narg = argc - (n + 1); /* number of arguments to the script */
- luaL_checkstack(L, narg + 3, "too many arguments to script");
- for (i=n+1; i < argc; i++)
- lua_pushstring(L, argv[i]);
- lua_createtable(L, narg, n + 1);
- for (i=0; i < argc; i++) {
- lua_pushstring(L, argv[i]);
- lua_rawseti(L, -2, i - n);
- }
- return narg;
-}
-
-
-static int dofile (lua_State *L, const char *name) {
- int status = luaL_loadfile(L, name) || docall(L, 0, 1);
- return report(L, status);
-}
-
-
-static int dostring (lua_State *L, const char *s, const char *name) {
- int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
- return report(L, status);
-}
-
-
-static int dolibrary (lua_State *L, const char *name) {
- lua_getglobal(L, "require");
- lua_pushstring(L, name);
- return report(L, docall(L, 1, 1));
-}
-
-
-static const char *get_prompt (lua_State *L, int firstline) {
- const char *p;
- lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
- p = lua_tostring(L, -1);
- if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
- lua_pop(L, 1); /* remove global */
- return p;
-}
-
-
-static int incomplete (lua_State *L, int status) {
- if (status == LUA_ERRSYNTAX) {
- size_t lmsg;
- const char *msg = lua_tolstring(L, -1, &lmsg);
- const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1);
- if (strstr(msg, LUA_QL("")) == tp) {
- lua_pop(L, 1);
- return 1;
- }
- }
- return 0; /* else... */
-}
-
-
-static int pushline (lua_State *L, int firstline) {
- char buffer[LUA_MAXINPUT];
- char *b = buffer;
- size_t l;
- const char *prmt = get_prompt(L, firstline);
- if (lua_readline(L, b, prmt) == 0)
- return 0; /* no input */
- l = strlen(b);
- if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
- b[l-1] = '\0'; /* remove it */
- if (firstline && b[0] == '=') /* first line starts with `=' ? */
- lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
- else
- lua_pushstring(L, b);
- lua_freeline(L, b);
- return 1;
-}
-
-
-static int loadline (lua_State *L) {
- int status;
- lua_settop(L, 0);
- if (!pushline(L, 1))
- return -1; /* no input */
- for (;;) { /* repeat until gets a complete line */
- status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
- if (!incomplete(L, status)) break; /* cannot try to add lines? */
- if (!pushline(L, 0)) /* no more input? */
- return -1;
- lua_pushliteral(L, "\n"); /* add a new line... */
- lua_insert(L, -2); /* ...between the two lines */
- lua_concat(L, 3); /* join them */
- }
- lua_saveline(L, 1);
- lua_remove(L, 1); /* remove line */
- return status;
-}
-
-
-static void dotty (lua_State *L) {
- int status;
- const char *oldprogname = progname;
- progname = NULL;
- while ((status = loadline(L)) != -1) {
- if (status == 0) status = docall(L, 0, 0);
- report(L, status);
- if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
- lua_getglobal(L, "print");
- lua_insert(L, 1);
- if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
- l_message(progname, lua_pushfstring(L,
- "error calling " LUA_QL("print") " (%s)",
- lua_tostring(L, -1)));
- }
- }
- lua_settop(L, 0); /* clear stack */
- fputs("\n", stdout);
- fflush(stdout);
- progname = oldprogname;
-}
-
-
-static int handle_script (lua_State *L, char **argv, int n) {
- int status;
- const char *fname;
- int narg = getargs(L, argv, n); /* collect arguments */
- lua_setglobal(L, "arg");
- fname = argv[n];
- if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
- fname = NULL; /* stdin */
- status = luaL_loadfile(L, fname);
- lua_insert(L, -(narg+1));
- if (status == 0)
- status = docall(L, narg, 0);
- else
- lua_pop(L, narg);
- return report(L, status);
-}
-
-
-/* check that argument has no extra characters at the end */
-#define notail(x) {if ((x)[2] != '\0') return -1;}
-
-
-static int collectargs (char **argv, int *pi, int *pv, int *pe) {
- int i;
- for (i = 1; argv[i] != NULL; i++) {
- if (argv[i][0] != '-') /* not an option? */
- return i;
- switch (argv[i][1]) { /* option */
- case '-':
- notail(argv[i]);
- return (argv[i+1] != NULL ? i+1 : 0);
- case '\0':
- return i;
- case 'i':
- notail(argv[i]);
- *pi = 1; /* go through */
- case 'v':
- notail(argv[i]);
- *pv = 1;
- break;
- case 'e':
- *pe = 1; /* go through */
- case 'l':
- if (argv[i][2] == '\0') {
- i++;
- if (argv[i] == NULL) return -1;
- }
- break;
- default: return -1; /* invalid option */
- }
- }
- return 0;
-}
-
-
-static int runargs (lua_State *L, char **argv, int n) {
- int i;
- for (i = 1; i < n; i++) {
- if (argv[i] == NULL) continue;
- lua_assert(argv[i][0] == '-');
- switch (argv[i][1]) { /* option */
- case 'e': {
- const char *chunk = argv[i] + 2;
- if (*chunk == '\0') chunk = argv[++i];
- lua_assert(chunk != NULL);
- if (dostring(L, chunk, "=(command line)") != 0)
- return 1;
- break;
- }
- case 'l': {
- const char *filename = argv[i] + 2;
- if (*filename == '\0') filename = argv[++i];
- lua_assert(filename != NULL);
- if (dolibrary(L, filename))
- return 1; /* stop if file fails */
- break;
- }
- default: break;
- }
- }
- return 0;
-}
-
-
-static int handle_luainit (lua_State *L) {
- const char *init = getenv(LUA_INIT);
- if (init == NULL) return 0; /* status OK */
- else if (init[0] == '@')
- return dofile(L, init+1);
- else
- return dostring(L, init, "=" LUA_INIT);
-}
-
-
-struct Smain {
- int argc;
- char **argv;
- int status;
-};
-
-
-static int pmain (lua_State *L) {
- struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
- char **argv = s->argv;
- int script;
- int has_i = 0, has_v = 0, has_e = 0;
- globalL = L;
- if (argv[0] && argv[0][0]) progname = argv[0];
- lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
- luaL_openlibs(L); /* open libraries */
- lua_gc(L, LUA_GCRESTART, 0);
- s->status = handle_luainit(L);
- if (s->status != 0) return 0;
- script = collectargs(argv, &has_i, &has_v, &has_e);
- if (script < 0) { /* invalid args? */
- print_usage();
- s->status = 1;
- return 0;
- }
- if (has_v) print_version();
- s->status = runargs(L, argv, (script > 0) ? script : s->argc);
- if (s->status != 0) return 0;
- if (script)
- s->status = handle_script(L, argv, script);
- if (s->status != 0) return 0;
- if (has_i)
- dotty(L);
- else if (script == 0 && !has_e && !has_v) {
- if (lua_stdin_is_tty()) {
- print_version();
- dotty(L);
- }
- else dofile(L, NULL); /* executes stdin as a file */
- }
- return 0;
-}
-
-
-int main (int argc, char **argv) {
- int status;
- struct Smain s;
- lua_State *L = lua_open(); /* create state */
- if (L == NULL) {
- l_message(argv[0], "cannot create state: not enough memory");
- return EXIT_FAILURE;
- }
- s.argc = argc;
- s.argv = argv;
- status = lua_cpcall(L, &pmain, &s);
- report(L, status);
- lua_close(L);
- return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
-}
-
diff --git a/lib/lua/lua.h b/lib/lua/lua.h
deleted file mode 100644
index e4bdfd3..0000000
--- a/lib/lua/lua.h
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
-** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
-** Lua - An Extensible Extension Language
-** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
-** See Copyright Notice at the end of this file
-*/
-
-
-#ifndef lua_h
-#define lua_h
-
-#include
-#include
-
-
-#include "luaconf.h"
-
-
-#define LUA_VERSION "Lua 5.1"
-#define LUA_RELEASE "Lua 5.1.4"
-#define LUA_VERSION_NUM 501
-#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
-#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
-
-
-/* mark for precompiled code (`Lua') */
-#define LUA_SIGNATURE "\033Lua"
-
-/* option for multiple returns in `lua_pcall' and `lua_call' */
-#define LUA_MULTRET (-1)
-
-
-/*
-** pseudo-indices
-*/
-#define LUA_REGISTRYINDEX (-10000)
-#define LUA_ENVIRONINDEX (-10001)
-#define LUA_GLOBALSINDEX (-10002)
-#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
-
-
-/* thread status; 0 is OK */
-#define LUA_YIELD 1
-#define LUA_ERRRUN 2
-#define LUA_ERRSYNTAX 3
-#define LUA_ERRMEM 4
-#define LUA_ERRERR 5
-
-
-typedef struct lua_State lua_State;
-
-typedef int (*lua_CFunction) (lua_State *L);
-
-
-/*
-** functions that read/write blocks when loading/dumping Lua chunks
-*/
-typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
-
-typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
-
-
-/*
-** prototype for memory-allocation functions
-*/
-typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
-
-
-/*
-** basic types
-*/
-#define LUA_TNONE (-1)
-
-#define LUA_TNIL 0
-#define LUA_TBOOLEAN 1
-#define LUA_TLIGHTUSERDATA 2
-#define LUA_TNUMBER 3
-#define LUA_TSTRING 4
-#define LUA_TTABLE 5
-#define LUA_TFUNCTION 6
-#define LUA_TUSERDATA 7
-#define LUA_TTHREAD 8
-
-
-
-/* minimum Lua stack available to a C function */
-#define LUA_MINSTACK 20
-
-
-/*
-** generic extra include file
-*/
-#if defined(LUA_USER_H)
-#include LUA_USER_H
-#endif
-
-
-/* type of numbers in Lua */
-typedef LUA_NUMBER lua_Number;
-
-
-/* type for integer functions */
-typedef LUA_INTEGER lua_Integer;
-
-
-
-/*
-** state manipulation
-*/
-LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
-LUA_API void (lua_close) (lua_State *L);
-LUA_API lua_State *(lua_newthread) (lua_State *L);
-
-LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
-
-
-/*
-** basic stack manipulation
-*/
-LUA_API int (lua_gettop) (lua_State *L);
-LUA_API void (lua_settop) (lua_State *L, int idx);
-LUA_API void (lua_pushvalue) (lua_State *L, int idx);
-LUA_API void (lua_remove) (lua_State *L, int idx);
-LUA_API void (lua_insert) (lua_State *L, int idx);
-LUA_API void (lua_replace) (lua_State *L, int idx);
-LUA_API int (lua_checkstack) (lua_State *L, int sz);
-
-LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
-
-
-/*
-** access functions (stack -> C)
-*/
-
-LUA_API int (lua_isnumber) (lua_State *L, int idx);
-LUA_API int (lua_isstring) (lua_State *L, int idx);
-LUA_API int (lua_iscfunction) (lua_State *L, int idx);
-LUA_API int (lua_isuserdata) (lua_State *L, int idx);
-LUA_API int (lua_type) (lua_State *L, int idx);
-LUA_API const char *(lua_typename) (lua_State *L, int tp);
-
-LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
-LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
-LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
-
-LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
-LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
-LUA_API int (lua_toboolean) (lua_State *L, int idx);
-LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
-LUA_API size_t (lua_objlen) (lua_State *L, int idx);
-LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
-LUA_API void *(lua_touserdata) (lua_State *L, int idx);
-LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
-LUA_API const void *(lua_topointer) (lua_State *L, int idx);
-
-
-/*
-** push functions (C -> stack)
-*/
-LUA_API void (lua_pushnil) (lua_State *L);
-LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
-LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
-LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
-LUA_API void (lua_pushstring) (lua_State *L, const char *s);
-LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
- va_list argp);
-LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
-LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
-LUA_API void (lua_pushboolean) (lua_State *L, int b);
-LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
-LUA_API int (lua_pushthread) (lua_State *L);
-
-
-/*
-** get functions (Lua -> stack)
-*/
-LUA_API void (lua_gettable) (lua_State *L, int idx);
-LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
-LUA_API void (lua_rawget) (lua_State *L, int idx);
-LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
-LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
-LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
-LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
-LUA_API void (lua_getfenv) (lua_State *L, int idx);
-
-
-/*
-** set functions (stack -> Lua)
-*/
-LUA_API void (lua_settable) (lua_State *L, int idx);
-LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
-LUA_API void (lua_rawset) (lua_State *L, int idx);
-LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
-LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
-LUA_API int (lua_setfenv) (lua_State *L, int idx);
-
-
-/*
-** `load' and `call' functions (load and run Lua code)
-*/
-LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
-LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
-LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
-LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
- const char *chunkname);
-
-LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
-
-
-/*
-** coroutine functions
-*/
-LUA_API int (lua_yield) (lua_State *L, int nresults);
-LUA_API int (lua_resume) (lua_State *L, int narg);
-LUA_API int (lua_status) (lua_State *L);
-
-/*
-** garbage-collection function and options
-*/
-
-#define LUA_GCSTOP 0
-#define LUA_GCRESTART 1
-#define LUA_GCCOLLECT 2
-#define LUA_GCCOUNT 3
-#define LUA_GCCOUNTB 4
-#define LUA_GCSTEP 5
-#define LUA_GCSETPAUSE 6
-#define LUA_GCSETSTEPMUL 7
-
-LUA_API int (lua_gc) (lua_State *L, int what, int data);
-
-
-/*
-** miscellaneous functions
-*/
-
-LUA_API int (lua_error) (lua_State *L);
-
-LUA_API int (lua_next) (lua_State *L, int idx);
-
-LUA_API void (lua_concat) (lua_State *L, int n);
-
-LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
-LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
-
-
-
-/*
-** ===============================================================
-** some useful macros
-** ===============================================================
-*/
-
-#define lua_pop(L,n) lua_settop(L, -(n)-1)
-
-#define lua_newtable(L) lua_createtable(L, 0, 0)
-
-#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
-
-#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
-
-#define lua_strlen(L,i) lua_objlen(L, (i))
-
-#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
-#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
-#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
-#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
-#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
-#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
-#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
-#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
-
-#define lua_pushliteral(L, s) \
- lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
-
-#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
-#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
-
-#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
-
-
-
-/*
-** compatibility macros and functions
-*/
-
-#define lua_open() luaL_newstate()
-
-#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
-
-#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
-
-#define lua_Chunkreader lua_Reader
-#define lua_Chunkwriter lua_Writer
-
-
-/* hack */
-LUA_API void lua_setlevel (lua_State *from, lua_State *to);
-
-
-/*
-** {======================================================================
-** Debug API
-** =======================================================================
-*/
-
-
-/*
-** Event codes
-*/
-#define LUA_HOOKCALL 0
-#define LUA_HOOKRET 1
-#define LUA_HOOKLINE 2
-#define LUA_HOOKCOUNT 3
-#define LUA_HOOKTAILRET 4
-
-
-/*
-** Event masks
-*/
-#define LUA_MASKCALL (1 << LUA_HOOKCALL)
-#define LUA_MASKRET (1 << LUA_HOOKRET)
-#define LUA_MASKLINE (1 << LUA_HOOKLINE)
-#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
-
-typedef struct lua_Debug lua_Debug; /* activation record */
-
-
-/* Functions to be called by the debuger in specific events */
-typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
-
-
-LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
-LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
-LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
-LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
-LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
-LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
-
-LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
-LUA_API lua_Hook lua_gethook (lua_State *L);
-LUA_API int lua_gethookmask (lua_State *L);
-LUA_API int lua_gethookcount (lua_State *L);
-
-
-struct lua_Debug {
- int event;
- const char *name; /* (n) */
- const char *namewhat; /* (n) `global', `local', `field', `method' */
- const char *what; /* (S) `Lua', `C', `main', `tail' */
- const char *source; /* (S) */
- int currentline; /* (l) */
- int nups; /* (u) number of upvalues */
- int linedefined; /* (S) */
- int lastlinedefined; /* (S) */
- char short_src[LUA_IDSIZE]; /* (S) */
- /* private part */
- int i_ci; /* active function */
-};
-
-/* }====================================================================== */
-
-
-/******************************************************************************
-* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining
-* a copy of this software and associated documentation files (the
-* "Software"), to deal in the Software without restriction, including
-* without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to
-* permit persons to whom the Software is furnished to do so, subject to
-* the following conditions:
-*
-* The above copyright notice and this permission notice shall be
-* included in all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-******************************************************************************/
-
-
-#endif
diff --git a/lib/lua/luac.c b/lib/lua/luac.c
deleted file mode 100644
index d070173..0000000
--- a/lib/lua/luac.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
-** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $
-** Lua compiler (saves bytecodes to files; also list bytecodes)
-** See Copyright Notice in lua.h
-*/
-
-#include
-#include
-#include
-#include
-
-#define luac_c
-#define LUA_CORE
-
-#include "lua.h"
-#include "lauxlib.h"
-
-#include "ldo.h"
-#include "lfunc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lstring.h"
-#include "lundump.h"
-
-#define PROGNAME "luac" /* default program name */
-#define OUTPUT PROGNAME ".out" /* default output file */
-
-static int listing=0; /* list bytecodes? */
-static int dumping=1; /* dump bytecodes? */
-static int stripping=0; /* strip debug information? */
-static char Output[]={ OUTPUT }; /* default output file name */
-static const char* output=Output; /* actual output file name */
-static const char* progname=PROGNAME; /* actual program name */
-
-static void fatal(const char* message)
-{
- fprintf(stderr,"%s: %s\n",progname,message);
- exit(EXIT_FAILURE);
-}
-
-static void cannot(const char* what)
-{
- fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
- exit(EXIT_FAILURE);
-}
-
-static void usage(const char* message)
-{
- if (*message=='-')
- fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
- else
- fprintf(stderr,"%s: %s\n",progname,message);
- fprintf(stderr,
- "usage: %s [options] [filenames].\n"
- "Available options are:\n"
- " - process stdin\n"
- " -l list\n"
- " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
- " -p parse only\n"
- " -s strip debug information\n"
- " -v show version information\n"
- " -- stop handling options\n",
- progname,Output);
- exit(EXIT_FAILURE);
-}
-
-#define IS(s) (strcmp(argv[i],s)==0)
-
-static int doargs(int argc, char* argv[])
-{
- int i;
- int version=0;
- if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
- for (i=1; itop+(i))->l.p)
-
-static const Proto* combine(lua_State* L, int n)
-{
- if (n==1)
- return toproto(L,-1);
- else
- {
- int i,pc;
- Proto* f=luaF_newproto(L);
- setptvalue2s(L,L->top,f); incr_top(L);
- f->source=luaS_newliteral(L,"=(" PROGNAME ")");
- f->maxstacksize=1;
- pc=2*n+1;
- f->code=luaM_newvector(L,pc,Instruction);
- f->sizecode=pc;
- f->p=luaM_newvector(L,n,Proto*);
- f->sizep=n;
- pc=0;
- for (i=0; ip[i]=toproto(L,i-n-1);
- f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);
- f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);
- }
- f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);
- return f;
- }
-}
-
-static int writer(lua_State* L, const void* p, size_t size, void* u)
-{
- UNUSED(L);
- return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
-}
-
-struct Smain {
- int argc;
- char** argv;
-};
-
-static int pmain(lua_State* L)
-{
- struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
- int argc=s->argc;
- char** argv=s->argv;
- const Proto* f;
- int i;
- if (!lua_checkstack(L,argc)) fatal("too many input files");
- for (i=0; i1);
- if (dumping)
- {
- FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
- if (D==NULL) cannot("open");
- lua_lock(L);
- luaU_dump(L,f,writer,D,stripping);
- lua_unlock(L);
- if (ferror(D)) cannot("write");
- if (fclose(D)) cannot("close");
- }
- return 0;
-}
-
-int main(int argc, char* argv[])
-{
- lua_State* L;
- struct Smain s;
- int i=doargs(argc,argv);
- argc-=i; argv+=i;
- if (argc<=0) usage("no input files given");
- L=lua_open();
- if (L==NULL) fatal("not enough memory for state");
- s.argc=argc;
- s.argv=argv;
- if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
- lua_close(L);
- return EXIT_SUCCESS;
-}
diff --git a/lib/lua/luaconf.h b/lib/lua/luaconf.h
deleted file mode 100644
index e2cb261..0000000
--- a/lib/lua/luaconf.h
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
-** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
-** Configuration file for Lua
-** See Copyright Notice in lua.h
-*/
-
-
-#ifndef lconfig_h
-#define lconfig_h
-
-#include
-#include
-
-
-/*
-** ==================================================================
-** Search for "@@" to find all configurable definitions.
-** ===================================================================
-*/
-
-
-/*
-@@ LUA_ANSI controls the use of non-ansi features.
-** CHANGE it (define it) if you want Lua to avoid the use of any
-** non-ansi feature or library.
-*/
-#if defined(__STRICT_ANSI__)
-#define LUA_ANSI
-#endif
-
-
-#if !defined(LUA_ANSI) && defined(_WIN32)
-#define LUA_WIN
-#endif
-
-#if defined(LUA_USE_LINUX)
-#define LUA_USE_POSIX
-#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
-#define LUA_USE_READLINE /* needs some extra libraries */
-#endif
-
-#if defined(LUA_USE_MACOSX)
-#define LUA_USE_POSIX
-#define LUA_DL_DYLD /* does not need extra library */
-#endif
-
-
-
-/*
-@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
-@* Interfaces Extension (XSI).
-** CHANGE it (define it) if your system is XSI compatible.
-*/
-#if defined(LUA_USE_POSIX)
-#define LUA_USE_MKSTEMP
-#define LUA_USE_ISATTY
-#define LUA_USE_POPEN
-#define LUA_USE_ULONGJMP
-#endif
-
-
-/*
-@@ LUA_PATH and LUA_CPATH are the names of the environment variables that
-@* Lua check to set its paths.
-@@ LUA_INIT is the name of the environment variable that Lua
-@* checks for initialization code.
-** CHANGE them if you want different names.
-*/
-#define LUA_PATH "LUA_PATH"
-#define LUA_CPATH "LUA_CPATH"
-#define LUA_INIT "LUA_INIT"
-
-
-/*
-@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
-@* Lua libraries.
-@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
-@* C libraries.
-** CHANGE them if your machine has a non-conventional directory
-** hierarchy or if you want to install your libraries in
-** non-conventional directories.
-*/
-#if defined(_WIN32)
-/*
-** In Windows, any exclamation mark ('!') in the path is replaced by the
-** path of the directory of the executable file of the current process.
-*/
-#define LUA_LDIR "!\\lua\\"
-#define LUA_CDIR "!\\"
-#define LUA_PATH_DEFAULT \
- ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
- LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
-#define LUA_CPATH_DEFAULT \
- ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
-
-#else
-#define LUA_ROOT "/usr/local/"
-#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
-#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
-#define LUA_PATH_DEFAULT \
- "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
- LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
-#define LUA_CPATH_DEFAULT \
- "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
-#endif
-
-
-/*
-@@ LUA_DIRSEP is the directory separator (for submodules).
-** CHANGE it if your machine does not use "/" as the directory separator
-** and is not Windows. (On Windows Lua automatically uses "\".)
-*/
-#if defined(_WIN32)
-#define LUA_DIRSEP "\\"
-#else
-#define LUA_DIRSEP "/"
-#endif
-
-
-/*
-@@ LUA_PATHSEP is the character that separates templates in a path.
-@@ LUA_PATH_MARK is the string that marks the substitution points in a
-@* template.
-@@ LUA_EXECDIR in a Windows path is replaced by the executable's
-@* directory.
-@@ LUA_IGMARK is a mark to ignore all before it when bulding the
-@* luaopen_ function name.
-** CHANGE them if for some reason your system cannot use those
-** characters. (E.g., if one of those characters is a common character
-** in file/directory names.) Probably you do not need to change them.
-*/
-#define LUA_PATHSEP ";"
-#define LUA_PATH_MARK "?"
-#define LUA_EXECDIR "!"
-#define LUA_IGMARK "-"
-
-
-/*
-@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
-** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
-** machines, ptrdiff_t gives a good choice between int or long.)
-*/
-#define LUA_INTEGER ptrdiff_t
-
-
-/*
-@@ LUA_API is a mark for all core API functions.
-@@ LUALIB_API is a mark for all standard library functions.
-** CHANGE them if you need to define those functions in some special way.
-** For instance, if you want to create one Windows DLL with the core and
-** the libraries, you may want to use the following definition (define
-** LUA_BUILD_AS_DLL to get it).
-*/
-#if defined(LUA_BUILD_AS_DLL)
-
-#if defined(LUA_CORE) || defined(LUA_LIB)
-#define LUA_API __declspec(dllexport)
-#else
-#define LUA_API __declspec(dllimport)
-#endif
-
-#else
-
-#define LUA_API extern
-
-#endif
-
-/* more often than not the libs go together with the core */
-#define LUALIB_API LUA_API
-
-
-/*
-@@ LUAI_FUNC is a mark for all extern functions that are not to be
-@* exported to outside modules.
-@@ LUAI_DATA is a mark for all extern (const) variables that are not to
-@* be exported to outside modules.
-** CHANGE them if you need to mark them in some special way. Elf/gcc
-** (versions 3.2 and later) mark them as "hidden" to optimize access
-** when Lua is compiled as a shared library.
-*/
-#if defined(luaall_c)
-#define LUAI_FUNC static
-#define LUAI_DATA /* empty */
-
-#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
- defined(__ELF__)
-#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
-#define LUAI_DATA LUAI_FUNC
-
-#else
-#define LUAI_FUNC extern
-#define LUAI_DATA extern
-#endif
-
-
-
-/*
-@@ LUA_QL describes how error messages quote program elements.
-** CHANGE it if you want a different appearance.
-*/
-#define LUA_QL(x) "'" x "'"
-#define LUA_QS LUA_QL("%s")
-
-
-/*
-@@ LUA_IDSIZE gives the maximum size for the description of the source
-@* of a function in debug information.
-** CHANGE it if you want a different size.
-*/
-#define LUA_IDSIZE 60
-
-
-/*
-** {==================================================================
-** Stand-alone configuration
-** ===================================================================
-*/
-
-#if defined(lua_c) || defined(luaall_c)
-
-/*
-@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
-@* is, whether we're running lua interactively).
-** CHANGE it if you have a better definition for non-POSIX/non-Windows
-** systems.
-*/
-#if defined(LUA_USE_ISATTY)
-#include
-#define lua_stdin_is_tty() isatty(0)
-#elif defined(LUA_WIN)
-#include
-#include
-#define lua_stdin_is_tty() _isatty(_fileno(stdin))
-#else
-#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
-#endif
-
-
-/*
-@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
-@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
-** CHANGE them if you want different prompts. (You can also change the
-** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
-*/
-#define LUA_PROMPT "> "
-#define LUA_PROMPT2 ">> "
-
-
-/*
-@@ LUA_PROGNAME is the default name for the stand-alone Lua program.
-** CHANGE it if your stand-alone interpreter has a different name and
-** your system is not able to detect that name automatically.
-*/
-#define LUA_PROGNAME "lua"
-
-
-/*
-@@ LUA_MAXINPUT is the maximum length for an input line in the
-@* stand-alone interpreter.
-** CHANGE it if you need longer lines.
-*/
-#define LUA_MAXINPUT 512
-
-
-/*
-@@ lua_readline defines how to show a prompt and then read a line from
-@* the standard input.
-@@ lua_saveline defines how to "save" a read line in a "history".
-@@ lua_freeline defines how to free a line read by lua_readline.
-** CHANGE them if you want to improve this functionality (e.g., by using
-** GNU readline and history facilities).
-*/
-#if defined(LUA_USE_READLINE)
-#include
-#include
-#include
-#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
-#define lua_saveline(L,idx) \
- if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
- add_history(lua_tostring(L, idx)); /* add it to history */
-#define lua_freeline(L,b) ((void)L, free(b))
-#else
-#define lua_readline(L,b,p) \
- ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
- fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
-#define lua_saveline(L,idx) { (void)L; (void)idx; }
-#define lua_freeline(L,b) { (void)L; (void)b; }
-#endif
-
-#endif
-
-/* }================================================================== */
-
-
-/*
-@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
-@* as a percentage.
-** CHANGE it if you want the GC to run faster or slower (higher values
-** mean larger pauses which mean slower collection.) You can also change
-** this value dynamically.
-*/
-#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
-
-
-/*
-@@ LUAI_GCMUL defines the default speed of garbage collection relative to
-@* memory allocation as a percentage.
-** CHANGE it if you want to change the granularity of the garbage
-** collection. (Higher values mean coarser collections. 0 represents
-** infinity, where each step performs a full collection.) You can also
-** change this value dynamically.
-*/
-#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
-
-
-
-/*
-@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
-** CHANGE it (define it) if you want exact compatibility with the
-** behavior of setn/getn in Lua 5.0.
-*/
-#undef LUA_COMPAT_GETN
-
-/*
-@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
-** CHANGE it to undefined as soon as you do not need a global 'loadlib'
-** function (the function is still available as 'package.loadlib').
-*/
-#undef LUA_COMPAT_LOADLIB
-
-/*
-@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
-** CHANGE it to undefined as soon as your programs use only '...' to
-** access vararg parameters (instead of the old 'arg' table).
-*/
-#define LUA_COMPAT_VARARG
-
-/*
-@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
-** CHANGE it to undefined as soon as your programs use 'math.fmod' or
-** the new '%' operator instead of 'math.mod'.
-*/
-#define LUA_COMPAT_MOD
-
-/*
-@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
-@* facility.
-** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
-** off the advisory error when nesting [[...]].
-*/
-#define LUA_COMPAT_LSTR 1
-
-/*
-@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
-** CHANGE it to undefined as soon as you rename 'string.gfind' to
-** 'string.gmatch'.
-*/
-#define LUA_COMPAT_GFIND
-
-/*
-@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
-@* behavior.
-** CHANGE it to undefined as soon as you replace to 'luaL_register'
-** your uses of 'luaL_openlib'
-*/
-#define LUA_COMPAT_OPENLIB
-
-
-
-/*
-@@ luai_apicheck is the assert macro used by the Lua-C API.
-** CHANGE luai_apicheck if you want Lua to perform some checks in the
-** parameters it gets from API calls. This may slow down the interpreter
-** a bit, but may be quite useful when debugging C code that interfaces
-** with Lua. A useful redefinition is to use assert.h.
-*/
-#if defined(LUA_USE_APICHECK)
-#include
-#define luai_apicheck(L,o) { (void)L; assert(o); }
-#else
-#define luai_apicheck(L,o) { (void)L; }
-#endif
-
-
-/*
-@@ LUAI_BITSINT defines the number of bits in an int.
-** CHANGE here if Lua cannot automatically detect the number of bits of
-** your machine. Probably you do not need to change this.
-*/
-/* avoid overflows in comparison */
-#if INT_MAX-20 < 32760
-#define LUAI_BITSINT 16
-#elif INT_MAX > 2147483640L
-/* int has at least 32 bits */
-#define LUAI_BITSINT 32
-#else
-#error "you must define LUA_BITSINT with number of bits in an integer"
-#endif
-
-
-/*
-@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
-@@ LUAI_INT32 is an signed integer with at least 32 bits.
-@@ LUAI_UMEM is an unsigned integer big enough to count the total
-@* memory used by Lua.
-@@ LUAI_MEM is a signed integer big enough to count the total memory
-@* used by Lua.
-** CHANGE here if for some weird reason the default definitions are not
-** good enough for your machine. (The definitions in the 'else'
-** part always works, but may waste space on machines with 64-bit
-** longs.) Probably you do not need to change this.
-*/
-#if LUAI_BITSINT >= 32
-#define LUAI_UINT32 unsigned int
-#define LUAI_INT32 int
-#define LUAI_MAXINT32 INT_MAX
-#define LUAI_UMEM size_t
-#define LUAI_MEM ptrdiff_t
-#else
-/* 16-bit ints */
-#define LUAI_UINT32 unsigned long
-#define LUAI_INT32 long
-#define LUAI_MAXINT32 LONG_MAX
-#define LUAI_UMEM unsigned long
-#define LUAI_MEM long
-#endif
-
-
-/*
-@@ LUAI_MAXCALLS limits the number of nested calls.
-** CHANGE it if you need really deep recursive calls. This limit is
-** arbitrary; its only purpose is to stop infinite recursion before
-** exhausting memory.
-*/
-#define LUAI_MAXCALLS 20000
-
-
-/*
-@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
-@* can use.
-** CHANGE it if you need lots of (Lua) stack space for your C
-** functions. This limit is arbitrary; its only purpose is to stop C
-** functions to consume unlimited stack space. (must be smaller than
-** -LUA_REGISTRYINDEX)
-*/
-#define LUAI_MAXCSTACK 8000
-
-
-
-/*
-** {==================================================================
-** CHANGE (to smaller values) the following definitions if your system
-** has a small C stack. (Or you may want to change them to larger
-** values if your system has a large C stack and these limits are
-** too rigid for you.) Some of these constants control the size of
-** stack-allocated arrays used by the compiler or the interpreter, while
-** others limit the maximum number of recursive calls that the compiler
-** or the interpreter can perform. Values too large may cause a C stack
-** overflow for some forms of deep constructs.
-** ===================================================================
-*/
-
-
-/*
-@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
-@* syntactical nested non-terminals in a program.
-*/
-#define LUAI_MAXCCALLS 200
-
-
-/*
-@@ LUAI_MAXVARS is the maximum number of local variables per function
-@* (must be smaller than 250).
-*/
-#define LUAI_MAXVARS 200
-
-
-/*
-@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
-@* (must be smaller than 250).
-*/
-#define LUAI_MAXUPVALUES 60
-
-
-/*
-@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
-*/
-#define LUAL_BUFFERSIZE BUFSIZ
-
-/* }================================================================== */
-
-
-
-
-/*
-** {==================================================================
-@@ LUA_NUMBER is the type of numbers in Lua.
-** CHANGE the following definitions only if you want to build Lua
-** with a number type different from double. You may also need to
-** change lua_number2int & lua_number2integer.
-** ===================================================================
-*/
-
-#define LUA_NUMBER_DOUBLE
-#define LUA_NUMBER double
-
-/*
-@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
-@* over a number.
-*/
-#define LUAI_UACNUMBER double
-
-
-/*
-@@ LUA_NUMBER_SCAN is the format for reading numbers.
-@@ LUA_NUMBER_FMT is the format for writing numbers.
-@@ lua_number2str converts a number to a string.
-@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
-@@ lua_str2number converts a string to a number.
-*/
-#define LUA_NUMBER_SCAN "%lf"
-#define LUA_NUMBER_FMT "%.14g"
-#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
-#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
-#define lua_str2number(s,p) strtod((s), (p))
-
-
-/*
-@@ The luai_num* macros define the primitive operations over numbers.
-*/
-#if defined(LUA_CORE)
-#include
-#define luai_numadd(a,b) ((a)+(b))
-#define luai_numsub(a,b) ((a)-(b))
-#define luai_nummul(a,b) ((a)*(b))
-#define luai_numdiv(a,b) ((a)/(b))
-#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
-#define luai_numpow(a,b) (pow(a,b))
-#define luai_numunm(a) (-(a))
-#define luai_numeq(a,b) ((a)==(b))
-#define luai_numlt(a,b) ((a)<(b))
-#define luai_numle(a,b) ((a)<=(b))
-#define luai_numisnan(a) (!luai_numeq((a), (a)))
-#endif
-
-
-/*
-@@ lua_number2int is a macro to convert lua_Number to int.
-@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
-** CHANGE them if you know a faster way to convert a lua_Number to
-** int (with any rounding method and without throwing errors) in your
-** system. In Pentium machines, a naive typecast from double to int
-** in C is extremely slow, so any alternative is worth trying.
-*/
-
-/* On a Pentium, resort to a trick */
-#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
- (defined(__i386) || defined (_M_IX86) || defined(__i386__))
-
-/* On a Microsoft compiler, use assembler */
-#if defined(_MSC_VER)
-
-#define lua_number2int(i,d) __asm fld d __asm fistp i
-#define lua_number2integer(i,n) lua_number2int(i, n)
-
-/* the next trick should work on any Pentium, but sometimes clashes
- with a DirectX idiosyncrasy */
-#else
-
-union luai_Cast { double l_d; long l_l; };
-#define lua_number2int(i,d) \
- { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
-#define lua_number2integer(i,n) lua_number2int(i, n)
-
-#endif
-
-
-/* this option always works, but may be slow */
-#else
-#define lua_number2int(i,d) ((i)=(int)(d))
-#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
-
-#endif
-
-/* }================================================================== */
-
-
-/*
-@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
-** CHANGE it if your system requires alignments larger than double. (For
-** instance, if your system supports long doubles and they must be
-** aligned in 16-byte boundaries, then you should add long double in the
-** union.) Probably you do not need to change this.
-*/
-#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
-
-
-/*
-@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
-** CHANGE them if you prefer to use longjmp/setjmp even with C++
-** or if want/don't to use _longjmp/_setjmp instead of regular
-** longjmp/setjmp. By default, Lua handles errors with exceptions when
-** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
-** and with longjmp/setjmp otherwise.
-*/
-#if defined(__cplusplus)
-/* C++ exceptions */
-#define LUAI_THROW(L,c) throw(c)
-#define LUAI_TRY(L,c,a) try { a } catch(...) \
- { if ((c)->status == 0) (c)->status = -1; }
-#define luai_jmpbuf int /* dummy variable */
-
-#elif defined(LUA_USE_ULONGJMP)
-/* in Unix, try _longjmp/_setjmp (more efficient) */
-#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf jmp_buf
-
-#else
-/* default handling with long jumps */
-#define LUAI_THROW(L,c) longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf jmp_buf
-
-#endif
-
-
-/*
-@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
-@* can do during pattern-matching.
-** CHANGE it if you need more captures. This limit is arbitrary.
-*/
-#define LUA_MAXCAPTURES 32
-
-
-/*
-@@ lua_tmpnam is the function that the OS library uses to create a
-@* temporary name.
-@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
-** CHANGE them if you have an alternative to tmpnam (which is considered
-** insecure) or if you want the original tmpnam anyway. By default, Lua
-** uses tmpnam except when POSIX is available, where it uses mkstemp.
-*/
-#if defined(loslib_c) || defined(luaall_c)
-
-#if defined(LUA_USE_MKSTEMP)
-#include
-#define LUA_TMPNAMBUFSIZE 32
-#define lua_tmpnam(b,e) { \
- strcpy(b, "/tmp/lua_XXXXXX"); \
- e = mkstemp(b); \
- if (e != -1) close(e); \
- e = (e == -1); }
-
-#else
-#define LUA_TMPNAMBUFSIZE L_tmpnam
-#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
-#endif
-
-#endif
-
-
-/*
-@@ lua_popen spawns a new process connected to the current one through
-@* the file streams.
-** CHANGE it if you have a way to implement it in your system.
-*/
-#if defined(LUA_USE_POPEN)
-
-#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
-#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
-
-#elif defined(LUA_WIN)
-
-#define lua_popen(L,c,m) ((void)L, _popen(c,m))
-#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
-
-#else
-
-#define lua_popen(L,c,m) ((void)((void)c, m), \
- luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
-#define lua_pclose(L,file) ((void)((void)L, file), 0)
-
-#endif
-
-/*
-@@ LUA_DL_* define which dynamic-library system Lua should use.
-** CHANGE here if Lua has problems choosing the appropriate
-** dynamic-library system for your platform (either Windows' DLL, Mac's
-** dyld, or Unix's dlopen). If your system is some kind of Unix, there
-** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
-** it. To use dlopen you also need to adapt the src/Makefile (probably
-** adding -ldl to the linker options), so Lua does not select it
-** automatically. (When you change the makefile to add -ldl, you must
-** also add -DLUA_USE_DLOPEN.)
-** If you do not want any kind of dynamic library, undefine all these
-** options.
-** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
-*/
-#if defined(LUA_USE_DLOPEN)
-#define LUA_DL_DLOPEN
-#endif
-
-#if defined(LUA_WIN)
-#define LUA_DL_DLL
-#endif
-
-
-/*
-@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
-@* (the data goes just *before* the lua_State pointer).
-** CHANGE (define) this if you really need that. This value must be
-** a multiple of the maximum alignment required for your machine.
-*/
-#define LUAI_EXTRASPACE 0
-
-
-/*
-@@ luai_userstate* allow user-specific actions on threads.
-** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
-** extra when a thread is created/deleted/resumed/yielded.
-*/
-#define luai_userstateopen(L) ((void)L)
-#define luai_userstateclose(L) ((void)L)
-#define luai_userstatethread(L,L1) ((void)L)
-#define luai_userstatefree(L) ((void)L)
-#define luai_userstateresume(L,n) ((void)L)
-#define luai_userstateyield(L,n) ((void)L)
-
-
-/*
-@@ LUA_INTFRMLEN is the length modifier for integer conversions
-@* in 'string.format'.
-@@ LUA_INTFRM_T is the integer type correspoding to the previous length
-@* modifier.
-** CHANGE them if your system supports long long or does not support long.
-*/
-
-#if defined(LUA_USELONGLONG)
-
-#define LUA_INTFRMLEN "ll"
-#define LUA_INTFRM_T long long
-
-#else
-
-#define LUA_INTFRMLEN "l"
-#define LUA_INTFRM_T long
-
-#endif
-
-
-
-/* =================================================================== */
-
-/*
-** Local configuration. You can use this space to add your redefinitions
-** without modifying the main part of the file.
-*/
-
-
-
-#endif
-
diff --git a/lib/lua/lualib.h b/lib/lua/lualib.h
deleted file mode 100644
index 469417f..0000000
--- a/lib/lua/lualib.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lua standard libraries
-** See Copyright Notice in lua.h
-*/
-
-
-#ifndef lualib_h
-#define lualib_h
-
-#include "lua.h"
-
-
-/* Key to file-handle type */
-#define LUA_FILEHANDLE "FILE*"
-
-
-#define LUA_COLIBNAME "coroutine"
-LUALIB_API int (luaopen_base) (lua_State *L);
-
-#define LUA_TABLIBNAME "table"
-LUALIB_API int (luaopen_table) (lua_State *L);
-
-#define LUA_IOLIBNAME "io"
-LUALIB_API int (luaopen_io) (lua_State *L);
-
-#define LUA_OSLIBNAME "os"
-LUALIB_API int (luaopen_os) (lua_State *L);
-
-#define LUA_STRLIBNAME "string"
-LUALIB_API int (luaopen_string) (lua_State *L);
-
-#define LUA_MATHLIBNAME "math"
-LUALIB_API int (luaopen_math) (lua_State *L);
-
-#define LUA_DBLIBNAME "debug"
-LUALIB_API int (luaopen_debug) (lua_State *L);
-
-#define LUA_LOADLIBNAME "package"
-LUALIB_API int (luaopen_package) (lua_State *L);
-
-
-/* open all previous libraries */
-LUALIB_API void (luaL_openlibs) (lua_State *L);
-
-
-
-#ifndef lua_assert
-#define lua_assert(x) ((void)0)
-#endif
-
-
-#endif
diff --git a/lib/lua/lundump.c b/lib/lua/lundump.c
deleted file mode 100644
index 8010a45..0000000
--- a/lib/lua/lundump.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
-** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
-** load precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#include
-
-#define lundump_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstring.h"
-#include "lundump.h"
-#include "lzio.h"
-
-typedef struct {
- lua_State* L;
- ZIO* Z;
- Mbuffer* b;
- const char* name;
-} LoadState;
-
-#ifdef LUAC_TRUST_BINARIES
-#define IF(c,s)
-#define error(S,s)
-#else
-#define IF(c,s) if (c) error(S,s)
-
-static void error(LoadState* S, const char* why)
-{
- luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
- luaD_throw(S->L,LUA_ERRSYNTAX);
-}
-#endif
-
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
-#define LoadByte(S) (lu_byte)LoadChar(S)
-#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
-#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
-
-static void LoadBlock(LoadState* S, void* b, size_t size)
-{
- size_t r=luaZ_read(S->Z,b,size);
- IF (r!=0, "unexpected end");
-}
-
-static int LoadChar(LoadState* S)
-{
- char x;
- LoadVar(S,x);
- return x;
-}
-
-static int LoadInt(LoadState* S)
-{
- int x;
- LoadVar(S,x);
- IF (x<0, "bad integer");
- return x;
-}
-
-static lua_Number LoadNumber(LoadState* S)
-{
- lua_Number x;
- LoadVar(S,x);
- return x;
-}
-
-static TString* LoadString(LoadState* S)
-{
- size_t size;
- LoadVar(S,size);
- if (size==0)
- return NULL;
- else
- {
- char* s=luaZ_openspace(S->L,S->b,size);
- LoadBlock(S,s,size);
- return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
- }
-}
-
-static void LoadCode(LoadState* S, Proto* f)
-{
- int n=LoadInt(S);
- f->code=luaM_newvector(S->L,n,Instruction);
- f->sizecode=n;
- LoadVector(S,f->code,n,sizeof(Instruction));
-}
-
-static Proto* LoadFunction(LoadState* S, TString* p);
-
-static void LoadConstants(LoadState* S, Proto* f)
-{
- int i,n;
- n=LoadInt(S);
- f->k=luaM_newvector(S->L,n,TValue);
- f->sizek=n;
- for (i=0; ik[i]);
- for (i=0; ik[i];
- int t=LoadChar(S);
- switch (t)
- {
- case LUA_TNIL:
- setnilvalue(o);
- break;
- case LUA_TBOOLEAN:
- setbvalue(o,LoadChar(S)!=0);
- break;
- case LUA_TNUMBER:
- setnvalue(o,LoadNumber(S));
- break;
- case LUA_TSTRING:
- setsvalue2n(S->L,o,LoadString(S));
- break;
- default:
- error(S,"bad constant");
- break;
- }
- }
- n=LoadInt(S);
- f->p=luaM_newvector(S->L,n,Proto*);
- f->sizep=n;
- for (i=0; ip[i]=NULL;
- for (i=0; ip[i]=LoadFunction(S,f->source);
-}
-
-static void LoadDebug(LoadState* S, Proto* f)
-{
- int i,n;
- n=LoadInt(S);
- f->lineinfo=luaM_newvector(S->L,n,int);
- f->sizelineinfo=n;
- LoadVector(S,f->lineinfo,n,sizeof(int));
- n=LoadInt(S);
- f->locvars=luaM_newvector(S->L,n,LocVar);
- f->sizelocvars=n;
- for (i=0; ilocvars[i].varname=NULL;
- for (i=0; ilocvars[i].varname=LoadString(S);
- f->locvars[i].startpc=LoadInt(S);
- f->locvars[i].endpc=LoadInt(S);
- }
- n=LoadInt(S);
- f->upvalues=luaM_newvector(S->L,n,TString*);
- f->sizeupvalues=n;
- for (i=0; iupvalues[i]=NULL;
- for (i=0; iupvalues[i]=LoadString(S);
-}
-
-static Proto* LoadFunction(LoadState* S, TString* p)
-{
- Proto* f;
- if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
- f=luaF_newproto(S->L);
- setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
- f->source=LoadString(S); if (f->source==NULL) f->source=p;
- f->linedefined=LoadInt(S);
- f->lastlinedefined=LoadInt(S);
- f->nups=LoadByte(S);
- f->numparams=LoadByte(S);
- f->is_vararg=LoadByte(S);
- f->maxstacksize=LoadByte(S);
- LoadCode(S,f);
- LoadConstants(S,f);
- LoadDebug(S,f);
- IF (!luaG_checkcode(f), "bad code");
- S->L->top--;
- S->L->nCcalls--;
- return f;
-}
-
-static void LoadHeader(LoadState* S)
-{
- char h[LUAC_HEADERSIZE];
- char s[LUAC_HEADERSIZE];
- luaU_header(h);
- LoadBlock(S,s,LUAC_HEADERSIZE);
- IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
-}
-
-/*
-** load precompiled chunk
-*/
-Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
-{
- LoadState S;
- if (*name=='@' || *name=='=')
- S.name=name+1;
- else if (*name==LUA_SIGNATURE[0])
- S.name="binary string";
- else
- S.name=name;
- S.L=L;
- S.Z=Z;
- S.b=buff;
- LoadHeader(&S);
- return LoadFunction(&S,luaS_newliteral(L,"=?"));
-}
-
-/*
-* make header
-*/
-void luaU_header (char* h)
-{
- int x=1;
- memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
- h+=sizeof(LUA_SIGNATURE)-1;
- *h++=(char)LUAC_VERSION;
- *h++=(char)LUAC_FORMAT;
- *h++=(char)*(char*)&x; /* endianness */
- *h++=(char)sizeof(int);
- *h++=(char)sizeof(size_t);
- *h++=(char)sizeof(Instruction);
- *h++=(char)sizeof(lua_Number);
- *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
-}
diff --git a/lib/lua/lundump.h b/lib/lua/lundump.h
deleted file mode 100644
index c80189d..0000000
--- a/lib/lua/lundump.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
-** load precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lundump_h
-#define lundump_h
-
-#include "lobject.h"
-#include "lzio.h"
-
-/* load one chunk; from lundump.c */
-LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
-
-/* make header; from lundump.c */
-LUAI_FUNC void luaU_header (char* h);
-
-/* dump one chunk; from ldump.c */
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
-
-#ifdef luac_c
-/* print one chunk; from print.c */
-LUAI_FUNC void luaU_print (const Proto* f, int full);
-#endif
-
-/* for header of binary files -- this is Lua 5.1 */
-#define LUAC_VERSION 0x51
-
-/* for header of binary files -- this is the official format */
-#define LUAC_FORMAT 0
-
-/* size of header of binary files */
-#define LUAC_HEADERSIZE 12
-
-#endif
diff --git a/lib/lua/lvm.c b/lib/lua/lvm.c
deleted file mode 100644
index ee3256a..0000000
--- a/lib/lua/lvm.c
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
-** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
-** Lua virtual machine
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-#include
-#include
-
-#define lvm_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-#include "lvm.h"
-
-
-
-/* limit for table tag-method chains (to avoid loops) */
-#define MAXTAGLOOP 100
-
-
-const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
- lua_Number num;
- if (ttisnumber(obj)) return obj;
- if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
- setnvalue(n, num);
- return n;
- }
- else
- return NULL;
-}
-
-
-int luaV_tostring (lua_State *L, StkId obj) {
- if (!ttisnumber(obj))
- return 0;
- else {
- char s[LUAI_MAXNUMBER2STR];
- lua_Number n = nvalue(obj);
- lua_number2str(s, n);
- setsvalue2s(L, obj, luaS_new(L, s));
- return 1;
- }
-}
-
-
-static void traceexec (lua_State *L, const Instruction *pc) {
- lu_byte mask = L->hookmask;
- const Instruction *oldpc = L->savedpc;
- L->savedpc = pc;
- if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
- resethookcount(L);
- luaD_callhook(L, LUA_HOOKCOUNT, -1);
- }
- if (mask & LUA_MASKLINE) {
- Proto *p = ci_func(L->ci)->l.p;
- int npc = pcRel(pc, p);
- int newline = getline(p, npc);
- /* call linehook when enter a new function, when jump back (loop),
- or when enter a new line */
- if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p)))
- luaD_callhook(L, LUA_HOOKLINE, newline);
- }
-}
-
-
-static void callTMres (lua_State *L, StkId res, const TValue *f,
- const TValue *p1, const TValue *p2) {
- ptrdiff_t result = savestack(L, res);
- setobj2s(L, L->top, f); /* push function */
- setobj2s(L, L->top+1, p1); /* 1st argument */
- setobj2s(L, L->top+2, p2); /* 2nd argument */
- luaD_checkstack(L, 3);
- L->top += 3;
- luaD_call(L, L->top - 3, 1);
- res = restorestack(L, result);
- L->top--;
- setobjs2s(L, res, L->top);
-}
-
-
-
-static void callTM (lua_State *L, const TValue *f, const TValue *p1,
- const TValue *p2, const TValue *p3) {
- setobj2s(L, L->top, f); /* push function */
- setobj2s(L, L->top+1, p1); /* 1st argument */
- setobj2s(L, L->top+2, p2); /* 2nd argument */
- setobj2s(L, L->top+3, p3); /* 3th argument */
- luaD_checkstack(L, 4);
- L->top += 4;
- luaD_call(L, L->top - 4, 0);
-}
-
-
-void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
- int loop;
- for (loop = 0; loop < MAXTAGLOOP; loop++) {
- const TValue *tm;
- if (ttistable(t)) { /* `t' is a table? */
- Table *h = hvalue(t);
- const TValue *res = luaH_get(h, key); /* do a primitive get */
- if (!ttisnil(res) || /* result is no nil? */
- (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
- setobj2s(L, val, res);
- return;
- }
- /* else will try the tag method */
- }
- else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
- luaG_typeerror(L, t, "index");
- if (ttisfunction(tm)) {
- callTMres(L, val, tm, t, key);
- return;
- }
- t = tm; /* else repeat with `tm' */
- }
- luaG_runerror(L, "loop in gettable");
-}
-
-
-void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
- int loop;
- for (loop = 0; loop < MAXTAGLOOP; loop++) {
- const TValue *tm;
- if (ttistable(t)) { /* `t' is a table? */
- Table *h = hvalue(t);
- TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
- if (!ttisnil(oldval) || /* result is no nil? */
- (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
- setobj2t(L, oldval, val);
- luaC_barriert(L, h, val);
- return;
- }
- /* else will try the tag method */
- }
- else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
- luaG_typeerror(L, t, "index");
- if (ttisfunction(tm)) {
- callTM(L, tm, t, key, val);
- return;
- }
- t = tm; /* else repeat with `tm' */
- }
- luaG_runerror(L, "loop in settable");
-}
-
-
-static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
- StkId res, TMS event) {
- const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
- if (ttisnil(tm))
- tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
- if (ttisnil(tm)) return 0;
- callTMres(L, res, tm, p1, p2);
- return 1;
-}
-
-
-static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
- TMS event) {
- const TValue *tm1 = fasttm(L, mt1, event);
- const TValue *tm2;
- if (tm1 == NULL) return NULL; /* no metamethod */
- if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
- tm2 = fasttm(L, mt2, event);
- if (tm2 == NULL) return NULL; /* no metamethod */
- if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */
- return tm1;
- return NULL;
-}
-
-
-static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
- TMS event) {
- const TValue *tm1 = luaT_gettmbyobj(L, p1, event);
- const TValue *tm2;
- if (ttisnil(tm1)) return -1; /* no metamethod? */
- tm2 = luaT_gettmbyobj(L, p2, event);
- if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */
- return -1;
- callTMres(L, L->top, tm1, p1, p2);
- return !l_isfalse(L->top);
-}
-
-
-static int l_strcmp (const TString *ls, const TString *rs) {
- const char *l = getstr(ls);
- size_t ll = ls->tsv.len;
- const char *r = getstr(rs);
- size_t lr = rs->tsv.len;
- for (;;) {
- int temp = strcoll(l, r);
- if (temp != 0) return temp;
- else { /* strings are equal up to a `\0' */
- size_t len = strlen(l); /* index of first `\0' in both strings */
- if (len == lr) /* r is finished? */
- return (len == ll) ? 0 : 1;
- else if (len == ll) /* l is finished? */
- return -1; /* l is smaller than r (because r is not finished) */
- /* both strings longer than `len'; go on comparing (after the `\0') */
- len++;
- l += len; ll -= len; r += len; lr -= len;
- }
- }
-}
-
-
-int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
- int res;
- if (ttype(l) != ttype(r))
- return luaG_ordererror(L, l, r);
- else if (ttisnumber(l))
- return luai_numlt(nvalue(l), nvalue(r));
- else if (ttisstring(l))
- return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
- else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
- return res;
- return luaG_ordererror(L, l, r);
-}
-
-
-static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
- int res;
- if (ttype(l) != ttype(r))
- return luaG_ordererror(L, l, r);
- else if (ttisnumber(l))
- return luai_numle(nvalue(l), nvalue(r));
- else if (ttisstring(l))
- return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
- else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
- return res;
- else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
- return !res;
- return luaG_ordererror(L, l, r);
-}
-
-
-int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {
- const TValue *tm;
- lua_assert(ttype(t1) == ttype(t2));
- switch (ttype(t1)) {
- case LUA_TNIL: return 1;
- case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
- case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
- case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
- case LUA_TUSERDATA: {
- if (uvalue(t1) == uvalue(t2)) return 1;
- tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,
- TM_EQ);
- break; /* will try TM */
- }
- case LUA_TTABLE: {
- if (hvalue(t1) == hvalue(t2)) return 1;
- tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
- break; /* will try TM */
- }
- default: return gcvalue(t1) == gcvalue(t2);
- }
- if (tm == NULL) return 0; /* no TM? */
- callTMres(L, L->top, tm, t1, t2); /* call TM */
- return !l_isfalse(L->top);
-}
-
-
-void luaV_concat (lua_State *L, int total, int last) {
- do {
- StkId top = L->base + last + 1;
- int n = 2; /* number of elements handled in this pass (at least 2) */
- if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
- if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
- luaG_concaterror(L, top-2, top-1);
- } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
- (void)tostring(L, top - 2); /* result is first op (as string) */
- else {
- /* at least two string values; get as many as possible */
- size_t tl = tsvalue(top-1)->len;
- char *buffer;
- int i;
- /* collect total length */
- for (n = 1; n < total && tostring(L, top-n-1); n++) {
- size_t l = tsvalue(top-n-1)->len;
- if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
- tl += l;
- }
- buffer = luaZ_openspace(L, &G(L)->buff, tl);
- tl = 0;
- for (i=n; i>0; i--) { /* concat all strings */
- size_t l = tsvalue(top-i)->len;
- memcpy(buffer+tl, svalue(top-i), l);
- tl += l;
- }
- setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
- }
- total -= n-1; /* got `n' strings to create 1 new */
- last -= n-1;
- } while (total > 1); /* repeat until only 1 result left */
-}
-
-
-static void Arith (lua_State *L, StkId ra, const TValue *rb,
- const TValue *rc, TMS op) {
- TValue tempb, tempc;
- const TValue *b, *c;
- if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
- (c = luaV_tonumber(rc, &tempc)) != NULL) {
- lua_Number nb = nvalue(b), nc = nvalue(c);
- switch (op) {
- case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
- case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
- case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
- case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
- case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
- case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
- case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
- default: lua_assert(0); break;
- }
- }
- else if (!call_binTM(L, rb, rc, ra, op))
- luaG_aritherror(L, rb, rc);
-}
-
-
-
-/*
-** some macros for common tasks in `luaV_execute'
-*/
-
-#define runtime_check(L, c) { if (!(c)) break; }
-
-#define RA(i) (base+GETARG_A(i))
-/* to be used after possible stack reallocation */
-#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
-#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
-#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
- ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
-#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
- ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
-#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
-
-
-#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);}
-
-
-#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
-
-
-#define arith_op(op,tm) { \
- TValue *rb = RKB(i); \
- TValue *rc = RKC(i); \
- if (ttisnumber(rb) && ttisnumber(rc)) { \
- lua_Number nb = nvalue(rb), nc = nvalue(rc); \
- setnvalue(ra, op(nb, nc)); \
- } \
- else \
- Protect(Arith(L, ra, rb, rc, tm)); \
- }
-
-
-
-void luaV_execute (lua_State *L, int nexeccalls) {
- LClosure *cl;
- StkId base;
- TValue *k;
- const Instruction *pc;
- reentry: /* entry point */
- lua_assert(isLua(L->ci));
- pc = L->savedpc;
- cl = &clvalue(L->ci->func)->l;
- base = L->base;
- k = cl->p->k;
- /* main loop of interpreter */
- for (;;) {
- const Instruction i = *pc++;
- StkId ra;
- if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
- (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
- traceexec(L, pc);
- if (L->status == LUA_YIELD) { /* did hook yield? */
- L->savedpc = pc - 1;
- return;
- }
- base = L->base;
- }
- /* warning!! several calls may realloc the stack and invalidate `ra' */
- ra = RA(i);
- lua_assert(base == L->base && L->base == L->ci->base);
- lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
- lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
- switch (GET_OPCODE(i)) {
- case OP_MOVE: {
- setobjs2s(L, ra, RB(i));
- continue;
- }
- case OP_LOADK: {
- setobj2s(L, ra, KBx(i));
- continue;
- }
- case OP_LOADBOOL: {
- setbvalue(ra, GETARG_B(i));
- if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
- continue;
- }
- case OP_LOADNIL: {
- TValue *rb = RB(i);
- do {
- setnilvalue(rb--);
- } while (rb >= ra);
- continue;
- }
- case OP_GETUPVAL: {
- int b = GETARG_B(i);
- setobj2s(L, ra, cl->upvals[b]->v);
- continue;
- }
- case OP_GETGLOBAL: {
- TValue g;
- TValue *rb = KBx(i);
- sethvalue(L, &g, cl->env);
- lua_assert(ttisstring(rb));
- Protect(luaV_gettable(L, &g, rb, ra));
- continue;
- }
- case OP_GETTABLE: {
- Protect(luaV_gettable(L, RB(i), RKC(i), ra));
- continue;
- }
- case OP_SETGLOBAL: {
- TValue g;
- sethvalue(L, &g, cl->env);
- lua_assert(ttisstring(KBx(i)));
- Protect(luaV_settable(L, &g, KBx(i), ra));
- continue;
- }
- case OP_SETUPVAL: {
- UpVal *uv = cl->upvals[GETARG_B(i)];
- setobj(L, uv->v, ra);
- luaC_barrier(L, uv, ra);
- continue;
- }
- case OP_SETTABLE: {
- Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
- continue;
- }
- case OP_NEWTABLE: {
- int b = GETARG_B(i);
- int c = GETARG_C(i);
- sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
- Protect(luaC_checkGC(L));
- continue;
- }
- case OP_SELF: {
- StkId rb = RB(i);
- setobjs2s(L, ra+1, rb);
- Protect(luaV_gettable(L, rb, RKC(i), ra));
- continue;
- }
- case OP_ADD: {
- arith_op(luai_numadd, TM_ADD);
- continue;
- }
- case OP_SUB: {
- arith_op(luai_numsub, TM_SUB);
- continue;
- }
- case OP_MUL: {
- arith_op(luai_nummul, TM_MUL);
- continue;
- }
- case OP_DIV: {
- arith_op(luai_numdiv, TM_DIV);
- continue;
- }
- case OP_MOD: {
- arith_op(luai_nummod, TM_MOD);
- continue;
- }
- case OP_POW: {
- arith_op(luai_numpow, TM_POW);
- continue;
- }
- case OP_UNM: {
- TValue *rb = RB(i);
- if (ttisnumber(rb)) {
- lua_Number nb = nvalue(rb);
- setnvalue(ra, luai_numunm(nb));
- }
- else {
- Protect(Arith(L, ra, rb, rb, TM_UNM));
- }
- continue;
- }
- case OP_NOT: {
- int res = l_isfalse(RB(i)); /* next assignment may change this value */
- setbvalue(ra, res);
- continue;
- }
- case OP_LEN: {
- const TValue *rb = RB(i);
- switch (ttype(rb)) {
- case LUA_TTABLE: {
- setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
- break;
- }
- case LUA_TSTRING: {
- setnvalue(ra, cast_num(tsvalue(rb)->len));
- break;
- }
- default: { /* try metamethod */
- Protect(
- if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
- luaG_typeerror(L, rb, "get length of");
- )
- }
- }
- continue;
- }
- case OP_CONCAT: {
- int b = GETARG_B(i);
- int c = GETARG_C(i);
- Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
- setobjs2s(L, RA(i), base+b);
- continue;
- }
- case OP_JMP: {
- dojump(L, pc, GETARG_sBx(i));
- continue;
- }
- case OP_EQ: {
- TValue *rb = RKB(i);
- TValue *rc = RKC(i);
- Protect(
- if (equalobj(L, rb, rc) == GETARG_A(i))
- dojump(L, pc, GETARG_sBx(*pc));
- )
- pc++;
- continue;
- }
- case OP_LT: {
- Protect(
- if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
- dojump(L, pc, GETARG_sBx(*pc));
- )
- pc++;
- continue;
- }
- case OP_LE: {
- Protect(
- if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
- dojump(L, pc, GETARG_sBx(*pc));
- )
- pc++;
- continue;
- }
- case OP_TEST: {
- if (l_isfalse(ra) != GETARG_C(i))
- dojump(L, pc, GETARG_sBx(*pc));
- pc++;
- continue;
- }
- case OP_TESTSET: {
- TValue *rb = RB(i);
- if (l_isfalse(rb) != GETARG_C(i)) {
- setobjs2s(L, ra, rb);
- dojump(L, pc, GETARG_sBx(*pc));
- }
- pc++;
- continue;
- }
- case OP_CALL: {
- int b = GETARG_B(i);
- int nresults = GETARG_C(i) - 1;
- if (b != 0) L->top = ra+b; /* else previous instruction set top */
- L->savedpc = pc;
- switch (luaD_precall(L, ra, nresults)) {
- case PCRLUA: {
- nexeccalls++;
- goto reentry; /* restart luaV_execute over new Lua function */
- }
- case PCRC: {
- /* it was a C function (`precall' called it); adjust results */
- if (nresults >= 0) L->top = L->ci->top;
- base = L->base;
- continue;
- }
- default: {
- return; /* yield */
- }
- }
- }
- case OP_TAILCALL: {
- int b = GETARG_B(i);
- if (b != 0) L->top = ra+b; /* else previous instruction set top */
- L->savedpc = pc;
- lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
- switch (luaD_precall(L, ra, LUA_MULTRET)) {
- case PCRLUA: {
- /* tail call: put new frame in place of previous one */
- CallInfo *ci = L->ci - 1; /* previous frame */
- int aux;
- StkId func = ci->func;
- StkId pfunc = (ci+1)->func; /* previous function index */
- if (L->openupval) luaF_close(L, ci->base);
- L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
- for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
- setobjs2s(L, func+aux, pfunc+aux);
- ci->top = L->top = func+aux; /* correct top */
- lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
- ci->savedpc = L->savedpc;
- ci->tailcalls++; /* one more call lost */
- L->ci--; /* remove new frame */
- goto reentry;
- }
- case PCRC: { /* it was a C function (`precall' called it) */
- base = L->base;
- continue;
- }
- default: {
- return; /* yield */
- }
- }
- }
- case OP_RETURN: {
- int b = GETARG_B(i);
- if (b != 0) L->top = ra+b-1;
- if (L->openupval) luaF_close(L, base);
- L->savedpc = pc;
- b = luaD_poscall(L, ra);
- if (--nexeccalls == 0) /* was previous function running `here'? */
- return; /* no: return */
- else { /* yes: continue its execution */
- if (b) L->top = L->ci->top;
- lua_assert(isLua(L->ci));
- lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);
- goto reentry;
- }
- }
- case OP_FORLOOP: {
- lua_Number step = nvalue(ra+2);
- lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
- lua_Number limit = nvalue(ra+1);
- if (luai_numlt(0, step) ? luai_numle(idx, limit)
- : luai_numle(limit, idx)) {
- dojump(L, pc, GETARG_sBx(i)); /* jump back */
- setnvalue(ra, idx); /* update internal index... */
- setnvalue(ra+3, idx); /* ...and external index */
- }
- continue;
- }
- case OP_FORPREP: {
- const TValue *init = ra;
- const TValue *plimit = ra+1;
- const TValue *pstep = ra+2;
- L->savedpc = pc; /* next steps may throw errors */
- if (!tonumber(init, ra))
- luaG_runerror(L, LUA_QL("for") " initial value must be a number");
- else if (!tonumber(plimit, ra+1))
- luaG_runerror(L, LUA_QL("for") " limit must be a number");
- else if (!tonumber(pstep, ra+2))
- luaG_runerror(L, LUA_QL("for") " step must be a number");
- setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
- dojump(L, pc, GETARG_sBx(i));
- continue;
- }
- case OP_TFORLOOP: {
- StkId cb = ra + 3; /* call base */
- setobjs2s(L, cb+2, ra+2);
- setobjs2s(L, cb+1, ra+1);
- setobjs2s(L, cb, ra);
- L->top = cb+3; /* func. + 2 args (state and index) */
- Protect(luaD_call(L, cb, GETARG_C(i)));
- L->top = L->ci->top;
- cb = RA(i) + 3; /* previous call may change the stack */
- if (!ttisnil(cb)) { /* continue loop? */
- setobjs2s(L, cb-1, cb); /* save control variable */
- dojump(L, pc, GETARG_sBx(*pc)); /* jump back */
- }
- pc++;
- continue;
- }
- case OP_SETLIST: {
- int n = GETARG_B(i);
- int c = GETARG_C(i);
- int last;
- Table *h;
- if (n == 0) {
- n = cast_int(L->top - ra) - 1;
- L->top = L->ci->top;
- }
- if (c == 0) c = cast_int(*pc++);
- runtime_check(L, ttistable(ra));
- h = hvalue(ra);
- last = ((c-1)*LFIELDS_PER_FLUSH) + n;
- if (last > h->sizearray) /* needs more space? */
- luaH_resizearray(L, h, last); /* pre-alloc it at once */
- for (; n > 0; n--) {
- TValue *val = ra+n;
- setobj2t(L, luaH_setnum(L, h, last--), val);
- luaC_barriert(L, h, val);
- }
- continue;
- }
- case OP_CLOSE: {
- luaF_close(L, ra);
- continue;
- }
- case OP_CLOSURE: {
- Proto *p;
- Closure *ncl;
- int nup, j;
- p = cl->p->p[GETARG_Bx(i)];
- nup = p->nups;
- ncl = luaF_newLclosure(L, nup, cl->env);
- ncl->l.p = p;
- for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)];
- else {
- lua_assert(GET_OPCODE(*pc) == OP_MOVE);
- ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
- }
- }
- setclvalue(L, ra, ncl);
- Protect(luaC_checkGC(L));
- continue;
- }
- case OP_VARARG: {
- int b = GETARG_B(i) - 1;
- int j;
- CallInfo *ci = L->ci;
- int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
- if (b == LUA_MULTRET) {
- Protect(luaD_checkstack(L, n));
- ra = RA(i); /* previous call may change the stack */
- b = n;
- L->top = ra + n;
- }
- for (j = 0; j < b; j++) {
- if (j < n) {
- setobjs2s(L, ra + j, ci->base - n + j);
- }
- else {
- setnilvalue(ra + j);
- }
- }
- continue;
- }
- }
- }
-}
-
diff --git a/lib/lua/lvm.h b/lib/lua/lvm.h
deleted file mode 100644
index bfe4f56..0000000
--- a/lib/lua/lvm.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
-** Lua virtual machine
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lvm_h
-#define lvm_h
-
-
-#include "ldo.h"
-#include "lobject.h"
-#include "ltm.h"
-
-
-#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
-
-#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \
- (((o) = luaV_tonumber(o,n)) != NULL))
-
-#define equalobj(L,o1,o2) \
- (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
-
-
-LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
-LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
-LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
-LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
-LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
- StkId val);
-LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
- StkId val);
-LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);
-LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
-
-#endif
diff --git a/lib/lua/lzio.c b/lib/lua/lzio.c
deleted file mode 100644
index 293edd5..0000000
--- a/lib/lua/lzio.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
-** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
-** a generic input stream interface
-** See Copyright Notice in lua.h
-*/
-
-
-#include
-
-#define lzio_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "llimits.h"
-#include "lmem.h"
-#include "lstate.h"
-#include "lzio.h"
-
-
-int luaZ_fill (ZIO *z) {
- size_t size;
- lua_State *L = z->L;
- const char *buff;
- lua_unlock(L);
- buff = z->reader(L, z->data, &size);
- lua_lock(L);
- if (buff == NULL || size == 0) return EOZ;
- z->n = size - 1;
- z->p = buff;
- return char2int(*(z->p++));
-}
-
-
-int luaZ_lookahead (ZIO *z) {
- if (z->n == 0) {
- if (luaZ_fill(z) == EOZ)
- return EOZ;
- else {
- z->n++; /* luaZ_fill removed first byte; put back it */
- z->p--;
- }
- }
- return char2int(*z->p);
-}
-
-
-void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
- z->L = L;
- z->reader = reader;
- z->data = data;
- z->n = 0;
- z->p = NULL;
-}
-
-
-/* --------------------------------------------------------------- read --- */
-size_t luaZ_read (ZIO *z, void *b, size_t n) {
- while (n) {
- size_t m;
- if (luaZ_lookahead(z) == EOZ)
- return n; /* return number of missing bytes */
- m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
- memcpy(b, z->p, m);
- z->n -= m;
- z->p += m;
- b = (char *)b + m;
- n -= m;
- }
- return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
- if (n > buff->buffsize) {
- if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
- luaZ_resizebuffer(L, buff, n);
- }
- return buff->buffer;
-}
-
-
diff --git a/lib/lua/lzio.h b/lib/lua/lzio.h
deleted file mode 100644
index 51d695d..0000000
--- a/lib/lua/lzio.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
-** Buffered streams
-** See Copyright Notice in lua.h
-*/
-
-
-#ifndef lzio_h
-#define lzio_h
-
-#include "lua.h"
-
-#include "lmem.h"
-
-
-#define EOZ (-1) /* end of stream */
-
-typedef struct Zio ZIO;
-
-#define char2int(c) cast(int, cast(unsigned char, (c)))
-
-#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
-
-typedef struct Mbuffer {
- char *buffer;
- size_t n;
- size_t buffsize;
-} Mbuffer;
-
-#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
-
-#define luaZ_buffer(buff) ((buff)->buffer)
-#define luaZ_sizebuffer(buff) ((buff)->buffsize)
-#define luaZ_bufflen(buff) ((buff)->n)
-
-#define luaZ_resetbuffer(buff) ((buff)->n = 0)
-
-
-#define luaZ_resizebuffer(L, buff, size) \
- (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
- (buff)->buffsize = size)
-
-#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
-
-
-LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
-LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
- void *data);
-LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
-LUAI_FUNC int luaZ_lookahead (ZIO *z);
-
-
-
-/* --------- Private Part ------------------ */
-
-struct Zio {
- size_t n; /* bytes still unread */
- const char *p; /* current position in buffer */
- lua_Reader reader;
- void* data; /* additional data */
- lua_State *L; /* Lua state (for reader) */
-};
-
-
-LUAI_FUNC int luaZ_fill (ZIO *z);
-
-#endif
diff --git a/lib/lua/print.c b/lib/lua/print.c
deleted file mode 100644
index e240cfc..0000000
--- a/lib/lua/print.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
-** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
-** print bytecodes
-** See Copyright Notice in lua.h
-*/
-
-#include
-#include
-
-#define luac_c
-#define LUA_CORE
-
-#include "ldebug.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lundump.h"
-
-#define PrintFunction luaU_print
-
-#define Sizeof(x) ((int)sizeof(x))
-#define VOID(p) ((const void*)(p))
-
-static void PrintString(const TString* ts)
-{
- const char* s=getstr(ts);
- size_t i,n=ts->tsv.len;
- putchar('"');
- for (i=0; ik[i];
- switch (ttype(o))
- {
- case LUA_TNIL:
- printf("nil");
- break;
- case LUA_TBOOLEAN:
- printf(bvalue(o) ? "true" : "false");
- break;
- case LUA_TNUMBER:
- printf(LUA_NUMBER_FMT,nvalue(o));
- break;
- case LUA_TSTRING:
- PrintString(rawtsvalue(o));
- break;
- default: /* cannot happen */
- printf("? type=%d",ttype(o));
- break;
- }
-}
-
-static void PrintCode(const Proto* f)
-{
- const Instruction* code=f->code;
- int pc,n=f->sizecode;
- for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t");
- printf("%-9s\t",luaP_opnames[o]);
- switch (getOpMode(o))
- {
- case iABC:
- printf("%d",a);
- if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
- if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
- break;
- case iABx:
- if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
- break;
- case iAsBx:
- if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
- break;
- }
- switch (o)
- {
- case OP_LOADK:
- printf("\t; "); PrintConstant(f,bx);
- break;
- case OP_GETUPVAL:
- case OP_SETUPVAL:
- printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
- break;
- case OP_GETGLOBAL:
- case OP_SETGLOBAL:
- printf("\t; %s",svalue(&f->k[bx]));
- break;
- case OP_GETTABLE:
- case OP_SELF:
- if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
- break;
- case OP_SETTABLE:
- case OP_ADD:
- case OP_SUB:
- case OP_MUL:
- case OP_DIV:
- case OP_POW:
- case OP_EQ:
- case OP_LT:
- case OP_LE:
- if (ISK(b) || ISK(c))
- {
- printf("\t; ");
- if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
- printf(" ");
- if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
- }
- break;
- case OP_JMP:
- case OP_FORLOOP:
- case OP_FORPREP:
- printf("\t; to %d",sbx+pc+2);
- break;
- case OP_CLOSURE:
- printf("\t; %p",VOID(f->p[bx]));
- break;
- case OP_SETLIST:
- if (c==0) printf("\t; %d",(int)code[++pc]);
- else printf("\t; %d",c);
- break;
- default:
- break;
- }
- printf("\n");
- }
-}
-
-#define SS(x) (x==1)?"":"s"
-#define S(x) x,SS(x)
-
-static void PrintHeader(const Proto* f)
-{
- const char* s=getstr(f->source);
- if (*s=='@' || *s=='=')
- s++;
- else if (*s==LUA_SIGNATURE[0])
- s="(bstring)";
- else
- s="(string)";
- printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
- (f->linedefined==0)?"main":"function",s,
- f->linedefined,f->lastlinedefined,
- S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
- printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
- f->numparams,f->is_vararg?"+":"",SS(f->numparams),
- S(f->maxstacksize),S(f->nups));
- printf("%d local%s, %d constant%s, %d function%s\n",
- S(f->sizelocvars),S(f->sizek),S(f->sizep));
-}
-
-static void PrintConstants(const Proto* f)
-{
- int i,n=f->sizek;
- printf("constants (%d) for %p:\n",n,VOID(f));
- for (i=0; isizelocvars;
- printf("locals (%d) for %p:\n",n,VOID(f));
- for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
- }
-}
-
-static void PrintUpvalues(const Proto* f)
-{
- int i,n=f->sizeupvalues;
- printf("upvalues (%d) for %p:\n",n,VOID(f));
- if (f->upvalues==NULL) return;
- for (i=0; iupvalues[i]));
- }
-}
-
-void PrintFunction(const Proto* f, int full)
-{
- int i,n=f->sizep;
- PrintHeader(f);
- PrintCode(f);
- if (full)
- {
- PrintConstants(f);
- PrintLocals(f);
- PrintUpvalues(f);
- }
- for (i=0; ip[i],full);
-}
diff --git a/scripts/ai/collective.lua b/scripts/ai/collective.lua
deleted file mode 100644
index 0feaf84..0000000
--- a/scripts/ai/collective.lua
+++ /dev/null
@@ -1,12 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-control_rate = 0.5 -- Lower control rate.
-aggressive = true
-land_planet = false
-
-function create()
- mem.bribe_no = "No response."
- attack_choose()
-end
-
diff --git a/scripts/ai/dummy.lua b/scripts/ai/dummy.lua
deleted file mode 100644
index 2b334fc..0000000
--- a/scripts/ai/dummy.lua
+++ /dev/null
@@ -1,36 +0,0 @@
---[[
--- Dummy AI - Does nothing excpet brake and then float around.
---]]
-
--- Required control rate.
-control_rate = 2
-
-function create()
- ai.pushtask(0, "idle")
- ai.pushtask(0, "brake")
-end
-
--- No need for control.
-function control()
-
-end
-
--- No response.
-function attacked(attacker)
-
-end
-
--- Does nothing.
-function idle()
-
-end
-
--- Brake the pilot.
-function brake()
- ai.brake()
- if ai.isstopped() then
- ai.stop()
- ai.poptask()
- end
-end
-
diff --git a/scripts/ai/dvaered.lua b/scripts/ai/dvaered.lua
deleted file mode 100644
index ef4d102..0000000
--- a/scripts/ai/dvaered.lua
+++ /dev/null
@@ -1,26 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-aggressive = true
-
-
-function create()
- ai.setcredits(rnd.int(1000, ai.shipprice()/200))
- attack_choose()
- if rnd.int() > 0.4 then
- mem.bribe_no = "\"I shall especially enjoy your death.\""
- else
- mem.bribe_no = "\"You shall not buy my honor!\""
- end
-end
-
-function taunt(target, offense)
- -- Offense is not actually used.
- taunts = {
- "Prepare for annihilation!",
- "I shall wash my hull with your blood!",
- "Your head will make a great trophy!"
- }
- ai.comm(target, taunts[rnd.int(1, #taunts)])
-end
-
diff --git a/scripts/ai/empire.lua b/scripts/ai/empire.lua
deleted file mode 100644
index e58911b..0000000
--- a/scripts/ai/empire.lua
+++ /dev/null
@@ -1,52 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-armour_run = 40
-armour_return = 70
-aggressive = true
-
-function create()
- ai.setcredits(rnd.int(1000, ai.shipprice()/70))
- if rnd.int(0,2)==0 then
- ai.broadcast("The Empire is watching")
- end
-
- if rnd.int() > 0.7 then
- mem.bribe = math.sqrt(ai.shipmass())*(500. * rnd.int() + 1750.)
- mem.bribe_prompt = string.format("\"For some %d credits I could forget about seeing you.\"", mem.bribe)
- mem.bribe_paid = "\"Now, scram, before I change my mind.\""
- else
- if rnd.int() > 0.5 then
- mem.bribe_no = "\"You won't buy your way out of this one.\""
- else
- mem.bribe_no = "\"The Empire likes to make examples out of scum like you.\""
- end
- end
-
- attack_choose()
-end
-
-function taunt(target, offence)
- -- Only 50% of actual taunting.
- if rnd.int(0, 1) == 0 then
- return
- end
-
- -- Taunt.
- if offence then
- taunts = {
- "There is no room in this universe for scum like you!",
- "The Empire will enjoy your death!",
- "Your head will make a fine gift for the Emperor!"
- } else
- taunts = {
- "You dare attack me!",
- "You are no match for the Empire!",
- "The Empire will have your head!",
- "You'll regret this!"
- }
- end
-
- ai.comm(target, taunts[rnd.int(1, #taunts)])
-end
-
diff --git a/scripts/ai/escort.lua b/scripts/ai/escort.lua
deleted file mode 100644
index 7132322..0000000
--- a/scripts/ai/escort.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-include("../scripts/ai/tpl/escort.lua")
-
diff --git a/scripts/ai/escort_player.lua b/scripts/ai/escort_player.lua
deleted file mode 100644
index b1a2dd9..0000000
--- a/scripts/ai/escort_player.lua
+++ /dev/null
@@ -1,12 +0,0 @@
-include("../scripts/ai/tpl/escort.lua")
-
--- Settings
-armour_run = 40
-armour_return = 70
-aggressive = true
-command = false
-
-function create()
- mem.escort = ai.getPlayer()
-end
-
diff --git a/scripts/ai/flf.lua b/scripts/ai/flf.lua
deleted file mode 100644
index 512cb7e..0000000
--- a/scripts/ai/flf.lua
+++ /dev/null
@@ -1,36 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-aggressive = true
-safe_distance = 300
-armour_run = 100
-shield_return = 20
-land_planet = false
-
-function create()
- ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
- attack_choose()
-end
-
-function taunt(target, offence)
- -- Only 50% of actual taunting.
- if rnd.int(0, 1) == 0 then
- return
- end
-
- -- Taunt.
- if offence then
- taunts = {
- "For the Frontiier!",
- "You'll make great target practice!",
- "Purge the oppressors!"
- } else
- taunts = {
- "You are no match for the FLF!",
- "I've killed scum much more dangerous than you!"
- }
- end
-
- ai.comm(target, taunts[rnd.int(1, #taunts)])
-end
-
diff --git a/scripts/ai/goddard.lua b/scripts/ai/goddard.lua
deleted file mode 100644
index 72c3c06..0000000
--- a/scripts/ai/goddard.lua
+++ /dev/null
@@ -1,20 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-aggressive = true
-
-function create()
- ai.setcredits(rnd.int(300, ai.shipprice()/70))
- attack_choose()
-end
-
-function taunt(target, offense)
- -- Offence is not actually used.
- taunts = {
- "Prepare to face annihilation!",
- "I shall wash my hull in your blood!",
- "Your head will make a great trophy!"
- }
- ai.comm(target, taunts[rnd.int(1, #taunts)])
-end
-
diff --git a/scripts/ai/include/attack.lua b/scripts/ai/include/attack.lua
deleted file mode 100644
index 07db9aa..0000000
--- a/scripts/ai/include/attack.lua
+++ /dev/null
@@ -1,49 +0,0 @@
---[[
--- Attack wrappers for calling the correct attack functions.
---]]
-
-include("../scripts/ai/include/attack_generic.lua")
-include("../scripts/ai/include/attack_bomber.lua")
-
-atk_think = true
-
---[[
--- Wrapper for the think functions.
---]]
-function attack_think()
- -- Not everyone wants to think..
- if atk_think == false then
- return
- end
-
- if mem.atk_think ~= nil then
- mem.atk_think()
- else
- atk_g_think()
- end
-end
-
---[[
--- Wrapper for the attack functions.
---]]
-function attack()
- if mem.atk ~= nil then
- mem.atk()
- else
- atk_g()
- end
-end
-
---[[
--- Generic function to choose what attack functions match the ship best.
---]]
-function attack_choose()
- class = ai.shipclass()
---[[
- if class == "Bomber" then
- mem.atk_think = atk_b_think
- mem.atk = atk_b
- end
- ]]
-end
-
diff --git a/scripts/ai/include/attack_bomber.lua b/scripts/ai/include/attack_bomber.lua
deleted file mode 100644
index 9e2c2a0..0000000
--- a/scripts/ai/include/attack_bomber.lua
+++ /dev/null
@@ -1,106 +0,0 @@
---[[
--- Attack functions for bombers.
---]]
-
---[[
--- Bombers don't really thing, they lock on until target is dead.
---]]
-function atk_b_think()
- -- No thinking atm.
-end
-
---[[
--- Attack the current target, task pops when target is dead.
---
--- Specialized for bomber type craft. AI will try to shoot missiles and such
--- until out and then they will melee.
---]]
-function atk_b()
- target = ai.target()
- ai.hostile(target) -- Mark as hostile.
-
- -- Make sure pilot exists.
- if not ai.exists(target) then
- ai.poptask()
- return
- end
-
- ai.settarget(target)
-
- -- Get stats about enemy.
- dist = ai.dist(ai.pos(target)) -- Get distance.
-
- -- Get bombing tool.
- secondary, special = ai.secondary("ranged")
- if secondary ~= "Launcher" or special == "Dumb" then -- No launcher, must melee.
- range = ai.getweaprange()
-
- -- Must approach.
- if dist > range then
- dir = ai.face(target)
- if dir < 10 then
- ai.accel()
- end
-
- -- Time to shoot!
- else
- dir = ai.aim(target) -- We aim instead of face.
-
- -- Fire secondary.
- if dir < 10 or special == "Turret" then
- ai.shoot(1)
- end
-
- -- Fire primary.
- if dir < 10 or ai.hasturrets() then
- ai.shoot()
- end
- end
- return -- No need to do ranged attack calculations.
- end
-
- -- Get ranges relative to bombing weapon of choice.
- bombrange = ai.getweaprange(1)
- backoff = bombrange / 4
-
- if dist > bombrange then
- dir = ai.face(target)
- if dir < 10 then
- ai.accel()
- end
-
- -- In bombing range.
- elseif dist > backoff then
- dir = ai.face(target)
-
- -- Shoot missiles if in range.
- if secondary == "Launcher" and
- dist < ai.getweaprange(1) then
-
- -- More lenient with aiming.
- if special == "Smart" and dir < 30 then
- ai.shoot(2)
-
- -- Non-smart miss more.
- elseif dir < 10 then
- ai.shoot(2)
- end
- end
-
- -- We don't apprauch, we try to stay away from melee.
-
- -- Time to break attack and get back to bomb.
- else
- range = ai.getweaprange()
-
- -- Flee
- ai.face(target, true)
- ai.accel()
-
- -- Fire turret if being chased.
- if dist < range and ai.hasturrets() then
- ai.shoot()
- end
- end
-end
-
diff --git a/scripts/ai/include/attack_generic.lua b/scripts/ai/include/attack_generic.lua
deleted file mode 100644
index e962948..0000000
--- a/scripts/ai/include/attack_generic.lua
+++ /dev/null
@@ -1,141 +0,0 @@
---[[
--- Generic attack functions.
---]]
-
-atk_changetarget = 1.8
-atk_approach = 1.4
-atk_aim = 1.0
-
---[[
--- Mainly manages targetting nearest enemy.
---]]
-function atk_g_think()
- enemy = ai.getenemy()
- target = ai.target()
-
- -- Stop attacking if it doesn't exist.
- if not ai.exists(target) then
- ai.poptask()
- return
- end
-
- -- Get new target if it's closer.
- if enemy ~= target and enemy ~= nil then
- dist = ai.dist(target)
- range = ai.getweaprange()
-
- -- Shouldn't switch targets if close.
- if dist > 400 and dist > range * atk_changetarget then
- ai.poptask()
- ai.pushtask(0, "attack", enemy)
- end
- end
-end
-
---[[
--- Generic "brute force" attack. Doesn't really do anything interesting.
---]]
-function atk_g()
- target = ai.target()
-
- -- Make sure pilot exists.
- if not ai.exists(target) then
- ai.poptask()
- return
- end
-
- -- Check if is bribed by target.
- if ai.isbribed(target) then
- ai.poptask()
- return
- end
-
- -- Targetting stuff.
- ai.hostile(target) -- Mark as hostile.
-
- ai.settarget(target)
-
- -- Get stats about enemy.
- dist = ai.dist(ai.pos(target)) -- Get distance.
- range = ai.getweaprange()
-
- -- We first bias towards range.
- if dist > range * atk_approach then
- atk_g_ranged(target, dist)
-
- -- Now we do an approach.
- elseif dist > range * atk_aim then
- atk_g_approach(target, dist)
-
- -- Close enough to melee.
- else
- atk_g_melee(target, dist)
- end
-end
-
--- ]]
--- Enter ranged combat with the target.
--- ]]
-function atk_g_ranged(target, dist)
- dir = ai.face(target) -- Normal face the target.
- secondary, special, ammo = ai.secondary("ranged")
-
- -- Always use figher bay.
- if secondary == "" then
-
- -- Shoot missiles if in range.
- elseif secondary == "Launcher" and
- dist < ai.getweaprange(1) then
- -- More lenient with aiming.
- if special == "Smart" and dir < 30 then
- ai.shoot(2)
-
- -- Non-smart miss more.
- elseif dir < 10 then
- ai.shoot(2)
- end
- end
-
- -- Approach for melee.
- if dir < 10 then
- ai.accel()
- end
-end
-
---[[
--- Approaches the target.
---]]
-function atk_g_approach(target, dist)
- dir = ai.aim(target)
- if dir < 10 then
- ai.accel()
- end
-end
-
---[[
--- Melee the target.
---]]
-function atk_g_melee(target, dist)
- secondary, special = ai.secondary("melee")
- dir = ai.aim(target) -- We aim instead of face.
- range = ai.getweaprange()
-
- -- Fire non-smart secondary weapons.
- if(secondary == "Launcher" and special ~= "Smart") or
- secondary == "Beam Weapon" then
- if dir < 10 or special == "Turret" then -- Need good acuracy.
- ai.shoot(2)
- end
- end
-
- -- Drifting away we'll want to get closer.
- if dir < 10 and dist > 0.5*range and ai.relvel(target) > -10 then
- ai.accel()
- end
-
- -- Shoot if should be shooting.
- if(dir < 10 and dist < range) or ai.hasturrets() then
- ai.shoot()
- end
-end
-
diff --git a/scripts/ai/include/basic.lua b/scripts/ai/include/basic.lua
deleted file mode 100644
index 95a327b..0000000
--- a/scripts/ai/include/basic.lua
+++ /dev/null
@@ -1,105 +0,0 @@
--- [[
--- Basic tasks for a pilot, no need to reinvent the wheel with these.
---
--- The idea is to have it all here and only really work on the "control"
--- functions and such for each AI.
---]]
-
---[[
--- Attempt to land on a planet.
---]]
-function land()
- -- Only want to land once, prevents guys fomr never leaving.
- if mem.landed then
- ai.poptask()
- return
- end
-
- target = mem.land
- dir = ai.face(target)
- dist = ai.dist(target)
- bdist = ai.minbrakedist()
-
- -- Need to get closer.
- if dir < 10 and dist > bdist then
- ai.accel()
- -- Need to start braking.
- elseif dist < bdist then
- ai.poptask()
- ai.pushtask(0, "landstop")
- end
-end
-
-function landstop()
- ai.brake()
-
- if ai.isstopped() then
- ai.stop() -- Will stop the pilot if below err vel.
- ai.settime(0, rnd.int(8000, 15000)) -- We wait during a while.
- ai.poptask()
- ai.pushtask(0, "landwait")
- end
-end
-
-function landwait()
- target = mem.land
- dist = ai.dist(target)
-
- -- In case for some reason landed far away..
- if dist > 50 then
- ai.poptask()
- ai.pushtask(0, "land")
-
- elseif ai.timeup(0) then
- mem.landed = true -- Mark as landed so they don't spend time forever floating around.
- ai.poptask() -- Ready to do whatever we were doing before.
- end
-end
-
---[[
--- Attempts to run from the target.
---]]
-function runaway()
- target = ai.target()
-
- -- Target must exist.
- if not ai.exists(target) then
- ai.poptask()
- return
- end
-
- dir = ai.face(target, true)
- ai.accel()
-
- --[[
- -- TODO: Afterburner handling.
- -- if ai.hasafterburner() then
- -- ai.afterburn(true)
- -- end
- --]]
- if ai.hasturrets() then
- dist = ai.dist(ai.pos(target))
- if dist < ai.getweaprange() then
- ai.settarget(target)
- ai.shoot()
- end
- end
-end
-
---[[
--- Start heading away to try to hyperspace.
---
--- Will need the following in control() to work:
---
--- task = ai.taskname()
--- if task == "hyperspace" then
--- ai.hyperspace() -- Try to hyperspace.
--- end
---]]
-function hyperspace()
- dir = ai.face(-1) -- Face away from (0,0).
- if(dir < 10) then
- ai.accel()
- end
-end
-
diff --git a/scripts/ai/noidle.lua b/scripts/ai/noidle.lua
deleted file mode 100644
index cf018a2..0000000
--- a/scripts/ai/noidle.lua
+++ /dev/null
@@ -1,7 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
-aggressive = true
-
--- No idle function, ship won't react until it detects enemies.
-function idle()
-end
diff --git a/scripts/ai/pirate.lua b/scripts/ai/pirate.lua
deleted file mode 100644
index a4a0a51..0000000
--- a/scripts/ai/pirate.lua
+++ /dev/null
@@ -1,53 +0,0 @@
-include("../scripts/ai/tpl/generic.lua")
-
--- Settings.
-aggressive = true
-safe_distance = 500
-armour_run = 80
-armour_return = 100
-
-function create()
- attack_choose()
- ai.setcredits(ai.shipprice()/1000, ai.shipprice()/40)
-
- -- Deal with bribeability.
- if rnd.int() < 0.05 then
- mem.bribe_no = "\"You won't be able to slide out of this one!\""
- else
- mem.bribe = math.sqrt(ai.shipmass()) * (300. * rnd.int() + 850.)
- if rnd.int() > 0.5 then
- mem.bribe_prompt = string.format("\"It'll cost you %d credits for me to ifnore your pile \
- of rubbish.\"", mem.bribe)
- mem.bribe_paid = "\"You're lucky I'm so kind.\""
- else
- mem.bribe_prompt = string.format("\"I'm in a good mood so I'll let you go for \
- %d credits.\"", mem.bribe)
- mem.bribe_paid = "\"Life doesn't get easier then this.\""
- end
- end
-end
-
-function taunt(target, offense)
- -- Only 50% of actually taunting.
- if rnd.int(0,1) == 0 then
- return
- end
-
- -- Some taunts.
- if offense then
- taunts = {
- "Prepare to be boarded!",
- "Yohoho!",
- "What's a pretty ship like you doing in a place like this?!"
- }
- else
- taunts = {
- "You dare attack me?!",
- "You think that you can take me on?!",
- "JUST!! DIE!!",
- "You'll regret this!"
- }
- end
- ai.comm(target, taunts[rnd.int(1, #taunts)])
-end
-
diff --git a/scripts/ai/scout.lua b/scripts/ai/scout.lua
deleted file mode 100644
index d6df314..0000000
--- a/scripts/ai/scout.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-include("../scripts/ai/tpl/scout.lua")
-
diff --git a/scripts/ai/tpl/escort.lua b/scripts/ai/tpl/escort.lua
deleted file mode 100644
index 36c7b21..0000000
--- a/scripts/ai/tpl/escort.lua
+++ /dev/null
@@ -1,116 +0,0 @@
-include("../scripts/ai/tpl/generic.lua") -- Simple create function.
-
--- Shouldn't think, should only obey orders.
-atk_think = false
-command = true
-
-function create(master)
- mem.escort = master
- mem.carrier = true
- attack_choose()
-end
-
--- Just tries to guard mem.escort.
-function idle()
- ai.pushtask(0, "escort")
-end
-
--- Escorts the target.
-function escort()
- target = mem.escort
-
- -- Will just float without a target to escort.
- if not ai.exists(target) then
- return
- end
-
- dir = ai.face(target)
- dist = ai.dist(target)
- bdist = ai.minbrakedist()
-
- -- Close enough.
- if ai.isstopped() and dist < 300 then
- return
-
- -- Brake.
- elseif dist+100 < bdist then
- ai.pushtask(0, "brake")
-
- -- Must approach.
- elseif dir < 10 and dist > 300 then
- ai.accel()
- end
-end
-
--- Just brakes.
-function brake()
- ai.brake()
- if ai.isstopped() then
- ai.poptask()
- end
-end
-
--- Holds position.
-function hold()
- if not ai.isstopped() then
- ai.brake()
- end
-end
-
--- Tries to fly back to carrier.
-function flyback()
- target = mem.escort
-
- dir = ai.face(target)
- dist = ai.dist(target)
- bdist = ai.minbrakedist()
-
- -- Try to brake.
- if not ai.isstopped() and dist < bdist then
- ai.pushtask(0, "brake")
-
- -- Try to dock.
- elseif ai.isstopped() and dist < 30 then
- ai.dock(target)
-
- -- Far away, must approach.
- elseif dir < 10 then
- ai.accel()
- end
-end
-
---[[
--- Escort commands.
---]]
---Attack target.
-function e_attack(target)
- if command then
- if target ~= nil then
- ai.pushtask(0, "attack", target)
- end
- end
-end
-
--- Hold position.
-function e_hold()
- if command then
- ai.pushtask(0, "hold")
- end
-end
-
--- Return to carrier.
-function e_return()
- if command and mem.carrier then
- ai.pushtask(0, "flyback")
- end
-end
-
--- Clear orders.
-function e_clear()
- if command then
- while ai.taskname() ~= "none" do
- ai.poptask()
- end
- end
-end
-
diff --git a/scripts/ai/tpl/generic.lua b/scripts/ai/tpl/generic.lua
deleted file mode 100644
index 5d622bd..0000000
--- a/scripts/ai/tpl/generic.lua
+++ /dev/null
@@ -1,129 +0,0 @@
-include("../scripts/ai/include/basic.lua")
-include("../scripts/ai/include/attack.lua")
-
---[[
--- Variables to adjust AI.
---
--- These variables can be used to adjust the generic AI to suit other roles.
---]]
-
-armour_run = 0 -- At which damage to run at.
-armour_return = 0 -- At which armour to return to combat.
-shield_run = 0 -- At which shield to run.
-shield_return = 0 -- At which shield to return to combat.
-aggressive = false -- Should pilot actively attack enemies?
-safe_distance = 300 -- Safe distance from enemies to jump.
-land_planet = true -- Should land on planets?
-
-control_rate = 2
-
-function control()
- task = ai.taskname()
- enemy = ai.getenemy()
-
- -- Get new task.
- if task == "none" then
- -- We'll first check enemy.
- if enemy ~= nil and aggressive then
- taunt(enemy, true)
- ai.pushtask(0, "attack", enemy)
- else
- idle()
- end
-
- -- Think for attacking.
- elseif task == "attack" then
- target = ai.target()
-
- -- Needs to have a target.
- if target == nil then
- ai.poptask()
- end
-
- -- Runaway if needed.
- if(shield_run > 0 and ai.pshield() < shield_run
- and ai.pshield() < ai.pshield(target)) or
- (armour_run > 0 and ai.parmour() < armour_run
- and ai.parmour() < ai.parmour(target)) then
- ai.pushtask(0, "runaway", ai.target())
-
- -- Think like normal.
- else
- attack_think()
- end
-
- -- Pilot is running away.
- elseif task == "runaway" then
- target = ai.target()
- dist = ai.dist(target)
-
- if aggressive and((shield_return > 0 and ai.pshield() >= shield_return) or
- (armour_return > 0 and ai.parmour() >= armour_return)) then
- ai.poptask() -- "attack" should be above "runaway"
-
- -- Try to jump now.
- elseif dist > safe_distance then
- ai.hyperspace()
- end
-
- -- Enemy sighted, handled after running away.
- elseif enemy ~= nil and aggressive then
- taunt(enemy, true)
- ai.pushtask(0, "attack", enemy)
-
- -- Enter hyperspace if possible.
- elseif task == "hyperspace" then
- ai.hyperspace() -- Try to hyperspace.
- end
-end
-
-function attacked(attacker)
- task = ai.taskname()
- if task ~= "attack" and task ~= "runaway" then
- -- Some taunting
- taunt(attacker, false)
-
- -- Now pilot fights back.
- ai.pushtask(0, "attack", attacker)
-
- elseif task == "attack" then
- if ai.target() ~= attacker then
- ai.pushtask(0, "attack", attacker)
- end
- elseif task == "runaway" then
- if ai.target() ~= attacker then
- ai.poptask()
- ai.pushtask(0, "runaway", attacker)
- end
- end
-end
-
--- Default task to run when idle.
-function idle()
- planet = ai.landplanet()
- -- Planet must exist.
- if planet == nil or land_planet == false then
- ai.settimer(0, rnd.int(1000, 3000))
- ai.pushtask(0, "enterdelay")
- else
- mem.land = planet
- ai.pushtask(0, "hyperspace")
- ai.pushtask(0, "land")
- end
-end
-
--- Delays the ship when entering systems so that it doesn't leave right away.
-function enterdelay()
- if ai.timeup(0) then
- ai.pushtask(0, "hyperspace")
- end
-end
-
-function create()
- attack_choose()
-end
-
-function taunt(target, offensive)
- -- Empty stub.
-end
-
diff --git a/scripts/ai/tpl/merchant.lua b/scripts/ai/tpl/merchant.lua
deleted file mode 100644
index efe0ab8..0000000
--- a/scripts/ai/tpl/merchant.lua
+++ /dev/null
@@ -1,83 +0,0 @@
-include("../scripts/ai/include/basic.lua")
-
--- Variables.
-enemy_close = 500 -- Distance enemy is too close for comfort.
-
--- Required control rate.
-control_rate = 2
-
-function control()
- task = ai.taskname()
- enemy = ai.getenemy()
-
- -- Runaway if enemy is near.
- if task ~= "runaway" and enemy ~= nil and ai.dist(enemy) < enemy_close then
- if task ~= "none" then
- ai.poptask()
- end
- ai.pushtask(0, "runaway", enemy)
- elseif task == "hyperspace" then
- ai.hyperspace() -- Try to hyperspace.
-
- -- Try to jump when far enough away.
- elseif task == "runaway" then
- target = ai.target()
-
- -- Check if should still run.
- if not ai.exists(target) then
- ai.poptask()
- return
- end
-
- -- See if another enemy is closer.
- if enemy ~= nil and enemy ~= target then
- ai.poptask()
- ai.pushtask(0, "runaway", enemy)
- end
-
- -- Try to jump.
- if ai.dist(target) > 400 then
- ai.hyperspace()
- end
-
- -- Find something to do.
- elseif task == "none" then
- planet = ai.landplanet()
- -- Planet must exist.
- if planet == nil then
- ai.settimer(0, rnd.int(1000, 3000))
- ai.pushtask(0, "enterdelay")
- else
- mem.land = planet
- ai.pushtask(0, "hyperspace")
- ai.pushtask(0, "land")
- end
- end
-end
-
--- Delay the ship when entering systems so that it doesn't leave right away.
-function entedelay()
- if ai.timeup(0) then
- ai.pushtask(0, "hyperspace")
- end
-end
-
-function sos()
-
-end
-
-function attacked(attacker)
- if ai.taskname() ~= "runaway" then
- sos()
- -- Sir Robin bravely ran away!!
- ai.pushtask(0, "runaway", attacker)
- else
- ai.poptask()
- ai.pushtask(0, "runaway", attacker)
- end
-end
-
-function create()
-
-end
-
diff --git a/scripts/ai/tpl/scout.lua b/scripts/ai/tpl/scout.lua
deleted file mode 100644
index 7c34355..0000000
--- a/scripts/ai/tpl/scout.lua
+++ /dev/null
@@ -1,107 +0,0 @@
-include("../scripts/ai/include/basic.lua")
-
--- Variables.
-planet_dist = 1500 -- Distance to keep from planets.
-enemy_dist = 800 -- Distance to keep from enemies.
-
--- Required control rate.
-control_rate = 2
--- Required "control" function.
-function control()
- task = ai.taskname()
-
- if task == "none" or task == "idle" then
- enemy = ai.getenemy()
-
- -- There is an enemy.
- if enemy ~= nil then
- if ai.dist(enemy) < enemy_dist or ai.haslockon() then
- ai.pushtask(0, "runaway", enemy)
- return
- end
- end
-
- -- Nothing to do so check if we are too far from the planet.
- -- (If there is one).
- if mem.approach == nil then
- mem.approach = ai.rndplanet()
- end
- planet = mem.approach
-
- if planet ~= nil then
- if ai.dist(planet) > planet_dist then
- ai.pushtask(0, "approach")
- return
- end
- end
-
- -- Go idle if no task.
- if task == "none" then
- ai.pushtask(0, "idle")
- return
- end
-
- -- Check if we are near enough.
- elseif task == "approach" then
- planet = mem.approach
-
- if ai.dist(planet) < planet_dist + ai.minbrakedist() then
- ai.poptask()
- ai.pushtask(0, "idle")
- return
- end
-
- -- Check if we need to run more.
- elseif task == "runaway" then
- enemy = ai.target()
-
- if ai.dist(enemy) > enemy_dist and ai.haslockon() == false then
- ai.poptask()
- return
- end
- end
-end
-
--- Required "attacked" function.
-function attacked(attaker)
- task = ai.taskname()
-
- -- Start running away
- if task ~= "runaway" then
- ai.pushtask(0, "runaway", attacker)
- elseif task == "runaway" then
- if ai.target() ~= attacker then
- -- Runaway from the new guy.
- ai.poptask()
- ai.pushtask(0, "runaway", attacker)
- end
- end
-end
-
--- Required "create" function.
-function create()
-
-end
-
--- Effectively does nothing.
-function idle()
- if ai.isstopped() == false then
- ai.brake()
- end
-end
-
--- Approaches the target.
-function approach()
- target = mem.approach
- dir = ai.face(target)
- dist = ai.dist(target)
-
- -- See if we should accel or brake.
- if dist > planet_dist then
- ai.accel()
- else
- ai.poptask()
- ai.pushtask(0, "idle")
- end
-end
-
diff --git a/scripts/ai/trader.lua b/scripts/ai/trader.lua
deleted file mode 100644
index 50ce91b..0000000
--- a/scripts/ai/trader.lua
+++ /dev/null
@@ -1,34 +0,0 @@
-include("../scripts/ai/tpl/merchant.lua")
-
-function sos()
- msg = {
- "Mayday! We are under attack!",
- "Requesting assistance. We are under attack!",
- "Merchant vessel here under attack! Requestin help!!",
- "Help! Ship under fire!",
- string.format("Mayday Merchant %s being assaulted!", ai.shipclass());
- }
- ai.broadcast(msg[rnd.int(1, #msg)])
-end
-
-function create()
- ai.setcredits(rnd.int(100, ai.shipprice()/25))
-
- mem.bribe_no = "\"The space Traders do not negotiate with criminals.\""
-
- -- Some stuff has more than others.
- num = rnd.int(12)
- if num < 5 then
- cargo = "Food"
- elseif num < 8 then
- cargo = "Ore"
- elseif num < 10 then
- cargo = "Industrial Goods"
- elseif num < 12 then
- cargo = "Luxury Goods"
- else
- cargo = "Medicine"
- end
- ai.setcargo(cargo, rnd.int(0, ai.cargofree()))
-end
-
diff --git a/snd/music.lua b/snd/music.lua
deleted file mode 100644
index 5edeca7..0000000
--- a/snd/music.lua
+++ /dev/null
@@ -1,242 +0,0 @@
---[[
--- Music will get called with a string parameter indicating status.
--- Valid Parameters:
--- load - game is loading.
--- land - player landed.
--- takeoff - player took off.
--- combat - Player just got a hostile on screen.
--- idle - Current playing music ran out.
-]]--
-last = "idle"
-function choose(str)
- -- Means to only change song if needed.
- if str == nil then
- str = "ambient"
- end
-
- if str == "load" then
- choose_load()
-
- elseif str == "intro" then
- choose_intro()
-
- elseif str == "credits" then
- choose_credits()
-
- elseif str == "land" then
- choose_land()
-
- elseif str == "takeoff" then
- choose_takeoff()
-
- elseif str == "ambient" then
- choose_ambient()
-
- elseif str == "combat" then
- choose_combat()
-
- elseif str == "idle" and last ~= "idle" then
- -- We'll play the same as last unless it was takeoff.
- if last == "takeoff" then
- choose_ambient()
- else
- choose(last)
- end
- end
-
- if str ~= "idle" then
- last = str -- Save the last string so we can use it.
- end
-end
-
-function checkIfPlayingOrStop(song)
- if music.isPlaying() then
- if music.current() ~= song then
- music.stop()
- end
- return true
- end
- return false
-end
-
--- Loading songs.
-function choose_load()
- load_song = "machina"
- -- Don't play again if needed.
- if checkIfPlayOrStop(load_song) then
- return
- end
- music.load(load_song)
- music.play()
- music.play()
-end
-
--- Intro music.
-function choose_intro()
- intro_song = "intro"
- -- Don't play again if needed.
- if checkIfPlayingOrStop(intro_song) then
- return
- end
- music.load(intro_song)
- music.play()
-end
-
--- Credits music.
-function choose_credits()
- credits_song = "empire1"
- -- Don't play again if needed.
- if checkIfPlayingOrStop(credits_song) then
- return
- end
- music.load(credits_song)
- music.play()
-end
-
--- Landing songs.
-function choose_land()
- planet = space.getPlanet()
- class = planet:class()
-
- if class == "M" then
- mus = "agriculture"
- elseif name == "Anecu" then -- TODO: We need a way to differenciate aquatics.
- mus = "ocean"
- elseif class == "P" then
- mus = "snow"
- else
- if planet:services() > 0 then
- mus = "cosmostation"
- else
- mus = "agriculture"
- end
- end
-
- music.load(mus)
- music.play()
-end
-
--- Takeoff songs.
-function choose_takeoff()
- -- No need to restart.
- if last == "takeoff" and music.isPlaying() then
- return
- end
- takeoff = { "liftoff", "launch2", "launch3chatstart" }
- music.load(takeoff[rnd.int(1, #takeoff)])
- music.play()
-end
-
--- Save old data.
-last_sysFaction = nil
-last_sysNebuDens = nil
-last_sysNebuVol = nil
-ambient_neutral = { "ambient2", "mission",
- "peace1", "peace2", "peace4", "peace6" }
--- Choose ambient songs.
-function choose_ambient()
- force = true
-
- -- Check to see if we want to update.
- if music.isPlaying() then
- if last == "takeoff" then
- return
- elseif last == "ambient" then
- force = false
- end
- end
-
- -- Get information about the current system.
- sys = space.getSystem()
- factions = sys:faction()
- nebu_dens, nebu_vol = sys:nebulae()
-
- -- Check to see if changing faction zone.
- if not factions[last_sysFaction] then
- -- Table must not be empty.
- if next(factions) ~= nil then
- force = true
- end
-
- if force then
- -- Give first value to last faction.
- for k, v in pairs(factions) do
- last_sysFaction = k
- break
- end
- end
- end
-
- -- Check to see if entering nebulae.
- nebu = nebu_dens > 0
- if nebu ~= last_sysNebuDens then
- force = true
- last_sysNebuDens = nebu
- end
-
- -- Must be forced.
- if force then
- -- Choose the music, bias by faction first.
- add_neatral = false
- if factions["Collective"] then
- ambient = { "collective1" }
- elseif factions["Empire"] then
- ambient = { "empire1", "empire1", "empire1", "empire1" }
- add_neutral = true
- elseif nebu then
- ambient = { "ambient1", "ambient1", "ambient1", "ambient1" }
- add_neutral = true
- else
- ambient = ambient_neutral
- end
-
- -- Check if we need to append neutral ambient songs.
- if add_neutral then
- for k,v in pairs(ambient_neutral) do
- table.insert(ambient, v)
- end
- end
-
- -- Make sure it's not already in the list or that we have to stop the
- -- currently playing song.
- if music.isPlaying() then
- cur = music.current()
- for k,v in pairs(ambient) do
- if cur == v then
- return
- end
- end
-
- music.stop()
- return
- end
-
- -- Load music and play.
- music.load(ambient[rnd.int(1, #ambient)])
- music.play()
- end
-end
-
--- Battle songs.
-function choose_combat()
- -- Stop music first, but since it'll get saved it'll run this next.
- if music.isPlaying() then
- music.stop()
- return
- end
-
- -- Get some data about the system.
- sys = space.getSystem()
- nebu_dens, nebu_vol = sys:nebulae()
-
- nebu = nebu_dens > 0
- if nebu then
- combat = { "nebu_battle1" }
- else
- combat = { "galacticbattle" }
- end
-
- music.load(combat[rnd.int(1, #combat)])
- music.play()
-end
-
diff --git a/snd/music/agriculture.ogg b/snd/music/agriculture.ogg
deleted file mode 100644
index fe51b62..0000000
Binary files a/snd/music/agriculture.ogg and /dev/null differ
diff --git a/snd/music/ambient1.ogg b/snd/music/ambient1.ogg
deleted file mode 100644
index 798282f..0000000
Binary files a/snd/music/ambient1.ogg and /dev/null differ
diff --git a/snd/music/ambient2.ogg b/snd/music/ambient2.ogg
deleted file mode 100644
index 47b2aa9..0000000
Binary files a/snd/music/ambient2.ogg and /dev/null differ
diff --git a/snd/music/collective1.ogg b/snd/music/collective1.ogg
deleted file mode 100644
index fadb39b..0000000
Binary files a/snd/music/collective1.ogg and /dev/null differ
diff --git a/snd/music/cosmostation.ogg b/snd/music/cosmostation.ogg
deleted file mode 100644
index 4f9ddfc..0000000
Binary files a/snd/music/cosmostation.ogg and /dev/null differ
diff --git a/snd/music/empire1.ogg b/snd/music/empire1.ogg
deleted file mode 100644
index adc8df5..0000000
Binary files a/snd/music/empire1.ogg and /dev/null differ
diff --git a/snd/music/galacticbattle.ogg b/snd/music/galacticbattle.ogg
deleted file mode 100644
index af9bf9b..0000000
Binary files a/snd/music/galacticbattle.ogg and /dev/null differ
diff --git a/snd/music/intro.ogg b/snd/music/intro.ogg
deleted file mode 100644
index 1319179..0000000
Binary files a/snd/music/intro.ogg and /dev/null differ
diff --git a/snd/music/landing_sinister.ogg b/snd/music/landing_sinister.ogg
deleted file mode 100644
index 0b86e92..0000000
Binary files a/snd/music/landing_sinister.ogg and /dev/null differ
diff --git a/snd/music/launch2.ogg b/snd/music/launch2.ogg
deleted file mode 100644
index e110a30..0000000
Binary files a/snd/music/launch2.ogg and /dev/null differ
diff --git a/snd/music/launch3chatstart.ogg b/snd/music/launch3chatstart.ogg
deleted file mode 100644
index 07fb866..0000000
Binary files a/snd/music/launch3chatstart.ogg and /dev/null differ
diff --git a/snd/music/liftoff.ogg b/snd/music/liftoff.ogg
deleted file mode 100644
index e357653..0000000
Binary files a/snd/music/liftoff.ogg and /dev/null differ
diff --git a/snd/music/machina.ogg b/snd/music/machina.ogg
deleted file mode 100644
index adda9f2..0000000
Binary files a/snd/music/machina.ogg and /dev/null differ
diff --git a/snd/music/mission.ogg b/snd/music/mission.ogg
deleted file mode 100644
index b3bbf78..0000000
Binary files a/snd/music/mission.ogg and /dev/null differ
diff --git a/snd/music/nebu_battle1.ogg b/snd/music/nebu_battle1.ogg
deleted file mode 100644
index cccfd71..0000000
Binary files a/snd/music/nebu_battle1.ogg and /dev/null differ
diff --git a/snd/music/ocean.ogg b/snd/music/ocean.ogg
deleted file mode 100644
index 27ee1c4..0000000
Binary files a/snd/music/ocean.ogg and /dev/null differ
diff --git a/snd/music/peace1.ogg b/snd/music/peace1.ogg
deleted file mode 100644
index f6babab..0000000
Binary files a/snd/music/peace1.ogg and /dev/null differ
diff --git a/snd/music/peace2.ogg b/snd/music/peace2.ogg
deleted file mode 100644
index 89e213c..0000000
Binary files a/snd/music/peace2.ogg and /dev/null differ
diff --git a/snd/music/peace4.ogg b/snd/music/peace4.ogg
deleted file mode 100644
index ae1e4da..0000000
Binary files a/snd/music/peace4.ogg and /dev/null differ
diff --git a/snd/music/peace6.ogg b/snd/music/peace6.ogg
deleted file mode 100644
index a37478c..0000000
Binary files a/snd/music/peace6.ogg and /dev/null differ
diff --git a/snd/music/snow.ogg b/snd/music/snow.ogg
deleted file mode 100644
index 3fb58cc..0000000
Binary files a/snd/music/snow.ogg and /dev/null differ
diff --git a/snd/music/tension.ogg b/snd/music/tension.ogg
deleted file mode 100644
index e643557..0000000
Binary files a/snd/music/tension.ogg and /dev/null differ
diff --git a/snd/sounds/afterburner.wav b/snd/sounds/afterburner.wav
deleted file mode 100644
index 4b6accc..0000000
Binary files a/snd/sounds/afterburner.wav and /dev/null differ
diff --git a/snd/sounds/beam0.wav b/snd/sounds/beam0.wav
deleted file mode 100644
index d90d996..0000000
Binary files a/snd/sounds/beam0.wav and /dev/null differ
diff --git a/snd/sounds/beam_off0.wav b/snd/sounds/beam_off0.wav
deleted file mode 100644
index ceaa35f..0000000
Binary files a/snd/sounds/beam_off0.wav and /dev/null differ
diff --git a/snd/sounds/engine.wav b/snd/sounds/engine.wav
deleted file mode 100644
index 282b36d..0000000
Binary files a/snd/sounds/engine.wav and /dev/null differ
diff --git a/snd/sounds/explosion0.wav b/snd/sounds/explosion0.wav
deleted file mode 100644
index a3d5a1e..0000000
Binary files a/snd/sounds/explosion0.wav and /dev/null differ
diff --git a/snd/sounds/explosion1.wav b/snd/sounds/explosion1.wav
deleted file mode 100644
index a80d87e..0000000
Binary files a/snd/sounds/explosion1.wav and /dev/null differ
diff --git a/snd/sounds/explosion2.wav b/snd/sounds/explosion2.wav
deleted file mode 100644
index fd3fbd1..0000000
Binary files a/snd/sounds/explosion2.wav and /dev/null differ
diff --git a/snd/sounds/grenade.wav b/snd/sounds/grenade.wav
deleted file mode 100644
index c7f88bd..0000000
Binary files a/snd/sounds/grenade.wav and /dev/null differ
diff --git a/snd/sounds/ion.wav b/snd/sounds/ion.wav
deleted file mode 100644
index 5bf8dcb..0000000
Binary files a/snd/sounds/ion.wav and /dev/null differ
diff --git a/snd/sounds/jump.wav b/snd/sounds/jump.wav
deleted file mode 100644
index a80b052..0000000
Binary files a/snd/sounds/jump.wav and /dev/null differ
diff --git a/snd/sounds/laser.wav b/snd/sounds/laser.wav
deleted file mode 100644
index 9d987db..0000000
Binary files a/snd/sounds/laser.wav and /dev/null differ
diff --git a/snd/sounds/mass.wav b/snd/sounds/mass.wav
deleted file mode 100644
index be8d1a9..0000000
Binary files a/snd/sounds/mass.wav and /dev/null differ
diff --git a/snd/sounds/missile.wav b/snd/sounds/missile.wav
deleted file mode 100644
index 7727f09..0000000
Binary files a/snd/sounds/missile.wav and /dev/null differ
diff --git a/snd/sounds/nav.wav b/snd/sounds/nav.wav
deleted file mode 100644
index c847773..0000000
Binary files a/snd/sounds/nav.wav and /dev/null differ
diff --git a/snd/sounds/neutron.wav b/snd/sounds/neutron.wav
deleted file mode 100644
index e685bd4..0000000
Binary files a/snd/sounds/neutron.wav and /dev/null differ
diff --git a/snd/sounds/target.wav b/snd/sounds/target.wav
deleted file mode 100644
index 4718890..0000000
Binary files a/snd/sounds/target.wav and /dev/null differ
diff --git a/src/ai.c b/src/ai.c
deleted file mode 100644
index f919f7e..0000000
--- a/src/ai.c
+++ /dev/null
@@ -1,1628 +0,0 @@
-/**
- * @file ai.c
- *
- * @brief Controls the Pilot AI.
- *
- * == AI ======================================================
- *
- * -- Goal (Task) based AI with additional optimization.
- * AI uses the goal (task) based AI approach with tasks scripted
- * in lua. Additionally there is a task that is hardcoded and
- * obligatory in any AI script. The 'control' task, whose only
- * purpose is to assign tasks if there is none, and optimize
- * or change tasks if there are.
- *
- * Eg.. Pilot A is attacking Pilot B. Pilot C then comes along
- * the same system and is of the same faction as Pilot B and
- * therefor attacks Pilot A. Pilot A would keep fighting pilot
- * B until the control task comes in. Then the pilot could
- * run if it deems fit that Pilot C and Pilot B together are
- * both too strong for her. Or.. Attack C as it is an easy target
- * to finish.
- * Basically, there is many possibilities, and it's down to the
- * Lua fanatics to decide what to do.
- *
- * -- AI will follow basic tasks defined from Lua AI scripts.
- * -- If task is NULL, AI will run "control" task.
- * -- Task is continued every frame.
- * -- "control" task is a special task that *must* exist in
- * any given Pilot AI (missiles, and suck will use "seek".
- * -- "control" task is not permanent, but transitory.
- * -- "control" task sets another task.
- * -- "control" task is also run at a set rate (depending on
- * Lua global "control_rate") to choose optimal behaviour
- * (task).
- *
- * Memory:
- * The AI currently has per-pilot memory which is accessible as "mem". This
- * memory is actually stored in the table pilotmem[cur_pilot->id]. This allows
- * the pilot to keep some memory always accessible between runs without having
- * to rely on the storage space a task has.
- *
- * @todo Clean up most of the code, it was written as one of the first
- * subsystems and is pretty lacking in quite a few aspects. Notably
- * removing the entire lightuserdata and actually go with full userdata.
- */
-
-#include
-#include
-#include
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-#include
-
-#include "lephisto.h"
-#include "log.h"
-#include "pilot.h"
-#include "player.h"
-#include "physics.h"
-#include "ldata.h"
-#include "rng.h"
-#include "space.h"
-#include "faction.h"
-#include "escort.h"
-#include "llua.h"
-#include "lluadef.h"
-#include "llua_space.h"
-#include "ai.h"
-
-
-/**
- * @def lua_regnumber(l, s, n)
- *
- * @brief Register a number constant n to name s (syntax is just like lua_regfunc).
- */
-#define lua_regnumber(l,s,n) (lua_pushnumber(l,n), lua_setglobal(l,s))
-
-/* Ai flags. */
-#define ai_setFlag(f) (pilot_flags |= f) /**< Set pilot flag f */
-#define ai_isFlag(f) (pilot_flags & f) /**< Check pilot flag f */
-/* Flags. */
-#define AI_PRIMARY (1<<0) /**< Firing primary weapon. */
-#define AI_SECONDARY (1<<1) /**< Firing secondary weapon. */
-
-/* file info. */
-#define AI_PREFIX "../scripts/ai/" /**< AI file prefix. */
-#define AI_SUFFIX ".lua" /**< AI file suffix. */
-#define AI_INCLUDE "include/" /**< Where to search for includes. */
-
-/* AI profiles. */
-static AI_Profile* profiles = NULL; /**< Array of AI_Profiles loaded. */
-static int nprofiles = 0; /**< Number of AI_Profiles loaded. */
-
-/* Extern pilot hacks. */
-extern Pilot** pilot_stack;
-extern int pilot_nstack;
-
-static int ai_minbrakedist(lua_State* L); /* Minimal breaking distance. */
-static int ai_accel(lua_State* L); /* Accelerate. */
-
-/* Internal C routines. */
-static void ai_run(lua_State* L, const char* funcname);
-static int ai_loadProfile(const char* filename);
-static void ai_freetask(Task* t);
-static void ai_setMemory(void);
-static void ai_create(Pilot* pilot, char* param);
-/* External C routines. */
-void ai_attacked(Pilot* attacked, const unsigned int attacker); /* weapon.c */
-/* C routines made external. */
-int ai_pinit(Pilot* p, char* ai); /* pilot.c */
-void ai_destroy(Pilot* p); /* pilot.c */
-void ai_think(Pilot* pilot); /* escort.c */
-
-/* Ai routines for Lua. */
-/* Tasks. */
-static int ai_pushtask(lua_State* L); /* pushtask(string, number/pointer, number) */
-static int ai_poptask(lua_State* L); /* poptask() */
-static int ai_taskname(lua_State* L); /* Number taskname. */
-/* Consult values. */
-static int ai_getplayer(lua_State* L); /* number getPlayer() */
-static int ai_gettarget(lua_State* L); /* Pointer gettarget() */
-static int ai_getrndpilot(lua_State* L); /* Number getrndpilot() */
-static int ai_armour(lua_State* L); /* armour() */
-static int ai_shield(lua_State* L); /* shield() */
-static int ai_parmour(lua_State* L); /* parmour() */
-static int ai_pshield(lua_State* L); /* pshield() */
-static int ai_getdistance(lua_State* L); /* Number getdist(Vec2) */
-static int ai_getpos(lua_State* L); /* getpos(number) */
-static int ai_minbrakedist(lua_State* L); /* Number minbrakedist() */
-static int ai_cargofree(lua_State* L); /* Number cargofree(). */
-static int ai_shipclass(lua_State* L); /* string shipclass(number). */
-static int ai_shipmass(lua_State* L); /* string shipmass(number) */
-static int ai_isbribed(lua_State* L); /* bool isbribed(number). */
-/* Boolean expressions. */
-static int ai_exists(lua_State* L); /* boolean exists */
-static int ai_ismaxvel(lua_State* L); /* Boolean ismaxvel() */
-static int ai_isstopped(lua_State* L); /* Boolean isstopped() */
-static int ai_isenemy(lua_State* L); /* boolean isenemy(number). */
-static int ai_isally(lua_State* L); /* boolean isally(number). */
-static int ai_incombat(lua_State* L); /* boolean incombat([number]) */
-static int ai_haslockon(lua_State* L); /* boolean haslockon() */
-
-/* Movement. */
-static int ai_accel(lua_State* L); /* accel(number); nuimber <= 1. */
-static int ai_turn(lua_State* L); /* turn(number); abs(number) <= 1. */
-static int ai_face(lua_State* L); /* face(number/pointer) */
-static int ai_aim(lua_State* L); /* aim(number). */
-static int ai_brake(lua_State* L); /* Brake() */
-static int ai_getnearestplanet(lua_State* L); /* Vec2 getnearestplanet() */
-static int ai_getrndplanet(lua_State* L); /* Vec2 getrndplanet() */
-static int ai_getlandplanet(lua_State* L); /* Vec2 getlandplanet() */
-static int ai_hyperspace(lua_State* L); /* [number] hyperspace() */
-static int ai_stop(lua_State* L); /* stop() */
-static int ai_relvel(lua_State* L); /* relvel(number) */
-/* Escorts. */
-static int ai_e_attack(lua_State* L); /* bool e_attack() */
-static int ai_e_hold(lua_State* L); /* bool e_hold() */
-static int ai_e_clear(lua_State* L); /* bool e_clear() */
-static int ai_e_return(lua_State* L); /* bool e_return() */
-static int ai_dock(lua_State* L); /* dock(number) */
-/* Combat. */
-static int ai_combat(lua_State* L); /* combat(number) */
-static int ai_settarget(lua_State* L); /* settarget(number) */
-static int ai_secondary(lua_State* L); /* string secondary() */
-static int ai_hasturrets(lua_State* L); /* bool hasturrets() */
-static int ai_shoot(lua_State* L); /* shoot(number) number = 1,2,3. */
-static int ai_getenemy(lua_State* L); /* number getenemy(). */
-static int ai_hostile(lua_State* L); /* hostile(number). */
-static int ai_getweaprange(lua_State* L); /* number getweaprange(). */
-/* Timers. */
-static int ai_settimer(lua_State* L); /* settimer(number, number) */
-static int ai_timeup(lua_State* L); /* boolean timeup(number) */
-/* Messages. */
-static int ai_comm(lua_State* L); /* comm(string) */
-static int ai_broadcast(lua_State* L); /* broadcast(string) */
-/* Loot. */
-static int ai_credits(lua_State* L); /* credits(number). */
-static int ai_cargo(lua_State* L); /* cargo(name, quantity). */
-static int ai_shipprice(lua_State* L); /* shipprice(). */
-
-static const luaL_Reg ai_methods[] = {
- /* Tasks. */
- { "pushtask", ai_pushtask },
- { "poptask", ai_poptask },
- { "taskname", ai_taskname },
- /* Is. */
- { "exists", ai_exists },
- { "ismaxvel", ai_ismaxvel },
- { "isstopped", ai_isstopped },
- { "isenemy", ai_isenemy },
- { "isally", ai_isally },
- { "incombat", ai_incombat },
- { "haslockon", ai_haslockon },
- /* Get. */
- { "getPlayer", ai_getplayer },
- { "target", ai_gettarget },
- { "rndpilot", ai_getrndpilot },
- { "armour", ai_armour },
- { "shield", ai_shield },
- { "parmour", ai_parmour },
- { "pshield", ai_pshield },
- { "dist", ai_getdistance },
- { "pos", ai_getpos },
- { "minbrakedist", ai_minbrakedist },
- { "cargofree", ai_cargofree },
- { "shipclass", ai_shipclass },
- { "shipmass", ai_shipmass },
- { "isbribed", ai_isbribed },
- /* Movement. */
- { "nearestplanet", ai_getnearestplanet },
- { "rndplanet", ai_getrndplanet },
- { "landplanet", ai_getlandplanet },
- { "accel", ai_accel },
- { "turn", ai_turn },
- { "face", ai_face },
- { "brake", ai_brake },
- { "stop", ai_stop },
- { "hyperspace", ai_hyperspace },
- { "relvel", ai_relvel },
- /* Escorts. */
- { "e_attack", ai_e_attack },
- { "e_hold", ai_e_hold },
- { "e_clear", ai_e_clear },
- { "e_return", ai_e_return },
- { "dock", ai_dock },
- /* Combat. */
- { "aim", ai_aim },
- { "combat", ai_combat },
- { "settarget", ai_settarget },
- { "secondary", ai_secondary },
- { "hasturrets", ai_hasturrets },
- { "shoot", ai_shoot },
- { "getenemy", ai_getenemy },
- { "hostile", ai_hostile },
- { "getweaprange", ai_getweaprange },
- /* Timers. */
- { "settime", ai_settimer },
- { "timeup", ai_timeup },
- /* Messages. */
- { "comm", ai_comm },
- { "broadcast", ai_broadcast },
- /* Loot. */
- { "setcredits", ai_credits },
- { "setcargo", ai_cargo },
- { "shipprice", ai_shipprice },
- { 0, 0 } /* End. */
-};
-
-/* Current pilot "thinking" and assorted variables. */
-static Pilot* cur_pilot = NULL; /**< Current pilot. All functions use this. */
-static double pilot_acc = 0.; /**< Current pilots acceleration. */
-static double pilot_turn = 0.; /**< Current pilots turning. */
-static int pilot_flags = 0; /**< Handle stuff like weapon firing. */
-
-/* Ai status: 'Create' functions that can't be used elsewhere. */
-#define AI_STATUS_NORMAL 1 /**< Normal AI function behaviour. */
-#define AI_STATUS_CREATE 2 /**< AI is running create function. */
-static int ai_status = AI_STATUS_NORMAL; /**< Current AI run statis. */
-
-/**
- * @brief Set the cur_pilots ai.
- */
-static void ai_setMemory(void) {
- lua_State* L;
- L = cur_pilot->ai->L;
-
- lua_getglobal(L, "pilotmem");
- /* pilotmem */
- lua_pushnumber(L, cur_pilot->id);
- /* pilotmem, id */
- lua_gettable(L, -2);
- /* pilotmem, table */
- lua_setglobal(L, "mem");
- /* pilotmem */
- lua_pop(L, 1);
-}
-
-/**
- * @brief Set the pilot for further AI calls.
- * @param p Pilot to set.
- */
-void ai_setPilot(Pilot* p) {
- cur_pilot = p;
- ai_setMemory();
-}
-
-/**
- * @brief Attemps to run a function.
- *
- * @param[in] L Lua state to run function on.
- * @param[in] funcname Function to run.
- */
-static void ai_run(lua_State* L, const char* funcname) {
- lua_getglobal(L, funcname);
- if(lua_pcall(L, 0, 0, 0))
- /* Errors accured. */
- WARN("Pilot '%s' ai -> '%s' : %s",
- cur_pilot->name, funcname, lua_tostring(L,-1));
-}
-
-/**
- * @brief Initializes the pilot in the ai.
- *
- * Mainly used to create the pilot's memory table.
- * @param p Pilot to initialize in AI.
- * @param ai AI to initialize pilot.
- */
-int ai_pinit(Pilot* p, char* ai) {
- int i, n;
- AI_Profile* prof;
- lua_State* L;
- char buf[PATH_MAX], param[PATH_MAX];
-
- /* Split parameter from ai itself. */
- n = 0;
- for(i = 0; ai[i] != '\0'; i++) {
- /* Overflow protection. */
- if(i > PATH_MAX)
- break;
-
- /* Check to see if we find the splitter. */
- if(ai[i] == '*') {
- buf[i] = '\0';
- n = i+1;
- continue;
- }
-
- if(n == 0)
- buf[i] = ai[i];
- else
- param[i-n] = ai[i];
- }
- if(n != 0) param[i-n] = '\0'; /* Terminate string if needed. */
- else buf[i] = '\0';
-
- prof = ai_getProfile(buf);
- if(prof == NULL)
- WARN("AI Profile '%s' not found.", buf);
- p->ai = prof;
- L = p->ai->L;
-
- /* Adds a new pilot memory in the memory table. */
- lua_getglobal(L, "pilotmem");
- lua_pushnumber(L, p->id);
- lua_newtable(L);
- lua_settable(L, -3);
- lua_pop(L, 1);
-
- /* Create the pilot. */
- ai_create(p, (n != 0) ? param : NULL);
-
- return 0;
-}
-
-/**
- * @brief Destroys the ai part of the pilot.
- *
- * @param[in] p Pilot to destroy it's AI part.
- */
-void ai_destroy(Pilot* p) {
- lua_State* L;
- L = p->ai->L;
-
- /* Get rid of pilot's memory. */
- lua_getglobal(L, "pilotmem");
- lua_pushnumber(L, p->id);
- lua_pushnil(L);
- lua_settable(L, -3);
- lua_pop(L, 1);
-
- /* Clean up tasks. */
- if(p->task)
- ai_freetask(p->task);
- p->task = NULL;
-}
-
-/**
- * @brief Initializes the AI stuff which is basically Lua.
- *
- * @return 0 on no errors.
- */
-int ai_init(void) {
- char** files;
- uint32_t nfiles, i;
- char path[PATH_MAX];
- int flen, suflen;
-
- /* Get the file list. */
- files = ldata_list(AI_PREFIX, &nfiles);
-
- /* Load the profiles. */
- suflen = strlen(AI_SUFFIX);
- for(i = 0; i < nfiles; i++) {
- flen = strlen(files[i]);
- if((flen > suflen) &&
- strncmp(&files[i][flen-suflen], AI_SUFFIX, suflen)==0) {
-
- snprintf(path, PATH_MAX, AI_PREFIX"%s", files[i]);
- if(ai_loadProfile(path)) /* Load the profile. */
- WARN("Error loading AI profile '%s'", path);
- }
-
- /* Clean up. */
- free(files[i]);
- }
-
- DEBUG("Loaded %d AI profile%c", nprofiles, (nprofiles==1)?' ':'s');
-
- /* More clean up. */
- free(files);
-
- return 0;
-}
-
-/**
- * @brief Initializes an AI_Profile and adds it to the stack.
- *
- * @param[in] filename File to create the profile from.
- * @return 0 on no error.
- */
-static int ai_loadProfile(const char* filename) {
- char* buf = NULL;
- uint32_t bufsize = 0;
- lua_State* L;
-
- profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles));
-
- profiles[nprofiles-1].name =
- malloc(sizeof(char)*
- (strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX))+1);
-
- snprintf(profiles[nprofiles-1].name,
- strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)+1,
- "%s", filename+strlen(AI_PREFIX));
-
- profiles[nprofiles-1].L = llua_newState();
-
- if(profiles[nprofiles-1].L == NULL) {
- ERR("Unable to create a new Lua state");
- return -1;
- }
-
- L = profiles[nprofiles-1].L;
-
- /* Open basic Lua stuff. */
- llua_loadBasic(L);
- llua_load(L, luaopen_string); /* Open string. */
-
- /* Constants. */
- lua_regnumber(L, "player", PLAYER_ID); /* Player id. */
-
- /* Register C funstions in Lua. */
- luaL_register(L, "ai", ai_methods);
- lua_loadRnd(L);
-
- /* Metatables to register. */
- lua_loadVector(L);
-
- /* Now load the file, since all the functions have been previously loaded. */
- buf = ldata_read(filename, &bufsize);
- if(luaL_dobuffer(L, buf, bufsize, filename) != 0) {
- ERR("Error loading AI file: %s\n"
- "%s\n"
- "Most likely Lua file has improper syntax, please check.",
- filename, lua_tostring(L, -1));
- return -1;
- }
-
- free(buf);
-
- /* Add the player memory. */
- lua_newtable(L);
- lua_setglobal(L, "pilotmem");
-
- return 0;
-}
-
-/*
- * @brief Get the AI_Profile by name.
- *
- * @param[in] name Name of the profile to get.
- * @return The profile or NULL on error.
- */
-AI_Profile* ai_getProfile(char* name) {
- if(profiles == NULL) return NULL;
-
- int i;
- for(i = 0; i < nprofiles; i++)
- if(strcmp(name, profiles[i].name)==0)
- return &profiles[i];
-
- WARN("AI Profile '%s' not found in AI stack", name);
- return NULL;
-}
-
-/**
- * @brief Clean up the gloabl AI.
- */
-void ai_exit(void) {
- int i;
- for(i = 0; i < nprofiles; i++) {
- free(profiles[i].name);
- lua_close(profiles[i].L);
- }
- free(profiles);
-}
-
-/**
- * @brief Heart of the AI, brains of the pilot.
- *
- * @param pilot Pilot that needs to think.
- */
-void ai_think(Pilot* pilot) {
- lua_State* L;
-
- ai_setPilot(pilot);
- L = cur_pilot->ai->L; /* Set the AI profile to the current pilot's. */
-
- /* Clean up some variables. */
- pilot_acc = 0;
- pilot_turn = 0.;
- pilot_flags = 0;
- cur_pilot->target = cur_pilot->id;
-
- /* Control function if pilot is idle or tick is up. */
- if((cur_pilot->tcontrol < 0.) || (cur_pilot->task == NULL)) {
- ai_run(L, "control"); /* Run control. */
- lua_getglobal(L, "control_rate");
- cur_pilot->tcontrol = lua_tonumber(L, -1);
- lua_pop(L, 1);
- }
- if(cur_pilot->task)
- /* Pilot has a currently running task. */
- ai_run(L, cur_pilot->task->name);
-
- /* Make sure pilot_acc and pilot_turn are legal moves. */
- if(pilot_acc > 1.) pilot_acc = 1.; /* Value must be <= 1. */
- if(pilot_turn > 1.) pilot_turn = 1.; /* Value must be between -1 and 1. */
- else if(pilot_turn < -1.) pilot_turn = -1.;
-
- cur_pilot->solid->dir_vel = 0.;
- if(pilot_turn) /* Set the turning velocity. */
- cur_pilot->solid->dir_vel += cur_pilot->turn * pilot_turn;
- vect_pset(&cur_pilot->solid->force, cur_pilot->thrust * pilot_acc,
- cur_pilot->solid->dir);
-
- /* Fire weapons if needs be. */
- if(ai_isFlag(AI_PRIMARY)) pilot_shoot(cur_pilot, 0); /* Primary. */
- if(ai_isFlag(AI_SECONDARY)) pilot_shoot(cur_pilot, 1); /* Secondary. */
-}
-
-/**
- * @brief Trigger the attacked() function in the Pilots AI.
- *
- * @param attacked Pilot that is attacked.
- * @param[in] attacker ID of the attacker.
- */
-void ai_attacked(Pilot* attacked, const unsigned int attacker) {
- lua_State* L;
-
- ai_setPilot(attacked);
- L = cur_pilot->ai->L;
- lua_getglobal(L, "attacked");
- lua_pushnumber(L, attacker);
- if(lua_pcall(L, 1, 0, 0))
- WARN("Pilot '%s' ai -> 'attacked' : %s", cur_pilot->name, lua_tostring(L, -1));
-}
-
-/**
- * @brief Run the create() function in the pilot.
- *
- * Should create all the gear and such the pilot has.
- *
- * @param pilot Pilot to "create".
- * @param param Parameter to pass to "create" function.
- */
-static void ai_create(Pilot* pilot, char* param) {
- lua_State* L;
-
- ai_setPilot(pilot);
- L = cur_pilot->ai->L;
-
- /* Set creation mode. */
- ai_status = AI_STATUS_CREATE;
-
- /* Prepare stack. */
- lua_getglobal(L, "create");
-
- /* Parse parameters. */
- if(param != NULL) {
- /* Number. */
- if(isdigit(param[0]))
- lua_pushnumber(L, atoi(param));
- /* Special case player. */
- else if(strcmp(param, "player")==0)
- lua_pushnumber(L, PLAYER_ID);
- /* Default. */
- else
- lua_pushstring(L, param);
- }
-
- /* Run function. */
- if(lua_pcall(L, (param!=NULL) ? 1 : 0, 0, 0)) /* Error has occured. */
- WARN("Pilot '%s' ai -> '%s' : %s", cur_pilot->name, "create", lua_tostring(L, -1));
-
- /* Recover normal mode. */
- ai_status = AI_STATUS_NORMAL;
-}
-
-/* ===================== */
-/* INTERNAL C FUNCTIONS. */
-/* ===================== */
-
-/**
- * @brief Free an AI task.
- * @param t Task to free.
- */
-static void ai_freetask(Task* t) {
- if(t->next != NULL) {
- ai_freetask(t->next); /* Woot, recursive freeing! */
- t->next = NULL;
- }
-
- if(t->name) free(t->name);
- free(t);
-}
-
-/**
- * @defgroup AI Lua AI Bindings
- *
- * @brief Handles how the AI interacts with the universe.
- *
- * Usage:
- * @code
- * ai.function(params)
- * @endcode
- *
- * @{
- */
-
-/**
- * @brief Pushes a task onto the pilots task list.
- * @luaparam pos Position to push into stack, 0 is front, 1 is back.
- * @luaparam func Function to call for task.
- * @luaparam data Data to pass to the function. Only lightuserdata or number
- * is currently supported.
- *
- * @luafunc pushtask(pos, func, data)
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_pushtask(lua_State* L) {
- LLUA_MIN_ARGS(2);
- int pos;
- char* func;
- Task* t, *pointer;
-
- /* Parse basic parameters. */
- if(lua_isnumber(L, 1)) pos = (int) lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
- if(lua_isstring(L, 2)) func = (char*)lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- t = malloc(sizeof(Task));
- t->next = NULL;
- t->name = strdup(func);
- t->dtype = TYPE_NULL;
-
- if(lua_gettop(L) > 2) {
- if(lua_isnumber(L, 3)) {
- t->dtype = TYPE_INT;
- t->dat.num = (unsigned int)lua_tonumber(L,3);
- }
- else LLUA_INVALID_PARAMETER();
- }
-
- if(pos == 1) { /* Put at the end. */
- for(pointer = cur_pilot->task; pointer->next != NULL; pointer = pointer->next);
- pointer->next = t;
- } else {
- /* Default put at the beginning. */
- t->next = cur_pilot->task;
- cur_pilot->task = t;
- }
- return 0;
-}
-
-/**
- * @brief Pops the current running task.
- * @luafunc poptask()
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_poptask(lua_State* L) {
- (void)L; /* Just a hack to avoid -W -Wall warnings. */
- Task* t = cur_pilot->task;
-
- /* Tasks must exist. */
- if(t == NULL) {
- LLUA_DEBUG("Trying to pop task when there are no tasks in stack");
- return 0;
- }
-
- cur_pilot->task = t->next;
- t->next = NULL;
- ai_freetask(t);
- return 0;
-}
-
-/**
- * @brief Get the current task's name.
- * @return The current task name or "none" if there are no tasks.
- *
- * @luafunc taskname()
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_taskname(lua_State* L) {
- if(cur_pilot->task) lua_pushstring(L, cur_pilot->task->name);
- else lua_pushstring(L, "none");
- return 1;
-}
-
-/**
- * @brief Get the player.
- * @return The players ship identifier.
- *
- * @luafunc getPlayer()
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_getplayer(lua_State* L) {
- lua_pushnumber(L, PLAYER_ID);
- return 1;
-}
-
-/**
- * @brief Get the pilots target.
- * @return The pilots target ship identifier or nil if no target.
- *
- * @luafunc target()
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_gettarget(lua_State* L) {
- switch(cur_pilot->task->dtype) {
- case TYPE_INT:
- lua_pushnumber(L, cur_pilot->task->dat.num);
- return 1;
- default:
- return 0;
- }
-}
-
-/**
- * @brief Get a random targets id.
- * @return Gets a random pilot in the system.
- *
- * @luafunc rndpilot()
- * @param L Lua state.
- * @return Number of Lua parameters.
- */
-static int ai_getrndpilot(lua_State* L) {
- int p;
- p = RNG(0, pilot_nstack-1);
- /* Make sure it can't be the same pilot. */
- if(pilot_stack[p]->id == cur_pilot->id) {
- p++;
- if(p >= pilot_nstack)
- p = 0;
- }
- /* Last check. */
- if(pilot_stack[p]->id == cur_pilot->id)
- return 0;
- /* Actually found a pilot. */
- lua_pushnumber(L, pilot_stack[p]->id);
- return 1;
-}
-
-/* Get the pilots armour. */
-static int ai_armour(lua_State* L) {
- double d;
-
- if(lua_isnumber(L,1)) d = pilot_get((unsigned int)lua_tonumber(L,1))->armour;
- else d = cur_pilot->armour;
-
- lua_pushnumber(L, d);
- return 1;
-}
-
-/* Get pilots shield. */
-static int ai_shield(lua_State* L) {
- double d;
-
- if(lua_isnumber(L,1)) d = pilot_get((unsigned int)lua_tonumber(L,1))->shield;
- else d = cur_pilot->shield;
-
- lua_pushnumber(L, d);
- return 1;
-}
-
-/* Get the pilot's armour in percentage. */
-static int ai_parmour(lua_State* L) {
- double d;
- Pilot* p;
-
- if(lua_isnumber(L,1)) {
- p = pilot_get((unsigned int)lua_tonumber(L,1));
- d = p->armour / p->armour_max * 100.;
- }
- else d = cur_pilot->armour / cur_pilot->armour_max * 100.;
-
- lua_pushnumber(L, d);
- return 1;
-}
-
-/* Get the pilot's shield in percentage. */
-static int ai_pshield(lua_State* L) {
- double d;
- Pilot* p;
-
- if(lua_isnumber(L,1)) {
- p = pilot_get((unsigned int)lua_tonumber(L,1));
- d = p->shield / p->shield_max * 100.;
- }
- else d = cur_pilot->shield / cur_pilot->shield_max * 100.;
-
- lua_pushnumber(L, d);
- return 1;
-}
-
-/* Get the distance from the pointer. */
-static int ai_getdistance(lua_State* L) {
- Vec2* v;
- LuaVector* lv;
- Pilot* pilot;
- unsigned int n;
-
- LLUA_MIN_ARGS(1);
-
- /* Vector as a parameter. */
- if(lua_isvector(L, 1)) {
- lv = lua_tovector(L, 1);
- v = &lv->vec;
- }
- else if(lua_islightuserdata(L,1))
- v = lua_touserdata(L,1);
-
- /* Pilot id as parameter. */
- else if(lua_isnumber(L, 1)) {
- n = (unsigned int)lua_tonumber(L,1);
- pilot = pilot_get((unsigned int) lua_tonumber(L, 1));
- if(pilot == NULL) {
- LLUA_DEBUG("Pilot '%d' not found in stack", n);
- return 0;
- }
- v = &pilot->solid->pos;
- } else
- /* Wrong parameter. */
- LLUA_INVALID_PARAMETER();
-
- lua_pushnumber(L, vect_dist(v, &cur_pilot->solid->pos));
- return 1;
-}
-
-/* Get the pilots position. */
-static int ai_getpos(lua_State* L) {
- Pilot* p;
- if(lua_isnumber(L, 1)) {
- p = pilot_get((int)lua_tonumber(L,1)); /* Pilot ID. */
- if(p == NULL) return 0;
- }
- else p = cur_pilot; /* Default to ones self. */
-
- lua_pushlightuserdata(L, &p->solid->pos);
-
- return 1;
-}
-
-/*
- * Get the minimum braking distance.
- *
- * Braking vel ==> 0 = v - a*dt
- * Add turn around time (to initial velocity) :
- * ==> 180.*360./cur_pilot->turn
- * Add it to general euler equation x = v*t + 0.5 * a * t^2
- * Have fun.
- *
- * I really hate this function. Why isn't it depricated yet?
- */
-static int ai_minbrakedist(lua_State* L) {
- double time, dist, vel;
- time = VMOD(cur_pilot->solid->vel) /
- (cur_pilot->thrust / cur_pilot->solid->mass);
-
- vel = MIN(cur_pilot->speed, VMOD(cur_pilot->solid->vel));
- dist = vel*(time+1.1*180./cur_pilot->turn) -
- 0.5 * (cur_pilot->thrust / cur_pilot->solid->mass)*time*time;
-
- lua_pushnumber(L, dist); /* return */
- return 1;
-}
-
-static int ai_cargofree(lua_State* L) {
- lua_pushnumber(L, pilot_cargoFree(cur_pilot));
- return 1;
-}
-
-/* Get the pilots ship class. */
-static int ai_shipclass(lua_State* L) {
- Pilot* p;
-
- if(lua_gettop(L) > 0) {
- if(lua_isnumber(L, 1))
- p = pilot_get((unsigned int)lua_tonumber(L, 1));
- else LLUA_INVALID_PARAMETER();
- } else
- p = cur_pilot;
-
- if(p == NULL) {
- LLUA_DEBUG("Trying to get class of unexpectant ship!");
- return 0;
- }
-
- lua_pushstring(L, ship_class(p->ship));
- return 1;
-}
-
-/* Get the ships mass. */
-static int ai_shipmass(lua_State* L) {
- Pilot* p;
-
- if(lua_gettop(L) > 0) {
- if(lua_isnumber(L, 1))
- p = pilot_get((unsigned int)lua_tonumber(L,1));
- else LLUA_INVALID_PARAMETER();
- } else
- p = cur_pilot;
-
- if(p == NULL) {
- LLUA_DEBUG("Trying to get class of unexistant ship!");
- return 0;
- }
-
- lua_pushnumber(L, p->solid->mass);
- return 1;
-}
-
-/* Check to see if target has bribed pilot. */
-static int ai_isbribed(lua_State* L) {
- unsigned int target;
-
- if(lua_isnumber(L, 1))
- target = (unsigned int) lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- lua_pushboolean(L, (target == PLAYER_ID) && pilot_isFlag(cur_pilot, PILOT_BRIBED));
- return 1;
-}
-
-static int ai_exists(lua_State* L) {
- Pilot* p;
- int i;
-
- if(lua_isnumber(L,1)) {
- i = 1;
- p = pilot_get((unsigned int)lua_tonumber(L,1));
- if(p == NULL) i = 0;
- else if(pilot_isFlag(p, PILOT_DEAD)) i = 0;
- lua_pushboolean(L, i);
- return 1;
- }
-
- /* Default to false for everything that isn't a pilot. */
- lua_pushboolean(L, 0);
- return 0;
-}
-
-/* Are we at max velocity? */
-static int ai_ismaxvel(lua_State* L) {
- lua_pushboolean(L,(VMOD(cur_pilot->solid->vel)>cur_pilot->speed-MIN_VEL_ERR));
- return 1;
-}
-
-/* Have we stopped? */
-static int ai_isstopped(lua_State* L) {
- lua_pushboolean(L, VMOD(cur_pilot->solid->vel) < MIN_VEL_ERR);
- return 1;
-}
-
-/* Check if the pilot is an enemy. */
-static int ai_isenemy(lua_State* L) {
- if(lua_isnumber(L,1))
- lua_pushboolean(L, areEnemies(cur_pilot->faction,
- pilot_get(lua_tonumber(L,1))->faction));
- return 1;
-}
-
-/* Check if the pilot is an ally. */
-static int ai_isally(lua_State* L) {
- lua_pushboolean(L, areAllies(cur_pilot->faction,
- pilot_get(lua_tonumber(L,1))->faction));
- return 1;
-}
-
-/* Check to see if the pilot is in combat. Defaults to self. */
-static int ai_incombat(lua_State* L) {
- Pilot* p;
-
- if(lua_isnumber(L, 1)) p = pilot_get((unsigned int)lua_tonumber(L,1));
- else p = cur_pilot;
-
- lua_pushboolean(L,pilot_isFlag(p, PILOT_COMBAT));
- return 1;
-}
-
-static int ai_haslockon(lua_State* L) {
- lua_pushboolean(L, cur_pilot->lockons > 0);
- return 1;
-}
-
-/* Accelerate the pilot based on a param. */
-static int ai_accel(lua_State* L) {
- double n;
-
- if(lua_gettop(L) > 1 && lua_isnumber(L, 1)) {
- n = (double)lua_tonumber(L,1);
-
- if(n > 1.) n = 1.;
- else if(n < 0.) n = 0.;
-
- if(VMOD(cur_pilot->solid->vel) > (n * cur_pilot->speed))
- pilot_acc = 0.;
- } else
- pilot_acc = 1.;
-
- return 0;
-}
-
-/* Turn the pilot based on a param. */
-static int ai_turn(lua_State* L) {
- LLUA_MIN_ARGS(1);
- pilot_turn = (lua_isnumber(L, 1)) ? (double)lua_tonumber(L, 1) : 0.;
- return 0;
-}
-
-/* Face the target. */
-static int ai_face(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaVector* lv;
- Vec2 sv, tv; /* Grab the position to face. */
- Pilot* p;
- double mod, diff;
- int n;
-
- /* Get first parameter, aka what to face. */
- n = -2;
- lv = NULL;
- if(lua_isnumber(L, 1)) {
- n = (int)lua_tonumber(L, 1);
-
- if(n >= 0) {
- p = pilot_get(n);
- if(p == NULL) return 0; /* Make sure pilot is valid. */
- vect_cset(&tv, VX(p->solid->pos), VY(p->solid->pos));
- }
- }
- else if(lua_isvector(L, 1))
- lv = lua_tovector(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- mod = 10;
-
- /* Check if must invert. */
- if(lua_gettop(L) > 1) {
- if(lua_isboolean(L, 2) && lua_toboolean(L, 2))
- mod *= -1;
- }
-
- vect_cset(&sv, VX(cur_pilot->solid->pos), VY(cur_pilot->solid->pos));
-
- if(lv == NULL)
- /* Target is dynamic. */
- diff = angle_diff(cur_pilot->solid->dir,
- (n==-1) ? VANGLE(sv) :
- vect_angle(&sv, &tv));
- else
- /* Target is static. */
- diff = angle_diff(cur_pilot->solid->dir,
- (n==-1) ? VANGLE(cur_pilot->solid->pos) :
- vect_angle(&cur_pilot->solid->pos, &lv->vec));
-
- /* Make pilot turn. */
- pilot_turn = mod*diff;
-
- /* Return angle in degrees away from target. */
- lua_pushnumber(L, ABS(diff*180./M_PI));
- return 1;
-}
-
-/* This is generally good for coming to a halt. */
-static int ai_brake(lua_State* L) {
- (void)L; /* Just a hack to avoid -W -Wall warnings. */
- double diff, d;
-
- d = cur_pilot->solid->dir+M_PI;
- if(d >= 2*M_PI) d = fmodf(d, 2*M_PI);
-
- diff = angle_diff(d, VANGLE(cur_pilot->solid->vel));
- pilot_turn = 10*diff;
-
- if(ABS(diff) < MAX_DIR_ERR && VMOD(cur_pilot->solid->vel) > MIN_VEL_ERR)
- pilot_acc = 1.;
- return 0;
-}
-
-/* Return the nearest friendly planet's position to the pilot. */
-static int ai_getnearestplanet(lua_State* L) {
- double dist, d;
- int i, j;
- LuaVector lv;
-
- if(cur_system->nplanets == 0) return 0; /* No planets. */
-
- /* Cycle through planets. */
- for(dist = 0., j = -1, i = 0; i < cur_system->nplanets; i++) {
- d = vect_dist(&cur_system->planets[i]->pos, &cur_pilot->solid->pos);
- if((!areEnemies(cur_pilot->faction, cur_system->planets[i]->faction)) &&
- (d < dist)) {
- /* Closer friendly planet. */
- j = i;
- dist = d;
- }
- }
-
- /* No friendly planet found. */
- if(j == -1) return 0;
-
- vectcpy(&lv.vec, &cur_system->planets[j]->pos);
- lua_pushvector(L, lv);
-
- return 1;
-}
-
-/* Return a random planet's position to the pilot. */
-static int ai_getrndplanet(lua_State* L) {
- LuaVector lv;
- int p;
-
- if(cur_system->nplanets == 0) return 0; /* No planets. */
-
- /* Get a random planet. */
- p = RNG(0, cur_system->nplanets-1);
-
- /* Copy the data into a vector. */
- vectcpy(&lv.vec, &cur_system->planets[p]->pos);
- lua_pushvector(L, lv);
-
- return 1;
-}
-
-/* Return a random friendly planet's position to the pilot. */
-static int ai_getlandplanet(lua_State* L) {
- Planet** planets;
- int nplanets, i;
- LuaVector lv;
-
- if(cur_system->nplanets == 0) return 0; /* No planets. */
-
- /* Allocate memory. */
- planets = malloc(sizeof(Planet*) * cur_system->nplanets);
-
- /* Copy friendly planets. */
- for(nplanets = 0, i = 0; i < cur_system->nplanets; i++)
- if(planet_hasService(cur_system->planets[i], PLANET_SERVICE_BASIC) &&
- !areEnemies(cur_pilot->faction, cur_system->planets[i]->faction))
- planets[nplanets++] = cur_system->planets[i];
-
- /* No planet to land on found. */
- if(nplanets == 0) {
- free(planets);
- return 0;
- }
-
- /* We can actually get a random planet now. */
- i = RNG(0,nplanets-1);
- vectcpy(&lv.vec, &planets[i]->pos);
- vect_cadd(&lv, RNG(0, planets[i]->gfx_space->sw)-planets[i]->gfx_space->sw/2.,
- RNG(0, planets[i]->gfx_space->sh)-planets[i]->gfx_space->sh/2.);
- lua_pushvector(L, lv);
- free(planets);
- return 1;
-}
-
-/* Attempt to enter the pilot hyperspace. Return the distance if too far away. */
-static int ai_hyperspace(lua_State* L) {
- int dist;
-
- pilot_shootStop(cur_pilot, 0);
- pilot_shootStop(cur_pilot, 1);
- dist = space_hyperspace(cur_pilot);
- if(dist == 0.) return 0;
-
- lua_pushnumber(L,dist);
- return 1;
-}
-
-/* Get the relative velocity of a pilot. */
-static int ai_relvel(lua_State* L) {
- unsigned int id;
- double dot, mod;
- Pilot* p;
- Vec2 vv, pv;
-
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L, 1)) id = (unsigned int)lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- p = pilot_get(id);
- if(p == NULL) {
- LLUA_DEBUG("Invalid pilot identifier.");
- return 0;
- }
-
- /* Get te projection of target on current velocity. */
- vect_cset(&vv, p->solid->vel.x - cur_pilot->solid->vel.x,
- p->solid->vel.y - cur_pilot->solid->vel.y);
- vect_cset(&pv, p->solid->pos.x - cur_pilot->solid->pos.x,
- p->solid->pos.y - cur_pilot->solid->pos.y);
- dot = vect_dot(&pv, &vv);
- mod = MAX(VMOD(pv), 1.); /* Avoid /0. */
-
- lua_pushnumber(L, dot / mod);
- return 1;
-}
-
-/* Completely stop the pilot if it is below minimum vel error. (No instant stops.) */
-static int ai_stop(lua_State* L) {
- (void)L; /* Just avoid a gcc warning. */
-
- if(VMOD(cur_pilot->solid->vel) < MIN_VEL_ERR)
- vect_pset(&cur_pilot->solid->vel, 0., 0.);
-
- return 0;
-}
-
-/* Tell the pilots escort to attack its target. */
-static int ai_e_attack(lua_State* L) {
- int ret;
- ret = escorts_attack(cur_pilot);
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-/* Tell the pilots escort to hold position. */
-static int ai_e_hold(lua_State* L) {
- int ret;
- ret = escorts_hold(cur_pilot);
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-/* Tell the pilots escort to clear orders. */
-static int ai_e_clear(lua_State* L) {
- int ret;
- ret = escorts_clear(cur_pilot);
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-/* Tells the pilots escorts to return to dock. */
-static int ai_e_return(lua_State* L) {
- int ret;
- ret = escorts_return(cur_pilot);
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-/* Docks the ship. */
-static int ai_dock(lua_State* L) {
- Pilot* p;
-
- /* Target is another ship. */
- if(lua_isnumber(L, 1)) {
- p = pilot_get(lua_tonumber(L, 1));
- if(p == NULL) return 0;
- pilot_dock(cur_pilot, p);
- }
- else LLUA_INVALID_PARAMETER();
-
- return 0;
-}
-
-/* Aim at the pilot, trying to hit it. */
-static int ai_aim(lua_State* L) {
- int id;
- double x, y;
- double t;
- Pilot* p;
- Vec2 tv;
- double dist, diff;
- double mod;
- double speed;
- LLUA_MIN_ARGS(1);
-
- /* Only acceptable parameter is pilot id. */
- if(lua_isnumber(L,1))
- id = lua_tonumber(L,1);
- else
- LLUA_INVALID_PARAMETER();
-
- /* Get the pilot. */
- p = pilot_get(id);
- if(p == NULL) {
- WARN("Pilot is invalid");
- return 0;
- }
-
- /* Get the distance. */
- dist = vect_dist(&cur_pilot->solid->pos, &p->solid->pos);
-
- /* Check if we should recalculate weapon speed with secondary weapon. */
- if((cur_pilot->secondary != NULL) &&
- outfit_isBolt(cur_pilot->secondary->outfit) &&
- (cur_pilot->secondary->outfit->type == OUTFIT_TYPE_MISSILE_DUMB)) {
- speed = cur_pilot->weap_speed + outfit_speed(cur_pilot->secondary->outfit);
- speed /= 2.;
- }
- else speed = cur_pilot->weap_speed;
-
- /* Time for shots to reach distance. */
- t = dist / speed;
-
- /* Position is calculated on where it should be. */
- x = p->solid->pos.x + p->solid->vel.x*t
- - (cur_pilot->solid->pos.x + cur_pilot->solid->vel.x*t);
-
- y = p->solid->pos.y + p->solid->vel.y*t
- - (cur_pilot->solid->pos.y + cur_pilot->solid->vel.y*t);
- vect_cset(&tv, x, y);
-
- /* Calculate what we need to turn. */
- mod = 10.;
- diff = angle_diff(cur_pilot->solid->dir, VANGLE(tv));
- pilot_turn = mod * diff;
-
- /* Return distance to target (in grad). */
- lua_pushnumber(L, ABS(diff*180./M_PI));
- return 1;
-}
-
-/* Toggle combat flag. Default is on. */
-static int ai_combat(lua_State* L) {
- int i;
-
- if(lua_isnumber(L, 1)) {
- i = (int)lua_tonumber(L,1);
- if(i == 1) pilot_setFlag(cur_pilot, PILOT_COMBAT);
- else if(i == 0) pilot_rmFlag(cur_pilot, PILOT_COMBAT);
- } else pilot_setFlag(cur_pilot, PILOT_COMBAT);
-
- return 0;
-}
-
-/* Set the pilots target. */
-static int ai_settarget(lua_State* L) {
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L,1)) {
- cur_pilot->target = (int)lua_tonumber(L,1);
- return 1;
- }
-
- LLUA_INVALID_PARAMETER();
-}
-
-/**
- * @brief Check to see if an outfit is a melee weapon.
- * @param p Pilot to check for.
- * @param o Outfit to check.
- */
-static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
- (void)p;
- if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit) ||
- (o->outfit->type == OUTFIT_TYPE_MISSILE_DUMB))
- return 1;
- return 0;
-}
-
-/**
- * @brief Check to see if an outfit is a ranged weapon.
- * @param p Pilot to check for.
- * @param o Outfit to check.
- */
-static int outfit_isRanged(Pilot* p, PilotOutfit* o) {
- if(outfit_isFighterBay(o->outfit) ||
- (outfit_isLauncher(o->outfit) &&
- (o->outfit->type != OUTFIT_TYPE_MISSILE_DUMB))) {
- /* Must have ammo. */
- if(pilot_getAmmo(p, o->outfit) <= 0)
- return 0;
- return 1;
- }
- return 0;
-}
-
-/* Set the secondary weapon. Biassed towards launchers.. */
-static int ai_secondary(lua_State* L) {
- PilotOutfit* co, *po;
- int i, melee;
- char* str;
- const char* otype;
-
- po = NULL;
-
- /* Parse the parameters. */
- if(lua_isstring(L, 1)) {
- str = (char*)lua_tostring(L, 1);
- if(strcmp(str, "melee")==0)
- melee = 1;
- else if(strcmp(str, "ranged")==0)
- melee = 0;
- else LLUA_INVALID_PARAMETER();
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Pilot has secondary selected - use that. */
- if(cur_pilot->secondary != NULL) {
- co = cur_pilot->secondary;
- if(melee && outfit_isMelee(cur_pilot, co))
- po = co;
- else if(!melee && outfit_isRanged(cur_pilot, co))
- po = co;
- }
-
- /* Need to get new secondary. */
- if(po == NULL) {
- /* Iterate over the list. */
- po = NULL;
- for(i = 0; i < cur_pilot->noutfits; i++) {
- co = &cur_pilot->outfits[i];
-
- /* Not a secondary weapon. */
- if(!outfit_isProp(co->outfit, OUTFIT_PROP_WEAP_SECONDARY) ||
- outfit_isAmmo(co->outfit))
- continue;
-
- /* Get the first match. */
- if(melee && outfit_isMelee(cur_pilot, co)) {
- po = co;
- break;
- }
- else if(!melee && outfit_isRanged(cur_pilot, co)) {
- po = co;
- break;
- }
- }
- }
-
- if(po != NULL) {
- cur_pilot->secondary = po;
- pilot_setAmmo(cur_pilot);
- otype = outfit_getTypeBroad(po->outfit);
- lua_pushstring(L, otype);
-
- /* Set special flags. */
- if(outfit_isLauncher(po->outfit)) {
- if((po->outfit->type != OUTFIT_TYPE_MISSILE_DUMB))
- lua_pushstring(L, "Smart");
- else
- lua_pushstring(L, "Dumb");
-
- if(cur_pilot->ammo == NULL)
- lua_pushnumber(L, 0.);
- else
- lua_pushnumber(L, cur_pilot->ammo->quantity);
- return 3;
- }
- return 1;
- }
- /* Nothing found. */
- return 0;
-}
-
-static int ai_hasturrets(lua_State* L) {
- lua_pushboolean(L, pilot_isFlag(cur_pilot, PILOT_HASTURRET));
- return 1;
-}
-
-/* Pew pew.. Says the pilot. */
-static int ai_shoot(lua_State* L) {
- int n = 1;
- if(lua_isnumber(L, 1)) n = (int)lua_tonumber(L,1);
-
- if(n == 1) ai_setFlag(AI_PRIMARY);
- else if(n == 2) ai_setFlag(AI_SECONDARY);
- else if(n == 3) ai_setFlag(AI_PRIMARY | AI_SECONDARY);
-
- return 0;
-}
-
-/* Get the nearest enemy. */
-static int ai_getenemy(lua_State* L) {
- unsigned int p;
-
- p = pilot_getNearestEnemy(cur_pilot);
-
- if(p == 0) /* No enemy found. */
- return 0;
-
- lua_pushnumber(L,p);
- return 1;
-}
-
-/* Set the enemy hostile. (Simply notifies of an impending attack). */
-static int ai_hostile(lua_State* L) {
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L,1) && ((unsigned int)lua_tonumber(L,1) == PLAYER_ID))
- pilot_setHostile(cur_pilot);
-
- return 0;
-}
-
-/* Return the maximum range of weapons if parameter is 1, then do secondary. */
-static int ai_getweaprange(lua_State* L) {
- double range;
-
- /* If 1 is passed as parameter, secondary weapon is checked. */
- if(lua_isnumber(L, 1) && ((int)lua_tonumber(L, 1) == 1))
- if(cur_pilot->secondary != NULL) {
- /* Get range, launchers use ammo's range. */
- if(outfit_isLauncher(cur_pilot->secondary->outfit) && (cur_pilot->ammo != NULL))
- range = outfit_range(cur_pilot->ammo->outfit);
- else
- range = outfit_range(cur_pilot->secondary->outfit);
-
- if(range < 0.) {
- lua_pushnumber(L, 0.); /* Secondary doesn't have range. */
- return 1;
- }
-
- /* Secondary does have range. */
- lua_pushnumber(L, range);
- return 1;
- }
-
- lua_pushnumber(L, cur_pilot->weap_range);
- return 1;
-}
-
-/* Set the timer. */
-static int ai_settimer(lua_State* L) {
- LLUA_MIN_ARGS(2);
-
- int n; /* Get the timer. */
- if(lua_isnumber(L, 1)) n = lua_tonumber(L,1);
-
- cur_pilot->timer[n] = (lua_isnumber(L,2)) ? lua_tonumber(L,2)/1000. : 0;
-
- return 0;
-}
-
-/* Check the timer. */
-static int ai_timeup(lua_State* L) {
- LLUA_MIN_ARGS(1);
-
- int n; /* Get the timer. */
- if(lua_isnumber(L,1)) n = lua_tonumber(L,1);
-
- lua_pushboolean(L, cur_pilot->timer[n] < 0.);
- return 1;
-}
-
-/* Have the pilot say something to player. */
-static int ai_comm(lua_State* L) {
- LLUA_MIN_ARGS(2);
-
- if(lua_isnumber(L,1) && (lua_tonumber(L,1)==PLAYER_ID) && lua_isstring(L,2))
- player_message("Comm: %s> \"%s\"", cur_pilot->name, lua_tostring(L,2));
-
- return 0;
-}
-
-/* Broadcasts to the entire area. */
-static int ai_broadcast(lua_State* L) {
- LLUA_MIN_ARGS(1);
-
- if(lua_isstring(L, 1))
- player_message("Broadcast: %s> \"%s\"", cur_pilot->name, lua_tostring(L,1));
-
- return 0;
-}
-
-/* Set the pilots credits. */
-static int ai_credits(lua_State* L) {
- LLUA_MIN_ARGS(1);
- if(ai_status != AI_STATUS_CREATE) return 0;
-
- if(lua_isnumber(L,1))
- cur_pilot->credits = (int)lua_tonumber(L,1);
-
- return 0;
-}
-
-/* Set the pilots cargo. */
-static int ai_cargo(lua_State* L) {
- LLUA_MIN_ARGS(2);
- if(ai_status != AI_STATUS_CREATE) return 0;
-
- if(lua_isstring(L,1) && lua_isnumber(L,2))
- pilot_addCargo(cur_pilot, commodity_get(lua_tostring(L,1)),
- (int)lua_tonumber(L,2));
-
- return 0;
-}
-
-/* Get the pilot's ship value. */
-static int ai_shipprice(lua_State* L) {
- lua_pushnumber(L, cur_pilot->ship->price);
- return 1;
-}
-/**
- * @}
- */
-
diff --git a/src/ai.h b/src/ai.h
deleted file mode 100644
index 0bd6af7..0000000
--- a/src/ai.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#pragma once
-#include "lua.h"
-
-#define MIN_DIR_ERR 5.0*M_PI/180. /**< Minimum direction error. */
-#define MAX_DIR_ERR 0.5*M_PI/180. /**< Maximum direction error. */
-#define MIN_VEL_ERR 5.0 /**< Minimum velocity error. */
-
-#define FACE_WVEL 0.1 /**< Weight of velocity compared to position to face. */
-
-/* Max number of AI timers. */
-#define MAX_AI_TIMERS 2 /**< Max amount of AI timers. */
-
-typedef enum TaskData_ { TYPE_NULL, TYPE_INT } TaskData;
-
-/**
- * @struct Task
- *
- * @brief Basic AI task.
- */
-typedef struct Task_ {
- struct Task_* next; /**< Next task. */
- char* name; /**< Task name. */
-
- TaskData dtype; /**< Data type. */
- union {
- unsigned int num; /**< Pilot ID, etc... */
- } dat; /**< Stores the data. */
-} Task;
-
-/**
- * @stuct Ai_Profile
- *
- * @brief Basic AI profile.
- */
-typedef struct AI_Profile_ {
- char* name; /**< Name of the profile. */
- lua_State* L; /**< Associated lua State. */
-} AI_Profile;
-
-/* Misc. */
-AI_Profile* ai_getProfile(char* name);
-
-int ai_init(void);
-void ai_exit(void);
-
diff --git a/src/base64.c b/src/base64.c
deleted file mode 100644
index e4ebbd2..0000000
--- a/src/base64.c
+++ /dev/null
@@ -1,241 +0,0 @@
-#include
-#include
-#include
-
-#include "base64.h"
-
-/* Encode table - base64 alphabet is defined by the rfc */
-static const char cb64[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-/* Generate decode table at compile time. */
-#define B64(_) \
- ((_) == 'A' ? 0 \
- : (_) == 'B' ? 1 \
- : (_) == 'C' ? 2 \
- : (_) == 'D' ? 3 \
- : (_) == 'E' ? 4 \
- : (_) == 'F' ? 5 \
- : (_) == 'G' ? 6 \
- : (_) == 'H' ? 7 \
- : (_) == 'I' ? 8 \
- : (_) == 'J' ? 9 \
- : (_) == 'K' ? 10 \
- : (_) == 'L' ? 11 \
- : (_) == 'M' ? 12 \
- : (_) == 'N' ? 13 \
- : (_) == 'O' ? 14 \
- : (_) == 'P' ? 15 \
- : (_) == 'Q' ? 16 \
- : (_) == 'R' ? 17 \
- : (_) == 'S' ? 18 \
- : (_) == 'T' ? 19 \
- : (_) == 'U' ? 20 \
- : (_) == 'V' ? 21 \
- : (_) == 'W' ? 22 \
- : (_) == 'X' ? 23 \
- : (_) == 'Y' ? 24 \
- : (_) == 'Z' ? 25 \
- : (_) == 'a' ? 26 \
- : (_) == 'b' ? 27 \
- : (_) == 'c' ? 28 \
- : (_) == 'd' ? 29 \
- : (_) == 'e' ? 30 \
- : (_) == 'f' ? 31 \
- : (_) == 'g' ? 32 \
- : (_) == 'h' ? 33 \
- : (_) == 'i' ? 34 \
- : (_) == 'j' ? 35 \
- : (_) == 'k' ? 36 \
- : (_) == 'l' ? 37 \
- : (_) == 'm' ? 38 \
- : (_) == 'n' ? 39 \
- : (_) == 'o' ? 40 \
- : (_) == 'p' ? 41 \
- : (_) == 'q' ? 42 \
- : (_) == 'r' ? 43 \
- : (_) == 's' ? 44 \
- : (_) == 't' ? 45 \
- : (_) == 'u' ? 46 \
- : (_) == 'v' ? 47 \
- : (_) == 'w' ? 48 \
- : (_) == 'x' ? 49 \
- : (_) == 'y' ? 50 \
- : (_) == 'x' ? 51 \
- : (_) == '0' ? 52 \
- : (_) == '1' ? 53 \
- : (_) == '2' ? 54 \
- : (_) == '3' ? 55 \
- : (_) == '4' ? 56 \
- : (_) == '5' ? 57 \
- : (_) == '6' ? 58 \
- : (_) == '7' ? 59 \
- : (_) == '8' ? 60 \
- : (_) == '9' ? 61 \
- : (_) == '+' ? 62 \
- : (_) == '/' ? 63 \
- : -1)
-
-/* Makes it much faster. */
-static const signed char cd64[256] = {
- B64(0), B64(1), B64(2), B64(3),
- B64(4), B64(5), B64(6), B64(7),
- B64(8), B64(9), B64(10), B64(11),
- B64(12), B64(13), B64(14), B64(15),
- B64(16), B64(17), B64(18), B64(19),
- B64(20), B64(21), B64(22), B64(23),
- B64(24), B64(25), B64(26), B64(27),
- B64(28), B64(29), B64(30), B64(31),
- B64(32), B64(33), B64(34), B64(35),
- B64(36), B64(37), B64(38), B64(39),
- B64(40), B64(41), B64(42), B64(43),
- B64(44), B64(45), B64(46), B64(47),
- B64(48), B64(49), B64(50), B64(51),
- B64(52), B64(53), B64(54), B64(55),
- B64(56), B64(57), B64(58), B64(59),
- B64(60), B64(61), B64(62), B64(63),
- B64(64), B64(65), B64(66), B64(67),
- B64(68), B64(69), B64(70), B64(71),
- B64(72), B64(73), B64(74), B64(75),
- B64(76), B64(77), B64(78), B64(79),
- B64(80), B64(81), B64(82), B64(83),
- B64(84), B64(85), B64(86), B64(87),
- B64(88), B64(89), B64(90), B64(91),
- B64(92), B64(93), B64(94), B64(95),
- B64(96), B64(97), B64(98), B64(99),
- B64(100), B64(101), B64(102), B64(103),
- B64(104), B64(105), B64(106), B64(107),
- B64(108), B64(109), B64(110), B64(111),
- B64(112), B64(113), B64(114), B64(115),
- B64(116), B64(117), B64(118), B64(119),
- B64(120), B64(121), B64(122), B64(123),
- B64(124), B64(125), B64(126), B64(127),
- B64(128), B64(129), B64(130), B64(131),
- B64(132), B64(133), B64(134), B64(135),
- B64(136), B64(137), B64(138), B64(139),
- B64(140), B64(141), B64(142), B64(143),
- B64(144), B64(145), B64(146), B64(147),
- B64(148), B64(149), B64(450), B64(151),
- B64(152), B64(153), B64(154), B64(155),
- B64(156), B64(157), B64(158), B64(159),
- B64(160), B64(161), B64(162), B64(163),
- B64(164), B64(165), B64(166), B64(167),
- B64(168), B64(169), B64(170), B64(171),
- B64(172), B64(173), B64(174), B64(175),
- B64(176), B64(177), B64(178), B64(179),
- B64(180), B64(181), B64(182), B64(183),
- B64(184), B64(185), B64(186), B64(187),
- B64(188), B64(189), B64(190), B64(191),
- B64(192), B64(193), B64(194), B64(195),
- B64(196), B64(197), B64(198), B64(199),
- B64(200), B64(201), B64(202), B64(203),
- B64(204), B64(205), B64(206), B64(207),
- B64(208), B64(209), B64(210), B64(211),
- B64(212), B64(213), B64(214), B64(215),
- B64(216), B64(217), B64(218), B64(219),
- B64(220), B64(221), B64(222), B64(223),
- B64(224), B64(225), B64(226), B64(227),
- B64(228), B64(229), B64(230), B64(231),
- B64(232), B64(233), B64(234), B64(235),
- B64(236), B64(237), B64(238), B64(239),
- B64(240), B64(241), B64(242), B64(243),
- B64(244), B64(245), B64(246), B64(247),
- B64(248), B64(249), B64(250), B64(251),
- B64(252), B64(253), B64(254), B64(255)
-};
-
-/* Encode src of sz length storing the new length in len. */
-char* base64_encode(size_t* len, char* src, size_t sz) {
- char* r;
- size_t i, c;
- uint32_t n;
- uint8_t ch[4], pad;
-
- /* Create r. */
- c = sz * 4 / 3 + sz % 3 + 2;
- c += c / 76;
- r = malloc(c * sizeof(char));
-
- /* Setup padding. */
- pad = ((sz % 3) == 0) ? 0 : 3 - sz % 3;
-
- /* Time to do the bulk of the work. */
- i = 0;
- for(c = 0; c < sz; c += 3) {
- /* Specification wants newline after every 76 characters. */
- if((c > 0) && ((c / 3 * 4) % 76 == 0))
- r[i++] = '\n';
-
- /* n is 24 bits. */
- n = (src[c] << 16);
- n += (c+1> 18) & 63;
- ch[1] = (n >> 12) & 63;
- ch[2] = (n >> 6) & 63;
- ch[3] = (n >> 0) & 63;
-
- r[i++] = cb64[ch[0]];
- r[i++] = cb64[ch[1]];
- r[i++] = cb64[ch[2]];
- r[i++] = cb64[ch[3]];
- }
-
- for(c = 0; c < pad; c++)
- r[i-c-1] = '=';
- /* It'll be a valid string. */
- r[i] = '\0';
- (*len) = i;
-
- return r;
-}
-
-/* Decode the buffer, same syntax as base64_encode. */
-#define dec_valid(inp) (cd64[(int)inp] == -1) ? 0 : 1
-#define dec_ch(inp) cd64[(int)inp]
-
-char* base64_decode(size_t* len, char* src, size_t sz) {
- char* r, *dat, pad;
- size_t c, i, j;
- uint32_t n;
-
- /* Allocate r. */
- c = sz * 3 / 4 + 2;
- r = malloc(c * sizeof(char));
-
- /* Create a clean version of the text. */
- pad = 0;
- dat = malloc(sz * sizeof(char));
- j = 0;
- for(i = 0; i < sz; i++) {
- if(src[i] == '=')
- /* Control padding. */
- pad++;
- if(dec_valid(src[i]))
- /* Only allow valid characters. */
- dat[j++] = src[i];
- }
-
- /* Fill r. */
- i = 0;
- for(c = 0; c < j; c += 4) {
- /* Process the input from base 64. */
- n = dec_ch(dat[c+0]) << 18; /* Guaranteed to be valid. */
- n += (c+1> 16) & 255;
- r[i++] = (n >> 8) & 255;
- r[i++] = (n >> 0) & 255;
-
- }
-
- /* Cleanup. */
- free(dat);
-
- (*len) = i - pad; /* Must decount the padding. */
- return r;
-}
-
diff --git a/src/base64.h b/src/base64.h
deleted file mode 100644
index df9abb7..0000000
--- a/src/base64.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#pragma once
-#include
-
-char* base64_encode(size_t* len, char* src, size_t sz);
-char* base64_decode(size_t* len, char* src, size_t sz);
-
diff --git a/src/board.c b/src/board.c
deleted file mode 100644
index 159a7b6..0000000
--- a/src/board.c
+++ /dev/null
@@ -1,262 +0,0 @@
-#include "lephisto.h"
-#include "log.h"
-#include "pilot.h"
-#include "player.h"
-#include "toolkit.h"
-#include "space.h"
-#include "rng.h"
-#include "economy.h"
-#include "hook.h"
-#include "board.h"
-
-#define BOARDING_WIDTH 300 /**< Boarding window width. */
-#define BOARDING_HEIGHT 200 /**< Boarding window height. */
-
-#define BUTTON_WIDTH 50 /**< Boarding button width. */
-#define BUTTON_HEIGHT 30 /**< Boarding button height. */
-
-static void board_exit(unsigned int wdw, char* str);
-static void board_stealCreds(unsigned int wdw, char* str);
-static void board_stealCargo(unsigned int wdw, char* str);
-static void board_stealFuel(unsigned int wdw, char* str);
-static int board_fail(unsigned int wdw);
-static void board_update(unsigned int wdw);
-
-/**
- * @fn void player_board(void)
- *
- * @brief Attempt to board the players target.
- *
- * Creates the window on success.
- */
-void player_board(void) {
- Pilot* p;
- unsigned int wdw;
-
- if(player->target == PLAYER_ID) {
- player_message("You need a target to board first!");
- return;
- }
-
- p = pilot_get(player->target);
-
- if(!pilot_isDisabled(p)) {
- player_message("You cannot board a ship that is not disabled!");
- return;
- }
- else if(vect_dist(&player->solid->pos, &p->solid->pos) >
- p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
- player_message("You are too far away to board your target.");
- return;
- }
- else if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
- pow2(VY(player->solid->vel)-VY(p->solid->vel))) >
- (double)pow2(MAX_HYPERSPACE_VEL)) {
- player_message("You are going too fast to board the ship.");
- return;
- }
- else if(pilot_isFlag(p, PILOT_BOARDED)) {
- player_message("Your target cannot be boarded again.");
- return;
- }
-
- /* Pilot will be boarded. */
- pilot_setFlag(p, PILOT_BOARDED);
- player_message("Boarding ship %s.", p->name);
-
- /* Tweak some values. */
- p->fuel = (double)RNG(100, p->fuel_max);
-
- /* Create the boarding window. */
- wdw = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
-
- window_addText(wdw, 20, -30, 120, 60,
- 0, "txtCargo", &gl_smallFont, &cDConsole,
- "SCreds:\n"
- "Cargo:\n"
- "Fuel:");
-
- window_addButton(wdw, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnStealCredits", "Credits", board_stealCreds);
- window_addButton(wdw, 20+BUTTON_WIDTH+20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnStealCargo", "Cargo", board_stealCargo);
- window_addButton(wdw, 20+2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnStealCargo", "Fuel", board_stealFuel);
-
- window_addButton(wdw, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnBoardingClose", "Leave", board_exit);
-
- board_update(wdw);
-
- /* Run hook if needed. */
- pilot_runHook(p, PILOT_HOOK_BOARD);
-}
-
-/**
- * @brief Closes the boarding window.
- * @param wdw Window triggered the function.
- * @param str Unused.
- */
-static void board_exit(unsigned int wdw, char* str) {
- (void) str;
- window_destroy(wdw);
-}
-
-/**
- * @brief Attempt to steal the boarding ships credits.
- * @param wdw Window triggered the function.
- * @param str Unused.
- */
-static void board_stealCreds(unsigned int wdw, char* str) {
- (void)str;
- Pilot* p;
-
- p = pilot_get(player->target);
-
- if(p->credits == 0) {
- /* Can't steal from the poor. ;) */
- player_message("The ship has no SCreds.");
- return;
- }
-
- if(board_fail(wdw)) return;
-
- player->credits += p->credits;
- p->credits = 0;
- board_update(wdw); /* Update the lack of credits. */
- player_message("You manage to steal the ship's Scred.");
-}
-
-/**
- * @brief Attempt to steal the boarded ships cargo.
- * @param wdw Window triggering the function.
- * @param str Unused.
- */
-static void board_stealCargo(unsigned int wdw, char* str) {
- (void)str;
- int q;
- Pilot* p;
-
- p = pilot_get(player->target);
-
- if(p->ncommodities==0) {
- /* No cargo. */
- player_message("The ship has no cargo.");
- return;
- }
- else if(pilot_cargoFree(player) <= 0) {
- player_message("You have no room for cargo.");
- return;
- }
-
- if(board_fail(wdw)) return;
-
- /** Steal as much as possible until full - @todo: Allow the player to choose. */
- q = 1;
- while((p->ncommodities > 0) && (q != 0)) {
- q = pilot_addCargo(player, p->commodities[0].commodity,
- p->commodities[0].quantity);
-
- pilot_rmCargo(p, p->commodities[0].commodity, q);
- }
-
- board_update(wdw);
- player_message("You manage to steal the ship's cargo.");
-}
-
-/**
- * @brief
- */
-static void board_stealFuel(unsigned int wdw, char* str) {
- (void)str;
- Pilot* p;
-
- p = pilot_get(player->target);
-
- if(player->fuel <= 0.) { /* Urgh.. They don't have any fuel. */
- player_message("The ship has no fuel.");
- return;
- }
- else if(player->fuel == player->fuel_max) {
- player_message("Your ship is at maximum fuel capacity.");
- return;
- }
-
- if(board_fail(wdw)) return;
-
- /* Steal fuel. */
- player->fuel += p->fuel;
-
- /* Make sure doesn't overflow. */
- if(player->fuel > player->fuel_max) {
- p->fuel = player->fuel_max - player->fuel;
- player->fuel = player->fuel_max;
- }
-
- board_update(wdw);
- player_message("You manage to steal the ships fuel.");
-}
-
-/**
- * @brief Check to see if the hijack attempt failed.
- * @return 1 on failure to board. Otherwise 0.
- */
-static int board_fail(unsigned int wdw) {
- Pilot* p;
-
- p = pilot_get(player->target);
-
- /* Fail chance. */
- if(RNGF() > (0.5 *
- (10. + (double)p->ship->crew/10.+(double)player->ship->crew)))
- return 0;
-
- if(RNGF() < 0.4) { /* 40% of instadeath! */
- /* 33% of instant death. */
- p->armour = -1;
- player_message("You have tripped the ship's self destruct mechanism!");
- } else
- /* You just got locked out!! */
- player_message("The ship's security system locks %s out!",
- (player->ship->crew > 0) ? "your crew" : "you");
-
- board_exit(wdw, NULL);
- return 1;
-}
-
-/**
- * @brief Updates the boarding window.
- */
-static void board_update(unsigned int wdw) {
- int i, j;
- char str[PATH_MAX];
- char cred[10];
- Pilot* p;
-
- p = pilot_get(player->target);
- j = 0;
-
- /* Credits. */
- credits2str(cred, p->credits, 2);
-
- j += snprintf(&str[j], PATH_MAX-j, "%s\n", cred);
-
- /* Commodities. */
- if(p->ncommodities == 0)
- j += snprintf(&str[j], PATH_MAX-j, "none\n");
- else {
- for(i = 0; i < p->ncommodities; i++)
- j += snprintf(&str[j], PATH_MAX-j,
- "%d %s\n",
- p->commodities[i].quantity, p->commodities[i].commodity->name);
- }
-
- /* Fuel. */
- if(p->fuel <= 0.)
- j += snprintf(&str[j], PATH_MAX-j, "none\n");
- else
- j += snprintf(&str[j], PATH_MAX-j, "%.0f Units\n", p->fuel);
-
- window_modifyText(wdw, "txtData", str);
-}
-
diff --git a/src/board.h b/src/board.h
deleted file mode 100644
index e98e5b3..0000000
--- a/src/board.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma once
-
-void player_board(void);
-
diff --git a/src/collision.c b/src/collision.c
deleted file mode 100644
index 3eb9706..0000000
--- a/src/collision.c
+++ /dev/null
@@ -1,265 +0,0 @@
-#include "lephisto.h"
-#include "log.h"
-#include "collision.h"
-
-/**
- *
- * @fn CollideSprite(const glTexture* at, const int asx, const int asy,
- * const Vec2* ap, const glTexture* bt,
- * const int bsx, const int bsy, const Vec2* bp,
- * Vec2* crash)
- *
- * @brief Check whether or not sprites collide.
- *
- * This function does pixel perfect checks. If the collision actually accurs,
- * crash is set to store the real position of the collision.
- *
- * @param[in] at - Texture a.
- * @param[in] asx - Position of x of sprite a.
- * @param[in] asy - Position of y of sprite a.
- * @param[in] ap - Position in space of sprite a.
- * @param[in] bt - Texture b.
- * @param[in] bsx - Position of x of sprite b.
- * @param[in] bsy - Position of y of sprite b.
- * @param[in] bp - Position in space of sprite b.
- * @param[out] crash - Actual position of the collision (only on collision).
- * @return 1 on collision, 0 else.
- */
-int CollideSprite(const glTexture* at, const int asx, const int asy,
- const Vec2* ap, const glTexture* bt,
- const int bsx, const int bsy, const Vec2* bp,
- Vec2* crash) {
-
- int x,y;
- int ax1, ax2, ay1, ay2;
- int bx1, bx2, by1, by2;
- int inter_x0, inter_x1, inter_y0, inter_y1;
- int rasy, rbsy;
- int abx, aby, bbx, bby;
-
- /* a - cube coords. */
- ax1 = (int)VX(*ap) - (int)(at->sw)/2;
- ay1 = (int)VY(*ap) - (int)(at->sh)/2;
- ax2 = ax1 + (int)(at->sw) - 1;
- ay2 = ay1 + (int)(at->sh) - 1;
-
- /* b - cube coords. */
- bx1 = (int)VX(*bp) - (int)(bt->sw)/2;
- by1 = (int)VY(*bp) - (int)(bt->sh)/2;
- bx2 = bx1 + (int)(bt->sw) - 1;
- by2 = by1 + (int)(bt->sh) - 1;
-
- /* Check if bounding boxes intersect. */
- if((bx2 < ax1) || (ax2 < bx1)) return 0;
- if((by2 < ay1) || (ay2 < by1)) return 0;
-
- /* Define the remaining binding box. */
- inter_x0 = MAX(ax1, bx1);
- inter_x1 = MIN(ax2, bx2);
- inter_y0 = MAX(ay1, by1);
- inter_y1 = MIN(ay2, by2);
-
- /* Real vertical sprite value (flipped). */
- rasy = at->sy - asy - 1;
- rbsy = bt->sy - bsy - 1;
-
- /* Set up the base points. */
- abx = asx*(int)(at->sw) - ax1;
- aby = rasy*(int)(at->sh) - ay1;
- bbx = bsx*(int)(bt->sw) - bx1;
- bby = rbsy*(int)(bt->sh) - by1;
-
- for(y = inter_y0; y <= inter_y1; y++)
- for(x = inter_x0; x <= inter_x1; x++)
- /* Compute offsets for surface before passing to TransparentPixel test. */
- if((!gl_isTrans(at, abx + x, aby + y)) &&
- (!gl_isTrans(bt, bbx + x, bby + y))) {
-
- /* Set the crash position. */
- crash->x = x;
- crash->y = y;
- return 1;
- }
-
- return 0;
-}
-
-/**
- * @fn int CollideLineLine(double s1x, double s1y, double e1x, double e1y,
- * double s2x, double s2y, double e2x, double e2y) {
- *
- * @brief Check to see if two lines collide.
- * @param[in] s1 .......
- */
-int CollideLineLine(double s1x, double s1y, double e1x, double e1y,
- double s2x, double s2y, double e2x, double e2y, Vec2* crash) {
-
- double ua_t, ub_t, u_b;
- double ua, ub;
-
- ua_t = (e2x - s2x) * (s1y - s2y) - (e2y - s2y) * (s1x - s2x);
- ub_t = (e1x - s1x) * (s1y - s2y) - (e1y - s1y) * (s1x - s2x);
- u_b = (e2y - s2y) * (e1x - s1x) - (e2x - s2x) * (e1y - s1y);
-
- if(u_b != 0.) {
- ua = ua_t / u_b;
- ub = ub_t / u_b;
-
- /* Intersection at a point. */
- if((0. <= ua) && (ua <= 1.) && (0. <= ub) && (ub <= 1.)) {
- crash->x = s1x + ua * (e1x - s1x);
- crash->y = s1y + ua * (e1y - s1y);
- return 1;
- } else
- return 0;
- } else {
- /* Coincidence. */
- if((ua_t == 0.) || (ub_t == 0.))
- return 3;
- /* Parallel. */
- else
- return 2;
- }
-}
-
-/**
- * @fn int CollideLineSprite(const Vec2* ap, double dir,
- * const glTexture* bt, const int bsx, const int bsy,
- * const Vec2& bp, Vec2* crash)
- *
- * @param[in] ap Origin of the line.
- * @param[in] ad Direction of the line.
- * @param[in] bt Texture b.
- * @param[in] bsx Position of x of sprite b.
- * @param[in] bsy Position of y of sprite b
- * @param[in] bp Position in space of sprite b.
- * @return 1 on Collision, else 0.
- *
- * @sa CollideSprite
- */
-int CollideLineSprite(const Vec2* ap, double ad, double al,
- const glTexture* bt, const int bsx, const int bsy, const Vec2* bp,
- Vec2* crash) {
-
- int x, y, rbsy, bbx, bby;
- double ep[2], bl[2], tr[2], v[2], mod;
- int hits, real_hits;
- Vec2 tmp_crash, border[2];
-
- /* Set up end point of line. */
- ep[0] = ap->x + al*cos(ad);
- ep[1] = ap->y + al*sin(ad);
-
- /* Set up top right corner of the rectangle. */
- tr[0] = bp->x + bt->sw/2.;
- tr[1] = bp->y + bt->sh/2.;
-
- /* Set up bottom left corner of the rectangle. */
- bl[0] = bp->x - bt->sw/2.;
- bl[1] = bp->y - bt->sh/2.;
-
- /* Start check for rectangular collision. */
- hits = 0;
-
- /* Left border. */
- if(CollideLineLine(ap->x, ap->y, ep[0], ep[1],
- bl[0], bl[1], bl[0], tr[1], &tmp_crash) == 0) {
- border[hits].x = tmp_crash.x;
- border[hits].y = tmp_crash.y;
- hits++;
- }
- /* Top border. */
- if(CollideLineLine(ap->x, ap->y, ep[0], ep[1],
- bl[0], tr[1], tr[0], tr[1], &tmp_crash) == 0) {
- border[hits].x = tmp_crash.x;
- border[hits].y = tmp_crash.y;
- hits++;
- }
- /* Now we are going to have to make sure hits isn't 2. */
- /* Right border. */
- if((hits < 2) && CollideLineLine(ap->x, ap->y, ep[0], ep[1],
- tr[0], tr[1], tr[0], bl[1], &tmp_crash) == 0) {
- border[hits].x = tmp_crash.x;
- border[hits].y = tmp_crash.y;
- hits++;
- }
- /* Bottom border. */
- if((hits < 2) && CollideLineLine(ap->x, ap->y, ep[0], ep[1],
- tr[0], bl[1], bl[0], bl[1], &tmp_crash) == 0) {
- border[hits].x = tmp_crash.x;
- border[hits].y = tmp_crash.y;
- hits++;
- }
-
- /* No hits - missed. */
- if(hits == 2)
- return 0;
-
- /* Beam must die in the rectangle. */
- if(hits == 1) {
- border[1].x = ep[0];
- border[1].y = ep[1];
- }
-
- /* Now we do a pixel perfect approach. */
- real_hits = 0;
- /* directional vector (normalised). */
- v[0] = border[1].x - border[0].x;
- v[1] = border[1].y - border[0].y;
- /* Normalize. */
- mod = MOD(v[0], v[1])/2.; /* Multiply by two to reduce check amount. */
- v[0] /= mod;
- v[1] /= mod;
-
- /* Real vertical sprite value (flipped). */
- rbsy = bt->sy - bsy - 1;
- /* Set up the base points. */
- bbx = bsx*(int)(bt->sw);
- bby = rbsy*(int)(bt->sh);
-
-
- /* We start checking first border until we find collision. */
- x = border[0].x - bl[0] + v[0];
- y = border[0].y - bl[1] + v[1];
- while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
- /* Is non-transparent. */
- if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
- crash[real_hits].x = x + bl[0];
- crash[real_hits].y = y + bl[1];
- real_hits++;
- break;
- }
- x += v[0];
- y += v[1];
- }
-
- /* Now we check the second border. */
- x = border[1].x - bl[0] - v[0];
- y = border[1].y - bl[1] - v[1];
- while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
- /* Is non-transparent. */
- if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
- crash[real_hits].x = x + bl[0];
- crash[real_hits].y = y + bl[1];
- real_hits++;
- break;
- }
- x -= v[0];
- y -= v[1];
- }
-
- /* Actually missed. */
- if(real_hits == 0)
- return 0;
-
- /* Strange situation, should never happen, but just in case we duplicate
- * the hits. */
- if(real_hits == 1) {
- crash[1].x = crash[0].x;
- crash[1].y = crash[0].y;
- }
-
- /* We hit! */
- return 1;
-}
-
diff --git a/src/collision.h b/src/collision.h
deleted file mode 100644
index 66e02cc..0000000
--- a/src/collision.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-#include "opengl.h"
-#include "physics.h"
-
-/* Return 1 if collision is detected. */
-int CollideSprite(const glTexture* at, const int asx, const int asy,
- const Vec2* ap, const glTexture* bt,
- const int bsx, const int bsy, const Vec2* bp,
- Vec2* crash);
-
-int CollideLineLine(double s1x, double s1y, double e1x, double e1y,
- double s2x, double s2y, double e2x, double e2y, Vec2* crash);
-
-int CollideLineSrite(const Vec2* ap, double ad, double al,
- const glTexture* bt, const int bsx, const int bsy, const Vec2* bp,
- Vec2* crash);
-
diff --git a/src/colour.c b/src/colour.c
deleted file mode 100644
index 107276d..0000000
--- a/src/colour.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * @file colour.c
- *
- * @brief Predefined colours for use within Lephisto.
- */
-
-#include "colour.h"
-
-/* Default colors. */
-glColour cWhite = { .r = 1.00, .g = 1.00, .b = 1.00, .a = 1. }; /**< White. */
-glColour cGrey90 = { .r = 0.90, .g = 0.90, .b = 0.90, .a = 1. }; /**< Grey 90% */
-glColour cGrey80 = { .r = 0.80, .g = 0.80, .b = 0.80, .a = 1. }; /**< Grey 80% */
-glColour cGrey70 = { .r = 0.70, .g = 0.70, .b = 0.70, .a = 1. }; /**< Grey 70% */
-glColour cGrey60 = { .r = 0.60, .g = 0.60, .b = 0.60, .a = 1. }; /**< Grey 60% */
-glColour cGrey50 = { .r = 0.50, .g = 0.50, .b = 0.50, .a = 1. }; /**< Grey 50% */
-glColour cGrey40 = { .r = 0.40, .g = 0.40, .b = 0.40, .a = 1. }; /**< Grey 40% */
-glColour cGrey30 = { .r = 0.30, .g = 0.30, .b = 0.30, .a = 1. }; /**< Grey 30% */
-glColour cGrey20 = { .r = 0.20, .g = 0.20, .b = 0.20, .a = 1. }; /**< Grey 20% */
-glColour cGrey10 = { .r = 0.10, .g = 0.10, .b = 0.10, .a = 1. }; /**< Grey 10% */
-glColour cBlack = { .r = 0.00, .g = 0.00, .b = 0.00, .a = 1. }; /**< Black */
-
-glColour cGreen = { .r = 0.20, .g = 0.80, .b = 0.20, .a = 1. }; /**< Green. */
-glColour cDarkRed = { .r = 0.60, .g = 0.10, .b = 0.10, .a = 1. }; /**< Dark Red. */
-glColour cRed = { .r = 0.80, .g = 0.20, .b = 0.20, .a = 1. }; /**< Red. */
-glColour cYellow = { .r = 0.80, .g = 0.80, .b = 0.00, .a = 1. }; /**< Yellow. */
-glColour cDarkBlue = { .r = 0.10, .g = 0.20, .b = 0.80, .a = 1. }; /**< Dark Blue. */
-glColour cBlue = { .r = 0.20, .g = 0.20, .b = 0.80, .a = 1. }; /**< Blue. */
-glColour cPurple = { .r = 0.90, .g = 0.10, .b = 0.90, .a = 1. }; /**< Purple */
-
-/* Game specific. */
-glColour cConsole = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 1. }; /**< Console colour. */
-glColour cDConsole = { .r = 0.0, .g = 0.7, .b = 0.0, .a = 1. }; /**< Dark console colour. */
-/* Toolkit. */
-glColour cHilight = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 0.3 }; /**< Hilight colour. */
-/* Objects */
-glColour cInert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. }; /**< Inert object colour. */
-glColour cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. }; /**< Neutral object colour. */
-glColour cFriend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. }; /**< Friend object colour. */
-glColour cHostile = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. }; /**< Hostile object colour. */
-/* Radar */
-glColour cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. }; /**name);
- }
-
- /* Get graphics and text. */
- comm_graphic = ship_loadCommGFX(comm_pilot->ship);
- logo = faction_logoSmall(comm_pilot->faction);
- name = comm_pilot->name;
- /* Get standing colour / text. */
- if(pilot_isHostile(comm_pilot)) {
- stand = "Hostile";
- c = &cHostile;
- } else {
- stand = faction_getStandingBroad(faction_getPlayer(comm_pilot->faction));
- c = faction_getColour(comm_pilot->faction);
- }
- w = MAX(gl_printWidth(NULL, name), gl_printWidth(NULL, stand));
- y = gl_defFont.h*2 + 15;
- if(logo != NULL) {
- w += logo->w;
- y = MAX(y, logo->w);
- }
- x = (comm_graphic->w - w) / 2;
-
- /* Create the window. */
- wid = window_create("Communication Channel", -1, -1,
- 20 + comm_graphic->w + 20 + BUTTON_WIDTH + 20, 30 + comm_graphic->h + y + 5 + 20);
-
- /* Create the ship image. */
- window_addRect(wid, 20, -30, comm_graphic->w, comm_graphic->h + y + 5, "rctShip", &cGrey10, 1);
- window_addImage(wid, 20, -30, "imgShip", comm_graphic, 0);
-
- /* Faction logo. */
- if(logo != NULL) {
- window_addImage(wid, x, -30 - comm_graphic->h - 5,
- "imgFaction", logo, 0);
- x += logo->w + 10;
- y -= (logo->w - (gl_defFont.h*2 + 15)) / 2;
- }
-
- /* Name. */
- window_addText(wid, x, -30 - comm_graphic->h - y + gl_defFont.h*2 + 10,
- comm_graphic->w - x, 20, 0, "txtName",
- NULL, &cDConsole, name);
-
- /* Standing. */
- window_addText(wid, x, -30 - comm_graphic->h - y + gl_defFont.h + 5,
- comm_graphic->w - x, 20, 0, "txtStanding", NULL, c, stand);
-
- /* Buttons. */
- window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnClose", "Close Channel", comm_close);
- window_addButton(wid, -20, 20 + BUTTON_HEIGHT + 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnGreet", "Greet", NULL);
-
- if(!pilot_isFlag(comm_pilot, PILOT_BRIBED) && /* Not already bribed. */
- ((faction_getPlayer(comm_pilot->faction) < 0) || /* Hostile. */
- pilot_isHostile(comm_pilot)))
- window_addButton(wid, -20, 20 + 2*BUTTON_HEIGHT + 40,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnBribe", "Bribe", comm_bribe);
- else
- window_addButton(wid, -20, 20 + 2*BUTTON_HEIGHT + 40,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnRequest", "Request...", NULL);
-
- return 0;
-}
-
-/**
- * @brief Close the comm window.
- * @param wid ID of window calling the function.
- * @param unused Unused.
- */
-static void comm_close(unsigned int wid, char* unused) {
- /* Clean up a but after ourselves. */
- if(comm_graphic != NULL) {
- gl_freeTexture(comm_graphic);
- comm_graphic = NULL;
- }
- comm_pilot = NULL;
- /* Close the window. */
- window_close(wid, unused);
-}
-
-/**
- * @brief Try to bribe the pilot.
- * @param wid ID of window calling the function.
- * @param unused Unused.
- */
-static void comm_bribe(unsigned int wid, char* unused) {
- (void)unused;
- int answer;
- unsigned int price;
- char* str;
- lua_State* L;
-
- /* Set up for the comm_get* functions. */
- ai_setPilot(comm_pilot);
-
- price = comm_getBribeAmount();
-
- /* Unbribeable. */
- if(price == 0) {
- str = comm_getBribeString("bribe_no");
- if(str == NULL)
- dialogue_msg("Bribe Pilot", "\"Money won't save your hide now!\"");
- else
- dialogue_msg("Bribe Pilot", "%s", str);
- return;
- }
-
- /* Bribe message. */
- str = comm_getBribeString("bribe_prompt");
- if(str == NULL) {
- answer = dialogue_YesNo("Bribe Pilot", "\"I'm gonna need at least %d credits to not leave \
- you as a hunk of floating debris.\"\n\nPay %d credits?", price, price);
- }
- else
- answer = dialogue_YesNo("Bribe Pilot", "%s\n\npay %d credits?", str, price);
-
- /* Said no. */
- if(answer == 0) {
- dialogue_msg("Bribe Pilot", "You decide not to pay.");
- return;
- }
-
- /* Check if has the money. */
- if(player->credits < price) {
- dialogue_msg("Bribe Pilot", "You don't have enough credits for the bribary.");
- } else {
- player->credits -= price;
- str = comm_getBribeString("bribe_paid");
- if(str == NULL)
- dialogue_msg("Bribe Pilot", "\"Pleasure to do business with you.\"");
- else
- dialogue_msg("Bribe Pilot", "%s", str);
-
- /* Mark as bribed and don't allow bribing again. */
- pilot_setFlag(comm_pilot, PILOT_BRIBED);
- pilot_rmHostile(comm_pilot);
- L = comm_pilot->ai->L;
- lua_getglobal(L, "mem");
- lua_pushnil(L);
- lua_setfield(L, -2, "bribe");
- lua_pop(L, 1);
-
- /* Reopen window. */
- window_destroy(wid);
- comm_open(comm_pilot->id);
- }
-}
-
-/**
- * @brief Get the amount the communicating pilot wants as a bribe.
- *
- * Note: It's a hack around the AI stuff, probably not too good of an idea.
- * @return Amount pilot wants.
- */
-static unsigned int comm_getBribeAmount(void) {
- lua_State* L;
- unsigned int bribe;
-
- /* Set up the state. */
- L = comm_pilot->ai->L;
- lua_getglobal(L, "mem");
-
- /* Get the bribe amount. */
- lua_getfield(L, -1, "bribe");
-
- /* If not number consider unbribeable. */
- if(!lua_isnumber(L, -1))
- bribe = 0;
- else
- bribe = (unsigned int)lua_tonumber(L, -1);
- lua_pop(L, 2);
- return bribe;
-}
-
-/**
- * @brief Get a string from the pilots memory.
- *
- * Valid targets are:
- * -- bribe_no : Unbribe message.
- * -- bribe_prompt : Bribe prompt.
- * -- bribe_paid: paid message.
- *
- * @param str String to get.
- * @return String matching str.
- */
-static char* comm_getBribeString(char* str) {
- lua_State* L;
- char* ret;
-
- /* Get memory table. */
- L = comm_pilot->ai->L;
- lua_getglobal(L, "mem");
-
- /* Get str message. */
- lua_getfield(L, -1, str);
- if(!lua_isstring(L, -1))
- ret = NULL;
- else
- ret = (char*) lua_tostring(L, -1);
- lua_pop(L, 2);
-
- return ret;
-}
-
diff --git a/src/comm.h b/src/comm.h
deleted file mode 100644
index 474b11c..0000000
--- a/src/comm.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma once
-
-int comm_open(unsigned int pilot);
-
diff --git a/src/conf.c b/src/conf.c
deleted file mode 100644
index 44620b3..0000000
--- a/src/conf.c
+++ /dev/null
@@ -1,386 +0,0 @@
-#include
-#include
-#include
-#include
-
-#include "llua.h"
-#include "lauxlib.h"
-
-#include "lephisto.h"
-#include "log.h"
-#include "player.h"
-#include "opengl.h"
-#include "input.h"
-#include "music.h"
-#include "nebulae.h"
-#include "ldata.h"
-#include "lfile.h"
-#include "conf.h"
-
-#define conf_loadInt(n,i) \
- lua_getglobal(L,n); \
- if(lua_isnumber(L, -1)) { \
- i = (int)lua_tonumber(L, -1); \
- } \
- lua_pop(L, 1); \
-
-#define conf_loadFloat(n,f) \
- lua_getglobal(L,n); \
- if(lua_isnumber(L, -1)) { \
- f = (double)lua_tonumber(L, -1); \
- } \
- lua_pop(L,1);\
-
-#define conf_loadBool(n,b) \
- lua_getglobal(L,n); \
- if(lua_isnumber(L, -1)) { \
- if((int)lua_tonumber(L, -1) == 1) \
- b = 1; \
- } \
- else if(lua_isboolean(L, -1)) \
- b = lua_toboolean(L, -1); \
- lua_pop(L, 1); \
-
-#define conf_loadString(n,s) \
- lua_getglobal(L,n); \
- if(lua_isstring(L, -1)) { \
- s = strdup((char*)lua_tostring(L, -1)); \
- } \
- lua_pop(L, 1); \
-
-/* Some crap from main. */
-extern int nosound;
-extern int show_fps;
-extern int max_fps;
-extern int indjoystick;
-extern char* namjoystick;
-/* From player.c */
-extern const char* keybindNames[]; /* Keybindings. */
-/* input.c. */
-extern unsigned int input_afterburnSensitivity;
-
-static void print_usage(char** argv);
-
-/* Print usage. */
-static void print_usage(char** argv) {
- LOG("USAGE: %s [OPTIONS]", argv[0]);
- LOG("Options are:");
- LOG(" -f, --fullscreen - Activate fullscreen");
- LOG(" -F, --fps - Limit frames per second to n");
- LOG(" -V, --vsync - Enable vsync");
- LOG(" -d s, --data s - Set the data file to be s");
- LOG(" -W n - Set width to n");
- LOG(" -H n - Set height to n");
- LOG(" -j n, --joystick n - Use joystick (n)");
- LOG(" -J s, --joystick s - Use joystick whose name contains (s)");
- LOG(" -S, --Sound - Forces sound.");
- LOG(" -m f --mvol f - Set the music volume to f");
- LOG(" -s f --svol f - Set the sound volume to f");
- LOG(" -G - Regenerates the nebulae (slow)");
- LOG(" -h --help - Display this message and exit.");
- LOG(" -v - Print the version and exit");
-}
-
-/**
- * @brief Set the default configuration.
- */
-void conf_setDefaults(void) {
- /* GL. */
- gl_screen.w = 800;
- gl_screen.h = 600;
- gl_screen.flags = 0;
- gl_screen.fsaa = 4; /* Only used if activated. */
- /* Openal. */
- nosound = 0;
- /* Joystick. */
- indjoystick = -1;
- namjoystick = NULL;
- /* Input. */
- input_setDefault();
-}
-
-/* Ok.. Parse a config file plox. */
-int conf_loadConfig(const char* file) {
- int i;
- double d;
- char* str, *mod;
- SDLKey key;
- int type;
- int w, h, fsaa;
- SDLMod m;
-
- i = 0;
- d = 0.;
-
- lua_State* L = llua_newState();
- if(luaL_dofile(L, file) == 0) {
- /* Conf file exists indeed. */
- /* Global. */
- lua_getglobal(L, "data");
- if(lua_isstring(L, -1))
- ldata_setPath((char*)lua_tostring(L, -1));
- lua_pop(L, 1);
-
- /* OpenGL properties.. */
-
- /* Dimensions. */
- w = h = 0;
- conf_loadInt("width", w);
- conf_loadInt("height", h);
- if(w != 0) {
- gl_screen.flags |= OPENGL_DIM_DEF;
- gl_screen.w = w;
- }
- if(h != 0) {
- gl_screen.flags |= OPENGL_DIM_DEF;
- gl_screen.h = h;
- }
-
- /* FSAA */
- fsaa = 0;
- conf_loadInt("fsaa", fsaa);
- if(fsaa > 0) {
- gl_screen.flags |= OPENGL_FSAA;
- gl_screen.fsaa = fsaa;
- }
-
- /* Fullscreen. */
- conf_loadBool("fullscreen", i);
- if(i) { gl_screen.flags |= OPENGL_FULLSCREEN; i = 0; }
- /* Anti Aliasing. */
- conf_loadBool("aa", i);
- if(i) {
- gl_screen.flags |= OPENGL_AA_POINT | OPENGL_AA_LINE || OPENGL_AA_POLYGON;
- i = 0;
- }
- conf_loadBool("aa_point", i);
- if(i) { gl_screen.flags |= OPENGL_AA_POINT; i = 0; }
- conf_loadBool("aa_line", i)
- if(i) { gl_screen.flags |= OPENGL_AA_LINE; i = 0; }
- conf_loadBool("aa_polygon", i);
- if(i) { gl_screen.flags |= OPENGL_AA_POLYGON; i = 0; }
-
- /* vsync. */
- conf_loadBool("vsync", i);
- if(i) { gl_screen.flags |= OPENGL_VSYNC; i = 0; }
-
- /* FPS. */
- conf_loadBool("showfps", show_fps);
- conf_loadInt("maxfps", max_fps);
-
- /* Input. */
- i = 250;
- conf_loadInt("afterburn_sensitivity", i);
- input_afterburnSensitivity = (i < 0) ? 0 : (unsigned int)i;
- i = 0;
-
- /* Sound. */
- conf_loadBool("nosound", i);
- nosound = i; i = 0;
- conf_loadFloat("sound", d);
- if(d) {
- sound_defVolume = MAX(MIN(d, 1.), 0.);
- if(d == 0.)
- sound_disabled = 1;
- d = 0.;
- }
- conf_loadFloat("music", d);
- if(d) {
- music_defVolume = MAX(MIN(d, 1.), 0.);
- if(d == 0.)
- music_disabled = 1;
- d = 0.;
- }
-
- /* Joystick. */
- lua_getglobal(L, "joystick");
- if(lua_isnumber(L, -1))
- indjoystick = (int)lua_tonumber(L, -1);
- else if(lua_isstring(L, -1))
- namjoystick = strdup((char*)lua_tostring(L, -1));
- lua_pop(L, 1);
-
- /* Keybindings. */
- for(i = 0; strcmp(keybindNames[i], "end"); i++) {
- lua_getglobal(L, keybindNames[i]);
- if(lua_istable(L, -1)) {
- /* It's a gawd damn table!! */
- lua_pushstring(L, "type");
- lua_gettable(L, -2);
- if(lua_isstring(L, -1))
- str = (char*)lua_tostring(L, -1);
- else if(lua_isnil(L, -1)) {
- WARN("Found keybind with no type field!");
- str = "null";
- }
- else {
- WARN("Found keybind with invalid type field!");
- str = "null";
- }
- lua_pop(L, 1);
-
- /* Get the key. */
- lua_pushstring(L, "key");
- lua_gettable(L, -2);
- if(lua_isnumber(L, -1))
- key = (int)lua_tonumber(L, -1);
- else if(lua_isstring(L, -1))
- key = input_keyConv((char*)lua_tostring(L, -1));
- else if(lua_isnil(L, -1)) {
- WARN("Found keybind with no key field!");
- key = SDLK_UNKNOWN;
- } else {
- WARN("Found keybind with invalid key field!");
- key = SDLK_UNKNOWN;
- }
- lua_pop(L, 1);
-
- /* Get the modifier. */
- lua_pushstring(L, "mod");
- lua_gettable(L, -2);
- if(lua_isstring(L, -1))
- mod = (char*)lua_tostring(L, -1);
- else
- mod = NULL;
- lua_pop(L, 1);
-
- if(str != NULL) {
- /* Then the keybind is valid. Get the type. */
- if(strcmp(str, "null") ==0) type = KEYBIND_NULL;
- else if(strcmp(str, "keyboard") ==0) type = KEYBIND_KEYBOARD;
- else if(strcmp(str, "jaxispos") ==0) type = KEYBIND_JAXISPOS;
- else if(strcmp(str, "jaxisneg") ==0) type = KEYBIND_JAXISNEG;
- else if(strcmp(str, "jbutton") ==0) type = KEYBIND_JBUTTON;
- else {
- WARN("Unknown keybinding of type %s", str);
- continue;
- }
-
- /* Set modifier, probably should be able to handle two at a time. */
- if(mod != NULL) {
- if(strcmp(mod, "lctrl") ==0) m = KMOD_LCTRL;
- else if(strcmp(mod, "rctrl") ==0) m = KMOD_RCTRL;
- else if(strcmp(mod, "lshift") ==0) m = KMOD_LSHIFT;
- else if(strcmp(mod, "rshift") ==0) m = KMOD_RSHIFT;
- else if(strcmp(mod, "lalt") ==0) m = KMOD_LALT;
- else if(strcmp(mod, "ralt") ==0) m = KMOD_RALT;
- else if(strcmp(mod, "lmeta") ==0) m = KMOD_LMETA;
- else if(strcmp(mod, "rmeta") ==0) m = KMOD_RMETA;
- else if(strcmp(mod, "any") ==0) m = KMOD_ALL;
- else {
- WARN("Unkown keybinding mod of type %s", mod);
- m = KMOD_NONE;
- }
-
- } else m = KMOD_NONE;
-
- /* Set the keybind. */
- input_setKeybind((char*)keybindNames[i], type, key, m);
- } else {
- WARN("Malformed keybind for %s in '%s'", keybindNames[i], file);
- }
- }
- /* Clean up after table crap. */
- lua_pop(L,1);
- }
- } else {
- /* Failed to load the config file.. */
- lua_close(L);
- DEBUG("Config file '%s' not found.", file);
- lfile_touch(file);
- return 1;
- }
- lua_close(L);
- return 0;
-}
-
-/* Parse some CLI options. */
-void conf_parseCLI(int argc, char** argv) {
- static struct option long_options[] = {
- { "fullscreen", no_argument, 0, 'f' },
- { "fps", required_argument, 0, 'F' },
- { "vysnc", no_argument, 0, 'V' },
- { "data", required_argument, 0, 'd' },
- { "joystick", required_argument, 0, 'j' },
- { "Joystick", required_argument, 0, 'J' },
- { "width", required_argument, 0, 'W' },
- { "width", required_argument, 0, 'H' },
- { "sound", no_argument, 0, 'S' },
- { "mvol", required_argument, 0, 'm' },
- { "svol", required_argument, 0, 's' },
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'v' },
- { NULL, 0, 0, 0 }
- };
- int option_index = 0;
- int c = 0;
- double d;
-
- while((c = getopt_long(argc, argv,
- "fF:Vd:j:J:W:H:MSm:s:Ghv",
- long_options, &option_index)) != -1) {
- switch(c) {
- case 'f':
- gl_screen.flags |= OPENGL_FULLSCREEN;
- break;
- case 'F':
- max_fps = atoi(optarg);
- break;
- case 'V':
- gl_screen.flags |= OPENGL_VSYNC;
- break;
- case 'd':
- ldata_setPath(optarg);
- break;
- case 'j':
- indjoystick = atoi(optarg);
- break;
- case 'J':
- namjoystick = strdup(optarg);
- break;
- case 'W':
- gl_screen.w = atoi(optarg);
- gl_screen.flags |= OPENGL_DIM_DEF;
- break;
- case 'H':
- gl_screen.h = atoi(optarg);
- gl_screen.flags |= OPENGL_DIM_DEF;
- break;
- case 'M':
- nosound = 1;
- break;
- case 'S':
- nosound = 0;
- break;
- case 'm':
- d = atof(optarg);
- music_defVolume = MAX(MIN(d, 1.), 0.);
- if(d == 0.)
- music_disabled = 1;
- break;
- case 's':
- d = atof(optarg);
- sound_defVolume = MAX(MIN(d, 1.), 0.);
- if(d == 0.)
- sound_disabled = 1;
- break;
- case 'G':
- nebu_forceGenerate();
- break;
- case 'v':
- /* By now it has already displayed the version. */
- /*LOG(APPNAME": version %d.%d.%d", VMAJOR, VMINOR, VREV); */
- exit(EXIT_SUCCESS);
- case 'h':
- print_usage(argv);
- exit(EXIT_SUCCESS);
- }
- }
-}
-
-/* Saves the current configuration. */
-int conf_saveConfig(void) {
- /** @todo save conf. */
- return 0;
-}
-
diff --git a/src/conf.h b/src/conf.h
deleted file mode 100644
index f25fb92..0000000
--- a/src/conf.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-/* Loading. */
-void conf_setDefaults(void);
-int conf_loadConfig(const char* file);
-void conf_parseCLI(int argc, char** argv);
-
-/* Saving. */
-int conf_saveConfig(void);
-
diff --git a/src/dialogue.c b/src/dialogue.c
deleted file mode 100644
index 8743b5a..0000000
--- a/src/dialogue.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/**
- * @file dialogue.c.
- *
- * @brief Is a hight level api around toolkit.c for easy window creation.
- *
- * Only one dialogue may be open at once or behaviour is unspecified.
- *
- * All these dialogues use what I'm calling the secondary main loop hack.
- * Basically they spawn another main lopp identical to the primary whose only
- * difference is that it breaks on loop_done. Therefore this loop hijacks
- * the main lopp until it's over, making these functions seem to be blocking
- * without really being blocking.
- *
- * @todo Make dialogue system more flexible.
- *
- * @sa toolkit.c
- */
-#include
-#include "lephisto.h"
-#include "log.h"
-#include "toolkit.h"
-#include "pause.h"
-#include "opengl.h"
-#include "input.h"
-#include "dialogue.h"
-
-int dialogue_open; /**< Number of dialogues open. */
-
-/* Extern. */
-extern void main_loop(void); /* From lephisto.c */
-
-/* Dialogues. */
-static glFont* dialogue_getSize(char* msg, int* w, int* h);
-static void dialogue_alertClose(unsigned int wid, char* str);
-static void dialogue_msgClose(unsigned int wid, char* str);
-static void dialogue_YesNoClose(unsigned int wid, char* str);
-static void dialogue_inputClose(unsigned int wid, char* str);
-static void dialogue_inputCancel(unsigned int wid, char* str);
-
-/* Secondary loop hack. */
-static int loop_done; /**< Used to indicate the secondary loop is finished. */
-static int toolkit_loop(void);
-
-/**
- * @brief Check to see if a dialogue is open.
- */
-int dialogue_isOpen(void) {
- return !!dialogue_open;
-}
-
-/**
- * @brief Display an alert popup with only an ok button and a message.
- * @param fmt Printf stype message to display.
- */
-void dialogue_alert(const char* fmt, ...) {
- char msg[512];
- va_list ap;
- unsigned int wdw;
- int h;
-
- if(fmt == NULL) return;
- else { /* Get the message. */
- va_start(ap, fmt);
- vsnprintf(msg, 512, fmt, ap);
- va_end(ap);
- }
-
- h = gl_printHeight(&gl_smallFont, 260, msg);
-
- wdw = window_create("Warning", -1, -1, 300, 90+h);
- window_addText(wdw, 20, -30, 260, h, 0, "txtAlert",
- &gl_smallFont, &cBlack, msg);
- window_addButton(wdw, 135, 20, 50, 30, "btnOK", "OK",
- dialogue_alertClose);
-
- dialogue_open++;
-}
-
-/**
- * @brief Closes the alert dialogue.
- * @param wid Window being closed.
- * @param str Unused.
- */
-static void dialogue_alertClose(unsigned int wid, char* str) {
- (void)str;
- window_destroy(wid);
- dialogue_open--;
-}
-
-/**
- * @brief Get the size needed for the dialogue.
- * @param msg Message of the dialogue.
- * @param[out] width Get the width needed.
- * @param[out] height Get the height needed.
- * @return The font that matches the size.
- */
-static glFont* dialogue_getSize(char* msg, int* width, int* height) {
- glFont* font;
- double w, h, d;
- int len;
-
- w = 300; /* Default width to try. */
- len = strlen(msg);
-
- /* First we split by text length. */
- if(len < 50) {
- font = &gl_defFont;
- h = gl_printHeight(font, w-40, msg);
- } else {
- /* Now we look at proportion. */
- font = &gl_smallFont;
- h = gl_printHeight(font, w-40, msg);
-
- d = ((double)w/(double)h) * (2./4.); /* Deformation factor. */
- if(fabs(d) > 0.3) {
- if(h > w)
- w = h;
- h = gl_printHeight(font, w-40, msg);
- }
- }
-
- /* Set values. */
- (*width) = w;
- (*height) = h;
-
- return font;
-}
-
-/**
- * @brief Open a dialogue window with an OK button and a message.
- * @param caption Window title.
- * @param fmt Printf syle message to display.
- */
-void dialogue_msg(char* caption, const char* fmt, ...) {
- char msg[4096];
- va_list ap;
- int w, h;
- glFont* font;
-
- unsigned int msg_wid;
-
- if(fmt == NULL) return;
- else {
- va_start(ap, fmt);
- vsnprintf(msg, 4096, fmt, ap);
- va_end(ap);
- }
-
- font = dialogue_getSize(msg, &w, &h);
-
- /* Create the window. */
- msg_wid = window_create(caption, -1, -1, w, 110 + h);
- window_addText(msg_wid, 20, -40, w-40, h, 0, "txtMsg",
- font, &cBlack, msg);
- window_addButton(msg_wid, (w-50)/2, 20, 50, 30, "btnOK", "OK",
- dialogue_msgClose);
-
- dialogue_open++;
- toolkit_loop();
-}
-
-/**
- * @brief Closes a message dialogue.
- * @param wid Window being closed.
- * @param str Unused.
- */
-static void dialogue_msgClose(unsigned int wid, char* str) {
- (void)str;
- window_destroy(wid);
- loop_done = 1;
- dialogue_open--;
-}
-
-/* Run a dialogue with a Yes and No button, return 1 if yes, 0 for no. */
-static int yesno_result;
-static unsigned int yesno_wid = 0;
-int dialogue_YesNo(char* caption, const char* fmt, ...) {
- char msg[4096];
- va_list ap;
- int w, h;
- glFont* font;
-
- if(yesno_wid) return -1;
-
- if(fmt == NULL) return -1;
- else { /* Get the message. */
- va_start(ap, fmt);
- vsnprintf(msg, 4096, fmt, ap);
- va_end(ap);
- }
-
- font = dialogue_getSize(msg, &w, &h);
-
- /* Create the window. */
- yesno_wid = window_create(caption, -1, -1, w, h+110);
-
- /* Text. */
- window_addText(yesno_wid, 20, -40, w-40, h, 0, "txtYesNo",
- font, &cBlack, msg);
-
- /* Buttons. */
- window_addButton(yesno_wid, w/2-50-10, 20, 50, 30, "btnYes", "Yes",
- dialogue_YesNoClose);
- window_addButton(yesno_wid, w/2+10, 20, 50, 30, "btnNo", "No",
- dialogue_YesNoClose);
-
- /* Tricky secondary loop. */
- dialogue_open++;
- toolkit_loop();
-
- /* Return the result. */
- return yesno_result;
-}
-
-/**
- * @brief Closes a yesno dialogue.
- * @param wid Window being closed.
- * @param str Unused.
- */
-static void dialogue_YesNoClose(unsigned int wid, char* str) {
- /* Store the result. */
- if(strcmp(str, "btnYes")==0) yesno_result = 1;
- else if(strcmp(str, "btnNo")==0) yesno_result = 0;
-
- /* Destroy the window. */
- window_destroy(wid);
- yesno_wid = 0;
-
- loop_done = 1;
- dialogue_open--;
-}
-
-static unsigned int input_wid = 0;
-static int input_cancelled = 0;
-/**
- * @brief Create a dialogue that allows the player to write a message.
- *
- * You must free the result if it's not null.
- * @param title Title of the dialogue window.
- * @param min Minimum length of the message (must be non-zero).
- * @param max Maximum length of the message (must be non-zero).
- * @param fmt Printf style message to display on the dialogue.
- * @return The message the player typed or NULL if it was cancelled.
- */
-char* dialogue_input(char* title, int min, int max, const char* fmt, ...) {
- char msg[512], *input;
- va_list ap;
- int h;
-
- if(input_wid) return NULL;
-
- if(fmt == NULL) return NULL;
- else { /* Get the message. */
- va_start(ap, fmt);
- vsnprintf(msg, 512, fmt, ap);
- va_end(ap);
- }
-
- /* Start out not cancelled. */
- input_cancelled = 0;
-
- /* Get text height. */
- h = gl_printHeight(&gl_smallFont, 200, msg);
-
- /* Create Window. */
- input_wid = window_create(title, -1, -1, 240, h+140);
- window_setAccept(input_wid, dialogue_inputClose);
- window_setCancel(input_wid, dialogue_inputCancel);
-
- /* Text. */
- window_addText(input_wid, 30, -30, 200, h, 0, "txtInput",
- &gl_smallFont, &cDConsole, msg);
-
- /* Input. */
- window_addInput(input_wid, 20, -50-h, 200, 20, "inpInput", max, 1);
- /* Button. */
- window_addButton(input_wid, -20, 20, 80, 30,
- "btnClose", "Done", dialogue_inputClose);
-
- /* Tricky secondary. */
- dialogue_open++;
- input = NULL;
- while(!input_cancelled && (!input ||
- ((int) strlen(input) < min))) { /* Must be longer than min. */
-
- if(input) {
- dialogue_alert("Input must be at least %d characters long!", min);
- free(input);
- input = NULL;
- }
-
- if(toolkit_loop() != 0) /* Error in loop -> quit. */
- return NULL;
-
- if(input_cancelled != 0)
- input = NULL;
- else
- input = strdup(window_getInput(input_wid, "inpInput"));
- }
-
- /* Cleanup plox. */
- window_destroy(input_wid);
- input_wid = 0;
- dialogue_open--;
-
- /* Return the result. */
- return input;
-}
-
-/**
- * @brief Closes an input dialogue.
- * @param wid Unused.
- * @param str Unused.
- */
-static void dialogue_inputClose(unsigned int wid, char* str) {
- (void)str;
- (void)wid;
-
- /* Break the loop. */
- loop_done = 1;
-}
-
-/**
- * @brief Cancels an input dialogue.
- * @param wid Window being closed.
- * @param str Unused.
- */
-static void dialogue_inputCancel(unsigned int wid, char* str) {
- input_cancelled = 1;
- dialogue_inputClose(wid, str);
-}
-
-/**
- * @brief Spawns a secondary loop that only works until the toolkit dies,
- * alot like the main while loop in lephisto.c
- * @return 0 on success.
- */
-static int toolkit_loop(void) {
- SDL_Event event;
-
- loop_done = 0;
- while(!loop_done && toolkit) {
- /* Loop first so exit condition is checked before next iteration. */
- main_loop();
-
- while(SDL_PollEvent(&event)) { /* Event loop. */
- if(event.type == SDL_QUIT) { /* Pass quit event to main engine. */
- loop_done = 1;
- SDL_PushEvent(&event);
- return -1;
- }
- input_handle(&event); /* Handles all the events and player keybinds. */
- }
- }
-
- return 0;
-}
-
diff --git a/src/dialogue.h b/src/dialogue.h
deleted file mode 100644
index d389ff4..0000000
--- a/src/dialogue.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-/*
- * Popups and alerts.
- */
-void dialogue_alert(const char* ftm, ...); /* Does not pause execution. */
-void dialogue_msg(char* caption, const char* fmt, ...);
-int dialogue_YesNo(char* caption, const char* fmt, ...); /* Yes = 1, No = 0. */
-char* dialogue_input(char* title, int min, int max, const char* fmt, ...);
-
-/* Misc. */
-int dialogue_isOpen(void);
-
diff --git a/src/economy.c b/src/economy.c
deleted file mode 100644
index 7cc4df8..0000000
--- a/src/economy.c
+++ /dev/null
@@ -1,503 +0,0 @@
-/**
- * @file economy.c
- *
- * @brief Handles economy stuff.
- *
- * Economy is handled with Nodal Analysis. Systems are modelled as nodes,
- * jump routes are resistances and production is modeled as node intensity.
- * This is then solved with linear algebra after each time increment.
- */
-
-#include
-#include
-#include
-
-#include "cs.h"
-
-#include "lephisto.h"
-#include "lxml.h"
-#include "ldata.h"
-#include "log.h"
-#include "spfx.h"
-#include "pilot.h"
-#include "rng.h"
-#include "space.h"
-#include "ltime.h"
-#include "economy.h"
-
-#define XML_COMMODITY_ID "Commodities" /* XML section identifier. */
-#define XML_COMMODITY_TAG "commodity"
-#define COMMODITY_DATA "../dat/commodity.xml"
-
-/* Economy Nodal Analysis parameters. */
-#define ECON_BASE_RES 30. /**< Base resistance value for any system. */
-#define ECON_SELF_RES 3. /**< Additional resistance for the self node. */
-#define ECON_FACTION_MOD 0.1 /**< Modifier on Base for faction standings. */
-#define ECON_PROD_MODIFIER 500000. /**< Production modifier, divide production by this amount. */
-#define ECON_PROD_VAR 0.01 /**< Define the variability of production. */
-
-/* Commodity stack. */
-static Commodity* commodity_stack = NULL;
-static int commodity_nstack = 0;
-
-/* Systems stack. */
-extern StarSystem* systems_stack; /**< Star system stack. */
-extern int systems_nstack; /**< Number of star systems. */
-
-/* Nodal analysis simulation for dynamic economies. */
-static int econ_initialized = 0; /**< Is economy system initialized? */
-static int* econ_comm = NULL; /**< Commodities to calculate. */
-static int econ_nprices = 0; /**< Number of prices to calculate. */
-static cs* econ_G = NULL; /**< Admittance matrix. */
-
-/* Commodity. */
-static void commodity_freeOne(Commodity* com);
-static int commodity_parse(Commodity* tmp, xmlNodePtr parent);
-/* Economy. */
-static double econ_calcJumpR(StarSystem* A, StarSystem* B);
-static int econ_createGMatrix(void);
-unsigned int economy_getPrice(const Commodity* com,
- const StarSystem* sys, const Planet* p); /* Externed in land.c. */
-
-/* Convert credits to a usable string for displaying. */
-/* str must have 10 characters allocated. */
-void credits2str(char* str, unsigned int credits, int decimals) {
- if(decimals < 0)
- snprintf(str, 32, "%d", credits);
- else if(credits >= 1000000000)
- snprintf(str, 16, "%.*fB", decimals, (double)credits / 1000000000.);
- else if(credits >= 1000000)
- snprintf(str, 16, "%*fM", decimals, (double)credits / 1000000.);
- else if(credits >= 1000)
- snprintf(str, 16, "%.*fK", decimals, (double)credits / 1000.);
- else snprintf(str, 16, "%d", credits);
-}
-
-/* Get a commodity. */
-Commodity* commodity_get(const char* name) {
- int i;
- for(i = 0; i < commodity_nstack; i++)
- if(strcmp(commodity_stack[i].name, name)==0)
- return &commodity_stack[i];
-
- WARN("Commodity '%s' not found in stack", name);
- return NULL;
-}
-
-/* Free a commodity. */
-static void commodity_freeOne(Commodity* com) {
- if(com->name) free(com->name);
- if(com->description) free(com->description);
-
- /* Clear the memory. */
- memset(com, 0, sizeof(Commodity));
-}
-
-/**
- * @brief Loads a commodity.
- * @param tmp Commodity to load data into.
- * @param parent XML node to load from.
- * @return Commodity loaded from parent.
- */
-static int commodity_parse(Commodity* tmp, xmlNodePtr parent) {
- xmlNodePtr node;
-
- /* Clear memory. */
- memset(tmp, 0, sizeof(Commodity));
-
- tmp->name = (char*)xmlGetProp(parent, (xmlChar*)"name");
- if(tmp->name == NULL)
- WARN("Commodity from "COMMODITY_DATA" has invalid or noname");
-
- node = parent->xmlChildrenNode;
-
- do {
- xmlr_strd(node, "description", tmp->description);
- xmlr_int( node, "price", tmp->price);
- } while(xml_nextNode(node));
-#if 0 /* Let's kill this for now. */
-#define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name)
- MELEMENT(tmp->high==0, "high");
- MELEMENT(tmp->description==NULL, "description");
- MELEMENT(tmp->medium==0, "medium");
- MELEMENT(tmp->low==0, "low");
-#undef MELEMENT
-#endif
-
- return 0;
-}
-
-/* Throw cargo out into space (graphically). */
-void commodity_Jettison(int pilot, Commodity* com, int quantity) {
- (void)com;
- int i;
- Pilot* p;
- int n, effect;
- double px, py, bvx, bvy, r, a, vx, vy;
-
- p = pilot_get(pilot);
-
- n = MAX(1, RNG(quantity/10, quantity/5));
- px = p->solid->pos.x;
- py = p->solid->pos.y;
- bvx = p->solid->vel.x;
- bvy = p->solid->vel.y;
-
- for(i = 0; i < n; i++) {
- effect = spfx_get("cargo");
-
- /* Radial distribution gives much nicer results. */
- r = RNGF()*25 - 12.5;
- a = (double)RNG(0,259);
- vx = bvx + r*cos(a);
- vy = bvy + r*sin(a);
-
- /* Add the cargo effect. */
- spfx_add(effect, px, py, vx, vy, SPFX_LAYER_BACK);
- }
-}
-
-/* Init/exit */
-int commodity_load(void) {
- uint32_t bufsize;
- char* buf = ldata_read(COMMODITY_DATA, &bufsize);
-
- xmlNodePtr node;
- xmlDocPtr doc = xmlParseMemory(buf, bufsize);
-
- node = doc->xmlChildrenNode; /* Commoditys node. */
- if(strcmp((char*)node->name, XML_COMMODITY_ID)) {
- ERR("Malformed "COMMODITY_DATA
- " file: Missing root element '"XML_COMMODITY_ID"'");
- return -1;
- }
-
- node = node->xmlChildrenNode; /* First faction node. */
- if(node == NULL) {
- ERR("Malformed "COMMODITY_DATA" file: does not contain elements");
- return -1;
- }
-
- do {
- if(xml_isNode(node, XML_COMMODITY_TAG)) {
- /* Make room for commodity. */
- commodity_stack = realloc(commodity_stack,
- sizeof(Commodity)*(++commodity_nstack));
-
- /* Load commodity. */
- commodity_parse(&commodity_stack[commodity_nstack-1], node);
-
- /* See if it should get added to commodity list. */
- if(commodity_stack[commodity_nstack-1].price > 0.) {
- econ_nprices++;
- econ_comm = realloc(econ_comm, econ_nprices * sizeof(int));
- econ_comm[econ_nprices-1] = commodity_nstack-1;
- }
- }
- } while((node = node->next));
-
- xmlFreeDoc(doc);
- free(buf);
-
- DEBUG("Loaded %d commodit%s",
- commodity_nstack, (commodity_nstack==1) ? "y" : "ies");
-
- return 0;
-}
-
-void commodity_free(void) {
- int i;
- for(i = 0; i < commodity_nstack; i++)
- commodity_freeOne(&commodity_stack[i]);
- free(commodity_stack);
- commodity_stack = NULL;
- commodity_nstack = 0;
-}
-
-/**
- * @brief Get the price of a good on a planet in a system.
- * @param com Commodity to get price of.
- * @param sys System to get price of commodity.
- * @param p Planet to get price of commodity.
- * @return The price of the commodity.
- */
-unsigned int economy_getPrice(const Commodity* com,
- const StarSystem* sys, const Planet* p) {
- (void)p;
- int i, k;
- double price;
-
- /* Get position in stack. */
- k = com - commodity_stack;
-
- /* Find what commodity that is. */
- for(i = 0; i < econ_nprices; i++)
- if(econ_comm[i] == k)
- break;
-
- /* Check if found. */
- if(i >= econ_nprices) {
- WARN("Price for commodity '%s' not known.", com->name);
- return 0;
- }
-
- /* Calculate price. */
- price = (double)com->price;
- price *= sys->prices[i];
- return (unsigned int) price;
-}
-
-/**
- * @brief Calculates the resistance between two star systems.
- * @param A Star system to calculate the resistance between.
- * @param B Star system to calculate the resistance between.
- * @return Resistance between A and B.
- */
-static double econ_calcJumpR(StarSystem* A, StarSystem* B) {
- double R;
-
- /* Set to base to ensure price change. */
- R = ECON_BASE_RES;
-
- /* Modify based on system conditions. */
- R += (A->nebu_density + B->nebu_density) / 1000.; /* Density shouldn't affect much. */
- R += (A->nebu_volatility + B->nebu_volatility) / 100.; /* Volatility should. */
-
- /* Modify based on global faction. */
- if((A->faction != -1) && (B->faction != -1)) {
- if(areEnemies(A->faction, B->faction))
- R += ECON_FACTION_MOD * ECON_BASE_RES;
- else if(areAllies(A->faction, B->faction))
- R -= ECON_FACTION_MOD * ECON_BASE_RES;
- }
-
- /* @todo Modify based on fleets. */
- return R;
-}
-
-/**
- * @brief Calculates the intensity in a system node.
- *
- * @todo Make it time/item dependent.
- */
-static double econ_calcSysI(unsigned int dt, StarSystem* sys, int price) {
- (void)dt;
- (void)price;
- int i;
- double I;
- double prodfactor, p, pp;
- double ddt;
- Planet* planet;
-
- ddt = (double)(dt / LTIME_UNIT_LENGTH);
-
- /* Calculate production level. */
- p = 0.;
- for(i = 0; i < sys->nplanets; i++) {
- planet = sys->planets[i];
- if(planet_hasService(planet, PLANET_SERVICE_BASIC)) {
- /* Calculate production.
- *
- * We base off the current production.
- */
- prodfactor = planet->cur_prodfactor;
- /* Add a variability factor based on the gaussian distribution. */
- prodfactor += ECON_PROD_VAR * RNG_2SIGMA() * ddt;
- /* Add a tendency to return to the planets base production. */
- prodfactor -= ECON_PROD_VAR *
- (planet->cur_prodfactor - prodfactor)*ddt;
- /* Save for next iteration. */
- planet->cur_prodfactor = prodfactor;
- /* We base off the sqrt of the population otherwise it changes too fast. */
- p += prodfactor * sqrt(planet->population);
-
- /* Add it to the current system production. */
- p += pp;
- }
- }
-
- /* The intensity is basically the modified production. */
- I = p / ECON_PROD_MODIFIER;
-
- return I;
-}
-
-/**
- * @brief Create the admitance matrix.
- * @return 0 on suceess.
- */
-static int econ_createGMatrix(void) {
- int ret;
- int i, j;
- double R, Rsum;
- cs* M;
- StarSystem* sys;
-
- /* Create the matrix. */
- M = cs_spalloc(systems_nstack, systems_nstack, 1, 1, 1);
- if(M == NULL)
- ERR("Unable to create CSparse Matrix.");
-
- /* Fill the matrix. */
- for(i = 0; i < systems_nstack; i++) {
- sys = &systems_stack[i];
- Rsum = 0.;
-
- /* Set some values. */
- for(j = 0; j < sys->njumps; j++) {
- /* Get the resistance. */
- R = econ_calcJumpR(sys, &systems_stack[sys->jumps[j]]);
- R = 1./R; /* Must be inverted. */
- Rsum += R;
-
- /* Matrix is symetrical and non-diagonal is negative. */
- ret = cs_entry(M, i, sys->jumps[j], -R);
- if(ret != 1)
- WARN("Unable to enter CSparse Matrix Cell.");
- ret = cs_entry(M, sys->jumps[j], i, -R);
- if(ret != 1)
- WARN("Unable to enter CSparse Matrix Cell.");
- }
-
- /* Set the diagonal. */
- Rsum += 1./ECON_SELF_RES; /* We add a resistence for dampening. */
- cs_entry(M, i, i, Rsum);
- }
-
- /* Compress M matrix and put into G. */
- if(econ_G != NULL)
- cs_spfree(econ_G);
- econ_G = cs_compress(M);
- if(econ_G == NULL)
- ERR("Unable to create economy G Matrix.");
-
- /* Clean up. */
- cs_spfree(M);
-
- return 0;
-}
-
-/**
- * @brief Initializes the economy.
- * @return 0 on success.
- */
-int economy_init(void) {
- int i;
-
- /* Allocate price space. */
- for(i = 0; i < systems_nstack; i++) {
- if(systems_stack[i].prices != NULL)
- free(systems_stack[i].prices);
- systems_stack[i].prices = calloc(econ_nprices, sizeof(double));
- }
-
- /* Mark economy as initialized. */
- econ_initialized = 1;
-
- /* Refresh economy. */
- economy_refresh();
-
- return 0;
-}
-
-/**
- * @brief Regenerates the economy matrix. Should be used if the universe
- * changes in any permanent way.
- */
-int economy_refresh(void) {
- /* Economy must be initialized. */
- if(econ_initialized == 0)
- return 0;
-
- /* Create the resistance matrix. */
- if(econ_createGMatrix())
- return -1;
-
- /* Initialize the prices. */
- economy_update(0);
-
- return 0;
-}
-
-/**
- * @brief Updates the economy.
- * @param dt Deltatick in LTIME.
- */
-int economy_update(unsigned int dt) {
- int ret;
- int i, j;
- double *X;
- double scale, offset;
- /*double min, max;*/
-
- /* Create the vector to solve the system. */
- X = malloc(sizeof(double)*systems_nstack);
- if(X == NULL)
- return -1;
-
- /* Calculate the results for each price set. */
- for(j = 0; j < econ_nprices; j++) {
- /* First we must load the vector with intensities. */
- for(i = 0; i < systems_nstack; i++)
- X[i] = econ_calcSysI(dt, &systems_stack[i], j);
-
- /* Solve the system. */
- ret = cs_lsolve(econ_G, X);
- if(ret != 1)
- WARN("Failed to solve the Economy System.");
-
- /* Get the minimum and maximum to scale. */
- /*
- min = +HUGE_VALF;
- max = -HUGE_VALF;
- for(i = 0; i < systems_nstack; i++) {
- if(X[i] < min)
- min = X[i];
- if(X[i] > max)
- max = X[i];
- }
- scale = 1. / (max - min);
- offset = 0.5 - min * scale;
- */
-
- /*
- * I'm not sure I like the filtering of the results, but it would take
- * much more work to get a sane system working without the need of post
- * filtering.
- */
- scale = 1.;
- offset = 1.;
- for(i = 0; i < systems_nstack; i++) {
- systems_stack[i].prices[j] = X[i] * scale + offset;
- }
- }
-
- /* Clean up. */
- free(X);
- return 0;
-}
-
-/**
- * @brief Destroys the economy.
- */
-void economy_destroy(void) {
- int i;
-
- /* Clean up the prices in the systems stack. */
- for(i = 0; i < systems_nstack; i++) {
- if(systems_stack[i].prices != NULL) {
- free(systems_stack[i].prices);
- systems_stack[i].prices = NULL;
- }
- }
-
- /* Destroy the economy matrix. */
- if(econ_G != NULL) {
- cs_spfree(econ_G);
- econ_G = NULL;
- }
-
- /* Economy is now deinitialized. */
- econ_initialized = 0;
-}
-
diff --git a/src/economy.h b/src/economy.h
deleted file mode 100644
index 8b46d4a..0000000
--- a/src/economy.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-typedef struct Commodity_ {
- char* name; /**< Name of the commodity. */
- char* description; /**< Description of the commodity. */
- double price; /**< Base price of the commodity. */
-} Commodity;
-
-/* Commidity stuff. */
-Commodity* commodity_get(const char* name);
-int commodity_load(void);
-void commodity_free(void);
-
-/* Economy stuff. */
-int economy_init(void);
-int economy_update(unsigned int dt);
-int economy_refresh(void);
-void economy_destroy(void);
-
-/* Misc. */
-void credits2str(char* str, unsigned int credits, int decimals);
-void commodity_Jettison(int pilot, Commodity* com, int quantity);
-
diff --git a/src/escort.c b/src/escort.c
deleted file mode 100644
index fb1188e..0000000
--- a/src/escort.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * @file escorts.c
- *
- * @brief Handles the players escorts.
- */
-
-#include "lephisto.h"
-#include "log.h"
-#include "player.h"
-#include "llua.h"
-#include "lluadef.h"
-#include "llua_space.h"
-#include "escort.h"
-
-#define ESCORT_PREALLOC 8 /**< Number of escorts to automatically allocate first. */
-
-#define ESCORT_ATTACK 1 /**< Attack order. */
-#define ESCORT_HOLD 2 /**< Hold order. */
-#define ESCORT_RETURN 3 /**< Return to ship order. */
-#define ESCORT_CLEAR 4 /**< Clear orders. */
-
-/* Static. */
-static int escort_command(Pilot* parent, int cmd, int param);
-/* Extern. */
-extern void ai_setPilot(Pilot* p); /**< From ai.c. */
-
-/**
- * @fn int escort_create(unsigned int parent, char* ship,
- * Vec2* pos, Vec2* vel, int carried)
- *
- * @brief Create an escort.
- * @param parent Parent of the escort (who she's guarding).
- * @param ship Name of the ship escort should have.
- * @param pos Position to create escort at.
- * @param vel Velocity to create escort with.
- * @param carried Does escort come out of the parent?
- */
-int escort_create(unsigned int parent, char* ship,
- Vec2* pos, Vec2* vel, int carried) {
-
- Ship* s;
- Pilot* p, *pe;
- char buf[16];
- unsigned int e, f;
- double dir;
-
- /* Get important stuff. */
- p = pilot_get(parent);
- s = ship_get(ship);
- snprintf(buf, 16, "escort*%u", parent);
-
- /* Set flags. */
- f = PILOT_ESCORT;
- if(carried) f |= PILOT_CARRIED;
-
- /* Get the direction. */
- if(carried) dir = p->solid->dir;
- else dir = 0.;
-
- /* Create the pilot. */
- e = pilot_create(s, NULL, p->faction, buf, dir, pos, vel, f);
- pe = pilot_get(e);
- pe->parent = parent;
-
- /* Add to escort list. */
- p->nescorts++;
- if(p->nescorts == 1)
- p->escorts = malloc(sizeof(unsigned int) * ESCORT_PREALLOC);
- else if(p->nescorts > ESCORT_PREALLOC)
- p->escorts = realloc(p->escorts, sizeof(unsigned int) * p->nescorts);
- p->escorts[p->nescorts-1] = e;
-
- return 0;
-}
-
-/**
- * @fn static int escort_command(Pilot* parent, int cmd, int param)
- *
- * @brief Run an escort command on all of a pilots escorts.
- * @param parent Pilot who is giving orders.
- * @param cmd Order to give.
- * @param param Parameter for order.
- * @return 0 on success, 1 if no orders given.
- */
-static int escort_command(Pilot* parent, int cmd, int param) {
- int i, n;
- lua_State* L;
- Pilot* e;
- char* buf;
-
- if(parent->nescorts == 0)
- return 1;
-
- n = 0;
- for(i = 0; i < parent->nescorts; i++) {
- e = pilot_get(parent->escorts[i]);
- if(e == NULL) /* Most likely died. */
- continue;
-
- /* Check if command makes sense. */
- if((cmd == ESCORT_RETURN) && !pilot_isFlag(e, PILOT_CARRIED))
- continue;
-
- n++; /* Amount of escorts left. */
-
- /* Prepare ai. */
- ai_setPilot(e);
-
- /* Set up stack. */
- L = e->ai->L;
- switch(cmd) {
- case ESCORT_ATTACK:
- buf = "e_attack";
- break;
- case ESCORT_HOLD:
- buf = "e_hold";
- break;
- case ESCORT_RETURN:
- buf = "e_return";
- break;
- case ESCORT_CLEAR:
- buf = "e_clear";
- break;
- }
- lua_getglobal(L, buf);
- if(param >= 0)
- lua_pushnumber(L, param);
-
- /* Run command. */
- if(lua_pcall(L, (param >= 0) ? 1 : 0, 0, 0))
- WARN("Pilot '%s' ai -> '%s' : %s", e->name,
- buf, lua_tostring(L, -1));
- }
- return !n;
-}
-
-/**
- * @fn int escorts_attack(Pilot* parent)
- *
- * @brief HAve a pilot order it's escorts to attack its target.
- * @param parent Pilot giving the order.
- */
-int escorts_attack(Pilot* parent) {
- int ret;
- Pilot* t;
-
- ret = 1;
- if(parent->target != parent->id)
- ret = escort_command(parent, ESCORT_ATTACK, parent->target);
- if((ret == 0) && (parent == player)) {
- t = pilot_get(parent->target);
- if(t != NULL)
- player_message("Escorts: Attacking %s.", t->name);
- }
- return ret;
-}
-
-/**
- * @fn int escorts_hold(Pilot* parent)
- *
- * @brief Have a pilot order its escorts to hold position.
- * @param parent Pilot giving the order.
- */
-int escorts_hold(Pilot* parent) {
- int ret;
- ret = escort_command(parent, ESCORT_HOLD, -1);
- if((ret == 0) && (parent == player))
- player_message("Escorts: Holding position.");
- return ret;
-}
-
-/**
- * @fn int escorts_return(Pilot* parent)
- *
- * @brief Have a pilot order its escorts to dock.
- * @param parent Pilot giving the order.
- */
-int escorts_return(Pilot* parent) {
- int ret;
- ret = escort_command(parent, ESCORT_RETURN, -1);
- if((ret == 0) && (parent == player))
- player_message("Escorts: Returning to ship.");
- return ret;
-}
-
-/**
- * @fn int escorts_clear(Pilot* parent)
- *
- * @brief Have a pilot order its escorts to clear orders.
- * @param parent Pilot giving the order.
- */
-int escorts_clear(Pilot* parent) {
- int ret;
- ret = escort_command(parent, ESCORT_CLEAR, -1);
- if((ret == 0) && (parent == player))
- player_message("Escorts: Clearing orders.");
- return ret;
-}
-
diff --git a/src/escort.h b/src/escort.h
deleted file mode 100644
index 1b379b1..0000000
--- a/src/escort.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-#include "physics.h"
-#include "pilot.h"
-
-int escort_create(unsigned int parent, char* ship,
- Vec2* pos, Vec2* vel, int carried);
-
-/* Keybind commands. */
-int escorts_attack(Pilot* parent);
-int escorts_hold(Pilot* parent);
-int escorts_return(Pilot* parent);
-int escorts_clear(Pilot* parent);
-
diff --git a/src/explosion.c b/src/explosion.c
deleted file mode 100644
index 40f9290..0000000
--- a/src/explosion.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * @file explosion.c
- */
-#include "lephisto.h"
-#include "log.h"
-#include "pilot.h"
-#include "weapon.h"
-#include "spfx.h"
-#include "rng.h"
-#include "explosion.h"
-
-/**
- * @brief Does explosion in a radius (damage and graphics).
- * @param x X position of explosion center.
- * @param y Y position of explosion center.
- * @param vx X velocity of explosion center.
- * @param vy Y velocity of explosion center.
- * @param radius Radius of the explosion.
- * @param dtype Damage type.
- * @param damage Damage amount.
- * @param parent Parent of the explosion, 0 is none.
- * @param mode Defines the explosion behaviour.
- */
-void expl_explode(double x, double y, double vx, double vy,
- double radius, DamageType dtype, double damage,
- unsigned int parent, int mode) {
-
- int i, n;
- double a, d;
- double area;
- double ex, ey;
- double layer;
- int efx;
- int exp_s, exp_m, exp_l;
-
- /* Standard stuff. */
- exp_s = spfx_get("ExpS");
- exp_m = spfx_get("ExpM");
- exp_l = spfx_get("ExpL");
- layer = SPFX_LAYER_FRONT;
-
- /* Number of explosions. */
- area = M_PI * pow2(radius);
- n = (int)(area / 100.);
-
- /* Create explosions. */
- for(i = 0; i < n; i++) {
- /* Get position. */
- a = RNGF()*360.;
- d = RNGF()*(radius-5.) + 5.;
- ex = d*cos(a);
- ey = d*sin(a);
-
- /* Create explosion. */
- efx = (RNG(0,2)==0) ? exp_m : exp_s;
- spfx_add(efx, x+ex, y+ey, vx, vy, layer);
- }
-
- /* Final explosion. */
- spfx_add(exp_l, x, y, vx, vy, layer);
-
- /* Run the damage. */
- if(damage > 0.)
- expl_explodeDamage(x, y, radius, dtype, damage, parent, mode);
-}
-
-/**
- * @fn
- *
- * @brief
- */
-void expl_explodeDamage(double x, double y, double radius,
- DamageType dtype, double damage,
- unsigned int parent, int mode) {
-
- /* Explosion affects ships. */
- if(mode & EXPL_MODE_SHIP)
- pilot_explode(x, y, radius, dtype, damage, parent);
-
- /* Explosion affects missiles and bolts. */
- if((mode & EXPL_MODE_MISSILE) && (mode & EXPL_MODE_BOLT))
- weapon_explode(x, y, radius, dtype, damage, parent, mode);
-
- /* Explosion affects missiles. */
- else if(mode & EXPL_MODE_MISSILE)
- weapon_explode(x, y, radius, dtype, damage, parent, mode);
-
- /* Explosion affects bolts. */
- else if(mode & EXPL_MODE_BOLT)
- weapon_explode(x, y, radius, dtype, damage, parent, mode);
-}
-
diff --git a/src/explosion.h b/src/explosion.h
deleted file mode 100644
index 6e5976a..0000000
--- a/src/explosion.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include "outfit.h"
-
-#define EXPL_MODE_SHIP (1<<0) /**< Affects ships. */
-#define EXPL_MODE_MISSILE (1<<1) /**< Affects missiles. */
-#define EXPL_MODE_BOLT (1<<2) /**< Affects bots. */
-
-void expl_explode(double x, double y, double vx, double vy,
- double radius, DamageType dtype, double damage,
- unsigned int parent, int mode);
-
-void expl_explodeDamage(double x, double y, double radius,
- DamageType dtype, double damage,
- unsigned int parent, int mode);
-
diff --git a/src/faction.c b/src/faction.c
deleted file mode 100644
index 236f2db..0000000
--- a/src/faction.c
+++ /dev/null
@@ -1,737 +0,0 @@
-/**
- * @file faction.c
- *
- * @brief Handle the Lephisto factions.
- */
-
-#include
-#include
-
-#include "opengl.h"
-#include "lephisto.h"
-#include "log.h"
-#include "ldata.h"
-#include "lxml.h"
-#include "rng.h"
-#include "faction.h"
-
-#define XML_FACTION_ID "Factions" /* XML section id. */
-#define XML_FACTION_TAG "faction"
-
-#define FACTION_DATA "../dat/faction.xml" /**< Faction xml file. */
-#define FACTION_LOGO_PATH "../gfx/logo/" /**< Path to logo gfx. */
-
-#define PLAYER_ALLY 70. /**< Above this, player is considered ally. */
-
-#define CHUNK_SIZE 32 /**< Size of chunk for allocation. */
-
-#define FACTION_STATIC (1<<0) /**< Faction doesn't change standing with player. */
-
-#define faction_setFlag(fa, f) ((fa)->flags |= (f))
-#define faction_isFlag(fa, f) ((fa)->flags & (f))
-
-/**
- * @struct Faction.
- *
- * @brief Represents a faction.
- */
-typedef struct Faction_ {
- char* name; /**< Normal name. */
- char* longname; /**< Long name. */
-
- /* Graphics. */
- glTexture* logo_small; /**< Small logo. */
-
- /* Enemies. */
- int* enemies; /**< Enemies by ID of the faction. */
- int nenemies; /**< Number of enemies. */
-
- /* Allies. */
- int* allies; /**< Allies by ID of the faction. */
- int nallies; /**< Number of allies. */
-
- double player_def; /**< Default player standing. */
- double player; /**< Standing with player - from -100 to 100. */
-
- unsigned int flags; /**< Flags affecting the faction. */
-} Faction;
-
-static Faction* faction_stack = NULL; /**< Faction stack. */
-static int faction_nstack = 0; /**< Number of factions in the faction stack. */
-
-/* Static. */
-static int faction_isFaction(int f);
-static void faction_sanitizePlayer(Faction* faction);
-static int faction_parse(Faction* tmp, xmlNodePtr parent);
-static void faction_parseSocial(xmlNodePtr parent);
-/* Extern. */
-int pfaction_save(xmlTextWriterPtr writer);
-int pfaction_load(xmlNodePtr parent);
-
-/**
- * @brief Get a faction ID by name.
- * @param name Name of the faction to seek.
- * @return ID of the faction.
- */
-int faction_get(const char* name) {
- int i;
- for(i = 0; i < faction_nstack; i++)
- if(strcmp(faction_stack[i].name, name)==0)
- break;
-
- if(i != faction_nstack)
- return i;
-
- WARN("Faction '%s' not found in stack.", name);
- return -1;
-}
-
-/**
- * @fn char* faction_name(int f)
- *
- * @brief Get a factions short name.
- * @param f Faction to get the name of.
- * @return Name of the faction.
- */
-char* faction_name(int f) {
- if((f < 0) || (f >= faction_nstack)) {
- WARN("Faction id '%d' is invalid.", f);
- return NULL;
- }
- /* Don't want player to see her escorts as "Player" faction. */
- if(f == FACTION_PLAYER)
- return "Escort";
- return faction_stack[f].name;
-}
-
-/**
- * @fn char* faction_longname(int f)
- *
- * @brief Get the factions long name (formal).
- * @param f Faction to get the name of.
- * @return The factions long name.
- */
-char* faction_longname(int f) {
- if((f < 0) || (f >= faction_nstack)) {
- WARN("Faction id '%d' is invalid.", f);
- return NULL;
- }
- if(faction_stack[f].longname != NULL)
- return faction_stack[f].longname;
- return faction_stack[f].name;
-}
-
-/**
- * @fn glTexture* faction_logoSmall(int f)
- *
- * @brief Get the factions small logo.
- * @param f Faction to get the logo of.
- * @return The factions small logo image.
- */
-glTexture* faction_logoSmall(int f) {
- if((f < 0) || (f >= faction_nstack)) {
- WARN("Faction id '%d' is invalid.", f);
- return NULL;
- }
- return faction_stack[f].logo_small;
-}
-
-/**
- * @brief Get the list of enemies of a faction.
- * @param f faction to get enemies of.
- * @param[out] Number of enemies.
- * @return The enemies of the faction.
- */
-int* faction_getEnemies(int f, int* n) {
- if((f < 0) || (f >= faction_nstack)) {
- WARN("Faction id '%d' is invalid.", f);
- return NULL;
- }
- *n = faction_stack[f].nenemies;
- return faction_stack[f].enemies;
-}
-
-/**
- * @brief Get the list of allies of a faction.
- * @param f Faction to get allies of.
- * @param[out] Number of allies.
- * @return The allies of the faction.
- */
-int* faction_getAllies(int f, int* n) {
- if((f < 0) || (f >= faction_nstack)) {
- WARN("Faction id '%d' is invalid.", f);
- return NULL;
- }
- *n = faction_stack[f].nallies;
- return faction_stack[f].allies;
-}
-
-/**
- * @fn static void faction_sanitizePlayer(Faction* faction)
- *
- * @brief Sanitizes player faction standing.
- * @param faction Faction to sanitize.
- */
-static void faction_sanitizePlayer(Faction* faction) {
- if(faction->player > 100.)
- faction->player = 100.;
- else if(faction->player < -100.)
- faction->player = -100.;
-}
-
-/**
- * @fn void faction_modPlayer(int f, double mod)
- *
- * @brief Modifies the players standing with a faction.
- *
- * Affects enemies and allies too.
- * @param f Faction to modify players standing.
- * @param mod Modifier to modify by.
- *
- * @sa faction_modPlayerRaw
- */
-void faction_modPlayer(int f, double mod) {
- int i;
- Faction* faction, *ally, *enemy;
- double m;
-
- if(!faction_isFaction(f)) {
- WARN("%d is an invalid faction.", f);
- return;
- }
-
- faction = &faction_stack[f];
-
- /* Make sure it's not static. */
- if(faction_isFlag(faction, FACTION_STATIC))
- return;
-
- /* Faction in question gets direct increment. */
- faction->player += mod;
- faction_sanitizePlayer(faction);
-
- /* Now mod allies to a lesser degree. */
- for(i = 0; i < faction->nallies; i++) {
- ally = &faction_stack[faction->allies[i]];
-
- /* Enemies are made faster. */
- m = RNGF();
- if(mod > 0.)
- m *= 0.75;
-
- ally->player += m*mod;
- faction_sanitizePlayer(ally);
- }
-
- /* Now mod enemies. */
- for(i = 0; i < faction->nenemies; i++) {
- enemy = &faction_stack[faction->enemies[i]];
-
- /* Enemies are made faster. */
- m = RNGF();
- if(mod < 0.)
- m *= 0.75;
-
- enemy->player -= m*mod;
- faction_sanitizePlayer(enemy);
- }
-}
-
-/**
- * @fn void faction_modPlayerRaw(int f, double mod)
- *
- * @brief Modifies the players standing without affecting others.
- * @param f Faction whose standing to modify.
- * @param mod Amount to modify standing by.
- *
- * @sa faction_modPlayer
- */
-void faction_modPlayerRaw(int f, double mod) {
- Faction* faction;
-
- if(!faction_isFaction(f)) {
- WARN("%d is an invalid faction.", f);
- return;
- }
-
- faction = &faction_stack[f];
-
- /* Make sure it's not static. */
- if(faction_isFlag(faction, FACTION_STATIC))
- return;
-
- faction->player += mod;
- faction_sanitizePlayer(faction);
-}
-
-/**
- * @fn double faction_getPlayer(int f)
- *
- * @brief Get the players standing with a faction.
- * @param f Faction to get standing from.
- * @return The standing the player has with the faction.
- */
-double faction_getPlayer(int f) {
- if(faction_isFaction(f)) {
- return faction_stack[f].player;
- } else {
- WARN("%d is an invalid faction.", f);
- return -1000;
- }
-}
-
-/**
- * @fn glColour* faction_getColour(int f)
- *
- * @brief Get the colour of the faction basewd on its standing with the player.
- *
- * Used to unify the colour checks all over.
- * @param f Faction to get the colour of based on players standing.
- * @return Pointer to the colour.
- */
-glColour* faction_getColour(int f) {
- if(f < 0) return &cInert;
- else if(areAllies(FACTION_PLAYER, f)) return &cFriend;
- else if(areEnemies(FACTION_PLAYER, f)) return &cHostile;
- else return &cNeutral;
-}
-
-/**
- * @fn char* faction_getStanding(double mod)
- *
- * @brief Get the players standing in human readable form.
- * @param mod Players standing.
- * @return Human readable players standing.
- */
-
-#define STANDING(m, s) if(mod >= m) return s; /**< Hack to get standings easily. */
-char* faction_getStanding(double mod) {
- STANDING( 90., "Here");
- STANDING( 70., "Admired");
- STANDING( 50., "Great");
- STANDING( 30., "Good");
- STANDING( 0., "Decent");
- STANDING(-15., "Wanted");
- STANDING(-30., "Outlaw");
- STANDING(-50., "Criminal");
- return "Enemy";
-
-}
-#undef STANDING
-
-/**
- * @brief Get the broad faction standing.
- * @param mod Players standing.
- * @return Human readable broad players standing.
- */
-char* faction_getStandingBroad(double mod) {
- if(mod > PLAYER_ALLY) return "Friendly";
- else if(mod > 0.) return "Neutral";
- return "Hostile";
-}
-
-/**
- * @fn int areEnemies(int a, int b)
- *
- * @brief Check whether two factions are enemies.
- * @param a Faction A.
- * @param b Faction B.
- * @return 1 if A and B are enemies, 0 otherwise.
- */
-int areEnemies(int a, int b) {
- Faction* fa, *fb;
- int i = 0;
-
- if(a == b) return 0; /* Luckily our factions aren't masochistic. */
-
- /* Player handled seperately. */
- if(a == FACTION_PLAYER) {
- if(faction_isFaction(b)) {
- if(faction_stack[b].player < 0)
- return 1;
- else return 0;
- } else {
- WARN("areEnemies: %d is an invalid faction.", b);
- return 0;
- }
- }
- if(b == FACTION_PLAYER) {
- if(faction_isFaction(a)) {
- if(faction_stack[a].player < 0)
- return 1;
- else return 0;
- } else {
- WARN("areEnemies: %d is an invalid faction.", a);
- return 0;
- }
- }
-
- /* Handle a. */
- if(faction_isFaction(a)) fa = &faction_stack[a];
- else {
- /* a isn't valid. */
- WARN("areEnemies: %d is an invalid faction.", a);
- return 0;
- }
-
- /* Handle b. */
- if(faction_isFaction(b)) fb = &faction_stack[b];
- else {
- /* b isn't valid. */
- WARN("areEnemies: %d is an invalid faction.", b);
- return 0;
- }
-
- if(fa && fb) {
- /* Both are factions. */
- for(i = 0; i < fa->nenemies; i++)
- if(fa->enemies[i] == b)
- return 1;
- for(i = 0; i < fb->nenemies; i++)
- if(fb->enemies[i] == a)
- return 1;
- }
- return 0;
-}
-
-/**
- * @fn int areAllies(int a, int b)
- *
- * @brief Check whether two factions are allies or not.
- * @param a Faction A.
- * @param b Faction B.
- * @return 1 if A and B are allies, 0 otherwise.
- */
-int areAllies(int a, int b) {
- Faction* fa, *fb;
- int i;
-
- /* If they are the same, they must be allies. */
- if(a == b) return 1;
-
- /* We assume player becomes allies with high rating. */
- if(a == FACTION_PLAYER) {
- if(faction_isFaction(b)) {
- if(faction_stack[b].player > PLAYER_ALLY) return 1;
- else return 0;
- } else {
- WARN("%d is an invalid faction.", b);
- return 0;
- }
- }
- if(b == FACTION_PLAYER) {
- if(faction_isFaction(a)) {
- if(faction_stack[a].player > PLAYER_ALLY) return 1;
- else return 0;
- } else {
- WARN("%d is an invalid faction.", a);
- return 0;
- }
- }
-
- /* D'aww. Player has no allies. */
- if((a == FACTION_PLAYER) || (b == FACTION_PLAYER))
- return 0;
-
- /* Handle a. */
- if(faction_isFaction(a)) fa = &faction_stack[a];
- else {
- /* b isn't valid. */
- WARN("%d is an invalid faction.", a);
- return 0;
- }
-
- /* Handle b. */
- if(faction_isFaction(b)) fb = &faction_stack[b];
- else {
- /* b isn't valid. */
- WARN("%d is an invalid faction.", b);
- return 0;
- }
-
- if(fa && fb) {
- /* Both are factions. */
- for(i = 0; i < fa->nallies; i++)
- if(fa->allies[i] == b)
- return 1;
-
- for(i = 0; i < fb->nallies; i++)
- if(fb->allies[i] == a)
- return 1;
- }
- return 0;
-}
-
-/**
- * @fn static int faction_isFaction(int f)
- *
- * @brief Check whether or not a faction is valid.
- * @param f Faction to check for validity.
- * @return 1 if faction is valid, 0 otherwise.
- */
-static int faction_isFaction(int f) {
- if((f < 0) || (f >= faction_nstack))
- return 0;
- return 1;
-}
-
-/**
- * @brief Parses a single faction, but doesn't set the allies/enemies bit.
- * @param tmp Faction to load data into.
- * @param parent Parent node to extract faction from.
- * @return Faction created from parent node.
- */
-static int faction_parse(Faction* tmp, xmlNodePtr parent) {
- xmlNodePtr node;
- int player;
- char buf[PATH_MAX];
-
- /* Clear memory. */
- memset(tmp, 0, sizeof(Faction));
-
- tmp->name = xml_nodeProp(parent, "name");
- if(tmp->name == NULL)
- WARN("Faction from "FACTION_DATA" has invalid or no name");
-
- player = 0;
- node = parent->xmlChildrenNode;
- do {
- /* Can be 0 or negative, so we have to take that into account. */
- if(xml_isNode(node, "player")) {
- tmp->player_def = xml_getFloat(node);
- player = 1;
- continue;
- }
-
- xmlr_strd(node, "longname", tmp->longname);
-
- if(xml_isNode(node, "logo")) {
- snprintf(buf, PATH_MAX, FACTION_LOGO_PATH"%s_small.png", xml_get(node));
- tmp->logo_small = gl_newImage(buf, 0);
- continue;
- }
-
- if(xml_isNode(node, "static")) {
- faction_setFlag(tmp, FACTION_STATIC);
- continue;
- }
- } while(xml_nextNode(node));
-
- if(player == 0) WARN("Faction '%s' missing player tag", tmp->name);
-
- return 0;
-}
-
-/* Parse the social tidbits: Allies and enemies. */
-static void faction_parseSocial(xmlNodePtr parent) {
- xmlNodePtr node, cur;
- char* buf;
- Faction* base;
- int mod;
- int mem;
-
- buf = xml_nodeProp(parent, "name");
- base = &faction_stack[faction_get(buf)];
- free(buf);
-
- node = parent->xmlChildrenNode;
- do {
- if(xml_isNode(node, "allies")) {
- cur = node->xmlChildrenNode;
-
- mem = 0;
- do {
- if(xml_isNode(cur, "ally")) {
- mod = faction_get(xml_get(cur));
- base->nallies++;
- if(base->nallies > mem) {
- mem += CHUNK_SIZE;
- base->allies = realloc(base->allies, sizeof(int)*mem);
- }
- base->allies[base->nallies-1] = mod;
- }
- } while(xml_nextNode(cur));
- if(base->nallies > 0)
- base->allies = realloc(base->allies, sizeof(int)*base->nallies);
- }
-
- /* Grab the enemies. */
- if(xml_isNode(node, "enemies")) {
- cur = node->xmlChildrenNode;
-
- mem = 0;
- do {
- if(xml_isNode(cur, "enemy")) {
- mod = faction_get(xml_get(cur));
- base->nenemies++;
- if(base->nenemies > mem) {
- mem += CHUNK_SIZE;
- base->enemies = realloc(base->enemies, sizeof(int)*mem);
- }
- base->enemies[base->nenemies-1] = mod;
- }
- } while(xml_nextNode(cur));
- if(base->nenemies > 0)
- base->enemies = realloc(base->enemies, sizeof(int)*base->nenemies);
- }
- } while(xml_nextNode(node));
-}
-
-/**
- * @fn void factions_reset(void)
- *
- * @brief Reset the players standing with the factions to default.
- */
-void factions_reset(void) {
- int i;
- for(i = 0; i < faction_nstack; i++)
- faction_stack[i].player = faction_stack[i].player_def;
-}
-
-/**
- * @fn int factions_load(void)
- *
- * @brief Loads up all the factions from the data file.
- * @return 0 on success.
- */
-int factions_load(void) {
- int mem;
- uint32_t bufsize;
- char* buf = ldata_read(FACTION_DATA, &bufsize);
-
- xmlNodePtr factions, node;
- xmlDocPtr doc = xmlParseMemory(buf, bufsize);
-
- node = doc->xmlChildrenNode; /* Faction node. */
- if(!xml_isNode(node, XML_FACTION_ID)) {
- ERR("Malformed "FACTION_DATA" file: missing root element '"XML_FACTION_ID"'");
- return -1;
- }
-
- factions = node->xmlChildrenNode; /* First faction node. */
- if(factions == NULL) {
- ERR("Malformed "FACTION_DATA" file: does not contain elements");
- return -1;
- }
-
- /* Player faction is hardcoded. */
- faction_stack = malloc(sizeof(Faction));
- memset(faction_stack, 0, sizeof(Faction));
- faction_stack[0].name = strdup("Player");
- faction_nstack++;
-
- /* First pass. */
- node = factions;
- mem = 0;
- do {
- if(xml_isNode(node, XML_FACTION_TAG)) {
- /* See if stack needs to grow. */
- faction_nstack++;
- if(faction_nstack > mem) {
- mem += CHUNK_SIZE;
- faction_stack = realloc(faction_stack, sizeof(Faction)*mem);
- }
-
- /* Load faction. */
- faction_parse(&faction_stack[faction_nstack-1], node);
- }
- } while(xml_nextNode(node));
-
- /* Shrink stack to minimum size. */
- faction_stack = realloc(faction_stack, sizeof(Faction)*faction_nstack);
-
- /* Second pass - Set allies and enemies. */
- node = factions;
- do {
- if (xml_isNode(node,XML_FACTION_TAG))
- faction_parseSocial(node);
- } while (xml_nextNode(node));
-
- xmlFreeDoc(doc);
- free(buf);
-
- DEBUG("Loaded %d Faction%s", faction_nstack, (faction_nstack==1) ?"": "s");
-
- return 0;
-}
-
-/**
- * @fn void factions_free(void)
- *
- * @brief Frees the factions.
- */
-void factions_free(void) {
- int i;
-
- /* Free factions. */
- for(i = 0; i < faction_nstack; i++) {
- free(faction_stack[i].name);
- if(faction_stack[i].longname != NULL) free(faction_stack[i].longname);
- if(faction_stack[i].logo_small != NULL) gl_freeTexture(faction_stack[i].logo_small);
- if(faction_stack[i].nallies > 0) free(faction_stack[i].allies);
- if(faction_stack[i].nenemies > 0) free(faction_stack[i].enemies);
- }
- free(faction_stack);
- faction_stack = NULL;
- faction_nstack = 0;
-}
-
-/**
- * @fn int pfaction_save(xmlTextWriterPtr writer)
- *
- * @brief Save players standings with the factions.
- * @param writer The XML writer to use.
- * @return 0 on success.
- */
-int pfaction_save(xmlTextWriterPtr writer) {
- int i;
-
- xmlw_startElem(writer, "factions");
-
- /* Player is faction 0. */
- for(i = 1; i < faction_nstack; i++) {
- xmlw_startElem(writer, "faction");
-
- xmlw_attr(writer, "name", "%s", faction_stack[i].name);
- xmlw_str(writer, "%f", faction_stack[i].player);
-
- xmlw_endElem(writer); /* Faction. */
- }
-
- xmlw_endElem(writer); /* Faction. */
-
- return 0;
-}
-
-/**
- * @fn int pfaction_load(xmlNodePtr parent)
- *
- * @brief Load up the players faction standings.
- * @param parent Parent xml node to read from.
- * @return 0 on success.
- */
-int pfaction_load(xmlNodePtr parent) {
- xmlNodePtr node, cur;
- char* str;
- int faction;
-
- node = parent->xmlChildrenNode;
-
- do {
- if(xml_isNode(node, "factions")) {
- cur = node->xmlChildrenNode;
- do {
- if(xml_isNode(cur, "factions")) {
- xmlr_attr(cur, "name", str);
- faction = faction_get(str);
- if(faction != -1) /* Faction is valid. */
- faction_stack[faction].player = xml_getFloat(cur);
- free(str);
- }
- } while(xml_nextNode(cur));
- }
- } while(xml_nextNode(node));
-
- return 0;
-}
-
diff --git a/src/faction.h b/src/faction.h
deleted file mode 100644
index 60aa885..0000000
--- a/src/faction.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-#include "opengl.h"
-#include "colour.h"
-
-#define FACTION_PLAYER 0
-
-/* Get stuff. */
-int faction_get(const char* name);
-char* faction_name(int f);
-char* faction_longname(int f);
-glTexture* faction_logoSmall(int f);
-int* faction_getEnemies(int f, int* n);
-int* faction_getAllies(int f, int* n);
-
-/* Player stuff. */
-void faction_modPlayer(int f, double mod);
-void faction_modPlayerRaw(int f, double mod);
-double faction_getPlayer(int f);
-char* faction_getStanding(double mod);
-char* faction_getStandingBroad(double mod);
-glColour* faction_getColour(int f);
-
-/* Works with only factions. */
-int areEnemies(int a, int b);
-int areAllies(int a, int b);
-
-/* Load/Free. */
-int factions_load(void);
-void factions_free(void);
-void factions_reset(void);
-
diff --git a/src/fleet.c b/src/fleet.c
deleted file mode 100644
index 6fa0f97..0000000
--- a/src/fleet.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/**
- * @file fleet.c
- *
- * @brief Handles the fleet stuff.
- */
-
-#include "fleet.h"
-
-#include
-#include
-#include
-#include
-
-#include "lxml.h"
-#include "lephisto.h"
-#include "log.h"
-#include "pilot.h"
-#include "ldata.h"
-
-#define FLEET_DATA "../dat/fleet.xml" /**< Where to find fleet data. */
-#define FLEETGROUP_DATA "../dat/fleetgroup.xml" /**< Where to find fleetgroup. */
-
-#define CHUNK_SIZE 32 /**< Size to allocate memory by. */
-
-/* Stack of fleets. */
-static Fleet* fleet_stack = NULL; /**< Fleet stack. */
-static int nfleets = 0; /**< Number of fleets. */
-
-/* Stack of fleetgroups. */
-static FleetGroup* fleetgroup_stack = NULL; /**< FleetGroup stack. */
-static int nfleetgroups = 0; /**< Number of fleetgroups. */
-
-static int fleet_parse(Fleet* tmp, const xmlNodePtr parent);
-static int fleet_parseGroup(FleetGroup* fltgrp, xmlNodePtr parent);
-
-/**
- * @brief Grabs a fleet out of the stack.
- * @param name Name of the fleet to match.
- * @return The fleet mactching name or NULL if not found.
- */
-Fleet* fleet_get(const char* name) {
- int i;
-
- for(i = 0; i < nfleets; i++)
- if(strcmp(fleet_stack[i].name, name)==0)
- return &fleet_stack[i];
-
- return NULL;
-}
-
-/**
- * @brief Grab a fleetgroup out of the stack.
- * @param name Name of the fleetgroup to match.
- * @return The fleetgroup matching name or NULL if not found.
- */
-FleetGroup* fleet_getGroup(const char* name) {
- int i;
-
- for(i = 0; i < nfleetgroups; i++)
- if(strcmp(fleetgroup_stack[i].name, name)==0)
- return &fleetgroup_stack[i];
-
- return NULL;
-}
-
-/**
- * @brief Parses the fleet node.
- * @param tmp Fleet to load.
- * @param parent Parent xml node of the fleet in question.
- * @return A newly allocated fleet loaded with data in parent node.
- */
-static int fleet_parse(Fleet* tmp, const xmlNodePtr parent) {
- xmlNodePtr cur, node;
- FleetPilot* pilot;
- char* c;
- int mem;
- node = parent->xmlChildrenNode;
-
- /* Sane defaults and clean up. */
- memset(tmp, 0, sizeof(Fleet));
- tmp->faction = -1;
-
- tmp->name = (char*)xmlGetProp(parent, (xmlChar*)"name"); /* Already mallocs. */
- if(tmp->name == NULL) WARN("Fleet in "FLEET_DATA" has invalid or no name");
-
- do { /* Load all the data. */
- if(xml_isNode(node, "faction"))
- tmp->faction = faction_get(xml_get(node));
- else if(xml_isNode(node, "ai"))
- tmp->ai = xml_getStrd(node);
- else if(xml_isNode(node, "pilots")) {
- cur = node->children;
- mem = 0;
- do {
- if(xml_isNode(cur, "pilot")) {
- /* See if must grow. */
- tmp->npilots++;
- if(tmp->npilots > mem) {
- mem += CHUNK_SIZE;
- tmp->pilots = realloc(tmp->pilots, mem * sizeof(FleetPilot));
- }
- pilot = &tmp->pilots[tmp->npilots-1];
-
- /* Clear memory. */
- memset(pilot, 0, sizeof(FleetPilot));
-
- /* Check for name override. */
- xmlr_attr(cur, "name", c);
- pilot->name = c; /* No need to free since it will have later. */
-
- /* Check for ai override. */
- xmlr_attr(cur, "ai", pilot->ai);
-
- /* Load pilots ship. */
- pilot->ship = ship_get(xml_get(cur));
- if(pilot->ship == NULL)
- WARN("Pilot %s in Fleet %s has null ship", pilot->name, tmp->name);
-
- /* Load chance. */
- xmlr_attr(cur, "chance", c);
- pilot->chance = atoi(c);
- if(pilot->chance == 0)
- WARN("Pilot %s in Fleet %s has 0%% chance of appearing",
- pilot->name, tmp->name);
-
- if(c != NULL)
- free(c); /* Free the external malloc. */
- }
- } while(xml_nextNode(cur));
-
- /* Resize to minimum. */
- tmp->pilots = realloc(tmp->pilots, sizeof(FleetPilot)*tmp->npilots);
- }
- } while(xml_nextNode(node));
-
-#define MELEMENT(o,s) \
- if(o) WARN("Fleet '%s' missing '"s"' element", tmp->name)
- /**< Hack to check for missing fields. */
- MELEMENT(tmp->ai == NULL, "ai");
- MELEMENT(tmp->faction == -1, "faction");
- MELEMENT(tmp->pilots == NULL, "pilots");
-#undef MELEMENT
-
- return 0;
-}
-
-/**
- * @brief Loads all the fleets.
- * @return 0 on success.
- */
-static int fleet_loadFleets(void) {
- int mem;
- uint32_t bufsize;
-
- char* buf;
- xmlNodePtr node;
-
- xmlDocPtr doc;
-
- /* Load the data. */
- buf = ldata_read(FLEET_DATA, &bufsize);
- doc = xmlParseMemory(buf, bufsize);
-
- node = doc->xmlChildrenNode; /* Fleets node. */
- if(strcmp((char*)node->name, "Fleets")) {
- ERR("Malformed "FLEET_DATA" file: missing root element 'Fleets'.");
- return -1;
- }
-
- node = node->xmlChildrenNode; /* First fleet node. */
- if(node == NULL) {
- ERR("Malformed "FLEET_DATA" file: does not contain elements.");
- return -1;
- }
-
- mem = 0;
- do {
- if(xml_isNode(node, "fleet")) {
- /* See if memory must grow. */
- nfleets++;
- if(nfleets > mem) {
- mem += CHUNK_SIZE;
- fleet_stack = realloc(fleet_stack, sizeof(Fleet) * mem);
- }
-
- /* Load the fleet. */
- fleet_parse(&fleet_stack[nfleets-1], node);
- }
- } while(xml_nextNode(node));
-
- /* Shrink to minimum. */
- fleet_stack = realloc(fleet_stack, sizeof(Fleet) * nfleets);
-
- xmlFreeDoc(doc);
- free(buf);
-
- return 0;
-}
-
-/**
- * @brief Parses a fleetgroup from an xml node.
- * @param fltgrp FleetGroup to fill with data from the xml node.
- * @param parent Node containing fleetgroup data.
- * @return 0 on success.
- */
-static int fleet_parseGroup(FleetGroup* fltgrp, xmlNodePtr parent) {
- int mem;
- xmlNodePtr node;
- Fleet* f;
- char* buf;
-
- /* Clear memory. */
- memset(fltgrp, 0, sizeof(FleetGroup));
-
- /* Get the name. */
- xmlr_attr(parent, "name", fltgrp->name);
-
- /* Load the fleetgroup data. */
- node = parent->children;
- mem = 0;
- do {
- if(xml_isNode(node, "fleet")) {
- /* See if memory must grow. */
- fltgrp->nfleets++;
- if(fltgrp->nfleets > mem) {
- mem += CHUNK_SIZE;
- fltgrp->fleets = realloc(fltgrp->fleets, sizeof(Fleet*) * mem);
- fltgrp->chance = realloc(fltgrp->chance, sizeof(int) * mem);
- }
-
- /* Add the fleet. */
- f = fleet_get(xml_get(node));
- if(f == NULL) {
- WARN("Fleet '%s' in FleetGroup '%s' not found in stack.",
- xml_get(node), fltgrp->name);
- fltgrp->nfleets--;
- continue;
- }
- fltgrp->fleets[fltgrp->nfleets-1] = f;
-
- /* Get the chance. */
- xmlr_attr(node, "chance", buf);
- if(buf == NULL) {
- WARN("Fleet '%s' in FleetGroup '%s' missing 'chance' attribute.",
- xml_get(node), fltgrp->name);
- fltgrp->chance[fltgrp->nfleets-1] = 0;
- continue;
- }
- fltgrp->chance[fltgrp->nfleets-1] = CLAMP(0, 100, atoi(buf));
- free(buf);
- }
- } while(xml_nextNode(node));
-
- return 0;
-}
-
-/**
- * @brief Load all the fleetgroups.
- * @return 0 on success.
- */
-static int fleet_loadFleetGroups(void) {
- int mem;
- uint32_t bufsize;
- char* buf;
- xmlNodePtr node;
- xmlDocPtr doc;
-
- /* Create the document. */
- buf = ldata_read(FLEETGROUP_DATA, &bufsize);
- doc = xmlParseMemory(buf, bufsize);
-
- node = doc->xmlChildrenNode; /* Fleetgroups node. */
- if(strcmp((char*)node->name, "FleetGroups")) {
- ERR("Malformed "FLEETGROUP_DATA" file: missing root element 'FleetGroups'");
- return -1;
- }
-
- node = node->xmlChildrenNode; /* First fleetgroup node. */
- if(node == NULL) {
- ERR("Malformed "FLEETGROUP_DATA" file: does not contain elements");
- return -1;
- }
-
- mem = 0;
- do {
- if(xml_isNode(node, "fleetgroup")) {
- /* See if memory must grow. */
- nfleetgroups++;
- if(nfleets > mem) {
- mem += CHUNK_SIZE;
- fleetgroup_stack = realloc(fleetgroup_stack, sizeof(FleetGroup) * mem);
- }
-
- /* Load the fleetgroup. */
- fleet_parseGroup(&fleetgroup_stack[nfleetgroups-1], node);
- }
- } while(xml_nextNode(node));
-
- /* Shrink to minimum. */
- fleet_stack = realloc(fleet_stack, sizeof(Fleet) * nfleets);
-
- xmlFreeDoc(doc);
- free(buf);
-
- return 0;
-}
-
-/**
- * @brief Load all the fleets and fleetgroups.
- * @return 0 on success.
- */
-int fleet_load(void) {
- if(fleet_loadFleets())
- return -1;
- if(fleet_loadFleetGroups())
- return -1;
-
- DEBUG("Loaded %d Fleet%s", nfleets, (nfleets==1) ? "" : "s");
-
- return 0;
-}
-
-/**
- * @brief Cleans up by freeing all the fleet data.
- */
-void fleet_free(void) {
- int i,j;
- if(fleet_stack != NULL) {
- for(i = 0; i < nfleets; i++) {
- for(j = 0; j < fleet_stack[i].npilots; j++) {
- if(fleet_stack[i].pilots[j].name)
- free(fleet_stack[i].pilots[j].name);
- if(fleet_stack[i].pilots[j].ai)
- free(fleet_stack[i].pilots[j].ai);
- }
- free(fleet_stack[i].name);
- free(fleet_stack[i].pilots);
- free(fleet_stack[i].ai);
- }
- free(fleet_stack);
- }
- fleet_stack = NULL;
- nfleets = 0;
-
- /* Free the fleetgroup stack. */
- if(fleetgroup_stack != NULL) {
- for(i = 0; i < nfleetgroups; i++) {
- free(fleetgroup_stack[i].name);
- free(fleetgroup_stack[i].fleets);
- free(fleetgroup_stack[i].chance);
- }
- free(fleetgroup_stack);
- }
- fleetgroup_stack = NULL;
- nfleetgroups = 0;
-}
-
diff --git a/src/fleet.h b/src/fleet.h
deleted file mode 100644
index 8da1b74..0000000
--- a/src/fleet.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#pragma once
-#include "pilot.h"
-
-/**
- * @struct FleetPilot
- *
- * @brief Represents a pilot in a fleet.
- *
- * @sa Fleet
- * @sa Pilot
- */
-typedef struct FleetPilot_ {
- Ship* ship; /**< Ship the pilot is flying. */
- char* name; /**< Used if they have a special name like uniques. */
- int chance; /**< Chance of this pilot appearing in the fleet. */
- char* ai; /**< ai different of fleets global ai. */
-} FleetPilot;
-
-/**
- * @struct Fleet
- *
- * @brief Represenets a fleet.
- *
- * Fleets are used to create pilots, both from being in a system and from
- * mission triggers.
- *
- * @sa FleetPilot
- * @sa FleetGroup
- */
-typedef struct Fleet_ {
- char* name; /**< Fleet name, used as the identifier. */
- int faction; /**< Faction of the fleet. */
- char* ai; /**< faction of the fleet. */
- FleetPilot* pilots; /**< The pilots in the fleet. */
- int npilots; /**< Total number of pilots. */
-} Fleet;
-
-/**
- * @brief Represents a group of fleets.
- *
- * Used to simplify creation of star systems and easily synchonize all systems.
- * with new ship additions.
- *
- * @sa Fleet
- */
-typedef struct FleetGroup_ {
- char* name; /** Name of the fleetgroup, used as the identifier. */
- Fleet** fleets; /**< List of fleets in the group. */
- int* chance; /**< Chance of each fleet in the group. */
- int nfleets; /**< Number of fleets in the group. */
-} FleetGroup;
-
-/*
- * Get fleet stuff.
- */
-Fleet* fleet_get(const char* name);
-FleetGroup* fleet_getGroup(const char* name);
-
-/*
- * Load / cleanup.
- */
-int fleet_load(void);
-void fleet_free(void);
-
diff --git a/src/font.c b/src/font.c
deleted file mode 100644
index 280cfe6..0000000
--- a/src/font.c
+++ /dev/null
@@ -1,589 +0,0 @@
-/**
- * @file font.c
- *
- * @brief OpenGL font rendering routines.
- *
- * Use a displaylist to store ASCII chars rendered with freefont.
- * There are several drawing methods depending on whether you want
- * to print it all, print to a max width, print centered or print a
- * block of text.
- *
- * There are hardcoded size limits. 256 characters for all routines
- * except gl_printText which has a 1024 limit.
- *
- * @todo Check if length is too long.
- */
-
-#include "font.h"
-
-#include "ft2build.h"
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-#include "lephisto.h"
-#include "log.h"
-#include "ldata.h"
-
-#define FONT_DEF "../dat/font.ttf" /**< Default font path. */
-
-/* Default font. */
-glFont gl_defFont; /**< Default font. */
-glFont gl_smallFont; /**< Small font. */
-
-static void glFontMakeDList(FT_Face face, char ch,
- GLuint list_base, GLuint* tex_base,
- int* width_base);
-static int font_limitSize(const glFont* ft_font, int* width,
- char* txt, const int max);
-
-/**
- * @brief Limits the text to max.
- * @param ft_font Font to calculate width with.
- * @param width Actual width it takes up.
- * @param text Text to parse.
- * @param max Max to look for.
- */
-static int font_limitSize(const glFont* ft_font, int* width,
- char* text, const int max) {
- int n, len, i;
-
- /* Limit size. */
- len = (int)strlen(text);
- n = 0;
- for(i = 0; i < len; i++) {
- n += ft_font->w[(int)text[i]];
- if(n > max) {
- n -= ft_font->w[(int)text[i]]; /* Actual size. */
- text[i] = '\0';
- break;
- }
- }
- if(width != NULL)
- (*width) = n;
- return i;
-}
-
-/**
- * @brief Get the number of characters in text that fit into width.
- * @param ft_font Font to use.
- * @param text Text to check.
- * @param width Width to match.
- * @return Number of characters that fit.
- */
-int gl_printWidthForText(const glFont* ft_font, char* txt,
- const int width) {
-
- int i, n, lastspace;
-
- if(ft_font == NULL)
- ft_font = &gl_defFont;
-
- /* Limit size per line. */
- lastspace = 0; /* last ' ' or '\n' in the text. */
- n = 0; /* Current width. */
- i = 0; /* Current position. */
- while((txt[i] != '\n') && (txt[i] != '\0')) {
- /* Characters we should ignore. */
- if(txt[i] == '\t') {
- i++;
- continue;
- }
-
- /* Increase size. */
- n += ft_font->w[(int)txt[i]];
-
- /* Save last space. */
- if(txt[i] == ' ')
- lastspace = i;
-
- /* Check if out of bounds. */
- if(n > width)
- return lastspace;
-
- /* Check next character. */
- i++;
- }
- return i;
-}
-
-/**
- * @fn void gl_print(const glFont* ft_font, const double x, const double y,
- * const glColour* c, const char* fmt, ...)
- *
- * @brief Print text on screen like printf.
- *
- * Defaults ft_font to gl_defFont if NULL.
- * @param ft_font Font to use (NULL means gl_defFont).
- * @param x X position to put text at.
- * @param y Y position to put text at.
- * @param c Colour to use (uses white if NULL).
- * @param fmt String formatted like printf to print. *
- */
-void gl_print(const glFont* ft_font, const double x, const double y,
- const glColour* c, const char* fmt, ...) {
- /*float h = ft_font->h / .63; // Slightly increases font size. */
- char txt[256];
- va_list ap;
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return;
- else {
- /* convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 256, fmt, ap);
- va_end(ap);
- }
-
- glEnable(GL_TEXTURE_2D);
-
- glListBase(ft_font->list_base);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix(); /* Translation matrix. */
- glTranslated(round(x - (double)SCREEN_W/2.),
- round(y - (double)SCREEN_H/2.), 0);
-
- if(c == NULL) glColor4d(1., 1., 1., 1.);
- else COLOUR(*c);
- glCallLists(strlen(txt), GL_UNSIGNED_BYTE, &txt);
-
- glPopMatrix(); /* Translation matrix. */
- glDisable(GL_TEXTURE_2D);
-
- gl_checkErr();
-}
-
-/**
- * @fn int gl_printMax(const glFont* ft_font, const int max,
- * const double x, const double y, const glColour* c, const char* fmt, ...)
- *
- * @brief Act like gl_print but stops displaying text after reaching a certain length.
- * @param ft_font Font to use (Null means use gl_defFont).
- * @param max Maximum length to reach.
- * @param x X position to display text at.
- * @param y Y position to display text at.
- * @param c Colour to use (NULL defaults to white).
- * @param fmt String to display formatted like printf.
- * @return The number of characters it had to suppress.
- */
-int gl_printMax(const glFont* ft_font, const int max,
- const double x, const double y, const glColour* c, const char* fmt, ...) {
- /*float h = ft_font->h / .63; // Slightly increases font size. */
- char txt[256];
- va_list ap;
- int ret;
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return -1;
- else {
- /* convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 256, fmt, ap);
- va_end(ap);
- }
-
- /* Limit the size. */
- ret = font_limitSize(ft_font, NULL, txt, max);
-
- /* Display the text. */
- glEnable(GL_TEXTURE_2D);
-
- glListBase(ft_font->list_base);
-
- glMatrixMode(GL_MODELVIEW); /* Projection gets full fast using modelview. */
- glPushMatrix(); /* Translation matrix. */
- glTranslated(round(x - (double)SCREEN_W/2.),
- round(y - (double)SCREEN_H/2.), 0);
-
- if(c == NULL) glColor4d(1., 1., 1., 1.);
- else COLOUR(*c);
- glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
-
- glPopMatrix(); /* Translation matrix. */
- glDisable(GL_TEXTURE_2D);
-
- gl_checkErr();
-
- return 0;
-}
-
-/**
- * @fn int gl_printMid(const glFont* ft_font, const int width, double x, const double y,
- * const glColour* c, const char* fmt, ...)
- *
- * @brief Display text centered in position and width.
- *
- * Will truncate if text is too long.
- * @param ft_font Font to use (NULL defaults to gl_defFont).
- * @param width Width of area to center in.
- * @param x X Position to display text at.
- * @param y Y Position to display text at.
- * @param c Colour to use for text (NULL defaults to white).
- * @param fmt Text to display formatted string like printf.
- * @return The number of characters it had to truncate.
- */
-int gl_printMid(const glFont* ft_font, const int width, double x, const double y,
- const glColour* c, const char* fmt, ...) {
- /*float h = ft_font->h / .63; // Slightly increases font size. */
- char txt[256];
- va_list ap;
- int n, ret;
-
- ret = 0; /* Default return value. */
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return -1;
- else {
- /* convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 256, fmt, ap);
- va_end(ap);
- }
-
- /* Limit the size. */
- ret = font_limitSize(ft_font, &n, txt, width);
-
- x += (double)(width-n)/2.;
-
- /* Display the text. */
- glEnable(GL_TEXTURE_2D);
-
- glListBase(ft_font->list_base);
-
- glMatrixMode(GL_MODELVIEW); /* Projection gets full fast using modelview. */
- glPushMatrix(); /* Translation matrix. */
- glTranslated(round(x - (double)SCREEN_W/2.),
- round(y - (double)SCREEN_H/2.), 0);
-
- if(c == NULL) glColor4d(1., 1., 1., 1.);
- else COLOUR(*c);
- glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
-
- glPopMatrix(); /* Translation matrix. */
- glDisable(GL_TEXTURE_2D);
-
- gl_checkErr();
-
- return 0;
-}
-
-/**
- * @fn int gl_printText(const glFont* ft_font, const int width, const int height,
- * double bx, double by, glColour* c, const char* fmt, ...)
- *
- * @brief Print a block of text that fits in the dimensions given.
- *
- * Positions are based on origin being top-left.
- * @param ft_font Font to use (NULL defaults to gl_defFont).
- * @param width Maximum width to print to.
- * @param height Maximum height to print to.
- * @param bx X position to display text at.
- * @param by Y position to display text at.
- * @param c Colour to use (NULL defaults to white).
- * @param fmt Text to display formatted like printf.
- * @return 0 on success.
- */
-int gl_printText(const glFont* ft_font, const int width, const int height,
- double bx, double by, glColour* c, const char* fmt, ...) {
-
- /*float h = ft_font->h / .63; // Slightly increase font size. */
- char txt[4096];
- va_list ap;
- int i, p;
- double x, y;
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return -1;
- else {
- /* Convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 4096, fmt, ap);
- va_end(ap);
- }
- bx -= (double)SCREEN_W/2.;
- by -= (double)SCREEN_H/2.;
- x = bx;
- y = by + height - (double)ft_font->h; /* y is top left corner. */
-
- /* Prepare opengl. */
- glEnable(GL_TEXTURE_2D);
- glListBase(ft_font->list_base);
- if(c == NULL) glColor4d(1., 1., 1., 1.);
- else COLOUR(*c);
-
- p = 0; /* Where we last drew up to. */
- while(y - by > -1e-5) {
- i = gl_printWidthForText(ft_font, &txt[p], width);
-
- glMatrixMode(GL_MODELVIEW); /* Using MODELVIEW, PROJECTION gets full fast. */
- glPushMatrix(); /* Translation matrix. */
- glTranslated(round(x), round(y), 0);
-
- glCallLists(i, GL_UNSIGNED_BYTE, &txt[p]); /* The actual displaying. */
-
- glPopMatrix(); /* Translation matrix. */
-
- if(txt[p+i] == '\0')
- break;
- p += i + 1;
- y -= 1.5*(double)ft_font->h; /* Move position down. */
- }
- glDisable(GL_TEXTURE_2D);
-
- gl_checkErr();
-
- return 0;
-}
-
-/**
- * @fn int gl_printWidth(const glFont* ft_font, const char* fmt, ...)
- *
- * @brief Get the width that it would take to print some text.
- *
- * Does not display text on screen.
- * @param ft_font Font to use (NULL defaults to gl_defFont).
- * @param fmt Text to calculate the length of.
- * @return The length of the text in pixels.
- */
-int gl_printWidth(const glFont* ft_font, const char* fmt, ...) {
- int i, n;
- char txt[256]; /* Holds the string. */
- va_list ap;
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return 0;
- else {
- /* Convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 256, fmt, ap);
- va_end(ap);
- }
-
- for(n = 0, i = 0; i < (int)strlen(txt); i++)
- n += ft_font->w[(int)txt[i]];
-
- return n;
-}
-
-/**
- * @fn int gl_printHeight(const glFont* ft_font, const int width,
- * const char* fmt, ...)
- *
- * @brief Get the height of the text if it were printed.
- *
- * Does not display the text on screen.
- * @param ft_font Font to use (NULL defaults to gl_defFont).
- * @param width Width to jump to next line once reached.
- * @param fmt Text to get the height of in printf format.
- * @return The heiht of the text.
- */
-int gl_printHeight(const glFont* ft_font, const int width,
- const char* fmt, ...) {
-
- char txt[1024]; /* Holds the string. */
- va_list ap;
- int i, p;
- double y;
-
- if(ft_font == NULL) ft_font = &gl_defFont;
-
- if(fmt == NULL) return -1;
- else {
- /* Convert the symbols to text. */
- va_start(ap, fmt);
- vsnprintf(txt, 1024, fmt, ap);
- va_end(ap);
- }
-
- if(txt[0] == '\0')
- return 0;
-
- y = 0.;
-
- p = 0;
- do {
- i = gl_printWidthForText(ft_font, &txt[p], width);
-
- if(txt[p+i] == '\0')
- break;
- p += i + 1;
- y += 1.5*(double)ft_font->h; /* Move position down. */
- } while(txt[p-1] != '\0');
- return (int)(y - 0.5*(double)ft_font->h);
-}
-
-/* ================
- * FONT!
- * ================
- */
-
-/**
- * @fn static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
- * GLuint* tex_base, int* width_base)
- *
- * @brief Makes the font display list.
- */
-static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
- GLuint* tex_base, int* width_base) {
- FT_Bitmap bitmap;
- GLubyte* expanded_data;
- FT_GlyphSlot slot;
- int w, h;
- int i, j;
- double x, y;
-
- slot = face->glyph; /* Small shortcut. */
-
- /* Load the glyph. */
- if(FT_Load_Char(face, ch, FT_LOAD_RENDER))
- WARN("FT_Load_Char failed.");
-
- bitmap = slot->bitmap; /* To simplify. */
-
- /* Need the POT wrapping for GL. */
- w = gl_pot(bitmap.width);
- h = gl_pot(bitmap.rows);
-
- /* Memory for textured data. */
- /* Bitmap is useing two channels, one for luminosity and one for alpha. */
- expanded_data = (GLubyte*)malloc(sizeof(GLubyte)*2*w*h + 1);
- for(j = 0; j < h; j++) {
- for(i = 0; i < w; i++) {
- expanded_data[2*(i+j*w)] = 0xcf; /* Set LUMINANCE to constant. */
- expanded_data[2*(i+j*w)+1] = /* Alpha varies with bitmap. */
- ((i >= bitmap.width) || (j >= bitmap.rows)) ?
- 0 : bitmap.buffer[i + bitmap.width*j];
- }
- }
-
- /* Create the GL texture. */
- glBindTexture(GL_TEXTURE_2D, tex_base[(int)ch]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_LUMINANCE_ALPHA,
- GL_UNSIGNED_BYTE, expanded_data);
-
- free(expanded_data); /* No need for this now. */
-
- /* Create the display lists. */
- glNewList(list_base+ch, GL_COMPILE);
-
- /* Corrects a spacing flaw between letters and */
- /* downwards correction for letters like g or y. */
- glPushMatrix();
- glTranslated((double)slot->bitmap_left, (double)(slot->bitmap_top-bitmap.rows), 0);
-
- /* Take the opengl POT wrapping into account. */
- x = (double)bitmap.width/(double)w;
- y = (double)bitmap.rows/(double)h;
-
- /* Draw the texture mapped quad. */
- glBindTexture(GL_TEXTURE_2D, tex_base[(int)ch]);
- glBegin(GL_QUADS);
- glTexCoord2d(0., 0.);
- glVertex2d(0., (double)bitmap.rows);
- glTexCoord2d(x, 0.);
- glVertex2d((double)bitmap.width, (double)bitmap.rows);
- glTexCoord2d(x, y);
- glVertex2d((double)bitmap.width, 0.);
- glTexCoord2d(0., y);
- glVertex2d(0., 0.);
- glEnd();
-
- glPopMatrix();
- glTranslated((double)(slot->advance.x >> 6), (double)(slot->advance.y >> 6), 0);
- width_base[(int)ch] = slot->advance.x >> 6;
-
- /* End of the display list. */
- glEndList();
-
- gl_checkErr();
-}
-
-/**
- * @fn void gl_fontInit(glFont* font, const char* fname, const unsigned int h)
- *
- * @brief Initializes a font.
- * @param font Font to load (NULL defaults to gl_defFont).
- * @param fname Name of the font (from inside packfile, NULL defaults to default font).
- * @param h Height of the font to generate.
- */
-void gl_fontInit(glFont* font, const char* fname, const unsigned int h) {
- FT_Library library;
- FT_Face face;
- uint32_t bufsize;
- int i;
-
- if(font == NULL) font = &gl_defFont;
-
- FT_Byte* buf = ldata_read((fname != NULL) ? fname : FONT_DEF, &bufsize);
-
- /* Allocatagery. */
- font->textures = malloc(sizeof(GLuint)*128);
- font->w = malloc(sizeof(int)*128);
- font->h = (int)h;
- if(font->textures == NULL || font->w == NULL) {
- WARN("Out of memory!");
- return;
- }
-
- /* Create a FreeType font library. */
- if(FT_Init_FreeType(&library)) {
- WARN("FT_Init_FreeType failed");
- }
-
- /* Objects that freetype uses to store font info. */
- if(FT_New_Memory_Face(library, buf, bufsize, 0, &face))
- WARN("FT_New_Face failed loading library from %s",
- (fname != NULL) ? fname : FONT_DEF);
-
- /* Try to resize. */
- if(FT_IS_SCALABLE(face)) {
- if(FT_Set_Char_Size(face,
- 0, /* Same as width. */
- h << 6, /* In 1/64th of a pixel. */
- 96, /* Create at 96 DPI. */
- 96)) /* Create at 96 DPI. */
- WARN("FT_Set_Char_Size failed.");
- } else
- WARN("Font isn't resizable!");
-
- /* Selected the character map. */
- if(FT_Select_Charmap(face, FT_ENCODING_UNICODE))
- WARN("FT_Select_Charmap failed to change character mapping.");
-
- /* Have OpenGL allocate space for the textures / display lists. */
- font->list_base = glGenLists(128);
- glGenTextures(128, font->textures);
-
- /* Create each of the font display lists. */
- for(i = 0; i < 128; i++)
- glFontMakeDList(face, i, font->list_base, font->textures, font->w);
-
- /* We can now free the face and library. */
- FT_Done_Face(face);
- FT_Done_FreeType(library);
- free(buf);
-}
-
-/**
- * @fn void gl_freeFont(glFont* font)
- *
- * @brief Free a loaded font.
- * @param font Font to free.
- */
-void gl_freeFont(glFont* font) {
- if(font == NULL) font = &gl_defFont;
- glDeleteLists(font->list_base, 128);
- glDeleteTextures(128, font->textures);
- free(font->textures);
- free(font->w);
-}
-
diff --git a/src/font.h b/src/font.h
deleted file mode 100644
index 4044ef3..0000000
--- a/src/font.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#pragma once
-#include "opengl.h"
-
-/**
- * struct glFont
- *
- * @brief Represents a font in memory.
- */
-typedef struct glFont_ {
- int h; /**< Font height. */
- int* w; /**< Width of each font member. */
- GLuint* textures; /**< Textures in the font. */
- GLuint list_base; /**< Display list base. */
-} glFont;
-
-extern glFont gl_defFont; /**< Default font. */
-extern glFont gl_smallFont; /**< Small font. */
-
-/* glFont loading/freeing. */
-/* If font is NULL it uses the internal default font, same with gl_print */
-void gl_fontInit(glFont* font, const char* fname, const unsigned int h);
-void gl_freeFont(glFont* font);
-
-/* Print text. */
-void gl_print(const glFont* ft_font, const double x, const double y,
- const glColour* c, const char* fmt, ...);
-
-/* Print text to a max length. */
-int gl_printMax(const glFont* ft_font, const int max,
- const double x, const double y, const glColour* c, const char* fmt, ...);
-
-/* Print text centered in width at x. */
-int gl_printMid(const glFont* ft_font, const int width,
- double x, const double y, const glColour* c, const char* fmt, ...);
-
-/* Respects \n -> bx, by is top left position. */
-int gl_printText(const glFont* ft_font, const int width, const int height,
- double bx, double by, glColour* c, const char* fmt, ...);
-
-/* Dimension stuff. */
-int gl_printWidthForText(const glFont* ft_font, char* text,
- const int width);
-
-int gl_printWidth(const glFont* ft_font, const char* fmt, ...);
-
-int gl_printHeight(const glFont* ft_font, const int width,
- const char* fmt, ...);
-
diff --git a/src/gui.c b/src/gui.c
deleted file mode 100644
index a40c384..0000000
--- a/src/gui.c
+++ /dev/null
@@ -1,1250 +0,0 @@
-/**
- * @file gui.c
- *
- * @brief Contains the GUI stuff for the player.
- */
-#include
-
-#include "player.h"
-#include "lxml.h"
-#include "lephisto.h"
-#include "pilot.h"
-#include "log.h"
-#include "opengl.h"
-#include "font.h"
-#include "ldata.h"
-#include "space.h"
-#include "rng.h"
-#include "land.h"
-#include "sound.h"
-#include "economy.h"
-#include "pause.h"
-#include "menu.h"
-#include "toolkit.h"
-#include "dialogue.h"
-#include "mission.h"
-#include "llua_misn.h"
-#include "ltime.h"
-#include "hook.h"
-#include "map.h"
-#include "lfile.h"
-#include "spfx.h"
-#include "unidiff.h"
-#include "comm.h"
-#include "intro.h"
-#include "perlin.h"
-#include "ai.h"
-#include "ai.h"
-#include "gui.h"
-
-#define XML_GUI_ID "GUIs" /**< XML section identifier for GUI document. */
-#define XML_GUI_TAG "gui" /**< XML section identifier for gui tags. */
-
-#define GUI_DATA "../dat/gui.xml" /**< Global GUI configuration file. */
-#define GUI_GFX "../gfx/gui/" /**< Location of the GUI graphics. */
-
-#define TARGET_WIDTH 128 /**< Width of the target graphic. */
-#define TARGET_HEIGHT 96 /**< Height of the target graphic. */
-
-#define INTERFERENCE_LAYERS 16 /**< Number of interference layers. */
-#define INTERFERENCE_CHANGE_DT 0.1 /** Speed to change at. */
-
-/* For interference. */
-static int interference_layer = 0; /**< Layer of the current interference. */
-double interference_alpha = 0.; /**< Alpha of the current interference layer. */
-static double interference_t = 0.; /**< Interference timer to control transitions. */
-
-/* Pilot stuff for GUI. */
-extern Pilot** pilot_stack;
-extern int pilot_nstack;
-
-/* Space stuff for GUI. */
-extern StarSystem* systems_stack;
-
-/* Map stuff for autonav. */
-extern int map_npath;
-
-/**
- * @struct Radar
- *
- * @brief Represents the players radar.
- */
-typedef struct Radar_ {
- double x; /**< X position. */
- double y; /**< Y position. */
- double w; /**< Width. */
- double h; /**< Height. */
- RadarShape shape; /**< Shape. */
- double res; /** Resolution. */
- glTexture* interference[INTERFERENCE_LAYERS]; /**< Interference texture. */
-} Radar;
-/* Radar resolutions. */
-#define RADAR_RES_MAX 100. /**< Maximum radar resolution. */
-#define RADAR_RES_MIN 10. /**< Minimum radar resolution. */
-#define RADAR_RES_INTERVAL 10. /**< Steps used to increase/decrease resolution. */
-#define RADAR_RES_DEFAULT 40. /**< Default resolution. */
-
-/**
- * @struct Rect
- *
- * @brief Represents a rectangle.
- */
-typedef struct Rect_ {
- double x; /**< X position. */
- double y; /**< Y position. */
- double w; /**< Width. */
- double h; /**< Height. */
-} Rect;
-
-typedef struct HealthBar_ {
- Rect rect;
- glColour col;
- glTexture* gfx;
-} HealthBar;
-
-/**
- * @struct GUI
- *
- * @brief Represents the ingame player graphical user interface.
- */
-typedef struct GUI_ {
- /* Graphics. */
- glTexture* gfx_frame; /**< Frame of the GUI. */
- glTexture* gfx_targetPilot; /**< Graphics used to target pilot. */
- glTexture* gfx_targetPlanet; /**< Graphics used to target planets. */
-
- /*
- * Rects.
- */
- /* Radar. */
- Radar radar; /**< The radar. */
- /* Navigation. */
- Rect nav; /**< Navigation computer. */
- /* Health. */
- HealthBar shield; /**< Shield bar. */
- HealthBar armour; /**< Armour bar. */
- HealthBar energy; /**< Energy bar. */
- HealthBar fuel; /**< Fuel bar. */
- /* Weapon. */
- Rect weapon; /**< Weapon targetting system. */
- /* Targetting. */
- Rect target_health; /**< Target health. */
- Rect target_name; /**< Name of the target. */
- Rect target_faction; /**< Faction of the target. */
- /* Misc. */
- Rect misc; /**< Misc stuff: credits, cargo etc.. */
- /* Messages. */
- Rect msg; /**< Where messages go. */
-
- /* Positions. */
- Vec2 frame; /**< Global frame position. */
- Vec2 target; /**< Global target position. */
-} GUI;
-
-static GUI gui = {
- .gfx_frame = NULL,
- .gfx_targetPilot = NULL,
- .gfx_targetPlanet = NULL
-};
-
-/* Needed to render properly. */
-double gui_xoff = 0.; /**< X offset that GUI introduces. */
-double gui_yoff = 0.; /**< Y offset that GUI introduces. */
-
-/* Messages. */
-#define MSG_SIZE_MAX 120 /**< Maximum message length. */
-double msg_timeout = 5.; /**< Time it takes for a message to timeout. */
-int msg_max = 5; /**< Maximum messages onscreen. */
-
-/**
- * @struct Msg.
- *
- * @brief On screen player messages.
- */
-typedef struct Msg_ {
- char str[MSG_SIZE_MAX]; /**< The message. */
- double t; /**< Timer related to messages. */
-} Msg;
-static Msg* msg_stack; /**< Stack of messages, will be of msg_max size. */
-
-/* External. */
-extern void weapon_minmap(const double res, const double w, const double h,
- const RadarShape shape, double alpha); /**< From weapon.c */
-extern void planets_minimap(const double res, const double w, const double h,
- const RadarShape shape, double alpha); /**< From space.c */
-
-/* Gui. */
-static void gui_createInterference(void);
-static void rect_parseParam(const xmlNodePtr parent,
- char* name, double* param);
-static void rect_parse(const xmlNodePtr parent,
- double* x, double* y, double* w, double* h);
-static int gui_parseBar(xmlNodePtr parent, HealthBar* bar, const glColour* col);
-static int gui_parse(const xmlNodePtr parent, const char* name);
-static void gui_cleanupBar(HealthBar* bar);
-/* Render GUI. */
-static void gui_renderRadar(double dt);
-static void gui_renderMessages(double dt);
-static void gui_renderPilot(const Pilot* p);
-static void gui_renderHealth(const HealthBar* bar, const double w);
-static void gui_renderInterference(double dt);
-
-/**
- * @brief Set the GUI to defaults.
- */
-void gui_setDefaults(void) {
- gui.radar.res = RADAR_RES_DEFAULT;
- memset(msg_stack, 0, msg_max * sizeof(Msg));
-}
-
-/**
- * @brief Add a msg to the queue to be displayed on screen.
- * @param fmt String with formatting like printf.
- */
-void player_message(const char* fmt, ...) {
- va_list ap;
- int i;
-
- if(fmt == NULL) return; /* Message not valid. */
-
- /* Copy old messages back. */
- for(i = 1; i < msg_max; i++) {
- if(msg_stack[msg_max-i-1].str[0] != '\0') {
- strcpy(msg_stack[msg_max-i].str, msg_stack[msg_max-i-1].str);
- msg_stack[msg_max-i].t = msg_stack[msg_max-i-1].t;
- }
- }
-
- /* Add the new one. */
- va_start(ap, fmt);
- vsnprintf(msg_stack[0].str, MSG_SIZE_MAX, fmt, ap);
- va_end(ap);
-
- msg_stack[0].t = msg_timeout;
-}
-
-/**
- * @brief Render the background GUI stuff, namely planet target gfx.
- * @param dt Current delta tick.
- */
-void gui_renderBG(double dt) {
- (void) dt;
- double x, y;
- glColour* c;
- Planet* planet;
-
- /* NJo need to draw if pilot is dead. */
- if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) ||
- ((player != NULL) && pilot_isFlag(player, PILOT_DEAD)))
- return;
-
- if(planet_target >= 0) {
- planet = cur_system->planets[planet_target];
-
- c = faction_getColour(planet->faction);
-
- x = planet->pos.x - planet->gfx_space->sw/2.;
- y = planet->pos.y + planet->gfx_space->sh/2.;
- gl_blitSprite(gui.gfx_targetPlanet, x, y, 0, 0, c); /* Top left. */
-
- x += planet->gfx_space->sw;
- gl_blitSprite(gui.gfx_targetPlanet, x, y, 1, 0, c); /* Top right. */
-
- y -= planet->gfx_space->sh;
- gl_blitSprite(gui.gfx_targetPlanet, x, y, 1, 1, c); /* Bottom right. */
-
- x -= planet->gfx_space->sw;
- gl_blitSprite(gui.gfx_targetPlanet, x, y, 0, 1, c); /* Bottom left. */
- }
-}
-
-/**
- * @brief Render the players pilot target.
- * @param dt Current delta tick.
- */
-void gui_renderTarget(double dt) {
- (void)dt;
- Pilot* p;
- glColour* c;
- double x, y;
-
- /* Get the target. */
- if(player->target != PLAYER_ID)
- p = pilot_get(player->target);
- else p = NULL;
-
- if((p == NULL) || pilot_isFlag(p, PILOT_DEAD))
- player->target = PLAYER_ID; /* No more pilot_target. */
- else { /* Still is a pilot_target. */
- if(pilot_isDisabled(p))
- c = &cInert;
- else if(pilot_isFlag(p, PILOT_BRIBED))
- c = &cNeutral;
- else if(pilot_isHostile(p))
- c = &cHostile;
- else if(pilot_isFriendly(p))
- c = &cFriend;
- else
- c = faction_getColour(p->faction);
-
- x = p->solid->pos.x - p->ship->gfx_space->sw * PILOT_SIZE_APROX/2.;
- y = p->solid->pos.y + p->ship->gfx_space->sh * PILOT_SIZE_APROX/2.;
- gl_blitSprite(gui.gfx_targetPilot, x, y, 0, 0, c); /* Top left. */
-
- x += p->ship->gfx_space->sw * PILOT_SIZE_APROX;
- gl_blitSprite(gui.gfx_targetPilot, x, y, 1, 0, c); /* Top right. */
-
- y -= p->ship->gfx_space->sh * PILOT_SIZE_APROX;
- gl_blitSprite(gui.gfx_targetPilot, x, y, 1, 1, c); /* Bottom right. */
-
- x -= p->ship->gfx_space->sw * PILOT_SIZE_APROX;
- gl_blitSprite(gui.gfx_targetPilot, x, y, 0, 1, c); /* Bottom left. */
- }
-}
-
-static int can_jump = 0; /**< Store whether or not the player is able to jump. */
-/**
- * @brief Render the players GUI.
- * @param dt Current delta tick.
- */
-void gui_render(double dt) {
- int i, j;
- double x;
- char str[10];
- Pilot* p;
- glColour* c;
- glFont* f;
- StarSystem* sys;
- int quantity, delay;
-
- /* If player is dead, just render the cinematic mode. */
- if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) ||
- ((player != NULL) && pilot_isFlag(player, PILOT_DEAD))) {
-
- spfx_cinematic();
- return;
- }
-
- /* Make sure player is valid. */
- if(player == NULL) return;
-
- /* Lockon warning. */
- if(player->lockons > 0)
- gl_printMid(NULL, SCREEN_W - gui_xoff, 0., SCREEN_H-gl_defFont.h-25.,
- &cRed, "LOCKON DETECTED");
-
- /* Volatile environment. */
- if(cur_system->nebu_volatility > 0.)
- gl_printMid(NULL, SCREEN_W - gui_xoff, 0., SCREEN_H-gl_defFont.h*2.-35.,
- &cRed, "VOLATILE ENVIRONMENT DETECTED");
-
- /*
- * GUI.
- */
- /* Frame. */
- gl_blitStatic(gui.gfx_frame, gui.frame.x, gui.frame.y, NULL);
-
- /* Radar. */
- gui_renderRadar(dt);
-
- /*
- * NAV
- */
- if(planet_target >= 0) { /* Planet landing target. */
- gl_printMid(NULL, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 5,
- &cConsole, "Land");
-
- gl_printMid(&gl_smallFont, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 10 - gl_smallFont.h,
- NULL, "%s", cur_system->planets[planet_target]->name);
- }
- else if(hyperspace_target >= 0) { /* Hyperspace target. */
- sys = system_getIndex(cur_system->jumps[hyperspace_target]);
-
- /* Determine if we have to play the "enter hyperspace range" sound. */
- i = space_canHyperspace(player);
- if((i != 0) && (i != can_jump))
- if(!pilot_isFlag(player, PILOT_HYPERSPACE))
- player_playSound(snd_jump, 1);
- can_jump = i;
-
- /* Determine the colour of the NAV text. */
- if(can_jump || pilot_isFlag(player, PILOT_HYPERSPACE) ||
- pilot_isFlag(player, PILOT_HYP_PREP) ||
- pilot_isFlag(player, PILOT_HYP_BEGIN))
- c = &cConsole;
- else c = NULL;
-
- gl_printMid(NULL, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 5,
- c, "Hyperspace");
-
- gl_printMid(&gl_smallFont, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 10 - gl_smallFont.h,
- NULL, "%d - %s", pilot_getJumps(player),
- (sys_isKnown(sys)) ? sys->name : "Unknown");
- } else { /* No NAV target. */
- gl_printMid(NULL, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 5,
- &cConsole, "Navigation");
-
- gl_printMid(&gl_smallFont, (int)gui.nav.w,
- gui.nav.x, gui.nav.y - 10 - gl_smallFont.h,
- &cGrey, "Off");
- }
-
- /* Health. */
- gui_renderHealth(&gui.shield, player->shield / player->shield_max);
- gui_renderHealth(&gui.armour, player->armour / player->armour_max);
- gui_renderHealth(&gui.energy, player->energy / player->energy_max);
- gui_renderHealth(&gui.fuel, player->fuel / player->fuel_max);
-
- /* Weapon. */
- if(player->secondary == NULL) { /* No secondary weapon. */
- gl_printMid(NULL, (int)gui.weapon.w,
- gui.weapon.x, gui.weapon.y - 5,
- &cConsole, "Secondary");
-
- gl_printMid(&gl_smallFont, (int)gui.weapon.w,
- gui.weapon.x, gui.weapon.y - 10 - gl_defFont.h,
- &cGrey, "None");
- } else {
- f = &gl_defFont;
-
- quantity = pilot_oquantity(player, player->secondary);
- delay = outfit_delay(player->secondary->outfit);
-
- /* Check to see if weapon is ready. */
- if(player->secondary->timer > 0.)
- c = &cGrey;
- else
- c = &cConsole;
-
- /* Launcher. */
- if(player->ammo != NULL) {
- /* Use the ammunitions name. */
- i = gl_printWidth(f, "%s", outfit_ammo(player->secondary->outfit)->name);
- if(i > gui.weapon.w) /* Font is too big. */
- f = &gl_smallFont;
-
- /* Weapon name. */
- gl_printMid(f, (int)gui.weapon.w,
- gui.weapon.x, gui.weapon.y - 5,
- (player->ammo) ? c : &cGrey, "%s",
- outfit_ammo(player->secondary->outfit)->name);
-
- /* Print ammo left underneath. */
- gl_printMid(&gl_smallFont, (int)gui.weapon.w,
- gui.weapon.x, gui.weapon.y - 10 - gl_defFont.h,
- NULL, "%d", (player->ammo) ? player->ammo->quantity : 0);
- } else { /* Other. */
- i = gl_printWidth(f, "%s", player->secondary->outfit->name);
- if(i > (int)gui.weapon.w) /* Font is too big. */
- f = &gl_smallFont;
- gl_printMid(f, (int)gui.weapon.w,
- gui.weapon.x, gui.weapon.y - (gui.weapon.h - f->h)/2.,
- c, "%s", player->secondary->outfit->name);
- }
- }
-
- /* Target. */
- if(player->target != PLAYER_ID) {
- p = pilot_get(player->target);
-
- /* Blit the pilot target. */
- gl_blitStatic(p->ship->gfx_target, gui.target.x, gui.target.y, NULL);
- /* Blit the pilot space image. */
- /*x = gui.target.x + (TARGET_WIDTH - p->ship->gfx_space->sw)/2.;
- y = gui.target.y + (TARGET_HEIGHT - p->ship->gfx_space->sh)/2.;
- gl_blitStaticSprite(p->ship->gfx_space,
- x, y, p->tsx, p->tsy, NULL); */
-
- /* Target name. */
- gl_print(NULL,
- gui.target_name.x,
- gui.target_name.y,
- NULL, "%s", p->name);
- gl_print(&gl_smallFont,
- gui.target_faction.x,
- gui.target_faction.y,
- NULL, "%s", faction_name(p->faction));
-
- /* Target status. */
- if(pilot_isDisabled(p)) /* Pilot is disabled. */
- gl_print(&gl_smallFont,
- gui.target_health.x,
- gui.target_health.y,
- NULL, "Disabled");
- else if(p->shield > p->shield_max/100.) /* On shields. */
- gl_print(&gl_smallFont,
- gui.target_health.x,
- gui.target_health.y, NULL,
- "%s: %.0f%%", "Shield", p->shield/p->armour_max*100.);
- } else { /* No target. */
- gl_printMid(NULL, SHIP_TARGET_W,
- gui.target.x, gui.target.y + (SHIP_TARGET_H - gl_defFont.h)/2.,
- &cGrey, "No Target");
- }
-
- /* Misc. */
-
- /* Money. */
- j = gui.misc.y - 8 - gl_smallFont.h;
- gl_print(&gl_smallFont,
- gui.misc.x + 8, j,
- &cConsole, "Creds:");
- credits2str(str, player->credits, 2);
- i = gl_printWidth(&gl_smallFont, str);
- gl_print( &gl_smallFont,
- gui.misc.x + gui.misc.w - 8 - i, j,
- NULL, str );
- /* Cargo and friends. */
- if(player->ncommodities > 0) {
- j -= gl_smallFont.h + 5;
- gl_print(&gl_smallFont,
- gui.misc.x + 8, j,
- &cConsole, "Cargo:");
- for(i = 0; i < MIN(player->ncommodities, 3); i++) {
- j -= gl_smallFont.h + 3;
- if(player->commodities[i].quantity) /* Quantity is over. */
- gl_printMax(&gl_smallFont, gui.misc.w - 15,
- gui.misc.x + 13, j,
- NULL, "%d %s%s", player->commodities[i].quantity,
- player->commodities[i].commodity->name,
- (player->commodities[i].id) ? "*" : "");
- else /* Basically for weightless mission stuff. */
- gl_printMax(&gl_smallFont, gui.misc.w - 15,
- gui.misc.x + 13, j,
- NULL, "%s%s", player->commodities[i].commodity->name,
- (player->commodities[i].id) ? "*" : "");
- }
- }
-
- j -= gl_smallFont.h + 5;
- gl_print(&gl_smallFont,
- gui.misc.x + 8, j,
- &cConsole, "Free:");
- i = gl_printWidth(&gl_smallFont, "%d", pilot_cargoFree(player));
- gl_print(&gl_smallFont,
- gui.misc.x + gui.misc.w - 8 - i, j,
- NULL, "%d", pilot_cargoFree(player));
-
- /* Messages. */
- gui_renderMessages(dt);
-
- /* Hyperspace. */
- if(pilot_isFlag(player, PILOT_HYPERSPACE) &&
- (player->ptimer < HYPERSPACE_FADEOUT)) {
- if(i < j) {
- x = (HYPERSPACE_FADEOUT-player->ptimer) / HYPERSPACE_FADEOUT;
- glColor4d(1.,1.,1., x);
- glBegin(GL_QUADS);
- glVertex2d( -SCREEN_W/2., -SCREEN_H/2.);
- glVertex2d( -SCREEN_W/2., SCREEN_H/2.);
- glVertex2d( SCREEN_W/2., SCREEN_H/2.);
- glVertex2d( SCREEN_W/2., -SCREEN_H/2.);
- glEnd();
- }
- }
-}
-
-/**
- * @brief Render the GUI Radar.
- * @param dt Current deltatick.
- */
-static void gui_renderRadar(double dt) {
- int i, j;
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- if(gui.radar.shape == RADAR_RECT)
- glTranslated(gui.radar.x - SCREEN_W/2. + gui.radar.w/2.,
- gui.radar.y - SCREEN_H/2. - gui.radar.h/2., 0);
- else if(gui.radar.shape == RADAR_CIRCLE)
- glTranslated(gui.radar.x - SCREEN_W/2.,
- gui.radar.y - SCREEN_H/2, 0.);
-
- /* Planets. */
- planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h,
- gui.radar.shape, 1.-interference_alpha);
-
- /* Weapons. */
- weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h,
- gui.radar.shape, 1.-interference_alpha);
-
- /* Render the pilot_nstack. */
- j = 0;
- for(i = 1; i < pilot_nstack; i++) { /* Skip the player. */
- if(pilot_stack[i]->id == player->target)
- j = i;
- else
- gui_renderPilot(pilot_stack[i]);
- }
-
- /* Render the targetted pilot. */
- if(j != 0)
- gui_renderPilot(pilot_stack[j]);
-
- glPopMatrix(); /* GL_PROJECTION. */
-
- /* Interference. */
- gui_renderInterference(dt);
-
- glPushMatrix();
- if(gui.radar.shape == RADAR_RECT)
- glTranslated(gui.radar.x - SCREEN_W/2. + gui.radar.w/2.,
- gui.radar.y - SCREEN_H/2. - gui.radar.h/2., 0.);
- else if(gui.radar.shape == RADAR_CIRCLE)
- glTranslated(gui.radar.x - SCREEN_W/2.,
- gui.radar.y - SCREEN_H/2., 0.);
-
- /* The + sign in the center of the radar represents the player. */
- glBegin(GL_LINES);
- glVertex2d( 0., -3.);
- glVertex2d( 0., 3.);
- glVertex2d( -3., 0.);
- glVertex2d( 3., 0.);
- glEnd();
-
- glPopMatrix(); /* GL_PROJECTION. */
-}
-
-/**
- * @brief Render the players messages on screen.
- * @param dt Current delta tick.
- */
-
-static void gui_renderMessages(double dt) {
- double x, y;
- glColour c;
- int i;
-
- x = gui.msg.x;
- y = gui.msg.y + (double)(gl_defFont.h*msg_max)*1.2;
- c.r = c.g = c.b = 1.;
-
- for(i = msg_max-1; i >= 0; i--) {
- y -= (double)gl_defFont.h*1.2;
-
- if(msg_stack[i].str[0] != '\0') {
-
- /* Decrement timer. */
- msg_stack[i].t -= dt;
-
- /* Set to NULL if timer is up. */
- if(msg_stack[i].t < 0.)
- msg_stack[i].str[0] = '\0';
- else { /* Draw with variable alpha. */
- if(msg_stack[i].t - msg_timeout/2 < 0.)
- c.a = msg_stack[i].t / (msg_timeout/2.);
- else
- c.a = 1.;
- gl_print(NULL, x, y, &c, "%s", msg_stack[i].str);
- }
- }
- }
-}
-
-/**
- * @brief Render interference if needed.
- * @param dt Current deltatick.
- */
-static void gui_renderInterference(double dt) {
- glColour c;
- glTexture* tex;
- int t;
-
- /* Must be displaying interference. */
- if(interference_alpha <= 0.)
- return;
-
- /* Calculate frame to draw. */
- interference_t += dt;
- if(interference_t > INTERFERENCE_CHANGE_DT) { /* Time to change. */
- t = RNG(0, INTERFERENCE_LAYERS-1);
- if(t != interference_layer)
- interference_layer = t;
- else
- interference_layer = (interference_layer == INTERFERENCE_LAYERS-1) ?
- 0 : interference_layer+1;
- interference_t -= INTERFERENCE_CHANGE_DT;
- }
-
- /* Render the interference. */
- c.r = c.g = c.b = 1.;
- c.a = interference_alpha;
- tex = gui.radar.interference[interference_layer];
- if(gui.radar.shape == RADAR_CIRCLE)
- gl_blitStatic(tex,
- gui.radar.x - gui.radar.w,
- gui.radar.y - gui.radar.w, &c);
- else if(gui.radar.shape == RADAR_RECT)
- gl_blitStatic(tex,
- gui.radar.x - gui.radar.w/2,
- gui.radar.y - gui.radar.h/2, &c);
-}
-
-/**
- * @brief Render a pilot in the GUI radar.
- * @param p Pilot to render.
- */
-static void gui_renderPilot(const Pilot* p) {
- int x, y, sx, sy;
- double w, h;
- glColour* col;
- double a;
-
- /* Get position. */
- x = (p->solid->pos.x - player->solid->pos.x) / gui.radar.res;
- y = (p->solid->pos.y - player->solid->pos.y) / gui.radar.res;
- /* Get size. */
- sx = PILOT_SIZE_APROX/2. * p->ship->gfx_space->sw / gui.radar.res;
- sy = PILOT_SIZE_APROX/2. * p->ship->gfx_space->sh / gui.radar.res;
- if(sx < 1.)
- sx = 1.;
- if(sy < 1.)
- sy = 1.;
-
- /* Check if the pilot is in range. */
- if(((gui.radar.shape == RADAR_RECT) &&
- ((ABS(x) > gui.radar.w/2.+sx) || (ABS(y) > gui.radar.h/2.+sy))) ||
- ((gui.radar.shape == RADAR_CIRCLE) &&
- ((x*x+y*y) > (int)(gui.radar.w*gui.radar.w)))) {
- /* Draw a little targetted symbol. */
- if(p->id == player->target) {
- /* Circle radars have it easy. */
- if(gui.radar.shape == RADAR_CIRCLE) {
- /* We'll create a line. */
- a = ANGLE(x,y);
- x = gui.radar.w * cos(a);
- y = gui.radar.w * sin(a);
- sx = 0.85 * x;
- sy = 0.85 * y;
-
- COLOUR(cRadar_tPilot);
- glBegin(GL_LINES);
- glVertex2d( x, y);
- glVertex2d(sx, sy);
- glEnd(); /* GL_LINES. */
- }
- }
- return;
- }
-
- if(gui.radar.shape == RADAR_RECT) {
- w = gui.radar.w/2.;
- h = gui.radar.h/2.;
- }
- else if(gui.radar.shape == RADAR_CIRCLE) {
- w = gui.radar.w;
- h = gui.radar.w;
- }
- glBegin(GL_QUADS);
- /* Colours. */
- if(p->id == player->target) col = &cRadar_tPilot;
- else if(pilot_isDisabled(p)) col = &cInert;
- else if(pilot_isFlag(p, PILOT_BRIBED)) col = &cNeutral;
- else if(pilot_isHostile(p)) col = &cHostile;
- else if(pilot_isFriendly(p)) col = &cFriend;
- else col = faction_getColour(p->faction);
- ACOLOUR(*col, 1-interference_alpha); /**< Makes it much harder to see. */
-
- /* Image. */
- glVertex2d( MAX(x-sx,-w), MIN(y+sy, h) ); /* Top left. */
- glVertex2d( MIN(x+sx, w), MIN(y+sy, h) ); /* Top right. */
- glVertex2d( MIN(x+sx, w), MAX(y-sy,-h) ); /* Bottom right. */
- glVertex2d( MAX(x-sx,-w), MAX(y-sy,-h) ); /* Bottom left. */
- glEnd(); /* GL_QUADS. */
-}
-
-/**
- * @brief Render a health bar.
- * @param bar Health bar to render.
- * @param w Width of the health bar.
- */
-static void gui_renderHealth(const HealthBar* bar, const double w) {
- double x,y, sx,sy, tx,ty;
-
- /* Set the colour. */
- COLOUR(bar->col);
-
- /* Just create a bar. */
- if(bar->gfx == NULL) {
- /* Set the position values. */
- x = bar->rect.x - SCREEN_W/2.;
- y = bar->rect.x - SCREEN_H/2.;
- sx = w * bar->rect.w;
- sy = bar->rect.h;
-
- glBegin(GL_QUADS);
- glVertex2d(x, y);
- glVertex2d(x+sx, y);
- glVertex2d(x+sx, y-sy);
- glVertex2d(x, y-sy);
- glEnd(); /* GL_QUADS. */
- } else { /* Render the texture. */
- x = bar->rect.x - SCREEN_W/2.;
- y = bar->rect.y - SCREEN_H/2. + bar->gfx->sh;
- sx = w *bar->gfx->sw;
- sy = bar->gfx->sh;
- tx = bar->gfx->sw / bar->gfx->rw;
- ty = bar->gfx->sh / bar->gfx->rh;
-
- /* Draw the image. */
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, bar->gfx->texture);
- glBegin(GL_QUADS);
- glTexCoord2d(0., ty);
- glVertex2d(x, y);
-
- glTexCoord2d(w*tx, ty);
- glVertex2d(x+sx, y);
-
- glTexCoord2d(w*tx, 0.);
- glVertex2d(x+sx, y-sy);
-
- glTexCoord2d(0., 0.);
- glVertex2d(x, y-sy);
- glEnd(); /* GL_QUADS. */
- glDisable(GL_TEXTURE_2D);
- }
-}
-
-/**
- * brief Initialises the GUI system.
- * @return 0 on success.
- */
-int gui_init(void) {
- /* Set gfx to NULL. */
- memset(&gui, 0, sizeof(GUI));
-
- /* Radar. */
- gui.radar.res = RADAR_RES_DEFAULT;
-
- /* Messages. */
- gui.msg.x = 20;
- gui.msg.y = 30;
- msg_stack = calloc(msg_max, sizeof(Msg));
- if(msg_stack == NULL) {
- ERR("Out of memory!");
- return -1;
- }
- return 0;
-}
-
-/**
- * @brief Attempts to load the actual GUI.
- * @param name Name of the GUI to load.
- * @return 0 on success.
- */
-int gui_load(const char* name) {
- uint32_t bufsize;
- char* buf = ldata_read(GUI_DATA, &bufsize);
- char* tmp;
- int found = 0;
-
- xmlNodePtr node;
- xmlDocPtr doc = xmlParseMemory(buf, bufsize);
-
- node = doc->xmlChildrenNode;
- if(!xml_isNode(node, XML_GUI_ID)) {
- ERR("Malformed '"GUI_DATA"' file: missing root element '"XML_GUI_ID"'");
- return -1;
- }
-
- node = node->xmlChildrenNode; /* First system node. */
- if(node == NULL) {
- ERR("Malformed '"GUI_DATA"' file: does not contain elements");
- return -1;
- }
-
- do {
- if(xml_isNode(node, XML_GUI_TAG)) {
- tmp = xml_nodeProp(node, "name"); /* Mallocs. */
- /* Is this the GUI we are looking for? */
- if(strcmp(tmp, name) == 0) {
- found = 1;
-
- /* Parse the xml node. */
- if(gui_parse(node, name))
- WARN("Trouble loading GUI '%s'", name);
- free(tmp);
- break;
- }
- free(tmp);
- }
- } while(xml_nextNode(node));
-
- xmlFreeDoc(doc);
- free(buf);
-
- if(!found) {
- WARN("GUI '%s' not found in '"GUI_DATA"'", name);
- return -1;
- }
-
- return 0;
-}
-
-/**
- * @brief Parse a parameter of the rect node.
- */
-static void rect_parseParam(const xmlNodePtr parent,
- char* name, double* param) {
-
- char* buf;
-
- /* Get the attribute. */
- xmlr_attr(parent, name, buf);
-
- /* Wants attribute. */
- if(param != NULL) {
- if(buf == NULL)
- WARN("Node '%s' mising 'x' parameter.", parent->name);
- else if(buf != NULL)
- *param = atoi(buf);
- }
- /* Doesn't want it. */
- else if(buf != NULL)
- WARN("Node '%s' has superfluous 'x' parameter.", parent->name);
-
- /* Clean it up. */
- if(buf != NULL)
- free(buf);
-}
-
-/**
- * @brief Used to pull out a rect from an xml node.
- */
-static void rect_parse(const xmlNodePtr parent,
- double* x, double* y, double* w, double* h) {
- rect_parseParam(parent, "w", w);
- rect_parseParam(parent, "h", h);
- rect_parseParam(parent, "x", x);
- rect_parseParam(parent, "y", y);
-}
-
-/**
- * @brief Create the interference map for the current gui.
- */
-static void gui_createInterference(void) {
- uint8_t raw;
- int i, j, k;
- float* map;
- uint32_t* pix;
- SDL_Surface* sur;
- int w, h, hw, hh;
- float c;
- int r;
-
- /* Dimension shortcuts. */
- if(gui.radar.shape == RADAR_CIRCLE) {
- w = gui.radar.w*2.;
- h = w;
- }
- else if(gui.radar.shape == RADAR_RECT) {
- w = gui.radar.w;
- h = gui.radar.h;
- }
-
- for(k = 0; k < INTERFERENCE_LAYERS; k++) {
- /* free the old texture. */
- if(gui.radar.interference[k] != NULL)
- gl_freeTexture(gui.radar.interference[k]);
-
- /* Create the temporary surface. */
- sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBAMASK);
- pix = sur->pixels;
-
- /* Load the interference map. */
- map = noise_genRadarInt(w, h, 100.);
-
- /* Create the texture. */
- SDL_LockSurface(sur);
- if(gui.radar.shape == RADAR_CIRCLE) {
- r = pow2((int)gui.radar.w);
- hw = w/2;
- hh = h/2;
- for(i = 0; i < h; i++) {
- for(j = 0; j < w; j++) {
- /* Must be in circle. */
- if(pow2(i-hh) + pow2(j-hw) > r)
- continue;
- c = map[i*w + j];
- raw = 0xff &(uint8_t)((float)0xff * c);
- memset(&pix[i*w + j], raw, sizeof(uint32_t));
- pix[i*w + j] |= AMASK;
- }
- }
- }
- else if(gui.radar.shape == RADAR_RECT) {
- for(i = 0; i < h*w; i++) {
- /* Process pixels. */
- c = map[i];
- raw = 0xff &(uint8_t)((float)0xff * c);
- memset(&pix[i], raw, sizeof(uint32_t));
- pix[i] |= AMASK;
- }
- }
- SDL_UnlockSurface(sur);
-
- /* Set the interference. */
- gui.radar.interference[k] = gl_loadImage(sur);
-
- /* Clean up. */
- free(map);
- }
-}
-
-/**
- * @brief Parses a healthbar.
- * @param parent Parent node of the healthbar.
- * @param bar Bar to load into.
- * @param col Default colour to use.
- */
-static int gui_parseBar(xmlNodePtr parent, HealthBar* bar, const glColour* col) {
- char* tmp, buf[PATH_MAX];
-
- /* Parse the rectangle. */
- rect_parse(parent, &bar->rect.x, &bar->rect.y,
- &bar->rect.w, &bar->rect.h);
-
- /* Load the colour. */
- memcpy(&bar->col, col, sizeof(glColour));
- xmlr_attr(parent, "alpha", tmp);
- if(tmp != NULL) {
- bar->col.a = atof(tmp);
- free(tmp);
- }
-
- /* Check for graphics. */
- tmp = xml_get(parent);
- if(tmp != NULL) {
- snprintf(buf, PATH_MAX, GUI_GFX"%s.png", tmp);
- bar->gfx = gl_newImage(buf, 0);
- }
-
- return 0;
-}
-
-#define RELATIVIZE(a) \
-{(a).x += VX(gui.frame); (a).y = VY(gui.frame)+gui.gfx_frame->h-(a).y;}
-/**< Converts a rect to absolute coords. */
-
-/**
- * @brief Parses a GUI node.
- * @param parent node to parse from.
- * @param name Name of the GUI to load.
- */
-static int gui_parse(const xmlNodePtr parent, const char* name) {
- xmlNodePtr cur, node;
- char* tmp, buf[PATH_MAX];
-
- /* Clean up. */
- gui_cleanup();
-
- /*
- * -- gfx --
- * Set as a property and not a node because it must be loaded first.
- */
- tmp = xml_nodeProp(parent, "gfx");
- if(tmp == NULL) {
- ERR("GUI '%s' has no gfx property", name);
- return -1;
- }
-
- /* Load gfx. */
- /* Frame. */
- snprintf(buf, PATH_MAX, GUI_GFX"%s.png", tmp);
- gui.gfx_frame = gl_newImage(buf, 0);
- /* Pilot. */
- snprintf(buf, PATH_MAX, GUI_GFX"%s_pilot.png", tmp);
- gui.gfx_targetPilot = gl_newSprite(buf, 2, 2, 0);
- /* Planet. */
- snprintf(buf, PATH_MAX, GUI_GFX"%s_planet.png", tmp);
- gui.gfx_targetPlanet = gl_newSprite(buf, 2, 2, 0);
- free(tmp);
-
- /* Frame (based on gfx). */
- vect_csetmin(&gui.frame,
- SCREEN_W - gui.gfx_frame->w, /* x */
- SCREEN_H - gui.gfx_frame->h); /* y */
-
- /* Now actually parse the data. */
- node = parent->children;
-
- do { /* Load all the data. */
- /* Offset. */
- if(xml_isNode(node, "offset"))
- rect_parse(node, &gui_xoff, &gui_yoff, NULL, NULL);
-
- /* Radar. */
- else if(xml_isNode(node, "radar")) {
- tmp = xml_nodeProp(node, "type");
-
- if(strcmp(tmp, "rectangle")==0) gui.radar.shape = RADAR_RECT;
- else if(strcmp(tmp, "circle")==0) gui.radar.shape = RADAR_CIRCLE;
- else {
- WARN("Radar for GUI '%s' is missing 'type' tag or has invalid 'type' tag", name);
- gui.radar.shape = RADAR_RECT;
- }
- free(tmp);
-
- /* Load the appropriate measurements. */
- if(gui.radar.shape == RADAR_RECT)
- rect_parse(node, &gui.radar.x, &gui.radar.y, &gui.radar.w, &gui.radar.h);
- else if(gui.radar.shape == RADAR_CIRCLE)
- rect_parse(node, &gui.radar.x, &gui.radar.y, &gui.radar.w, NULL);
- RELATIVIZE(gui.radar);
- }
-
- /* Nav computer. */
- else if(xml_isNode(node, "nav")) {
- rect_parse(node, &gui.nav.x, &gui.nav.y, &gui.nav.w, &gui.nav.h);
- RELATIVIZE(gui.nav);
- gui.nav.y -= gl_defFont.h;
- }
-
- /* Health bars. */
- else if(xml_isNode(node, "health")) {
- cur = node->children;
- do {
- if(xml_isNode(cur, "shield")) {
- gui_parseBar(cur, &gui.shield, &cShield);
- RELATIVIZE(gui.shield.rect);
- }
- if(xml_isNode(cur, "armour")) {
- gui_parseBar(cur, &gui.armour, &cArmour);
- RELATIVIZE(gui.armour.rect);
- }
- if(xml_isNode(cur, "energy")) {
- gui_parseBar(cur, &gui.energy, &cEnergy);
- RELATIVIZE(gui.energy.rect);
- }
- if(xml_isNode(cur, "fuel")) {
- gui_parseBar(cur, &gui.fuel, &cFuel);
- RELATIVIZE(gui.fuel.rect);
- }
- } while(xml_nextNode(cur));
- }
-
- /* Secondary weapon. */
- else if(xml_isNode(node, "weapon")) {
- rect_parse(node, &gui.weapon.x, &gui.weapon.y,
- &gui.weapon.w, &gui.weapon.h);
- RELATIVIZE(gui.weapon);
- gui.weapon.y -= gl_defFont.h;
- }
-
- /* Target. */
- else if(xml_isNode(node, "target")) {
- cur = node->children;
- do {
- if(xml_isNode(cur, "gfx")) {
- rect_parse(cur, &gui.target.x, &gui.target.y, NULL, NULL);
- RELATIVIZE(gui.target);
- gui.target.y -= SHIP_TARGET_H;
- }
- else if(xml_isNode(cur, "name")) {
- rect_parse(cur, &gui.target_name.x, &gui.target_name.y, NULL, NULL);
- RELATIVIZE(gui.target_name);
- gui.target_name.y -= gl_defFont.h;
- }
- else if(xml_isNode(cur, "faction")) {
- rect_parse(cur, &gui.target_faction.x, &gui.target_faction.y, NULL, NULL);
- RELATIVIZE(gui.target_faction);
- gui.target_faction.y -= gl_smallFont.h;
- }
- else if(xml_isNode(cur, "health")) {
- rect_parse(cur, &gui.target_health.x, &gui.target_health.y, NULL, NULL);
- RELATIVIZE(gui.target_health);
- gui.target_health.y -= gl_defFont.h;
- }
- } while(xml_nextNode(cur));
- }
-
- /* Misc. */
- else if(xml_isNode(node, "misc")) {
- rect_parse(node, &gui.misc.x, &gui.misc.y, &gui.misc.w, &gui.misc.h);
- RELATIVIZE(gui.misc);
- }
- } while(xml_nextNode(node));
-
- /* Some postprocessing. */
- gui_createInterference();
-
- return 0;
-}
-#undef RELATIVIZE
-
-/**
- * @brief Clean up a health bar.
- */
-static void gui_cleanupBar(HealthBar* bar) {
- if(bar->gfx != NULL) {
- gl_freeTexture(bar->gfx);
- bar->gfx = NULL;
- }
-}
-
-/*
- * @brief Clean up the GUI.
- */
-void gui_cleanup(void) {
- int i;
- /* free textures. */
- if( gui.gfx_frame != NULL) {
- gl_freeTexture(gui.gfx_frame);
- gui.gfx_frame = NULL;
- }
- if(gui.gfx_targetPilot != NULL) {
- gl_freeTexture(gui.gfx_targetPilot);
- gui.gfx_targetPilot = NULL;
- }
- if(gui.gfx_targetPlanet != NULL) {
- gl_freeTexture(gui.gfx_targetPlanet);
- gui.gfx_targetPlanet = NULL;
- }
- /* Health textures. */
- gui_cleanupBar(&gui.shield);
- gui_cleanupBar(&gui.armour);
- gui_cleanupBar(&gui.energy);
- gui_cleanupBar(&gui.fuel);
-
- for(i = 0; i < INTERFERENCE_LAYERS; i++) {
- if(gui.radar.interference[i] != NULL) {
- gl_freeTexture(gui.radar.interference[i]);
- gui.radar.interference[i] = NULL;
- }
- }
-
- /* Clean up interference. */
- interference_alpha = 0.;
- interference_layer = 0;
- interference_t = 0;
-}
-
-/**
- * @brief Free the gui stuff.
- */
-void gui_free(void) {
- /* Clean up gui. */
- gui_cleanup();
-
- /* Free messages. */
- free(msg_stack);
-}
-
-/**
- * @brief Modifies the radar resolution.
- * @param mod Number of intervals to jump (up or down).
- */
-void gui_setRadarRel(int mod) {
- gui.radar.res += mod * RADAR_RES_INTERVAL;
- if(gui.radar.res > RADAR_RES_MAX) gui.radar.res = RADAR_RES_MAX;
- else if(gui.radar.res < RADAR_RES_MIN) gui.radar.res = RADAR_RES_MIN;
-
- player_message("Radar set to %dx.", (int)gui.radar.res);
-}
-
diff --git a/src/gui.h b/src/gui.h
index 761d8b0..f943285 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -1,27 +1,39 @@
-#pragma once
+ #pragma once
+#include "libs.h"
-/* Enums. */
-typedef enum RadarShape_ {
- RADAR_RECT, /**< Rectangular radar. */
- RADAR_CIRCLE /**< Circular radar. */
-} RadarShape; /**< Plaers radar shape. */
+ namespace Gui {
+ namespace Color {
+ extern const float bg[];
+ extern const float bgShadow[];
+ }
-extern double gui_xoff; /**< GUI X center offset. */
-extern double gui_yoff; /**< GUI Y center offset. */
+ void HandleSDLEvent(SDL_Event* event);
+ void Draw(void);
+ void Init(int screen_width, int screen_height, int ui_width, int ui_height);
+ }
-/* Loading/cleaning up. */
-int gui_init(void);
-void gui_free(void);
-int gui_load(const char* name);
-void gui_cleanup(void);
+#include "gui_events.h"
-/* Render. */
-void gui_renderBG(double dt);
-void gui_renderTarget(double dt);
-void gui_render(double dt);
+namespace Gui {
+ namespace RawEvents {
+ extern sigc::signal onMouseDown;
+ extern sigc::signal onMouseUp;
+ extern sigc::signal onKeyDown;
+ extern sigc::signal onKeyUp;
+ }
+}
-/* Misc. */
-void gui_setDefaults(void);
-void player_message(const char* fmt, ...);
-void gui_setRadarRel(int mod);
+#include "gui_widget.h"
+#include "gui_image.h"
+#include "gui_button.h"
+#include "gui_toggle_button.h"
+#include "gui_multi_state_image_button.h"
+#include "gui_image_button.h"
+#include "gui_iselectable.h"
+#include "gui_radio_button.h"
+#include "gui_image_radio_button.h"
+#include "gui_radio_group.h"
+#include "gui_fixed.h"
+#include "gui_label.h"
+#include "gui_screen.h"
diff --git a/src/hook.c b/src/hook.c
deleted file mode 100644
index 992e232..0000000
--- a/src/hook.c
+++ /dev/null
@@ -1,298 +0,0 @@
-#include
-#include
-
-#include "log.h"
-#include "lephisto.h"
-#include "lxml.h"
-#include "hook.h"
-
-#define HOOK_CHUNK 32 /* Size to grow by when out of space. */
-
-/* The hook. */
-typedef struct Hook_ {
- unsigned int id; /* Unique id. */
- unsigned int parent; /* Mission it's connected to. */
- char* func; /* Function returned. */
- char* stack; /* Stack it's a part of. */
-
- int delete; /* Indicates it should be deleted when possible. */
-} Hook;
-
-/* The stack. */
-static unsigned int hook_id = 0; /* Unique hook id. */
-static Hook* hook_stack = NULL;
-static int hook_mstack = 0;
-static int hook_nstack = 0;
-static int hook_runningstack = 0; /* Check if stack is running. */
-
-/* Extern. */
-extern int misn_run(Mission* misn, char* func);
-/* Intern. */
-static int hook_run(Hook* hook);
-static void hook_free(Hook* h);
-static int hook_needSave(Hook* h);
-static int hook_parse(xmlNodePtr base);
-/* Extern. */
-int hook_save(xmlTextWriterPtr writer);
-int hook_load(xmlNodePtr parent);
-
-static int hook_run(Hook* hook) {
- int i;
- Mission* misn;
-
- if(hook->delete) return 0; /* Hook should be deleted not run. */
-
- /* Locate the mission. */
- for(i = 0; i < MISSION_MAX; i++)
- if(player_missions[i].id == hook->parent)
- break;
- if(i >= MISSION_MAX) {
- WARN("Trying to run hook with parent not in player mission stack: deleting");
- hook->delete = 1; /* So delete it. */
- return -1;
- }
- misn = &player_missions[i];
-
- if(misn_run(misn, hook->func) < 0)
- /* Error has accured. */
- WARN("Hook [%s] '%d' -> '%s' failed", hook->stack,
- hook->id, hook->func);
-
- return 0;
-}
-
-/* Add/Remove hooks. */
-unsigned int hook_add(unsigned int parent, char* func, char* stack) {
- Hook* new_hook;
-
- /* If the memory must grow. */
- if(hook_nstack+1 > hook_mstack) {
- hook_mstack += HOOK_CHUNK;
- hook_stack = realloc(hook_stack, hook_mstack*sizeof(Hook));
- }
-
- /* Create the new hook. */
- new_hook = &hook_stack[hook_nstack];
- new_hook->id = ++hook_id;
- new_hook->parent = parent;
- new_hook->func = strdup(func);
- new_hook->stack = strdup(stack);
- new_hook->delete = 0;
-
- hook_nstack++;
-
- return new_hook->id;
-}
-
-/**
- * @brief Remove a hook.
- * @param id Identifier of the hook to remove.
- * @return 1 if hook was removed, 2 if hook was scheuled for removal and
- * 0 if it wasn't removed.
- */
-int hook_rm(unsigned int id) {
- int l, m, h, f;
-
- /* Binary search. */
- f = 0;
- l = 0;
- h = hook_nstack-1;
-
- while(l <= h) {
- m = (l+h)/2;
- if(hook_stack[m].id > id) h = m-1;
- else if(hook_stack[m].id < id) l = m+1;
- else {
- f = 1;
- break;
- }
- }
-
- /* Check if hook was found. */
- if(f == 0)
- return 0;
-
- /* Mark to delete, but do not delete yet, hooks are running. */
- if(hook_runningstack) {
- hook_stack[m].delete = 1;
- return 2;
- }
-
- /* Free the hook. */
- hook_free(&hook_stack[m]);
-
- /* Last hook, just clip the stack. */
- if(m == (hook_nstack-1)) {
- hook_nstack--;
- return 1;
- }
-
- /* Move it! */
- memmove(&hook_stack[m], &hook_stack[m+1], sizeof(Hook)*(hook_nstack-(m+1)));
- hook_nstack--;
- return 1;
-}
-
-/**
- * @brief Remove all hooks belonging to parent.
- * @param parent Parent id to remove all hooks belonging to.
- */
-void hook_rmParent(unsigned int parent) {
- int i;
- for(i = 0; i < hook_nstack; i++)
- if(parent == hook_stack[i].parent) {
- /* Only decrement if hook was actually removed. */
- if(hook_rm(hook_stack[i].id) == 1)
- i--;
- }
-}
-
-/**
- * @brief Run all the hooks of stack.
- * @param stack Stack to run.
- * @return 0 on success.
- */
-int hooks_run(char* stack) {
- int i;
-
- hook_runningstack = 1; /* Running hooks. */
- for(i = 0; i < hook_nstack; i++)
- if((strcmp(stack, hook_stack[i].stack)==0) && !hook_stack[i].delete) {
- hook_run(&hook_stack[i]);
- }
- hook_runningstack = 0; /* Not running hooks anymore. */
-
- for(i = 0; i < hook_nstack; i++)
- if(hook_stack[i].delete) { /* Delete any that need deleting. */
- hook_rm(hook_stack[i].id);
- i--;
- }
-
- return 0;
-}
-
-/**
- * @brief Run a single hook by id.
- * @param id Identifier of the hook to run.
- * @return The ID of the hook or 0 if it got deleted.
- */
-void hook_runID(unsigned int id) {
- Hook* h;
- int i, ret;
-
- /* Try to find the hook and run it. */
- ret = 0;
- for(i = 0; i < hook_nstack; i++)
- if(hook_stack[i].id == id) {
- h = &hook_stack[i];
- hook_run(h);
- ret = 1;
- break;
- }
-
- /* Hook not found. */
- if(ret == 0)
- DEBUG("Attempting to run hook of id '%d' which is not in the stack", id);
-}
-
-/* Free a hook. */
-static void hook_free(Hook* h) {
- if(h->func != NULL) free(h->func);
- if(h->stack != NULL) free(h->stack);
-}
-
-/* Clean upi after ourselves. */
-void hook_cleanup(void) {
- int i;
-
- for(i = 0; i < hook_nstack; i++)
- hook_free(&hook_stack[i]);
- free(hook_stack);
- hook_stack = NULL;
- /* Sane defaults just in case. */
- hook_nstack = 0;
- hook_mstack = 0;
-}
-
-/* Save the hooks. */
-static int hook_needSave(Hook* h) {
- int i;
- char* nosave[] = {
- "death", "board", "disable", "jump", /* Pilot hooks. */
- "end" };
-
- for(i = 0; strcmp(nosave[i], "end") != 0; i++)
- if(strcmp(nosave[i], h->stack)==0) return 0;
-
- return 1;
-}
-
-int hook_save(xmlTextWriterPtr writer) {
- int i;
- Hook* h;
-
- xmlw_startElem(writer, "hooks");
- for(i = 0; i < hook_nstack; i++) {
- h = &hook_stack[i];
-
- if(!hook_needSave(h)) continue; /* No need to save it. */
-
- xmlw_startElem(writer, "hook");
-
- /*xmlw_attr(writer, "id", "%u", h->id);*/ /* I don't think it's needed. */
- xmlw_elem(writer, "parent", "%u", h->parent);
- xmlw_elem(writer, "func", "%s", h->func);
- xmlw_elem(writer, "stack", "%s", h->stack);
-
- xmlw_endElem(writer); /* Hook. */
- }
- xmlw_endElem(writer); /* Hooks. */
-
- return 0;
-}
-
-/* Load hooks for a player. */
-int hook_load(xmlNodePtr parent) {
- xmlNodePtr node;
-
- hook_cleanup();
-
- node = parent->xmlChildrenNode;
- do {
- if(xml_isNode(node, "hooks"))
- hook_parse(node);
- } while(xml_nextNode(node));
-
- return 0;
-}
-
-static int hook_parse(xmlNodePtr base) {
- xmlNodePtr node, cur;
- char* func, *stack;
- unsigned int parent;
-
- node = base->xmlChildrenNode;
- do {
- if(xml_isNode(node, "hook")) {
- parent = 0;
- func = NULL;
- stack = NULL;
-
- cur = node->xmlChildrenNode;
- do {
- xmlr_long(cur, "parent", parent);
- xmlr_str(cur, "func", func);
- xmlr_str(cur, "stack", stack);
- } while(xml_nextNode(cur));
-
- if((parent == 0) || (func == NULL) || (stack == NULL)) {
- WARN("Invalid hook.");
- return -1;
- }
- hook_add(parent, func, stack);
- }
- } while(xml_nextNode(node));
-
- return 0;
-}
-
diff --git a/src/hook.h b/src/hook.h
deleted file mode 100644
index e0f7a83..0000000
--- a/src/hook.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-#include "mission.h"
-
-/* Add/Run hooks. */
-unsigned int hook_add(unsigned int parent, char* func, char* stack);
-int hook_rm(unsigned int id);
-void hook_rmParent(unsigned int parent);
-
-/* ========================================================
- * Run Hooks:
- *
- * Currently used:
- * -- "land" - When landed.
- * -- "takeoff" - When taking off.
- * -- "jump" - When changing systems.
- * -- "time" - When time is increment drastically
- * (hyperspace and taking off).
- * ========================================================
- */
-
-int hooks_run(char* stack);
-void hook_runID(unsigned int id); /* Runs hook of specific id. */
-
-/* Destroy hook. */
-void hook_cleanup(void);
-
diff --git a/src/input.c b/src/input.c
deleted file mode 100644
index 9b8cbf3..0000000
--- a/src/input.c
+++ /dev/null
@@ -1,716 +0,0 @@
-/**
- * @file input.c
- *
- * @brief Handle all the keybindings and input.
- */
-
-#include "lephisto.h"
-#include "log.h"
-#include "player.h"
-#include "pause.h"
-#include "toolkit.h"
-#include "menu.h"
-#include "board.h"
-#include "map.h"
-#include "escort.h"
-#include "land.h"
-#include "lstd.h"
-#include "gui.h"
-#include "input.h"
-
-#define KEY_PRESS ( 1.) /**< Key is pressed. */
-#define KEY_RELEASE (-1.) /**< Key is released. */
-
-/* Keybind structure. */
-
-/**
- * @brief Lephisto Keybinding.
- */
-typedef struct Keybind_ {
- char* name; /**< Keybinding name, taken from keybindNames[] */
- KeybindType type; /**< type, defined in player.h. */
- SDLKey key; /**< Key/axis/button event number. */
- SDLMod mod; /**< Key modifiers (where applicable). */
-} Keybind;
-
-static Keybind** input_keybinds; /**< Contains the players keybindings. */
-
-
-/* Name of each keybinding. */
-const char* keybindNames[] = {
- /* Movement. */
- "accel", "left", "right", "reverse", "afterburn",
- /* Targetting. */
- "target", "target_prev", "target_nearest", "target_hostile",
- /* Fighting. */
- "primary", "face", "board",
- /* Secondary weapons. */
- "secondary", "secondary_next", "secondary_prev",
- /* Escorts. */
- "e_targetNext", "e_targetPrev", "e_attack", "e_hold", "e_return", "e_clear",
- /* Space Navigation. */
- "autonav", "target_planet", "land", "thyperspace","starmap", "jump",
- /* Communication. */
- "hail",
- /* Misc. */
- "mapzoomin", "mapzoomout", "screenshot", "pause", "speed", "menu", "info",
- /* Must terminate in "end". */
- "end"
- /**< Names of possible keybindings. */
-};
-
-/* Keybinding descriptions. Should match in position of the names. */
-const char* keybindDescription[] = {
- /* Movement. */
- "Makes your ship accelerate forward.",
- "Makes your ship turn left.",
- "Makes your ship turn right.",
- "Makes your ship turn around and face the direction you're moving from. Good for braking.",
- "Makes your ship afterburn if you have an afterburner installed.",
- /* Targetting. */
- "Cycles through ship targets.",
- "Cycles backwards through ship targets.",
- "Targets the nearest non-disabled ship.",
- "Targets the nearest hostile ship.",
- /* Fighting. */
- "Fires your primary weapons.",
- "Faces your target (ship target if you have one, otherwise planet target).",
- "Attempts to board your target ship.",
- /* Secondary weapons. */
- "Fires your secondary weapon.",
- "Cycles through secondary weapons.",
- "Cycles backwards through secondary weapons.",
- /* Escorts. */
- "Cycles through your esorts.",
- "Cycles backwards through your escorts.",
- "Tells your escorts to attack your target.",
- "Tells your escorts to hold their posistion.",
- "Tells your escorts to return to your ships hanger.",
- "Clears your escorts commands.",
- /* Space navigation. */
- "Initializes the autonavigation system.",
- "Cycles through planet targets.",
- "Attempt to land on your targetted planet or targets nearest landable planet. \
- Requests for landing if you don't have permission yet.",
- "Cycles through hyperspace targets.",
- "Opens the Star Map.",
- "Attempt to jump to your hyperspace target.",
- /* Communication. */
- "Attempts to initialize communication with your taretted ship.",
- /* Misc. */
- "Zooms in on your radar.",
- "Zooms out on your radar.",
- "Takes a screenshot.",
- "Toggles 2x speed modifier.",
- "Pauses the game.",
- "Opens the small ingame menu.",
- "Opens the information menu."
-}; /**< Descriptions of the keybindings. Should be in the same position as the
- matching keybinding name. */
-
-/* Accel hacks. */
-static unsigned int input_accelLast = 0; /**< Used to see if double tap. */
-unsigned int input_afterburnSensitivity = 200; /**< ms between taps to afterburn. */
-
-extern double player_left; /**< player.c */
-extern double player_right; /**< player.c */
-
-#if SDL_VERSION_ATLEAST(1,3,0)
-# define INPUT_NUMKEYS SDL_NUM_SCANCODES /**< Number of keys available. */
-#else /* SDL_VERSION_ATLEASE(1,3,0) */
-# define INPUT_NUMKEYS SDLK_LAST /**< Number of keys available. */
-#endif /* SDL_VERSION_ATLEAST(1,3,0) */
-static const char* keyconv[INPUT_NUMKEYS]; /**< Key conversion table. */
-
-static void input_keyConvGen(void);
-static void input_keyConvDestroy(void);
-
-/**
- * @brief Set the default input keys.
- */
-void input_setDefault(void) {
- /* Movement. */
- input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, KMOD_ALL);
- input_setKeybind("afterburn", KEYBIND_NULL, SDLK_UNKNOWN, KMOD_NONE);
- input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, KMOD_ALL);
- input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, KMOD_ALL);
- input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_ALL);
- /* Targetting. */
- input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_NONE);
- input_setKeybind("target_prev", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_RCTRL);
- input_setKeybind("target_nearest", KEYBIND_KEYBOARD, SDLK_t, KMOD_NONE);
- input_setKeybind("target_hostile", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE);
- /* Combat. */
- input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, KMOD_ALL);
- input_setKeybind("face", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE);
- input_setKeybind("board", KEYBIND_KEYBOARD, SDLK_b, KMOD_NONE);
- /* Escorts. */
- input_setKeybind("e_targetNext", KEYBIND_KEYBOARD, SDLK_g, KMOD_NONE); /* Tmp keybind. */
- input_setKeybind("e_targetPrev", KEYBIND_KEYBOARD, SDLK_g, KMOD_LCTRL); /* Tmp keybind. */
- input_setKeybind("e_attack", KEYBIND_KEYBOARD, SDLK_1, KMOD_NONE);
- input_setKeybind("e_hold", KEYBIND_KEYBOARD, SDLK_2, KMOD_NONE);
- input_setKeybind("e_return", KEYBIND_KEYBOARD, SDLK_3, KMOD_NONE);
- input_setKeybind("e_clear", KEYBIND_KEYBOARD, SDLK_4, KMOD_NONE);
- /* Secondary weapon. */
- input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LALT, KMOD_ALL);
- input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE);
- input_setKeybind("secondary_prev", KEYBIND_KEYBOARD, SDLK_e, KMOD_LCTRL);
- /* Space */
- input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_j, KMOD_LCTRL);
- input_setKeybind("target_planet", KEYBIND_KEYBOARD, SDLK_p, KMOD_NONE);
- input_setKeybind("land", KEYBIND_KEYBOARD, SDLK_l, KMOD_NONE);
- input_setKeybind("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE);
- input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE);
- input_setKeybind("jump", KEYBIND_KEYBOARD, SDLK_j, KMOD_NONE);
- /* Communication. */
- input_setKeybind("hail", KEYBIND_KEYBOARD, SDLK_y, KMOD_NONE);
- /* Misc. */
- input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_ALL);
- input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_ALL);
- input_setKeybind("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, KMOD_ALL);
- input_setKeybind("pause", KEYBIND_KEYBOARD, SDLK_F1, KMOD_NONE);
- input_setKeybind("speed", KEYBIND_KEYBOARD, SDLK_BACKQUOTE, KMOD_ALL);
- input_setKeybind("menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, KMOD_ALL);
- input_setKeybind("info", KEYBIND_KEYBOARD, SDLK_i, KMOD_NONE);
-}
-
-/**
- * @brief Initialize the input subsystem (does not set keys).
- */
-void input_init(void) {
- Keybind* tmp;
- int i;
-
-#if SDL_VERSION_ATLEAST(1,3,0)
- /* Window. */
- SDL_EventState(SDL_WINDOW_EVENT, SDL_DISABLE);
- sDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
-
- /* Keyboard. */
- SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
- SDL_EventState(SDL_KEYUP, SDL_ENABLE);
- SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
-
- /* Mice. */
- SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
- SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
- SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
- SDL_EventState(SDL_MOUSEWHEEL, SDL_ENABLE);
-
- /* Joystick, enabled in joystick.c if needed. */
- SDL_EventState(SDL_JOYAXISMOTION, SDL_DISABLE);
- SDL_EventState(SDL_JOYHATMOTION, SDL_DISABLE);
- SDL_EventState(SDL_JOYBUTTONDOWN, SDL_DISABLE);
- SDL_EventState(SDL_JOYBUTTONUP, SDL_DISABLE);
-
- /* Quit. */
- SDL_EventState(SDL_QUIT, SDL_ENABLE);
-
- /* Proximity. */
- SDL_EventState(SDL_PROXIMITYIN, SDL_DISABLE);
- SDL_EventState(SDL_PROXIMITYOUT, SDL_DISABLE);
-#endif
-
- /* Get the number of keybindings. */
- for(i = 0; strcmp(keybindNames[i], "end"); i++);
- input_keybinds = malloc(i*sizeof(Keybind*));
-
- /* Create sane null keybinding for each. */
- for(i = 0; strcmp(keybindNames[i], "end"); i++) {
- tmp = malloc(sizeof(Keybind));
- tmp->name = (char*)keybindNames[i];
- tmp->type = KEYBIND_NULL;
- tmp->key = SDLK_UNKNOWN;
- tmp->mod = KMOD_NONE;
- input_keybinds[i] = tmp;
- }
-
- /* Generate key translation table. */
- input_keyConvGen();
-}
-
-/**
- * @brief Exit the input subsystem.
- */
-void input_exit(void) {
- int i;
- for(i = 0; strcmp(keybindNames[i], "end"); i++)
- free(input_keybinds[i]);
- free(input_keybinds);
-
- input_keyConvDestroy();
-}
-
-/**
- * @brief Create the key conversion table.
- */
-static void input_keyConvGen(void) {
- SDLKey k;
-
- for(k = 0; k < INPUT_NUMKEYS; k++)
- keyconv[k] = strdup(SDL_GetKeyName(k));
-}
-
-/**
- * @brief Destroy the key conversion table.
- */
-static void input_keyConvDestroy(void) {
- int i;
-
- for(i = 0; i < INPUT_NUMKEYS; i++)
- free(keyconv[i]);
-}
-
-/**
- * @brief Get the key id from its name.
- * @param name Name of the key to get id from.
- * @return ID of the key.
- */
-SDLKey input_keyConv(char* name) {
- SDLKey k, m;
- size_t l;
- char buf;
-
- l = strlen(name);
- buf = tolower(name[0]);
-
- /* Compare for single character. */
- if(l == 1) {
- m = MIN(256, INPUT_NUMKEYS);
- for(k = 0; k < m; k++) { /* Only valid for char range. */
- /* Must not be NULL. */
- if(keyconv[k] == NULL)
- continue;
-
- /* Check if it's also a single char. */
- if((buf == tolower(keyconv[k][0])) && (keyconv[k][1] == '\0'))
- return k;
- }
- } else { /* Compare for strings. */
- for(k = 0; k < INPUT_NUMKEYS; k++) {
- /* Must not be NULL. */
- if(keyconv[k] == NULL)
- continue;
-
- /* Compare strings. */
- if(strcmp(name, keyconv[k])==0)
- return k;
- }
- }
-
- WARN("Keyname '%s' doesn't match any key.", name);
- return SDLK_UNKNOWN;
-}
-
-/**
- * @brief Bind a key of type to action keybind.
- * @param keybind The name of the keybind defined above.
- * @param type The type of the keybind.
- * @param key The key to bind to.
- * @param mod Modifiers to check for.
- */
-void input_setKeybind(char* keybind, KeybindType type, int key, SDLMod mod) {
- int i;
- for(i = 0; strcmp(keybindNames[i], "end"); i++)
- if(strcmp(keybind, input_keybinds[i]->name)==0) {
- input_keybinds[i]->type = type;
- input_keybinds[i]->key = key;
- /* Non-keyboards get mod KMOD_ALL to always match. */
- input_keybinds[i]->mod = (type == KEYBIND_KEYBOARD) ? mod : KMOD_ALL;
- return;
- }
- WARN("Unable to set keybind '%s', That command does not exist.", keybind);
-}
-
-/**
- * @brief Get the value of a keybind.
- * @param keybind Name of the keybinding to get.
- * @param[out] type Store the type of the keybinding.
- * @param[out] mod Store the modifiers used with the keybinding.
- * @return The key assosciated with the keybinding.
- */
-SDLKey input_getKeybind(const char* keybind, KeybindType* type, SDLMod* mod) {
- int i;
- for(i = 0; strcmp(keybindNames[i], "end"); i++)
- if(strcmp(keybind, input_keybinds[i]->name)==0) {
- if(type != NULL) (*type) = input_keybinds[i]->type;
- if(mod != NULL) (*mod) = input_keybinds[i]->mod;
- return input_keybinds[i]->key;
- }
-
- WARN("Unable to get keybinding '%s', that command doesn't exist", keybind);
- return (SDLKey)-1;
-}
-
-/**
- * @brief Get the description of the keybinding
- */
-const char* input_getKeybindDescription(char* keybind) {
- int i;
- for(i = 0; strcmp(keybindNames[i], "end"); i++)
- if(strcmp(keybind, input_keybinds[i]->name)==0)
- return keybindDescription[i];
- WARN("Unable to key keybinding description '%s', that cmmand doesn't exist", keybind);
- return NULL;
-}
-
-#define KEY(s) (strcmp(input_keybinds[keynum]->name, s)==0) /**< Shortcut for ease. */
-#define INGAME() (!toolkit && !paused) /**< Make sure player is in game. */
-#define NOHYP() \
- (player && !pilot_isFlag(player, PILOT_HYP_PREP) && \
- !pilot_isFlag(player, PILOT_HYP_BEGIN) && \
- !pilot_isFlag(player, PILOT_HYPERSPACE)) /**< Make sure player isn't jumping. */
-#define NODEAD() (player) /**< Player isn't dead. */
-#define NOLAND() (!landed) /**< Player isn't landed. */
-
-/**
- * @brief Run the input command.
- * @param keynum The index of the keybind.
- * @param value The value of the keypress (defined above).
- * @param kabs The absolute value.
- */
-static void input_key(int keynum, double value, double kabs) {
- unsigned int t;
-
- /* Accelerating. */
- if(KEY("accel")) {
- if(kabs) {
- player_abortAutonav(NULL);
- player_accel(value);
- }
- else {
- /* Prevent it from getting stuck. */
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_accel(1.);
- }
- else if(value == KEY_RELEASE) player_accelOver();
- }
-
- /* Double tap accel = afterburn! */
- t = SDL_GetTicks();
- if((value == KEY_PRESS) && INGAME() && NOHYP() &&
- (t-input_accelLast <= input_afterburnSensitivity))
- player_afterburn();
- else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
- player_afterburnOver();
-
- if(value == KEY_PRESS) input_accelLast = t;
- }
- /* Afterburning. */
- else if(KEY("afterburn") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS)
- player_afterburn();
- else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
- player_afterburnOver();
- }
- /* Turning left. */
- else if(KEY("left")) {
- if(kabs) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_TURN_LEFT);
- player_left = value;
- } else {
- /* Set flags for facing correction. */
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_TURN_LEFT);
- player_left = 1.;
- }
- else if(value == KEY_RELEASE) {
- player_rmFlag(PLAYER_TURN_LEFT);
- player_left = 0.;
- }
- }
- }
- /* Turning right. */
- else if(KEY("right")) {
- if(kabs) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_TURN_RIGHT);
- player_right = value;
- } else {
- /* Set flags for facing correction. */
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_TURN_RIGHT);
- player_right = 1.;
- }
- else if(value == KEY_RELEASE) {
- player_rmFlag(PLAYER_TURN_RIGHT);
- player_right = 0.;
- }
- }
- }
- /* Turn around to face vel. */
- else if(KEY("reverse")) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_REVERSE);
- }
- else if((value == KEY_RELEASE) && player_isFlag(PLAYER_REVERSE))
- player_rmFlag(PLAYER_REVERSE);
- }
- /* Combat. */
- /* Shooting primary weapon. */
- else if(KEY("primary")) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_PRIMARY);
- }
- else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_PRIMARY); }
- }
- /* Targetting. */
- else if(INGAME() && NODEAD() && KEY("target")) {
- if(value == KEY_PRESS) player_targetNext();
- }
- else if(INGAME() && NODEAD() && KEY("target_prev")) {
- if(value == KEY_PRESS) player_targetPrev();
- }
- else if(INGAME() && NODEAD() && KEY("target_nearest")) {
- if(value == KEY_PRESS) player_targetNearest();
- }
- else if(INGAME() && NODEAD() && KEY("target_hostile")) {
- if(value == KEY_PRESS) player_targetHostile();
- }
- /* Face the target. */
- else if(KEY("face")) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_FACE);
- }
- else if((value == KEY_RELEASE) && player_isFlag(PLAYER_FACE))
- player_rmFlag(PLAYER_FACE);
- }
- /* Board those ships. */
- else if(KEY("board") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_board();
- }
- }
- /* Escorts. */
- else if(INGAME() && NODEAD() && KEY("e_targetNext")) {
- if(value == KEY_PRESS) player_targetEscort(0);
- }
- else if(INGAME() && NODEAD() && KEY("e_targetPrev")) {
- if(value == KEY_PRESS) player_targetEscort(1);
- }
- else if(INGAME() && NODEAD() && KEY("e_attack")) {
- if(value == KEY_PRESS) escorts_attack(player);
- }
- else if(INGAME() && NODEAD() && KEY("e_hold")) {
- if(value == KEY_PRESS) escorts_hold(player);
- }
- else if(INGAME() && NODEAD() && KEY("e_return")) {
- if(value == KEY_PRESS) escorts_return(player);
- }
- else if(INGAME() && NODEAD() && KEY("e_clear")) {
- if(value == KEY_PRESS) escorts_clear(player);
- }
- /* Secondary weapons. */
- /* Shooting secondary weapon. */
- else if(KEY("secondary") && NOHYP()) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_setFlag(PLAYER_SECONDARY);
- }
- else if(value == KEY_RELEASE)
- player_rmFlag(PLAYER_SECONDARY);
- }
- /* Selecting secondary weapon. */
- else if(KEY("secondary_next") && INGAME()) {
- if(value == KEY_PRESS) player_secondaryNext();
- }
- else if(KEY("secondary_prev") && INGAME()) {
- if(value == KEY_PRESS) player_secondaryPrev();
- }
- /* Space. */
- else if(KEY("autonav") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS) player_startAutonav();
- }
- /* Target planet (cycles just like target). */
- else if(KEY("target_planet") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS) player_targetPlanet();
- }
- /* Target nearest planet or attempt to land. */
- else if(KEY("land") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_land();
- }
- }
- else if(KEY("thyperspace") && NOHYP() && NOLAND() && NODEAD()) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_targetHyperspace();
- }
- }
- else if(KEY("starmap") && NOHYP() && NODEAD()) {
- if(value == KEY_PRESS) map_open();
- }
- else if(KEY("jump") && INGAME()) {
- if(value == KEY_PRESS) {
- player_abortAutonav(NULL);
- player_jump();
- }
- }
- /* Communication. */
- else if(KEY("hail") && INGAME() && NOHYP()) {
- if(value == KEY_PRESS) {
- player_hail();
- }
- }
- /* Zoom in. */
- else if(KEY("mapzoomin") && INGAME()) {
- if(value == KEY_PRESS) gui_setRadarRel(1);
- }
- /* Zoom out. */
- else if(KEY("mapzoomout") && INGAME()) {
- if(value == KEY_PRESS) gui_setRadarRel(-1);
- }
- /* Take a screenshot. */
- else if(KEY("screenshot") && INGAME()) {
- if(value == KEY_PRESS) player_screenshot();
- }
- /* Pause the game. */
- else if(KEY("pause") && NOHYP()) {
- if(value == KEY_PRESS) {
- if(!toolkit) {
- if(paused) unpause_game();
- } else pause_game();
- }
- }
- /* Toggle speed mode. */
- else if(KEY("speed")) {
- if(value == KEY_PRESS) {
- if(dt_mod == 1.) pause_setSpeed(2.);
- else pause_setSpeed(1.);
- }
- }
- /* Opens a menu. */
- else if(KEY("menu")) {
- if(value == KEY_PRESS) menu_small();
- }
- /* Show pilot information. */
- else if(KEY("info") && NOHYP()) {
- if(value == KEY_PRESS) menu_info();
- }
-}
-#undef KEY
-
-/* --Events-- */
-
-static void input_joyaxis(const SDLKey axis, const int value);
-static void input_joyevent(const int event, const SDLKey button);
-static void input_keyevent(const int event, const SDLKey key, const SDLMod mod);
-
-/* Joystick. */
-
-/**
- * @brief Filters a joystick axis event.
- * @param axis Axis generated by the event.
- * @param value Value of the axis.
- */
-static void input_joyaxis(const SDLKey axis, const int value) {
- int i, k;
- for(i = 0; strcmp(keybindNames[i], "end"); i++) {
- if(input_keybinds[i]->key == axis) {
- /* Positive axis keybinding. */
- if((input_keybinds[i]->type == KEYBIND_JAXISPOS)
- && (value >= 0)) {
- k = (value > 0) ? KEY_PRESS : KEY_RELEASE;
- input_key(i, k, fabs(((double)value)/32767.));
- }
- /* Negative axis keybinding. */
- if((input_keybinds[i]->type == KEYBIND_JAXISNEG)
- && (value <= 0)) {
- k = (value < 0) ? KEY_PRESS : KEY_RELEASE;
- input_key(i, k, fabs(((double)value)/32767.));
- }
- }
- }
-}
-
-/**
- * @brief Filters a joystick button event.
- * @param event Event type (down/up).
- * @param button Button generating the event.
- */
-static void input_joyevent(const int event, const SDLKey button) {
- int i;
- for(i = 0; strcmp(keybindNames[i], "end"); i++)
- if((input_keybinds[i]->type == KEYBIND_JBUTTON) &&
- (input_keybinds[i]->key == button))
- input_key(i, event, 0.);
-}
-
-/* Keyboard. */
-
-/**
- * @brief Filters a keyboard event.
- * @param event Event type(down/up).
- * @param key Key generating the event.
- * @param mod Modifiers active when event was generated.
- */
-static void input_keyevent(const int event, SDLKey key, const SDLMod mod) {
- int i;
- SDLMod mod_filtered;
-
- /* We want to ignore "global" modifiers. */
- mod_filtered = mod & ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE);
-
- for(i = 0; strcmp(keybindNames[i], "end"); i++) {
- if((input_keybinds[i]->type == KEYBIND_KEYBOARD) &&
- (input_keybinds[i]->key == key)) {
- if((input_keybinds[i]->mod == mod_filtered) ||
- (input_keybinds[i]->mod == KMOD_ALL) ||
- (event == KEY_RELEASE)) /**< Release always gets through. */
- input_key(i, event, 0.);
- /* No break so all keys get pressed if needed. */
- }
- }
-}
-
-
-/**
- * @brief Handle global input.
- *
- * Basically seperates the event types.
- * @param event Incoming SDL_Event.
- */
-void input_handle(SDL_Event* event) {
- /* Pause the game if it is unfocused. */
- if(event->type == SDL_ACTIVEEVENT) {
- if(event->active.state != SDL_APPMOUSEFOCUS) {
- /* We don't need mouse focus. */
- if((event->active.gain == 0) && !paused) pause_game();
- else if((event->active.gain == 1) && paused) unpause_game();
- return;
- }
- }
-
- if(toolkit)
- /* Toolkit is handled seperately. */
- if(toolkit_input(event))
- return; /* We don't process it if toolkit grabs it. */
-
- switch(event->type) {
- case SDL_JOYAXISMOTION:
- input_joyaxis(event->jaxis.axis, event->jaxis.value);
- break;
- case SDL_JOYBUTTONDOWN:
- input_joyevent(KEY_PRESS, event->jbutton.button);
- break;
- case SDL_JOYBUTTONUP:
- input_joyevent(KEY_RELEASE, event->jbutton.button);
- break;
- case SDL_KEYDOWN:
- input_keyevent(KEY_PRESS, event->key.keysym.sym, event->key.keysym.mod);
- break;
- case SDL_KEYUP:
- input_keyevent(KEY_RELEASE, event->key.keysym.sym, event->key.keysym.mod);
- break;
- }
-}
-
diff --git a/src/input.h b/src/input.h
deleted file mode 100644
index 5b9eef8..0000000
--- a/src/input.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-#include
-
-#define KMOD_ALL 0xffff /**< Comfort thing SDL is lacking. */
-
-/* Input types. */
-typedef enum {
- KEYBIND_NULL, /**< Null keybinding. */
- KEYBIND_KEYBOARD, /**< Keyboard keybinding. */
- KEYBIND_JAXISPOS, /**< Joystick axis positive side keybinding. */
- KEYBIND_JAXISNEG, /**< Joystick axis negative side keybinding. */
- KEYBIND_JBUTTON
-} KeybindType;
-
-/* Set input. */
-void input_setDefault(void);
-SDLKey input_keyConv(char* name);
-void input_setKeybind(char* keybind, KeybindType type, int key, SDLMod mod);
-SDLKey input_getKeybind(const char* keybind, KeybindType* type, SDLMod* mod);
-const char* input_getKeybindDescription(char* keybind);
-
-/* Handle the events. */
-void input_handle(SDL_Event* event);
-
-/* Init/Exit. */
-void input_init(void);
-void input_exit(void);
-
diff --git a/src/intro.c b/src/intro.c
deleted file mode 100644
index 772387b..0000000
--- a/src/intro.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * @file intro.c
- *
- * @brief Handle the introduction sequence.
- *
- * @todo Allow handling of images and other fancy things once we get them.
- */
-
-#include
-#include "SDL.h"
-#include "lephisto.h"
-#include "log.h"
-#include "ldata.h"
-#include "font.h"
-#include "music.h"
-#include "lstd.h"
-#include "intro.h"
-
-#define INTRO_FONT_SIZE 18. /**< Intro text font size. */
-#define INTRO_SPEED 30. /**< Speed of text in characters / seconds. */
-
-/* Intro text lines. */
-static char** intro_lines = NULL; /**< Introduction text lines. */
-static int intro_nlines = 0; /**< Number of introduction text lines. */
-static int intro_length = 0; /**< Length of the text. */
-static glFont intro_font; /** Introduction font. */
-
-static int intro_load(const char* text);
-static void intro_cleanup(void);
-
-static int intro_load(const char* text) {
- uint32_t intro_size;
- char* intro_buf;
- int i, p, n;
- int mem;
-
- intro_buf = ldata_read(text, &intro_size);
- intro_length = intro_size; /* Length aproximation! */
-
- /* Create intro font. */
- gl_fontInit(&intro_font, NULL, INTRO_FONT_SIZE);
-
- /* Load lines. */
- p = 0;
- n = 0;
- mem = 0;
- while((uint32_t)p < intro_size) {
- /* Get the length. */
- i = gl_printWidthForText(&intro_font, &intro_buf[p], SCREEN_W - 200.);
-
- /* Copy the line. */
- if(n+1 > mem) {
- mem += 128;
- intro_lines = realloc(intro_lines, sizeof(char*) * mem);
- }
- intro_lines[n] = malloc(i+1);
- strncpy(intro_lines[n], &intro_buf[p], i);
- intro_lines[n][i] = '\0';
-
- p += i + 1; /* Move pointer. */
- n++; /* New line. */
- }
- /* Clean up. */
- free(intro_buf);
-
- intro_nlines = n;
- return 0;
-}
-
-/**
- * @brief Cleans up the intro crap!
- */
-static void intro_cleanup(void) {
- int i;
-
- /* Free memory. */
- for(i = 0; i < intro_nlines; i++)
- free(intro_lines[i]);
- free(intro_lines);
- gl_freeFont(&intro_font);
-
- /* Set default. */
- intro_lines = NULL;
- intro_nlines = 0;
-}
-
-/**
- * @brief Display the introduction sequence.
- * @param text Path of text file to use.
- * @param mus Type of music to use (run through music.lua).
- * @return 0 on success.
- */
-int intro_display(const char* text, const char* mus) {
- int i, max;
- unsigned int tcur, tlast;
- double dt;
- double x, y, vel;
- double offset;
- double density;
- SDL_Event event;
-
- /* Load the introduction. */
- if(intro_load(text) < 0)
- return -1;
-
- /* Calculate velocity. */
- density = ((double)intro_length / (double)intro_nlines); /* char / line. */
- density /= (double)intro_font.h; /* char / pixel. */
- vel = INTRO_SPEED / density; /* (char / s) * (pixel / char) = pixel / s */
-
- /* Change music to intro music. */
- if(mus != NULL)
- music_choose(mus);
-
- /* Prepare for intro loop. */
- x = 100.;
- y = 0.;
- tlast = SDL_GetTicks();
- offset = 0.;
- /*offset = -(intro_font.h + 5.);*/
- max = intro_nlines + SCREEN_H / ((intro_font.h + 5.));
-
- while(1) {
- /* Get delta tick in seconds! */
- tcur = SDL_GetTicks();
- dt = (double)(tcur - tlast) / 1000.;
- tlast = tcur;
-
- /* Handle events. */
- while(SDL_PollEvent(&event)) {
- switch(event.type) {
- case SDL_KEYDOWN:
- /* Skip the boring intro we saw a million times already! */
- if(event.key.keysym.sym == SDLK_ESCAPE)
- offset = max * (intro_font.h + 5.);
- /* Only handle space from here down. */
- else if(!lstd_isspace(event.key.keysym.sym))
- break;
- /* Purpose fallthrough. */
- case SDL_JOYBUTTONDOWN:
- offset += 250.;
- default:
- break;
- }
- /* Only thing we actually care about updating is music. */
- music_update();
- }
-
- /* Increment position. */
- offset += vel * dt;
-
- /* Clear stuff. */
- glClear(GL_COLOR_BUFFER_BIT);
-
- /* Draw text! */
- i = (int)(offset / (intro_font.h + 5.));
- if(i > max) /* Out of lines. */
- break;
- y = offset - (i+1) * (intro_font.h + 5.);
-
- while(i >= 0) {
- /* Skip in line isn't valid. */
- if(i >= intro_nlines) {
- i--;
- y += intro_font.h + 5.;
- continue;
- }
-
- gl_print(&intro_font, x, y, &cConsole, intro_lines[i]);
-
- /* Increment line and position. */
- i--;
- y += intro_font.h + 5.;
- }
-
- /* Display our sh*t. */
- SDL_GL_SwapBuffers();
-
- SDL_Delay(10); /* No need to go burning our CPU now! */
- }
-
- /* Stops music, normal music will start shortly after. */
- music_stop();
-
- /* Cleanup our mess. */
- intro_cleanup();
-
- return 0;
-}
-
diff --git a/src/intro.h b/src/intro.h
deleted file mode 100644
index e46f2e1..0000000
--- a/src/intro.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma once
-
-int intro_display(const char* text, const char* mus);
-
diff --git a/src/joystick.c b/src/joystick.c
deleted file mode 100644
index e86e57e..0000000
--- a/src/joystick.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * @file joystick.c
- *
- * @brief Handles joystick initialization.
- */
-
-#include
-#include
-#include
-#if SDL_VERSION_ATLEAST(1,3,0)
-#include "SDL/SDL_haptic.h"
-#endif
-#include "lephisto.h"
-#include "log.h"
-#include "joystick.h"
-
-static SDL_Joystick* joystick = NULL; /**< Current joystick in use. */
-#if SDL_VERSION_ATLEAST(1,3,0)
-static int has_haptick = 0; /**< Does the player have haptic? */
-SDL_Haptic* haptic = NULL; /**< Current haptic to use, externed in spfx.c */
-unsigned int haptic_query = 0; /**< Properties of the haptic device. */
-#endif
-
-static void joystick_initHaptic(void);
-
-/**
- * @brief Get the joystick index by name.
- * @param namjoystick Looks for given string in the joystick name.
- * @return The index if found, defaults to 0 if it isn't found.
- */
-int joystick_get(char* namjoystick) {
- int i;
- for(i = 0; i < SDL_NumJoysticks(); i++)
- if(strstr(SDL_JoystickName(i), namjoystick))
- return i;
-
- WARN("Joystick '%s' not found, using default joystick '%s'",
- namjoystick, SDL_JoystickName(0));
- return 0;
-}
-
-/**
- * @brief Make the game use a joystick by index.
- * @param indjoystick Index of the joystick to use.
- * @return 0 on success.
- */
-int joystick_use(int indjoystick) {
- /* Check to see if it exists. */
- if(indjoystick < 0 || indjoystick >= SDL_NumJoysticks()) {
- WARN("Joystick of index number %d does not exist. Switching to default (0)",
- indjoystick);
- indjoystick = 0;
- }
- /* Close if already open. */
- if(joystick != NULL) {
- SDL_JoystickClose(joystick);
- joystick = NULL;
- }
- /* Start using the joystick. */
- joystick = SDL_JoystickOpen(indjoystick);
- if(joystick == NULL) {
- WARN("Error opening joystick %d [%s]",
- indjoystick, SDL_JoystickName(indjoystick));
- return -1;
- }
- LOG("Using joystick %d - %s", indjoystick, SDL_JoystickName(indjoystick));
- DEBUG(" With %d axes, %d buttons, %d balls, and %d hats\n",
- SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick),
- SDL_JoystickNumBalls(joystick), SDL_JoystickNumHats(joystick));
-
- /* Initialize the haptic if possible. */
- joystick_initHaptic();
-
- /* For style purposes. */
- DEBUG();
-
- return 0;
-}
-
-/**
- * @brief Initializes force feedback for the loaded device.
- */
-static void joystick_initHaptic(void) {
-#if SDL_VERSION_ATLEAST(1,3,0)
- if(has_haptic && SDL_JoystickIsHaptic(joystick)) {
- /* Close haptic if already open. */
- if(haptic != NULL) {
- SDL_HapticClose(haptic);
- haptic = NULL;
- }
-
- /* Try to create haptic device. */
- haptic = SDL_HapticOpenFromJoystick(joystick);
- if(haptic == NULL) {
- WARN("Unable to initialize force feedback.");
- return;
- }
-
- /* Check to see what it supports. */
- haptic_query = SDL_HapticQuery(haptic);
- if(!(haptic_query & SDL_HAPTIC_SINE)) {
- SDL_HapticClose(haptic);
- haptic = NULL;
- return;
- }
- DEBUG(" force feedback enabled");
- }
-#endif
-}
-
-/**
- * @brief Initializes the joystick subsystem.
- * @return 0 on success.
- */
-int joystick_init(void) {
- int numjoysticks, i;
-
- /* Init the SDL subsys. */
- if(SDL_InitSubSystem(SDL_INIT_JOYSTICK)) {
- WARN("Unable to init the joystick subsystem.");
- return -1;
- }
-
-#if SDL_VERSION_ATLEAST(1,3,0)
- if(SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0)
- has_haptic = 1;
-#endif
-
- /* Figure out how many joysticks there are. */
- numjoysticks = SDL_NumJoysticks();
- LOG("%d joystick%s detected", numjoysticks, (numjoysticks==1)?"":"s");
- for(i = 0; i < numjoysticks; i++)
- DEBUG(" %d. %s", i, SDL_JoystickName(i));
-
- /* Enable joystick events. */
- SDL_JoystickEventState(SDL_ENABLE);
-
- return 0;
-}
-
-/**
- * @brief Exit the joystick subsystem.
- */
-void joystick_exit(void) {
-#if SDL_VERSION_ATLEAST(1,3,0)
- if(haptic != NULL) {
- SDL_HapticClose(haptic);
- haptic = NULL;
- }
-#endif
- if(joystick != NULL) {
- SDL_JoystickClose(joystick);
- joystick = NULL;
- }
-}
-
diff --git a/src/joystick.h b/src/joystick.h
deleted file mode 100644
index 30cff30..0000000
--- a/src/joystick.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-/* Get the joystick index number based on its name. */
-int joystick_get(char* namjoystick);
-
-/* set the game to use the joystick of index indjoystick. */
-int joystick_use(int indjoystick);
-
-/* Exit functions. */
-int joystick_init(void);
-void joystick_exit(void);
-
diff --git a/src/land.c b/src/land.c
deleted file mode 100644
index 18e9615..0000000
--- a/src/land.c
+++ /dev/null
@@ -1,1524 +0,0 @@
-#include
-#include
-#include
-#include
-
-#include "lephisto.h"
-#include "log.h"
-#include "toolkit.h"
-#include "dialogue.h"
-#include "player.h"
-#include "rng.h"
-#include "music.h"
-#include "economy.h"
-#include "hook.h"
-#include "mission.h"
-#include "ltime.h"
-#include "save.h"
-#include "music.h"
-#include "map.h"
-#include "land.h"
-
-/* Global/main window. */
-#define LAND_WIDTH 700
-#define LAND_HEIGHT 600
-#define BUTTON_WIDTH 200
-#define BUTTON_HEIGHT 40
-
-/* Commodity window. */
-#define COMMODITY_WIDTH 400
-#define COMMODITY_HEIGHT 400
-
-/* Outfits. */
-#define OUTFITS_WIDTH 800
-#define OUTFITS_HEIGHT 600
-
-/* Shipyard. */
-#define SHIPYARD_WIDTH 800
-#define SHIPYARD_HEIGHT 600
-
-/* News window. */
-#define NEWS_WIDTH 400
-#define NEWS_HEIGHT 500
-
-/* Bar window. */
-#define BAR_WIDTH 460
-#define BAR_HEIGHT 300
-
-/* Mission computer window. */
-#define MISSION_WIDTH 700
-#define MISSION_HEIGHT 600
-
-/* We use visited flags to not duplicate missions generated. */
-#define VISITED_LAND (1<<0) /**< Player already landed. */
-#define VISITED_COMMODITY (1<<1) /**< Player already visited commodities. */
-#define VISITED_BAR (1<<2) /**< Player already visited bar. */
-#define VISITED_OUTFITS (1<<3) /**< Player already visited outfits. */
-#define VISITED_SHIPYARD (1<<4) /**< Player already visited shipyard. */
-#define visited(f) (land_visited |= (f)) /**< Mark place is visited. */
-#define has_visited(f) (land_visited & (f)) /**< Check if player has visited. */
-static unsigned int land_visited = 0;
-
-/* Land variables. */
-int landed = 0; /**< Is player landed. */
-static unsigned int land_wid = 0; /**< Land window ID. */
-
-Planet* land_planet = NULL; /**< Planet player landed at. */
-static glTexture* gfx_exterior = NULL; /**< Exterior graphic of the landed planet. */
-
-/* Mission computer stack. */
-static Mission* mission_computer = NULL; /**< Missions at the computer. */
-static int mission_ncomputer = 0; /**< Number of missions at the computer. */
-
-/* Player stuff. */
-extern int hyperspace_target; /**< From player.c. */
-
-/* Commodity excahnge. */
-static void commodity_exchange_open(void);
-static void commodity_update(unsigned int wid, char* str);
-static void commodity_buy(unsigned int wid, char* str);
-static void commodity_sell(unsigned int wid, char* str);
-/* Outfits. */
-static void outfits_open(void);
-static void outfits_update(unsigned int wid, char* str);
-static int outfit_canBuy(Outfit* outfit, int q, int errmsg);
-static void outfits_buy(unsigned int wid, char* str);
-static int outfit_canSell(Outfit* outfit, int q, int errmsg);
-static void outfits_sell(unsigned int wid, char* str);
-static int outfits_getMod(void);
-static void outfits_renderMod(double bx, double by, double w, double h);
-/* Shipyard. */
-static void shipyard_open(void);
-static void shipyard_update(unsigned int wid, char* str);
-static void shipyard_info(unsigned int wid, char* str);
-static void shipyard_buy(unsigned int wid, char* str);
-/* Your ship. */
-static void shipyard_yours_open(unsigned int wid, char* str);
-static void shipyard_yoursUpdate(unsigned int wid, char* str);
-static void shipyard_yoursChange(unsigned int wid, char* str);
-static void shipyard_yoursSell(unsigned int wid, char* str);
-static void shipyard_yoursTransport(unsigned int wid, char* str);
-static unsigned int shipyard_yoursTransportPrice(char* shipname);
-/* Spaceport bar. */
-static void spaceport_bar_open(void);
-/* News. */
-static void news_open(unsigned int parent, char* str);
-/* Mission computer. */
-static void misn_open(void);
-static void misn_close(unsigned int wid, char* name);
-static void misn_accept(unsigned int wid, char* str);
-static void misn_genList(unsigned int wid, int first);
-static void misn_update(unsigned int wid, char* str);
-/* Refuel. */
-static void land_checkAddRefuel(void);
-static unsigned int refuel_price(void);
-static void spaceport_refuel(unsigned int wid, char* str);
-/* External. */
-static unsigned int economy_getPrice(const Commodity* com,
- const StarSystem* sys, const Planet* p);
-
-/**
- * @brief Open the local market window.
- */
-static void commodity_exchange_open(void) {
- int i;
- char** goods;
- unsigned int wid;
-
- wid = window_create("Commodity Exchange", -1, -1,
- COMMODITY_WIDTH, COMMODITY_HEIGHT);
-
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
- "Close", window_close);
-
- window_addButton(wid, -40-((BUTTON_WIDTH-20)/2), 20*2+BUTTON_HEIGHT,
- (BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommodityBuy",
- "Buy", commodity_buy);
-
- window_addButton(wid, -20, 20*2+BUTTON_HEIGHT,
- (BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommoditySell",
- "Sell", commodity_sell);
-
- window_addText(wid, -20, -40, BUTTON_WIDTH, 60, 0,
- "txtSInfo", &gl_smallFont, &cDConsole,
- "You have:\n"
- "Market price:\n"
- "\n"
- "Free Space:\n");
-
- window_addText(wid, -20, -40, BUTTON_WIDTH/2, 60, 0,
- "txtDInfo", &gl_smallFont, &cBlack, NULL);
-
- window_addText(wid, -40, -120, BUTTON_WIDTH-20,
- BUTTON_WIDTH, 0, "txtDesc", &gl_smallFont, &cBlack, NULL);
-
- goods = malloc(sizeof(char*)*land_planet->ncommodities);
- for(i = 0; i < land_planet->ncommodities; i++)
- goods[i] = strdup(land_planet->commodities[i]->name);
-
- window_addList(wid, 20, -40,
- COMMODITY_WIDTH-BUTTON_WIDTH-60,
- COMMODITY_HEIGHT-80-BUTTON_HEIGHT, "lstGoods",
- goods, land_planet->ncommodities, 0, commodity_update);
-
- /* Update. */
- commodity_update(wid, NULL);
-
- /* Check commodity exchange missions. */
- if(!has_visited(VISITED_COMMODITY)) {
- /*missions_run(MIS_AVAIL_COMMODITY, land_planet->faction,
- land_planet->name, cur_system->name);*/
- visited(VISITED_COMMODITY);
- }
-}
-
-/**
- * @brief Update the commodity window.
- * @param wid Window to update.
- * @param str Unused.
- */
-static void commodity_update(unsigned int wid, char* str) {
- (void)str;
- char buf[PATH_MAX];
- char* comname;
- Commodity* com;
-
- comname = toolkit_getList(wid, "lstGoods");
- com = commodity_get(comname);
-
- snprintf(buf, PATH_MAX,
- "%d tons\n"
- "%d Scred\n"
- "\n"
- "%d tons\n",
- player_cargoOwned(comname),
- economy_getPrice(com, cur_system, land_planet),
- pilot_cargoFree(player));
-
- window_modifyText(wid, "txtDInfo", buf);
- window_modifyText(wid, "txtDesc", com->description);
-}
-
-/**
- * @brief Buys the selected commodity.
- * @param wid Window buying from.
- * @param str Unused.
- */
-static void commodity_buy(unsigned int wid, char* str) {
- (void)str;
- char* comname;
- Commodity* com;
- unsigned int q, price;
-
- q = 10;
- comname = toolkit_getList(wid, "lstGoods");
- com = commodity_get(comname);
- price = economy_getPrice(com, cur_system, land_planet);
-
- if(player->credits < q * price) {
- dialogue_alert("Not enough Scred!");
- return;
- }
- else if(pilot_cargoFree(player) <= 0) {
- dialogue_alert("not enough free space!");
- return;
- }
-
- q = pilot_addCargo(player, com, q);
- player->credits -= q * price;
- land_checkAddRefuel();
- commodity_update(wid, NULL);
-}
-
-/**
- * @brief Attempts to sell a commodity.
- * @param wid Window selling commodity from.
- * @param str Unused.
- */
-static void commodity_sell(unsigned int wid, char* str) {
- (void)str;
- char* comname;
- Commodity* com;
- unsigned int q, price;
-
- q = 10;
- comname = toolkit_getList(wid, "lstGoods");
- com = commodity_get(comname);
- price = economy_getPrice(com, cur_system, land_planet);
-
- q = pilot_rmCargo(player, com, q);
- player->credits += q * price;
- land_checkAddRefuel();
- commodity_update(wid, NULL);
-}
-
-/**
- * @brief Open the outfit exchange center window.
- */
-static void outfits_open(void) {
- int i;
- Outfit** outfits;
- char** soutfits;
- glTexture** toutfits;
- int noutfits;
- char buf[128];
- unsigned int wid;
-
- /* Create window. */
- snprintf(buf, 128, "%s - Outfits", land_planet->name);
- wid = window_create(buf, -1, -1,
- OUTFITS_WIDTH, OUTFITS_HEIGHT);
-
- /* Will allow buying from keyboard. */
- window_setAccept(wid, outfits_buy);
-
- /* Buttons. */
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits",
- "Close", window_close);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyOutfit",
- "Buy", outfits_buy);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellOutfit",
- "Sell", outfits_sell);
-
- /* Fancy 128x128 image. */
- window_addRect(wid, -20, -50, 128, 128, "rctImage", &cBlack, 0);
- window_addImage(wid, -20-128, -50-128, "imgOutfit", NULL, 1);
-
- window_addCust(wid, -40-BUTTON_WIDTH, 60+2*BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT,
- "cstMod", 0, outfits_renderMod, NULL);
-
- /* The descriptive text. */
- window_addText(wid, 40+300+20, -60,
- 80, 160, 0, "txtSDesc", &gl_smallFont, &cDConsole,
- "Name:\n"
- "Type:\n"
- "Owned:\n"
- "\n"
- "Space taken:\n"
- "Free Space:\n"
- "\n"
- "Price:\n"
- "Money:\n"
- "License:\n");
-
- window_addText(wid, 40+300+40+60, -60,
- 250, 160, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
-
- window_addText(wid, 20+300+40, -240,
- OUTFITS_WIDTH-400, 180, 0, "txtDescription",
- &gl_smallFont, NULL, NULL);
-
- /* Set up the outfits to buy/sell. */
- outfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
-
- if(noutfits <= 0) { /* No outfits. */
- soutfits = malloc(sizeof(char*));
- soutfits[0] = strdup("None");
- toutfits = malloc(sizeof(glTexture*));
- toutfits[0] = NULL;
- noutfits = 1;
- } else {
- /* Create the outfit arrays. */
- soutfits = malloc(sizeof(char*)*noutfits);
- toutfits = malloc(sizeof(glTexture*)*noutfits);
- for(i = 0; i < noutfits; i++) {
- soutfits[i] = strdup(outfits[i]->name);
- toutfits[i] = outfits[i]->gfx_store;
- }
- free(outfits);
- }
-
- window_addImageArray(wid, 20, 40,
- 310, OUTFITS_HEIGHT-80, "iarOutfits", 64, 64,
- toutfits, soutfits, noutfits, outfits_update);
-
- /* Write the outfits stuff. */
- outfits_update(wid, NULL);
-
- /* Check outfit missions. */
- if(!has_visited(VISITED_OUTFITS)) {
- missions_run(MIS_AVAIL_OUTFIT, land_planet->faction,
- land_planet->name, cur_system->name);
- visited(VISITED_OUTFITS);
- }
-}
-
-/**
- * @brief Updates the outfits in the outfit window.
- * @param wid Window to update the outfits in.
- * @param str Unused.
- */
-static void outfits_update(unsigned int wid, char* str) {
- (void)str;
- char* outfitname;
- Outfit* outfit;
- char buf[PATH_MAX], buf2[16], buf3[16];
-
- outfitname = toolkit_getList(wid, "iarOutfits");
- if(strcmp(outfitname, "None")==0) { /* No outfits. */
- window_modifyImage(wid, "imgOutfit", NULL);
- window_disableButton(wid, "btnBuyOutfit");
- window_disableButton(wid, "btnSellOutfit");
- snprintf(buf, PATH_MAX,
- "None\n"
- "NA\n"
- "NA\n"
- "\n"
- "NA\n"
- "%d\n"
- "\n"
- "NA\n"
- "MA\m"
- "NA\n",
- pilot_freeSpace(player));
- window_modifyText(wid, "txtDDesc", buf);
- return;
- }
-
- outfit = outfit_get(outfitname);
-
- window_modifyImage(wid, "imgOutfit", outfit->gfx_store);
-
- if(outfit_canBuy(outfit, 1, 0) > 0)
- window_enableButton(wid, "btnBuyOutfit");
- else
- window_disableButton(wid, "btnBuyOutfit");
-
- /* Gray out sell button. */
- if(outfit_canSell(outfit, 1, 0) > 0)
- window_enableButton(wid, "btnSellOutfit");
- else
- window_disableButton(wid, "btnSellOutfit");
-
- /* New text. */
- window_modifyText(wid, "txtDescription", outfit->description);
- credits2str(buf2, outfit->price, 2);
- credits2str(buf3, player->credits, 2);
- snprintf(buf, PATH_MAX,
- "%s\n"
- "%s\n"
- "%d\n"
- "\n"
- "%d\n"
- "%d\n"
- "\n"
- "%s SCred\n"
- "%s SCred\n"
- "%s\n",
- outfit->name,
- outfit_getType(outfit),
- (outfit_isLicense(outfit)) ?
- player_hasLicense(outfit->name) :
- player_outfitOwned(outfitname),
- outfit->mass,
- pilot_freeSpace(player),
- buf2,
- buf3,
- (outfit->license != NULL) ? outfit->license : "None");
-
- window_modifyText(wid, "txtDDesc", buf);
-}
-
-/**
- * @brief Check to see if the player can buy the outfit.
- * @param outfit Outfit to buy.
- * @param q Quantity to buy.
- * @param errmsg Should alert the player?
- */
-static int outfit_canBuy(Outfit* outfit, int q, int errmsg) {
- char buf[16];
-
- /* Can player actually fit the outfit? */
- if((pilot_freeSpace(player) - outfit->mass) < 0) {
- if(errmsg != 0)
- dialogue_alert("No enough free space (you need %d more slots).",
- outfit->mass - pilot_freeSpace(player));
- return 0;
- }
- else if(player_outfitOwned(outfit->name) >= outfit->max) {
- /* Already has too many. */
- if(errmsg != 0)
- dialogue_alert("You can only carry %d of this outfit.", outfit->max);
- return 0;
- }
- else if(outfit_isAfterburner(outfit) && (player->afterburner != NULL)) {
- if(errmsg != 0)
- dialogue_alert("You can only have one afterburner.");
- return 0;
- }
- /* Takes away cargo space but you don't have any. */
- else if(outfit_isMod(outfit) && (outfit->u.mod.cargo < 0)
- && (pilot_cargoFree(player) < -outfit->u.mod.cargo)) {
- if(errmsg != 0)
- dialogue_alert("You need to empty your cargo first.");
- return 0;
- }
- /* Not enough $$. */
- else if(q*outfit->price > player->credits) {
- if(errmsg != 0) {
- credits2str(buf, q*outfit->price - player->credits, 2);
- dialogue_alert("You need %s more SCred.", buf);
- }
- return 0;
- }
- /* Map alrady mapped. */
- else if(outfit_isMap(outfit) && map_isMapped(NULL, outfit->u.map.radius)) {
- if(errmsg != 0)
- dialogue_alert("You already own this map.");
- return 0;
- }
- /* Already has license. */
- else if(outfit_isLicense(outfit) && player_hasLicense(outfit->name)) {
- if(errmsg != 0)
- dialogue_alert("You already have this license.");
- return 0;
- }
- /* Needs license. */
- else if((outfit->license != NULL) && !player_hasLicense(outfit->license)) {
- if(errmsg != 0)
- dialogue_alert("You need the '%s' license to buy this outfit.",
- outfit->license);
- return 0;
- }
-
- return 1;
-}
-
-/**
- * @brief Attempts to buy the outfit that is selected.
- * @param wid Window buying outfit from.
- * @param str Unused.
- */
-static void outfits_buy(unsigned int wid, char* str) {
- (void)str;
- char* outfitname;
- Outfit* outfit;
- int q;
-
- outfitname = toolkit_getList(wid, "iarOutfits");
- outfit = outfit_get(outfitname);
-
- q = outfits_getMod();
-
- /* Can buy the outfit? */
- if(outfit_canBuy(outfit, q, 1) == 0) return;
-
- player->credits -= outfit->price * pilot_addOutfit(player, outfit,
- MIN(q, outfit->max));
- land_checkAddRefuel();
- outfits_update(wid, NULL);
-}
-
-/**
- * @brief Check to see if the player can sell the selected outfit.
- * @param outfit Outfit to try to sell.
- * @param q Quantity to try to sell.
- * @param errmsg Should alert player?
- */
-static int outfit_canSell(Outfit* outfit, int q, int errmsg) {
- /* No outfits to sell. */
- if(player_outfitOwned(outfit->name) <= 0) {
- if(errmsg != 0)
- dialogue_alert("You can't sell something you don't have!");
- return 0;
- }
- /* Can't sell when you are using it. */
- else if(outfit_isMod(outfit) && (pilot_cargoFree(player) < outfit->u.mod.cargo * q)) {
- if(errmsg != 0)
- dialogue_alert("You currently have cargo in this modification.");
- return 0;
- }
- else if((outfit->mass < 0) && (pilot_freeSpace(player) < -outfit->mass)) {
- if(errmsg != 0)
- dialogue_alert("Get rid of other outfits first.");
- return 0;
- }
-
- return 1;
-}
-
-/**
- * @brief Attempts to sell the selected outfit the player has.
- * @param wid Window selling outfits from.
- * @param str Unused.
- */
-static void outfits_sell(unsigned int wid, char* str) {
- (void)str;
- char* outfitname;
- Outfit* outfit;
- int q;
-
- outfitname = toolkit_getList(wid, "iarOutfits");
- outfit = outfit_get(outfitname);
-
- q = outfits_getMod();
-
- /* Has no outfits to sell. */
- if(outfit_canSell(outfit, q, 1) == 0) return;
-
- player->credits += outfit->price * pilot_rmOutfit(player, outfit, q);
- land_checkAddRefuel();
- outfits_update(wid, NULL);
-}
-
-/**
- * @brief Get the current modifier status.
- * @return The amount modifier when buying or selling outfits.
- */
-static int outfits_getMod(void) {
- SDLMod mods;
- int q;
-
- mods = SDL_GetModState();
- q = 1;
- if(mods & (KMOD_LCTRL | KMOD_RCTRL)) q *= 5;
- if(mods & (KMOD_LSHIFT | KMOD_RSHIFT)) q *= 10;
-
- return q;
-}
-
-/**
- * @brief Render the outfit buying modifier.
- * @param bx Base X position to render at.
- * @param by Base Y position to render at.
- * @param w Width to render at.
- * @param h Height to render at.
- */
-static void outfits_renderMod(double bx, double by, double w, double h) {
- (void) h;
- int q;
- char buf[8];
-
- q = outfits_getMod();
- if(q == 1) return; /* Ignore modifier. */
-
- snprintf(buf, 8, "%dx", q);
- gl_printMid(&gl_smallFont, w,
- bx + (double)SCREEN_W/2.,
- by + (double)SCREEN_H/2.,
- &cBlack, buf);
-}
-
-/**
- * Brief Open the shipyard window.
- */
-static void shipyard_open(void) {
- int i;
- Ship** ships;
- char** sships;
- glTexture** tships;
- int nships;
- char buf[128];
- unsigned int wid;
-
- /* Window creation. */
- snprintf(buf, 128, "%s - Shipyard", land_planet->name);
- wid = window_create(buf,
- -1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
- /* Buttons. */
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard",
- "Close", window_close);
-
- window_addButton(wid, -20, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnYourShips",
- "Your Ships", shipyard_yours_open);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
- "Buy", shipyard_buy);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnInfoShip",
- "Info", shipyard_info);
-
- /* Target gfx. */
- window_addRect(wid, -40, -50,
- 128, 96, "rctTarget", &cBlack, 0);
-
- window_addImage(wid, -40-128, -50-96,
- "imgTarget", NULL, 1);
-
- /* Text. */
- window_addText(wid, 40+300+40, -55,
- 80, 128, 0, "txtSDesc", &gl_smallFont, &cDConsole,
- "Name:\n"
- "Class:\n"
- "Fabricator:\n"
- "\n"
- "Price:\n"
- "Money:\n"
- "License:\n");
-
- window_addText(wid, 40+300+40+80, -55,
- 130, 128, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
-
-
- window_addText(wid, 20+310+40, -55-128-20,
- SHIPYARD_WIDTH-(20+310+40) - 20, 185, 0, "txtDescription",
- &gl_smallFont, NULL, NULL);
-
- /* Set up the ships to buy/sell. */
- ships = ship_getTech(&nships, land_planet->tech, PLANET_TECH_MAX);
-
- if(nships <= 0) {
- sships = malloc(sizeof(char*));
- sships[0] = strdup("None");
- tships = malloc(sizeof(glTexture*));
- tships[0] = NULL;
- nships = 1;
- } else {
- sships = malloc(sizeof(char*)*nships);
- tships = malloc(sizeof(glTexture*)*nships);
- for(i = 0; i < nships; i++) {
- sships[i] = strdup(ships[i]->name);
- tships[i] = ships[i]->gfx_target;
- }
- free(ships);
- }
- window_addImageArray(wid, 20, 40,
- 310, SHIPYARD_HEIGHT-80, "iarShipyard", 64./96.*128., 64.,
- tships, sships, nships, shipyard_update);
-
- /* Write the shipyard stuff. */
- shipyard_update(wid, NULL);
-
- /* Run available missions. */
- if(!has_visited(VISITED_SHIPYARD)) {
- missions_run(MIS_AVAIL_SHIPYARD, land_planet->faction,
- land_planet->name, cur_system->name);
- visited(VISITED_SHIPYARD);
- }
-}
-
-/**
- * @brief Update the shops in the shipyard window.
- * @param wid Window to update the ships in.
- * @param str Unused.
- */
-static void shipyard_update(unsigned int wid, char* str) {
- (void)str;
- char* shipname;
- Ship* ship;
- char buf[PATH_MAX], buf2[16], buf3[16];
-
- shipname = toolkit_getList(wid, "iarShipyard");
-
- /* No ships. */
- if(strcmp(shipname, "None")==0) {
- window_modifyImage(wid, "imgTarget", NULL);
- window_disableButton(wid, "btnBuyShip");
- window_disableButton(wid, "btnInfoShip");
- snprintf(buf, PATH_MAX,
- "None\n"
- "NA\n"
- "NA\n"
- "\n"
- "NA\n"
- "NA\n"
- "NA\n");
- window_modifyText(wid, "txtDDesc", buf);
- return;
- }
-
- ship = ship_get(shipname);
-
- if(player_nships()==0) window_disableButton(wid, "btnYourShips");
- else window_enableButton(wid, "btnYourShips");
-
- window_modifyImage(wid, "imgTarget", ship->gfx_target);
- window_modifyText(wid, "txtDescription", ship->description);
-
- credits2str(buf2, ship->price, 2);
- credits2str(buf3, player->credits, 2);
- snprintf(buf, PATH_MAX,
- "%s\n"
- "%s\n"
- "%s\n"
- "\n"
- "%s SCred\n"
- "%s SCred\n"
- "%s\n",
- ship->name,
- ship_class(ship),
- ship->fabricator,
- buf2,
- buf3,
- (ship->license != NULL) ? ship->license : "None");
-
- window_modifyText(wid, "txtDDesc", buf);
-
- if(ship->price > player->credits)
- window_disableButton(wid, "btnBuyShip");
- else window_enableButton(wid, "btnBuyShip");
-}
-
-/**
- * @brief Open the ships information window.
- * @param wid Window to find out selected ship.
- * @param str Unused.
- */
-static void shipyard_info(unsigned int wid, char* str) {
- (void)str;
- char* shipname;
-
- shipname = toolkit_getList(wid, "iarShipyard");
- ship_view(0, shipname);
-}
-
-/**
- * @brief Player attempts to buy a ship.
- * @param wid Window player is buying ship from.
- * @param str Unused.
- */
-static void shipyard_buy(unsigned int wid, char* str) {
- (void)str;
- char* shipname, buf[16];
- Ship* ship;
-
- shipname = toolkit_getList(wid, "iarShipyard");
- ship = ship_get(shipname);
-
- /* Must have enough money. */
- if(ship->price > player->credits) {
- dialogue_alert("Not enough credits!");
- return;
- }
-
- /* Must have enough credits. */
- if((ship->license != NULL) && !player_hasLicense(ship->license)) {
- dialogue_alert("You do not have the '%s' license required to buy this ship.",
- ship->license);
- return;
- }
-
- if(pilot_cargoUsed(player) > ship->cap_cargo) {
- dialogue_alert("You won't have space to move your current cargo onto the new ship.");
- return;
- }
-
- credits2str(buf, ship->price, 2);
- if(dialogue_YesNo("Are you sure?",
- "Do you really want to spend %s on a new ship?", buf)==0)
- return;
-
- if(player_newShip(ship, player->solid->pos.x, player->solid->pos.y,
- 0., 0., player->solid->dir) != 0) {
- /* Player actually oborted naming process. */
- return;
- }
-
- player->credits -= ship->price; /* Auch! Paying is hard! */
- land_checkAddRefuel();
-
- shipyard_update(wid, NULL);
-}
-
-/**
- * @brief Opens the players ship window.
- * @param parent Unused.
- * @param str Unused.
- */
-static void shipyard_yours_open(unsigned int parent, char* str) {
- (void)str;
- (void)parent;
- char** sships;
- glTexture** tships;
- int nships;
- unsigned int wid;
-
- /* Create window. */
- wid = window_create("Your Ships",
- -1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
-
- /* Buttons. */
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseYourShips",
- "Shipyard", window_close);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnChangeShip",
- "Change Ship", shipyard_yoursChange);
-
- window_addButton(wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnTransportShip",
- "Transport Ship", shipyard_yoursTransport);
-
- window_addButton(wid, -20, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellShip",
- "Sell Ship", shipyard_yoursSell);
-
- /* Image. */
- window_addRect(wid, -40, -50,
- 128, 96, "rctTarget", &cBlack, 0);
-
- window_addImage(wid, -40-128, -50-96,
- "imgTarget", NULL, 1);
-
- /* Text. */
- window_addText(wid, 40+300+40, -55,
- 100, 200, 0, "txtSDesc", &gl_smallFont, &cDConsole,
- "Name:\n"
- "Ship:\n"
- "Class:\n"
- "Location:\n"
- "\n"
- "Cargo free:\n"
- "Weapons free\n"
- "\n"
- "Transportation\n"
- "Sell price\n");
-
- window_addText(wid, 40+300+40+100, -55,
- 130, 200, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
-
- window_addText(wid, 40+300+40, -255,
- 100, 20, 0, "txtSOutfits", &gl_smallFont, &cDConsole,
- "Outfits:\n");
-
- window_addText(wid, 40+300+40, -255-gl_smallFont.h-5,
- SHIPYARD_WIDTH-40-300-40-20, 200, 0, "txtDOutfits",
- &gl_smallFont, &cBlack, NULL);
-
- /* Ship list. */
- nships = MAX(1, player_nships());
- sships = malloc(sizeof(char*)*nships);
- tships = malloc(sizeof(glTexture*)*nships);
- player_ships(sships, tships);
- window_addImageArray(wid, 20, 40,
- 310, SHIPYARD_HEIGHT-80, "lstYourShips", 64./96.*128., 64.,
- tships, sships, nships, shipyard_yoursUpdate);
-
- shipyard_yoursUpdate(wid, NULL);
-}
-
-/**
- * @brief Update the players ship window.
- * @param wid Window to update.
- * @param str Unused.
- */
-static void shipyard_yoursUpdate(unsigned int wid, char* str) {
- (void)str;
- char buf[256], buf2[16], buf3[16], *buf4;
- char* shipname;
- Pilot* ship;
- char* loc;
- unsigned int price;
-
- shipname = toolkit_getList(wid, "lstYourShips");
- if(strcmp(shipname, "None")==0) {
- /* No ships. */
- window_disableButton(wid, "btnChangeShip");
- window_disableButton(wid, "btnTransportShip");
- window_disableButton(wid, "btnSellShip");
- return;
- }
- ship = player_getShip(shipname);
- loc = player_getLoc(ship->name);
- price = shipyard_yoursTransportPrice(shipname);
-
- /* Update the image. */
- window_modifyImage(wid, "imgTarget", ship->ship->gfx_target);
-
- /* Update text. */
- credits2str(buf2, price, 2); /* Transport. */
- credits2str(buf3, player_shipPrice(shipname), 2); /* Sell price. */
-
- snprintf(buf, 256,
- "%s\n"
- "%s\n"
- "%s\n"
- "%s\n"
- "\n"
- "%d tons\n"
- "%d tons\n"
- "\n"
- "%s scred\n"
- "%s scred\n",
- ship->name,
- ship->ship->name,
- ship_class(ship->ship),
- loc,
- pilot_cargoFree(ship),
- pilot_freeSpace(ship),
- buf2,
- buf3);
-
- window_modifyText(wid, "txtDDesc", buf);
-
- buf4 = pilot_getOutfits(ship);
- window_modifyText(wid, "txtDOutfits", buf4);
- free(buf4);
-
- /* Button disabling. */
- if(strcmp(land_planet->name, loc)) {
- /* Ship not here. */
- window_disableButton(wid, "btnChangeShip");
- if(price > player->credits)
- window_disableButton(wid, "btnTransportShip");
- else window_enableButton(wid, "btnTransportShip");
- } else {
- window_enableButton(wid, "btnChangeShip");
- window_disableButton(wid, "btnTransportShip");
- }
- /* If ship is there you can always sell. */
- window_enableButton(wid, "btnSellShip");
-}
-
-/**
- * @brief Player attempts to change the ship.
- * @param wid Window player is attempting to change ships in.
- * @param str Unused.
- */
-static void shipyard_yoursChange(unsigned int wid, char* str) {
- (void)str;
- char* shipname, *loc;
- Pilot* newship;
-
- shipname = toolkit_getList(wid, "lstYourShips");
- newship = player_getShip(shipname);
- if(strcmp(shipname, "None")==0) {
- /* No ships. */
- dialogue_alert("You need another ship to change to!");
- return;
- }
-
- loc = player_getLoc(shipname);
-
- if(strcmp(loc, land_planet->name)) {
- dialogue_alert("You must transport the ship to %s to be able to get in.",
- land_planet->name);
- return;
- }
- else if(pilot_cargoUsed(player) > pilot_cargoFree(newship)) {
- dialogue_alert("You won't be able to fit your current cago in the new ship.");
- return;
- }
-
- player_swapShip(shipname);
-
- /* Recreate the window. */
- window_destroy(wid);
- shipyard_yours_open(0, NULL);
-}
-
-/**
- * @brief Player tries to sell a ship.
- * @param wid Window player is selling ships in.
- * @param str Unused.
- */
-static void shipyard_yoursSell(unsigned int wid, char* str) {
- (void)str;
- char* shipname, buf[16];
- int price;
-
- shipname = toolkit_getList(wid, "lstYourShips");
- if(strcmp(shipname, "None")==0) { /* No ships. */
- dialogue_alert("You can't sell nothing!");
- return;
- }
-
- /* Calculate price. */
- price = player_shipPrice(shipname);
- credits2str(buf, price, 2);
-
- /* Check if player really wants to sell. */
- if(!dialogue_YesNo("Sell Ship",
- "Are you sure you wish to sell your ship %s for %s SCred?", shipname, buf)) {
- return;
- }
-
- /* Sold. */
- player->credits += price;
- land_checkAddRefuel();
- player_rmShip(shipname);
- dialogue_msg("Ship Sold", "You have sold your ship %s for %s SCred.",
- shipname, buf);
-
- /* Recreate the window. */
- window_destroy(wid);
- shipyard_yours_open(0, NULL);
-}
-
-/**
- * @brief Player attempts to transport her ship to the planet she's at.
- * @param wid Window player is trying to transport her ship from.
- * @param str Unused.
- */
-static void shipyard_yoursTransport(unsigned int wid, char* str) {
- (void)str;
- unsigned int price;
- char* shipname, buf[16];
-
- shipname = toolkit_getList(wid, "lstYourShips");
- if(strcmp(shipname, "None")==0) { /* No ships. */
- dialogue_alert("You can't transport nothing here!");
- return;
- }
-
- price = shipyard_yoursTransportPrice(shipname);
- if(price == 0) {
- /* Already here. */
- dialogue_alert("Your ship '%s' is already here.", shipname);
- return;
- }
- else if(player->credits < price) {
- /* You are broke. */
- credits2str(buf, price-player->credits, 2);
- dialogue_alert("You need %d more credits to transport '%s' here.",
- buf, shipname);
- return;
- }
-
- /* Success. */
- player->credits -= price;
- land_checkAddRefuel();
- player_setLoc(shipname, land_planet->name);
-
- /* Update the window to reflect the change. */
- shipyard_yoursUpdate(wid, NULL);
-}
-
-/**
- * @brief Get the ships transport price.
- * @param shipname Name of the ship to get the transport price.
- * @return The price to transport the ship to the current planet.
- */
-static unsigned int shipyard_yoursTransportPrice(char* shipname) {
- char* loc;
- Pilot* ship;
- unsigned int price;
-
- ship = player_getShip(shipname);
- loc = player_getLoc(shipname);
- if(strcmp(loc, land_planet->name)==0) /* Already here. */
- return 0;
-
- price = (unsigned int)(sqrt(ship->solid->mass)*5000.);
-
- return price;
-}
-
-/**
- * @brief Open the spaceport bar window.
- */
-static void spaceport_bar_open(void) {
- unsigned int wid;
-
- wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
-
- window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnCloseBar", "Close", window_close);
-
- window_addButton(wid, 20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
- "News", (void(*)(unsigned int,char*))news_open);
-
- window_addText(wid, 20, -30,
- BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
- "txtDescription", &gl_smallFont, &cBlack,
- land_planet->bar_description);
-
- if(!has_visited(VISITED_BAR)) {
- missions_run(MIS_AVAIL_BAR, land_planet->faction, land_planet->name, cur_system->name);
- visited(VISITED_BAR);
- }
-}
-
-/**
- * @brief Open the planetary news reports window.
- */
-static void news_open(unsigned int parent, char* str) {
- (void)parent;
- (void)str;
- unsigned int wid;
-
- wid = window_create("News Reports",
- -1, -1, NEWS_WIDTH, NEWS_HEIGHT);
-
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnCloseNews", "Close", window_close);
-
- window_addText(wid, 20, 20 + BUTTON_HEIGHT + 20,
- NEWS_WIDTH-40, NEWS_HEIGHT - 20 - BUTTON_HEIGHT - 20 - 20 -20,
- 0, "txtNews", &gl_smallFont, &cBlack,
- "News reporters report that they are on strike right now! D:");
-}
-
-/**
- * @brief Open the mission computer window.
- */
-static void misn_open(void) {
- unsigned int wid;
-
- wid = window_create("Mission Computer",
- -1, -1, MISSION_WIDTH, MISSION_HEIGHT);
-
- /* Buttons. */
- window_addButton(wid, -20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseMission",
- "Close", misn_close);
-
- window_addButton(wid, -20, 40+BUTTON_HEIGHT,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnAcceptMission",
- "Accept", misn_accept);
-
- /* Text. */
- window_addText(wid, 300+40, -60,
- 300, 40, 0, "txtSReward",
- &gl_smallFont, &cDConsole, "Reward:");
-
- window_addText(wid, 300+100, -60,
- 240, 40, 0, "txtReward", &gl_smallFont, &cBlack, NULL);
-
- window_addText(wid, 300+40, -100,
- 300, MISSION_HEIGHT - BUTTON_WIDTH - 120, 0,
- "txtDesc", &gl_smallFont, &cBlack, NULL);
-
- misn_genList(wid, 1);
-}
-
-/**
- * @brief Close the mission computer window.
- * @param wid Window to close.
- * @param name Unused.
- */
-static void misn_close(unsigned int wid, char* name) {
- /* Remove computer markers just in case. */
- space_clearComputerMarkers();
- window_close(wid, name);
-}
-
-/**
- * @brief Accepts the selected mission.
- * @param wid Window of the mission computer.
- * @param str Unused.
- */
-static void misn_accept(unsigned int wid, char* str) {
- (void)str;
- char* misn_name;
- Mission* misn;
- int pos;
- int i;
-
- misn_name = toolkit_getList(wid, "lstMission");
-
- /* Make sure you have missions. */
- if(strcmp(misn_name, "No Missions")==0)
- return;
-
- /* Make sure player can accept the mission. */
- for(i = 0; i < MISSION_MAX; i++)
- if(player_missions[i].data == NULL) break;
- if(i >= MISSION_MAX) {
- dialogue_alert("You have too many active missions.");
- return;
- }
-
- if(dialogue_YesNo("Accept Mission",
- "Are you sure you want to accept this mission?")) {
- pos = toolkit_getListPos(wid, "lstMission");
- misn = &mission_computer[pos];
- if(mission_accept(misn)) {
- /* Success is accepting the mission. */
- memmove(&mission_computer[pos], &mission_computer[pos+1],
- sizeof(Mission) * (mission_ncomputer-pos-1));
- mission_ncomputer--;
- misn_genList(wid, 0);
- }
- }
-}
-
-/**
- * @brief Generates the mission list.
- * @param wid Window to generate the mission list for.
- * @param first Is it the first time generated?
- */
-static void misn_genList(unsigned int wid, int first) {
- int i, j;
- char** misn_names;
-
- if(!first)
- window_destroyWidget(wid, "lstMission");
-
- /* List. */
- j = 1; /* Make sure we don't accidently free the memory twise. */
- if(mission_ncomputer > 0) {
- /* there are missions. */
- misn_names = malloc(sizeof(char*) * mission_ncomputer);
- j = 0;
- for(i = 0; i < mission_ncomputer; i++)
- if(mission_computer[i].title != NULL)
- misn_names[j++] = strdup(mission_computer[i].title);
- }
- if((mission_ncomputer==0) || (j == 0)) { /* No missions. */
- if(j == 0)
- free(misn_names);
- misn_names = malloc(sizeof(char*));
- misn_names[0] = strdup("No Missions");
- }
-
- window_addList(wid, 20, -40,
- 300, MISSION_HEIGHT-60,
- "lstMission", misn_names, j, 0, misn_update);
-
- misn_update(wid, NULL);
-}
-
-/**
- * @brief Update the mission list.
- * @param wid Window of the mission computer.
- * @param str Unused.
- */
-static void misn_update(unsigned int wid, char* str) {
- (void)str;
- char* active_misn;
- Mission* misn;
-
- active_misn = toolkit_getList(wid, "lstMission");
- if(strcmp(active_misn, "No Missions")==0) {
- window_modifyText(wid, "txtReward", "None");
- window_modifyText(wid, "txtDesc",
- "There are no missions available here.");
-
- window_disableButton(wid, "btnAcceptMission");
- return;
- }
- misn = &mission_computer[toolkit_getListPos(wid, "lstMission")];
- mission_sysComputerMark(misn);
- window_modifyText(wid, "txtReward", misn->reward);
- window_modifyText(wid, "txtDesc", misn->desc);
- window_enableButton(wid, "btnAcceptMission");
-}
-
-/**
- * @brief Get the cost to refuel.
- * @return Refuel price.
- */
-static unsigned int refuel_price(void) {
- return (unsigned int)((player->fuel_max - player->fuel)*3);
-}
-
-/**
- * @brief Refuel the player.
- * @param wid Land window.
- * @param str Unused.
- */
-static void spaceport_refuel(unsigned int wid, char* str) {
- (void)str;
-
- if(player->credits < refuel_price()) {
- /* Player is out of moniez after landing D: */
- dialogue_alert("You seem to not have enough scred to refuel your ship.");
- return;
- }
-
- player->credits -= refuel_price();
- player->fuel = player->fuel_max;
- window_destroyWidget(wid, "btnRefuel");
-}
-
-/**
- * @brief Check if should add the refuel button and does if needed.
- */
-static void land_checkAddRefuel(void) {
- char buf[32], cred[16];
-
- /* Check to see if fuel conditions are met. */
- if(!planet_hasService(land_planet, PLANET_SERVICE_BASIC))
- return;
-
- /* Full fuel. */
- if(player->fuel >= player->fuel_max)
- return;
-
- /* Just enable button if it exists. */
- if(widget_exists(land_wid, "btnRefuel")) {
- window_enableButton(land_wid, "btnRefuel");
- } else { /* Create it. */
- credits2str(cred, refuel_price(), 2);
- snprintf(buf, 32, "Refuel %s", cred);
- window_addButton(land_wid, -20, 20+2*(BUTTON_HEIGHT+20),
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnRefuel",
- buf, spaceport_refuel);
- }
-
- /* Make sure player can click it. */
- if(player->credits < refuel_price())
- window_disableButton(land_wid, "btnRefuel");
-}
-
-/* Land the player. */
-void land(Planet* p) {
- glTexture* logo;
- int offset;
-
- if(landed) return;
-
- /* Load stuff. */
- land_planet = p;
- gfx_exterior = gl_newImage(p->gfx_exterior, 0);
- land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT);
-
- /* Faction logo. */
- offset = 20;
- if(land_planet->faction != -1) {
- logo = faction_logoSmall(land_planet->faction);
- if(logo != NULL) {
- window_addImage(land_wid, 440 + (LAND_WIDTH-460-logo->w)/2, -20,
- "imgFaction", logo, 0);
- offset = 84;
- }
- }
-
- /* Pretty display. */
- window_addImage(land_wid, 20, -40, "imgPlanet", gfx_exterior, 1);
- window_addText(land_wid, 440, -20-offset,
- LAND_WIDTH-460, LAND_HEIGHT-20-offset-60-BUTTON_HEIGHT*2, 0,
- "txtPlanetDesc", &gl_smallFont, &cBlack, p->description);
- /* Buttons. */
- window_addButton(land_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnTakeoff", "Takeoff", (void(*)(unsigned int,char*))takeoff);
-
- if(planet_hasService(land_planet, PLANET_SERVICE_COMMODITY))
- window_addButton(land_wid, -20, 20 + BUTTON_HEIGHT + 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodity",
- "Commodity Exchange", (void(*)(unsigned int,char*))commodity_exchange_open);
-
- if(planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
- window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnShipyard",
- "Shipyard", (void(*)(unsigned int,char*))shipyard_open);
-
- if(planet_hasService(land_planet, PLANET_SERVICE_OUTFITS))
- window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20 + BUTTON_HEIGHT + 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits",
- "Outfits", (void(*)(unsigned int,char*))outfits_open);
-
- /* Third column. */
- if(planet_hasService(land_planet, PLANET_SERVICE_BASIC)) {
- window_addButton(land_wid, 20, 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
- "Mission Terminal", (void(*)(unsigned int,char*))misn_open);
-
- window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
- BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",
- "Spaceport Bar", (void(*)(unsigned int,char*))spaceport_bar_open);
- }
-
- /* Player is now officailly landed. */
- landed = 1;
-
- /* Change the music. */
- music_choose("land");
-
- /* Run hooks, run after music in case hook wants to change music. */
- hooks_run("land");
-
- /* Generate mission computer stuff. */
- mission_computer = missions_computer(&mission_ncomputer,
- land_planet->faction, land_planet->name, cur_system->name);
-
- /* Check land missions. */
- if(!has_visited(VISITED_LAND)) {
- missions_run(MIS_AVAIL_LAND, land_planet->faction,
- land_planet->name, cur_system->name);
- visited(VISITED_LAND);
- }
-
- /* Add fuel button if needed - AFTER missions pay :D. */
- land_checkAddRefuel();
-
- /* Mission forced take off. */
- if(landed == 0) {
- landed = 1; /* Ugly hack to make takeoff not complain. */
- takeoff();
- }
-}
-
-/* Takeoff from the planet. */
-void takeoff(void) {
- int sw, sh, i, h;
- char* lt;
-
- if(!landed) return;
-
- /* The music. */
- music_choose("takeoff");
-
- sw = land_planet->gfx_space->w;
- sh = land_planet->gfx_space->h;
-
- /* No longer authorized to land. */
- player_rmFlag(PLAYER_LANDACK);
-
- /* Set player to another position with random facing direction and no velocity. */
- player_warp(land_planet->pos.x + RNG(-sw/2, sw/2),
- land_planet->pos.y + RNG(-sh/2, sh/2));
- vect_pset(&player->solid->vel, 0., 0.);
- player->solid->dir = RNG(0, 359) * M_PI/180.;
-
- /* Heal the player. */
- player->armour = player->armour_max;
- player->shield = player->shield_max;
- player->energy = player->energy_max;
-
- /* Time goes by, triggers hook before takeoff. */
- ltime_inc(RNG(2*LTIME_UNIT_LENGTH, 3*LTIME_UNIT_LENGTH));
- lt = ltime_pretty(0);
- player_message("taking off from %s on %s.", land_planet->name, lt);
- free(lt);
-
- /* Initialize the new space. */
- h = hyperspace_target;
- space_init(NULL);
- hyperspace_target = h;
-
- /* Cleanup. */
- if(save_all() < 0) { /* Must be before cleaning up planet. Duh! */
- dialogue_alert("Failed to save game! You should exit and check the log to \
- see what happened and then file a bug report!");
- }
- land_cleanup(); /* Cleanup stuff. */
- hooks_run("takeoff"); /* Must be run after cleanup sine we don't want the
- missions to think we are landed. */
- hooks_run("enter");
-
- /* Cleanup mission computer. */
- for(i = 0; i < mission_ncomputer; i++)
- mission_cleanup(&mission_computer[i]);
- free(mission_computer);
- mission_computer = NULL;
- mission_ncomputer = 0;
-}
-
-/**
- * @brief Cleans up some land-related variables.
- */
-void land_cleanup(void) {
- /* Clean up default stuff. */
- land_planet = NULL;
- landed = 0;
- land_visited = 0;
-
- /* Destroy window. */
- if(land_wid > 0) {
- window_destroy(land_wid);
- land_wid = 0;
- }
-
- /* Clean up possible stray graphic. */
- if(gfx_exterior != NULL) {
- gl_freeTexture(gfx_exterior);
- gfx_exterior = NULL;
- }
-}
-
diff --git a/src/land.h b/src/land.h
deleted file mode 100644
index 7ff7845..0000000
--- a/src/land.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-#include "space.h"
-
-extern int landed;
-extern Planet* land_planet;
-
-void land(Planet* p);
-void takeoff(void);
-void land_cleanup(void);
-
diff --git a/src/lcompat.h b/src/lcompat.h
deleted file mode 100644
index 132fd2d..0000000
--- a/src/lcompat.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-/* System specific. */
-#define HAS_LINUX (defined(linux) || defined(__linux) || defined(__linux__))
-#define HAS_FREEBSD (defined(__FreeBSD__))
-#define HAS_HAS_WIN32 (defined(__WIN32))
-
-/* Standard specific. */
-#define HAS_POSIX HAS_UNIX /* (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L)) */
-#define HAS_UNIX (defined(__unix__) || defined(__unix))
-
diff --git a/src/ldata.c b/src/ldata.c
deleted file mode 100644
index 4e242d3..0000000
--- a/src/ldata.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/**
- * @file ldata.c
- *
- * @brief Wrapper to handle reading/writing the ldata file.
- *
- * Optimizes to minimize the opens and frees, plus tries to read from the
- * filesystem instead of always looking for a packfile.
- */
-
-#include "SDL.h"
-
-#include "lephisto.h"
-#include "log.h"
-#include "md5.h"
-#include "lxml.h"
-#include "pack.h"
-#include "lfile.h"
-#include "ldata.h"
-
-#define LDATA_FILENAME "ldata" /**< Generic ldata file name. */
-#ifndef LDATA_DEF
-#define LDATA_DEF LDATA_FILENAME /**< Default ldata to use. */
-#endif
-
-#define XML_START_ID "Start" /**< XML document tag of module start file. */
-#define START_DATA "../dat/start.xml" /**< Path to module start file. */
-
-/* Packfile. */
-static char* ldata_filename = NULL; /**< Packfile name. */
-static Packcache_t* ldata_cache = NULL; /**< Actual packfile. */
-static char* ldata_packName = NULL; /**< Name of the ldata module. */
-
-/* File list. */
-static const char** ldata_fileList = NULL; /**< List of the files in the packfile. */
-static uint32_t ldata_fileNList = 0; /**< Number of files in ldata_fileList. */
-
-static char** filterList(const char** list, int nlist,
- const char* path, uint32_t* nfiles);
-
-/**
- * @brief Check to see if path is an ldata file.
- *
- * Should be called before ldata_open.
- * @param path Path to check to see if it's an ldata file.
- * @return 1 if it is an ldata file, otherwise 0.
- */
-int ldata_check(char* path) {
- return pack_check(path);
-}
-
-/**
- * @brief Set the current ldata path to use.
- *
- * Should be called before ldata_open
- * @param path Path to set.
- * @return 0 on success.
- */
-int ldata_setPath(char* path) {
- if(ldata_filename != NULL)
- free(ldata_filename);
- ldata_filename = (path == NULL) ? NULL : strdup(path);
- return 0;
-}
-
-/**
- * @brief Open a packfile if needed.
- * @return 0 on success.
- */
-static int ldata_openPackfile(void) {
- int i;
- char** files;
- int nfiles;
- size_t len;
-
- /* Try to find the ldata file. */
- if(ldata_filename == NULL) {
- /* Check ldata with version appended. */
- if(lfile_fileExists("%s-%d.%d.%d", LDATA_FILENAME, VMAJOR, VMINOR, VREV)) {
- ldata_filename = malloc(PATH_MAX);
- snprintf(ldata_filename, PATH_MAX, "%s-%d.%d.%d",
- LDATA_FILENAME, VMAJOR, VMINOR, VREV);
- }
- /* Check default ldata. */
- else if(lfile_fileExists(LDATA_DEF))
- ldata_filename = strdup(LDATA_DEF);
- /* Try to open any ldata in path. */
- else {
- files = lfile_readDir(&nfiles, ".");
- len = strlen(LDATA_FILENAME);
- for(i = 0; i < nfiles; i++) {
- if(strncmp(files[i], LDATA_FILENAME, len)==0) {
- /* Must be a packfile. */
- if(pack_check(files[i]))
- continue;
-
- ldata_filename = strdup(files[i]);
- break;
- }
- }
- /* Clean up. */
- for(i = 0; i < nfiles; i++)
- free(files[i]);
- free(files);
- }
- }
-
- /* Open the cache. */
- if(lfile_fileExists(ldata_filename) != 1) {
- WARN("Cannot find ldata file!");
- WARN("Please specify ldata file with -d or data in the conf file.");
- exit(1);
- return -1;
- }
- ldata_cache = pack_openCache(ldata_filename);
- if(ldata_cache == NULL)
- WARN("Unalbe to create Packcache from '%s'.", ldata_filename);
-
- return 0;
-}
-
-/**
- * @brief Open the ldata file.
- * @return 0 on success.
- */
-int ldata_open(void) {
- return 0;
-}
-
-/**
- * @brief Close and clean up the ldata file.
- */
-void ldata_close(void) {
- /* Destroy the name. */
- if(ldata_packName != NULL) {
- free(ldata_packName);
- ldata_packName = NULL;
- }
-
- /* Destroy the list. */
- if(ldata_fileList != NULL) {
- /* No need to free memory since cache does that. */
- ldata_fileList = NULL;
- ldata_fileNList = 0;
- }
-
- /* Close the packfile. */
- if(ldata_cache) {
- pack_closeCache(ldata_cache);
- ldata_cache = NULL;
- }
-}
-
-/**
- * @brief Get the ldata's name.
- *
- * Thread safe (uses ldata_read).
- * @return The ldata's name.
- */
-const char* ldata_name(void) {
- char* buf;
- uint32_t size;
- xmlNodePtr node;
- xmlDocPtr doc;
-
- /* Alreay loaded. */
- if(ldata_packName != NULL)
- return ldata_packName;
-
- /* We'll just read it and parse it. */
- buf = ldata_read(START_DATA, &size);
- doc = xmlParseMemory(buf, size);
-
- /* Make sure it's what we are looking for. */
- node = doc->xmlChildrenNode;
- if(!xml_isNode(node, XML_START_ID)) {
- ERR("Malformed '"START_DATA"' file: missing root element '"XML_START_ID"'");
- return NULL;
- }
-
- /* Check if node is valid. */
- node = node->xmlChildrenNode; /* First system node. */
- if(node == NULL) {
- ERR("Malformed '"START_DATA"' file: does not contain elements");
- return NULL;
- }
- do {
- xmlr_strd(node, "name", ldata_packName);
- } while(xml_nextNode(node));
-
- xmlFreeDoc(doc);
- free(buf);
-
- /* Check if data name is found. */
- if(ldata_packName == NULL)
- WARN("No ldata packname found.");
-
- return ldata_packName;
-}
-
-/**
- * @brief Read a file from the ldata.
- * @param filename Name of the file to read.
- * @param[out] filesize Stores the size of the file.
- * @return The file data or NULL on error.
- */
-void* ldata_read(const char* filename, uint32_t* filesize) {
- char* buf;
- int nbuf;
- /* See if needs to load the packfile. */
- if(ldata_cache == NULL) {
- /* Try to read the file as locally. */
- buf = lfile_readFile(&nbuf, filename);
- if(buf != NULL) {
- *filesize = nbuf;
- return buf;
- }
-
- /* Load the packfile. */
- ldata_openPackfile();
- }
-
- /* Get data from packfile. */
- return pack_readfileCached(ldata_cache, filename, filesize);
-}
-
-/**
- * @brief Create an rwops from a file in the ldata.
- * @param filename Name of the file create rwops of.
- * @retuen rwops that accesses the file in the ldata.
- */
-SDL_RWops* ldata_rwops(const char* filename) {
- SDL_RWops* rw;
-
- if(ldata_cache == NULL) {
- /* Try to open from file. */
- rw = SDL_RWFromFile(filename, "rb");
- if(rw != NULL)
- return rw;
-
- /* Load the packfile. */
- ldata_openPackfile();
- }
-
- return pack_rwopsCached(ldata_cache, filename);
-}
-
-/**
- * @brief Filter a file list to match path.
- *
- * Uses read only data, should be thread safe.
- *
- * @param list List to filter.
- * @param nlist Members in list.
- * @param path Path to filter.
- * @param[out] nfiles Files that match.
- */
-static char** filterList(const char** list, int nlist,
- const char* path, uint32_t* nfiles) {
-
- char** filtered;
- int i, j, k;
- int len;
-
- /* Maximum size by default. */
- filtered = malloc(sizeof(char*) * nlist);
- len = strlen(path);
-
- /* Filter list. */
- j = 0;
- for(i = 0; i < nlist; i++) {
- /* Must match path. */
- if(strncmp(list[i], path, len) != 0)
- continue;
-
- /* Make sure there are no stray '/'. */
- for(k = len; list[i][k] != '\0'; k++)
- if(list[i][k] != '/')
- break;
- if(list[i][k] != '\0')
- continue;
-
- /* Copy the file name without the path. */
- filtered[j++] = strdup(&list[i][len]);
- }
-
- /* Return results. */
- *nfiles = j;
- return filtered;
-}
-
-/**
- * @brief Get the list of files in the ldata.
- * @param path List files in path.
- * @param nfiles Number of files found.
- * @return List of files found.
- */
-char** ldata_list(const char* path, uint32_t* nfiles) {
- (void)path;
- char** files;
- int n;
-
- /* Already loaded the list. */
- if(ldata_fileList != NULL)
- return filterList(ldata_fileList, ldata_fileNList, path, nfiles);
-
- /* See if we can load from local directory. */
- if(ldata_cache == NULL) {
- files = lfile_readDir(&n, path);
-
- /* Found locally. */
- if(files != NULL) {
- *nfiles = n;
- return files;
- }
-
- /* Open packfile. */
- ldata_openPackfile();
- }
-
- /* Load list. */
- ldata_fileList = pack_listfilesCached(ldata_cache, &ldata_fileNList);
-
- return filterList(ldata_fileList, ldata_fileNList, path, nfiles);
-}
-
diff --git a/src/ldata.h b/src/ldata.h
deleted file mode 100644
index 56ad270..0000000
--- a/src/ldata.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-#include
-
-#include "SDL.h"
-
-/* ldata open/close. */
-int ldata_open(void);
-void ldata_close(void);
-
-/* General. */
-int ldata_check(char* path);
-int ldata_setPath(char* path);
-const char* ldata_name(void);
-
-/* Individual file functions. */
-void* ldata_read(const char* filename, uint32_t* filesize);
-char** ldata_list(const char* path, uint32_t* nfiles);
-
-/* RWops. */
-SDL_RWops* ldata_rwops(const char* filename);
-
diff --git a/src/lephisto.c b/src/lephisto.c
deleted file mode 100644
index 0d42234..0000000
--- a/src/lephisto.c
+++ /dev/null
@@ -1,700 +0,0 @@
-/**
- * @mainpage LEPHISTO
- *
- * Doxygen documentation for the Lephisto project. (c) SaraCraft.
- */
-/**
- * @file lephisto.c
- *
- * @brief Control the overall game flow: data loading/unloading and game loop.
- */
-
-#include
-
-#include "lcompat.h"
-
-/* Global. */
-#include
-#if HAS_LINUX && defined(DEBUG) /* DEBUGGING isn't defined yet. */
-#include
-#include
-#include
-#include
-#endif /* HAS_LINUX && defined(DEBUG) */
-
-/* Local. */
-#include "lephisto.h"
-#include "conf.h"
-#include "log.h"
-#include "physics.h"
-#include "opengl.h"
-#include "font.h"
-#include "ship.h"
-#include "pilot.h"
-#include "fleet.h"
-#include "player.h"
-#include "input.h"
-#include "joystick.h"
-#include "space.h"
-#include "rng.h"
-#include "ai.h"
-#include "outfit.h"
-#include "ldata.h"
-#include "weapon.h"
-#include "faction.h"
-#include "lxml.h"
-#include "pause.h"
-#include "toolkit.h"
-#include "pilot.h"
-#include "sound.h"
-#include "music.h"
-#include "spfx.h"
-#include "economy.h"
-#include "menu.h"
-#include "mission.h"
-#include "llua_misn.h"
-#include "lfile.h"
-#include "unidiff.h"
-#include "gui.h"
-#include "nebulae.h"
-
-
-#define CONF_FILE "conf" /**< Configuration file by default. */
-#define VERSION_FILE "VERSION" /**< Version file by default. */
-#define VERSION_LEN 10 /**< Max length of the version file. */
-#define FONT_SIZE 12 /**< Normal font size. */
-#define FONT_SIZE_SMALL 10 /**< Small font size. */
-
-#define LEPHISTO_INIT_DELAY 3000 /**< Minimum amount of time to wait with loading screen. */
-
-static int quit = 0; /**< For primary loop. */
-static unsigned int time = 0; /**< Used to calculate FPS and movement. */
-static char version[VERSION_LEN]; /**< Contains version. */
-static glTexture* loading; /**< Loading screen. */
-
-/* Some defaults. */
-int nosound = 0; /**< Disable sound when loaded. */
-int show_fps = 1; /**< Shows fps - default true. */
-int max_fps = 0; /**< Default FPS limit, 0 is no limit. */
-int indjoystick = -1; /**< Index of joystick to use, -1 is none. */
-char* namjoystick = NULL; /**< Name of joystick to use, NULL is none. */
-
-/* Prototypes. */
-/* Loading. */
-static void print_SDLversion(void);
-static void loadscreen_load(void);
-void loadscreen_render(double done, const char* msg); /* nebulae.c */
-static void loadscreen_unload(void);
-static void load_all(void);
-static void unload_all(void);
-static void display_fps(const double dt);
-static void window_caption(void);
-static void debug_sigInit(void);
-/* Update. */
-static void fps_control(void);
-static void update_all(void);
-static void update_routine(double dt);
-static void render_all(void);
-/* Misc. */
-void main_loop(void); /* dialogue.c */
-
-
-/**
- * @brief The entry point of Lephisto.
- *
- * @param[in] argc Number of arguments.
- * @param[in] argv Array of argc arguments.
- * @return EXIT_SUCCESS on success.
- */
-#ifdef WIN32
-int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine,
- int nCmdShow) {
- int argc = 0;
- char *argv[] = { NULL };
-#else
-int main(int argc, char** argv) {
-#endif
-
- char buf[PATH_MAX];
-
- /* Print the version. */
- snprintf(version, VERSION_LEN, "%d.%d.%d", VMAJOR, VMINOR, VREV);
- LOG("\n "APPNAME" - Dark Tides v%s", version);
- LOG(" ----------------------------\n");
-
- /* Initialize SDL for possible warnings. */
- SDL_Init(0);
-
- /* Set up debug signal handlers. */
- debug_sigInit();
-
- /* Create the home directory if needed. */
- if(lfile_dirMakeExist("%s", lfile_basePath()))
- WARN("Unable to create lephisto directory '%s'", lfile_basePath());
-
- /* Must be initialized befre input init is called. */
- if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
- WARN("Unable to initialize SDL video: %s", SDL_GetError());
- return -1;
- }
-
- /* Input must be initialized for config to work. */
- input_init();
-
- /* Set the configuration. */
- snprintf(buf, PATH_MAX, "%s"CONF_FILE, lfile_basePath());
- conf_setDefaults(); /* Default config values. */
- conf_loadConfig(buf); /* Have Lua parse config. */
- conf_parseCLI(argc, argv); /* Parse CLI arguments. */
-
- /* Open the data. */
- if(ldata_open() != 0)
- ERR("Failed to open ldata.");
-
- /* Load the data basics. */
- LOG(" %s", ldata_name());
- DEBUG();
-
- /* Display the SDL Version. */
- print_SDLversion();
- DEBUG();
-
- /* Random numbers. */
- rng_init();
-
- /* OpenGL */
- if(gl_init()) { /* Init video output. */
- ERR("Initializing video output failed, exiting...");
- SDL_Quit();
- exit(EXIT_FAILURE);
- }
-
- gl_fontInit(NULL, NULL, FONT_SIZE); /* Initializes default font size. */
- gl_fontInit(&gl_smallFont, NULL, FONT_SIZE_SMALL); /* Small font. */
- window_caption();
-
- /* Display the load screen. */
- loadscreen_load();
- loadscreen_render(0., "Initializing subsystems...");
- time = SDL_GetTicks();
-
- /* Input. */
- if((indjoystick >= 0) || (namjoystick != NULL)) {
- if(joystick_init())
- WARN("Error initializing joystick input");
- if(namjoystick != NULL) {
- /* Use a joystick name to find joystick. */
- if(joystick_use(joystick_get(namjoystick))) {
- WARN("Failure to open any joystick, falling back to default keybinds");
- input_setDefault();
- }
- free(namjoystick);
- }
- else if(indjoystick >= 0)
- /* Must be using an id instead. */
- if(joystick_use(indjoystick)) {
- WARN("Failure to open any joystick, falling back to default keybinds");
- input_setDefault();
- }
- }
-
- /* OpenAL sound. */
- if(nosound) {
- LOG("Sound is disabled!");
- sound_disabled = 1;
- music_disabled = 1;
- }
- if(sound_init()) WARN("Problem setting up sound!");
- music_choose("load");
-
- /* Misc. */
- if(ai_init())
- WARN("Error initializing AI");
-
- /* Misc graphics init stuff. */
- if(nebu_init() != 0) { /* Init the nebulae. */
- /* An error happened. */
- ERR("Unable to init the Nebulae subsystem!");
- /* Weirdness will accur. */
- }
- gui_init(); /* Init the GUI crap. */
- toolkit_init(); /* Init the toolkit. */
-
- /* Data loading. */
- load_all();
-
- /* Unload load screen. */
- loadscreen_unload();
-
- /* Start menu. */
- menu_main();
-
- /* Force a minimum delay with loading screen. */
- if((SDL_GetTicks() - time) < LEPHISTO_INIT_DELAY)
- SDL_Delay(LEPHISTO_INIT_DELAY - (SDL_GetTicks() - time));
- time = SDL_GetTicks(); /* Init the time. */
-
- /* Main loop. */
- SDL_Event event;
- /* Flushes the event loop, since I notices that when the joystick is loaded, it */
- /* creates button events that results in the player starting out accelerating. */
- while(SDL_PollEvent(&event));
- while(!quit) {
- /* Event loop. */
- while(SDL_PollEvent(&event)) {
- if(event.type == SDL_QUIT) quit = 1; /* Handle quit. */
-
- input_handle(&event); /* handles all the events the player keybinds. */
- }
- main_loop();
- }
-
- /* Clean up some stuff. */
- player_cleanup(); /* Cleans up the player stuff. */
- gui_free(); /* Free up the gui. */
- weapon_exit(); /* Destroy all active weapons. */
- pilots_free(); /* Free the pilots, they where locked up D: */
-
- /* Unload data. */
- unload_all();
-
- /* Cleanup opengl fonts. */
- gl_freeFont(NULL);
- gl_freeFont(&gl_smallFont);
-
- /* Close data. */
- ldata_close();
-
- /* Exit subsystems. */
- toolkit_exit(); /* Kill the toolkit. */
- ai_exit(); /* Stop the Lua AI magicness. */
- joystick_exit(); /* Release joystick. */
- input_exit(); /* Clean up keybindings. */
- nebu_exit(); /* Destroys the nebulae. */
- gl_exit(); /* Kills video output. */
- sound_exit(); /* Kills the sound. */
- SDL_Quit(); /* Quits SDL. */
-
- /* All is good. */
- exit(EXIT_SUCCESS);
-}
-
-/**
- * @brief Display a loading screen.
- */
-void loadscreen_load(void) {
- unsigned int i;
- char file_path[PATH_MAX];
- char** loadscreens;
- uint32_t nload;
-
- /* Count the loading screens. */
- loadscreens = ldata_list("../gfx/loading/", &nload);
-
- /* Must have loading screens. */
- if(nload == 0) {
- WARN("No loading screens found!");
- return;
- }
-
- /* Load the texture. */
- snprintf(file_path, PATH_MAX, "../gfx/loading/%s",
- loadscreens[RNG_SANE(0, nload-1)]);
- loading = gl_newImage(file_path, 0);
-
- /* Clean up. */
- for(i = 0; i < nload; i++)
- free(loadscreens[i]);
- free(loadscreens);
-}
-
-/**
- * @brief Render the load screen with message.
- * @param done Amount done (1. == completed).
- * @param msg Loading screen message.
- */
-void loadscreen_render(double done, const char* msg) {
- double x, y, w, h, rh;
-
- /* Clear background. */
- glClear(GL_COLOR_BUFFER_BIT);
-
- /* Draw loading screen image. */
- gl_blitScale(loading, 0., 0., SCREEN_W, SCREEN_H, NULL);
-
- /* Draw progress bar. */
- w = gl_screen.w * 0.4;
- h = gl_screen.h * 0.02;
- rh = h + gl_defFont.h + 4.;
- x = -w/2.;
- y = -h/2.;
- /* BG. */
- ACOLOUR(cBlack, 0.7);
- glBegin(GL_QUADS);
- glVertex2d(x-2., y-2. + 0.);
- glVertex2d(x-2., y+2. + rh);
- glVertex2d(x-2. + w+4., y+2. + rh);
- glVertex2d(x-2. + w+4., y-2. + 0.);
- glEnd();
- /* FG. */
- ACOLOUR(cConsole, 0.7);
- glBegin(GL_QUADS);
- glVertex2d(x, y + 0.);
- glVertex2d(x, y + h);
- glVertex2d(x + done*w, y + h);
- glVertex2d(x + done*w, y + 0.);
- glEnd();
-
- /* Draw text. */
- gl_print(&gl_defFont, x + gl_screen.w/2., y + gl_screen.h/2 + 2. + h,
- &cConsole, msg);
-
- /* Flip buffers. */
- SDL_GL_SwapBuffers();
-}
-
-/**
- * @brief Frees the loading screen.
- */
-static void loadscreen_unload(void) {
- /* Free the textures. */
- gl_freeTexture(loading);
- loading = NULL;
-}
-
-/**
- * @brief Load all the data, makes main() simpler.
- */
-#define LOADING_STAGES 9. /**< Amount of loading stages. */
-void load_all(void) {
- /* Ordering of these is very important as they are interdependent. */
- loadscreen_render(1./LOADING_STAGES, "Loading the pilot's food surplus...");
- commodity_load();
- loadscreen_render(2./LOADING_STAGES, "Loading the powers that be...");
- factions_load(); /* Dep for fleet, space, missions. */
- loadscreen_render(3./LOADING_STAGES, "Loading things to do...");
- missions_load(); /* No dep. */
- loadscreen_render(4./LOADING_STAGES, "Loading firework displays...");
- spfx_load();
- loadscreen_render(5./LOADING_STAGES, "Loading laser beams...");
- outfit_load();
- loadscreen_render(6./LOADING_STAGES, "Loading floating homes...");
- ships_load();
- loadscreen_render(7./LOADING_STAGES, "Loading rich snobs...");
- fleet_load();
- loadscreen_render(8./LOADING_STAGES, "Loading the entire universe");
- space_load();
- loadscreen_render(1./LOADING_STAGES, "Load Complete!!");
- xmlCleanupParser(); /* Only needed to be run after all the loading is done. */
-}
-
-/**
- * @brief Unloads all data, simplifies main().
- */
-void unload_all(void) {
- /* Data unloading - Inverse load_all is a good order. */
- economy_destroy(); /* Must be called before space_exit. */
- space_exit(); /* Cleans up the universe. */
- fleet_free();
- ships_free();
- outfit_free();
- spfx_free(); /* Remove the special effects. */
- missions_free();
- factions_free();
- commodity_free();
- var_cleanup(); /* Clean up mission variables. */
-}
-
-/**
- * @brief Split main loop from main() for secondary loop hack in toolkit.c.
- */
-void main_loop(void) {
- glClear(GL_COLOR_BUFFER_BIT);
-
- fps_control(); /* Everyone loves fps control.. */
-
- sound_update(); /* Update sounds. */
- if(toolkit) toolkit_update(); /* To simulate key repetition. */
- if(!menu_isOpen(MENU_MAIN)) {
- if(!paused) update_all(); /* Update game. */
- render_all();
- }
- if(toolkit) toolkit_render();
-
- gl_checkErr(); /* Check error every loop. */
-
- SDL_GL_SwapBuffers();
-}
-
-static double fps_dt = 1.; /**< Display fps accumulator. */
-static double cur_dt = 0.; /**< Current deltatick. */
-/**
- * @brief Controls the FPS.
- */
-static void fps_control(void) {
- unsigned int t;
- double delay;
-
- /* dt in s. */
- t = SDL_GetTicks();
- cur_dt = (double)(t - time); /* Get the elapsed ms. */
- cur_dt *= dt_mod; /* Apply the modifier. */
- cur_dt /= 1000.; /* Convert to seconds. */
- time = t;
-
- if(paused) SDL_Delay(10); /* Drop paused FPS to be nice to the CPU. */
-
- /* If the fps is limited.. */
- if((max_fps != 0) && (cur_dt < 1./max_fps)) {
- delay = 1./max_fps - cur_dt;
- SDL_Delay((unsigned int)(delay*1000));
- fps_dt += delay; /* Make sure it displays the propper FPS. */
- }
-}
-
-static const double fps_min = 1./50.0;
-/**
- * @brief Updates the game itself (player flying around etc).
- */
-static void update_all(void) {
- double tmpdt;
-
- if(cur_dt > 0.25/**dt_mod*/) { /* Slow timers down and rerun calculations */
- pause_delay((unsigned int)cur_dt*1000.);
- return;
- }
- /* We'll force a minimum of 50 FPS. */
- else if(cur_dt > fps_min) {
- tmpdt = cur_dt - fps_min;
- pause_delay((unsigned int)(tmpdt*1000));
- update_routine(fps_min);
-
- /* Run as many cycles of dt=fps_min as needed. */
- while(tmpdt > fps_min) {
- pause_delay((unsigned int)(-fps_min*1000)); /* Increment counters */
- update_routine(fps_min);
- tmpdt -= fps_min;
- }
- /* Note we don't touch cur_dt so that fps_delay works well. */
- update_routine(tmpdt); /* Leftovers. */
- } else /* Standard, just update with the last dt. */
- update_routine(cur_dt);
-}
-
-/**
- * @brief Actually runs the update.
- * @param[in] dt Current delta tick.
- */
-static void update_routine(double dt) {
- space_update(dt);
- weapons_update(dt);
- spfx_update(dt);
- pilots_update(dt);
- missions_update(dt);
-}
-
-/**
- * @brief Renders the game itself (player flying around etc).
- *
- * Blitting order. (layers)
- *
- * - BG
- * -- Stars and planets.
- * -- Background player stuff (planet targetting)
- * -- Background particles.
- * -- Back layer weapons.
- * - N
- * -- NPC ships.
- * -- Front layer weapons.
- * -- Normal layer particles (above ships).
- * - FG
- * -- Player.
- * -- Foreground particles.
- * -- Text and GUI.
- */
-static void render_all(void) {
- double dt;
-
- dt = (paused) ? 0. : cur_dt;
-
- /* Setup. */
- spfx_start(dt);
- /* BG. */
- space_render(dt);
- planets_render();
- gui_renderBG(dt);
- weapons_render(WEAPON_LAYER_BG, dt);
- /* N. */
- pilots_render();
- weapons_render(WEAPON_LAYER_FG, dt);
- spfx_render(SPFX_LAYER_BACK);
- /* FG. */
- player_render(dt);
- spfx_render(SPFX_LAYER_FRONT);
- space_renderOverlay(dt);
- gui_render(dt);
- display_fps(dt); /* Exception. */
-}
-
-
-static double fps = 0.; /**< FPS to finally display. */
-static double fps_cur = 0.; /**< FPS accumulator to trigger change. */
-/**
- * @brief Displays FPS on the screen.
- *
- * @param[in] dt Current delta tick.
- */
-static void display_fps(const double dt) {
- double x, y;
-
- fps_dt += dt / dt_mod;
- fps_cur += 1.;
- if(fps_dt > 1.) {
- /* Recalculate every second. */
- fps = fps_cur / fps_dt;
- fps_dt = fps_cur = 0.;
- }
-
- x = 10.;
- y = (double)(gl_screen.h - 20);
- if(show_fps) {
- gl_print(NULL, x, y, NULL, "%3.2f", fps);
- y -= gl_defFont.h + 5.;
- }
- if(dt_mod != 1.)
- gl_print(NULL, x, y, NULL, "%3.1fx", dt_mod);
-}
-
-/**
- * @brief Set the window caption.
- */
-static void window_caption(void) {
- char buf[PATH_MAX];
-
- snprintf(buf, PATH_MAX, APPNAME" - %s", ldata_name());
- SDL_WM_SetCaption(buf, NULL);
-}
-
-static char human_version[50]; /**< Stores human readable version string. */
-
-/**
- * @brief Return the version in a human readable string.
- *
- * @return The human readable version string.
- */
-char* lephisto_version(void) {
- if(human_version[0] == '\0')
- snprintf(human_version, 50, " "APPNAME" v%s - %s", version, ldata_name());
-
- return human_version;
-}
-
-/**
- * @bief Print the SDL version to console.
- */
-static void print_SDLversion(void) {
- const SDL_version* linked;
- SDL_version compiled;
- SDL_VERSION(&compiled);
- linked = SDL_Linked_Version();
-
- DEBUG("SDL: %d.%d.%d [compiled: %d.%d.%d]",
- linked->major, linked->minor, linked->patch,
- compiled.major, compiled.minor, compiled.patch);
-
- /* Check if major/minor version differ. */
- if((linked->major*100 + linked->minor) > compiled.major*100 + compiled.minor)
- WARN("SDL is newer than compiled version.");
- if((linked->major*100 + linked->minor) < compiled.major*100 + compiled.minor)
- WARN("SDL is older than compiled version.");
-}
-
-#if HAS_LINUX && defined(DEBUGGING)
-/**
- * @brief Get the string related to the signal code.
- * @param sig Signal to which code belongs.
- * @param sig_code Signal code to get string of.
- * @return String of signal code.
- */
-static const char* debug_sigCodeToStr(int sig, int sig_code) {
- if(sig == SIGFPE)
- switch(sig_code) {
- case SI_USER: return "SIGFPE (raised by program)";
- case FPE_INTDIV: return "SIGFPE (integer divide by zero)";
- case FPE_INTOVF: return "SIGFPE (integer overflow)";
- case FPE_FLTDIV: return "SIGFPE (floating-point divide by zero)";
- case FPE_FLTOVF: return "SIGFPE (floating-point overflow)";
- case FPE_FLTUND: return "SIGFPE (floating-point underflow)";
- case FPE_FLTRES: return "SIGFPE (floating-point inexact result)";
- case FPE_FLTINV: return "SIGFPE (floating-point invalid operation)";
- case FPE_FLTSUB: return "SIGFPE (subscript out of range)";
- default: return "SIGFPE";
- }
- else if(sig == SIGSEGV)
- switch(sig_code) {
- case SI_USER: return "SIGSEGV (raised by program)";
- case SEGV_MAPERR: return "SIGEGV (address not mapped to object)";
- case SEGV_ACCERR: return "SIGEGV (invalid permissions for mapped object)";
- default: return "SIGSEGV";
- }
- else if(sig == SIGABRT)
- switch(sig_code) {
- case SI_USER: return "SIGABRT (raised by program)";
- default: return "SIGABRT";
- }
- /* No suitable code found. */
- return strsignal(sig);
-}
-
-/**
- * @brief Backtrace signal handler for linux.
- * @param sig Signal.
- * @param info Signal information.
- * @param unused Unused.
- */
-static void debug_sigHandler(int sig, siginfo_t* info, void* unused) {
- (void) sig;
- (void) unused;
- int i, num;
- void* buf[64];
- char** symbols;
-
- num = backtrace(buf, 64);
- symbols = backtrace_symbols(buf, num);
-
- DEBUG("LEPHISTO recieved %s!",
- debug_sigCodeToStr(info->si_signo, info->si_code));
- for(i = 0; i < num; i++)
- DEBUG(" %s", symbols[i]);
- DEBUG("Report this to project maintainer with the backtrace.");
-
- exit(1);
-}
-#endif /* HAS_LINUX && defined(DEBUGGING) */
-
-/**
- * @brief Set up the SignalHandler for Linux.
- */
-static void debug_sigInit(void) {
-#if HAS_LINUX && defined(DEBUGGING)
- struct sigaction sa, so;
-
- /* Set up handler. */
- sa.sa_handler = NULL;
- sa.sa_sigaction = debug_sigHandler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_SIGINFO;
-
- /* Attach signals. */
- sigaction(SIGSEGV, &sa, &so);
- if(so.sa_handler == SIG_IGN)
- DEBUG("Unable to set up SIGSEGV signal handler.");
- sigaction(SIGFPE, &sa, &so);
- if(so.sa_handler == SIG_IGN)
- DEBUG("Unable to set up SIGFPE signal handler.");
- sigaction(SIGABRT, &sa, &so);
- if(so.sa_handler == SIG_IGN)
- DEBUG("Unable to get set up SIGABRT signal handler.");
-#endif /* #if HAS_LINUX && defined(DEBUGGING) */
-}
-
diff --git a/src/lephisto.h b/src/lephisto.h
deleted file mode 100644
index e8f5597..0000000
--- a/src/lephisto.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-/**
- * @file lephisto.h
- *
- * @brief Header file with generic functions and lephisto-specifics.
- */
-
-#define APPNAME "Lephisto" /**< Application name. */
-
-#define ABS(x) (((x)<0)?-(x):(x)) /**< Return absulute value. */
-#define FABS(x) (((x)<0.)?-(x):(x)) /**< Return float absolute value. */
-
-#define MAX(x,y) (((x)>(y))?(x):(y)) /**< Return maximum. */
-#define MIN(x,y) (((x)>(y))?(y):(x)) /**< Return minumum. */
-#define CLAMP(a, b, x) ((x)<(a)?(a):((x)>(b)?(b):(x))) /**< Clamps x between a and b: a <= x <= b */
-
-#define pow2(x) ((x)*(x)) /**< ^2 */
-
-/* Max filename path. */
-#ifndef PATH_MAX
-# define PATH_MAX 256 /**< If not already defined. */
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846 /**< If not already defined. */
-#endif
-
-char* lephisto_version(void);
-
diff --git a/src/lfile.c b/src/lfile.c
deleted file mode 100644
index 7783b65..0000000
--- a/src/lfile.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/**
- * @file lfile.c
- *
- * @brief Handle read/write abstractions to the users directory.
- *
- * @todo Add support for windows and mac OS.
- */
-
-#include "lcompat.h"
-
-#include
-#include
-#include
-#if HAS_POSIX
-#include
-#include
-#include
-#include
-#include
-#include
-#endif /* HAS_POSIX */
-
-#include "lephisto.h"
-#include "log.h"
-#include "lfile.h"
-
-#define BLOCK_SIZE 128*1024 /**< 128 kilobytes. */
-
-static char lephisto_base[PATH_MAX] = "\0"; /**< Store Lephisto's base path. */
-/**
- * @brief Get Lephisto's base path (for saves etc..).
- * @return The base path to Lephisto.
- */
-char* lfile_basePath(void) {
- char* home;
-
- if(lephisto_base[0] == '\0') {
-#if HAS_UNIX
- home = getenv("HOME");
- snprintf(lephisto_base, PATH_MAX, "%s/.lephisto/", home);
-#else /* HAS_UNIX */
- FILE* f;
-
- /* Try to open the file, C89 compliant, but not as precise as stat. */
- f = fopen(file, 'r');
- if(f != NULL) {
- fclose(f);
- return 1;
- }
-#endif
- }
-
- return lephisto_base;
-}
-
-/**
- * @brief Create a directory if it doesn't exist.
- *
- * Uses relative path to basePath.
- * @param path Path to create directory if it doesn't exist.
- * @return 0 on success.
- */
-int lfile_dirMakeExist(const char* path, ...) {
- char file[PATH_MAX];
- va_list ap;
-
- if(path == NULL) return -1;
- else { /* Get the message. */
- va_start(ap, path);
- vsnprintf(file, PATH_MAX, path, ap);
- va_end(ap);
- }
-
-#if HAS_POSIX
- struct stat buf;
-
- stat(file, &buf);
- if(!S_ISDIR(buf.st_mode))
- if(mkdir(file, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- WARN("Dir '%s' does not exist and unable to create", file);
- return -1;
- }
-#else /* HAS_POSIX */
-#error "Feature needs implementation on this Operating System for Lephisto to work."
-#endif /* HAS_POSIX */
-
- return 0;
-}
-
-/**
- * @brief Check to see if a file exists.
- * @param path printf formatted string pointing to the file to check for existance.
- * @return 1 if file exists, 0 if it doesn't or -1 on error.
- */
-int lfile_fileExists(const char* path, ...) {
- char file[PATH_MAX];
- va_list ap;
-
- if(path == NULL) return -1;
- else { /* Get the message. */
- va_start(ap, path);
- vsnprintf(file, PATH_MAX, path, ap);
- va_end(ap);
- }
-
-#if HAS_POSIX
- struct stat buf;
-
- if(stat(file, &buf)==0) /* Stat worked, file must exist. */
- return 1;
-#else /* HAS_POSIX */
- FILE* f;
-
- /* Try to open the file, C89 compliant, but not as precise as stat. */
- f = fopen(file, 'r');
- if(f != NULL) {
- fclose(f);
- return 1;
- }
-#endif /* HAS_POSIX */
- return 0;
-}
-
-/**
- * @brief Lists all the visible files in a directory.
- *
- * Should also sort by last modified but thats up to the OS in question.
- * Paths are relative to base directory.
- * @param[out] lfiles Returns how many files there are.
- * @param path Directory to read.
- */
-char** lfile_readDir(int* lfiles, const char* path, ...) {
- char file[PATH_MAX], base[PATH_MAX];
- char** files;
- va_list ap;
-
- if(path == NULL) {
- *lfiles = 0;
- return NULL;
- } else { /* Get the message. */
- va_start(ap, path);
- vsnprintf(base, PATH_MAX, path, ap);
- va_end(ap);
- }
-
-#if HAS_POSIX
- int i, j, k, n;
- DIR* d;
- struct dirent *dir;
- char* name;
- int mfiles;
- struct stat sb;
- time_t* tt, *ft;
- char** tfiles;
-
- (*lfiles) = 0;
- mfiles = 100;
- tfiles = malloc(sizeof(char*)*mfiles);
- tt = malloc(sizeof(time_t)*mfiles);
-
- d = opendir(base);
- if(d == NULL)
- return NULL;
-
- /* Get the file list. */
- while((dir = readdir(d)) != NULL) {
- name = dir->d_name;
-
- /* Skip hidden directories. */
- if(name[0] == '.')
- continue;
-
- /* Stat the file. */
- snprintf(file, PATH_MAX, "%s/%s", base, name);
- if(stat(file, &sb) == -1)
- continue; /* Unable to stat. */
-
- /* Enough memory? */
- if((*lfiles)+1 > mfiles) {
- mfiles += 100;
- tfiles = realloc(files, sizeof(char*) * mfiles);
- tt = realloc(tt, sizeof(time_t) * mfiles);
- }
-
- /* Write the information. */
- tfiles[(*lfiles)] = strdup(name);
- tt[(*lfiles)] = sb.st_mtime;
- (*lfiles)++;
- }
-
- closedir(d);
-
- /* Sort by last changed date. */
- if((*lfiles) > 0) {
- /* Need to allocate some stuff. */
- files = malloc(sizeof(char*)*(*lfiles));
- ft = malloc(sizeof(time_t)*(*lfiles));
-
- /* Fill the list. */
- for(i = 0; i < (*lfiles); i++) {
- n = -1;
-
- /* Get the next lowest. */
- for(j = 0; j < (*lfiles); j++) {
- /* Is lower? */
- if((n == -1) || (tt[j] > tt[n])) {
- /* Check if it's already there. */
- for(k = 0; k < i; k++)
- if(strcmp(files[k], tfiles[j])==0)
- break;
-
- /* New lowest. */
- if(k >= i)
- n = j;
- }
- }
- files[i] = tfiles[n];
- ft[i] = tt[n];
- }
- free(ft);
- } else
- files = NULL;
-
- /* Free temp stuff. */
- free(tfiles);
- free(tt);
-
-#else /* HAS_POSIX */
-#error "Feature needs implementation on this Operating System for Lephito to work."
-#endif /* HAS_POSIX
-
- /* What if we find nothing? */
- if((*lfiles) == 0) {
- free(files);
- files = NULL;
- }
-
- return files;
-}
-
-/**
- * @brief Try to read a file.
- * @param filesize Stores the size of the file.
- * @param path Path of the file.
- * @return The file data.
- */
-char* lfile_readFile(int* filesize, const char* path, ...) {
- char base[PATH_MAX];
- char* buf;
- FILE* file;
- int len, pos;
- va_list ap;
-
- if(path == NULL) {
- *filesize = 0;
- return NULL;
- } else { /* Get the message. */
- va_start(ap, path);
- vsnprintf(base, PATH_MAX, path, ap);
- va_end(ap);
- }
-
- /* Open file. */
- file = fopen(base, "r");
- if(file == NULL)
- return NULL;
-
- /* Get file size. */
- len = fseek(file, 0, SEEK_END);
- if(len == -1) {
- fclose(file);
- return NULL;
- }
- len = ftell(file);
- fseek(file, 0, SEEK_SET);
-
- /* Allocate buffer. */
- buf = malloc(len);
- if(buf == NULL) {
- WARN("Out of memory!");
- fclose(file);
- return NULL;
- }
-
- /* Read the file. */
- pos = fread(buf, len, 1, file);
- if(pos != 1)
- WARN("Error occurred while reading '%s'.", base);
-
- *filesize = len;
- return buf;
-}
-
-/**
- * @brief Tries to create the file if it doesn't exist.
- * @param path Path of the file to create.
- */
-int lfile_touch(const char* path, ...) {
- char file[PATH_MAX];
- va_list ap;
- FILE* f;
-
- if(path == NULL) return -1;
- else { /* Get the message. */
- va_start(ap, path);
- vsnprintf(file, PATH_MAX, path, ap);
- va_end(ap);
- }
-
- /* Try to open the file, C89 cmpliant, but not as precise as stat. */
- f = fopen(file, "a+");
- if(f == NULL) {
- WARN("Unable to touch file '%s': %s", file, strerror(errno));
- return -1;
- }
- fclose(f);
- return 0;
-}
-
diff --git a/src/lfile.h b/src/lfile.h
deleted file mode 100644
index c7e3aa9..0000000
--- a/src/lfile.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-char* lfile_basePath(void);
-int lfile_dirMakeExist(const char* path, ...);
-int lfile_fileExists(const char* path, ...);
-char** lfile_readDir(int* lfiles, const char* path, ...);
-char* lfile_readFile(int* filesize, const char* path, ...);
-int lfile_touch(const char* path, ...);
-
diff --git a/src/llua.c b/src/llua.c
deleted file mode 100644
index 652dc68..0000000
--- a/src/llua.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/**
- * @file llua.c
- *
- * @brief Contains some standard Lua binding libraries.
- *
- * Namely:
- * -- lephisto : General game stuff.
- * -- time : For manipulating time.
- * -- rnd : For access to the random number generator.
- * -- tk : Access to the toolkit.
- */
-
-#include "lauxlib.h"
-
-#include "log.h"
-#include "lephisto.h"
-#include "rng.h"
-#include "ltime.h"
-#include "dialogue.h"
-#include "space.h"
-#include "land.h"
-#include "map.h"
-#include "ldata.h"
-#include "lluadef.h"
-#include "llua.h"
-
-static int llua_packfileLoader(lua_State* L);
-
-/* -- Libraries. -- */
-
-/* Lephisto. */
-static int lephisto_lang(lua_State* L);
-static const luaL_reg lephisto_methods[] = {
- { "lang", lephisto_lang },
- { 0, 0 }
-};
-
-/* Time. */
-static int time_get(lua_State* L);
-static int time_str(lua_State* L);
-static int time_units(lua_State* L);
-static const luaL_reg time_methods[] = {
- { "get", time_get },
- { "str", time_str },
- { "units", time_units },
- {0, 0}
-};
-
-/* RND. */
-static int rnd_int(lua_State*L);
-static int rnd_sigma(lua_State* L);
-static int rnd_twosigma(lua_State* L);
-static int rnd_threesigma(lua_State* L);
-static const luaL_reg rnd_methods[] = {
- { "int", rnd_int }, /* Obsolete, rnd.rnd is prefered. */
- { "rnd", rnd_int },
- { "sigma", rnd_sigma },
- { "twosigma", rnd_twosigma },
- { "threesigma", rnd_threesigma },
- { 0, 0 }
-};
-
-/* Toolkit. */
-static int tk_msg(lua_State* L);
-static int tk_yesno(lua_State* L);
-static int tk_input(lua_State* L);
-static const luaL_reg tk_methods[] = {
- { "msg", tk_msg },
- { "yesno", tk_yesno },
- { "input", tk_input },
- { 0, 0 }
-};
-
-/* Wrapper around luaL_newstate. */
-lua_State* llua_newState(void) {
- lua_State* L;
- /* Try to create the new state. */
- L = luaL_newstate();
- if(L == NULL) {
- WARN("Failed to create new lua state.");
- return NULL;
- }
-
- return L;
-}
-
-/* Open a lua library. */
-int llua_load(lua_State* L, lua_CFunction f) {
- lua_pushcfunction(L, f);
- if(lua_pcall(L, 0, 0, 0))
- WARN("llua include error: %s", lua_tostring(L, 1));
-
- return 0;
-}
-
-/**
- * @brief Load specially modified basic stuff.
- * @param L Lua state to load the basic stuff into.
- * @return 0 on success.
- */
-int llua_loadBasic(lua_State* L) {
- int i;
- /* Unsafe functions. */
- const char* override[] = {
- "collectgarbage",
- "dofile",
- "getfenv",
- "getmetatable",
- "load",
- "loadfile",
- "loadstring",
- "rawequal",
- "rawget",
- "rawset",
- "setfenv",
- "setmetatable",
- "END"
- };
-
- llua_load(L, luaopen_base); /* Open base. */
-
- /* Replace non-safe functions. */
- for(i = 0; strcmp(override[i], "END") != 0; i++) {
- lua_pushnil(L);
- lua_setglobal(L, override[i]);
- }
-
- llua_load(L, luaopen_math); /* Open math. */
- llua_load(L, luaopen_table); /* Open table. */
-
- /* Add our own. */
- lua_register(L, "include", llua_packfileLoader);
-
- return 0;
-}
-
-/**
- * @brief include(string module)
- *
- * Loads a module into the current Lua state from inside the data file.
- * @param module Name of the module to load.
- * @return An error string on error.
- */
-static int llua_packfileLoader(lua_State* L) {
- char* buf, *filename;
- uint32_t bufsize;
-
- LLUA_MIN_ARGS(1);
-
- if(!lua_isstring(L, 1)) {
- LLUA_INVALID_PARAMETER();
- return 0;
- }
-
- filename = (char*) lua_tostring(L, 1);
-
- /* Try to locate the data. */
- buf = ldata_read(filename, &bufsize);
- if(buf == NULL) {
- lua_pushfstring(L, "%s not found in ldata.", filename);
- return 1;
- }
-
- /* Run the buffer. */
- if(luaL_dobuffer(L, buf, bufsize, filename) != 0) {
- /* Will push the current error from the dobuffer. */
- return 1;
- }
-
- /* Cleanup. */
- free(buf);
- return 0;
-}
-
-/* Individual libraries. */
-int lua_loadLephisto(lua_State* L) {
- luaL_register(L, "lephisto", lephisto_methods);
- return 0;
-}
-
-int lua_loadTime(lua_State* L, int readonly) {
- (void)readonly;
- luaL_register(L, "time", time_methods);
- return 0;
-}
-
-int lua_loadRnd(lua_State* L) {
- luaL_register(L, "rnd", rnd_methods);
- return 0;
-}
-
-int lua_loadTk(lua_State* L) {
- luaL_register(L, "tk", tk_methods);
- return 0;
-}
-
-/* -- Lephisto. -- */
-static int lephisto_lang(lua_State* L) {
- /* @todo Multilanguage stuff. */
- lua_pushstring(L, "en");
- return 1;
-}
-
-/* -- Time. -- */
-static int time_get(lua_State* L) {
- lua_pushnumber(L, ltime_get());
- return 1;
-}
-
-static int time_str(lua_State* L) {
- char* lt;
- if((lua_gettop(L) > 0) && (lua_isnumber(L, 1)))
- lt = ltime_pretty((unsigned int) lua_tonumber(L, 1));
- else
- lt = ltime_pretty(ltime_get());
- lua_pushstring(L, lt);
- free(lt);
- return 1;
-}
-
-static int time_units(lua_State* L) {
- if((lua_gettop(L) > 0) && (lua_isnumber(L, 1)))
- lua_pushnumber(L, (unsigned int) lua_tonumber(L, 1) * LTIME_UNIT_LENGTH);
- else
- lua_pushnumber(L, LTIME_UNIT_LENGTH);
- return 1;
-}
-
-/* -- RND. -- */
-static int rnd_int(lua_State* L) {
- int o;
-
- o = lua_gettop(L);
-
- if(o == 0) lua_pushnumber(L, RNGF()); /* Random double o <= x <= 1. */
- else if(o == 1) {
- /* Random int 0 <= x <= param. */
- if(lua_isnumber(L, 1))
- lua_pushnumber(L, RNG(0, (int)lua_tonumber(L, 1)));
- else return 0;
- }
- else if(o >= 2) {
- /* Random int param 1 <= x <= param 2. */
- if(lua_isnumber(L, 1) && lua_isnumber(L, 2))
- lua_pushnumber(L, RNG((int)lua_tonumber(L, 1), (int)lua_tonumber(L, 2)));
- else return 0;
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Unless it's returned 0 already it'll always return param. */
- return 1;
-}
-
-static int rnd_sigma(lua_State* L) {
- lua_pushnumber(L, RNG_1SIGMA());
- return 1;
-}
-
-static int rnd_twosigma(lua_State* L) {
- lua_pushnumber(L, RNG_2SIGMA());
- return 1;
-}
-
-static int rnd_threesigma(lua_State* L) {
- lua_pushnumber(L, RNG_3SIGMA());
- return 1;
-}
-
-/**
- * @defgroup TOOLKIT Toolkit Lua Bindings.
- *
- * @brief Bindings for interacting with the toolkit.
- *
- * Functions should be called like:
- *
- * @code
- * tk.function(parameters)
- * @endcode
- *
- * @{
- */
-/**
- * @brief msg(string title, string message)
- *
- * Creates a window with an ok button.
- * @param title Title of the window.
- * @param message Message to display in the window.
- */
-static int tk_msg(lua_State* L) {
- char* title, *str;
- LLUA_MIN_ARGS(2);
-
- if(lua_isstring(L, 1)) title = (char*) lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
- if(lua_isstring(L, 2)) str = (char*) lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- dialogue_msg(title, str);
- return 0;
-}
-
-static int tk_yesno(lua_State* L) {
- int ret;
- char* title, *str;
- LLUA_MIN_ARGS(2);
-
- if(lua_isstring(L, 1)) title = (char*) lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
- if(lua_isstring(L, 2)) str = (char*) lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- ret = dialogue_YesNo(title, str);
- lua_pushboolean(L, ret);
- return 1;
-}
-
-static int tk_input(lua_State* L) {
- char* title, *str;
- int min, max;
- LLUA_MIN_ARGS(4);
-
- if(lua_isstring(L, 1)) title = (char*) lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
- if(lua_isnumber(L, 2)) min = (int) lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
- if(lua_isnumber(L, 3)) max = (int) lua_tonumber(L, 3);
- else LLUA_INVALID_PARAMETER();
- if(lua_isstring(L, 4)) str = (char*) lua_tostring(L, 4);
- else LLUA_INVALID_PARAMETER();
-
- dialogue_input(title, min, max, str);
- return 0;
-}
-
diff --git a/src/llua.h b/src/llua.h
deleted file mode 100644
index f99061c..0000000
--- a/src/llua.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include "lua.h"
-
-/* Standard lua stuff wrappers. */
-lua_State* llua_newState (void); /* Creates a new state */
-int llua_load(lua_State* L, lua_CFunction f);
-int llua_loadBasic(lua_State* L);
-
-/* Individual custom libraries. */
-int lua_loadLephisto(lua_State* L); /* Always read only. */
-int lua_loadSpace(lua_State* L, int readonly);
-int lua_loadTime(lua_State* L, int readonly);
-int lua_loadRnd(lua_State* L); /* Always read only. */
-int lua_loadTk(lua_State* L); /* Always read only. */
-
diff --git a/src/llua_faction.c b/src/llua_faction.c
deleted file mode 100644
index 4c22532..0000000
--- a/src/llua_faction.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/**
- * @file llua_faction.c
- *
- * @breif Handle the Lua faction bindings.
- *
- * These bindings control the faction.
- */
-
-#include "lauxlib.h"
-
-#include "log.h"
-#include "lephisto.h"
-#include "llua.h"
-#include "lluadef.h"
-#include "faction.h"
-#include "llua_faction.h"
-
-static int factionL_createmetatable(lua_State* L, int readonly);
-
-/* Faction metatable methods. */
-static int factionL_eq(lua_State* L);
-static int factionL_name(lua_State* L);
-static int factionL_longname(lua_State* L);
-static int factionL_areenemies(lua_State* L);
-static int factionL_areallies(lua_State* L);
-static int factionL_modplayer(lua_State* L);
-static int factionL_modplayerraw(lua_State* L);
-static int factionL_playerstanding(lua_State* L);
-static int factionL_enemies(lua_State* L);
-static int factionL_allies(lua_State* L);
-static const luaL_reg faction_methods[] = {
- { "__eq", factionL_eq },
- { "__tostring", factionL_name },
- { "name", factionL_name },
- { "longname", factionL_longname },
- { "areEnemeies", factionL_areenemies },
- { "areAllies", factionL_areallies },
- { "modPlayer", factionL_modplayer },
- { "modPlayerRaw", factionL_modplayerraw },
- { "playerStanding", factionL_playerstanding },
- { "enemies", factionL_enemies },
- { "allies", factionL_allies },
- { 0, 0 }
-}; /**< Faction metatable methods. */
-
-static const luaL_reg faction_methods_cond[] = {
- { "__eq", factionL_eq },
- { "__tostring", factionL_name },
- { "name", factionL_name },
- { "longname", factionL_longname },
- { "areEnemeies", factionL_areenemies },
- { "areAllies", factionL_areallies },
- { "playerStanding", factionL_playerstanding },
- { "enemies", factionL_enemies },
- { "allies", factionL_allies },
- { 0, 0 }
-}; /**< Factions read only metatable methods. */
-
-/* Global faction functions. */
-static int factionL_get(lua_State* L);
-static const luaL_reg factionL_methods[] = {
- { "get", faction_get },
- { 0, 0 }
-}; /**< Faction module functions. */
-
-/**
- * @brief Load the faction library.
- * @param L State to load faction library into.
- * @param readonly Load as read only?
- * @return 0 on success.
- */
-int lua_loadFaction(lua_State* L, int readonly) {
- /* Register the faction functions. */
- luaL_register(L, "faction", factionL_methods);
-
- /* Register the metatables. */
- factionL_createmetatable(L, readonly);
-
- return 0;
-}
-
-/**
- * @brief Register the faction metatable.
- * @param L Lua state to register metatable into.
- * @param readonly Whether table should be readonly.
- * @return 0 on success.
- */
-static int factionL_createmetatable(lua_State* L, int readonly) {
- /* Create metatable. */
- luaL_newmetatable(L, FACTION_METATABLE);
-
- /* Create the access table. */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
- /* Register the values. */
- luaL_register(L, NULL, (readonly) ? faction_methods_cond : faction_methods);
-
- lua_pop(L, 1);
-
- return 0; /* No error. */
-}
-
-/**
- * @defgroup FACTION Faction Lua bindings.
- *
- * @brief Lua bindings to deal with factions.
- *
- * @luamod faction
- * Use with:
- * @code
- * faction.func(params)
- * @endcode
- *
- * @{
- */
-
-/**
- * @brief faction get(string name)
- *
- * Get the faction based on its name.
- * @param name Name of the faction to get.
- * @return The faction matching name.
- */
-static int factionL_get(lua_State* L) {
- LuaFaction f;
- char* name;
-
- if(lua_isstring(L, 1)) name = (char*) lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- f.f = faction_get(name);
- lua_pushfaction(L, f);
- return 1;
-}
-
-/**
- * @}
- */
-
-/**
- * @defgroup META_FACTION Faction Metatable.
- *
- * @brief The faction metatable is a way to represent a faction in Lua.
- *
- * It allows all sorts of operators making it much more natural to use.
- *
- * To call members of the metatable always use:
- *
- * @code
- * faction:function(param)
- * @endcode
- *
- * @{
- */
-
-/**
- * @brief Get faction at index.
- * @param L Lua state to get faction from.
- * @param ind Index position to find the faction.
- * @return Faction found at the index in the state.
- */
-LuaFaction* lua_tofaction(lua_State* L, int ind) {
- if(lua_isuserdata(L, ind)) {
- return (LuaFaction*) lua_touserdata(L, ind);
- }
-
- luaL_typerror(L, ind, FACTION_METATABLE);
- return NULL;
-}
-
-/**
- * @brief Pushes a faction on the stack.
- * @param L lua state to push faction into.
- * @param faction Faction to push.
- * @return Newly pushed faction.
- */
-LuaFaction* lua_pushfaction(lua_State* L, LuaFaction faction) {
- LuaFaction* f;
- f = (LuaFaction*) lua_newuserdata(L, sizeof(LuaFaction));
- *f = faction;
- luaL_getmetatable(L, FACTION_METATABLE);
- lua_setmetatable(L, -2);
- return f;
-}
-
-/**
- * @brief Check to see if ind is a faction.
- * @param L Lua state to check.
- * @param ind Index position to check.
- * @return 1 if ind is a faction.
- */
-int lua_isfaction(lua_State* L, int ind) {
- int ret;
-
- if(lua_getmetatable(L, ind)==0)
- return 0;
- lua_getfield(L, LUA_REGISTRYINDEX, FACTION_METATABLE);
-
- ret = 0;
- if(lua_rawequal(L, -1, -2)) /* Does it have the correct mt? */
- ret = 1;
-
- lua_pop(L, 2); /* Remove both metatables. */
- return ret;
-}
-
-/**
- * @brief __eq (equality) metamethod for factions.
- *
- * You can use the '=' operator within Lua to compare factions with this.
- * @luaparam comp faction to compare against.
- * @return true if both factions are the same.
- * @luafunc __eq(comp)
- */
-static int factionL_eq(lua_State* L) {
- LuaFaction* a, *b;
- a = lua_tofaction(L, 1);
- b = lua_tofaction(L, 2);
- lua_pushboolean(L, a->f == b->f);
- return 1;
-}
-
-/**
- * @brief Get the faction's name.
- * @return The name of the faction.
- * @luafunc name()
- */
-static int factionL_name(lua_State* L) {
- LuaFaction* f;
- f = lua_tofaction(L, 1);
- lua_pushstring(L, faction_name(f->f));
- return 1;
-}
-
-/**
- * @brief Get the factions long name.
- * @return The long name of the faction.
- * @luafunc longname()
- */
-static int factionL_longname(lua_State* L) {
- LuaFaction* f;
- f = lua_tofaction(L, 1);
- lua_pushstring(L, faction_longname(f->f));
- return 1;
-}
-
-/**
- * @brief Check to see if f is an enemy.
- * @luaparam f Faction to check if is an enemy.
- * @return true if they are enemies, false if they aren't.
- * @luafunc areEnemies( f )
- */
-static int factionL_areenemies(lua_State* L) {
- LuaFaction* f, *ff;
- f = lua_tofaction(L, 1);
- if(lua_isfaction(L, 2)) ff = lua_tofaction(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- lua_pushboolean(L, areEnemies(f->f, ff->f));
- return 1;
-}
-
-/**
- * @brief Check to see if f is an enemy.
- * @luaparam f Faction to check if is an enemy.
- * @return true if they are enemies, false if they aren't.
- * @luafunc areAllies( f )
- */
-static int factionL_areallies(lua_State* L) {
- LuaFaction* f, *ff;
- f = lua_tofaction(L, 1);
- if(lua_isfaction(L, 2)) ff = lua_tofaction(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- lua_pushboolean(L, areAllies(f->f, ff->f));
- return 1;
-}
-
-/**
- * @brief Modifies the players standing with the faction.
- * @luaparam mod The modifier to modify faction by.
- * @luafunc modPlayer( mod )
- */
-static int factionL_modplayer(lua_State* L) {
- LuaFaction* f;
- double n;
- f = lua_tofaction(L, 1);
-
- if(lua_isnumber(L, 2)) n = lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- faction_modPlayer(f->f, n);
- return 0;
-}
-
-/**
- * @brief Modifies the players standing with the faction. *
- * Does not affect other faction standings.
- * @luaparam mod The modifier to modify faction by.
- * @luafunc modPlayerRaw( mod )
- */
-static int factionL_modplayerraw(lua_State* L) {
- LuaFaction* f;
- double n;
- f = lua_tofaction(L, 1);
-
- if(lua_isnumber(L, 2)) n = lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- faction_modPlayerRaw(f->f, n);
- return 0;
-}
-
-/**
- * @brief Get the players standing with the faction.
- * @return The value of the standing and the human readable string.
- * @luafunc playerStanding()
- */
-static int factionL_playerstanding(lua_State* L) {
- LuaFaction* f;
- int n;
- f = lua_tofaction(L, 1);
- n = faction_getPlayer(f->f);
- lua_pushnumber(L, n);
- lua_pushstring(L, faction_getStanding(n));
- return 1;
-}
-
-/**
- * @brief Get the enemies of the faction.
- * @return A table containing the enemies of the faction.
- * @luafunc enemies()
- */
-static int factionL_enemies(lua_State* L) {
- int i, n;
- int* factions;
- LuaFaction*f, fe;
-
- f = lua_tofaction(L, 1);
-
- /* Push the enemies in a table. */
- lua_newtable(L);
- factions = faction_getEnemies(f->f, &n);
- for(i = 0; i < n; i++) {
- lua_pushnumber(L, i+1); /* Key. */
- fe.f = factions[i];
- lua_pushfaction(L, fe); /* value */
- lua_rawset(L, -3);
- }
-
- return 1;
-}
-
-/**
- * @brief Get the alies of the faction.
- * @return A table containing the allies of the faction.
- * @luafunc allies()
- */
-static int factionL_allies(lua_State* L) {
- int i, n;
- int* factions;
- LuaFaction* f, fa;
-
- f = lua_tofaction(L, 1);
-
- /* Push the enemeies in a table. */
- lua_newtable(L);
- factions = faction_getAllies(f->f, &n);
- for(i = 0; i < n; i++) {
- lua_pushnumber(L, i+1); /* Key. */
- fa.f = factions[i];
- lua_pushfaction(L, fa); /* value. */
- lua_rawset(L, -3);
- }
-
- return 1;
-}
-
-/**
- * @}
- */
-
diff --git a/src/llua_faction.h b/src/llua_faction.h
deleted file mode 100644
index 69d71c5..0000000
--- a/src/llua_faction.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-#include "lua.h"
-
-#define FACTION_METATABLE "Faction" /**< Faction metatable identifier. */
-
-/**
- * @brief Lua faction wrapper.
- */
-typedef struct LuaFaction_s {
- int f; /**< Internal use faction identifier. */
-} LuaFaction;
-
-/* Load the space library. */
-int lua_loadFaction(lua_State* L, int readonly);
-
-/* Faction operations. */
-LuaFaction* lua_tofaction(lua_State* L, int ind);
-LuaFaction* lua_pushfaction(lua_State* L, LuaFaction faction);
-int lua_isfaction(lua_State* L, int ind);
-
diff --git a/src/llua_misn.c b/src/llua_misn.c
deleted file mode 100644
index 5323a0e..0000000
--- a/src/llua_misn.c
+++ /dev/null
@@ -1,1117 +0,0 @@
-#include
-#include
-#include
-#include
-
-#include "lua.h"
-#include "lauxlib.h"
-
-#include "llua.h"
-#include "llua_space.h"
-#include "llua_pilot.h"
-#include "llua_faction.h"
-#include "lluadef.h"
-#include "hook.h"
-#include "mission.h"
-#include "log.h"
-#include "lephisto.h"
-#include "rng.h"
-#include "space.h"
-#include "toolkit.h"
-#include "land.h"
-#include "pilot.h"
-#include "player.h"
-#include "ltime.h"
-#include "lxml.h"
-#include "music.h"
-#include "unidiff.h"
-#include "llua_misn.h"
-
-/* Similar to lua vars, but with less variety. */
-#define MISN_VAR_NIL 0
-#define MISN_VAR_NUM 1
-#define MISN_VAR_BOOL 2
-#define MISN_VAR_STR 3
-typedef struct misn_var_ {
- char* name;
- char type;
- union {
- double num;
- char* str;
- int b;
- } d;
-} misn_var;
-
-/* Variable stack. */
-static misn_var* var_stack = NULL;
-static int var_nstack = 0;
-static int var_mstack = 0;
-
-/* Current mission. */
-static Mission* cur_mission = NULL;
-static int misn_delete = 0; /* If 1 delete current mission. */
-
-/* Static. */
-static int var_add(misn_var* var);
-static void var_free(misn_var* var);
-static unsigned int hook_generic(lua_State* L, char* stack);
-static int misn_runTopStack(Mission* misn, char* func);
-/* Extern. */
-int misn_run(Mission* misn, char* func);
-int var_save(xmlTextWriterPtr writer);
-int var_load(xmlNodePtr parent);
-/* External. */
-extern void mission_sysMark(void);
-
-/* -- Libraries. -- */
-
-/* Mission. */
-static int misn_setTitle(lua_State* L);
-static int misn_setDesc(lua_State* L);
-static int misn_setReward(lua_State* L);
-static int misn_setMarker(lua_State* L);
-static int misn_factions(lua_State* L);
-static int misn_accept(lua_State* L);
-static int misn_finish(lua_State* L);
-static int misn_timerStart(lua_State* L);
-static int misn_timerStop(lua_State* L);
-static int misn_takeoff(lua_State* L);
-static const luaL_reg misn_methods[] = {
- { "setTitle", misn_setTitle },
- { "setDesc", misn_setDesc },
- { "setReward", misn_setReward },
- { "setMarker", misn_setMarker },
- { "factions", misn_factions },
- { "accept", misn_accept },
- { "finish", misn_finish },
- { "timerStart", misn_timerStart },
- { "timerStop", misn_timerStop },
- { "takeoff", misn_takeoff },
- { 0, 0 }
-};
-
-/* Var. */
-static int var_peek(lua_State* L);
-static int var_pop(lua_State* L);
-static int var_push(lua_State* L);
-static const luaL_reg var_methods[] = {
- { "peek", var_peek },
- { "pop", var_pop},
- { "push", var_push},
- {0, 0}
-};
-
-/* Only conditional. */
-static const luaL_reg var_cond_methods[] = {
- { "peek", var_peek },
- {0, 0 }
-};
-
-/* Player. */
-static int player_getname(lua_State* L);
-static int player_shipname(lua_State* L);
-static int player_freeSpace(lua_State* L);
-static int player_addCargo(lua_State* L);
-static int player_rmCargo(lua_State* L);
-static int player_jetCargo(lua_State* L);
-static int player_pay(lua_State* L);
-static int player_msg(lua_State* L);
-static int player_modFaction(lua_State* L);
-static int player_modFactionRaw(lua_State* L);
-static int player_getFaction(lua_State* L);
-static int player_getRating(lua_State* L);
-static int player_getPosition(lua_State* L);
-static int player_getPilot(lua_State* L);
-static const luaL_reg player_methods[] = {
- { "name", player_getname },
- { "ship", player_shipname },
- { "freeCargo", player_freeSpace },
- { "addCargo", player_addCargo },
- { "rmCargo", player_rmCargo },
- { "jetCargo", player_jetCargo },
- { "pay", player_pay },
- { "msg", player_msg },
- { "modFaction", player_modFaction },
- { "modFactionRaw", player_modFactionRaw },
- { "getFaction", player_getFaction },
- { "getRating", player_getRating },
- { "pos", player_getPosition },
- { "pilot", player_getPilot },
- { 0, 0 }
-};
-
-static const luaL_reg player_cond_methods[] = {
- { "name", player_getname },
- { "ship", player_shipname },
- { "getFaction", player_getFaction },
- { "getRating", player_getRating },
- { 0, 0 }
-};
-
-/* Hooks. */
-static int hook_land(lua_State* L);
-static int hook_takeoff(lua_State* L);
-static int hook_time(lua_State* L);
-static int hook_enter(lua_State* L);
-static int hook_pilot(lua_State* L);
-static const luaL_reg hook_methods[] = {
- { "land", hook_land },
- { "takeoff", hook_takeoff },
- { "time", hook_time },
- { "enter", hook_enter },
- { "pilot", hook_pilot },
- { 0, 0 }
-}; /**< Hook Lua methods. */
-
-/* Diffs. */
-static int diff_applyL(lua_State* L);
-static int diff_removeL(lua_State* L);
-static int diff_isappliedL(lua_State* L);
-static const luaL_reg diff_methods[] = {
- { "apply", diff_applyL },
- { "remove", diff_removeL },
- { "isApplied", diff_isappliedL },
- { 0, 0 }
-}; /**< Unidiff Lua methods. */
-
-static const luaL_reg diff_cond_methods[] = {
- { "isApplied", diff_isappliedL },
- { 0, 0 }
-}; /**< Unidiff Lua read only methods. */
-
-/* Register all the libaries. */
-int misn_loadLibs(lua_State* L) {
- lua_loadLephisto(L);
- lua_loadMisn(L);
- lua_loadVar(L, 0);
- lua_loadSpace(L, 0);
- lua_loadTime(L, 0);
- lua_loadPlayer(L, 0);
- lua_loadRnd(L);
- lua_loadTk(L);
- lua_loadHook(L);
- lua_loadPilot(L, 0);
- lua_loadMusic(L, 0);
- lua_loadDiff(L, 0);
- lua_loadFaction(L, 0);
- return 0;
-}
-
-int misn_loadCondLibs(lua_State* L) {
- lua_loadTime(L, 1);
- lua_loadSpace(L, 1);
- lua_loadVar(L, 1);
- lua_loadPlayer(L, 1);
- lua_loadDiff(L,1);
- return 0;
-}
-
-/* Individual libarary loading. */
-int lua_loadMisn(lua_State* L) {
- luaL_register(L, "misn", misn_methods);
- return 0;
-}
-
-/**
- * @brief Load the mission variable lua library.
- * @param readonly Whether to open in read-only form.
- * @retrun 0 on success.
- */
-int lua_loadVar(lua_State* L, int readonly) {
- if(readonly == 0)
- luaL_register(L, "var", var_methods);
- else
- luaL_register(L, "var", var_cond_methods);
- return 0;
-}
-
-int lua_loadPlayer(lua_State* L, int readonly) {
- if(readonly == 0)
- luaL_register(L, "player", player_methods);
- else
- luaL_register(L, "player", player_cond_methods);
- return 0;
-}
-
-/**
- * @brief Loads the hook lua library.
- * @param L Lua state.
- * @return 0 on success.
- */
-int lua_loadHook(lua_State* L) {
- luaL_register(L, "hook", hook_methods);
- return 0;
-}
-
-/**
- * @brief Loads the diff Lua library.
- * @param L Lua State.
- * @param readonly Load read only functions.
- * @return 0 on success.
- */
-int lua_loadDiff(lua_State* L, int readonly) {
- if(readonly == 0)
- luaL_register(L, "diff", diff_methods);
- else
- luaL_register(L, "diff", diff_cond_methods);
- return 0;
-}
-
-/**
- * @brief Tries to run a mission, but doesn't err if it fails.
- * @param misn Mission that owns the function.
- * @param func Name of the function to call.
- * @return -1 on error, 1 on misn.finish() call, 2 if mission got deleted
- * and 0 normally.
- */
-int misn_tryRun(Mission* misn, char* func) {
- /* Get the function to run. */
- lua_getglobal(misn->L, func);
- if(lua_isnil(misn->L, -1))
- return 0;
- return misn_runTopStack(misn, func);
-}
-
-/*
- * Run a mission function.
- * -1 on error, 1 on misn.finish() call, 2 if mission got deleted and 0 normally.
- */
-int misn_run(Mission* misn, char* func) {
- /* Run the function. */
- lua_getglobal(misn->L, func);
- return misn_runTopStack(misn, func);
-}
-
-/**
- *
- */
-static int misn_runTopStack(Mission* misn, char* func) {
- int i, ret;
- char* err;
- lua_State* L;
-
- cur_mission = misn;
- misn_delete = 0;
- L = misn->L;
-
- ret = lua_pcall(L, 0, 0, 0);
- if(ret != 0) { /* Error has occured. */
- /* Did an oops. */
- err = (lua_isstring(L, -1)) ? (char*) lua_tostring(L, -1) : NULL;
- if(strcmp(err, "Mission Done")!=0)
- WARN("Mission '%s' -> '%s' : %s",
- cur_mission->data->name, func, (err) ? err : "Unknown Error");
- else ret = 1;
- }
-
- /* Mission is finished. */
- if(misn_delete) {
- mission_cleanup(cur_mission);
- for(i = 0; i < MISSION_MAX; i++)
- if(cur_mission == &player_missions[i]) {
- memmove(&player_missions[i], &player_missions[i+1],
- sizeof(Mission) * (MISSION_MAX-i-1));
- memset(&player_missions[MISSION_MAX-1], 0, sizeof(Mission));
- break;
- }
- }
- cur_mission = NULL;
-
- return ret;
-}
-
-/* Save the mission variables. */
-int var_save(xmlTextWriterPtr writer) {
- int i;
-
- xmlw_startElem(writer, "vars");
-
- for(i = 0; i < var_nstack; i++) {
- xmlw_startElem(writer, "vars");
-
- xmlw_attr(writer, "name", var_stack[i].name);
-
- switch(var_stack[i].type) {
- case MISN_VAR_NIL:
- xmlw_attr(writer, "type", "nil");
- break;
- case MISN_VAR_NUM:
- xmlw_attr(writer, "type", "num");
- xmlw_str(writer, "%d", var_stack[i].d.num);
- break;
- case MISN_VAR_BOOL:
- xmlw_attr(writer, "type", "bool");
- xmlw_str(writer, "%d", var_stack[i].d.b);
- break;
- case MISN_VAR_STR:
- xmlw_attr(writer, "type", "str");
- xmlw_str(writer, var_stack[i].d.str);
- break;
- }
- xmlw_endElem(writer); /* var. */
- }
- xmlw_endElem(writer); /* vars. */
-
- return 0;
-}
-
-/* Load the vars. */
-int var_load(xmlNodePtr parent) {
- char* str;
- xmlNodePtr node, cur;
- misn_var var;
-
- var_cleanup();
-
- node = parent->xmlChildrenNode;
-
- do {
- if(xml_isNode(node, "vars")) {
- cur = node->xmlChildrenNode;
-
- do {
- if(xml_isNode(cur, "var")) {
- xmlr_attr(cur, "name", var.name);
- xmlr_attr(cur, "type", str);
- if(strcmp(str, "nil")==0)
- var.type = MISN_VAR_NIL;
- else if(strcmp(str, "num")==0) {
- var.type = MISN_VAR_NUM;
- var.d.num = xml_getFloat(cur);
- }
- else if(strcmp(str, "bool")==0) {
- var.type = MISN_VAR_BOOL;
- var.d.b = xml_getInt(cur);
- }
- else if(strcmp(str, "str")==0) {
- var.type = MISN_VAR_STR;
- var.d.str = xml_getStrd(cur);
- } else {
- /* Supeh error checking. */
- WARN("Unknown var type '%s'", str);
- free(var.name);
- continue;
- }
- free(str);
- var_add(&var);
- }
- } while(xml_nextNode(cur));
- }
- } while(xml_nextNode(node));
-
- return 0;
-}
-
-/* Add a var to the stack, strings will be SHARED, don't free!!! */
-static int var_add(misn_var* new_var) {
- int i;
-
- if(var_nstack+1 > var_mstack) {
- /* More memory. */
- var_mstack += 64; /* Overkill much?? */
- var_stack = realloc(var_stack, var_mstack * sizeof(misn_var));
- }
-
- /* Check if already exists. */
- for(i = 0; i < var_nstack; i++)
- if(strcmp(new_var->name, var_stack[i].name)==0) {
- var_free(&var_stack[i]);
- memcpy(&var_stack[i], new_var, sizeof(misn_var));
- return 0;
- }
-
- memcpy(&var_stack[var_nstack], new_var, sizeof(misn_var));
- var_nstack++;
-
- return 0;
-}
-
-/* -- Mission. -- */
-
-static int misn_setTitle(lua_State* L) {
- LLUA_MIN_ARGS(1);
- if(lua_isstring(L, 1)) {
- if(cur_mission->title)
- /* Cleanup the old title. */
- free(cur_mission->title);
- cur_mission->title = strdup((char*)lua_tostring(L, 1));
- }
- return 0;
-}
-
-static int misn_setDesc(lua_State* L) {
- LLUA_MIN_ARGS(1);
- if(lua_isstring(L, 1)) {
- if(cur_mission->desc)
- /* Cleanup the old description. */
- free(cur_mission->desc);
- cur_mission->desc = strdup((char*)lua_tostring(L, 1));
- }
- return 0;
-}
-
-static int misn_setReward(lua_State* L) {
- LLUA_MIN_ARGS(1);
- if(lua_isstring(L, 1)) {
- if(cur_mission->reward != NULL) /* Cleanup old reward. */
- /* Cleanup the old reward. */
- free(cur_mission->reward);
- cur_mission->reward = strdup((char*)lua_tostring(L, 1));
- }
- else LLUA_INVALID_PARAMETER();
- return 0;
-}
-
-static int misn_setMarker(lua_State* L) {
- LuaSystem* sys;
-
- /* No parameter clears the marker. */
- if(lua_gettop(L)==0) {
- if(cur_mission->sys_marker != NULL)
- free(cur_mission->sys_marker);
- mission_sysMark(); /* Clear the marker. */
- }
-
- /* Passing in a Star System. */
- if(lua_issystem(L, 1)) {
- sys = lua_tosystem(L, 1);
- cur_mission->sys_marker = strdup(sys->s->name);
- mission_sysMark(); /* Mark the system. */
- }
- else LLUA_INVALID_PARAMETER();
-
- return 0;
-}
-
-static int misn_factions(lua_State* L) {
- int i;
- MissionData* dat;
- LuaFaction f;
-
- dat = cur_mission->data;
-
- /* We'll push all the factions in table form. */
- lua_newtable(L);
- for(i = 0; i < dat->avail.nfactions; i++) {
- lua_pushnumber(L, i+1); /* Index, starts with 1. */
- f.f = dat->avail.factions[i];
- lua_pushfaction(L, f); /* Value. */
- lua_rawset(L, -3); /* Store the value in the table. */
- }
- return 1;
-}
-
-static int misn_accept(lua_State* L) {
- int i, ret;
-
- ret = 0;
-
- /* Find the last mission. */
- for(i = 0; i < MISSION_MAX; i++)
- if(player_missions[i].data == NULL) break;
-
- /* No missions left. */
- if(i >= MISSION_MAX) ret = 1;
- else {
- memcpy(&player_missions[i], cur_mission, sizeof(Mission));
- memset(cur_mission, 0, sizeof(Mission));
- cur_mission = &player_missions[i];
- }
- lua_pushboolean(L, !ret); /* We'll convert C style return to lua. */
- return 1;
-}
-
-static int misn_finish(lua_State* L) {
- int b;
-
- if(lua_isboolean(L, 1)) b = lua_toboolean(L, 1);
- else {
- lua_pushstring(L, "Mission Done");
- lua_error(L); /* THERE IS NO RETURN! */
- return 0;
- }
-
- misn_delete = 1;
-
- if(b && mis_isFlag(cur_mission->data, MISSION_UNIQUE))
- player_missionFinished(mission_getID(cur_mission->data->name));
-
- lua_pushstring(L, "Mission Done");
- lua_error(L); /* Should not return.. */
-
- return 0;
-}
-
-/**
- * @fn static int misn_timerStart(lua_State* L)
- *
- * @brief number timerStart( string func, number delay )
- *
- * Start a timer.
- * @param func Function to run when timer is up.
- * @param delay Milliseconds to wait for timer.
- * @return The timer being used.
- */
-static int misn_timerStart(lua_State* L) {
- LLUA_MIN_ARGS(2);
- int i;
- char* func;
- double delay;
-
- /* Parse arguments. */
- if(lua_isstring(L,1))
- func = (char*)lua_tostring(L,1);
- else LLUA_INVALID_PARAMETER();
- if(lua_isnumber(L,2))
- delay = lua_tonumber(L,2);
- else LLUA_INVALID_PARAMETER();
-
- /* Add timer. */
- for(i = 0; i < MISSION_TIMER_MAX; i++) {
- if(cur_mission->timer[i] == 0.) {
- cur_mission->timer[i] = delay / 1000.;
- cur_mission->tfunc[i] = strdup(func);
- break;
- }
- }
-
- /* No timer found. */
- if(i >= MISSION_TIMER_MAX) {
- return 0;
- }
-
- /* Return the timer id. */
- lua_pushnumber(L, i);
- return 1;
-}
-
-/**
- * @fn static int misn_timerStop(lua_State* L)
- *
- * @brief timerStop(number t)
- *
- * Stop a timer previously started with timerStart().
- * @param t Timer to stop.
- */
-static int misn_timerStop(lua_State* L) {
- LLUA_MIN_ARGS(1);
- int t;
-
- /* Parse arguments. */
- if(lua_isnumber(L,1))
- t = (int)lua_tonumber(L,1);
- else LLUA_INVALID_PARAMETER();
-
- /* Stop the timer. */
- if(cur_mission->timer[t] != 0.) {
- cur_mission->timer[t] = 0.;
- if(cur_mission->tfunc[t] != NULL) {
- free(cur_mission->tfunc[t]);
- cur_mission->tfunc[t] = NULL;
- }
- }
- return 0;
-}
-
-/**
- * @brief Force the player to take off if she is landed.
- *
- * @luafunc takeoff()
- */
-static int misn_takeoff(lua_State* L) {
- (void) L;
- if(landed)
- landed = 0;
-
- return 0;
-}
-
-/* -- Var. -- */
-
-/* Check if a variable exists. */
-int var_checkflag(char* str) {
- int i;
- for(i = 0; i < var_nstack; i++)
- if(strcmp(var_stack[i].name, str)==0)
- return 1;
- return 0;
-}
-
-static int var_peek(lua_State* L) {
- LLUA_MIN_ARGS(1);
- int i;
- char* str;
-
- if(lua_isstring(L, 1)) str = (char*) lua_tostring(L, 1);
- else {
- LLUA_DEBUG("Trying to peek a var with non-string name");
- return 0;
- }
-
- for(i = 0; i < var_nstack; i++)
- if(strcmp(str, var_stack[i].name)==0) {
- switch(var_stack[i].type) {
- case MISN_VAR_NIL:
- lua_pushnil(L);
- break;
- case MISN_VAR_NUM:
- lua_pushnumber(L, var_stack[i].d.num);
- break;
- case MISN_VAR_BOOL:
- lua_pushboolean(L, var_stack[i].d.b);
- break;
- case MISN_VAR_STR:
- lua_pushstring(L, var_stack[i].d.str);
- break;
- }
- return 1;
- }
- lua_pushnil(L);
- return 1;
-}
-
-static int var_pop(lua_State* L) {
- LLUA_MIN_ARGS(1);
- int i;
- char* str;
-
- if(lua_isstring(L, 1)) str = (char*) lua_tostring(L, 1);
- else {
- LLUA_DEBUG("Trying to pop a var with non-string name");
- return 0;
- }
-
- for(i = 0; i < var_nstack; i++)
- if(strcmp(str, var_stack[i].name)==0) {
- var_free(&var_stack[i]);
- memmove(&var_stack[i], &var_stack[i+1], sizeof(misn_var)*(var_nstack-i-1));
- var_stack--;
- return 0;
- }
- LLUA_DEBUG("Var '%s' not found in stack", str);
- return 0;
-}
-
-static int var_push(lua_State* L) {
- LLUA_MIN_ARGS(2);
- char* str;
- misn_var var;
-
- if(lua_isstring(L, 1)) str = (char*) lua_tostring(L, 1);
- else {
- LLUA_DEBUG("Trying to push a var with non-string name");
- return 0;
- }
-
- var.name = strdup(str);
-
- /* Store appropriate data. */
- if(lua_isnil(L, 2))
- var.type = MISN_VAR_NIL;
- else if(lua_isnumber(L, 2)) {
- var.type = MISN_VAR_NUM;
- var.d.num = (double)lua_tonumber(L, 2);
- }
- else if(lua_isboolean(L, 2)) {
- var.type = MISN_VAR_BOOL;
- var.d.b = lua_toboolean(L, 2);
- }
- else if(lua_isstring(L, 2)) {
- var.type = MISN_VAR_STR;
- var.d.str = strdup((char*)lua_tostring(L, 2));
- } else {
- LLUA_DEBUG("Trying to push a var of invalid data type to stack");
- return 0;
- }
-
- var_add(&var);
-
- return 0;
-}
-
-static void var_free(misn_var* var) {
- switch(var->type) {
- case MISN_VAR_STR:
- if(var->d.str != NULL) {
- free(var->d.str);
- var->d.str = NULL;
- }
- break;
- case MISN_VAR_NIL:
- case MISN_VAR_NUM:
- case MISN_VAR_BOOL:
- break;
- }
- if(var->name != NULL) {
- free(var->name);
- var->name = NULL;
- }
-}
-
-void var_cleanup(void) {
- int i;
- for(i = 0; i < var_nstack; i++)
- var_free(&var_stack[i]);
-
- if(var_stack != NULL) free(var_stack);
- var_stack = NULL;
- var_nstack = 0;
- var_mstack = 0;
-}
-
-/* -- Player. -- */
-
-static int player_getname(lua_State* L) {
- lua_pushstring(L, player_name);
- return 1;
-}
-
-static int player_shipname(lua_State* L) {
- lua_pushstring(L, player->name);
- return 1;
-}
-
-static int player_freeSpace(lua_State* L) {
- lua_pushnumber(L, pilot_cargoFree(player));
- return 1;
-}
-
-static int player_addCargo(lua_State* L) {
- Commodity* cargo;
- int quantity, ret;
-
- LLUA_MIN_ARGS(2);
-
- if(lua_isstring(L, 2)) cargo = commodity_get((char*) lua_tostring(L, 1));
- else LLUA_INVALID_PARAMETER();
- if(lua_isnumber(L, 2)) quantity = (int)lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* First try to add the cargo. */
- ret = pilot_addMissionCargo(player, cargo, quantity);
- mission_linkCargo(cur_mission, ret);
-
- lua_pushnumber(L, ret);
- return 1;
-}
-
-static int player_rmCargo(lua_State* L) {
- int ret;
- unsigned int id;
-
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L, 1)) id = (unsigned int) lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- /* First try to remove the cargo from player. */
- if(pilot_rmMissionCargo(player, id, 0) != 0) {
- lua_pushboolean(L, 0);
- return 1;
- }
-
- /* Now unlink the mission cargo if it was successful. */
- ret = mission_unlinkCargo(cur_mission, id);
-
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-/**
- * @brief jetCargo(number cargoid)
- *
- * Jettison the mission cargo.
- * @param cargoid ID of the cargo to jettison.
- */
-static int player_jetCargo(lua_State* L) {
- int ret;
- unsigned int id;
-
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L, 1)) id = (unsigned int)lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- /* First try to remove the cargo from player. */
- if(pilot_rmMissionCargo(player, id, 0) != 0) {
- lua_pushboolean(L, 0);
- return 1;
- }
-
- /* Now unlink the mission cargo if it was successful. */
- ret = mission_unlinkCargo(cur_mission, id);
-
- lua_pushboolean(L, !ret);
- return 1;
-}
-
-static int player_pay(lua_State* L) {
- int money;
-
- LLUA_MIN_ARGS(1);
-
- if(lua_isnumber(L, 1)) money = (int) lua_tonumber(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- player->credits += money;
-
- return 0;
-}
-
-static int player_msg(lua_State* L) {
- LLUA_MIN_ARGS(1);
- char* str;
-
- if(lua_isstring(L, -1)) str = (char*) lua_tostring(L, -1);
- else LLUA_INVALID_PARAMETER();
-
- player_message(str);
- return 0;
-}
-
-static int player_modFaction(lua_State* L) {
- LLUA_MIN_ARGS(2);
- int f;
- double mod;
-
- if(lua_isstring(L, 1)) f = faction_get(lua_tostring(L, 1));
- else LLUA_INVALID_PARAMETER();
-
- if(lua_isnumber(L, 2)) mod = lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- faction_modPlayer(f, mod);
-
- return 0;
-}
-
-static int player_modFactionRaw(lua_State* L) {
- LLUA_MIN_ARGS(2);
- int f;
- double mod;
-
- if(lua_isstring(L, 1)) f = faction_get(lua_tostring(L,1));
- else LLUA_INVALID_PARAMETER();
-
- if(lua_isnumber(L,2)) mod = lua_tonumber(L,2);
- else LLUA_INVALID_PARAMETER();
-
- faction_modPlayerRaw(f, mod);
-
- return 0;
-}
-
-static int player_getFaction(lua_State* L) {
- LLUA_MIN_ARGS(1);
- int f;
-
- if(lua_isstring(L, 1)) f = faction_get(lua_tostring(L, 1));
- else LLUA_INVALID_PARAMETER();
- lua_pushnumber(L, faction_getPlayer(f));
-
- return 1;
-}
-
-static int player_getRating(lua_State* L) {
- lua_pushnumber(L, player_crating);
- lua_pushstring(L, player_rating());
- return 2;
-}
-
-/* -- HOOK -- */
-static unsigned int hook_generic(lua_State* L, char* stack) {
- int i;
- char* func;
-
- LLUA_MIN_ARGS(1);
-
- /* Last parameter must be function to hook. */
- if(lua_isstring(L, -1)) func = (char*)lua_tostring(L, -1);
- else LLUA_INVALID_PARAMETER();
-
- /* Make sure mission is a player mission. */
- for(i = 0; i < MISSION_MAX; i++)
- if(player_missions[i].id == cur_mission->id)
- break;
- if(i >= MISSION_MAX) {
- WARN("Mission not in stack trying to hook");
- return 0;
- }
-
- return hook_add(cur_mission->id, func, stack);
-}
-
-static int hook_land(lua_State* L) {
- hook_generic(L, "land");
- return 0;
-}
-
-static int hook_takeoff(lua_State* L) {
- hook_generic(L, "takeoff");
- return 0;
-}
-
-static int hook_time(lua_State* L) {
- hook_generic(L, "time");
- return 0;
-}
-
-static int hook_enter(lua_State* L) {
- hook_generic(L, "enter");
- return 0;
-}
-
-/**
- * @fn static int player_getPosition(lua_State* L)
- *
- * @brief Vec2 getPos(nil)
- *
- * Get the players position.
- * @return The position of the player.
- */
-static int player_getPosition(lua_State* L) {
- LuaVector v;
-
- vectcpy(&v.vec, &player->solid->pos);
- lua_pushvector(L, v);
- return 1;
-}
-
-/**
- * @fn static int player_getPilot(lua_State* L)
- *
- * @brief Pilot getPilot(nil)
- *
- * Get the players associated pilot.
- * @return The players pilot.
- */
-static int player_getPilot(lua_State* L) {
- LuaPilot lp;
- lp.pilot = PLAYER_ID;
- lua_pushpilot(L, lp);
- return 1;
-}
-
-/**
- * @fn static int hook_pilot(lua_State* L)
- * @ingroup HOOK
- *
- * @brief number pilot(Pilot pilot, string type, string func)
- *
- * Hooks the function to a specific pilot.
- *
- * You can hook to different actions. At the moment hook system only supports:
- * -- "death" : Triggered when pilot dies.
- * -- "board" : Triggered when pilot is boarded.
- * -- "disable" : Triggered when pilot is disabled.
- * -- "jump" : Triggered when pilot jumps to hyperspace.
- *
- * @param pilot Pilot identifier to hook.
- * @param typer One of the supported hook types.
- * @param func Function to run when hook is triggered.
- * @return Hook identifier.
- */
-static int hook_pilot(lua_State* L) {
- LLUA_MIN_ARGS(2);
- unsigned int h;
- LuaPilot* p;
- int type;
- char* hook_type;
-
- /* First parameter - pilot to hook. */
- if(lua_ispilot(L, 1)) p = lua_topilot(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- /* Second parameer - Hook name. */
- if(lua_isstring(L, 2)) hook_type = (char*) lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Check to see if hook_type is valid. */
- if(strcmp(hook_type, "death")==0) type = PILOT_HOOK_DEATH;
- else if(strcmp(hook_type, "board")==0) type = PILOT_HOOK_BOARD;
- else if(strcmp(hook_type, "disable")==0) type = PILOT_HOOK_DISABLE;
- else if(strcmp(hook_type, "jump")==0) type = PILOT_HOOK_JUMP;
- else { /* Hook type not valid. */
- LLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type);
- return 0;
- }
-
-
- /* Actually add the hook. */
- h = hook_generic(L, hook_type);
- pilot_addHook(pilot_get(p->pilot), type, h);
-
- return 0;
-}
-
-/**
- * @defgroup DIFF Universe Diff Lua Bindings.
- *
- * @brief Lua bindings to apply/remove Universe Diffs.
- *
- * Functions should be called like:
- *
- * @code
- * diff.function(parameters)
- * @endcode
- *
- * @{
- */
-
-/**
- * @fn static int diff_applyL(lua_State* L)
- *
- * @brief apply(string name)
- *
- * Applies a diff by name.
- * @param name Name of the diff to apply.
- */
-static int diff_applyL(lua_State* L) {
- char* name;
-
- if(lua_isstring(L, 1)) name = (char*)lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- diff_apply(name);
- return 0;
-}
-
-/**
- * @fn static int diff_removeL(lua_State* L)
- *
- * @brief remove(string name)
- *
- * Removes a diff by name.
- * @param name Name of the diff to remove.
- */
-static int diff_removeL(lua_State* L) {
- char* name;
-
- if(lua_isstring(L, 1)) name = (char*)lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- diff_remove(name);
- return 0;
-}
-
-/**
- * @fn static int diff_isappliedL(lua_State* L)
- *
- * @brief bool isApplied(string name)
- *
- * Check to see if a diff is currently applied.
- * @param name Name of the diff to check.
- * @return true if it is applied, false if it isn't.
- */
-static int diff_isappliedL(lua_State* L) {
- char* name;
- if(lua_isstring(L, 1)) name = (char*)lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- lua_pushboolean(L, diff_isApplied(name));
- return 1;
-}
-/**
- * @}
- */
-
diff --git a/src/llua_misn.h b/src/llua_misn.h
deleted file mode 100644
index c9db818..0000000
--- a/src/llua_misn.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#include "lua.h"
-
-/* Check if a flag exists on the variable stack. */
-int var_checkflag(char* str);
-void var_cleanup(void);
-
-/* Load the libraries for a lua state. */
-int misn_loadLibs(lua_State* L);
-int misn_loadCondLibs(lua_State* L); /* Safe read only stuff. */
-
-/* Individual library stuff. */
-int lua_loadMisn(lua_State* L);
-int lua_loadVar(lua_State* L, int readonly);
-int lua_loadPlayer(lua_State* L, int readonly);
-int lua_loadHook(lua_State* L);
-int lua_loadDiff(lua_State* L, int readonly);
-
diff --git a/src/llua_pilot.c b/src/llua_pilot.c
deleted file mode 100644
index 7dbcdfa..0000000
--- a/src/llua_pilot.c
+++ /dev/null
@@ -1,682 +0,0 @@
-/**
- * @file llua_space.c
- *
- * @brief Handle the Lua space bindings.
- *
- * These bindings control the planets and systems.
- */
-
-#include "lauxlib.h"
-#include "lephisto.h"
-#include "llua.h"
-#include "lluadef.h"
-#include "llua_space.h"
-#include "llua_faction.h"
-#include "rng.h"
-#include "pilot.h"
-#include "player.h"
-#include "llua_pilot.h"
-
-/* From pilot.c */
-extern Pilot** pilot_stack;
-extern int pilot_nstack;
-
-static int pilotL_createmetatable(lua_State* L);
-/* Pilots. */
-static int pilot_getPlayer(lua_State* L);
-static int pilot_addFleet(lua_State* L);
-static int pilot_clear(lua_State* L);
-static int pilot_toggleSpawn(lua_State* L);
-static int pilot_getPilots(lua_State* L);
-static const luaL_reg pilot_methods[] = {
- { "player", pilot_getPlayer },
- { "add", pilot_addFleet },
- { "clear", pilot_clear },
- { "toggleSpawn", pilot_toggleSpawn },
- { "get", pilot_getPilots },
- { 0, 0 }
-}; /**< Pilot lua methods. */
-
-/* Pilot metatable methods. */
-static int pilotL_eq(lua_State* L);
-static int pilotL_name(lua_State* L);
-static int pilotL_alive(lua_State* L);
-static int pilotL_rename(lua_State* L);
-static int pilotL_position(lua_State* L);
-static int pilotL_velocity(lua_State* L);
-static int pilotL_warp(lua_State* L);
-static int pilotL_broadcast(lua_State* L);
-static int pilotL_setFaction(lua_State* L);
-static int pilotL_setHostile(lua_State* L);
-static int pilotL_setFriendly(lua_State* L);
-static const luaL_reg pilotL_methods[] = {
- { "__eq", pilotL_eq },
- { "name", pilotL_name },
- { "alive", pilotL_alive },
- { "rename", pilotL_rename },
- { "pos", pilotL_position },
- { "vel", pilotL_velocity },
- { "warp", pilotL_warp },
- { "broadcast", pilotL_broadcast },
- { "setFaction", pilotL_setFaction },
- { "setHostile", pilotL_setHostile },
- { "setFriendly", pilotL_setFriendly },
- { 0, 0 }
-}; /**< Pilot metatable methods. */
-
-/**
- * @fn int lua_loadPilot(lua_State* L, int readonly)
- *
- * @brief Load the space library.
- * @param L State to load space library into.
- * @return 0 on success.
- */
-int lua_loadPilot(lua_State* L, int readonly) {
- if(readonly) /* Nothing is read only. */
- return 0;
-
- /* Register the functions. */
- luaL_register(L, "pilot", pilot_methods);
-
- /* Register the metatables. */
- pilotL_createmetatable(L);
-
- return 0;
-}
-
-/**
- * @fn static int pilotL_createmetatable(lua_State* L)
- *
- * @brief Registers the pilot metatable.
- * @param L Lua state to register metatable in.
- * @return 0 on success.
- */
-static int pilotL_createmetatable(lua_State* L) {
- /* Create the metatable. */
- luaL_newmetatable(L, PILOT_METATABLE);
-
- /* Create the access table. */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
- /* Register the values. */
- luaL_register(L, NULL, pilotL_methods);
-
- return 0;
-}
-
-/**
- * @defgroup PILOT Pilot Lua bindings.
- *
- * @brief Lua bindings to interact with pilots.
- *
- * @luamod pilot
- * Functions should be called like:
- *
- * @code
- * pilot.function(parameters)
- * @endcode
- */
-/**
- * @defgroup META_PILOT Pilot Metatable
- *
- * @brief Represents a pilot in Lua.
- *
- * To call members of the metatable always use:
- *
- * @code
- * pilot:function(param)
- * @endcode
- */
-
-/**
- * @fn LuaPilot* lua_topilot(lua_State* L, int ind)
- *
- * @brief Get pilot at index.
- * @param L Lua state to get pilot from.
- * @param ind Index position to find the pilot.
- * @return Pilot found at the index in the state.
- */
-LuaPilot* lua_topilot(lua_State* L, int ind) {
- if(lua_isuserdata(L, ind)) {
- return (LuaPilot*)lua_touserdata(L, ind);
- }
- luaL_typerror(L, ind, PILOT_METATABLE);
- return NULL;
-}
-
-/**
- * @fn LuaPilot* lua_pushpilot(lua_State* L, LuaPilot pilot)
- *
- * @brief Push a pilot on the stack.
- * @param L Lua state to push pilot into.
- * @param pilot Pilot to push.
- * @return Newly pushed pilot.
- */
-LuaPilot* lua_pushpilot(lua_State* L, LuaPilot pilot) {
- LuaPilot* p;
- p = (LuaPilot*)lua_newuserdata(L, sizeof(LuaPilot));
- *p = pilot;
- luaL_getmetatable(L, PILOT_METATABLE);
- lua_setmetatable(L, -2);
- return p;
-}
-
-/**
- * @fn int lua_ispilot(lua_State* L, int ind)
- *
- * @brief Check to see if ind is a pilot.
- * @param L Lua state to check.
- * @param ind Index position to check.
- * @return 1 if ind is a pilot.
- */
-int lua_ispilot(lua_State* L, int ind) {
- int ret;
-
- if(lua_getmetatable(L, ind)==0)
- return 0;
- lua_getfield(L, LUA_REGISTRYINDEX, PILOT_METATABLE);
-
- ret = 0;
- if(lua_rawequal(L, -1, -2)) /* Does it have the correct mt?*/
- ret = 1;
-
- lua_pop(L, 2); /* Remove both metatables. */
- return ret;
-}
-
-/**
- * @ingroup PILOT
- *
- * @brief Get the players pilot.
- * @return Pilot pointing to the player.
- * @luafunc player()
- */
-static int pilot_getPlayer(lua_State* L) {
- LuaPilot lp;
-
- if(player == NULL) {
- lua_pushnil(L);
- return 1;
- }
-
- lp.pilot = player->id;
- lua_pushpilot(L, lp);
- return 1;
-}
-
-/**
- * @ingroup PILOT
- *
- * @brief Adds a fleet to the system.
- * @luaparam fleetname Name of the fleet to add.
- * @luaparam ai If set will override the standard fleet AI. "def" means use default.
- * @luaparam pos Position to create pilots around instead of choosing randomly.
- * @return Table populated with all the identifiers of the pilots created.
- * @luafunc add(fleetname, ai, pos)
- */
-static int pilot_addFleet(lua_State* L) {
- LLUA_MIN_ARGS(1);
- Fleet* flt;
- char* fltname, *fltai;
- int i, j;
- unsigned int p;
- double a;
- double d;
- Vec2 vv, vp, vn;
- FleetPilot* plt;
- LuaPilot lp;
- LuaVector* lv;
-
-
- /* Parse first argument - Fleet name */
- if(lua_isstring(L, 1)) fltname = (char*) lua_tostring(L, 1);
- else LLUA_INVALID_PARAMETER();
-
- /* Parse second argument - Fleet IA override. */
- if(lua_gettop(L) > 1) {
- if(lua_isstring(L, 2)) {
- fltai = (char*)lua_tostring(L, 2);
- if(strcmp(fltai, "def")==0) /* Check if set to default. */
- fltai = NULL;
- }
- else LLUA_INVALID_PARAMETER();
- }
- else fltai = NULL;
-
- /* Parse third argument - Position. */
- if(lua_gettop(L) > 2) {
- if(lua_isvector(L,3))
- lv = lua_tovector(L,3);
- else LLUA_INVALID_PARAMETER();
- }
- else lv = NULL;
-
- /* Needed to determine angle. */
- vectnull(&vn);
-
- /* Pull the fleet. */
- flt = fleet_get(fltname);
- if(flt == NULL) {
- LLUA_DEBUG("Fleet not found!");
- return 0;
- }
-
- /* Use position passed if possible. */
- if(lv != NULL)
- vectcpy(&vp, &lv->vec);
- else {
- d = RNGF()*(HYPERSPACE_ENTER_MAX-HYPERSPACE_ENTER_MIN) + HYPERSPACE_ENTER_MIN;
- }
-
- j = 0;
- lua_newtable(L);
- for(i = 0; i < flt->npilots; i++) {
- plt = &flt->pilots[i];
-
- if(RNG(0, 100) <= plt->chance) {
- /* Fleet displacement. */
- vect_cadd(&vp, RNG(75, 150) * (RNG(0,1) ? 1 : -1),
- RNG(75, 150) * (RNG(0,1) ? 1 : -1));
-
- /* Set velocity only if no position is set.. */
- if(lv != NULL) {
- if(VMOD(lv->vec) > HYPERSPACE_ENTER_MIN*0.9) {
- a = vect_angle(&vp, &vn);
- vect_pset(&vv, HYPERSPACE_VEL, a);
- }
- else vectnull(&vv);
- }
- else { /* Enterting via hyperspace. */
- a = vect_angle(&vp, &vn);
- vect_pset(&vv, HYPERSPACE_VEL, a);
- }
-
- /* Create the pilot. */
- p = pilot_create(plt->ship,
- plt->name,
- flt->faction,
- (fltai != NULL) ? /* Lua AI override. */
- fltai :
- (plt->ai != NULL) ? /* Pilot AI override */
- plt->ai : flt->ai,
- a,
- &vp,
- &vv,
- 0);
-
- /* We push each pilot created into a table and return it. */
- lua_pushnumber(L, ++j); /* Index, starts with 1. */
- lp.pilot = p;
- lua_pushpilot(L, lp); /* value = LuaPilot */
- lua_rawset(L, -3); /* Store the value in the table. */
- }
- }
-
- return 1;
-
-}
-
-/**
- * @ingroup PILOT
- * @brief Clears the current system of pilots. Used for epic battles and such.
- * @luafunc clear()
- */
-static int pilot_clear(lua_State* L) {
- (void) L;
- pilots_clean();
- return 0;
-}
-
-/**
- * @ingroup PILOT
- *
- * @brief Disable or enable pilot spawning in the current system. If player jumps
- * the spawn is enabled again automatically.
- * @luaparam enable true enables spawn, false disables it.
- * @return The current spawn state.
- * @luafunc togglespawn(enable)
- */
-static int pilot_toggleSpawn(lua_State* L) {
- /* Setting it directly. */
- if((lua_gettop(L) > 0) && lua_isboolean(L, 1))
- space_spawn = lua_toboolean(L, 1);
- /* Toggling. */
- else
- space_spawn = !space_spawn;
-
- lua_pushboolean(L, space_spawn);
- return 1;
-}
-
-/**
- * @ingroup PILOT
- */
-static int pilot_getPilots(lua_State* L) {
- int i, j, k;
- int* factions;
- int nfactions;
- LuaFaction* f;
- LuaPilot p;
-
- /* Check for belonging to faction. */
- if(lua_istable(L, 1)) {
- /* get table length and preallocate. */
- nfactions = (int)lua_objlen(L, 1);
- factions = malloc(sizeof(int) * nfactions);
- /* Load up the table. */
- lua_pushnil(L);
- i = 0;
- while(lua_next(L, -2) != 0) {
- f = lua_tofaction(L, -1);
- factions[i++] = f->f;
- lua_pop(L, 1);
- }
-
- /* Now put all the matching pilots in a table. */
- lua_newtable(L);
- k = 1;
- for(i = 0; i < pilot_nstack; i++) {
- for(j = 0; j < nfactions; j++) {
- if((pilot_stack[i]->faction == factions[j]) &&
- !pilot_isDisabled(pilot_stack[i])) {
- lua_pushnumber(L, k++); /* key. */
- p.pilot = pilot_stack[i]->id;
- lua_pushpilot(L, p); /* Value. */
- lua_rawset(L, -3); /* table[key] = value */
- break; /* Continue to next pilot. */
- }
- }
- }
-
- /* Clean up. */
- free(factions);
- } else
- LLUA_INVALID_PARAMETER();
-
- return 1;
-}
-
-/**
- * @brief Check to see if pilot and p are the same.
- * @luaparam p Pilot to compare against.
- * @return true if they are the same.
- * @luafunc __eq(pilot)
- */
-static int pilotL_eq(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaPilot* p1, *p2;
-
- /* Get parameters. */
- p1 = lua_topilot(L, 1);
- if(lua_ispilot(L, 2))
- p2 = lua_topilot(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Push result. */
- lua_pushboolean(L, p1->pilot == p2->pilot);
- return 1;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Get the pilots current name.
- * @return The current name of the pilot.
- * @luafunc name()
- */
-static int pilotL_name(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaPilot* p1;
- Pilot* p;
-
- /* Parse parameters. */
- p1 = lua_topilot(L, 1);
- p = pilot_get(p1->pilot);
-
- /* Pilot must exist. */
- if(p == NULL) return 0;
-
- /* Get name. */
- lua_pushstring(L, p->name);
- return 1;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Checks to see if pilot is still alive.
- * @return true if pilot is still alive.
- * @luafunc alive()
- */
-static int pilotL_alive(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaPilot* lp;
- Pilot* p;
-
- /* Parse parameters. */
- lp = lua_topilot(L, 1);
- p = pilot_get(lp->pilot);
-
- /* Check if is alive. */
- lua_pushboolean(L, p != NULL);
- return 1;
-}
-
-/**
- * @brief Changes the pilots name.
- * @param name Name to change to.
- * @luafunc rename(name)
- */
-static int pilotL_rename(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaPilot* p1;
- char* name;
- Pilot* p;
-
- /* Parse parameters. */
- p1 = lua_topilot(L, 1);
- p = pilot_get(p1->pilot);
- if(lua_isstring(L, 2))
- name = (char*)lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Pilot must exist. */
- if(p == NULL) return 0;
-
- /* Change name. */
- if(p->name != NULL)
- free(p->name);
- p->name = strdup(name);
-
- return 0;
-}
-
-/**
- * @brief Get the pilots position.
- * @return The pilots current position.
- * @luafunc pos()
- */
-static int pilotL_position(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaPilot* p1;
- Pilot* p;
- LuaVector v;
-
- /* Parse parameters */
- p1 = lua_topilot(L, 1);
- p = pilot_get(p1->pilot);
-
- /* Pilot must exist. */
- if(p == NULL) return 0;
-
- /* Push position. */
- vectcpy(&v.vec, &p->solid->pos);
- lua_pushvector(L, v);
- return 1;
-}
-
-/**
- * @fn static int pilotL_velocity(lua_State* L)
- * @ingroup META_PILOT
- *
- * @brief Gets the pilots velocity.
- * @return The pilots current velocity.
- * @luafunc vel()
- */
-static int pilotL_velocity(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaPilot* p1;
- Pilot* p;
- LuaVector v;
-
- /* Parse parameters. */
- p1 = lua_topilot(L, 1);
- p = pilot_get(p1->pilot);
-
- /* Pilot must exist.. */
- if(p == NULL) return 0;
-
- /* Push velocity. */
- vectcpy(&v.vec, &p->solid->vel);
- lua_pushvector(L, v);
- return 1;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Set the pilots position.
- * @luaparam pos Position to set.
- * @luafunc warp( pos )
- */
-static int pilotL_warp(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaPilot* p1;
- Pilot* p;
- LuaVector* v;
-
- /* Parse parameters. */
- p1 = lua_topilot(L, 1);
- p = pilot_get(p1->pilot);
- if(lua_isvector(L,2))
- v = lua_tovector(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Pilot must exist. */
- if(p == NULL) return 0;
-
- /* Warp pilot to new position. */
- vectcpy(&p->solid->pos, &v->vec);
- vectnull(&p->solid->vel); /* Clear velocity otherwise it's a bit weird. */
- return 0;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Make the pilot broadcast a message.
- * @luaparam msg Message to broadcast.
- * @luafunc broadcast(msg)
- */
-static int pilotL_broadcast(lua_State* L) {
- LLUA_MIN_ARGS(2);
- Pilot* p;
- LuaPilot* lp;
- char* msg;
-
- /* Parse arguments. */
- lp = lua_topilot(L, 1);
- if(lua_isstring(L, 2))
- msg = (char*)lua_tostring(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Check to see if pilot is valid. */
- p = pilot_get(lp->pilot);
- if(p == NULL)
- return 0;
-
- /* Broadcast message. */
- player_message("Broadcast %s> \"%s\"", p->name, msg);
- return 0;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Set the pilots faction.
- * @luaparam faction Faction to set by name or faction.
- * @luafunc setFaction( faction )
- */
-static int pilotL_setFaction(lua_State* L) {
- LLUA_MIN_ARGS(2);
- Pilot* p;
- LuaPilot* lp;
- LuaFaction* f;
- int fid;
- char* faction;
-
- /* Parse parameters. */
- lp = lua_topilot(L, 1);
- if(lua_isstring(L, 2)) {
- faction = (char*)lua_tostring(L,2);
- fid = faction_get(faction);
- }
- else if(lua_isfaction(L, 2)) {
- f = lua_tofaction(L, 2);
- fid = f->f;
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Get pilot/faction. */
- p = pilot_get(lp->pilot);
- if(p == NULL) return 0;
-
- /* Set the new faction. */
- p->faction = fid;
-
- return 0;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Set the pilot as hostile to player.
- * @luafunc setHostile()
- */
-static int pilotL_setHostile(lua_State* L) {
- LuaPilot* lp;
- Pilot* p;
-
- /* Get the pilot. */
- lp = lua_topilot(L, 1);
- p = pilot_get(lp->pilot);
- if(p == NULL) return 0;
-
- /* Set as hostile. */
- pilot_setHostile(p);
-
- return 0;
-}
-
-/**
- * @ingroup META_PILOT
- *
- * @brief Set the pilot as friendly to player.
- * @luafunc setHostile()
- */
-static int pilotL_setFriendly(lua_State* L) {
- LuaPilot* lp;
- Pilot* p;
-
- /* Get the pilot. */
- lp = lua_topilot(L, 1);
- p = pilot_get(lp->pilot);
- if(p == NULL) return 0;
-
- /* Remove hostile and mark as friendly. */
- pilot_setFriendly(p);
-
- return 0;
-}
-
diff --git a/src/llua_pilot.h b/src/llua_pilot.h
deleted file mode 100644
index fa6858b..0000000
--- a/src/llua_pilot.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-#include "lua.h"
-#include "pilot.h"
-
-#define PILOT_METATABLE "Pilot" /**< Pilot metatable identifier. */
-
-/**
- * @brief Lua pilot wrapper.
- */
-typedef struct LuaPilot_s {
- unsigned int pilot;
-} LuaPilot;
-
-/* Library loading. */
-int lua_loadPilot(lua_State* L, int readonly);
-
-LuaPilot* lua_topilot(lua_State* L, int ind);
-LuaPilot* lua_pushpilot(lua_State* L, LuaPilot pilot);
-int lua_ispilot(lua_State* L, int ind);
-
diff --git a/src/llua_space.c b/src/llua_space.c
deleted file mode 100644
index 936328b..0000000
--- a/src/llua_space.c
+++ /dev/null
@@ -1,1006 +0,0 @@
-#include "lauxlib.h"
-
-#include "log.h"
-#include "lephisto.h"
-#include "rng.h"
-#include "land.h"
-#include "llua.h"
-#include "lluadef.h"
-#include "llua_faction.h"
-#include "map.h"
-#include "llua_space.h"
-
-static int planetL_createmetatable(lua_State* L);
-static int systemL_createmetatable(lua_State* L);
-static int vectorL_createmetatable(lua_State* L);
-
-/* Space. */
-static int planetL_get(lua_State* L);
-static int systemL_get(lua_State* L);
-static const luaL_reg space_methods[] = {
- { "getPlanet", planetL_get },
- { "getSystem", systemL_get },
- { 0, 0 }
-};
-
-/* Planet metatable methods. */
-static int planetL_eq(lua_State* L);
-static int planetL_name(lua_State* L);
-static int planetL_faction(lua_State* L);
-static int planetL_class(lua_State* L);
-static int planetL_services(lua_State* L);
-static int planetL_position(lua_State* L);
-static const luaL_reg planet_methods[] = {
- { "__eq", planetL_eq },
- { "__tostring", planetL_name },
- { "name", planetL_name },
- { "faction", planetL_faction },
- { "class", planetL_class },
- { "services", planetL_services },
- { "pos", planetL_position },
- { 0, 0 }
-};
-
-/* System metatable methods. */
-static int systemL_eq(lua_State* L);
-static int systemL_name(lua_State* L);
-static int systemL_faction(lua_State* L);
-static int systemL_nebulae(lua_State* L);
-static int systemL_jumpdistance(lua_State* L);
-static int systemL_adjacent(lua_State* L);
-static const luaL_reg system_methods[] = {
- { "__eq", systemL_eq },
- { "__tostring", systemL_name },
- { "name", systemL_name },
- { "faction", systemL_faction },
- { "nebulae", systemL_nebulae },
- { "jumpDist", systemL_jumpdistance },
- { "adjacentSystems", systemL_adjacent },
- { 0, 0 }
-};
-
-/* Vector metatable methods. */
-static int vectorL_new(lua_State* L);
-static int vectorL_add(lua_State* L);
-static int vectorL_sub(lua_State* L);
-static int vectorL_mul(lua_State* L);
-static int vectorL_div(lua_State* L);
-static int vectorL_get(lua_State* L);
-static int vectorL_set(lua_State* L);
-static int vectorL_distance(lua_State* L);
-static int vectorL_mod(lua_State* L);
-static const luaL_reg vector_methods[] = {
- { "new", vectorL_new },
- { "__add", vectorL_add },
- { "add", vectorL_add },
- { "__sub", vectorL_sub },
- { "sub", vectorL_sub },
- { "__mul", vectorL_mul },
- { "__div", vectorL_div },
- { "get", vectorL_get },
- { "set", vectorL_set },
- { "dist", vectorL_distance },
- { "mod", vectorL_mod },
- { 0, 0 }
-}; /**< Vector metatable methods. */
-
-/**
- * @brief Load the space library.
- * @param L State to load space library into.
- * @param readonly Load read only functions?
- * @return 0 on success.
- */
-int lua_loadSpace(lua_State* L, int readonly) {
- (void)readonly; /* Only read only atm. */
-
- /* Register the functions. */
- luaL_register(L, "space", space_methods);
-
- /* Register the metatables. */
- planetL_createmetatable(L);
- systemL_createmetatable(L);
- lua_loadVector(L);
-
- return 0;
-}
-
-/**
- * @brief Loads the vector metatable.
- * @param L State to load the vector metatable into.
- * @return 0 on success.
- */
-int lua_loadVector(lua_State* L) {
- vectorL_createmetatable(L);
-
- return 0;
-}
-
-/**
- * @brief Registers the planet metatable.
- * @param L Lua state to register metatable in.
- * @return 0 on success.
- */
-static int planetL_createmetatable(lua_State* L) {
- /* Create the metatable. */
- luaL_newmetatable(L, PLANET_METATABLE);
-
- /* Create the access table. */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2,"__index");
-
- /* Register the values. */
- luaL_register(L, NULL, planet_methods);
-
- /* Clean up. */
- lua_pop(L, 1);
-
- return 0; /* No error. */
-}
-
-/**
- * @brief Register the system metatable.
- * @param L Lua state to register metatable in.
- * @param 0 on success.
- */
-static int systemL_createmetatable(lua_State* L) {
- /* Create the metatable. */
- luaL_newmetatable(L, SYSTEM_METATABLE);
-
- /* Create the access table. */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
- /* Register the values. */
- luaL_register(L, NULL, system_methods);
-
- /* Clean up. */
- lua_pop(L, 1);
-
- return 0; /* No error. */
-}
-
-/**
- * @brief Registers the vector metatable.
- * @param L Lua state to register metatable in.
- * @return 0 on success.
- */
-static int vectorL_createmetatable(lua_State* L) {
- /* Create the metatable. */
- luaL_newmetatable(L, VECTOR_METATABLE);
-
- /* Create the access table. */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
- /* Register the values. */
- luaL_register(L, NULL, vector_methods);
-
- /* Clean up. */
- lua_pop(L, 1);
-
- return 0; /* No error. */
-}
-
-/**
- * @defgroup SPACE Space Lua Bindings.
- *
- * @brief Contains Lua bindings for manipulating the space itself.
- */
-/**
- * @defgroup META_PLANET Planet metatable
- *
- * @brief The planet metatable is a way to represent a planet in Lua.
- *
- * @luamod planet
- *
- * It allows all sorts of operators making it much more natural to use.
- *
- * To call Members of the metatable always use:
- * @code
- * planet:function(param)
- * @endcode
- */
-
-/**
- * @brief Get planet at index.
- * @param L Lua state to get planet from.
- * @param ind Index position to find the planet.
- * @return Planet found at the index in the state.
- */
-LuaPlanet* lua_toplanet(lua_State* L, int ind) {
- if(lua_isuserdata(L, ind)) {
- return (LuaPlanet*) lua_touserdata(L, ind);
- }
-
- luaL_typerror(L, ind, PLANET_METATABLE);
- return NULL;
-}
-
-/**
- * @brief Pushes a planet on the stack.
- * @param L Lua state to push planet into.
- * @param planet Planet to push.
- * @return Newly pushed planet.
- */
-LuaPlanet* lua_pushplanet(lua_State* L, LuaPlanet planet) {
- LuaPlanet* p;
- p = (LuaPlanet*) lua_newuserdata(L, sizeof(LuaPlanet));
- *p = planet;
- luaL_getmetatable(L, PLANET_METATABLE);
- lua_setmetatable(L, -2);
- return p;
-}
-
-/**
- * @brief Check to see if ind is a planet.
- * @param L Lua state to check.
- * @param ind Index at position to check.
- * @return 1 if ind is a planet.
- */
-int lua_isplanet(lua_State* L, int ind) {
- int ret;
-
- if(lua_getmetatable(L, ind)==0)
- return 0;
- lua_getfield(L, LUA_REGISTRYINDEX, PLANET_METATABLE);
-
- ret = 0;
- if(lua_rawequal(L, -1, -2)) /* Does it have the correct mt? */
- ret = 1;
-
- lua_pop(L, 2); /* Remove both metatables. */
- return ret;
-}
-
-/**
- * @ingroup SPACE
- *
- * @brief planet, system getPlanet([param])
- *
- * Get a planet.
- *
- * Possible values of param:
- * -- nil : Get the current landed planet or nil if there is none.
- * -- number : Get a random planet belonging to faction matching the number.
- * -- string : Get the planet by name.
- * -- table : Get random planet belonging to any of the factions in the table.
- *
- * @param param See description.
- * @return Returns the planet and the system it belongs to.
- */
-static int planetL_get(lua_State* L) {
- int i;
- int* factions;
- int nfactions;
- char** planets;
- int nplanets;
- char* rndplanet;
- LuaPlanet planet;
- LuaSystem sys;
- LuaFaction* f;
-
- rndplanet = NULL;
- nplanets = 0;
-
- /* Get the landed planet. */
- if(lua_gettop(L) == 0) {
- if(land_planet != NULL) {
- planet.p = land_planet;
- lua_pushplanet(L, planet);
- sys.s = system_get(planet_getSystem(land_planet->name));
- lua_pushsystem(L, sys);
- return 2;
- }
- return 0; /* Not landed. */
- }
-
- /* Get a planet by faction */
- else if(lua_isfaction(L, 1)) {
- f = lua_tofaction(L, 1);
- planets = space_getFactionPlanet(&nplanets, &f->f, 1);
- }
-
- /* Get a planet by name. */
- else if(lua_isstring(L, 1)) {
- rndplanet = (char*) lua_tostring(L, 1);
- }
-
- /* Get a planet from faction list. */
- else if(lua_istable(L, 1)) {
- /* Get table length and preallocate. */
- nfactions = (int) lua_objlen(L, 1);
- factions = malloc(sizeof(int) * nfactions);
- /* Load up the table. */
- lua_pushnil(L);
- i = 0;
- while(lua_next(L, -2) != 0) {
- f = lua_tofaction(L, -1);
- factions[i++] = f->f;
- lua_pop(L,1);
- }
-
- /* Get the planets. */
- planets = space_getFactionPlanet(&nplanets, factions, nfactions);
- free(factions);
- }
- else LLUA_INVALID_PARAMETER(); /* Bad parameter. */
-
- /* No suitable planet found. */
- if((rndplanet == NULL) && (nplanets == 0)) {
- free(planets);
- return 0;
- }
-
- /* Pick random planet. */
- else if(rndplanet == NULL) {
- rndplanet = planets[RNG(0, nplanets-1)];
- free(planets);
- }
-
- /* Push the planet. */
- planet.p = planet_get(rndplanet); /* The real planet. */
- lua_pushplanet(L, planet);
- sys.s = system_get(planet_getSystem(rndplanet));
- lua_pushsystem(L, sys);
- return 2;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief bool __eq(planet comp)
- *
- * __eq (equality) metamethod for planets.
- *
- * You can use the '=' operator within Lua to compare planets with this.
- * @param comp planet to compare against.
- * @return true if both planets are the same.
- */
-static int planetL_eq(lua_State* L) {
- LuaPlanet* a, *b;
- a = lua_toplanet(L, 1);
- b = lua_toplanet(L, 2);
- if(a->p == b->p)
- lua_pushboolean(L, 1);
- else
- lua_pushboolean(L, 0);
- return 1;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief string name(nil)
- *
- * Get the planets name.
- * @return The name of the planet.
- */
-static int planetL_name(lua_State* L) {
- LuaPlanet* p;
- p = lua_toplanet(L, 1);
- lua_pushstring(L, p->p->name);
- return 1;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief number faction(nil)
- *
- * Get the planets faction.
- * @return The planets faction.
- */
-static int planetL_faction(lua_State* L) {
- LuaPlanet* p;
- LuaFaction f;
- p = lua_toplanet(L, 1);
- f.f = p->p->faction;
- lua_pushfaction(L, f);
- return 1;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief string class(nil)
- *
- * Get the planets class.
- * @return The class of the planet in one char identifier.
- */
-static int planetL_class(lua_State* L) {
- char buf[2];
- LuaPlanet* p;
- p = lua_toplanet(L, 1);
- buf[0] = planet_getClass(p->p);
- buf[1] = '\0';
- lua_pushstring(L, buf);
- return 1;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief Number services(nil)
- *
- * Get planet services.
- * @return The services the planet has it stored bitwise.
- */
-static int planetL_services(lua_State* L) {
- LuaPlanet* p;
- p = lua_toplanet(L, 1);
- lua_pushnumber(L, (p->p->services & (~PLANET_SERVICE_LAND)));
- return 1;
-}
-
-/**
- * @ingroup META_PLANET
- *
- * @brief Vec2 pos(nil)
- *
- * Get the position of the planet in the system.
- * @return The position of the planet in the system.
- */
-static int planetL_position(lua_State* L) {
- LuaPlanet* p;
- LuaVector v;
- p = lua_toplanet(L, 1);
- vectcpy(&v.vec, &p->p->pos);
- lua_pushvector(L, v);
- return 1;
-}
-
-/**
- * @defgroup META_SYSTEM System Metatable.
- *
- * @brief Represents a system in Lua.
- *
- * @luamod system
- *
- * To call members of the metatable always use:
- * @code
- * system:function(param)
- * @endcode
- */
-
-/**
- * @brief Get system at index.
- * @param L Lus state to get system from.
- * @param ind Index position of system.
- * @return The LuaSystem at ind.
- */
-LuaSystem* lua_tosystem(lua_State* L, int ind) {
- if(lua_isuserdata(L, ind)) {
- return (LuaSystem*) lua_touserdata(L,ind);
- }
- luaL_typerror(L, ind, SYSTEM_METATABLE);
- return NULL;
-}
-
-/**
- * @brief Pushes a system on the stack.
- * @param L Lua state to push system onto.
- * @param sys System to push.
- * @return System just pushed.
- */
-LuaSystem* lua_pushsystem(lua_State* L, LuaSystem sys) {
- LuaSystem* s;
- s = (LuaSystem*) lua_newuserdata(L, sizeof(LuaSystem));
- *s = sys;
- luaL_getmetatable(L, SYSTEM_METATABLE);
- lua_setmetatable(L, -2);
- return s;
-}
-
-/**
- * @brief Check to see if ind is a system.
- * @param L Lua state to check.
- * @param ind Index position to check.
- * @return 1 if there is a system at index position.
- */
-int lua_issystem(lua_State* L, int ind) {
- int ret;
-
- if(lua_getmetatable(L, ind)==0)
- return 0;
- lua_getfield(L, LUA_REGISTRYINDEX, SYSTEM_METATABLE);
-
- ret = 0;
- if(lua_rawequal(L, -1, -2)) /* Does it have the correct mt? */
- ret = 1;
-
- lua_pop(L, 2); /* Remove both metatables. */
- return ret;
-}
-
-/**
- * @ingroup SPACE
- *
- * @brief system getSystem([param])
- *
- * Get a system.
- *
- * Behaves differently depending on what you pass as param:
- * -- nil : Get the current system.
- * -- string : Get the system by name.
- * -- planet : Get the system by planet.
- *
- * @param param Read description for details.
- * @return System metatable matching param.
- */
-static int systemL_get(lua_State* L) {
- LuaSystem sys;
- LuaPlanet* p;
-
- /* Get the current system with no parameters. */
- if(lua_gettop(L) == 0) {
- sys.s = cur_system;
- }
- /* Passing a string (systemname) */
- else if(lua_isstring(L, 1)) {
- sys.s = system_get((char*)lua_tostring(L, 1));
- }
- /* Passing a planet */
- else if(lua_isplanet(L, 1)) {
- p = lua_toplanet(L, 1);
- sys.s = system_get(planet_getSystem(p->p->name));
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Return the system. */
- lua_pushsystem(L, sys);
- return 1;
-}
-
-/**
- * @ingroup META_SYSTEM
- *
- * @brief bool __eq(system comp)
- *
- * Check systems for equality.
- *
- * Allows you to use the '=' operator in Lua with systems.
- * @param comp System to compare against.
- * @return true if both systems are the same.
- */
-static int systemL_eq(lua_State* L) {
- LuaSystem* a, *b;
- a = lua_tosystem(L, 1);
- b = lua_tosystem(L, 2);
- if(a->s == b->s)
- lua_pushboolean(L, 1);
- else
- lua_pushboolean(L, 0);
-
- return 1;
-}
-
-/**
- * @ingroup META_SYSTEM
- *
- * @brief string name(nil)
- *
- * Return the systems name.
- * @return The name of the system.
- */
-static int systemL_name(lua_State* L) {
- LuaSystem* sys;
- sys = lua_tosystem(L, 1);
- lua_pushstring(L, sys->s->name);
- return 1;
-}
-
-/**
- * @ingroup META_SYSTEM
- *
- * @brief table faction(nil)
- *
- * Get system factions.
- *
- * @code
- * foo = space.faction("foo")
- * if foo["bar"] then
- * print("faction 'bar' found")
- * end
- * @endcode
- * @return A table containing all the factions in the system.
- */
-static int systemL_faction(lua_State* L) {
- int i;
- LuaSystem* sys;
- sys = lua_tosystem(L, 1);
-
- /* Return result in table. */
- lua_newtable(L);
- for(i = 0; i < sys->s->nplanets; i++) {
- if(sys->s->planets[i]->faction > 0) { /* Faction must be valid. */
- lua_pushboolean(L, 1); /* Value. */
- lua_setfield(L, -2, faction_name(sys->s->planets[i]->faction)); /* Key. */
- /* Allows syntax foo = space.faction("foo"); if foo["bar"] then ... end */
- }
- }
-
- return 1;
-}
-
-/**
- * @ingroup META_SYSTEM
- */
-static int systemL_nebulae(lua_State* L) {
- LuaSystem* sys;
- sys = lua_tosystem(L, 1);
-
- /* Push the density and volatility. */
- lua_pushnumber(L, sys->s->nebu_density);
- lua_pushnumber(L, sys->s->nebu_volatility);
-
- return 2;
-}
-
-/**
- * @ingroup META_SYSTEM
- *
- * @brief number jumpDist([param])
- *
- * Get jump distance from current system, or to another.
- *
- * Does different things depending on the parameter type:
- * -- nil : Get distance from current system.
- * -- string : Get distance from system matching name.
- * -- system : Get distance from system.
- *
- * @param param See description.
- * @return Number of jumps to system.
- */
-static int systemL_jumpdistance(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaSystem* sys;
- StarSystem** s;
- int jumps;
- char* start, *goal;
-
- sys = lua_tosystem(L, 1);
- start = sys->s->name;
-
- if((lua_gettop(L) > 1) && lua_isstring(L, 2))
- goal = (char*)lua_tostring(L, 2);
- else
- goal = cur_system->name;
-
- s = map_getJumpPath(&jumps, start, goal, 1);
- free(s);
-
- lua_pushnumber(L, jumps);
- return 1;
-}
-
-/**
- * @ingroup META_SYSTEM
- */
-static int systemL_adjacent(lua_State* L) {
- int i;
- LuaSystem* sys, sysp;
-
- sys = lua_tosystem(L, 1);
-
- /* Push all adjacent systems. */
- lua_newtable(L);
- for(i = 0; i < sys->s->njumps; i++) {
- sysp.s = system_getIndex(sys->s->jumps[i]);
- lua_pushnumber(L, i+1); /* Key. */
- lua_pushsystem(L, sysp); /* Value. */
- lua_rawset(L, -3);
- }
-
- return 1;
-}
-
-/**
- * @defgroup META_VECTOR Vector Metatable
- *
- * @brief Represents a 2d vector in Lua.
- *
- * @luamod vec2
- *
- * To call members of the metatable always use:
- * @code
- * vector:function(param)
- * @endcode
- */
-
-/**
- * @brief Gets vector at index.
- * @param L Lua state to get vector from.
- * @param ind Index position of vector.
- * @return The LuaVector at ind.
- */
-LuaVector* lua_tovector(lua_State* L, int ind) {
- if(lua_isuserdata(L, ind)) {
- return (LuaVector*)lua_touserdata(L, ind);
- }
-
- luaL_typerror(L, ind, VECTOR_METATABLE);
- return NULL;
-}
-
-/**
- * @brief Pushes a vector on the stack.
- * @param L Lua state to push vector onto.
- * @param vec Vector to push.
- * @return Vector just pushed.
- */
-LuaVector* lua_pushvector(lua_State* L, LuaVector vec) {
- LuaVector* v;
- v = (LuaVector*) lua_newuserdata(L, sizeof(LuaVector));
- *v = vec;
- luaL_getmetatable(L, VECTOR_METATABLE);
- lua_setmetatable(L, -2);
- return v;
-}
-
-/**
- * @brief Check to see if ind is a vector.
- * @param L lua state to check.
- * @param ind Index position to check.
- * @return 1 if there is a vector at index position.
- */
-int lua_isvector(lua_State* L, int ind) {
- int ret;
-
- if(lua_getmetatable(L, ind)==0)
- return 0;
- lua_getfield(L, LUA_REGISTRYINDEX, VECTOR_METATABLE);
-
- ret = 0;
- if(lua_rawequal(L, -1, -2)) /* Does it have the correct mt? */
- ret = 1;
-
- lua_pop(L, 2); /* Remove both metatables. */
- return ret;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Vec2 new([number x, number y])
- *
- * Creates a new vector.
- * @param x if set, the X value for the new vector.
- * @param y if set, the Y value for the new vector.
- * @return The new vector.
- */
-static int vectorL_new(lua_State* L) {
- LuaVector v;
- double x, y;
-
- if((lua_gettop(L) > 1) && lua_isnumber(L,1) && lua_isnumber(L,2)) {
- x = lua_tonumber(L,1);
- y = lua_tonumber(L,2);
- } else {
- x = 0.;
- y = 0.;
- }
-
- vect_cset(&v.vec, x, y);
- lua_pushvector(L, v);
- return 1;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief __add(Vec2 vector)
- *
- * __add(number x, number y)
- *
- * Adds two vectors or a vector and some cartesian coords.
- */
-static int vectorL_add(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaVector* v1, *v2;
- double x, y;
-
- /* Get self. */
- v1 = lua_tovector(L, 1);
-
- /* Get rest of parameters. */
- v2 = NULL;
- if(lua_isvector(L, 2)) {
- v2 = lua_tovector(L, 2);
- x = v2->vec.x;
- y = v2->vec.y;
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Actually add it. */
- vect_cadd(&v1->vec, x, y);
- return 0;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Subtracts a vector and some cartesian coords.
- * @luaparam x X coordinate to subtract.
- * @luaparam y Y coordinate to subtract.
- *
- * @luafunc __sub(vector)
- * @brief Subtracts two vectors.
- * @luaparam x
- * @luafunc __sub(x, y)
- */
-static int vectorL_sub(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaVector* v1, *v2;
- double x, y;
-
- /* Get self. */
- v1 = lua_tovector(L,1);
-
- /* Get rest of parameters. */
- v2 = NULL;
- if(lua_isvector(L, 2)) {
- v2 = lua_tovector(L, 2);
- x = v2->vec.x;
- y = v2->vec.y;
- }
- else if((lua_gettop(L) > 2) && lua_isnumber(L, 2) && lua_isnumber(L, 3)) {
- x = lua_tonumber(L, 2);
- y = lua_tonumber(L, 3);
- }
- else LLUA_INVALID_PARAMETER();
-
- /* Actually add it. */
- vect_cadd(&v1->vec, -x, -y);
- return 0;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Multiplies a vector by a number.
- * @luaparam mod Amount to multiply by.
- * @luafunc __mul(mod)
- */
-static int vectorL_mul(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaVector* v1;
- double mod;
-
- /* Get self. */
- v1 = lua_tovector(L,1);
-
- /* Get rest of parameters. */
- if(lua_isnumber(L, 2))
- mod = lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Actually add it. */
- vect_cadd(&v1->vec, v1->vec.x * mod, v1->vec.x * mod);
- return 0;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Divides a vector by a number.
- * @luaparam mod Amount to divide by.
- * @luafunc __div(mod)
- */
-static int vectorL_div(lua_State* L) {
- LLUA_MIN_ARGS(2);
- LuaVector* v1;
- double mod;
-
- /* Get self. */
- v1 = lua_tovector(L,1);
-
- /* Get rest of parameters. */
- if(lua_isnumber(L, 2))
- mod = lua_tonumber(L, 2);
- else LLUA_INVALID_PARAMETER();
-
- /* Actually add it. */
- vect_cadd(&v1->vec, v1->vec.x / mod, v1->vec.x / mod);
- return 0;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Get the cartesian positions of the vector.
- * @luareturn X and Y position of the vector.
- *
- * @luafunc get()
- */
-static int vectorL_get(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaVector* v1;
-
- /* Get self. */
- v1 = lua_tovector(L,1);
-
- /* Push the vector. */
- lua_pushnumber(L, v1->vec.x);
- lua_pushnumber(L, v1->vec.y);
- return 2;
-}
-
-/**
- * @brief Set the vector by cartesian coordinates.
- * @luaparam x X coordinate to set.
- * @luaparam y Y coordinate to set.
- *
- * @luafunc set(x, y)
- */
-static int vectorL_set(lua_State* L) {
- LLUA_MIN_ARGS(3);
- LuaVector* v1;
- double x, y;
-
- /* Get self */
- v1 = lua_tovector(L, 1);
-
- /* Get parameters. */
- if(lua_isnumber(L,2))
- x = lua_tonumber(L,2);
- else LLUA_INVALID_PARAMETER();
- if(lua_isnumber(L, 3))
- y = lua_tonumber(L, 3);
- else LLUA_INVALID_PARAMETER();
-
- vect_cset(&v1->vec, x, y);
- return 0;
-}
-
-/**
- * @ingroup META_VECTOR
- *
- * @brief Get the distance from the Vec2.
- * @param vector Vector to get distance from, uses origin(0,0) if not set.
- * @luareturn The distance calculated.
- *
- * @luafunc dist(vector)
- */
-static int vectorL_distance(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaVector* v1, *v2;
- double dist;
-
- /* Get self. */
- v1 = lua_tovector(L, 1);
-
- /* Get rest of parameters. */
- v2 = NULL;
- if(lua_gettop(L) > 1) {
- if(lua_isvector(L,2))
- v2 = lua_tovector(L, 2);
- else LLUA_INVALID_PARAMETER();
- }
-
- /* Get distance. */
- if(v2 == NULL)
- dist = vect_odist(&v1->vec);
- else
- dist = vect_dist(&v1->vec, &v2->vec);
-
- /* Return the distance. */
- lua_pushnumber(L, dist);
- return 1;
-}
-
-/**
- * @ingroup META_VECTOR.
- *
- * @brief Gets the modulus of the vector.
- * @luareturn The modulus of the vector.
- * @luafunc mod()
- */
-static int vectorL_mod(lua_State* L) {
- LLUA_MIN_ARGS(1);
- LuaVector* v;
-
- v = lua_tovector(L, 1);
- lua_pushnumber(L, VMOD(v->vec));
- return 1;
-}
-
diff --git a/src/llua_space.h b/src/llua_space.h
deleted file mode 100644
index 4e8dd02..0000000
--- a/src/llua_space.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#pragma once
-#include "lua.h"
-#include "space.h"
-
-#define PLANET_METATABLE "Planet"
-#define SYSTEM_METATABLE "System"
-#define VECTOR_METATABLE "Vec2"
-
-/* Lua wrappers. */
-
-/**
- * @brief Lua Planet wrapper.
- */
-typedef struct LuaPlanet_s {
- Planet* p;
-} LuaPlanet;
-/**
- * @brief Lua StarSystem wrapper
- */
-typedef struct LuaSystem_s {
- StarSystem* s;
-} LuaSystem;
-/**
- * @brief Lua Vec2 wrapper.
- */
-typedef struct LuaVector_s {
- Vec2 vec;
-} LuaVector;
-
-/* Load the space library. */
-int lua_loadSpace(lua_State* L, int readonly);
-int lua_loadVector(lua_State* L);
-
-/* Planet operations. */
-LuaPlanet* lua_toplanet(lua_State* L, int ind);
-LuaPlanet* lua_pushplanet(lua_State* L, LuaPlanet planet);
-int lua_isplanet(lua_State* L, int ind);
-
-/* System operations. */
-LuaSystem* lua_tosystem(lua_State* L, int ind);
-LuaSystem* lua_pushsystem(lua_State* L, LuaSystem sys);
-int lua_issystem(lua_State* L, int ind);
-
-/* Vector operations. */
-LuaVector* lua_tovector(lua_State* L, int ind);
-LuaVector* lua_pushvector(lua_State* L, LuaVector vec);
-int lua_isvector(lua_State* L, int ind);
-
diff --git a/src/lluadef.h b/src/lluadef.h
deleted file mode 100644
index 5586dfc..0000000
--- a/src/lluadef.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-
-#include "lua.h"
-#include "lauxlib.h"
-#include "lualib.h"
-
-/* Debug stuff. */
-#ifdef DEBUGGING
-#ifdef DEBUG_PARANOID
-#define LLUA_DEBUG(str, args...) \
- (fprintf(stdout, "Lua: "str"\n", ## args), abort())
-#else
-#define LLUA_DEBUG(str, args...) \
- (fprintf(stdout, "Lua: "str"\n", ## args))
-#endif
-
-#define LLUA_INVALID_PARAMETER() { \
- luaL_error(L, "Invalid parameter for %s.", __func__); \
- return 0; \
-}
-
-#define LLUA_MIN_ARGS(n) \
- if(lua_gettop(L) < n) { \
- luaL_error(L, "Too few arguments for %s.", __func__); \
- return 0; \
- }
-#else /* DEBUGGING. */
-#define LLUA_DEBUG(str, args...) do {;} while(0)
-#define LLUA_MIN_ARGS(n) do {;} while(0)
-#define LLUA_INVALID_PARAMETER() do {;} while(0)
-#endif /* DEBUGGING. */
-
-/* Comfortability macros. */
-#define luaL_dobuffer(L, b, n, s) \
- (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
-
diff --git a/src/log.h b/src/log.h
deleted file mode 100644
index 265c3a3..0000000
--- a/src/log.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-#include
-#include
-
-#define LOG(str, args...)(fprintf(stdout, str"\n", ## args))
-#ifdef DEBUG_PARANOID /* Will cause WARN's to blow up. */
-#define WARN(str, args...)(fprintf(stderr, "Warning: [%s] "str"\n", __func__, ## args), \
- abort())
-#else
-#define WARN(str, args...)(fprintf(stderr, "Warning: [%s] "str"\n", __func__, ## args))
-#endif
-
-#define ERR(str, args...) (fprintf(stderr, "ERROR %s:%d: [%s] "str"\n", \
- __FILE__, __LINE__, __func__, ## args), abort())
-
-#ifdef DEBUG
-# undef DEBUG
-# define DEBUG(str, args...) LOG(str, ## args)
-# define DEBUGGING
-#else
-# define DEBUG(str, args...) do {;} while(0)
-#endif
-
diff --git a/src/lstd.h b/src/lstd.h
deleted file mode 100644
index e14be23..0000000
--- a/src/lstd.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-#include
-#include
-
-/**
- * @brief Check to see if k is in ascii area.
- */
-#define lstd_checkascii(k) ((k & 0xff) == k)
-
-/**
- * @brief Check see if a key is alpha.
- */
-#define lstd_isalpha(k) (lstd_checkascii(k) ? isalpha(k) : 0)
-
-/**
- * @brief Check see if a key is alphanumeric.
- */
-#define lstd_isalnum(k) (lstd_checkascii(k) ? isalnum(k) : 0)
-
-/**
- * @brief Check see if a key is a control character.
- */
-#define lstd_iscntrl(k) (lstd_checkascii(k) ? iscntrl(k) : 0)
-
-/**
- * @brief Check to see if a key is a space character.
- */
-#define lstd_isspace(k) (lstd_checkascii(k) ? isspace(k) : 0)
-
-/**
- * @brief Convert a key to lowercase if applicable.
- */
-#define lstd_tolower(k) (lstd_checkascii(k) ? (SDLKey)tolower(k) : k)
-
-/**
- * @brief Convert a key to uppercase if applicable.
- */
-#define lstd_toupper(k) (lstd_checkascii(k) ? (SDLKey)toupper(k) : k)
-
diff --git a/src/ltime.c b/src/ltime.c
deleted file mode 100644
index 5050abc..0000000
--- a/src/ltime.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * @file ltime.c
- *
- * @brief Handle the lephisto time.
- *
- * The basic unit of time is the STU. There are 1000 STU in a MTU. The time
- * representation is generally UST which consists of MTU.STU.
- *
- * Acronyms:
- * - MTU : Major Time Unit (1000 STU)
- * - STU : Synchronized Time Unit.
- * - UST : Universal Synchonized Time.
- */
-#include
-#include
-#include
-
-#include "lephisto.h"
-#include "hook.h"
-#include "economy.h"
-#include "ltime.h"
-
-/**
- * @brief Used for storing time increments to not trigger hooks during Lua
- * calls and such.
- */
-typedef struct LTimeUpdate_s {
- struct LTimeUpdate_s* next; /**< Increment in the linked list. */
- unsigned int inc; /**< Time increment associated. */
-} LTimeUpdate_t;
-static LTimeUpdate_t* ltime_inclist = NULL; /** Time increment list. */
-
-static unsigned int lephisto_time = 0; /**< Contains the current time in mSTU. */
-
-/**
- * @brief Get the current time.
- * @return The current time in mSTU.
- */
-unsigned int ltime_get(void) {
- return lephisto_time;
-}
-
-/**
- * @brief Get the time in a pretty human readable format.
- * @param t Time to print (in STU), if 0 it'll use the current time.
- * @return The time in a human readable format (must free).
- */
-char* ltime_pretty(unsigned int t) {
- unsigned int lt;
- int maj, stu;
- char str[128], *ret;
-
- if(t == 0) lt = lephisto_time;
- else lt = t;
-
- /* UST (Universal Synchronized Time) - unit is STU (Syncronized Time Unit). */
- maj = lt / (1000*LTIME_UNIT_LENGTH);
- stu = (lt / (LTIME_UNIT_LENGTH)) % 1000;
- if(maj == 0) /* Only STU. */
- snprintf(str, 128, "%03d STU", stu);
- else /* Full format. */
- snprintf(str, 128, "UST %d.%03d", maj, stu);
- ret = strdup(str);
-
- return ret;
-}
-
-/**
- * @brief Set the time absolutely, does *not* generate an event, used at init.
- * @param t Absolute time to set to in STU.
- */
-void ltime_set(unsigned int t) {
- lephisto_time = t;
-}
-
-/**
- * @brief Set the time relatively.
- * @param t Time modifier in STU.
- */
-void ltime_inc(unsigned int t) {
- lephisto_time += t;
-
- hooks_run("time");
-
- economy_update(t);
-}
-
-/**
- * @brief Set the time relatively.
- *
- * This does *not* call hooks and such, they must be run with ltime_refresh
- * manually later.
- * @param t time modifier in STU.
- */
-void ltime_incLagged(unsigned int t) {
- LTimeUpdate_t* ltu, *iter;
-
- /* Create the time increment. */
- ltu = malloc(sizeof(LTimeUpdate_t));
- ltu->next = NULL;
- ltu->inc = t;
-
- /* Only member. */
- if(ltime_inclist == NULL)
- ltime_inclist = ltu;
- else {
- /* Find end of list. */
- for(iter = ltime_inclist; iter->next != NULL; iter = iter->next);
- /* Append to end. */
- iter->next = ltu;
- }
-}
-
-/**
- * @brief Check to see if ltime has any hooks pending to run.
- */
-void ltime_refresh(void) {
- LTimeUpdate_t* ltu;
-
- /*
- * We have to run all the increments one by one to ensure all hooks get
- * run and that no collisions accur.
- */
- while(ltime_inclist != NULL) {
- ltu = ltime_inclist;
-
- /* Run hook stuff and actually update time. */
- lephisto_time += ltu->inc;
- hooks_run("time");
- economy_update(ltu->inc);
-
- /* Remove the increment. */
- ltime_inclist = ltu->next;
-
- /* Free the increment. */
- free(ltu);
- }
-}
-
diff --git a/src/ltime.h b/src/ltime.h
deleted file mode 100644
index 32e7304..0000000
--- a/src/ltime.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-/* How long a 'unit' of time is. */
-#define LTIME_UNIT_LENGTH 1000
-
-/* Get. */
-unsigned int ltime_get(void);
-char* ltime_pretty(unsigned int t);
-
-/* Set. */
-void ltime_set(unsigned int t);
-void ltime_inc(unsigned int t);
-void ltime_incLagged(unsigned int t);
-
-/* Misc. */
-void ltime_refresh(void);
-
diff --git a/src/lxml.c b/src/lxml.c
deleted file mode 100644
index dfc6259..0000000
--- a/src/lxml.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * @file lxml.c
- *
- * Handles some complex xml parsing.
- */
-
-#include "lephisto.h"
-#include "lxml.h"
-
-/**
- * @brief Parses a texture handling the sx and sy elements.
- * @param node Node to parse.
- * @param path Path to get file from, should be in the format of
- * "PREFIX%sSUFFIX".
- * @param defsx Default X sprites.
- * @param defsy Default Y sprites.
- * @param flags Image parameter control flags.
- * @return The texture from the node or NULL if an error occurred.
- */
-glTexture* xml_parseTexture(xmlNodePtr node,
- const char* path, int defsx, int defsy,
- const unsigned int flags) {
-
- int sx, sy;
- char* buf, filename[PATH_MAX];
- glTexture* tex;
-
- /* Sane defaults. */
- sx = defsx;
- sy = defsy;
-
- /* Read x sprites. */
- xmlr_attr(node, "sx", buf);
- if(buf != NULL) {
- sx = atoi(buf);
- free(buf);
- }
-
- /* Read y sprites. */
- xmlr_attr(node, "sy", buf);
- if(buf != NULL) {
- sy = atoi(buf);
- free(buf);
- }
-
- /* Get graphic to load. */
- buf = xml_get(node);
- if(buf == NULL)
- return NULL;
-
- /* Convert name. */
- snprintf(filename, PATH_MAX, (path != NULL) ? path : "%s", buf);
-
- /* Load the graphic. */
- if((sx == 1) && (sy == 1))
- tex = gl_newImage(filename, flags);
- else
- tex = gl_newSprite(filename, sx, sy, flags);
-
- /* Return result. */
- return tex;
-}
-
diff --git a/src/lxml.h b/src/lxml.h
deleted file mode 100644
index 60184ff..0000000
--- a/src/lxml.h
+++ /dev/null
@@ -1,89 +0,0 @@
-#pragma once
-
-#include "libxml/parser.h"
-#include "libxml/xmlwriter.h"
-
-#include "log.h"
-#include "opengl.h"
-
-#define XML_NODE_START 1
-#define XML_NODE_TEXT 3
-
-/* Check if node n is of name s. */
-#define xml_isNode(n,s) \
- ((n!=NULL) && ((n)->type==XML_NODE_START) && \
- (strcmp((char*)(n)->name, s)==0))
-
-/* Get the next node. */
-#define xml_nextNode(n) \
- ((n!=NULL) && ((n = n->next) != NULL))
-
-/* Get the property s of node n. This mallocs. */
-#define xml_nodeProp(n,s) (char*)xmlGetProp(n, (xmlChar*)s)
-
-/* Get data different ways. */
-#define xml_raw(n) ((char*)(n)->children->content)
-#define xml_get(n) (((n)->children == NULL) ? NULL : (char*)(n)->children->content)
-#define xml_getInt(n) ((xml_get(n) == NULL) ? 0 : atoi(xml_raw(n)))
-#define xml_getLong(n) ((xml_get(n) == NULL) ? 0 : atol(xml_raw(n)))
-#define xml_getFloat(n) ((xml_get(n) == NULL) ? 0. : atof(xml_raw(n)))
-#define xml_getStrd(n) ((xml_get(n) == NULL) ? NULL : strdup(xml_raw(n)))
-
-/* Reader crap. */
-#define xmlr_int(n,s,i) \
- if(xml_isNode(n,s)) { i = xml_getInt(n); continue; }
-#define xmlr_long(n,s,l) \
- if(xml_isNode(n,s)) { l = xml_getLong(n); continue; }
-#define xmlr_float(n,s,f) \
- if(xml_isNode(n,s)) { f = xml_getFloat(n); continue; }
-#define xmlr_str(n,s,str) \
- if(xml_isNode(n,s)) { str = xml_get(n); continue; }
-#define xmlr_strd(n,s,str) \
- if(xml_isNode(n,s)) { str = ((xml_get(n) == NULL) ? NULL : strdup(xml_raw(n))); continue; }
-#define xmlr_attr(n,s,a) \
- a = xml_nodeProp(n,s)
-
-/* Writer crap. */
-
-/* Encompassing element. */
-#define xmlw_startElem(w, str) \
- if(xmlTextWriterStartElement(w, (xmlChar*)str) < 0) { \
- ERR("xmlw: Unable to create start element"); return -1; }
-
-#define xmlw_endElem(w) \
- if(xmlTextWriterEndElement(w) < 0) { \
- ERR("xmlw: Unable to create end element"); return -1; }
-
-/* Other stuff. */
-#define xmlw_elem(w, n, str, args...) \
- if(xmlTextWriterWriteFormatElement(w, (xmlChar*)n, str, ## args) < 0) { \
- ERR("xmlw: Unable to write format element"); return -1; }
-
-#define xmlw_raw(w,b,l) \
- if(xmlTextWriterWriteRawLen(w, (xmlChar*)b, l) < 0) { \
- ERR("xmlw: unable to write raw element"); return -1; }
-
-#define xmlw_attr(w, str, val...) \
- if(xmlTextWriterWriteFormatAttribute(w, (xmlChar*)str, ## val) < 0) { \
- ERR("xmlw: Unable to write element attribute"); return -1; }
-
-#define xmlw_str(w, str, val...) \
- if(xmlTextWriterWriteFormatString(w, str, ## val) < 0) { \
- ERR("xmlw: Unable to write element data"); return -1; }
-
-/* Document level. */
-#define xmlw_start(w) \
- if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) { \
- ERR("xmlw: Unable to start document"); return -1; }
-
-#define xmlw_done(w) \
- if(xmlTextWriterEndDocument(w) < 0) { \
- ERR("xmlw: Unable to end document"); return -1; }
-
-/*
- * Functions for generic complex reading.
- */
-glTexture* xml_parseTexture(xmlNodePtr node,
- const char* path, int defsx, int defsy,
- const unsigned int flags);
-
diff --git a/src/map.c b/src/map.c
deleted file mode 100644
index b594915..0000000
--- a/src/map.c
+++ /dev/null
@@ -1,949 +0,0 @@
-#include
-#include
-#include
-
-#include "log.h"
-#include "lephisto.h"
-#include "toolkit.h"
-#include "space.h"
-#include "opengl.h"
-#include "mission.h"
-#include "colour.h"
-#include "player.h"
-#include "map.h"
-
-#define MAP_WDWNAME "Star Map" /**< Map window name. */
-#define WINDOW_WIDTH 650 /**< Map window width. */
-#define WINDOW_HEIGHT 540 /**< Map window height. */
-
-#define MAP_WIDTH (WINDOW_WIDTH-150) /**< Map window width. */
-#define MAP_HEIGHT (WINDOW_HEIGHT-100) /**< Map height. */
-
-#define BUTTON_WIDTH 60 /**< Map button width. */
-#define BUTTON_HEIGHT 30 /**< Map button height. */
-
-#define MAP_LOOP_PROT 250 /**< Number of iterations max in pathfinding before
- aborting. */
-
-static double map_zoom = 1.; /**< Zoom of the map. */
-static double map_xpos = 0.; /**< Map X position. */
-static double map_ypos = 0.; /**< Map Y position. */
-static int map_selected = -1; /**< Currently selected system on map. */
-static StarSystem** map_path = NULL; /**< The path to current selected system. */
-int map_npath = 0; /**< Number of systems in map_path. */
-
-static int map_drag = 0; /**< Is the user dragging the map? */
-
-/* Extern. */
-/* space.c */
-extern StarSystem* systems_stack;
-extern int systems_nstack;
-
-static void map_update(unsigned int wid);
-static int map_inPath(StarSystem* sys);
-static void map_render(double bx, double by, double w, double h);
-static void map_mouse(unsigned int wid, SDL_Event* event, double mx, double my);
-static void map_buttonZoom(unsigned int wid, char* str);
-static void map_selectCur(void);
-
-/**
- * @brief Open the map window.
- */
-void map_open(void) {
- unsigned int wid;
- StarSystem* cur;
-
- /* Destroy window if exitsts. */
- wid = window_get(MAP_WDWNAME);
- if(wid > 0) {
- window_destroy(wid);
- return;
- }
-
- /* Set the position to focus on current system. */
- map_xpos = cur_system->pos.x;
- map_ypos = cur_system->pos.y;
-
- /* Mark systems as needed. */
- mission_sysMark();
-
- /* Attempt to select current map if none is selected. */
- if(map_selected == -1)
- map_selectCur();
-
- /* Get the selected system. */
- cur = system_getIndex(map_selected);
-
- /* Create the window. */
- wid = window_create("Star Map", -1, -1, WINDOW_WIDTH, WINDOW_HEIGHT);
-
- /*
- * SIDE TEXT
- *
- * $System
- *
- * Faction:
- * $Faction (or Multiple)
- *
- * Status:
- * $Status
- *
- * Planets:
- * $Planet1, $Planet2, ...
- *
- * Services:
- * $Services
- *
- * ...
- *
- * [Close]
- */
-
- /* System name. */
- window_addText(wid, -20, -20, 100, 20, 1, "txtSysname",
- &gl_defFont, &cDConsole, cur->name);
-
- /* Faction. */
- window_addText(wid, -20, -60, 90, 20, 0, "txtSFaction",
- &gl_smallFont, &cDConsole, "Faction:");
-
- window_addText(wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction",
- &gl_smallFont, &cBlack, NULL);
-
- /* Standing. */
- window_addText(wid, -20, -100, 90, 20, 0, "txtSStanding",
- &gl_smallFont, &cDConsole, "Standing:");
-
- window_addText(wid, -20, -100-gl_smallFont.h-5, 80, 100, 0, "txtStanding",
- &gl_smallFont, &cBlack, NULL);
-
- /* Planets. */
- window_addText(wid, -20, -140, 90, 20, 0, "txtSPlanets",
- &gl_smallFont, &cDConsole, "Planets:");
-
- window_addText(wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtPlanets",
- &gl_smallFont, &cBlack, NULL);
-
- /* Services. */
- window_addText(wid, -20, -180, 90, 20, 0, "txtSServices",
- &gl_smallFont, &cDConsole, "Services:");
-
- window_addText(wid, -20, -180-gl_smallFont.h-5, 80, 100, 0, "txtServices",
- &gl_smallFont, &cBlack, NULL);
-
- /* Close button. */
- window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
- "btnClose", "Close", (void(*)(char*))map_close);
-
- /* The map itself. */
- window_addCust(wid, 20, -40, MAP_WIDTH, MAP_HEIGHT,
- "cstMap", 1, map_render, map_mouse);
-
- /*
- * Bottom stuff.
- *
- * [+] [-] Nebulae, Asteroids, Interference.
- */
- /* Zoom buttons. */
- window_addButton(wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom);
- window_addButton(wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom);
- /* Situation text. */
- window_addText(wid, 140, 10, WINDOW_WIDTH-80-30-30, 30, 0,
- "txtSystemStatus", &gl_smallFont, &cBlack, NULL);
-
- map_update(wid);
-}
-
-static void map_update(unsigned int wid) {
- int i;
- StarSystem* sys;
- int f, y, h, standing, nstanding;
- unsigned int services;
- char buf[PATH_MAX];
- int p;
-
- /* Needs map to update. */
- if(!map_isOpen())
- return;
-
- sys = system_getIndex(map_selected);
-
- sys = &systems_stack[map_selected];
-
- /* Right text. */
- if(!sys_isKnown(sys)) { /* System isn't known. Erase all. */
- /* Right text. */
- window_modifyText(wid, "txtSysname", "Unknown");
- window_modifyText(wid, "txtFaction", "Unknown");
- /* Standing. */
- window_moveWidget(wid, "txtSStanding", -20, -100);
- window_moveWidget(wid, "txtStanding", -20, -100-gl_smallFont.h-5);
- window_modifyText(wid, "txtStanding", "Unknown");
- /* Planets. */
- window_moveWidget(wid, "txtSPlanets", -20, -140);
- window_moveWidget(wid, "txtPlanets", -20, -140-gl_smallFont.h-5);
- window_modifyText(wid, "txtPlanets", "Unknown");
- /* Services. */
- window_moveWidget(wid, "txtSServices", -20, -180);
- window_moveWidget(wid, "txtServices", -20, -180-gl_smallFont.h-5);
- window_modifyText(wid, "txtServices", "Unknown");
-
- /* Bottom text. */
- window_modifyText(wid, "txtSystemStatus", NULL);
-
- return;
- }
-
- /* System is known. */
- window_modifyText(wid, "txtSysname", sys->name);
-
- standing = 0;
- nstanding = 0;
- f = -1;
- for(i = 0; i < sys->nplanets; i++) {
- if((f == -1) && (sys->planets[i]->faction > 0)) {
- f = sys->planets[i]->faction;
- standing += faction_getPlayer(f);
- nstanding++;
- }
- else if(f != sys->planets[i]->faction && /* @todo More verbosity. */
- (sys->planets[i]->faction > 0)) {
- snprintf(buf, 100, "Multiple");
- break;
- }
- }
- if(f == -1) {
- window_modifyText(wid, "txtFaction", "NA");
- window_moveWidget(wid, "txtSStanding", -20, -100);
- window_moveWidget(wid, "txtStanding", -20, -100-gl_smallFont.h-5);
- window_modifyText(wid, "txtStanding", "NA");
- y = -100;
- } else {
- if(i == sys->nplanets)
- /* Saw them all, and all the same. */
- snprintf(buf, 100, "%s", faction_longname(f));
-
- /* Modify the text. */
- window_modifyText(wid, "txtFaction", buf);
- window_modifyText(wid, "txtStanding",
- faction_getStanding(standing / nstanding));
-
- /* Lower text if needed. */
- h = gl_printHeight(&gl_smallFont, 80, buf);
- y = -100 - (h - gl_smallFont.h);
- window_moveWidget(wid, "txtSStanding", -20, y);
- window_moveWidget(wid, "txtStanding", -20, y-gl_smallFont.h-5);
- }
-
- /* Get planets. */
- if(sys->nplanets == 0) {
- strncpy(buf, "None", 128);
- window_modifyText(wid, "txtPlanets", buf);
- } else {
- p = 0;
- buf[0] = '\0';
- if(sys->nplanets > 0)
- p += snprintf(&buf[p], PATH_MAX-p, "%s", sys->planets[0]->name);
- for(i = 1; i < sys->nplanets; i++) {
- p += snprintf(&buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name);
- }
- window_modifyText(wid, "txtPlanets", buf);
- }
- y -= 40;
- window_moveWidget(wid, "txtSPlanets", -20, y);
- window_moveWidget(wid, "txtPlanets", -20, y-gl_smallFont.h-5);
-
- /* Get the services. */
- h = gl_printHeight(&gl_smallFont, 80, buf);
- y -= 40 +(h - gl_smallFont.h);
- window_moveWidget(wid, "txtSServices", -20, y);
- window_moveWidget(wid, "txtServices", -20, y-gl_smallFont.h-5);
- services = 0;
- for(i = 0; i < sys->nplanets; i++)
- services |= sys->planets[i]->services;
- buf[0] = '\0';
- p = 0;
- /*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]); */
- if(services & PLANET_SERVICE_COMMODITY)
- p += snprintf(&buf[p], PATH_MAX-p, "Commodity\n");
- if(services & PLANET_SERVICE_OUTFITS)
- p += snprintf(&buf[p], PATH_MAX-p, "Outfits\n");
- if(services & PLANET_SERVICE_SHIPYARD)
- p += snprintf(&buf[p], PATH_MAX-p, "Shipyard\n");
- if(buf[0] == '\0')
- p += snprintf(&buf[p], PATH_MAX-p, "None");
- window_modifyText(wid, "txtServices", buf);
-
- /* System status. */
- buf[0] = '\0';
- p = 0;
-
- /* Nebulae. */
- if(sys->nebu_density > 0.) { /* Has nebulae. */
- /* Volatility. */
- if(sys->nebu_volatility > 700.)
- p += snprintf(&buf[p], PATH_MAX-p, " Volatile");
- else if(sys->nebu_volatility > 300.)
- p += snprintf(&buf[p], PATH_MAX-p, " Dangerous");
- else if(sys->nebu_volatility > 0.)
- p += snprintf(&buf[p], PATH_MAX-p, " Unstable");
-
- /* Density */
- if(sys->nebu_density > 700.)
- p += snprintf(&buf[p], PATH_MAX-p, " Dense");
- else if(sys->nebu_density < 300.)
- p += snprintf(&buf[p], PATH_MAX-p, " Light");
- p += snprintf(&buf[p], PATH_MAX-p, " Nebulae");
- }
- /* Interference. */
- if(sys->interference > 0.) {
- if(buf[0] != '\0')
- p += snprintf(&buf[p], PATH_MAX-p, ",");
-
- /* Density. */
- if(sys->interference > 700.)
- p += snprintf(&buf[p], PATH_MAX-p, " Dense");
- else if(sys->interference < 300.)
- p += snprintf(&buf[p], PATH_MAX-p, " Light");
-
- p += snprintf(&buf[p], PATH_MAX-p, " Interference");
- }
-
- window_modifyText(wid, "txtSystemStatus", buf);
-}
-
-/**
- * @brief Check to see if the map is open.
- * @return 0 if map is closed, non-zero if it's open.
- */
-int map_isOpen(void) {
- return window_exists(MAP_WDWNAME);
-}
-
-/* Return 1 if sys is part of the map_path. */
-static int map_inPath(StarSystem* sys) {
- int i, f;
-
- f = pilot_getJumps(player) - 1;
- for(i = 0; i < map_npath; i++)
- if(map_path[i] == sys) {
- if(i > f) {
- return 2;
- } else return 1;
- }
- return 0;
-}
-
-/* Render the map as a custom widget. */
-static void map_render(double bx, double by, double w, double h) {
- int i, j, n, m;
- double x, y, r, tx, ty;
- StarSystem* sys, *jsys, *hsys;
- glColour* col;
-
- r = 5.;
- x = (bx - map_xpos + w/2) * 1.;
- y = (by - map_ypos + h/2) * 1.;
- /* Background */
- COLOUR(cBlack);
- glBegin(GL_QUADS);
- glVertex2d(bx, by);
- glVertex2d(bx, by+h);
- glVertex2d(bx+w, by+h);
- glVertex2d(bx+w, by);
- glEnd();
-
- /* Render the star systems. */
- for(i = 0; i < systems_nstack; i++) {
- sys = system_getIndex(i);
-
- /* Check to make sure system is known of adjacent to known (or marked). */
- if(!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys))
- continue;
-
- /* System colours. */
- if(sys == cur_system) col = &cRadar_tPlanet;
- else if(!sys_isKnown(sys) || (sys->nplanets == 0)) col = &cInert;
- else col = faction_getColour(sys->faction);
- COLOUR(*col);
-
- /* Draw the system. */
- tx = x + sys->pos.x * map_zoom;
- ty = y + sys->pos.y * map_zoom;
- gl_drawCircleInRect(tx, ty, r, bx, by, w, h);
-
- /* Mark the system if needed. */
- if(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) {
- if(sys_isFlag(sys, SYSTEM_CMARKED))
- COLOUR(cGreen);
- else if(sys_isFlag(sys, SYSTEM_MARKED))
- COLOUR(cRed);
-
- glBegin(GL_TRIANGLES);
- glVertex2d(tx+r+9, ty+r+3);
- glVertex2d(tx+r+3, ty+r+3);
- glVertex2d(tx+r+3, ty+r+9);
- glEnd();
- }
-
- /* Draw the system name. */
- if(sys_isKnown(sys) && (map_zoom > 0.5)) {
- tx = x + 7. + sys->pos.x * map_zoom;
- ty = y - 5. + sys->pos.y * map_zoom;
- gl_print(&gl_smallFont,
- tx + SCREEN_W/2., ty + SCREEN_H/2.,
- &cWhite, sys->name);
- }
-
- if(!sys_isKnown(sys)) continue; /* We dont't draw hyperspace lines. */
-
- /* Draw the hyperspace paths. */
- glShadeModel(GL_SMOOTH);
- /* Cheaply use transparency instead of actually */
- /* calculating from x to y the line must go. :) */
- for(j = 0; j < sys->njumps; j++) {
- jsys = system_getIndex(sys->jumps[j]);
- hsys = system_getIndex(cur_system->jumps[hyperspace_target]);
-
- n = map_inPath(jsys);
- m = map_inPath(sys);
- /* Set the colours, is the route the current one? */
- if((hyperspace_target != -1) &&
- (((cur_system == sys) && (j == hyperspace_target)) ||
- ((cur_system == jsys) &&
- (sys == hsys)))) {
- if(player->fuel < HYPERSPACE_FUEL)
- col = &cRed;
- else
- col = &cGreen;
- }
- else if((n > 0) && (m > 0)) {
- if((n == 2) || (m == 2)) /* Out of fuel. */
- col = &cRed;
- else
- col = &cYellow;
- }
- else
- col = &cDarkBlue;
- glBegin(GL_LINE_STRIP);
- ACOLOUR(*col, 0.);
- tx = x + sys->pos.x * map_zoom;
- ty = y + sys->pos.y * map_zoom;
- glVertex2d(tx, ty);
- COLOUR(*col);
- tx += (jsys->pos.x - sys->pos.x)/2. * map_zoom;
- ty += (jsys->pos.y - sys->pos.y)/2. * map_zoom;
- glVertex2d(tx, ty);
- ACOLOUR(*col, 0.);
- tx = x + jsys->pos.x * map_zoom;
- ty = y + jsys->pos.y * map_zoom;
- glVertex2d(tx, ty);
- glEnd();
- }
- glShadeModel(GL_FLAT);
- }
- /* Selected planet. */
- if(map_selected != -1) {
- sys = system_getIndex(map_selected);
- COLOUR(cRed);
- gl_drawCircleInRect(x + sys->pos.x*map_zoom, y + sys->pos.y*map_zoom,
- r+3., bx, by, w, h);
- }
-}
-
-/* Map event handling. */
-static void map_mouse(unsigned int wid, SDL_Event* event, double mx, double my) {
- int i, j;
- double x, y, t;
- StarSystem* sys;
-
- t = 13.*15.; /* Threshold. */
-
- mx -= MAP_WIDTH/2 - map_xpos;
- my -= MAP_HEIGHT/2 - map_ypos;
-
- switch(event->type) {
- case SDL_MOUSEBUTTONDOWN:
- if(event->button.button == SDL_BUTTON_WHEELUP)
- map_buttonZoom(0, "btnZoomIn");
- else if(event->button.button == SDL_BUTTON_WHEELDOWN)
- map_buttonZoom(0, "btnZoomOut");
-
- /* Selecting star system. */
- else {
- for(i = 0; i < systems_nstack; i++) {
- sys = system_getIndex(i);
-
- /* Must be reachable. */
- if(!space_sysReachable(sys))
- continue;
-
- /* Get position. */
- x = systems_stack[i].pos.x * map_zoom;
- y = systems_stack[i].pos.y * map_zoom;
-
- if((pow2(mx-x)+pow2(my-y)) < t) {
- /* Select the current system and make a path to it. */
- map_selected = i;
- if(map_path)
- free(map_path);
- map_path = map_getJumpPath(&map_npath,
- cur_system->name, sys->name, 0);
-
- if(map_npath == 0)
- hyperspace_target = -1;
- else
- /* See if it is a valid hyperspace target. */
- for(j = 0; j < cur_system->njumps; j++) {
- if(map_path[0] == system_getIndex(cur_system->jumps[j])) {
- planet_target = -1; /* Override planet_target. */
- hyperspace_target = j;
- break;
- }
- }
- map_update(wid);
- break;
- }
- }
- map_drag = 1;
- }
- break;
-
- case SDL_MOUSEBUTTONUP:
- if(map_drag) map_drag = 0;
- break;
-
- case SDL_MOUSEMOTION:
- if(map_drag) {
- /* Axis is inverted. */
- map_xpos -= event->motion.xrel;
- map_ypos += event->motion.yrel;
- }
- break;
- }
-}
-
-static void map_buttonZoom(unsigned int wid, char* str) {
- (void)wid;
-
- if(strcmp(str, "btnZoomIn")==0) {
- map_zoom += (map_zoom >= 1.) ? 0.5 : 0.25;
- map_zoom = MIN(2.5, map_zoom);
- }
-
- else if(strcmp(str, "btnZoomOut")==0) {
- map_zoom -= (map_zoom > 1.) ? 0.5 : 0.25;
- map_zoom = MAX(0.25, map_zoom);
- }
-}
-
-/**
- * @brief Closes the map.
- */
-void map_close(void) {
- unsigned int wid;
-
- wid = window_get(MAP_WDWNAME);
- if(wid > 0)
- window_destroy(wid);
-}
-
-/* Set the map to sane defaults. */
-void map_clear(void) {
- map_zoom = 1.;
- if(cur_system != NULL) {
- map_xpos = cur_system->pos.x;
- map_ypos = cur_system->pos.y;
- } else {
- map_xpos = 0.;
- map_ypos = 0.;
- }
- if(map_path != NULL) {
- free(map_path);
- map_path = NULL;
- map_npath = 0;
- }
-
- /* Default system is current system. */
- map_selectCur();
-}
-
-/**
- * @brief Try to select the current system.
- */
-static void map_selectCur(void) {
- if(cur_system != NULL)
- map_selected = cur_system - systems_stack;
- else
- /* Probably going to seg fault now.. */
- map_selected = -1;
-}
-
-/**
- * @brief Update the map after a jump.
- */
-void map_jump(void) {
- int j;
-
- /* Set selected system to self. */
- map_selectCur();
-
- map_xpos = cur_system->pos.x;
- map_ypos = cur_system->pos.y;
-
- /* Update path if set. */
- if(map_path != NULL) {
- map_npath--;
- if(map_npath == 0) {
- /* Path is empty. */
- free(map_path);
- map_path = NULL;
- planet_target = -1;
- hyperspace_target = -1;
- } else {
- /* Get rid of bottom of the path. */
- memmove(&map_path[0], &map_path[1], sizeof(StarSystem*) * map_npath);
- map_path = realloc(map_path, sizeof(StarSystem*) * map_npath);
-
- /* Set the next jump to be the next in path. */
- for(j = 0; j < cur_system->njumps; j++) {
- if(map_path[0] == system_getIndex(cur_system->jumps[j])) {
- planet_target = -1; /* Override planet_target. */
- hyperspace_target = j;
- break;
- }
- }
- }
- }
-}
-
-/**
- * @brief Selects the system in the map.
- * @param sys System to select.
- */
-void map_select(StarSystem* sys) {
- unsigned int wid;
-
- wid = window_get(MAP_WDWNAME);
- if(sys == NULL)
- map_selectCur();
- else
- map_selected = sys - systems_stack;
- map_update(wid);
-}
-
-/* A* Algorithm fo shortest path finding. */
-
-/**
- * @brief Node structure for A* pathfinding.
- */
-typedef struct SysNode_ {
- struct SysNode_* next; /**< Next node. */
- struct SysNode_* gnext; /**< Next node in the garbage collector. */
-
- struct SysNode_* parent;
- StarSystem* sys;
- double r; /* Ranking. */
- int g; /* Step. */
-} SysNode;
-
-static SysNode* A_gc;
-/* Prototypes. */
-static SysNode* A_newNode(StarSystem* sys, SysNode* parent);
-static double A_h(StarSystem* n, StarSystem* g);
-static double A_g(SysNode* n);
-static SysNode* A_add(SysNode* first, SysNode* cur);
-static SysNode* A_rm(SysNode* first, StarSystem* cur);
-static SysNode* A_in(SysNode* first, StarSystem* cur);
-static SysNode* A_lowest(SysNode* first);
-static void A_freeList(SysNode* first);
-
-/* Creates a new node link to star system. */
-static SysNode* A_newNode(StarSystem* sys, SysNode* parent) {
- SysNode* n;
-
- n = malloc(sizeof(SysNode));
-
- n->next = NULL;
- n->parent = parent;
- n->sys = sys;
- n->r = DBL_MAX;
- n->g = 0.;
-
- n->gnext = A_gc;
- A_gc = n;
-
- return n;
-}
-
-static double A_h(StarSystem* n, StarSystem* g) {
- (void)n;
- (void)g;
- /* Euclidean distance. */
- /*return sqrt(pow2(n->pos.x - g->pos.x) + pow2(n->pos.y - g->pos.y))/100.; */
- return 0.;
-}
-
-/* Get the g from a node. */
-static double A_g(SysNode* n) {
- return n->g;
-}
-
-/* Add a node to the linkes list. */
-static SysNode* A_add(SysNode* first, SysNode* cur) {
- SysNode* n;
-
- if(first == NULL)
- return cur;
-
- n = first;
- while(n->next != NULL)
- n = n->next;
- n->next = cur;
-
- return first;
-}
-
-/* Remove a node from a linked list. */
-static SysNode* A_rm(SysNode* first, StarSystem* cur) {
- SysNode* n, *p;
-
- if(first->sys == cur) {
- n = first->next;
- first->next = NULL;
- return n;
- }
-
- p = first;
- n = p->next;
- do {
- if(n->sys == cur) {
- n->next = NULL;
- p->next = n->next;
- break;
- }
- } while((n=n->next) != NULL);
-
- return first;
-}
-
-/* Check if node is in linked list. */
-static SysNode* A_in(SysNode* first, StarSystem* cur) {
- SysNode* n;
-
- if(first == NULL)
- return NULL;
-
- n = first;
- do {
- if(n->sys == cur)
- return n;
- } while((n=n->next) != NULL);
- return NULL;
-}
-
-/* Return the lowest ranking node from a linked list of nodes. */
-static SysNode* A_lowest(SysNode* first) {
- SysNode* lowest, *n;
-
- if(first == NULL)
- return NULL;
-
- n = first;
- lowest = n;
- do {
- if(n->r < lowest->r)
- lowest = n;
- } while((n=n->next) != NULL);
-
- return lowest;
-}
-
-/* Free a linked list. */
-static void A_freeList(SysNode* first) {
- SysNode* p, *n;
-
- if(first == NULL)
- return;
-
- p = NULL;
- n = first;
- do {
- if(p != NULL)
- free(p);
- p = n;
- } while((n=n->gnext) != NULL);
-
- free(p);
-}
-
-StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known) {
- int i, j, cost;
-
- StarSystem* sys, *ssys, *esys, **res;
-
- SysNode* cur, *neighbour;
- SysNode* open, *closed;
- SysNode* ocost, *ccost;
-
- A_gc = NULL;
-
- /* Initial and target systems. */
- ssys = system_get(sysstart); /* Start. */
- esys = system_get(sysend); /* End. */
-
- /* System target must be known and reachable. */
- if(!ignore_known && !sys_isKnown(esys) && !space_sysReachable(esys)) {
- /* Can't reach - Don't make path. */
- (*njumps) = 0;
- return NULL;
- }
-
- /* Start the linked lists. */
- open = closed = NULL;
- cur = A_newNode(ssys, NULL);
- open = A_add(open, cur); /* Initial open node is the start system. */
-
- j = 0;
- while((cur = A_lowest(open))->sys != esys) {
- /* Break if infinite loop. */
- j++;
- if(j > MAP_LOOP_PROT)
- break;
-
- /* Get best from open and toss to closed. */
- open = A_rm(open, cur->sys);
- closed = A_add(closed, cur);
- cost = A_g(cur) + 1;
-
- for(i = 0; i < cur->sys->njumps; i++) {
- sys = system_getIndex(cur->sys->jumps[i]);
-
- /* Make sure it's reachable. */
- if(!ignore_known && (!sys_isKnown(sys) && !space_sysReachable(esys)))
- continue;
-
- neighbour = A_newNode(sys, NULL);
-
- ocost = A_in(open, sys);
- if((ocost != NULL) && (cost < ocost->g)) {
- open = A_rm(open, sys); /* New path is better. */
- }
-
- ccost = A_in(closed, sys);
- if(ccost != NULL) {
- closed = A_rm(closed, sys); /* Shouldn't happen. */
- }
-
- if((ocost == NULL) && (ccost == NULL)) {
- neighbour->g = cost;
- neighbour->r = A_g(neighbour) + A_h(cur->sys, sys);
- neighbour->parent = cur;
- open = A_add(open, neighbour);
- }
- }
- }
- /* Build the path backwards if not broken from loop. */
- if(j <= MAP_LOOP_PROT) {
- (*njumps) = A_g(cur);
- res = malloc(sizeof(StarSystem*) * (*njumps));
- for(i = 0; i < (*njumps); i++) {
- res[(*njumps)-i-1] = cur->sys;
- cur = cur->parent;
- }
- } else {
- (*njumps) = 0;
- res = NULL;
- }
-
- /* Free the linked list. */
- A_freeList(A_gc);
- return res;
-}
-
-/* Marks maps around a radius of current system as known. */
-int map_map(char* targ_sys, int r) {
- int i, dep;
- StarSystem* sys, *jsys;
- SysNode* closed, *open, *cur, *neighbour;
-
- A_gc = NULL;
- open = closed = NULL;
-
- if(targ_sys == NULL) sys = cur_system;
- else sys = system_get(targ_sys);
- sys_setFlag(sys, SYSTEM_KNOWN);
- open = A_newNode(sys, NULL);
- open->r = 0;
-
- while((cur = A_lowest(open)) != NULL) {
- /* Mark system as known and go to next. */
- sys = cur->sys;
- dep = cur->r;
- sys_setFlag(sys, SYSTEM_KNOWN);
- open = A_rm(open, sys);
- closed = A_add(closed, cur);
-
- /* Check it's jumps. */
- for(i = 0; i < sys->njumps; i++) {
- jsys = system_getIndex(cur->sys->jumps[i]);
-
- /* System has already been parsed or is too deep. */
- if((A_in(closed, jsys) != NULL) || (dep+1 > r))
- continue;
-
- /* Create new node and such. */
- neighbour = A_newNode(jsys, NULL);
- neighbour->r = dep+1;
- open = A_add(open, neighbour);
- }
- }
- A_freeList(A_gc);
- return 0;
-}
-
-/* Check to see if radius is mapped. */
-int map_isMapped(char* targ_sys, int r) {
- int i, dep, ret;
- StarSystem* sys, *jsys;
- SysNode* closed, *open, *cur, *neighbour;
-
- A_gc = NULL;
- open = closed = NULL;
-
- if(targ_sys == NULL) sys = cur_system;
- else sys = system_get(targ_sys);
- open = A_newNode(sys, NULL);
- open->r = 0;
- ret = 1;
-
- while((cur = A_lowest(open)) != NULL) {
- /* Mark system as known and go to next. */
- sys = cur->sys;
- dep = cur->r;
- if(!sys_isFlag(sys, SYSTEM_KNOWN)) {
- ret = 0;
- break;
- }
- open = A_rm(open, sys);
- closed = A_add(closed, cur);
-
- /* Check it's jumps. */
- for(i = 0; i < sys->njumps; i++) {
- jsys = system_getIndex(cur->sys->jumps[i]);
-
- /* System has already been parsed or is too deep. */
- if((A_in(closed, jsys) != NULL) || (dep+1 > r))
- continue;
-
- /* Create new node and such. */
- neighbour = A_newNode(jsys, NULL);
- neighbour->r = dep+1;
- open = A_add(open, neighbour);
- }
- }
-
- A_freeList(A_gc);
- return ret;
-}
-
diff --git a/src/map.h b/src/map.h
deleted file mode 100644
index 8eb8ee7..0000000
--- a/src/map.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-#include "space.h"
-
-/* Open the map window. */
-void map_open(void);
-void map_close(void);
-int map_isOpen(void);
-
-/* Misc. */
-void map_select(StarSystem* sys);
-void map_clear(void);
-void map_jump(void);
-
-/* Manipulate universe stuff. */
-StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known);
-int map_map(char* targ_sys, int r);
-int map_isMapped(char* targ_sys, int r);
-
diff --git a/src/md5.c b/src/md5.c
deleted file mode 100644
index 221aba1..0000000
--- a/src/md5.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- L. Peter Deutsch
- ghost@aladdin.com
-
- */
-/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
-/*
- Independent implementation of MD5 (RFC 1321).
-
- This code implements the MD5 Algorithm defined in RFC 1321, whose
- text is available at
- http://www.ietf.org/rfc/rfc1321.txt
- The code is derived from the text of the RFC, including the test suite
- (section A.5) but excluding the rest of Appendix A. It does not include
- any code or documentation that is identified in the RFC as being
- copyrighted.
-
- The original and principal author of md5.c is L. Peter Deutsch
- . Other authors are noted in the change history
- that follows (in reverse chronological order):
-
- 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
- either statically or dynamically; added missing #include