]> github.com/historicalsource and other repositories - Darwinia-and-Multiwinia-Source-Code.git/commitdiff
code: convert wildly inconsistent line endings to '\n' format
authorSteven <Steven@9244cb4f-d52e-49a9-a756-7d4e53ad8306>
Tue, 8 Jun 2010 19:08:21 +0000 (19:08 +0000)
committerSteven <Steven@9244cb4f-d52e-49a9-a756-7d4e53ad8306>
Tue, 8 Jun 2010 19:08:21 +0000 (19:08 +0000)
532 files changed:
darwinia/code/3d_sierpinski_gasket.cpp
darwinia/code/3d_sierpinski_gasket.h
darwinia/code/app.cpp
darwinia/code/app.h
darwinia/code/attract.cpp
darwinia/code/attract.h
darwinia/code/camera.cpp
darwinia/code/camera.h
darwinia/code/clouds.cpp
darwinia/code/clouds.h
darwinia/code/control_help.cpp
darwinia/code/control_help.h
darwinia/code/deform.cpp
darwinia/code/deform.h
darwinia/code/demoendsequence.cpp
darwinia/code/demoendsequence.h
darwinia/code/effect_processor.cpp
darwinia/code/effect_processor.h
darwinia/code/entity_grid.cpp
darwinia/code/entity_grid.h
darwinia/code/explosion.cpp
darwinia/code/explosion.h
darwinia/code/game_menu.cpp
darwinia/code/game_menu.h
darwinia/code/gamecursor.cpp
darwinia/code/gamecursor.h
darwinia/code/gesture.cpp
darwinia/code/gesture.h
darwinia/code/gesture_demo.cpp
darwinia/code/gesture_demo.h
darwinia/code/gesture_demo_sdl.cpp
darwinia/code/gesture_demo_win32.cpp
darwinia/code/global_internet.cpp
darwinia/code/global_internet.h
darwinia/code/global_world.cpp
darwinia/code/global_world.h
darwinia/code/globals.h
darwinia/code/helpsystem.cpp
darwinia/code/helpsystem.h
darwinia/code/interface/buildings_window.cpp
darwinia/code/interface/buildings_window.h
darwinia/code/interface/buynow_window.cpp
darwinia/code/interface/camera_anim_window.cpp
darwinia/code/interface/camera_anim_window.h
darwinia/code/interface/camera_mount_window.cpp
darwinia/code/interface/camera_mount_window.h
darwinia/code/interface/cheat_window.cpp
darwinia/code/interface/cheat_window.h
darwinia/code/interface/darwinia_window.cpp
darwinia/code/interface/darwinia_window.h
darwinia/code/interface/debugmenu.cpp
darwinia/code/interface/debugmenu.h
darwinia/code/interface/demoend_window.cpp
darwinia/code/interface/demoend_window.h
darwinia/code/interface/drop_down_menu.cpp
darwinia/code/interface/drop_down_menu.h
darwinia/code/interface/editor_window.cpp
darwinia/code/interface/editor_window.h
darwinia/code/interface/filedialog.cpp
darwinia/code/interface/filedialog.h
darwinia/code/interface/gesture_window.cpp
darwinia/code/interface/gesture_window.h
darwinia/code/interface/globalworldeditor_window.cpp
darwinia/code/interface/globalworldeditor_window.h
darwinia/code/interface/grabber_window.cpp
darwinia/code/interface/grabber_window.h
darwinia/code/interface/input_field.cpp
darwinia/code/interface/input_field.h
darwinia/code/interface/instant_unit_window.cpp
darwinia/code/interface/instant_unit_window.h
darwinia/code/interface/landscape_window.cpp
darwinia/code/interface/landscape_window.h
darwinia/code/interface/lights_window.cpp
darwinia/code/interface/lights_window.h
darwinia/code/interface/mainmenus.cpp
darwinia/code/interface/message_dialog.cpp
darwinia/code/interface/message_dialog.h
darwinia/code/interface/mods_window.cpp
darwinia/code/interface/mods_window.h
darwinia/code/interface/network_window.cpp
darwinia/code/interface/network_window.h
darwinia/code/interface/pokey_window.h
darwinia/code/interface/prefs_graphics_window.cpp
darwinia/code/interface/prefs_graphics_window.h
darwinia/code/interface/prefs_keybindings_window.cpp
darwinia/code/interface/prefs_keybindings_window.h
darwinia/code/interface/prefs_other_window.cpp
darwinia/code/interface/prefs_screen_window.cpp
darwinia/code/interface/prefs_screen_window.h
darwinia/code/interface/prefs_sound_window.cpp
darwinia/code/interface/prefs_sound_window.h
darwinia/code/interface/profilewindow.cpp
darwinia/code/interface/profilewindow.h
darwinia/code/interface/reallyquit_window.cpp
darwinia/code/interface/reallyquit_window.h
darwinia/code/interface/save_on_quit_window.cpp
darwinia/code/interface/save_on_quit_window.h
darwinia/code/interface/scrollbar.cpp
darwinia/code/interface/scrollbar.h
darwinia/code/interface/sound_profile_window.cpp
darwinia/code/interface/sound_profile_window.h
darwinia/code/interface/soundeditor_window.cpp
darwinia/code/interface/soundeditor_window.h
darwinia/code/interface/soundparameter_window.cpp
darwinia/code/interface/soundparameter_window.h
darwinia/code/interface/soundstats_window.cpp
darwinia/code/interface/soundstats_window.h
darwinia/code/interface/tree_window.cpp
darwinia/code/interface/tree_window.h
darwinia/code/interface/userprofile_window.cpp
darwinia/code/interface/userprofile_window.h
darwinia/code/keygen.cpp
darwinia/code/keygen.h
darwinia/code/landscape.cpp
darwinia/code/landscape.h
darwinia/code/landscape_renderer.cpp
darwinia/code/landscape_renderer.h
darwinia/code/level_file.cpp
darwinia/code/level_file.h
darwinia/code/lib/2d_array.cpp
darwinia/code/lib/2d_array.h
darwinia/code/lib/2d_surface_map.cpp
darwinia/code/lib/2d_surface_map.h
darwinia/code/lib/3d_sprite.cpp
darwinia/code/lib/3d_sprite.h
darwinia/code/lib/GetWinVer.cpp
darwinia/code/lib/GetWinVer.h
darwinia/code/lib/MiniVersion.cpp
darwinia/code/lib/MiniVersion.h
darwinia/code/lib/auto_vector.h
darwinia/code/lib/avi_generator.cpp
darwinia/code/lib/avi_generator.h
darwinia/code/lib/avi_player.cpp
darwinia/code/lib/avi_player.h
darwinia/code/lib/binary_stream_readers.cpp
darwinia/code/lib/binary_stream_readers.h
darwinia/code/lib/bitmap.cpp
darwinia/code/lib/bitmap.h
darwinia/code/lib/bounded_array.cpp
darwinia/code/lib/bounded_array.h
darwinia/code/lib/btree.cpp
darwinia/code/lib/btree.h
darwinia/code/lib/darray.cpp
darwinia/code/lib/darray.h
darwinia/code/lib/debug_fog_logging.cpp
darwinia/code/lib/debug_logging.cpp
darwinia/code/lib/debug_logging.h
darwinia/code/lib/debug_render.cpp
darwinia/code/lib/debug_render.h
darwinia/code/lib/debug_utils.cpp
darwinia/code/lib/debug_utils.h
darwinia/code/lib/debug_utils_gcc.cpp
darwinia/code/lib/debug_utils_linux.cpp
darwinia/code/lib/exception_handler.cpp
darwinia/code/lib/exception_handler.h
darwinia/code/lib/fast_darray.cpp
darwinia/code/lib/fast_darray.h
darwinia/code/lib/file_writer.cpp
darwinia/code/lib/file_writer.h
darwinia/code/lib/filesys_utils.cpp
darwinia/code/lib/filesys_utils.h
darwinia/code/lib/hash_table.cpp
darwinia/code/lib/hash_table.h
darwinia/code/lib/hi_res_time.cpp
darwinia/code/lib/hi_res_time.h
darwinia/code/lib/hi_res_time_gcc.cpp
darwinia/code/lib/hi_res_time_sdl.cpp
darwinia/code/lib/input/control_bindings.cpp
darwinia/code/lib/input/control_bindings.h
darwinia/code/lib/input/control_types.cpp
darwinia/code/lib/input/control_types.h
darwinia/code/lib/input/eventhandler.cpp
darwinia/code/lib/input/eventhandler.h
darwinia/code/lib/input/file_paths.cpp
darwinia/code/lib/input/file_paths.h
darwinia/code/lib/input/input.cpp
darwinia/code/lib/input/input.h
darwinia/code/lib/input/input_types.cpp
darwinia/code/lib/input/input_types.h
darwinia/code/lib/input/inputdriver.cpp
darwinia/code/lib/input/inputdriver.h
darwinia/code/lib/input/inputdriver_alias.cpp
darwinia/code/lib/input/inputdriver_alias.h
darwinia/code/lib/input/inputdriver_chord.cpp
darwinia/code/lib/input/inputdriver_chord.h
darwinia/code/lib/input/inputdriver_conjoin.cpp
darwinia/code/lib/input/inputdriver_conjoin.h
darwinia/code/lib/input/inputdriver_idle.cpp
darwinia/code/lib/input/inputdriver_idle.h
darwinia/code/lib/input/inputdriver_invert.cpp
darwinia/code/lib/input/inputdriver_invert.h
darwinia/code/lib/input/inputdriver_pipe.cpp
darwinia/code/lib/input/inputdriver_pipe.h
darwinia/code/lib/input/inputdriver_prefs.cpp
darwinia/code/lib/input/inputdriver_prefs.h
darwinia/code/lib/input/inputdriver_simple.cpp
darwinia/code/lib/input/inputdriver_simple.h
darwinia/code/lib/input/inputdriver_value.cpp
darwinia/code/lib/input/inputdriver_value.h
darwinia/code/lib/input/inputdriver_win32.cpp
darwinia/code/lib/input/inputdriver_win32.h
darwinia/code/lib/input/inputdriver_xinput.cpp
darwinia/code/lib/input/inputdriver_xinput.h
darwinia/code/lib/input/inputfilter.cpp
darwinia/code/lib/input/inputfilter.h
darwinia/code/lib/input/inputfilter_direction.cpp
darwinia/code/lib/input/inputfilter_direction.h
darwinia/code/lib/input/inputfilter_withdelta.cpp
darwinia/code/lib/input/inputfilter_withdelta.h
darwinia/code/lib/input/inputfiltermanager.cpp
darwinia/code/lib/input/inputfiltermanager.h
darwinia/code/lib/input/inputfilterspec.cpp
darwinia/code/lib/input/inputfilterspec.h
darwinia/code/lib/input/inputspec.cpp
darwinia/code/lib/input/inputspec.h
darwinia/code/lib/input/inputspeclist.h
darwinia/code/lib/input/keydefs.h
darwinia/code/lib/input/keynames.cpp
darwinia/code/lib/input/keynames.h
darwinia/code/lib/input/movement2d.cpp
darwinia/code/lib/input/movement2d.h
darwinia/code/lib/input/transform.cpp
darwinia/code/lib/input/transform.h
darwinia/code/lib/input/win32_eventhandler.cpp
darwinia/code/lib/input/win32_eventhandler.h
darwinia/code/lib/input/win32_eventproc.h
darwinia/code/lib/input_sdl.cpp
darwinia/code/lib/invert_matrix.cpp
darwinia/code/lib/invert_matrix.h
darwinia/code/lib/language_table.cpp
darwinia/code/lib/language_table.h
darwinia/code/lib/llist.cpp
darwinia/code/lib/llist.h
darwinia/code/lib/math_utils.cpp
darwinia/code/lib/math_utils.h
darwinia/code/lib/matrix33.cpp
darwinia/code/lib/matrix33.h
darwinia/code/lib/matrix34.cpp
darwinia/code/lib/matrix34.h
darwinia/code/lib/mouse_cursor.cpp
darwinia/code/lib/mouse_cursor.h
darwinia/code/lib/ogl_extensions.cpp
darwinia/code/lib/ogl_extensions.h
darwinia/code/lib/ogl_extensions_directx.cpp
darwinia/code/lib/ogl_extensions_sdl.cpp
darwinia/code/lib/opengl_directx.cpp
darwinia/code/lib/opengl_directx.h
darwinia/code/lib/opengl_directx_dlist.cpp
darwinia/code/lib/opengl_directx_dlist.h
darwinia/code/lib/opengl_directx_dlist_dev.cpp
darwinia/code/lib/opengl_directx_dlist_dev.h
darwinia/code/lib/opengl_directx_inline.h
darwinia/code/lib/opengl_directx_internals.h
darwinia/code/lib/opengl_directx_matrix_stack.cpp
darwinia/code/lib/opengl_directx_matrix_stack.h
darwinia/code/lib/opengl_directx_stubs.cpp
darwinia/code/lib/opengl_trace.cpp
darwinia/code/lib/opengl_trace.h
darwinia/code/lib/persisting_debug_render.cpp
darwinia/code/lib/persisting_debug_render.h
darwinia/code/lib/plane.cpp
darwinia/code/lib/plane.h
darwinia/code/lib/poster_maker.cpp
darwinia/code/lib/poster_maker.h
darwinia/code/lib/preferences.cpp
darwinia/code/lib/preferences.h
darwinia/code/lib/presized_array.h
darwinia/code/lib/profiler.cpp
darwinia/code/lib/profiler.h
darwinia/code/lib/random.cpp
darwinia/code/lib/random.h
darwinia/code/lib/render_utils.cpp
darwinia/code/lib/render_utils.h
darwinia/code/lib/resource.cpp
darwinia/code/lib/resource.h
darwinia/code/lib/rgb_colour.cpp
darwinia/code/lib/rgb_colour.h
darwinia/code/lib/shader.cpp
darwinia/code/lib/shader.h
darwinia/code/lib/shape.cpp
darwinia/code/lib/shape.h
darwinia/code/lib/slice_darray.cpp
darwinia/code/lib/slice_darray.h
darwinia/code/lib/sorting_hash_table.cpp
darwinia/code/lib/sorting_hash_table.h
darwinia/code/lib/sphere_renderer.cpp
darwinia/code/lib/sphere_renderer.h
darwinia/code/lib/string_utils.cpp
darwinia/code/lib/string_utils.h
darwinia/code/lib/system_info.cpp
darwinia/code/lib/system_info.h
darwinia/code/lib/system_info_macosx.cpp
darwinia/code/lib/targetcursor.cpp
darwinia/code/lib/targetcursor.h
darwinia/code/lib/text_renderer.cpp
darwinia/code/lib/text_renderer.h
darwinia/code/lib/text_stream_readers.cpp
darwinia/code/lib/text_stream_readers.h
darwinia/code/lib/texture.cpp
darwinia/code/lib/texture.h
darwinia/code/lib/texture_uv.cpp
darwinia/code/lib/texture_uv.h
darwinia/code/lib/tri_tri.cpp
darwinia/code/lib/universal_include.cpp
darwinia/code/lib/universal_include.h
darwinia/code/lib/user_info.cpp
darwinia/code/lib/user_info.h
darwinia/code/lib/vector2.cpp
darwinia/code/lib/vector2.h
darwinia/code/lib/vector3.cpp
darwinia/code/lib/vector3.h
darwinia/code/lib/window_manager.cpp
darwinia/code/lib/window_manager.h
darwinia/code/lib/window_manager_directx.cpp
darwinia/code/lib/window_manager_sdl.cpp
darwinia/code/lib/window_manager_win32.h
darwinia/code/loaders/amiga_loader.h
darwinia/code/loaders/credits_loader.cpp
darwinia/code/loaders/credits_loader.h
darwinia/code/loaders/fodder_loader.cpp
darwinia/code/loaders/fodder_loader.h
darwinia/code/loaders/gameoflife_loader.cpp
darwinia/code/loaders/gameoflife_loader.h
darwinia/code/loaders/loader.cpp
darwinia/code/loaders/loader.h
darwinia/code/loaders/matrix_loader.cpp
darwinia/code/loaders/matrix_loader.h
darwinia/code/loaders/raytrace_loader.cpp
darwinia/code/loaders/raytrace_loader.h
darwinia/code/loaders/soul_loader.cpp
darwinia/code/loaders/soul_loader.h
darwinia/code/loaders/speccy_loader.h
darwinia/code/location.cpp
darwinia/code/location.h
darwinia/code/location_editor.cpp
darwinia/code/location_editor.h
darwinia/code/location_input.cpp
darwinia/code/location_input.h
darwinia/code/main.cpp
darwinia/code/main.h
darwinia/code/network/bytestream.h
darwinia/code/network/clienttoserver.cpp
darwinia/code/network/clienttoserver.h
darwinia/code/network/generic.cpp
darwinia/code/network/generic.h
darwinia/code/network/networkupdate.cpp
darwinia/code/network/networkupdate.h
darwinia/code/network/server.cpp
darwinia/code/network/server.h
darwinia/code/network/servertoclient.cpp
darwinia/code/network/servertoclient.h
darwinia/code/network/servertoclientletter.cpp
darwinia/code/network/servertoclientletter.h
darwinia/code/obstruction_grid.cpp
darwinia/code/obstruction_grid.h
darwinia/code/particle_system.cpp
darwinia/code/particle_system.h
darwinia/code/renderer.cpp
darwinia/code/renderer.h
darwinia/code/routing_system.cpp
darwinia/code/routing_system.h
darwinia/code/script.cpp
darwinia/code/script.h
darwinia/code/sepulveda.cpp
darwinia/code/sepulveda.h
darwinia/code/sepulveda_strings.cpp
darwinia/code/sound/sample_cache.cpp
darwinia/code/sound/sample_cache.h
darwinia/code/sound/sound_filter.cpp
darwinia/code/sound/sound_filter.h
darwinia/code/sound/sound_instance.cpp
darwinia/code/sound/sound_instance.h
darwinia/code/sound/sound_library_2d.cpp
darwinia/code/sound/sound_library_2d.h
darwinia/code/sound/sound_library_2d_nosnd.cpp
darwinia/code/sound/sound_library_2d_sdl.cpp
darwinia/code/sound/sound_library_3d.cpp
darwinia/code/sound/sound_library_3d.h
darwinia/code/sound/sound_library_3d_dsound.cpp
darwinia/code/sound/sound_library_3d_dsound.h
darwinia/code/sound/sound_library_3d_software.cpp
darwinia/code/sound/sound_library_3d_software.h
darwinia/code/sound/sound_parameter.cpp
darwinia/code/sound/sound_parameter.h
darwinia/code/sound/sound_stream_decoder.cpp
darwinia/code/sound/sound_stream_decoder.h
darwinia/code/sound/soundsystem.cpp
darwinia/code/sound/soundsystem.h
darwinia/code/startsequence.cpp
darwinia/code/startsequence.h
darwinia/code/taskmanager.cpp
darwinia/code/taskmanager.h
darwinia/code/taskmanager_interface.cpp
darwinia/code/taskmanager_interface.h
darwinia/code/taskmanager_interface_gestures.cpp
darwinia/code/taskmanager_interface_gestures.h
darwinia/code/taskmanager_interface_icons.cpp
darwinia/code/taskmanager_interface_icons.h
darwinia/code/team.cpp
darwinia/code/team.h
darwinia/code/testharness.cpp
darwinia/code/testharness.h
darwinia/code/tutorial.cpp
darwinia/code/tutorial.h
darwinia/code/tutorial_demo1.cpp
darwinia/code/tutorial_demo2.cpp
darwinia/code/unit.cpp
darwinia/code/unit.h
darwinia/code/user_input.cpp
darwinia/code/user_input.h
darwinia/code/water.cpp
darwinia/code/water.h
darwinia/code/water_reflection.cpp
darwinia/code/water_reflection.h
darwinia/code/worldobject/ai.cpp
darwinia/code/worldobject/ai.h
darwinia/code/worldobject/airstrike.cpp
darwinia/code/worldobject/airstrike.h
darwinia/code/worldobject/anthill.cpp
darwinia/code/worldobject/anthill.h
darwinia/code/worldobject/armour.cpp
darwinia/code/worldobject/armour.h
darwinia/code/worldobject/armyant.cpp
darwinia/code/worldobject/armyant.h
darwinia/code/worldobject/blueprintstore.cpp
darwinia/code/worldobject/blueprintstore.h
darwinia/code/worldobject/bridge.cpp
darwinia/code/worldobject/bridge.h
darwinia/code/worldobject/building.cpp
darwinia/code/worldobject/building.h
darwinia/code/worldobject/cave.cpp
darwinia/code/worldobject/cave.h
darwinia/code/worldobject/centipede.cpp
darwinia/code/worldobject/centipede.h
darwinia/code/worldobject/constructionyard.cpp
darwinia/code/worldobject/constructionyard.h
darwinia/code/worldobject/controltower.cpp
darwinia/code/worldobject/controltower.h
darwinia/code/worldobject/darwinian.cpp
darwinia/code/worldobject/darwinian.h
darwinia/code/worldobject/egg.cpp
darwinia/code/worldobject/egg.h
darwinia/code/worldobject/engineer.cpp
darwinia/code/worldobject/engineer.h
darwinia/code/worldobject/entity.cpp
darwinia/code/worldobject/entity.h
darwinia/code/worldobject/entity_leg.cpp
darwinia/code/worldobject/entity_leg.h
darwinia/code/worldobject/factory.cpp
darwinia/code/worldobject/factory.h
darwinia/code/worldobject/feedingtube.cpp
darwinia/code/worldobject/feedingtube.h
darwinia/code/worldobject/flag.cpp
darwinia/code/worldobject/flag.h
darwinia/code/worldobject/generator.cpp
darwinia/code/worldobject/generator.h
darwinia/code/worldobject/generichub.cpp
darwinia/code/worldobject/generichub.h
darwinia/code/worldobject/goddish.cpp
darwinia/code/worldobject/goddish.h
darwinia/code/worldobject/gunturret.cpp
darwinia/code/worldobject/gunturret.h
darwinia/code/worldobject/incubator.cpp
darwinia/code/worldobject/incubator.h
darwinia/code/worldobject/insertion_squad.cpp
darwinia/code/worldobject/insertion_squad.h
darwinia/code/worldobject/lander.cpp
darwinia/code/worldobject/lander.h
darwinia/code/worldobject/laserfence.cpp
darwinia/code/worldobject/laserfence.h
darwinia/code/worldobject/lasertrooper.cpp
darwinia/code/worldobject/lasertrooper.h
darwinia/code/worldobject/library.cpp
darwinia/code/worldobject/library.h
darwinia/code/worldobject/mine.cpp
darwinia/code/worldobject/mine.h
darwinia/code/worldobject/officer.cpp
darwinia/code/worldobject/officer.h
darwinia/code/worldobject/powerstation.cpp
darwinia/code/worldobject/powerstation.h
darwinia/code/worldobject/radardish.cpp
darwinia/code/worldobject/radardish.h
darwinia/code/worldobject/researchitem.cpp
darwinia/code/worldobject/researchitem.h
darwinia/code/worldobject/rocket.cpp
darwinia/code/worldobject/rocket.h
darwinia/code/worldobject/safearea.cpp
darwinia/code/worldobject/safearea.h
darwinia/code/worldobject/scripttrigger.cpp
darwinia/code/worldobject/scripttrigger.h
darwinia/code/worldobject/snow.cpp
darwinia/code/worldobject/snow.h
darwinia/code/worldobject/souldestroyer.cpp
darwinia/code/worldobject/souldestroyer.h
darwinia/code/worldobject/spam.cpp
darwinia/code/worldobject/spam.h
darwinia/code/worldobject/spawnpoint.cpp
darwinia/code/worldobject/spawnpoint.h
darwinia/code/worldobject/spider.cpp
darwinia/code/worldobject/spider.h
darwinia/code/worldobject/spirit.cpp
darwinia/code/worldobject/spirit.h
darwinia/code/worldobject/spiritreceiver.cpp
darwinia/code/worldobject/spiritreceiver.h
darwinia/code/worldobject/spiritstore.cpp
darwinia/code/worldobject/spiritstore.h
darwinia/code/worldobject/sporegenerator.cpp
darwinia/code/worldobject/sporegenerator.h
darwinia/code/worldobject/staticshape.cpp
darwinia/code/worldobject/staticshape.h
darwinia/code/worldobject/switch.cpp
darwinia/code/worldobject/switch.h
darwinia/code/worldobject/teleport.cpp
darwinia/code/worldobject/teleport.h
darwinia/code/worldobject/tree.cpp
darwinia/code/worldobject/tree.h
darwinia/code/worldobject/triffid.cpp
darwinia/code/worldobject/triffid.h
darwinia/code/worldobject/tripod.cpp
darwinia/code/worldobject/tripod.h
darwinia/code/worldobject/trunkport.cpp
darwinia/code/worldobject/trunkport.h
darwinia/code/worldobject/upgrade_port.cpp
darwinia/code/worldobject/upgrade_port.h
darwinia/code/worldobject/virii.cpp
darwinia/code/worldobject/virii.h
darwinia/code/worldobject/wall.cpp
darwinia/code/worldobject/wall.h
darwinia/code/worldobject/weapons.cpp
darwinia/code/worldobject/weapons.h
darwinia/code/worldobject/worldobject.cpp
darwinia/code/worldobject/worldobject.h

index 7c7afd632067eccf08b05e6126b24900ede44cd4..06e7fdf543cfc3239b65076b55becee790a89978 100644 (file)
@@ -1,8 +1,8 @@
 #include "lib/universal_include.h"
-#include "lib/math_utils.h"\r
-#include "lib/matrix34.h"\r
-#include "lib/vector3.h"\r
-#include "lib/debug_render.h"\r
+#include "lib/math_utils.h"
+#include "lib/matrix34.h"
+#include "lib/vector3.h"
+#include "lib/debug_render.h"
 
 #include "app.h" // DELETEME
 #include "camera.h" // DELETEME
@@ -75,9 +75,9 @@ void Sierpinski3D::Render(float scale)
        glPointSize(3.0f);
        //glDepthMask(false);
        glDisable(GL_DEPTH_TEST);
-    glDisable(GL_TEXTURE_2D);\r
-    glDisable(GL_CULL_FACE);\r
-       glScalef(scale, scale, scale);\r
+    glDisable(GL_TEXTURE_2D);
+    glDisable(GL_CULL_FACE);
+       glScalef(scale, scale, scale);
 
        float alpha = 128.0f * scale;
        glColor4ub(alpha*0.4f, alpha*0.7f, alpha, 128);
@@ -93,5 +93,5 @@ void Sierpinski3D::Render(float scale)
        glDepthMask(true);
        glEnable(GL_LIGHTING);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glDisable(GL_BLEND);\r
+       glDisable(GL_BLEND);
 }
index 9afcee0592e4fb72e21a522659df42155e76e613..ced284e6e0f014076b77a6ce25398108711e3d7a 100644 (file)
@@ -1,19 +1,19 @@
-#ifndef INCLUDED_3DSIERPINSKI_GASKET_H\r
-#define INCLUDED_3DSIERPINSKI_GASKET_H\r
-\r
-\r
-class Sierpinski3D\r
-{\r
-public:\r
-       Vector3                 *m_points;\r
-       unsigned int    m_numPoints;\r
-\r
-       Sierpinski3D(unsigned int _numPoints);\r
-       ~Sierpinski3D();\r
-\r
-       void Render(float _scale);\r
-};\r
-\r
-\r
-#endif\r
-\r
+#ifndef INCLUDED_3DSIERPINSKI_GASKET_H
+#define INCLUDED_3DSIERPINSKI_GASKET_H
+
+
+class Sierpinski3D
+{
+public:
+       Vector3                 *m_points;
+       unsigned int    m_numPoints;
+
+       Sierpinski3D(unsigned int _numPoints);
+       ~Sierpinski3D();
+
+       void Render(float _scale);
+};
+
+
+#endif
+
index 16de94730cda1eb5c18b559ebd1ba0ebb7f3a73d..2c165bebb931d5b7ad9110ffaba6b7b313af0cd2 100644 (file)
-#include "lib/universal_include.h"\r
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <shlobj.h>\r
-\r
-#ifdef TARGET_OS_VISTA\r
-#include <knownfolders.h>\r
-#endif\r
-\r
-#include "network/clienttoserver.h"\r
-\r
-#ifdef TARGET_OS_VISTA\r
-#include "lib/poster_maker.h"\r
-#endif\r
-#include "lib/avi_generator.h"\r
-#include "lib/hi_res_time.h"\r
-#include "lib/language_table.h"\r
-#include "lib/mouse_cursor.h"\r
-#include "lib/preferences.h"\r
-#include "lib/profiler.h"\r
-#include "lib/resource.h"\r
-#include "lib/system_info.h"\r
-#include "lib/text_renderer.h"\r
-#include "lib/filesys_utils.h"\r
-#include "lib/bitmap.h"\r
-#include "lib/file_writer.h"\r
-#include "interface/prefs_other_window.h"\r
-\r
-#include "sound/sound_stream_decoder.h"\r
-#include "sound/soundsystem.h"\r
-\r
-#include "app.h"\r
-#include "camera.h"\r
-#include "effect_processor.h"\r
-#include "gesture.h"\r
-#include "global_world.h"\r
-#include "helpsystem.h"\r
-#include "tutorial.h"\r
-#include "keygen.h"\r
-#include "location.h"\r
-#include "location_input.h"\r
-#include "main.h"\r
-#include "particle_system.h"\r
-#include "renderer.h"\r
-#include "script.h"\r
-#include "sepulveda.h"\r
-#include "user_input.h"\r
-#include "taskmanager.h"\r
-#include "taskmanager_interface_gestures.h"\r
-#include "taskmanager_interface_icons.h"\r
-#include "gamecursor.h"\r
-#include "level_file.h"\r
-#include "demoendsequence.h"\r
-#include "attract.h"\r
-#include "control_help.h"\r
-#include "game_menu.h"\r
-\r
-void SetPreferenceOverrides(); // See main.cpp\r
-\r
-App *g_app = NULL;\r
-\r
-\r
-#ifdef DEMO2\r
-    #define GAMEDATAFILE "game_demo2.txt"\r
-#else\r
-    #ifdef DEMOBUILD\r
-        #define GAMEDATAFILE "game_demo.txt"\r
-    #else\r
-        #define GAMEDATAFILE "game.txt"\r
-    #endif\r
-#endif\r
-\r
-\r
-App::App()\r
-:   m_camera(NULL), \r
-    m_location(NULL),\r
-       m_locationId(-1),\r
-    m_server(NULL),\r
-    m_clientToServer(NULL),\r
-    m_renderer(NULL),\r
-    m_userInput(NULL),\r
-    m_profiler(NULL),\r
-    m_resource(NULL),\r
-    m_soundSystem(NULL),\r
-       m_locationInput(NULL),\r
-       m_locationEditor(NULL),\r
-    m_aviGenerator(NULL),\r
-       m_effectProcessor(NULL),\r
-    m_globalWorld(NULL),\r
-    m_helpSystem(NULL),\r
-    m_tutorial(NULL),\r
-       m_particleSystem(NULL),\r
-    m_taskManager(NULL),\r
-    m_gesture(NULL),\r
-    m_script(NULL),\r
-    m_sepulveda(NULL),\r
-    m_testHarness(NULL),\r
-    m_paused(false),\r
-       m_editing(false),\r
-       m_requestedLocationId(-1),\r
-       m_requestToggleEditing(false),\r
-       m_requestQuit(false),\r
-    m_negativeRenderer(false),\r
-       m_difficultyLevel(0),\r
-    m_levelReset(false),\r
-    m_langTable(NULL),\r
-    m_startSequence(NULL),\r
-    m_demoEndSequence(NULL),\r
-       m_largeMenus(false),\r
-       m_attractMode(NULL),\r
-    m_controlHelpSystem(NULL),\r
-    m_atMainMenu(false),\r
-    m_gameMenu(NULL),\r
-    m_gameMode(GameModeNone)\r
-#ifdef TARGET_OS_VISTA\r
-       ,m_thumbnailScreenshot(NULL),\r
-       m_saveThumbnail(false)\r
-#endif\r
-{\r
-    g_app = this;\r
-\r
-       // Load resources\r
-\r
-    m_resource = new Resource();\r
-    m_resource->ParseArchive( "main.dat", NULL );\r
-    m_resource->ParseArchive( "sounds.dat", NULL );\r
-       m_resource->ParseArchive( "patch.dat", NULL );\r
-    m_resource->ParseArchive( "language.dat", NULL );\r
-\r
-       g_prefsManager = new PrefsManager(App::GetPreferencesPath());\r
-       SetPreferenceOverrides();\r
-\r
-    m_bypassNetworking  = g_prefsManager->GetInt("BypassNetwork") ? true : false;\r
-\r
-    m_negativeRenderer  = g_prefsManager->GetInt("RenderNegative", 0) ? true : false;\r
-    if( m_negativeRenderer )    m_backgroundColour.Set(255,255,255,255);\r
-    else                        m_backgroundColour.Set(0,0,0,0);\r
-       \r
-       UpdateDifficultyFromPreferences();\r
-\r
-\r
-#ifdef PROFILER_ENABLED\r
-    m_profiler          = new Profiler();\r
-#endif\r
-\r
-    m_renderer          = new Renderer();\r
-    m_renderer->Initialise();\r
-\r
-       // Make sure that resources are now available - either the .dat files\r
-       // or the data directory must exist\r
-\r
-       SoundStreamDecoder *ssd = m_resource->GetSoundStreamDecoder("sounds/ablaster");\r
-       DarwiniaReleaseAssert(ssd,\r
-               "Couldn't find sound resources. This is probably because\n"\r
-               "sounds.dat isn't in the working directory.");\r
-       delete ssd;\r
-\r
-    int textureId = m_resource->GetTexture("textures/editor_font_normal.bmp");\r
-\r
-    m_gameCursor        = new GameCursor();\r
-    m_soundSystem       = new SoundSystem();\r
-    m_clientToServer    = new ClientToServer();\r
-    m_userInput         = new UserInput();\r
-//    m_location          = new Location();\r
-//    m_locationInput          = new LocationInput();\r
-\r
-\r
-       m_camera            = new Camera();\r
-    m_gameMenu          = new GameMenu();\r
-\r
-    strcpy( m_gameDataFile, "game.txt" );\r
-\r
-\r
-\r
-    //\r
-    // Determine default language if possible\r
-\r
-    char *language = g_prefsManager->GetString("TextLanguage");\r
-    if( stricmp(language, "unknown") == 0 )\r
-    {\r
-        char *defaultLang = g_systemInfo->m_localeInfo.m_language;\r
-        char langFilename[512];\r
-        sprintf( langFilename, "data/language/%s.txt", defaultLang );\r
-        if( DoesFileExist(langFilename) )\r
-        {\r
-            g_prefsManager->SetString( "TextLanguage", defaultLang );\r
-        }\r
-        else\r
-        {\r
-            g_prefsManager->SetString( "TextLanguage", "english" );\r
-        }        \r
-    }\r
-    language = g_prefsManager->GetString("TextLanguage");\r
-\r
-    SetLanguage( language, g_prefsManager->GetInt( "TextLanguageTest", 0 ) );\r
-\r
-\r
-\r
-#ifdef SOUND_EDITOR\r
-       m_effectProcessor   = new EffectProcessor();\r
-#endif // SOUND_EDITOR\r
-\r
-    SetProfileName( g_prefsManager->GetString("UserProfile", "none") );\r
-\r
-#ifdef TARGET_OS_VISTA\r
-    if( strlen( g_saveFile ) > 0 )\r
-    {\r
-        SetProfileName( g_saveFile );\r
-    }\r
-#endif\r
-\r
-    m_helpSystem        = new HelpSystem();\r
-       m_particleSystem        = new ParticleSystem();\r
-    m_taskManager       = new TaskManager();\r
-    m_gesture           = new Gesture("gestures.txt");\r
-    m_sepulveda         = new Sepulveda();\r
-    m_script            = new Script();\r
-#ifdef ATTRACTMODE_ENABLED\r
-       m_attractMode           = new AttractMode();\r
-#endif\r
-    m_controlHelpSystem = new ControlHelpSystem();\r
-\r
-    if( g_prefsManager->GetInt( "ControlMethod" ) == 0 )\r
-    {\r
-        m_taskManagerInterface = new TaskManagerInterfaceGestures();\r
-    }\r
-    else\r
-    {\r
-        m_taskManagerInterface = new TaskManagerInterfaceIcons();\r
-    }\r
-\r
-       m_soundSystem->Initialise();\r
-\r
-#ifdef DEMOBUILD\r
-    #ifdef DEMO2\r
-        m_tutorial = new Demo2Tutorial();\r
-    #else\r
-        m_tutorial = new Demo1Tutorial();\r
-    #endif\r
-#endif\r
-\r
-    int menuOption = g_prefsManager->GetInt( OTHER_LARGEMENUS, 0 );\r
-       if( menuOption == 2 ) // (todo) or is running in media center and tenFootMode == -1\r
-       {\r
-               m_largeMenus = true;\r
-       }\r
-#ifdef TARGET_OS_VISTA\r
-    else if( menuOption == 0 &&\r
-             g_mediaCenter == true )\r
-    {\r
-        m_largeMenus = true;\r
-    }\r
-#endif\r
-\r
-    //\r
-    // Load mods\r
-\r
-    char *modName = g_prefsManager->GetString("Mod", "none" );\r
-    if( stricmp( modName, "none" ) != 0 )\r
-    {\r
-        g_app->m_resource->LoadMod( modName );\r
-    }\r
-\r
-    \r
-    //\r
-    // Load save games\r
-    \r
-    bool profileLoaded = LoadProfile();\r
-}\r
-\r
-App::~App()\r
-{\r
-       SAFE_DELETE(m_globalWorld);\r
-       SAFE_DELETE(m_langTable);\r
-#ifdef DEMOBUILD\r
-       SAFE_DELETE(m_tutorial);\r
-#endif\r
-       SAFE_DELETE(m_taskManagerInterface);\r
-       SAFE_DELETE(m_controlHelpSystem);\r
-#ifdef ATTRACTMODE_ENABLED\r
-       SAFE_DELETE(m_attractMode);\r
-#endif\r
-       SAFE_DELETE(m_script);\r
-       SAFE_DELETE(m_sepulveda);\r
-       SAFE_DELETE(m_gesture);\r
-       SAFE_DELETE(m_taskManager);\r
-       SAFE_DELETE(m_particleSystem);\r
-       SAFE_DELETE(m_helpSystem);\r
-#ifdef SOUND_EDITOR\r
-       SAFE_DELETE(m_effectProcessor);\r
-#endif // SOUND_EDITOR\r
-       SAFE_DELETE(m_camera);\r
-       SAFE_DELETE(m_userInput);\r
-       SAFE_DELETE(m_clientToServer);\r
-       SAFE_DELETE(m_soundSystem);\r
-       SAFE_DELETE(m_gameCursor);\r
-       SAFE_DELETE(m_renderer);\r
-#ifdef PROFILER_ENABLED\r
-       SAFE_DELETE(m_profiler);\r
-#endif\r
-       SAFE_DELETE(g_prefsManager);\r
-       SAFE_DELETE(m_resource);\r
-}\r
-\r
-void App::UpdateDifficultyFromPreferences()\r
-{\r
-       // This method is called to make sure that the difficulty setting\r
-       // used to control the game play (g_app->m_difficultyLevel) is \r
-       // consistent with the user preferences. \r
-       \r
-       // Preferences value is 1-based, m_difficultyLevel is 0-based.\r
-       m_difficultyLevel = g_prefsManager->GetInt(OTHER_DIFFICULTY, 1) - 1;\r
-       if( m_difficultyLevel < 0 )     \r
-       {\r
-               m_difficultyLevel = 0;\r
-       }\r
-}\r
-\r
-\r
-void App::SetLanguage( char *_language, bool _test )\r
-{\r
-    //\r
-    // Delete existing language data\r
-\r
-    if( m_langTable )\r
-    {\r
-        delete m_langTable;\r
-        m_langTable = NULL;\r
-    }\r
-\r
-\r
-    //\r
-    // Load the language text file\r
-\r
-    char langFilename[256];\r
-#if defined(TARGET_OS_LINUX) && defined(TARGET_DEMOGAME)\r
-       sprintf( langFilename, "language/%s_demo.txt", _language );\r
-#else\r
-    sprintf( langFilename, "language/%s.txt", _language );\r
-#endif\r
-\r
-       m_langTable = new LangTable(langFilename);\r
-    \r
-    if( _test )\r
-    {\r
-        m_langTable->TestAgainstEnglish();\r
-    }\r
-\r
-    //\r
-    // Load the MOD language file if it exists\r
-\r
-    sprintf( langFilename, "strings_%s.txt", _language );\r
-    TextReader *modLangFile = g_app->m_resource->GetTextReader(langFilename);\r
-    if( !modLangFile )\r
-    {\r
-        sprintf( langFilename, "strings_default.txt" );\r
-        modLangFile = g_app->m_resource->GetTextReader(langFilename);\r
-    }\r
-\r
-    if( modLangFile )\r
-    {\r
-        delete modLangFile;\r
-        m_langTable->ParseLanguageFile( langFilename );\r
-    }\r
-\r
-    //\r
-    // Load localised fonts if they exist\r
-       \r
-    char fontFilename[256];\r
-    sprintf( fontFilename, "textures/speccy_font_%s.bmp", _language );\r
-    if( !g_app->m_resource->DoesTextureExist( fontFilename ) )\r
-    {\r
-        sprintf( fontFilename, "textures/speccy_font_normal.bmp" );\r
-    }\r
-    g_gameFont.Initialise( fontFilename );\r
-\r
-\r
-    sprintf( fontFilename, "textures/editor_font_%s.bmp", _language );\r
-    if( !g_app->m_resource->DoesTextureExist( fontFilename ) )\r
-    {\r
-        sprintf( fontFilename, "textures/editor_font_normal.bmp" );\r
-    }\r
-    g_editorFont.Initialise( fontFilename );\r
-\r
-       if ( g_inputManager )\r
-               m_langTable->RebuildTables();\r
-}\r
-\r
-\r
-void App::SetProfileName( char *_profileName )\r
-{\r
-    strcpy( m_userProfileName, _profileName );\r
-\r
-       if( stricmp( _profileName, "AttractMode" ) != 0 )\r
-       {\r
-               g_prefsManager->SetString( "UserProfile", m_userProfileName );\r
-               g_prefsManager->Save();\r
-       }\r
-}\r
-\r
-\r
-#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOSX)\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#endif \r
-\r
-const char *App::GetProfileDirectory()\r
-{\r
-#if defined(TARGET_OS_LINUX)\r
-       \r
-       static char userdir[256];\r
-       const char *home = getenv("HOME");\r
-       if (home != NULL) {\r
-               sprintf(userdir, "%s/.darwinia", home);\r
-               mkdir(userdir, 0777);\r
-\r
-               sprintf(userdir, "%s/.darwinia/%s/", home, DARWINIA_GAMETYPE);\r
-               mkdir(userdir, 0777);\r
-               return userdir;\r
-       }\r
-       else // Current directory if no home\r
-               return "";\r
-               \r
-#elif defined(TARGET_OS_MACOSX) \r
-       \r
-       static char userdir[256];\r
-       const char *home = getenv("HOME");\r
-       if (home != NULL) {\r
-               sprintf(userdir, "%s/Library", home);\r
-               mkdir(userdir, 0777);\r
-               \r
-               sprintf(userdir, "%s/Library/Application Support", home);\r
-               mkdir(userdir, 0777);\r
-\r
-               sprintf(userdir, "%s/Library/Application Support/Darwinia", home);\r
-               mkdir(userdir, 0777);\r
-\r
-               sprintf(userdir, "%s/Library/Application Support/Darwinia/%s/", \r
-                               home, DARWINIA_GAMETYPE);\r
-               mkdir(userdir, 0777);\r
-\r
-               return userdir;\r
-       }\r
-       else // Current directory if no home\r
-               return "";\r
-\r
-#else\r
-#ifdef TARGET_OS_VISTA\r
-    if( IsRunningVista() )\r
-    {\r
-        static char userdir[256];    \r
-\r
-               PWSTR path;\r
-               SHGetKnownFolderPath( FOLDERID_SavedGames, 0, NULL, &path );\r
-               wcstombs( userdir, path, sizeof(userdir) );             \r
-               CoTaskMemFree( path );\r
-\r
-#ifdef TARGET_VISTA_DEMO2\r
-               const char *subdir = "\\Darwinia Demo 2\\";\r
-#else\r
-               const char *subdir = "\\Darwinia\\";\r
-#endif\r
-        strncat(userdir, subdir, sizeof(userdir) );\r
-        CreateDirectory( userdir );\r
-\r
-        return userdir;\r
-    }\r
-    else\r
-#endif // TARGET_OS_VISTA\r
-       {\r
-        return "";\r
-    }  \r
-#endif\r
-}\r
-\r
-const char *App::GetPreferencesPath()\r
-{\r
-       // good leak #1\r
-       static char *path = NULL;\r
-\r
-       if (path == NULL) {\r
-               const char *profileDir = GetProfileDirectory();\r
-               path = new char[strlen(profileDir) + 32];\r
-               sprintf( path, "%spreferences.txt", profileDir );\r
-       }\r
-\r
-       return path;\r
-}\r
-\r
-const char *App::GetScreenshotDirectory()\r
-{\r
-#ifdef TARGET_OS_VISTA\r
-    static char dir[MAX_PATH];\r
-    SHGetFolderPath( NULL, CSIDL_DESKTOP, NULL, SHGFP_TYPE_CURRENT, dir );\r
-    sprintf( dir, "%s\\", dir );\r
-    return dir;\r
-#else\r
-    return "";\r
-#endif\r
-}\r
-\r
-bool App::LoadProfile()\r
-{    \r
-    DebugOut( "Loading profile %s\n", m_userProfileName );\r
-\r
-    if( (stricmp( m_userProfileName, "AccessAllAreas" ) == 0 ||\r
-               stricmp( m_userProfileName, "AttractMode" ) == 0 ) && \r
-        g_app->m_gameMode != GameModePrologue )\r
-    {\r
-        // Cheat username that opens all locations\r
-        // aimed at beta testers who've completed the game already\r
-\r
-        if( m_globalWorld )\r
-        {\r
-            delete m_globalWorld;\r
-            m_globalWorld = NULL;\r
-        }\r
-    \r
-        m_globalWorld = new GlobalWorld();\r
-        m_globalWorld->LoadGame( "game_unlockall.txt" );\r
-        for( int i = 0; i < m_globalWorld->m_buildings.Size(); ++i )\r
-        {\r
-            GlobalBuilding *building = m_globalWorld->m_buildings[i];\r
-            if( building && building->m_type == Building::TypeTrunkPort )\r
-            {\r
-                building->m_online = true;\r
-            }\r
-        }\r
-        for( int i = 0; i < m_globalWorld->m_locations.Size(); ++i )\r
-        {\r
-            GlobalLocation *loc = m_globalWorld->m_locations[i];\r
-            loc->m_available = true;\r
-        }        \r
-    }\r
-    else\r
-    {\r
-        if( m_globalWorld )\r
-        {\r
-            delete m_globalWorld;\r
-            m_globalWorld = NULL;\r
-        }\r
-    \r
-        m_globalWorld = new GlobalWorld();\r
-        m_globalWorld->LoadGame( m_gameDataFile );    \r
-    }\r
-\r
-    return true;\r
-}\r
-\r
-bool App::SaveProfile( bool _global, bool _local )\r
-{\r
-    if( stricmp( m_userProfileName, "none" ) == 0 ) return false;\r
-    if( stricmp( m_userProfileName, "AccessAllAreas" ) == 0 ) return false;\r
-       if( stricmp( m_userProfileName, "AttractMode" ) == 0 ) return false;\r
-\r
-    DebugOut( "Saving profile %s\n", m_userProfileName );\r
-\r
-    char folderName[512];\r
-    sprintf( folderName, "%susers/", GetProfileDirectory() );\r
-    bool success = CreateDirectory( folderName );        \r
-    if( !success ) \r
-    {\r
-        DebugOut( "failed to create folder %s\n", folderName );\r
-        return false;\r
-    }\r
-\r
-    sprintf( folderName, "%susers/%s", GetProfileDirectory(), m_userProfileName );\r
-    success = CreateDirectory( folderName );\r
-    if( !success ) \r
-    {\r
-        DebugOut( "failed to create folder %s\n", folderName );\r
-        return false;\r
-    }\r
-\r
-#ifdef TARGET_OS_VISTA\r
-       if( _global )\r
-       {\r
-               SaveRichHeader();\r
-       }\r
-#endif\r
-\r
-    if( _global )\r
-    {\r
-        m_globalWorld->SaveGame( m_gameDataFile );\r
-        DebugOut( "Saved global data for profile %s\n", m_userProfileName );\r
-    }\r
-\r
-    if( _local && g_app->m_location )\r
-    {\r
-        if( m_levelReset )\r
-        {\r
-            m_levelReset = false;\r
-            return false;\r
-        }\r
-        \r
-        g_app->m_location->m_levelFile->GenerateInstantUnits();\r
-        g_app->m_location->m_levelFile->GenerateDynamicBuildings();\r
-        char *missionFilename = m_location->m_levelFile->m_missionFilename;\r
-        m_location->m_levelFile->SaveMissionFile( missionFilename );\r
-        DebugOut( "Saved level %s for profile %s\n", missionFilename, m_userProfileName );\r
-    }\r
-    return true;\r
-}\r
-\r
-\r
-void App::ResetLevel( bool _global )\r
-{\r
-    if( m_location )\r
-    {\r
-        m_requestedLocationId = -1;\r
-           m_requestedMission[0] = '\0';\r
-           m_requestedMap[0] = '\0';\r
-\r
-        if( g_app->m_tutorial ) g_app->m_tutorial->Restart();\r
-        \r
-\r
-        //\r
-        // Delete the saved mission file\r
-\r
-        char *missionFilename = m_location->m_levelFile->m_missionFilename;\r
-        char saveFilename[256];\r
-        sprintf( saveFilename, "%susers/%s/%s", GetProfileDirectory(), m_userProfileName, missionFilename );\r
-    \r
-        DeleteThisFile( saveFilename );\r
-\r
-        m_levelReset = true;\r
-\r
-\r
-        //\r
-        // Delete the game file if required\r
-\r
-        if( _global )\r
-        {\r
-            sprintf( saveFilename, "%susers/%s/%s", GetProfileDirectory(), m_userProfileName, m_gameDataFile );\r
-\r
-            DeleteThisFile( saveFilename );\r
-\r
-            if( m_globalWorld )\r
-            {\r
-                delete m_globalWorld;\r
-                m_globalWorld = NULL;\r
-            }\r
-    \r
-            m_globalWorld = new GlobalWorld();\r
-            m_globalWorld->LoadGame( m_gameDataFile );     \r
-        }\r
-    }    \r
-}\r
-\r
-bool App::HasBoughtGame()\r
-{\r
-#if defined(DEMOBUILD)\r
-       return false;\r
-#else\r
-       return true;\r
-#endif\r
-}\r
-\r
-void App::LoadPrologue()\r
-{\r
-    m_gameMode = App::GameModePrologue;\r
-\r
-    m_soundSystem->StopAllSounds(WorldObjectId(), "Music");\r
-\r
-    strcpy( m_gameDataFile, "game_demo2.txt" );\r
-    LoadProfile();\r
-\r
-    m_requestedLocationId = m_globalWorld->GetLocationId("launchpad");\r
-    GlobalLocation *gloc = m_globalWorld->GetLocation(m_requestedLocationId);\r
-    strcpy(m_requestedMap, gloc->m_mapFilename);\r
-    strcpy(m_requestedMission, gloc->m_missionFilename);\r
-\r
-    m_tutorial = new Demo2Tutorial();\r
-\r
-    m_atMainMenu = false;\r
-\r
-    g_prefsManager->SetInt( "RenderSpecialLighting", 1 );\r
-       g_prefsManager->SetInt( "CurrentGameMode", 0 );\r
-       g_prefsManager->Save();\r
-}\r
-\r
-void App::LoadCampaign()\r
-{\r
-    if( m_tutorial )\r
-    {\r
-        delete m_tutorial;\r
-        m_tutorial = NULL;\r
-    }\r
-\r
-    m_soundSystem->StopAllSounds(WorldObjectId(), "Music");\r
-\r
-    //m_atMainMenu = false;\r
-\r
-    strcpy( m_gameDataFile, "game.txt" );\r
-    LoadProfile();\r
-    m_gameMode = App::GameModeCampaign;\r
-    m_requestedLocationId = -1;  \r
-    g_prefsManager->SetInt( "RenderSpecialLighting", 0 );\r
-    g_prefsManager->SetInt( "CurrentGameMode", 1 );\r
-    g_prefsManager->Save();\r
-}\r
-\r
-#ifdef TARGET_OS_VISTA\r
-void App::SaveRichHeader()\r
-{\r
-       if( g_app->m_editing ) return;\r
-       if( !m_thumbnailScreenshot ) return;\r
-\r
-       char _filename[256];\r
-       sprintf( _filename, "%s.dsg", m_userProfileName );\r
-\r
-       char fullFilename[256];\r
-    sprintf( fullFilename, "%susers/%s", g_app->GetProfileDirectory(), _filename );        \r
-\r
-       RICH_GAME_MEDIA_HEADER header;\r
-       ZeroMemory( &header, sizeof(RICH_GAME_MEDIA_HEADER) );\r
-       header.dwMagicNumber = RM_MAGICNUMBER;\r
-       header.dwHeaderVersion = 1;\r
-       header.dwHeaderSize = sizeof(RICH_GAME_MEDIA_HEADER);\r
-       header.liThumbnailOffset.QuadPart = 0;\r
-       if( m_thumbnailScreenshot )\r
-       {\r
-               unsigned int size = (m_thumbnailScreenshot->m_height * m_thumbnailScreenshot->m_width * 3 ) + 54;\r
-               header.dwThumbnailSize = size;\r
-       }\r
-       else\r
-       {\r
-               header.dwThumbnailSize = 0;\r
-       }\r
-\r
-       header.guidGameId.Data1 = 0xF58175C7;\r
-       header.guidGameId.Data2 = 0xE99C;\r
-       header.guidGameId.Data3 = 0x4151;\r
-\r
-       header.guidGameId.Data4[0] = 0x80;\r
-       header.guidGameId.Data4[1] = 0x0D;\r
-       header.guidGameId.Data4[2] = 0x7B;\r
-       header.guidGameId.Data4[3] = 0xB5;\r
-       header.guidGameId.Data4[4] = 0xE8;\r
-       header.guidGameId.Data4[5] = 0x9E;\r
-       header.guidGameId.Data4[6] = 0x49;\r
-       header.guidGameId.Data4[7] = 0x60;\r
-\r
-       WCHAR saveName[256];\r
-       char filePath[256];\r
-       sprintf( filePath, "%susers\\%s.dsg", GetProfileDirectory(), m_userProfileName );\r
-\r
-       mbstowcs( saveName, filePath, 256 );\r
-\r
-       wcscpy(header.szGameName,  L"Darwinia");\r
-       wcscpy(header.szSaveName, saveName );\r
-       wcscpy(header.szLevelName, L"");\r
-       wcscpy(header.szComments, L"");\r
-\r
-       FILE *file = fopen(fullFilename, "wb");\r
-       fwrite( &header, sizeof(RICH_GAME_MEDIA_HEADER), 1, file );\r
-\r
-       m_thumbnailScreenshot->WritePng( file );\r
-       // m_thumbnailScreenshot->SavePng( "ss.bmp" );\r
-       delete m_thumbnailScreenshot;\r
-       m_thumbnailScreenshot = NULL;\r
-\r
-       fclose(file);\r
-\r
-}\r
-\r
-void App::SaveThumbnailScreenshot()\r
-{\r
-       PosterMaker pm(g_app->m_renderer->ScreenW(), g_app->m_renderer->ScreenH());\r
-       pm.AddFrame();\r
-\r
-       float newWidth = 256.0f;\r
-       float newHeight = 192.0f;\r
-\r
-       BitmapRGBA scaled(newWidth, newHeight );\r
-\r
-       scaled.Blit(0, 0, pm.GetBitmap()->m_width, pm.GetBitmap()->m_height, pm.GetBitmap(), \r
-                                                          0, 0, newWidth, newHeight, true);\r
-\r
-       m_thumbnailScreenshot = new BitmapRGBA( scaled );\r
-\r
-       m_saveThumbnail = false;\r
-}\r
-\r
-#endif\r
+#include "lib/universal_include.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <shlobj.h>
+
+#ifdef TARGET_OS_VISTA
+#include <knownfolders.h>
+#endif
+
+#include "network/clienttoserver.h"
+
+#ifdef TARGET_OS_VISTA
+#include "lib/poster_maker.h"
+#endif
+#include "lib/avi_generator.h"
+#include "lib/hi_res_time.h"
+#include "lib/language_table.h"
+#include "lib/mouse_cursor.h"
+#include "lib/preferences.h"
+#include "lib/profiler.h"
+#include "lib/resource.h"
+#include "lib/system_info.h"
+#include "lib/text_renderer.h"
+#include "lib/filesys_utils.h"
+#include "lib/bitmap.h"
+#include "lib/file_writer.h"
+#include "interface/prefs_other_window.h"
+
+#include "sound/sound_stream_decoder.h"
+#include "sound/soundsystem.h"
+
+#include "app.h"
+#include "camera.h"
+#include "effect_processor.h"
+#include "gesture.h"
+#include "global_world.h"
+#include "helpsystem.h"
+#include "tutorial.h"
+#include "keygen.h"
+#include "location.h"
+#include "location_input.h"
+#include "main.h"
+#include "particle_system.h"
+#include "renderer.h"
+#include "script.h"
+#include "sepulveda.h"
+#include "user_input.h"
+#include "taskmanager.h"
+#include "taskmanager_interface_gestures.h"
+#include "taskmanager_interface_icons.h"
+#include "gamecursor.h"
+#include "level_file.h"
+#include "demoendsequence.h"
+#include "attract.h"
+#include "control_help.h"
+#include "game_menu.h"
+
+void SetPreferenceOverrides(); // See main.cpp
+
+App *g_app = NULL;
+
+
+#ifdef DEMO2
+    #define GAMEDATAFILE "game_demo2.txt"
+#else
+    #ifdef DEMOBUILD
+        #define GAMEDATAFILE "game_demo.txt"
+    #else
+        #define GAMEDATAFILE "game.txt"
+    #endif
+#endif
+
+
+App::App()
+:   m_camera(NULL), 
+    m_location(NULL),
+       m_locationId(-1),
+    m_server(NULL),
+    m_clientToServer(NULL),
+    m_renderer(NULL),
+    m_userInput(NULL),
+    m_profiler(NULL),
+    m_resource(NULL),
+    m_soundSystem(NULL),
+       m_locationInput(NULL),
+       m_locationEditor(NULL),
+    m_aviGenerator(NULL),
+       m_effectProcessor(NULL),
+    m_globalWorld(NULL),
+    m_helpSystem(NULL),
+    m_tutorial(NULL),
+       m_particleSystem(NULL),
+    m_taskManager(NULL),
+    m_gesture(NULL),
+    m_script(NULL),
+    m_sepulveda(NULL),
+    m_testHarness(NULL),
+    m_paused(false),
+       m_editing(false),
+       m_requestedLocationId(-1),
+       m_requestToggleEditing(false),
+       m_requestQuit(false),
+    m_negativeRenderer(false),
+       m_difficultyLevel(0),
+    m_levelReset(false),
+    m_langTable(NULL),
+    m_startSequence(NULL),
+    m_demoEndSequence(NULL),
+       m_largeMenus(false),
+       m_attractMode(NULL),
+    m_controlHelpSystem(NULL),
+    m_atMainMenu(false),
+    m_gameMenu(NULL),
+    m_gameMode(GameModeNone)
+#ifdef TARGET_OS_VISTA
+       ,m_thumbnailScreenshot(NULL),
+       m_saveThumbnail(false)
+#endif
+{
+    g_app = this;
+
+       // Load resources
+
+    m_resource = new Resource();
+    m_resource->ParseArchive( "main.dat", NULL );
+    m_resource->ParseArchive( "sounds.dat", NULL );
+       m_resource->ParseArchive( "patch.dat", NULL );
+    m_resource->ParseArchive( "language.dat", NULL );
+
+       g_prefsManager = new PrefsManager(App::GetPreferencesPath());
+       SetPreferenceOverrides();
+
+    m_bypassNetworking  = g_prefsManager->GetInt("BypassNetwork") ? true : false;
+
+    m_negativeRenderer  = g_prefsManager->GetInt("RenderNegative", 0) ? true : false;
+    if( m_negativeRenderer )    m_backgroundColour.Set(255,255,255,255);
+    else                        m_backgroundColour.Set(0,0,0,0);
+       
+       UpdateDifficultyFromPreferences();
+
+
+#ifdef PROFILER_ENABLED
+    m_profiler          = new Profiler();
+#endif
+
+    m_renderer          = new Renderer();
+    m_renderer->Initialise();
+
+       // Make sure that resources are now available - either the .dat files
+       // or the data directory must exist
+
+       SoundStreamDecoder *ssd = m_resource->GetSoundStreamDecoder("sounds/ablaster");
+       DarwiniaReleaseAssert(ssd,
+               "Couldn't find sound resources. This is probably because\n"
+               "sounds.dat isn't in the working directory.");
+       delete ssd;
+
+    int textureId = m_resource->GetTexture("textures/editor_font_normal.bmp");
+
+    m_gameCursor        = new GameCursor();
+    m_soundSystem       = new SoundSystem();
+    m_clientToServer    = new ClientToServer();
+    m_userInput         = new UserInput();
+//    m_location          = new Location();
+//    m_locationInput          = new LocationInput();
+
+
+       m_camera            = new Camera();
+    m_gameMenu          = new GameMenu();
+
+    strcpy( m_gameDataFile, "game.txt" );
+
+
+
+    //
+    // Determine default language if possible
+
+    char *language = g_prefsManager->GetString("TextLanguage");
+    if( stricmp(language, "unknown") == 0 )
+    {
+        char *defaultLang = g_systemInfo->m_localeInfo.m_language;
+        char langFilename[512];
+        sprintf( langFilename, "data/language/%s.txt", defaultLang );
+        if( DoesFileExist(langFilename) )
+        {
+            g_prefsManager->SetString( "TextLanguage", defaultLang );
+        }
+        else
+        {
+            g_prefsManager->SetString( "TextLanguage", "english" );
+        }        
+    }
+    language = g_prefsManager->GetString("TextLanguage");
+
+    SetLanguage( language, g_prefsManager->GetInt( "TextLanguageTest", 0 ) );
+
+
+
+#ifdef SOUND_EDITOR
+       m_effectProcessor   = new EffectProcessor();
+#endif // SOUND_EDITOR
+
+    SetProfileName( g_prefsManager->GetString("UserProfile", "none") );
+
+#ifdef TARGET_OS_VISTA
+    if( strlen( g_saveFile ) > 0 )
+    {
+        SetProfileName( g_saveFile );
+    }
+#endif
+
+    m_helpSystem        = new HelpSystem();
+       m_particleSystem        = new ParticleSystem();
+    m_taskManager       = new TaskManager();
+    m_gesture           = new Gesture("gestures.txt");
+    m_sepulveda         = new Sepulveda();
+    m_script            = new Script();
+#ifdef ATTRACTMODE_ENABLED
+       m_attractMode           = new AttractMode();
+#endif
+    m_controlHelpSystem = new ControlHelpSystem();
+
+    if( g_prefsManager->GetInt( "ControlMethod" ) == 0 )
+    {
+        m_taskManagerInterface = new TaskManagerInterfaceGestures();
+    }
+    else
+    {
+        m_taskManagerInterface = new TaskManagerInterfaceIcons();
+    }
+
+       m_soundSystem->Initialise();
+
+#ifdef DEMOBUILD
+    #ifdef DEMO2
+        m_tutorial = new Demo2Tutorial();
+    #else
+        m_tutorial = new Demo1Tutorial();
+    #endif
+#endif
+
+    int menuOption = g_prefsManager->GetInt( OTHER_LARGEMENUS, 0 );
+       if( menuOption == 2 ) // (todo) or is running in media center and tenFootMode == -1
+       {
+               m_largeMenus = true;
+       }
+#ifdef TARGET_OS_VISTA
+    else if( menuOption == 0 &&
+             g_mediaCenter == true )
+    {
+        m_largeMenus = true;
+    }
+#endif
+
+    //
+    // Load mods
+
+    char *modName = g_prefsManager->GetString("Mod", "none" );
+    if( stricmp( modName, "none" ) != 0 )
+    {
+        g_app->m_resource->LoadMod( modName );
+    }
+
+    
+    //
+    // Load save games
+    
+    bool profileLoaded = LoadProfile();
+}
+
+App::~App()
+{
+       SAFE_DELETE(m_globalWorld);
+       SAFE_DELETE(m_langTable);
+#ifdef DEMOBUILD
+       SAFE_DELETE(m_tutorial);
+#endif
+       SAFE_DELETE(m_taskManagerInterface);
+       SAFE_DELETE(m_controlHelpSystem);
+#ifdef ATTRACTMODE_ENABLED
+       SAFE_DELETE(m_attractMode);
+#endif
+       SAFE_DELETE(m_script);
+       SAFE_DELETE(m_sepulveda);
+       SAFE_DELETE(m_gesture);
+       SAFE_DELETE(m_taskManager);
+       SAFE_DELETE(m_particleSystem);
+       SAFE_DELETE(m_helpSystem);
+#ifdef SOUND_EDITOR
+       SAFE_DELETE(m_effectProcessor);
+#endif // SOUND_EDITOR
+       SAFE_DELETE(m_camera);
+       SAFE_DELETE(m_userInput);
+       SAFE_DELETE(m_clientToServer);
+       SAFE_DELETE(m_soundSystem);
+       SAFE_DELETE(m_gameCursor);
+       SAFE_DELETE(m_renderer);
+#ifdef PROFILER_ENABLED
+       SAFE_DELETE(m_profiler);
+#endif
+       SAFE_DELETE(g_prefsManager);
+       SAFE_DELETE(m_resource);
+}
+
+void App::UpdateDifficultyFromPreferences()
+{
+       // This method is called to make sure that the difficulty setting
+       // used to control the game play (g_app->m_difficultyLevel) is 
+       // consistent with the user preferences. 
+       
+       // Preferences value is 1-based, m_difficultyLevel is 0-based.
+       m_difficultyLevel = g_prefsManager->GetInt(OTHER_DIFFICULTY, 1) - 1;
+       if( m_difficultyLevel < 0 )     
+       {
+               m_difficultyLevel = 0;
+       }
+}
+
+
+void App::SetLanguage( char *_language, bool _test )
+{
+    //
+    // Delete existing language data
+
+    if( m_langTable )
+    {
+        delete m_langTable;
+        m_langTable = NULL;
+    }
+
+
+    //
+    // Load the language text file
+
+    char langFilename[256];
+#if defined(TARGET_OS_LINUX) && defined(TARGET_DEMOGAME)
+       sprintf( langFilename, "language/%s_demo.txt", _language );
+#else
+    sprintf( langFilename, "language/%s.txt", _language );
+#endif
+
+       m_langTable = new LangTable(langFilename);
+    
+    if( _test )
+    {
+        m_langTable->TestAgainstEnglish();
+    }
+
+    //
+    // Load the MOD language file if it exists
+
+    sprintf( langFilename, "strings_%s.txt", _language );
+    TextReader *modLangFile = g_app->m_resource->GetTextReader(langFilename);
+    if( !modLangFile )
+    {
+        sprintf( langFilename, "strings_default.txt" );
+        modLangFile = g_app->m_resource->GetTextReader(langFilename);
+    }
+
+    if( modLangFile )
+    {
+        delete modLangFile;
+        m_langTable->ParseLanguageFile( langFilename );
+    }
+
+    //
+    // Load localised fonts if they exist
+       
+    char fontFilename[256];
+    sprintf( fontFilename, "textures/speccy_font_%s.bmp", _language );
+    if( !g_app->m_resource->DoesTextureExist( fontFilename ) )
+    {
+        sprintf( fontFilename, "textures/speccy_font_normal.bmp" );
+    }
+    g_gameFont.Initialise( fontFilename );
+
+
+    sprintf( fontFilename, "textures/editor_font_%s.bmp", _language );
+    if( !g_app->m_resource->DoesTextureExist( fontFilename ) )
+    {
+        sprintf( fontFilename, "textures/editor_font_normal.bmp" );
+    }
+    g_editorFont.Initialise( fontFilename );
+
+       if ( g_inputManager )
+               m_langTable->RebuildTables();
+}
+
+
+void App::SetProfileName( char *_profileName )
+{
+    strcpy( m_userProfileName, _profileName );
+
+       if( stricmp( _profileName, "AttractMode" ) != 0 )
+       {
+               g_prefsManager->SetString( "UserProfile", m_userProfileName );
+               g_prefsManager->Save();
+       }
+}
+
+
+#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOSX)
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif 
+
+const char *App::GetProfileDirectory()
+{
+#if defined(TARGET_OS_LINUX)
+       
+       static char userdir[256];
+       const char *home = getenv("HOME");
+       if (home != NULL) {
+               sprintf(userdir, "%s/.darwinia", home);
+               mkdir(userdir, 0777);
+
+               sprintf(userdir, "%s/.darwinia/%s/", home, DARWINIA_GAMETYPE);
+               mkdir(userdir, 0777);
+               return userdir;
+       }
+       else // Current directory if no home
+               return "";
+               
+#elif defined(TARGET_OS_MACOSX) 
+       
+       static char userdir[256];
+       const char *home = getenv("HOME");
+       if (home != NULL) {
+               sprintf(userdir, "%s/Library", home);
+               mkdir(userdir, 0777);
+               
+               sprintf(userdir, "%s/Library/Application Support", home);
+               mkdir(userdir, 0777);
+
+               sprintf(userdir, "%s/Library/Application Support/Darwinia", home);
+               mkdir(userdir, 0777);
+
+               sprintf(userdir, "%s/Library/Application Support/Darwinia/%s/", 
+                               home, DARWINIA_GAMETYPE);
+               mkdir(userdir, 0777);
+
+               return userdir;
+       }
+       else // Current directory if no home
+               return "";
+
+#else
+#ifdef TARGET_OS_VISTA
+    if( IsRunningVista() )
+    {
+        static char userdir[256];    
+
+               PWSTR path;
+               SHGetKnownFolderPath( FOLDERID_SavedGames, 0, NULL, &path );
+               wcstombs( userdir, path, sizeof(userdir) );             
+               CoTaskMemFree( path );
+
+#ifdef TARGET_VISTA_DEMO2
+               const char *subdir = "\\Darwinia Demo 2\\";
+#else
+               const char *subdir = "\\Darwinia\\";
+#endif
+        strncat(userdir, subdir, sizeof(userdir) );
+        CreateDirectory( userdir );
+
+        return userdir;
+    }
+    else
+#endif // TARGET_OS_VISTA
+       {
+        return "";
+    }  
+#endif
+}
+
+const char *App::GetPreferencesPath()
+{
+       // good leak #1
+       static char *path = NULL;
+
+       if (path == NULL) {
+               const char *profileDir = GetProfileDirectory();
+               path = new char[strlen(profileDir) + 32];
+               sprintf( path, "%spreferences.txt", profileDir );
+       }
+
+       return path;
+}
+
+const char *App::GetScreenshotDirectory()
+{
+#ifdef TARGET_OS_VISTA
+    static char dir[MAX_PATH];
+    SHGetFolderPath( NULL, CSIDL_DESKTOP, NULL, SHGFP_TYPE_CURRENT, dir );
+    sprintf( dir, "%s\\", dir );
+    return dir;
+#else
+    return "";
+#endif
+}
+
+bool App::LoadProfile()
+{    
+    DebugOut( "Loading profile %s\n", m_userProfileName );
+
+    if( (stricmp( m_userProfileName, "AccessAllAreas" ) == 0 ||
+               stricmp( m_userProfileName, "AttractMode" ) == 0 ) && 
+        g_app->m_gameMode != GameModePrologue )
+    {
+        // Cheat username that opens all locations
+        // aimed at beta testers who've completed the game already
+
+        if( m_globalWorld )
+        {
+            delete m_globalWorld;
+            m_globalWorld = NULL;
+        }
+    
+        m_globalWorld = new GlobalWorld();
+        m_globalWorld->LoadGame( "game_unlockall.txt" );
+        for( int i = 0; i < m_globalWorld->m_buildings.Size(); ++i )
+        {
+            GlobalBuilding *building = m_globalWorld->m_buildings[i];
+            if( building && building->m_type == Building::TypeTrunkPort )
+            {
+                building->m_online = true;
+            }
+        }
+        for( int i = 0; i < m_globalWorld->m_locations.Size(); ++i )
+        {
+            GlobalLocation *loc = m_globalWorld->m_locations[i];
+            loc->m_available = true;
+        }        
+    }
+    else
+    {
+        if( m_globalWorld )
+        {
+            delete m_globalWorld;
+            m_globalWorld = NULL;
+        }
+    
+        m_globalWorld = new GlobalWorld();
+        m_globalWorld->LoadGame( m_gameDataFile );    
+    }
+
+    return true;
+}
+
+bool App::SaveProfile( bool _global, bool _local )
+{
+    if( stricmp( m_userProfileName, "none" ) == 0 ) return false;
+    if( stricmp( m_userProfileName, "AccessAllAreas" ) == 0 ) return false;
+       if( stricmp( m_userProfileName, "AttractMode" ) == 0 ) return false;
+
+    DebugOut( "Saving profile %s\n", m_userProfileName );
+
+    char folderName[512];
+    sprintf( folderName, "%susers/", GetProfileDirectory() );
+    bool success = CreateDirectory( folderName );        
+    if( !success ) 
+    {
+        DebugOut( "failed to create folder %s\n", folderName );
+        return false;
+    }
+
+    sprintf( folderName, "%susers/%s", GetProfileDirectory(), m_userProfileName );
+    success = CreateDirectory( folderName );
+    if( !success ) 
+    {
+        DebugOut( "failed to create folder %s\n", folderName );
+        return false;
+    }
+
+#ifdef TARGET_OS_VISTA
+       if( _global )
+       {
+               SaveRichHeader();
+       }
+#endif
+
+    if( _global )
+    {
+        m_globalWorld->SaveGame( m_gameDataFile );
+        DebugOut( "Saved global data for profile %s\n", m_userProfileName );
+    }
+
+    if( _local && g_app->m_location )
+    {
+        if( m_levelReset )
+        {
+            m_levelReset = false;
+            return false;
+        }
+        
+        g_app->m_location->m_levelFile->GenerateInstantUnits();
+        g_app->m_location->m_levelFile->GenerateDynamicBuildings();
+        char *missionFilename = m_location->m_levelFile->m_missionFilename;
+        m_location->m_levelFile->SaveMissionFile( missionFilename );
+        DebugOut( "Saved level %s for profile %s\n", missionFilename, m_userProfileName );
+    }
+    return true;
+}
+
+
+void App::ResetLevel( bool _global )
+{
+    if( m_location )
+    {
+        m_requestedLocationId = -1;
+           m_requestedMission[0] = '\0';
+           m_requestedMap[0] = '\0';
+
+        if( g_app->m_tutorial ) g_app->m_tutorial->Restart();
+        
+
+        //
+        // Delete the saved mission file
+
+        char *missionFilename = m_location->m_levelFile->m_missionFilename;
+        char saveFilename[256];
+        sprintf( saveFilename, "%susers/%s/%s", GetProfileDirectory(), m_userProfileName, missionFilename );
+    
+        DeleteThisFile( saveFilename );
+
+        m_levelReset = true;
+
+
+        //
+        // Delete the game file if required
+
+        if( _global )
+        {
+            sprintf( saveFilename, "%susers/%s/%s", GetProfileDirectory(), m_userProfileName, m_gameDataFile );
+
+            DeleteThisFile( saveFilename );
+
+            if( m_globalWorld )
+            {
+                delete m_globalWorld;
+                m_globalWorld = NULL;
+            }
+    
+            m_globalWorld = new GlobalWorld();
+            m_globalWorld->LoadGame( m_gameDataFile );     
+        }
+    }    
+}
+
+bool App::HasBoughtGame()
+{
+#if defined(DEMOBUILD)
+       return false;
+#else
+       return true;
+#endif
+}
+
+void App::LoadPrologue()
+{
+    m_gameMode = App::GameModePrologue;
+
+    m_soundSystem->StopAllSounds(WorldObjectId(), "Music");
+
+    strcpy( m_gameDataFile, "game_demo2.txt" );
+    LoadProfile();
+
+    m_requestedLocationId = m_globalWorld->GetLocationId("launchpad");
+    GlobalLocation *gloc = m_globalWorld->GetLocation(m_requestedLocationId);
+    strcpy(m_requestedMap, gloc->m_mapFilename);
+    strcpy(m_requestedMission, gloc->m_missionFilename);
+
+    m_tutorial = new Demo2Tutorial();
+
+    m_atMainMenu = false;
+
+    g_prefsManager->SetInt( "RenderSpecialLighting", 1 );
+       g_prefsManager->SetInt( "CurrentGameMode", 0 );
+       g_prefsManager->Save();
+}
+
+void App::LoadCampaign()
+{
+    if( m_tutorial )
+    {
+        delete m_tutorial;
+        m_tutorial = NULL;
+    }
+
+    m_soundSystem->StopAllSounds(WorldObjectId(), "Music");
+
+    //m_atMainMenu = false;
+
+    strcpy( m_gameDataFile, "game.txt" );
+    LoadProfile();
+    m_gameMode = App::GameModeCampaign;
+    m_requestedLocationId = -1;  
+    g_prefsManager->SetInt( "RenderSpecialLighting", 0 );
+    g_prefsManager->SetInt( "CurrentGameMode", 1 );
+    g_prefsManager->Save();
+}
+
+#ifdef TARGET_OS_VISTA
+void App::SaveRichHeader()
+{
+       if( g_app->m_editing ) return;
+       if( !m_thumbnailScreenshot ) return;
+
+       char _filename[256];
+       sprintf( _filename, "%s.dsg", m_userProfileName );
+
+       char fullFilename[256];
+    sprintf( fullFilename, "%susers/%s", g_app->GetProfileDirectory(), _filename );        
+
+       RICH_GAME_MEDIA_HEADER header;
+       ZeroMemory( &header, sizeof(RICH_GAME_MEDIA_HEADER) );
+       header.dwMagicNumber = RM_MAGICNUMBER;
+       header.dwHeaderVersion = 1;
+       header.dwHeaderSize = sizeof(RICH_GAME_MEDIA_HEADER);
+       header.liThumbnailOffset.QuadPart = 0;
+       if( m_thumbnailScreenshot )
+       {
+               unsigned int size = (m_thumbnailScreenshot->m_height * m_thumbnailScreenshot->m_width * 3 ) + 54;
+               header.dwThumbnailSize = size;
+       }
+       else
+       {
+               header.dwThumbnailSize = 0;
+       }
+
+       header.guidGameId.Data1 = 0xF58175C7;
+       header.guidGameId.Data2 = 0xE99C;
+       header.guidGameId.Data3 = 0x4151;
+
+       header.guidGameId.Data4[0] = 0x80;
+       header.guidGameId.Data4[1] = 0x0D;
+       header.guidGameId.Data4[2] = 0x7B;
+       header.guidGameId.Data4[3] = 0xB5;
+       header.guidGameId.Data4[4] = 0xE8;
+       header.guidGameId.Data4[5] = 0x9E;
+       header.guidGameId.Data4[6] = 0x49;
+       header.guidGameId.Data4[7] = 0x60;
+
+       WCHAR saveName[256];
+       char filePath[256];
+       sprintf( filePath, "%susers\\%s.dsg", GetProfileDirectory(), m_userProfileName );
+
+       mbstowcs( saveName, filePath, 256 );
+
+       wcscpy(header.szGameName,  L"Darwinia");
+       wcscpy(header.szSaveName, saveName );
+       wcscpy(header.szLevelName, L"");
+       wcscpy(header.szComments, L"");
+
+       FILE *file = fopen(fullFilename, "wb");
+       fwrite( &header, sizeof(RICH_GAME_MEDIA_HEADER), 1, file );
+
+       m_thumbnailScreenshot->WritePng( file );
+       // m_thumbnailScreenshot->SavePng( "ss.bmp" );
+       delete m_thumbnailScreenshot;
+       m_thumbnailScreenshot = NULL;
+
+       fclose(file);
+
+}
+
+void App::SaveThumbnailScreenshot()
+{
+       PosterMaker pm(g_app->m_renderer->ScreenW(), g_app->m_renderer->ScreenH());
+       pm.AddFrame();
+
+       float newWidth = 256.0f;
+       float newHeight = 192.0f;
+
+       BitmapRGBA scaled(newWidth, newHeight );
+
+       scaled.Blit(0, 0, pm.GetBitmap()->m_width, pm.GetBitmap()->m_height, pm.GetBitmap(), 
+                                                          0, 0, newWidth, newHeight, true);
+
+       m_thumbnailScreenshot = new BitmapRGBA( scaled );
+
+       m_saveThumbnail = false;
+}
+
+#endif
index 8650c1d3ac321f3bf42448222db9f2388de671a4..4bd92d0764eaf405fe51fbecfd5018ee67dd9379 100644 (file)
-#ifndef _INCLUDED_APP_H\r
-#define _INCLUDED_APP_H\r
-\r
-#include "lib/rgb_colour.h"\r
-\r
-class Camera;\r
-class Location;\r
-class Server;\r
-class ClientToServer;\r
-class Renderer;\r
-class UserInput;\r
-class Resource;\r
-class SoundSystem;\r
-class LocationInput;\r
-class LangTable;\r
-class EffectProcessor;\r
-class GlobalWorld;\r
-class HelpSystem;\r
-class Tutorial;\r
-class ParticleSystem;\r
-class TaskManager;\r
-class TaskManagerInterface;\r
-class Gesture;\r
-class Script;\r
-class Sepulveda;\r
-class TestHarness;\r
-class Profiler;\r
-class AVIGenerator;\r
-class LocationEditor;\r
-class MouseCursor;\r
-class GameCursor;\r
-class GameMenu;\r
-class StartSequence;\r
-class DemoEndSequence;\r
-class AttractMode;\r
-class ControlHelpSystem;\r
-class BitmapRGBA;\r
-class GameMenu;\r
-\r
-\r
-\r
-class App\r
-{\r
-public:\r
-       // Library Code Objects\r
-    UserInput           *m_userInput;\r
-    Resource            *m_resource;\r
-    SoundSystem         *m_soundSystem;\r
-       ParticleSystem          *m_particleSystem;\r
-       LangTable                       *m_langTable;\r
-    AVIGenerator        *m_aviGenerator;\r
-    Profiler            *m_profiler;\r
-       \r
-       // Things that are the world\r
-    GlobalWorld         *m_globalWorld;\r
-    Location            *m_location;\r
-       int                                     m_locationId;\r
-\r
-       // Everything else\r
-    Camera              *m_camera;\r
-       Server              *m_server;                  // Server process, can be NULL if client\r
-    ClientToServer      *m_clientToServer;          // Clients connection to Server\r
-    Renderer            *m_renderer;\r
-       LocationInput           *m_locationInput;\r
-       LocationEditor          *m_locationEditor;\r
-    HelpSystem          *m_helpSystem;\r
-    Tutorial            *m_tutorial;\r
-       EffectProcessor         *m_effectProcessor;\r
-    TaskManager         *m_taskManager;\r
-    TaskManagerInterface *m_taskManagerInterface;\r
-    Gesture             *m_gesture;\r
-    Script              *m_script;\r
-    Sepulveda           *m_sepulveda;\r
-    TestHarness         *m_testHarness;\r
-    GameCursor          *m_gameCursor;\r
-    StartSequence       *m_startSequence;\r
-    DemoEndSequence     *m_demoEndSequence;\r
-       AttractMode                     *m_attractMode;\r
-    ControlHelpSystem   *m_controlHelpSystem;\r
-    GameMenu            *m_gameMenu;\r
-\r
-    bool                m_bypassNetworking;\r
-    bool                m_negativeRenderer;\r
-       int                                     m_difficultyLevel;                      // Cached from preferences\r
-       bool                            m_largeMenus;\r
-\r
-       // State flags\r
-    bool                m_paused;\r
-       bool                m_editing;\r
-\r
-       // Requested state flags\r
-       int                                     m_requestedLocationId;          // -1 for global world\r
-       bool                m_requestToggleEditing;\r
-       bool                            m_requestQuit;\r
-\r
-    char                m_userProfileName[256];\r
-    char                m_requestedMission[256];\r
-    char                m_requestedMap[256];\r
-    bool                m_levelReset;\r
-    char                m_gameDataFile[256];\r
-\r
-       RGBAColour                      m_backgroundColour;\r
-\r
-    bool                m_atMainMenu;       // true when the player is viewing the darwinia/mutliwinia menu\r
-    int                 m_gameMode;\r
-\r
-#ifdef TARGET_OS_VISTA\r
-       BitmapRGBA                      *m_thumbnailScreenshot;\r
-       bool                            m_saveThumbnail;\r
-#endif\r
-\r
-    enum\r
-    {\r
-        GameModeNone,\r
-        GameModePrologue,\r
-        GameModeCampaign,\r
-        GameModeMultiwinia,\r
-        NumGameModes\r
-    };\r
-\r
-public:\r
-    App ();\r
-       ~App();\r
-\r
-\r
-    void    SetProfileName  ( char *_profileName );\r
-    bool    LoadProfile     ();\r
-    bool    SaveProfile     ( bool _global, bool _local );\r
-    void    ResetLevel      ( bool _global );\r
-       \r
-    void    SetLanguage     ( char *_language, bool _test );\r
-\r
-       bool    HasBoughtGame   ();\r
-\r
-    void    LoadPrologue    ();\r
-    void    LoadCampaign    ();\r
-\r
-       static const char *GetProfileDirectory();\r
-       static const char *GetPreferencesPath();\r
-    static const char *GetScreenshotDirectory();\r
-       \r
-       void    UpdateDifficultyFromPreferences();\r
-\r
-#ifdef TARGET_OS_VISTA\r
-       void    SaveRichHeader();\r
-       void    SaveThumbnailScreenshot();\r
-#endif\r
-};\r
-\r
-#ifdef TARGET_OS_VISTA\r
-#define RM_MAXLENGTH     1024 \r
-#define RM_MAGICNUMBER   'HMGR' \r
-\r
-#pragma pack(push)\r
-#pragma pack(1)\r
-typedef  struct  _RICH_GAME_MEDIA_HEADER \r
-{ \r
-     DWORD        dwMagicNumber; \r
-     DWORD        dwHeaderVersion; \r
-     DWORD        dwHeaderSize; \r
-     LARGE_INTEGER liThumbnailOffset; \r
-     DWORD        dwThumbnailSize; \r
-     GUID         guidGameId; \r
-     WCHAR        szGameName[RM_MAXLENGTH]; \r
-     WCHAR        szSaveName[RM_MAXLENGTH]; \r
-     WCHAR        szLevelName[RM_MAXLENGTH]; \r
-     WCHAR        szComments[RM_MAXLENGTH]; \r
-}  RICH_GAME_MEDIA_HEADER;\r
-#pragma pack(pop)\r
-\r
-#endif\r
-\r
-extern App *g_app;\r
-\r
-#endif\r
+#ifndef _INCLUDED_APP_H
+#define _INCLUDED_APP_H
+
+#include "lib/rgb_colour.h"
+
+class Camera;
+class Location;
+class Server;
+class ClientToServer;
+class Renderer;
+class UserInput;
+class Resource;
+class SoundSystem;
+class LocationInput;
+class LangTable;
+class EffectProcessor;
+class GlobalWorld;
+class HelpSystem;
+class Tutorial;
+class ParticleSystem;
+class TaskManager;
+class TaskManagerInterface;
+class Gesture;
+class Script;
+class Sepulveda;
+class TestHarness;
+class Profiler;
+class AVIGenerator;
+class LocationEditor;
+class MouseCursor;
+class GameCursor;
+class GameMenu;
+class StartSequence;
+class DemoEndSequence;
+class AttractMode;
+class ControlHelpSystem;
+class BitmapRGBA;
+class GameMenu;
+
+
+
+class App
+{
+public:
+       // Library Code Objects
+    UserInput           *m_userInput;
+    Resource            *m_resource;
+    SoundSystem         *m_soundSystem;
+       ParticleSystem          *m_particleSystem;
+       LangTable                       *m_langTable;
+    AVIGenerator        *m_aviGenerator;
+    Profiler            *m_profiler;
+       
+       // Things that are the world
+    GlobalWorld         *m_globalWorld;
+    Location            *m_location;
+       int                                     m_locationId;
+
+       // Everything else
+    Camera              *m_camera;
+       Server              *m_server;                  // Server process, can be NULL if client
+    ClientToServer      *m_clientToServer;          // Clients connection to Server
+    Renderer            *m_renderer;
+       LocationInput           *m_locationInput;
+       LocationEditor          *m_locationEditor;
+    HelpSystem          *m_helpSystem;
+    Tutorial            *m_tutorial;
+       EffectProcessor         *m_effectProcessor;
+    TaskManager         *m_taskManager;
+    TaskManagerInterface *m_taskManagerInterface;
+    Gesture             *m_gesture;
+    Script              *m_script;
+    Sepulveda           *m_sepulveda;
+    TestHarness         *m_testHarness;
+    GameCursor          *m_gameCursor;
+    StartSequence       *m_startSequence;
+    DemoEndSequence     *m_demoEndSequence;
+       AttractMode                     *m_attractMode;
+    ControlHelpSystem   *m_controlHelpSystem;
+    GameMenu            *m_gameMenu;
+
+    bool                m_bypassNetworking;
+    bool                m_negativeRenderer;
+       int                                     m_difficultyLevel;                      // Cached from preferences
+       bool                            m_largeMenus;
+
+       // State flags
+    bool                m_paused;
+       bool                m_editing;
+
+       // Requested state flags
+       int                                     m_requestedLocationId;          // -1 for global world
+       bool                m_requestToggleEditing;
+       bool                            m_requestQuit;
+
+    char                m_userProfileName[256];
+    char                m_requestedMission[256];
+    char                m_requestedMap[256];
+    bool                m_levelReset;
+    char                m_gameDataFile[256];
+
+       RGBAColour                      m_backgroundColour;
+
+    bool                m_atMainMenu;       // true when the player is viewing the darwinia/mutliwinia menu
+    int                 m_gameMode;
+
+#ifdef TARGET_OS_VISTA
+       BitmapRGBA                      *m_thumbnailScreenshot;
+       bool                            m_saveThumbnail;
+#endif
+
+    enum
+    {
+        GameModeNone,
+        GameModePrologue,
+        GameModeCampaign,
+        GameModeMultiwinia,
+        NumGameModes
+    };
+
+public:
+    App ();
+       ~App();
+
+
+    void    SetProfileName  ( char *_profileName );
+    bool    LoadProfile     ();
+    bool    SaveProfile     ( bool _global, bool _local );
+    void    ResetLevel      ( bool _global );
+       
+    void    SetLanguage     ( char *_language, bool _test );
+
+       bool    HasBoughtGame   ();
+
+    void    LoadPrologue    ();
+    void    LoadCampaign    ();
+
+       static const char *GetProfileDirectory();
+       static const char *GetPreferencesPath();
+    static const char *GetScreenshotDirectory();
+       
+       void    UpdateDifficultyFromPreferences();
+
+#ifdef TARGET_OS_VISTA
+       void    SaveRichHeader();
+       void    SaveThumbnailScreenshot();
+#endif
+};
+
+#ifdef TARGET_OS_VISTA
+#define RM_MAXLENGTH     1024 
+#define RM_MAGICNUMBER   'HMGR' 
+
+#pragma pack(push)
+#pragma pack(1)
+typedef  struct  _RICH_GAME_MEDIA_HEADER 
+{ 
+     DWORD        dwMagicNumber; 
+     DWORD        dwHeaderVersion; 
+     DWORD        dwHeaderSize; 
+     LARGE_INTEGER liThumbnailOffset; 
+     DWORD        dwThumbnailSize; 
+     GUID         guidGameId; 
+     WCHAR        szGameName[RM_MAXLENGTH]; 
+     WCHAR        szSaveName[RM_MAXLENGTH]; 
+     WCHAR        szLevelName[RM_MAXLENGTH]; 
+     WCHAR        szComments[RM_MAXLENGTH]; 
+}  RICH_GAME_MEDIA_HEADER;
+#pragma pack(pop)
+
+#endif
+
+extern App *g_app;
+
+#endif
index 5da9ac3985f5623935a72474ec8db617c7affc8f..86c80f36c9864f75c0c81bac530f09064a1e7af1 100644 (file)
@@ -1,69 +1,69 @@
-#include "lib/universal_include.h"\r
-\r
-#include <eclipse.h>\r
-\r
-#include "lib/input/input.h"\r
-\r
-#include "app.h"\r
-#include "script.h"\r
-#include "attract.h"\r
-#include "taskmanager_interface.h"\r
-\r
-AttractMode::AttractMode()\r
-:      m_running(false)\r
-{\r
-       strcpy(m_userProfile, "none");\r
-}\r
-\r
-void AttractMode::Advance()\r
-{\r
-       if( !m_running )\r
-       {               \r
-               if( g_inputManager->controlEvent( ControlStartAttractMode ) ) // change to a timer for user idleness\r
-               {\r
-                       StartAttractMode();\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if( g_inputManager->controlEvent( ControlStopAttractMode ) ||\r
-                       !g_app->m_script->IsRunningScript() ) // change to check for any user activity\r
-               {\r
-                       EndAttractMode();\r
-               }\r
-       }\r
-}\r
-\r
-void AttractMode::StartAttractMode()\r
-{\r
-       strcpy( m_userProfile, g_app->m_userProfileName );\r
-       g_app->SaveProfile(true, true);\r
-       g_app->SetProfileName( "AttractMode" );\r
-    g_app->m_taskManagerInterface->m_lockTaskManager = true;\r
-       if( g_app->LoadProfile() )\r
-       {\r
-               g_app->m_script->RunScript("attractmode.txt");\r
-               m_running = true;\r
-       }\r
-\r
-       LList<EclWindow *> *windows = EclGetWindows();\r
-    while (windows->Size() > 0) {\r
-        EclWindow *w = windows->GetData(0);\r
-        EclRemoveWindow(w->m_name);\r
-    }\r
-\r
-    \r
-}\r
-\r
-void AttractMode::EndAttractMode()\r
-{\r
-    g_app->m_script->m_waitForCamera = false;\r
-       g_app->m_script->RunScript("endattract.txt");\r
-       g_app->SetProfileName( m_userProfile );\r
-       g_app->LoadProfile();\r
-\r
-    g_app->m_taskManagerInterface->m_lockTaskManager = false;\r
-\r
-       m_running = false;\r
-       strcpy(m_userProfile, "none");\r
-}\r
+#include "lib/universal_include.h"
+
+#include <eclipse.h>
+
+#include "lib/input/input.h"
+
+#include "app.h"
+#include "script.h"
+#include "attract.h"
+#include "taskmanager_interface.h"
+
+AttractMode::AttractMode()
+:      m_running(false)
+{
+       strcpy(m_userProfile, "none");
+}
+
+void AttractMode::Advance()
+{
+       if( !m_running )
+       {               
+               if( g_inputManager->controlEvent( ControlStartAttractMode ) ) // change to a timer for user idleness
+               {
+                       StartAttractMode();
+               }
+       }
+       else
+       {
+               if( g_inputManager->controlEvent( ControlStopAttractMode ) ||
+                       !g_app->m_script->IsRunningScript() ) // change to check for any user activity
+               {
+                       EndAttractMode();
+               }
+       }
+}
+
+void AttractMode::StartAttractMode()
+{
+       strcpy( m_userProfile, g_app->m_userProfileName );
+       g_app->SaveProfile(true, true);
+       g_app->SetProfileName( "AttractMode" );
+    g_app->m_taskManagerInterface->m_lockTaskManager = true;
+       if( g_app->LoadProfile() )
+       {
+               g_app->m_script->RunScript("attractmode.txt");
+               m_running = true;
+       }
+
+       LList<EclWindow *> *windows = EclGetWindows();
+    while (windows->Size() > 0) {
+        EclWindow *w = windows->GetData(0);
+        EclRemoveWindow(w->m_name);
+    }
+
+    
+}
+
+void AttractMode::EndAttractMode()
+{
+    g_app->m_script->m_waitForCamera = false;
+       g_app->m_script->RunScript("endattract.txt");
+       g_app->SetProfileName( m_userProfile );
+       g_app->LoadProfile();
+
+    g_app->m_taskManagerInterface->m_lockTaskManager = false;
+
+       m_running = false;
+       strcpy(m_userProfile, "none");
+}
index b419138e21fb063b3a7db0fa1354f075c52f7dea..16c1871f0536094f108677267b1272d797c5d8c9 100644 (file)
@@ -1,19 +1,19 @@
-#ifndef INCLUDED_ATTRACT_H\r
-#define INCLUDED_ATTRACT_H\r
-\r
-class AttractMode\r
-{\r
-public:\r
-       char    m_userProfile[256];\r
-       bool    m_running;\r
-\r
-public:\r
-       AttractMode();\r
-\r
-       void Advance();\r
-       void StartAttractMode();\r
-       void EndAttractMode();\r
-\r
-};\r
-\r
+#ifndef INCLUDED_ATTRACT_H
+#define INCLUDED_ATTRACT_H
+
+class AttractMode
+{
+public:
+       char    m_userProfile[256];
+       bool    m_running;
+
+public:
+       AttractMode();
+
+       void Advance();
+       void StartAttractMode();
+       void EndAttractMode();
+
+};
+
 #endif
\ No newline at end of file
index ff7618e0bbddd1c1399a7be8c6df7a63e79e84aa..956188ef95aa8b3bd34949e92ea7556b56f3b740 100644 (file)
-#include "lib/universal_include.h"\r
-\r
-#include <math.h>\r
-#include <string.h>\r
-#include <float.h>\r
-\r
-#include "lib/debug_utils.h"\r
-#include "lib/hi_res_time.h"\r
-#include "lib/input/input.h"\r
-#include "lib/input/movement2d.h"\r
-#include "lib/targetcursor.h"\r
-#include "lib/window_manager.h"\r
-#include "lib/math_utils.h"\r
-#include "lib/matrix33.h"\r
-#include "lib/profiler.h"\r
-#include "lib/debug_render.h"\r
-\r
-#include "lib/preferences.h"\r
-#include "interface/prefs_other_window.h"\r
-\r
-#include "eclipse.h"\r
-\r
-#include "network/clienttoserver.h"\r
-\r
-#include "app.h"\r
-#include "camera.h"\r
-#include "global_world.h"\r
-#include "level_file.h"\r
-#include "location.h"\r
-#include "main.h"\r
-#include "renderer.h"\r
-#include "taskmanager.h"\r
-#include "taskmanager_interface.h"\r
-#include "team.h"\r
-#include "unit.h"\r
-#include "user_input.h"\r
-#include "helpsystem.h"\r
-#include "script.h"\r
-#include "sepulveda.h"\r
-#include "gamecursor.h"\r
-#include "control_help.h"\r
-\r
-#include "loaders/credits_loader.h"\r
-\r
-#include "worldobject/teleport.h"\r
-#include "worldobject/insertion_squad.h"\r
-\r
-\r
-#define MIN_GROUND_CLEARANCE   10.0f   // Minimum height relative to land\r
-#define MIN_HEIGHT                             10.0f   // Height above sea level (which is y=0)\r
-#define MAX_HEIGHT                             5000.0f // Height above sea level (which is y=0)\r
-#define MIN_TRACKING_HEIGHT     200.0f  // Minimum height of the camera when tracking an entity\r
-\r
-\r
-// ***************\r
-// Private Methods\r
-// ***************\r
-\r
-void Camera::AdvanceDebugMode()\r
-{\r
-       if( strcmp( EclGetCurrentFocus(), "none" ) != 0 && !g_app->m_editing ) return;\r
-\r
-    if( g_app->m_editing )\r
-    {\r
-        m_targetFov = 60.0f;\r
-    }\r
-        \r
-       float advanceTime = g_advanceTime;\r
-       Vector3 right = m_front ^ m_up;\r
-\r
-    float speedSideways = g_app->m_globalWorld->GetSize() / 30.0f;\r
-       if (g_app->m_locationId != -1)\r
-       {\r
-               speedSideways = g_app->m_location->m_landscape.GetWorldSizeX() / 30.0f;\r
-       }    \r
-    float speedVertical = speedSideways;\r
-    float speedForwards = speedSideways;\r
-\r
-    if ( g_inputManager->controlEvent( ControlCameraSpeedup ) )\r
-    {\r
-        speedSideways *= 10.0f;\r
-        speedVertical *= 10.0f;\r
-        speedForwards *= 10.0f;\r
-    }\r
-    else if ( g_inputManager->controlEvent( ControlCameraSlowdown ) )\r
-    {\r
-        speedSideways *= 0.1f;\r
-        speedVertical /= 10.0f;\r
-        speedForwards /= 10.0f;\r
-    }\r
-\r
-    //speedForwards *= 20.0f;\r
-       // TODO: Support mouse/joystick\r
-    //if( EclGetWindows()->Size() == 0 )\r
-    {\r
-           static DPadMovement cam_slide( ControlCameraForwards, ControlCameraBackwards,\r
-                                          ControlCameraLeft, ControlCameraRight, ControlCameraUp,\r
-                                          ControlCameraDown, 1 );\r
-           cam_slide.Advance();\r
-           m_pos -= right   * ( cam_slide.signX() * advanceTime * speedSideways );\r
-           m_pos += m_up    * ( cam_slide.signZ() * advanceTime * speedVertical );\r
-           m_pos += m_front * ( cam_slide.signY() * advanceTime * speedForwards );\r
-    }\r
-\r
-       int mx = g_target->dX();\r
-       int my = g_target->dY();\r
-\r
-       // TODO: Really?\r
-    if ( g_inputManager->controlEvent( ControlCameraDebugRotate ) )\r
-    {\r
-        Matrix33 mat(1);\r
-               mat.RotateAroundY((float)mx * -0.005f);\r
-               m_up = m_up * mat;\r
-               m_front = m_front * mat;\r
-\r
-        Vector3 right = GetRight();\r
-               mat.SetToIdentity();\r
-               mat.FastRotateAround(right, (float)my * -0.005f);\r
-               m_up = m_up * mat;\r
-               m_front = m_front * mat;\r
-    }\r
-}\r
-\r
-\r
-void Camera::Get2DScreenPos (Vector3 const &_vector, float *_screenX, float *_screenY)\r
-{\r
-    double outX, outY, outZ;\r
-\r
-    int viewport[4];\r
-    double viewMatrix[16];\r
-    double projMatrix[16];\r
-    glGetIntegerv(GL_VIEWPORT, viewport);\r
-    glGetDoublev(GL_MODELVIEW_MATRIX, viewMatrix);\r
-    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);\r
-    gluProject(_vector.x, _vector.y, _vector.z, \r
-        viewMatrix,\r
-        projMatrix,\r
-        viewport,\r
-        &outX,\r
-        &outY,\r
-        &outZ);\r
-\r
-    *_screenX = outX;\r
-       *_screenY = outY;\r
-}\r
-\r
-\r
-void Camera::SetHeight(float _height)\r
-{\r
-    m_height = _height;\r
-}\r
-\r
-\r
-void Camera::SetFOV(float _fov)\r
-{\r
-    m_targetFov = _fov;\r
-    m_fov = _fov;\r
-}\r
-\r
-\r
-void Camera::SetTargetFOV(float _fov)\r
-{\r
-    m_targetFov = _fov;\r
-}\r
-\r
-\r
-void Camera::AdvanceSphereWorldMode()\r
-{      \r
-    bool chatLog = g_app->m_sepulveda->ChatLogVisible();\r
-    if( chatLog ) return;\r
-\r
-       m_targetFov = 100.0f;\r
-    \r
-       int const screenH = g_app->m_renderer->ScreenH();\r
-       int const screenW = g_app->m_renderer->ScreenW();\r
-\r
-       Vector3 focusPos = Vector3(0, m_height * -400,0);\r
-\r
-       // Set up viewing matrices\r
-       glPushMatrix();\r
-       SetupProjectionMatrix(g_app->m_renderer->GetNearPlane(), g_app->m_renderer->GetFarPlane());\r
-       SetupModelviewMatrix();\r
-\r
-    // Get the 2D mouse coordinates before we move the camera\r
-       Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-       float oldMouseX, oldMouseY;\r
-       Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-       oldMouseY = screenH - oldMouseY;\r
-\r
-    InputDetails details;\r
-    if( g_inputManager->controlEvent( ControlCameraMove, details ) )\r
-    {\r
-        g_target->SetMousePos( g_target->X() + details.x, g_target->Y() + details.y );\r
-        g_app->m_userInput->RecalcMousePos3d();\r
-        mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-        Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-           oldMouseY = screenH - oldMouseY;\r
-    }\r
-\r
-       float factor1 = 2.0f * g_advanceTime;\r
-       float factor2 = 1.0f - factor1;\r
-\r
-       // Update camera orientation \r
-    if (mousePos3D.MagSquared() > 1.0f)\r
-    {\r
-        Vector3 desiredFront = mousePos3D - m_pos;\r
-        desiredFront.Normalise();\r
-\r
-        m_front = m_front * factor2 + desiredFront * factor1;\r
-        m_front.Normalise();\r
-        Vector3 right = m_front ^ g_upVector;\r
-               right.Normalise();\r
-        m_up = right ^ m_front;\r
-    }\r
-\r
-\r
-       //\r
-    // Move towards the idealPos\r
-\r
-       factor1 /= 2.0f;\r
-       factor2 = 1.0f - factor1;\r
-    \r
-    Vector3 idealPos = focusPos - m_front * 30000;\r
-    if( idealPos.Mag() > 35000.0f ) idealPos.SetLength( 35000.0f );\r
-    Vector3 toIdealPos = idealPos - m_pos;\r
-       float distToIdealPos = toIdealPos.Mag();\r
-       m_pos = idealPos * factor1 + m_pos * factor2;\r
-\r
-    // Set up viewing matrices\r
-       SetupModelviewMatrix();\r
-\r
-       // Get the 2D mouse coordinates now that we have moved the camera\r
-    float newMouseX, newMouseY;\r
-    Get2DScreenPos(mousePos3D, &newMouseX, &newMouseY);\r
-    newMouseY = screenH - newMouseY;\r
-\r
-       // Calculate how much to move the cursor to make it look like it is\r
-       // locked to a point on the landscape (we need to take account of\r
-       // sub-pixel error from previous frames)\r
-    static float mouseDeltaX = 0.0f;\r
-    static float mouseDeltaY = 0.0f;\r
-    mouseDeltaX += (newMouseX - oldMouseX) * 1.0f;\r
-    mouseDeltaY += (newMouseY - oldMouseY) * 1.0f;\r
-    int intMouseDeltaX = floorf(mouseDeltaX);\r
-    int intMouseDeltaY = floorf(mouseDeltaY);\r
-    mouseDeltaX -= intMouseDeltaX;\r
-    mouseDeltaY -= intMouseDeltaY;\r
-       newMouseX = g_target->X() + intMouseDeltaX;\r
-       newMouseY = g_target->Y() + intMouseDeltaY;\r
-\r
-       // Make sure these movements don't put the mouse cursor somewhere stupid\r
-       if (newMouseX < 0)                              newMouseX = 0;\r
-       if (newMouseX >= screenW)               newMouseX = screenW - 1;\r
-       if (newMouseY < 0)                              newMouseY = 0;\r
-       if (newMouseY >= screenH)               newMouseY = screenH - 1;\r
-\r
-       // Apply the mouse cursor movement\r
-       g_target->SetMousePos(newMouseX, newMouseY);\r
-    glPopMatrix();\r
-}\r
-\r
-\r
-void Camera::AdvanceSphereWorldScriptedMode()\r
-{\r
-    int b = 10;\r
-\r
-    m_height = 50.0f;\r
-    \r
-       int const screenH = g_app->m_renderer->ScreenH();\r
-       int const screenW = g_app->m_renderer->ScreenW();\r
-\r
-       Vector3 focusPos = Vector3(0, m_height * -400,0);\r
-    focusPos.x += sinf( g_gameTime*0.5f ) * 4000.0f;\r
-    focusPos.y += cosf( g_gameTime*0.4f ) * 2000.0f;\r
-    focusPos.z += sinf( g_gameTime*0.3f ) * 4000.0f;\r
-\r
-       // Set up viewing matrices\r
-       glPushMatrix();\r
-       SetupProjectionMatrix(g_app->m_renderer->GetNearPlane(), g_app->m_renderer->GetFarPlane());\r
-       SetupModelviewMatrix();\r
-\r
-    // Get the 2D mouse coordinates before we move the camera\r
-       Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-       float oldMouseX, oldMouseY;\r
-       Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-       oldMouseY = screenH - oldMouseY;\r
-\r
-       float factor1 = 1.0f * g_advanceTime;\r
-       float factor2 = 1.0f - factor1;\r
-\r
-       // Update camera orientation \r
-    Vector3 desiredFront = m_targetPos - m_pos;\r
-    desiredFront.Normalise();\r
-\r
-    m_front = m_front * factor2 + desiredFront * factor1;\r
-    m_front.Normalise();\r
-    Vector3 right = m_front ^ g_upVector;\r
-       right.Normalise();\r
-    m_up = right ^ m_front;\r
-\r
-\r
-       //\r
-    // Move towards the idealPos\r
-\r
-       factor1 /= 2.0f;\r
-       factor2 = 1.0f - factor1;\r
-    \r
-    Vector3 idealPos = focusPos - m_front * 30000;\r
-    if( idealPos.Mag() > 35000.0f ) idealPos.SetLength( 35000.0f );\r
-    Vector3 toIdealPos = idealPos - m_pos;\r
-       float distToIdealPos = toIdealPos.Mag();\r
-       m_pos = idealPos * factor1 + m_pos * factor2;\r
-\r
-    glPopMatrix();\r
-}\r
-\r
-\r
-/*\r
-void Camera::AdvanceSphereWorldIntroMode()\r
-{\r
-    m_targetFov = 100.0f;\r
-\r
-    static float fixMeUp = 45000.0f;\r
-\r
-    if( g_keys[KEY_G] )\r
-    {\r
-        fixMeUp = 45000.0;\r
-    }\r
-\r
-    if( fixMeUp == 45000.0f )\r
-    {\r
-        m_pos.Set( 0, 0, -1000000.0f );\r
-        m_front.Set( 1, 0, -1 );\r
-        m_up.Set( 1, 0, 0 );\r
-    }\r
-    \r
-    fixMeUp -= g_advanceTime * 500.0f;\r
-\r
-    Vector3 targetFront = Vector3(200, 200, 200) - m_pos;\r
-    float distance = targetFront.Mag();\r
-    \r
-    float forwardSpeed = 3000.0f;\r
-    \r
-    targetFront.Normalise();\r
-\r
-    float rotateSpeed = forwardSpeed / (fixMeUp*0.66f);\r
-    float factor1 = g_advanceTime * rotateSpeed;\r
-    float factor2 = 1.0f - factor1;\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    m_up.RotateAround( m_front * g_advanceTime * rotateSpeed * 0.2f );\r
-\r
-    m_pos += m_front * forwardSpeed;\r
-}*/\r
-\r
-\r
-void Camera::AdvanceSphereWorldIntroMode()\r
-{\r
-    m_targetFov = 70.0f;\r
-\r
-    static bool fixMeUp = true;\r
-    static float startTime = GetHighResTime();\r
-    static float lastFrame = startTime;\r
-\r
-    float timeNow = GetHighResTime();\r
-    float frameTime = timeNow - lastFrame;\r
-    float runningTime = timeNow - startTime;\r
-    lastFrame = timeNow;\r
-\r
-#ifdef _DEBUG\r
-    if( g_inputManager->controlEvent( ControlDebugCameraFixUp ) )\r
-    {\r
-        fixMeUp = true;\r
-    }\r
-#endif\r
-\r
-    if( fixMeUp )\r
-    {\r
-        startTime = GetHighResTime();\r
-\r
-        m_pos.Set( -965852, 1720000, 2600000 );\r
-        m_front.Set( -1, 0, 0 );\r
-        m_up.Set( 0.15,0.93, 0.31 );\r
-        m_front.Normalise();\r
-        m_up.Normalise();\r
-        \r
-        fixMeUp = false;\r
-    }\r
-    \r
-    Vector3 targetPos = g_zeroVector;\r
-    if( runningTime < 30.0f )\r
-    {\r
-        targetPos.Set( -1000000, 4000000, 397000 );\r
-    }\r
-    else\r
-    {\r
-        targetPos.Set( 1000, 500, 1000 );\r
-    }        \r
-    Vector3 targetFront = targetPos - m_pos;\r
-    float distance = targetFront.Mag();\r
-    \r
-    float forwardSpeed = 3000.0f;\r
-    \r
-    if( distance < 2000000 && runningTime > 30 )\r
-    {\r
-        forwardSpeed = (distance/1070000.0f) * 3000.0f;\r
-    }\r
-\r
-    targetFront.Normalise();\r
-\r
-    float rotateSpeed = 4000.0f / 30000.0f;\r
-    float factor1 = frameTime * rotateSpeed;\r
-    float factor2 = 1.0f - factor1;\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    m_up.RotateAround( m_front * frameTime * rotateSpeed * sinf(runningTime*0.1f+0.4f) * 1.6f );\r
-\r
-    m_pos += m_front * forwardSpeed * frameTime * 62;\r
-}\r
-\r
-\r
-\r
-void Camera::AdvanceSphereWorldOutroMode()\r
-{\r
-    m_targetFov = 70;\r
-\r
-    static bool fixMeUp = true;\r
-    static float startTime = GetHighResTime();\r
-    static float lastFrame = startTime;\r
-\r
-    float timeNow = GetHighResTime();\r
-    float frameTime = timeNow - lastFrame;\r
-    float runningTime = timeNow - startTime;\r
-    lastFrame = timeNow;\r
-\r
-#ifdef _DEBUG\r
-    if( g_inputManager->controlEvent( ControlDebugCameraFixUp ) )\r
-    {\r
-        fixMeUp = true;\r
-    }\r
-#endif\r
-\r
-    if( fixMeUp )\r
-    {\r
-        startTime = GetHighResTime();\r
-\r
-        m_pos.Set( 0, 0, 0 );\r
-        m_front.Set( 0, 1, 0 );\r
-        m_up.Set( 0, 0, 1 );\r
-        m_front.Normalise();\r
-        m_up.Normalise();\r
-        \r
-        m_vel = m_front;\r
-        \r
-        fixMeUp = false;\r
-    }\r
-    \r
-    Vector3 targetPos( -1000000, 4000000, 397000 );\r
-\r
-    if( runningTime > 30.0f )\r
-    {\r
-        targetPos.Set( -965852, 1720000, 2600000 );\r
-    }\r
-\r
-    Vector3 targetFront = (targetPos - m_pos) * -1.0f;\r
-    float distance = targetFront.Mag();\r
-    \r
-    float forwardSpeed = sqrtf(m_pos.Mag()) * 4;\r
-    forwardSpeed = max( forwardSpeed, 1000 );\r
-    forwardSpeed = min( forwardSpeed, 2000 );\r
-    \r
-    targetFront.Normalise();\r
-\r
-    float rotateSpeed = 4000.0f / 30000.0f;\r
-    float factor1 = frameTime * rotateSpeed;\r
-    float factor2 = 1.0f - factor1;\r
-    m_vel = m_vel * factor2 + targetFront * factor1;\r
-    m_up.RotateAround( m_front * frameTime * rotateSpeed * sinf(runningTime*0.1f+0.4f) * 0.6f );\r
-\r
-    m_pos -= m_vel * forwardSpeed * frameTime * 62;\r
-\r
-    targetFront = -m_pos;\r
-    if( runningTime > 30.0f )\r
-    {\r
-        targetFront = m_vel;\r
-    }\r
-\r
-    targetFront.Normalise();\r
-    factor1 *= 5.0f;\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-\r
-    if( runningTime > 70.0f )\r
-    {\r
-        int loaderType = Loader::GetLoaderIndex("credits");\r
-        if( loaderType != -1 )\r
-        {\r
-            Loader *loader = Loader::CreateLoader( loaderType );\r
-            loader->Run();\r
-            delete loader;\r
-        }\r
-\r
-        RequestMode( ModeSphereWorld );\r
-        m_pos.Set(0,0,100);\r
-    }\r
-}\r
-\r
-\r
-void Camera::RequestSphereFocusMode()\r
-{\r
-       m_framesInThisMode = 0;\r
-    m_mode = ModeSphereWorldFocus;\r
-    m_targetPos.Zero();\r
-    m_trackRange = 100000.0f;\r
-    m_trackHeight = 0.0f;\r
-    m_trackTimer = GetHighResTime();\r
-\r
-    m_trackVector = ( m_pos );\r
-    m_trackVector.y = 0.0f;\r
-    m_trackVector.Normalise();\r
-}\r
-\r
-\r
-void Camera::AdvanceSphereWorldFocusMode()\r
-{\r
-    m_targetFov = 100;\r
-\r
-    Vector3 oldPos = m_pos;\r
-   \r
-    m_trackRange = 100000;\r
-    m_trackHeight = 50000;\r
-    \r
-    //\r
-    // Target a point that slowly rotates around the building\r
-\r
-    m_trackVector.RotateAroundY( g_advanceTime * -0.15f );\r
-    m_trackVector.Normalise();\r
-    float height = sinf( g_gameTime * 0.2f ) * m_trackHeight;\r
-    float trackRange = fabs(m_trackRange) + sinf( g_gameTime * 0.3f ) * fabs(m_trackRange) * 0.4f;\r
-    Vector3 realTargetPos = m_targetPos + m_trackVector * trackRange;           \r
-    realTargetPos.y = -110000 + height;\r
-\r
-    // Calculate a Movement Factor, so we start moving slowly towards our target,\r
-    // then eventually reach full speed\r
-    float timeSinceBegin = GetHighResTime() - m_trackTimer;\r
-    float moveFactor = timeSinceBegin * 0.2f;\r
-    moveFactor = min( moveFactor, 1.0f );\r
-\r
-    float factor1 = moveFactor * 0.5f * g_advanceTime;    \r
-    float factor2 = 1.0f - factor1;\r
-    m_pos = m_pos * factor2 + realTargetPos * factor1;\r
-        \r
-    m_targetPos.y = 10000;\r
-    \r
-    Vector3 targetFront = ( m_targetPos - m_pos ).Normalise();\r
-    if( m_trackRange < 0.0f ) \r
-    {\r
-        targetFront.x *= -1.0f;\r
-        targetFront.z *= -1.0f;\r
-    }\r
-       factor1 = moveFactor * 1.0f * g_advanceTime * 0.5f;\r
-       factor2 = 1.0f - factor1;\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    \r
-    m_up.Set( 0.0f, -1.0f, 0.0f );\r
-    Vector3 right = m_up ^ m_front;\r
-    m_up = right ^ m_front;\r
-}\r
-\r
-\r
-\r
-// Returns the number of meters to the nearest blockage that the camera would\r
-// experience if it travelled in the specified direction. A blockage is defined\r
-// as a piece of land more than 10 metres higher than the camera's current \r
-// height. If there is no blockage FLT_MAX is returned.\r
-float Camera::DistanceToBlockage(Vector3 const &_dir, float const _maxDist)\r
-{\r
-    if( !g_app->m_location ) return FLT_MAX;\r
-\r
-       unsigned int const numSteps = 40;\r
-       float const distStep = _maxDist / (float)numSteps;\r
-       for (int i = 1; i <= numSteps; ++i)\r
-       {\r
-               float x = m_pos.x + _dir.x * distStep * (float)i;\r
-               float z = m_pos.z + _dir.z * distStep * (float)i;\r
-               float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(x, z);\r
-               if (landHeight + MIN_GROUND_CLEARANCE > m_height)\r
-               {\r
-                       return (float)i * distStep;\r
-               }\r
-       }\r
-\r
-       return _maxDist;\r
-}\r
-\r
-void Camera::AdvanceFreeMovementMode()\r
-{\r
-       if (g_app->m_renderer->m_renderingPoster)\r
-       {\r
-               return;\r
-       }\r
-       \r
-       UpdateEntityTrackingMode();\r
-\r
-       // Check to see whether we should switch to entity tracking mode\r
-       WorldObjectId selection;\r
-       if (m_entityTrack && GetEntityToTrack(selection)) \r
-       {\r
-        Entity *entity = g_app->m_location->GetEntity( selection );\r
-               if( entity->m_type == Entity::TypeInsertionSquadie )\r
-        {\r
-                   RequestEntityTrackMode( selection );\r
-                   return;\r
-        }\r
-        else\r
-        {\r
-            m_objectId = WorldObjectId();\r
-        }\r
-       }\r
-\r
-\r
-       int screenW = g_app->m_renderer->ScreenW();\r
-       int screenH = g_app->m_renderer->ScreenH();\r
-       InputManager *im = g_inputManager;\r
-\r
-       // Set up viewing matrices\r
-       glPushMatrix();\r
-       SetupProjectionMatrix(g_app->m_renderer->GetNearPlane(), g_app->m_renderer->GetFarPlane());\r
-       SetupModelviewMatrix();\r
-\r
-    // Get the 2D mouse coordinates before we move the camera\r
-       Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-       float oldMouseX, oldMouseY;\r
-       Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-       oldMouseY = screenH - oldMouseY;\r
-\r
-    // Allow quake keys to move us\r
-    if( !g_app->m_taskManagerInterface->m_visible )\r
-       {\r
-               float moveRate = 250.0f;\r
-               Vector3 accelForward = m_front;\r
-               accelForward.y = 0.0f;\r
-               accelForward.Normalise();\r
-               Vector3 accelRight = GetRight();\r
-               accelRight.y = 0.0f;\r
-               accelRight.Normalise();\r
-        Vector3 accelUp = g_upVector;\r
-\r
-               // TODO: Support mouse/joystick\r
-        if( g_inputManager->controlEvent( ControlCameraSpeedup ) ) moveRate *= 4.0f;\r
-        \r
-        bool keyForward     = g_inputManager->controlEvent( ControlCameraForwards );\r
-        bool keyBackward    = g_inputManager->controlEvent( ControlCameraBackwards );\r
-        bool keyLeft        = g_inputManager->controlEvent( ControlCameraLeft );\r
-        bool keyRight       = g_inputManager->controlEvent( ControlCameraRight );\r
-\r
-               if (keyLeft)            m_targetPos += accelRight * g_advanceTime * moveRate;\r
-               if (keyRight)           m_targetPos -= accelRight * g_advanceTime * moveRate;\r
-               if (keyForward)     m_targetPos += accelForward * g_advanceTime * moveRate;\r
-               if (keyBackward)        m_targetPos -= accelForward * g_advanceTime * moveRate;\r
-\r
-        if( m_mode == ModeFreeMovement )\r
-        {\r
-            InputDetails details;\r
-            if( g_inputManager->controlEvent( ControlCameraMove, details ) )\r
-            {\r
-                m_targetPos -= accelRight * g_advanceTime * details.x * 10.0f;\r
-                m_targetPos -= accelForward * g_advanceTime * details.y * 10.0f;\r
-\r
-                               g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondMoveCameraOrUnit);\r
-            }\r
-        }\r
-\r
-        if( keyForward || keyBackward || keyLeft || keyRight )\r
-        {\r
-            g_app->m_helpSystem->PlayerDoneAction( HelpSystem::CameraMovement );\r
-        }\r
-\r
-//             if (m_pos.x < m_minX)   m_targetPos.x -= (m_pos.x - m_minX);\r
-//             if (m_pos.x > m_maxX)   m_targetPos.x -= (m_pos.x - m_maxX);\r
-//             if (m_pos.z < m_minX)   m_targetPos.z -= (m_pos.z - m_minZ);\r
-//             if (m_pos.z > m_maxX)   m_targetPos.z -= (m_pos.z - m_maxZ);\r
-\r
-               // Stop camera getting too close to cliffs\r
-               {\r
-                       Vector3 horiDir = m_targetPos - m_pos;\r
-                       horiDir.y = 0.0f;\r
-                       if (horiDir.Mag() > 1e-4)\r
-                       {\r
-                               horiDir.Normalise();\r
-                               float const distToBlockage = DistanceToBlockage(horiDir, 100.0f);\r
-                               if (distToBlockage < 100.0f)\r
-                               {\r
-                                       Vector3 targetVector = m_targetPos - m_pos;\r
-                                       Vector3 targetVectorHori = targetVector;\r
-                                       targetVectorHori.y = 0.0f;\r
-                                       float maxSpeed = (distToBlockage - 30.0f) / (100.0f - 30.0f);\r
-                                       if (maxSpeed < 0.0f) maxSpeed = 0.0f;\r
-                                       targetVector *= maxSpeed;\r
-                                       m_targetPos = m_pos + targetVector;\r
-                                       m_height += (1.0f - maxSpeed) * 1.0f * targetVectorHori.Mag();\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // Make sure we haven't set the height too low\r
-               float const hitDownRadius = 10.0f;\r
-               float landheight = g_app->m_location->m_landscape.m_heightMap->GetValue(m_targetPos.x, m_targetPos.z);\r
-               float landHeight2 = g_app->m_location->m_landscape.m_heightMap->GetValue(m_targetPos.x - hitDownRadius, m_targetPos.z - hitDownRadius);\r
-               if (landHeight2 > landheight) landheight = landHeight2;\r
-               landHeight2 = g_app->m_location->m_landscape.m_heightMap->GetValue(m_targetPos.x + hitDownRadius, m_targetPos.z - hitDownRadius);\r
-               if (landHeight2 > landheight) landheight = landHeight2;\r
-               landHeight2 = g_app->m_location->m_landscape.m_heightMap->GetValue(m_targetPos.x - hitDownRadius, m_targetPos.z + hitDownRadius);\r
-               if (landHeight2 > landheight) landheight = landHeight2;\r
-               landHeight2 = g_app->m_location->m_landscape.m_heightMap->GetValue(m_targetPos.x + hitDownRadius, m_targetPos.z + hitDownRadius);\r
-               if (landHeight2 > landheight) landheight = landHeight2;\r
-               \r
-               if (landheight < MIN_HEIGHT) landheight = MIN_HEIGHT;\r
-\r
-               if (landheight + MIN_GROUND_CLEARANCE > m_height)\r
-               {\r
-                       m_targetPos.y = landheight + MIN_GROUND_CLEARANCE;\r
-                       m_height = m_targetPos.y;\r
-               }\r
-               else\r
-               {\r
-                       m_targetPos.y = m_height;\r
-               }\r
-\r
-               // Update our position\r
-               float factor1 = 4.0f * g_advanceTime;\r
-               float factor2 = 1.0f - factor1;\r
-               Vector3 deltaPos = -m_pos;    \r
-               Vector3 oldPos = m_pos;\r
-               m_pos = m_pos * factor2 + m_targetPos * factor1;\r
-           \r
-               deltaPos = m_pos + deltaPos;\r
-               m_vel = ( m_pos - oldPos ) / g_advanceTime;\r
-           \r
-               // Update camera orientation \r
-               bool chatLog = g_app->m_sepulveda->ChatLogVisible();\r
-\r
-               if( !g_app->m_taskManagerInterface->m_visible           \r
-                       && !chatLog     )\r
-               {\r
-                       if (mousePos3D.MagSquared() > 1.0f)\r
-                       {\r
-                               Vector3 desiredFront = mousePos3D - m_pos;\r
-                               desiredFront.Normalise();\r
-                               Vector3 oldFront = m_front;\r
-                               Vector3 desiredRotation = oldFront ^ desiredFront;\r
-                               float amountToRotate = sqrtf(g_advanceTime) * 1.0f;\r
-                               if (amountToRotate > 1.0f) amountToRotate = 1.0f;\r
-                               desiredRotation *= amountToRotate;\r
-                               m_front.RotateAround(desiredRotation);\r
-       //            m_front = m_front * factor2 + desiredFront * factor1;\r
-                               m_front.Normalise();\r
-                               \r
-                               Vector3 right = m_front ^ g_upVector;\r
-                               right.Normalise();\r
-                               m_up = right ^ m_front;\r
-                       }\r
-               }\r
-           \r
-               // Set up viewing matrices\r
-               SetupModelviewMatrix();\r
-\r
-               // Get the 2D mouse coordinates now that we have moved the camera\r
-               float newMouseX, newMouseY;\r
-               mousePos3D += deltaPos;\r
-               Get2DScreenPos(mousePos3D, &newMouseX, &newMouseY);\r
-               newMouseY = screenH - newMouseY;\r
-\r
-               // Calculate how much to move the cursor to make it look like it is\r
-               // locked to a point on the landscape (we need to take account of\r
-               // sub-pixel error from previous frames)\r
-               static float mouseDeltaX = 0.0f;\r
-               static float mouseDeltaY = 0.0f;\r
-               mouseDeltaX += (newMouseX - oldMouseX) * 1.0f;\r
-               mouseDeltaY += (newMouseY - oldMouseY) * 1.0f;\r
-               int intMouseDeltaX = floorf(mouseDeltaX);\r
-               int intMouseDeltaY = floorf(mouseDeltaY);\r
-               mouseDeltaX -= intMouseDeltaX;\r
-               mouseDeltaY -= intMouseDeltaY;\r
-               // g_inputManager->PollForEvents();\r
-               newMouseX = g_target->X() + intMouseDeltaX;\r
-               newMouseY = g_target->Y() + intMouseDeltaY;\r
-\r
-               // Make sure these movements don't put the mouse cursor somewhere stupid\r
-               if (newMouseX < 0)                      newMouseX = 0;\r
-               if (newMouseX >= screenW)       newMouseX = screenW - 1;\r
-               if (newMouseY < 0)                      newMouseY = 0;\r
-               if (newMouseY >= screenH)       newMouseY = screenH - 1;\r
-\r
-               // Apply the mouse cursor movement\r
-               g_target->SetMousePos(newMouseX, newMouseY);\r
-               glPopMatrix();\r
-       }\r
-}   \r
-\r
-\r
-void Camera::Render()\r
-{\r
-//    RenderArrow( m_targetPos, m_targetPos + m_trackVector * m_trackRange, 1.0f );\r
-//    RenderSphere( m_targetPos + m_trackVector * m_trackRange, 20.0f );\r
-}\r
-\r
-\r
-void Camera::AdvanceBuildingFocusMode()\r
-{\r
-    Vector3 oldPos = m_pos;\r
-\r
-    //\r
-    // Target a point that slowly rotates around the building\r
-\r
-    m_trackVector.RotateAroundY( g_advanceTime * -0.15f );\r
-    m_trackVector.Normalise();\r
-    float height = m_trackHeight + sinf( g_gameTime * 0.3f ) * m_trackHeight * 0.5f;\r
-    float trackRange = fabs(m_trackRange) + sinf( g_gameTime * 0.3f ) * fabs(m_trackRange) * 0.3f;\r
-    Vector3 realTargetPos = m_targetPos + m_trackVector * trackRange;           \r
-    realTargetPos.y = m_targetPos.y + height;\r
-\r
-    // Calculate a Movement Factor, so we start moving slowly towards our target,\r
-    // then eventually reach full speed\r
-    float timeSinceBegin = GetHighResTime() - m_trackTimer;\r
-    float moveFactor = timeSinceBegin * 1.0f;\r
-    moveFactor = min( moveFactor, 1.0f );\r
-\r
-    if( timeSinceBegin < 2.0f )\r
-    {\r
-        // Make the camera lift up when first moving towards a building\r
-        float distance = ( m_pos - realTargetPos ).Mag();\r
-        realTargetPos.y += distance * 0.75f * ( 2.0f - timeSinceBegin );\r
-        realTargetPos.y = min( realTargetPos.y, 1000.0f );\r
-    }\r
-\r
-    float factor1 = moveFactor * 0.5f * g_advanceTime;    \r
-    float factor2 = 1.0f - factor1;\r
-    m_pos = m_pos * factor2 + realTargetPos * factor1;\r
-        \r
-    Vector3 targetFront = ( m_targetPos - m_pos ).Normalise();\r
-    if( m_trackRange < 0.0f ) \r
-    {\r
-        targetFront.x *= -1.0f;\r
-        targetFront.z *= -1.0f;\r
-    }\r
-       factor1 = moveFactor * 1.0f * g_advanceTime;\r
-       factor2 = 1.0f - factor1;\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    \r
-    m_up.Set( 0.0f, -1.0f, 0.0f );\r
-    Vector3 right = m_up ^ m_front;\r
-    m_up = right ^ m_front;\r
-\r
-    float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue( m_pos.x, m_pos.z );\r
-    if( m_pos.y < landHeight + 10.0f )\r
-    {\r
-        m_pos.y = landHeight + 10.0f;\r
-    }\r
-}\r
-\r
-// Determine whether there is an entity or unit that has been selected\r
-// by the player, and if so, return true and fill in the object id.\r
-bool Camera::GetEntityToTrack( WorldObjectId &selection )\r
-{\r
-       if( !g_app->m_location )\r
-               return false;    \r
-\r
-    Team *team = g_app->m_location->GetMyTeam();\r
-\r
-       if( !team )\r
-               return false;\r
-\r
-    if( team->GetMyEntity() )\r
-    {\r
-        selection = team->GetMyEntity()->m_id;\r
-               return true;\r
-    }\r
-\r
-    Task *currentTask = g_app->m_taskManager->GetCurrentTask();\r
-    // if the task has just been ended or killed, it isnt valid\r
-    if (currentTask && currentTask->m_state == Task::StateStopping )\r
-        return false;\r
-\r
-    if( !currentTask )\r
-        return false;\r
-\r
-       Unit *unit = team->GetMyUnit();\r
-    if( !unit )\r
-               return false;\r
-\r
-       if( unit->m_troopType == Entity::TypeInsertionSquadie ) \r
-       {\r
-               InsertionSquad *squad = (InsertionSquad *) unit;\r
-               Entity *pointMan = squad->GetPointMan();\r
-               if (pointMan) {\r
-                       selection = pointMan->m_id;\r
-                       return true;\r
-               }\r
-       }\r
-\r
-       return false;\r
-}\r
-\r
-void Camera::AdvanceAutomaticTracking()\r
-{\r
-       float factor1 = g_advanceTime * 4.0f;\r
-       float factor2 = 1.0f - factor1;\r
-\r
-       Vector3 avgCameraTarget;\r
-       int numInputs = 0;\r
-\r
-       Vector3 cameraTarget;\r
-       \r
-       if (AdvanceRopeModel( cameraTarget )) {\r
-               avgCameraTarget += cameraTarget;\r
-               numInputs++;\r
-       }\r
-\r
-       if (AdvanceCanSeeUnits( cameraTarget )) {\r
-               avgCameraTarget += cameraTarget;\r
-               numInputs++;\r
-       }\r
-\r
-       if (AdvanceNotTooLow( cameraTarget )) {\r
-               avgCameraTarget += cameraTarget;\r
-               numInputs++;\r
-       }\r
-\r
-       if (AdvanceNotTooFarAway( cameraTarget )) {\r
-               avgCameraTarget += cameraTarget;\r
-               numInputs++;\r
-       }\r
-\r
-       if (AdvanceManualRotateCamera( cameraTarget )) {\r
-               avgCameraTarget += 3 * cameraTarget;\r
-               numInputs += 3;\r
-       }\r
-\r
-       if( AdvanceManualCameraHeight ( cameraTarget )) \r
-       {\r
-               avgCameraTarget += cameraTarget;\r
-               numInputs++;\r
-       }\r
-\r
-       if (numInputs > 0) \r
-               avgCameraTarget = avgCameraTarget / float(numInputs);\r
-       else\r
-               avgCameraTarget = m_pos;\r
-\r
-       m_cameraTarget = factor2 * m_cameraTarget + factor1 * avgCameraTarget;\r
-       m_pos = factor2 * m_pos + factor1 * m_cameraTarget;\r
-\r
-       // Finally face the unit\r
-    RotateTowardsEntity( m_trackingEntity );\r
-       UpdateControlVector();\r
-}\r
-void Camera::UpdateControlVector()\r
-{\r
-       const float angleThreshold = 0.98f;\r
-\r
-       bool recalc = false;\r
-       if( g_inputManager->controlEvent( ControlUnitMoveDirectionChange ) )\r
-       {\r
-               m_skipDirectionCalculation = false;\r
-               recalc = true;\r
-       }\r
-\r
-       float angle = cosf( g_upVector * GetUp() );\r
-       if((fabs(angle) < angleThreshold  && !m_skipDirectionCalculation ) ||\r
-               !g_inputManager->controlEvent( ControlUnitMove ) ||\r
-               recalc )\r
-       {\r
-               m_controlVector = GetRight();\r
-               m_skipDirectionCalculation = false;\r
-       }\r
-       else if( fabs(angle) >= angleThreshold  )\r
-       {\r
-               m_skipDirectionCalculation = true;\r
-       }\r
-}\r
-\r
-bool Camera::AdvanceManualRotateCamera( Vector3 &cameraTarget )\r
-{\r
-       if((g_inputManager->controlEvent( ControlCameraRotateLeft ) ||\r
-        g_inputManager->controlEvent( ControlCameraRotateRight ) ) &&\r
-               !g_inputManager->controlEvent( ControlUnitPrimaryFireDirected ))\r
-    {\r
-        m_trackHeight = 0.0f;\r
-\r
-        int rotSpeed = 100;\r
-\r
-               int halfWidth = g_app->m_renderer->ScreenW() / 2;\r
-               int deltaX = g_target->X() - halfWidth;\r
-        if( g_inputManager->controlEvent( ControlCameraRotateLeft )  )\r
-        {\r
-            deltaX = rotSpeed;\r
-        }\r
-\r
-        if( g_inputManager->controlEvent( ControlCameraRotateRight ) )\r
-        {\r
-            deltaX = -rotSpeed;\r
-        }\r
-\r
-        float rotY = (float)deltaX * 0.015f;\r
-\r
-               // Disable vertical camera adjustment, for now\r
-\r
-                int halfHeight = g_app->m_renderer->ScreenH() / 2;\r
-                int deltaY = g_target->Y() - halfHeight;\r
-         float rotRight = (float)deltaY * -0.01f;\r
-\r
-               Vector3 front = m_front;\r
-        front.RotateAroundY(rotY);\r
-\r
-        Vector3 right = (front ^ g_upVector).Normalise();\r
-        \r
-               Vector3 newUp = m_up;\r
-\r
-        newUp.RotateAround(right * rotRight);\r
-        if (newUp.y > 0.1f)\r
-        {\r
-            front.RotateAround(right * rotRight);\r
-        }        \r
-\r
-        cameraTarget = m_targetPos - front * m_currentDistance;\r
-               return true;\r
-    }\r
-       else {\r
-               m_currentDistance = (m_pos - m_predictedEntityPos).Mag();\r
-               return false;\r
-       }\r
-\r
-}\r
-\r
-bool Camera::AdvanceManualCameraHeight( Vector3 &cameraTarget )\r
-{\r
-       const float heightScale = 0.05f;\r
-\r
-       bool camDown = false;\r
-\r
-    if( EclGetWindows()->Size() == 0 )\r
-    {\r
-           if( g_inputManager->controlEvent( ControlCameraUp ) )\r
-           {\r
-                   m_heightMultiplier += heightScale;\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraUp);\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraDown);\r
-           }\r
-\r
-           if( g_inputManager->controlEvent( ControlCameraDown ) )\r
-           {\r
-                   m_heightMultiplier -= heightScale;\r
-                   camDown = true;\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraUp);\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraDown);\r
-           }\r
-\r
-           m_heightMultiplier = min( 2.0f, m_heightMultiplier );\r
-           m_heightMultiplier = max( m_heightMultiplier, 0.25f );\r
-\r
-           if( camDown )\r
-           {\r
-                   cameraTarget = m_pos;\r
-                   cameraTarget.y -= 25.0f;\r
-                   return true;\r
-           }\r
-    }\r
-\r
-       return false;   \r
-}\r
-\r
-bool Camera::AdvanceRopeModel( Vector3 &cameraTarget )\r
-{\r
-       // Follow along as if the camera is attached to the entity\r
-       // by a rope on the floor.\r
-\r
-    Vector3 C(m_pos); \r
-       C.y = 0.0f;\r
-\r
-    Vector3 E2(m_predictedEntityPos); \r
-       E2.y = 0.0f;\r
-\r
-    Vector3 B = C - E2;\r
-\r
-    // Distance to stay within\r
-    const float d = m_distFromEntity;\r
-    const float dSquared = d * d;\r
-\r
-    // Stay within a certain distance of the entity\r
-    if (B.MagSquared() > dSquared) \r
-    {\r
-        B.Normalise();\r
-               cameraTarget = E2 + B * d;\r
-               cameraTarget.y = m_pos.y;\r
-               return true;\r
-    }\r
-\r
-    // Distance to stay outside of\r
-\r
-    float cameraHeight = m_pos.y - m_predictedEntityPos.y;\r
-\r
-\r
-    // outsideD should be dependent on the camera height\r
-    // (oustideD = h / tan theta, where theta is the angle of elevation of the camera from the entity's point of view)\r
-    // Important that outsideD < d;\r
-\r
-    const float outsideD = 120.0;  // cameraHeight / 0.36; \r
-    const float outsideDSquared = outsideD * outsideD;\r
-\r
-    // DebugOut("2dcamdist = %f, outsideD = %f\n", B.Mag(), outsideD);\r
-    if (B.MagSquared() < outsideDSquared) \r
-    {\r
-        B.Normalise();\r
-        cameraTarget = E2 + B * outsideD;\r
-        cameraTarget.y = m_pos.y;\r
-        return true;\r
-    }\r
-\r
-       return false;\r
-}\r
-\r
-bool Camera::AdvanceCanSeeUnits( Vector3 &targetCamera )\r
-{\r
-       float distToEntity = (m_predictedEntityPos - m_pos).Mag();\r
-\r
-       if (DirectDistanceToBlockage(m_pos, m_predictedEntityPos, distToEntity) < distToEntity - 1.0f) {\r
-\r
-           Vector3 blockage;\r
-               GetHighestTangentPoint( m_predictedEntityPos, m_pos, distToEntity, blockage );\r
-\r
-               Vector3 ray = blockage - m_predictedEntityPos;\r
-               ray.Normalise();\r
-               targetCamera = m_predictedEntityPos + ray * distToEntity;\r
-               return true;\r
-       }\r
-\r
-       return false;\r
-}\r
-\r
-bool Camera::AdvanceNotTooLow( Vector3 &targetCamera )\r
-{\r
-       // Code to check if the camera is not too low of the ground     \r
-       float cameraHeight = m_pos.y - g_app->m_location->m_landscape.m_heightMap->GetValue( m_pos.x, m_pos.z );\r
-\r
-       if (m_pos.y < MIN_HEIGHT || cameraHeight < MIN_TRACKING_HEIGHT * m_heightMultiplier) {\r
-               targetCamera = m_pos;\r
-               targetCamera.y += 20;\r
-               return true;\r
-       }\r
-\r
-       return false;\r
-}\r
-\r
-bool Camera::AdvanceNotTooFarAway( Vector3 &targetCamera )\r
-{\r
-       Vector3 entityToCamera = m_pos - m_predictedEntityPos;\r
-\r
-       float maxDist = m_distFromEntity * 1.2f;\r
-\r
-       if (entityToCamera.MagSquared() > maxDist * maxDist) {\r
-               entityToCamera.Normalise();\r
-               targetCamera = m_predictedEntityPos + entityToCamera * maxDist;\r
-               return true;\r
-       }       \r
-\r
-       return false;\r
-}\r
-\r
-void Camera::RotateTowardsEntity( Entity *entity )\r
-{\r
-    float factor1 = g_advanceTime * 2.0f;\r
-    float factor2 = 1.0f - factor1;\r
-\r
-       // We deliberately overshoot the target pos? \r
-\r
-       Vector3 newTargetPos = entity->GetCameraFocusPoint();\r
-    m_targetPos = factor1 * newTargetPos + factor2 * m_targetPos;\r
-\r
-    Vector3 targetFront = ( m_targetPos - m_pos ).Normalise();\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    m_up.Set( 0.0f, -1.0f, 0.0f );\r
-    Vector3 right = m_up ^ m_front;\r
-    m_up = right ^ m_front;\r
-}\r
-\r
-void Camera::AdvanceEntityTrackMode()\r
-{\r
-    if( g_app->m_taskManagerInterface->m_visible)\r
-               return;\r
-\r
-       UpdateEntityTrackingMode();\r
-\r
-       if (!g_app->m_location || !m_entityTrack) \r
-               goto finishMode;\r
-\r
-       Entity *entity = g_app->m_location->GetEntity( m_objectId );\r
-       if (!entity || entity->m_dead)\r
-       {\r
-               WorldObjectId id;\r
-               GetEntityToTrack(id);\r
-               m_objectId = id;\r
-       }\r
-\r
-       entity = g_app->m_location->GetEntity( m_objectId );\r
-       if (!entity || entity->m_dead)\r
-               goto finishMode;\r
-\r
-    Task *currentTask = g_app->m_taskManager->GetCurrentTask();\r
-    if (currentTask && currentTask->m_state != Task::StateRunning )\r
-               goto finishMode;\r
-\r
-    if( !currentTask && entity->m_type != Entity::TypeOfficer )\r
-        goto finishMode;\r
-\r
-    if( !m_objectId.IsValid() )\r
-        goto finishMode;\r
-\r
-       // Calculate the predicated position of the entity (where it should be at\r
-       // the next frame). This is used by the auxiliary functions.\r
-       m_predictedEntityPos = entity->m_pos + g_advanceTime * entity->m_vel;\r
-       m_trackingEntity = entity;\r
-\r
-    AdvanceAutomaticTracking();\r
-\r
-       // Ensure that the target cursor remains in the centre of the screen\r
-    int halfHeight = g_app->m_renderer->ScreenH() / 2;\r
-       int halfWidth = g_app->m_renderer->ScreenW() / 2;\r
-       g_target->SetMousePos(halfWidth, halfHeight);\r
-\r
-       return;\r
-\r
-finishMode:\r
-       RequestMode( Camera::ModeFreeMovement );\r
-}\r
-\r
-\r
-void Camera::GetHighestTangentPoint( Vector3 const &_from, Vector3 const &_to, float _maxDist, Vector3 &location )\r
-{\r
-       unsigned int const numSteps = 40;\r
-       float const distStep = _maxDist / (float)numSteps;\r
-\r
-       Vector3 fromAtSameHeight = _from;\r
-       fromAtSameHeight.y = _to.y;\r
-    Vector3 dir = ( _to - fromAtSameHeight ).Normalise();\r
-\r
-       float x = _from.x;\r
-       float z = _from.z;\r
-\r
-       float const deltaX = distStep * dir.x;\r
-       float const deltaZ = distStep * dir.z;\r
-\r
-    float maxGradient = 0.0f;\r
-       float distanceTravelled = 0.0f;\r
-\r
-       for (int i = 1; i <= numSteps; ++i)\r
-       {\r
-               x += deltaX;\r
-               z += deltaZ;\r
-               distanceTravelled += distStep;\r
-\r
-               float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(x, z);\r
-\r
-               float gradient = (landHeight - _from.y) / distanceTravelled;\r
-\r
-               if (gradient > maxGradient) {\r
-                       maxGradient = gradient;\r
-                       location.Set( x, landHeight, z );\r
-               }\r
-       }\r
-}\r
-\r
-\r
-void Camera::GetHighestPoint( Vector3 const &_from, Vector3 const &_to, float _maxDist, Vector3 &location )\r
-{\r
-       unsigned int const numSteps = 40;\r
-       float const distStep = _maxDist / (float)numSteps;\r
-\r
-    Vector3 dir = ( _to - _from ).Normalise();\r
-\r
-    float maxHeight = 0.0f;\r
-\r
-       for (int i = 1; i <= numSteps; ++i)\r
-       {\r
-               float x = _from.x + dir.x * distStep * (float)i;\r
-               float z = _from.z + dir.z * distStep * (float)i;\r
-               float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(x, z);\r
-               if (landHeight > maxHeight)\r
-               {\r
-            maxHeight = landHeight;\r
-            location.Set( x, landHeight, z );\r
-               }\r
-       }\r
-}\r
-\r
-\r
-// Returns the number of meters to the nearest blockage that the camera would\r
-// experience if it travelled in the specified direction. A blockage is defined\r
-// as a piece of land more than 10 metres higher than the camera's current \r
-// height. If there is no blockage FLT_MAX is returned.\r
-float Camera::DirectDistanceToBlockage(Vector3 const &_from, Vector3 const &_to, float const _maxDist)\r
-{\r
-    if( !g_app->m_location ) return FLT_MAX;\r
-\r
-       unsigned int const numSteps = 40;\r
-       float const distStep = _maxDist / (float)numSteps;\r
-       \r
-       float x = _from.x;\r
-       float y = _from.y;\r
-       float z = _from.z;\r
-\r
-       Vector3 dir = ( _to - _from ).Normalise();\r
-\r
-       float const deltaX = distStep * dir.x;\r
-       float const deltaY = distStep * dir.y;\r
-       float const deltaZ = distStep * dir.z;\r
-\r
-       for (int i = 1; i <= numSteps; ++i)\r
-       {\r
-               x += deltaX;\r
-               y += deltaY;\r
-               z += deltaZ;\r
-\r
-               float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(x, z);\r
-\r
-               if (landHeight > y)     \r
-               {\r
-                       return (float)i * distStep;\r
-               }\r
-       }\r
-\r
-       return _maxDist;\r
-}\r
-\r
-\r
-\r
-// Expects m_targetPos to have been set\r
-void Camera::AdvanceRadarAimMode()\r
-{\r
-       int const screenH = g_app->m_renderer->ScreenH();\r
-       int const screenW = g_app->m_renderer->ScreenW();\r
-\r
-       Vector3 groundPos = m_targetPos;\r
-       groundPos.y = g_app->m_location->m_landscape.m_heightMap->GetValue(groundPos.x, groundPos.z);\r
-\r
-       Vector3 focusPos = groundPos;\r
-       focusPos.y += m_height;\r
-\r
-       // Set up viewing matrices\r
-       glPushMatrix();\r
-       SetupProjectionMatrix(g_app->m_renderer->GetNearPlane(), g_app->m_renderer->GetFarPlane());\r
-       SetupModelviewMatrix();\r
-\r
-    // Get the 2D mouse coordinates before we move the camera\r
-       Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-       float oldMouseX, oldMouseY;\r
-       Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-       oldMouseY = screenH - oldMouseY;\r
-    \r
-       float factor1 = 4.0f * g_advanceTime;\r
-       float factor2 = 1.0f - factor1;\r
-\r
-       // Update camera orientation \r
-    if (mousePos3D.MagSquared() > 1.0f)\r
-    {\r
-        Vector3 desiredFront = mousePos3D - m_pos;\r
-        desiredFront.Normalise();\r
-\r
-        m_front = m_front * factor2 + desiredFront * factor1;\r
-        m_front.Normalise();\r
-        Vector3 right = m_front ^ g_upVector;\r
-               right.Normalise();\r
-        m_up = right ^ m_front;\r
-    }\r
-\r
-\r
-       //\r
-    // Move towards the idealPos\r
-    \r
-       Vector3 idealPos = groundPos;\r
-       idealPos.y += m_height;\r
-       Vector3 horiCamFront = m_front;\r
-       horiCamFront.y = 0.0f;\r
-       horiCamFront.Normalise();\r
-       idealPos -= horiCamFront * (0.0f + m_height * 1.5f);\r
-    Vector3 toIdealPos = idealPos - m_pos;\r
-       float distToIdealPos = toIdealPos.Mag();\r
-       m_pos = idealPos * factor1 + m_pos * factor2;\r
-\r
-    // Set up viewing matrices\r
-       SetupModelviewMatrix();\r
-\r
-       // Get the 2D mouse coordinates now that we have moved the camera\r
-    float newMouseX, newMouseY;\r
-    Get2DScreenPos(mousePos3D, &newMouseX, &newMouseY);\r
-    newMouseY = screenH - newMouseY;\r
-\r
-       // Calculate how much to move the cursor to make it look like it is\r
-       // locked to a point on the landscape (we need to take account of\r
-       // sub-pixel error from previous frames)\r
-    static float mouseDeltaX = 0.0f;\r
-    static float mouseDeltaY = 0.0f;\r
-    mouseDeltaX += (newMouseX - oldMouseX) * 1.0f;\r
-    mouseDeltaY += (newMouseY - oldMouseY) * 1.0f;\r
-    int intMouseDeltaX = floorf(mouseDeltaX);\r
-    int intMouseDeltaY = floorf(mouseDeltaY);\r
-    mouseDeltaX -= intMouseDeltaX;\r
-    mouseDeltaY -= intMouseDeltaY;\r
-       newMouseX = g_target->X() + intMouseDeltaX;\r
-       newMouseY = g_target->Y() + intMouseDeltaY;\r
-\r
-       // Make sure these movements don't put the mouse cursor somewhere stupid\r
-       if (newMouseX < 0)                              newMouseX = 0;\r
-       if (newMouseX >= screenW)               newMouseX = screenW - 1;\r
-       if (newMouseY < 0)                              newMouseY = 0;\r
-       if (newMouseY >= screenH)               newMouseY = screenH - 1;\r
-\r
-       // Apply the mouse cursor movement\r
-//alleg    position_mouse(newMouseX, newMouseY);\r
-       g_target->SetMousePos(newMouseX, newMouseY);\r
-    glPopMatrix();\r
-}\r
-\r
-\r
-void Camera::AdvanceTurretAimMode()\r
-{\r
-       int const screenH = g_app->m_renderer->ScreenH();\r
-       int const screenW = g_app->m_renderer->ScreenW();\r
-\r
-       Vector3 groundPos = m_targetPos;\r
-    groundPos.y += 20.0f;\r
-    float minY = g_app->m_location->m_landscape.m_heightMap->GetValue(groundPos.x, groundPos.z);\r
-    \r
-    groundPos -= m_front * m_height;\r
-    //groundPos.y = max( groundPos.y, minY );\r
-    \r
-       //groundPos.y = ;\r
-    //groundPos.y -= 10.0f;\r
-    \r
-       Vector3 focusPos = groundPos;\r
-       focusPos.y += m_height;\r
-\r
-       // Set up viewing matrices\r
-       glPushMatrix();\r
-       SetupProjectionMatrix(g_app->m_renderer->GetNearPlane(), g_app->m_renderer->GetFarPlane());\r
-       SetupModelviewMatrix();\r
-\r
-    // Get the 2D mouse coordinates before we move the camera\r
-       Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();\r
-       float oldMouseX, oldMouseY;\r
-       Get2DScreenPos(mousePos3D, &oldMouseX, &oldMouseY);\r
-       oldMouseY = screenH - oldMouseY;\r
-\r
-       float factor1 = 4.0f * g_advanceTime;\r
-       float factor2 = 1.0f - factor1;\r
-\r
-       // Update camera orientation \r
-    if (mousePos3D.MagSquared() > 1.0f)\r
-    {\r
-        Vector3 desiredFront = mousePos3D - m_pos;\r
-        desiredFront.Normalise();\r
-\r
-        m_front = m_front * factor2 + desiredFront * factor1;\r
-        m_front.Normalise();\r
-        Vector3 right = m_front ^ g_upVector;\r
-               right.Normalise();\r
-        m_up = right ^ m_front;\r
-    }\r
-\r
-\r
-       //\r
-    // Move towards the idealPos\r
-    \r
-       Vector3 idealPos = groundPos;\r
-       idealPos.y += m_height;\r
-       Vector3 horiCamFront = m_front;\r
-       horiCamFront.y = 0.0f;\r
-       horiCamFront.Normalise();\r
-       idealPos -= horiCamFront * (0.0f + m_height * 0.4f);\r
-    Vector3 toIdealPos = idealPos - m_pos;\r
-       float distToIdealPos = toIdealPos.Mag();\r
-       m_pos = idealPos * factor1 + m_pos * factor2;\r
-\r
-    // Set up viewing matrices\r
-       SetupModelviewMatrix();\r
-\r
-       // Get the 2D mouse coordinates now that we have moved the camera\r
-    float newMouseX, newMouseY;\r
-    Get2DScreenPos(mousePos3D, &newMouseX, &newMouseY);\r
-    newMouseY = screenH - newMouseY;\r
-\r
-       // Calculate how much to move the cursor to make it look like it is\r
-       // locked to a point on the landscape (we need to take account of\r
-       // sub-pixel error from previous frames)\r
-    static float mouseDeltaX = 0.0f;\r
-    static float mouseDeltaY = 0.0f;\r
-    mouseDeltaX += (newMouseX - oldMouseX) * 1.0f;\r
-    mouseDeltaY += (newMouseY - oldMouseY) * 1.0f;\r
-    int intMouseDeltaX = floorf(mouseDeltaX);\r
-    int intMouseDeltaY = floorf(mouseDeltaY);\r
-    mouseDeltaX -= intMouseDeltaX;\r
-    mouseDeltaY -= intMouseDeltaY;\r
-       newMouseX = g_target->X() + intMouseDeltaX;\r
-       newMouseY = g_target->Y() + intMouseDeltaY;\r
-\r
-       // Make sure these movements don't put the mouse cursor somewhere stupid\r
-       if (newMouseX < 0)                              newMouseX = 0;\r
-       if (newMouseX >= screenW)               newMouseX = screenW - 1;\r
-       if (newMouseY < 0)                              newMouseY = 0;\r
-       if (newMouseY >= screenH)               newMouseY = screenH - 1;\r
-\r
-       // Apply the mouse cursor movement\r
-//alleg    position_mouse(newMouseX, newMouseY);\r
-       g_target->SetMousePos(newMouseX, newMouseY);\r
-    glPopMatrix();\r
-}\r
-\r
-\r
-void Camera::AdvanceFirstPersonMode()\r
-{\r
-    if( g_inputManager->controlEvent( ControlCameraFreeMovement ) )\r
-    {\r
-        RequestMode(Camera::ModeFreeMovement);\r
-        return;\r
-    }\r
-\r
-       // JAMES_TODO: Support directional firing mode\r
-       if( g_inputManager->controlEvent( ControlUnitPrimaryFireTarget ) )\r
-    {\r
-        static float lastFire = 0.0f;\r
-        if( GetHighResTime() > lastFire )\r
-        {\r
-            Vector3 from = m_pos +\r
-                           GetRight() * -2.0f +\r
-                           GetUp() * -3.0f;\r
-            g_app->m_location->FireLaser( from, m_front * 200.0f, 3 );\r
-            lastFire = GetHighResTime() + 0.1f;\r
-        }\r
-    }\r
-\r
-    //\r
-    // Allow quake keys to move us\r
-    \r
-    Vector3 accelForward = m_front;\r
-    accelForward.y = 0.0f;\r
-    accelForward.Normalise();\r
-    Vector3 accelRight = GetRight();\r
-    accelRight.y = 0.0f;\r
-    accelRight.Normalise();\r
-    float moveRate = 100.0f;\r
-//    if (g_controlBindings->CameraLeft())             m_vel += accelRight * g_advanceTime * moveRate;\r
-//     if (g_controlBindings->CameraRight())           m_vel -= accelRight * g_advanceTime * moveRate;\r
-//     if (g_controlBindings->CameraForwards())        m_vel += accelForward * g_advanceTime * moveRate * 2.0f;\r
-//     if (g_controlBindings->CameraBackwards())       m_vel -= accelForward * g_advanceTime * moveRate;\r
-\r
-\r
-    //\r
-    // Update our position and orientation\r
-\r
-    m_vel *= 0.9993f;\r
-    m_pos += g_advanceTime * m_vel;       \r
-\r
-    int mx=0, my=0;\r
-       mx = g_target->dX();\r
-       my = g_target->dY();\r
-\r
-    Matrix33 mat(1);\r
-       mat.RotateAroundY((float)mx * -0.01f);\r
-       m_up = m_up * mat;\r
-       m_front = m_front * mat;\r
-\r
-    Vector3 right = GetRight();\r
-       mat.SetToIdentity();\r
-       mat.RotateAround(right, (float)my * 0.01f);\r
-       m_up = m_up * mat;\r
-       m_front = m_front * mat;\r
-\r
-    float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue( m_pos.x, m_pos.z );\r
-    m_pos.y = landHeight + 3.0f;\r
-}\r
-\r
-\r
-void Camera::AdvanceMoveToTargetMode()\r
-{\r
-       double currentTimeFraction = (g_gameTime - m_startTime) / m_moveDuration;\r
-    currentTimeFraction = max( currentTimeFraction, 0.2f );\r
-\r
-\r
-       // Pos\r
-       Vector3 direction = m_targetPos - m_startPos;\r
-       float dist = direction.Mag();\r
-       direction /= dist;\r
-       float maxSpeed = (2.0f * dist) / m_moveDuration;\r
-       \r
-       // Orientation\r
-       Vector3 fullRotationDirection = m_startFront ^ m_targetFront;\r
-       Vector3 middleFront = m_startFront;\r
-       middleFront.RotateAround(fullRotationDirection * 0.5f);\r
-\r
-       if (currentTimeFraction < 0.5)\r
-       {\r
-               m_pos += direction * maxSpeed * 2.0 * currentTimeFraction * g_advanceTime;\r
-               float amount2 = RampUpAndDown(m_startTime, m_moveDuration, g_gameTime) * 2.0f;\r
-               float amount1 = 1.0f - amount2;\r
-               m_front = (m_startFront * amount1 + middleFront * amount2).Normalise();\r
-       }\r
-       else if (currentTimeFraction < 1.0)\r
-       {\r
-               m_pos += direction * maxSpeed * 2.0 * (1.0 - currentTimeFraction) * g_advanceTime;\r
-               float amount2 = (RampUpAndDown(m_startTime, m_moveDuration, g_gameTime) - 0.5f) * 2.0f;\r
-               float amount1 = 1.0f - amount2;\r
-               m_front = (middleFront * amount1 + m_targetFront * amount2).Normalise();\r
-       }\r
-       else\r
-       {\r
-               RequestMode(Camera::ModeDoNothing);\r
-               m_front = m_targetFront;\r
-       }\r
-    \r
-       m_front.Normalise();\r
-       m_up = g_upVector;\r
-    //Vector3 right = m_front ^ m_up;\r
-       //right.Normalise();\r
-       //m_up = right ^ m_front;\r
-       //m_up.Normalise();\r
-\r
-       //float dot = m_front * m_up;\r
-       //dot *= 1.0f;\r
-}\r
-\r
-\r
-void Camera::AdvanceEntityFollowMode()\r
-{\r
-    Entity *obj = (Entity*)g_app->m_location->GetEntity( m_objectId );    \r
-    if( !obj ) \r
-    {\r
-        RequestMode(Camera::ModeFreeMovement);\r
-        return;\r
-    }\r
-\r
-\r
-       //\r
-       // Get X and Y mouse move\r
-       \r
-       int halfHeight = g_app->m_renderer->ScreenH() / 2;\r
-       int halfWidth = g_app->m_renderer->ScreenW() / 2;\r
-       int deltaX = g_target->X() - halfWidth;\r
-       int deltaY = g_target->Y() - halfHeight;\r
-       g_target->SetMousePos(halfWidth, halfHeight);\r
-       \r
-\r
-       //\r
-       // Get Z mouse move\r
-\r
-       m_distFromEntity *= 1.0f + ((float)g_target->dZ() * -0.1f);\r
-       float radius = 15.0f;\r
-       if (m_distFromEntity < radius)\r
-       {\r
-               m_distFromEntity = radius;\r
-       }\r
-       else if (m_distFromEntity > 5000.0f)\r
-       {\r
-               m_distFromEntity = 5000.0f;\r
-       }\r
-\r
-       \r
-       // \r
-       // Do rotation\r
-\r
-       float rotY = (float)deltaX * -0.015f;\r
-       float rotRight = (float)deltaY * -0.01f;\r
-\r
-    m_front.RotateAroundY(rotY);\r
-    Vector3 right = (m_front ^ g_upVector).Normalise();\r
-       Vector3 newUp(m_up);\r
-       newUp.RotateAround(right * rotRight);\r
-       if (newUp.y > 0.1f)\r
-       {\r
-               m_front.RotateAround(right * rotRight);\r
-       }\r
-    m_up = (right ^ m_front).Normalise();\r
-\r
-\r
-       //\r
-       // Update position\r
-\r
-       float factor1 = g_advanceTime * 5.0f;\r
-       float factor2 = 1.0f - factor1;\r
-    Vector3 newTargetPos = obj->m_pos + g_predictionTime * obj->m_vel;\r
-       m_targetPos = factor1 * newTargetPos + factor2 * m_targetPos;\r
-       m_pos = m_targetPos - m_front * m_distFromEntity;\r
-}\r
-\r
-\r
-\r
-// **************\r
-// Public Methods\r
-// **************\r
-\r
-// *** Constructor\r
-Camera::Camera()\r
-:   m_fov(60.0f),\r
-    m_targetFov(60.0f),\r
-    m_height(50.0f),\r
-    m_vel(0,0,0),\r
-    m_mode(ModeDoNothing),\r
-       m_debugMode(DebugModeAuto),\r
-    m_objectId(),\r
-       m_framesInThisMode(0),\r
-       m_distFromEntity(100.0f),\r
-       m_anim(NULL),\r
-    m_cameraShake(0.0f),\r
-    m_entityTrack(false),\r
-       m_trackingEntity(NULL),\r
-    m_currentDistance(0.0f),\r
-       m_heightMultiplier(1.0f),\r
-       m_skipDirectionCalculation(false)\r
-{\r
-       m_cosFov = cos(m_fov / 180.0f * M_PI);\r
-    m_pos = Vector3(1000.0f, //g_app->m_location->m_landscape.GetWorldSizeX() / 2.0f, \r
-                                       500.0f,\r
-                                       1000.0f);//g_app->m_location->m_landscape.GetWorldSizeZ() / 2.0f);\r
-\r
-       m_minX = -1e6;\r
-       m_maxX = 1e6;\r
-       m_minZ = -1e6;\r
-       m_maxZ = 1e6;\r
-    \r
-    //m_front = Vector3(0, -0.7f, 1);\r
-    m_front.Set( 0,-0.5f,-1 );\r
-    m_front.Normalise();\r
-    \r
-    m_up = g_upVector;\r
-    Vector3 right = m_up ^ m_front;\r
-    right.Normalise();\r
-\r
-    m_up = m_front ^ right;\r
-    m_up.Normalise();\r
-\r
-       m_controlVector = right;\r
-}\r
-\r
-\r
-void Camera::CreateCameraShake(float _intensity)\r
-{\r
-    m_cameraShake = max( m_cameraShake, _intensity );\r
-}\r
-\r
-\r
-void Camera::SetupProjectionMatrix(float _nearPlane, float _farPlane)\r
-{\r
-       //DarwiniaDebugAssert(m_fov > 0.0f);\r
-       //DarwiniaDebugAssert(m_fov < 180.0f);\r
-\r
-    clamp( m_fov, 1, 180 );\r
-\r
-       g_app->m_renderer->SetNearAndFar(_nearPlane, _farPlane);\r
-       g_app->m_renderer->SetupProjMatrixFor3D();\r
-\r
-       float fovRadians = m_fov * M_PI / 180.0f;\r
-       m_cosFov = cosf(fovRadians);\r
-\r
-       // m_fov is actually the vertical fov. We need a fov covering\r
-       // the long diagonal of the screen for visibility checking.\r
-\r
-       float screenW = g_app->m_renderer->ScreenW();\r
-       float screenWHalf = screenW / 2.0;\r
-       float screenH = g_app->m_renderer->ScreenH();\r
-       float screenHHalf = screenH / 2.0;\r
-       \r
-       // Distance from camera to top-centre and bottom-centre of screen \r
-       float dtc = screenHHalf / sin(fovRadians/2.0);\r
-       \r
-       // Distance from camera to any corner of the screen\r
-       float dc = sqrt( dtc*dtc + screenWHalf*screenWHalf );\r
-       \r
-       // Half distance from one corner of the screen to the diagonally opposite corner\r
-       float ddHalf = sqrt(screenW * screenW + screenH * screenH) / 2.0;       \r
-       \r
-       m_maxFovRadians = 2.0 * asin(ddHalf/dc);\r
-}\r
-\r
-\r
-void Camera::SetupModelviewMatrix()\r
-{\r
-       float dot = m_front * m_up;\r
-       DarwiniaDebugAssert(NearlyEquals(m_front.MagSquared(), 1.0f));\r
-       DarwiniaDebugAssert(NearlyEquals(m_up.MagSquared(), 1.0f));\r
-       DarwiniaDebugAssert(NearlyEquals(dot, 0.0f));\r
-\r
-    glMatrixMode(GL_MODELVIEW);\r
-    glLoadIdentity();\r
-       float magOfPos = m_pos.Mag();\r
-       Vector3 front = m_front * magOfPos;\r
-       Vector3 up = m_up * magOfPos;\r
-       Vector3 forwards = m_pos + front;\r
-       gluLookAt(m_pos.x, m_pos.y, m_pos.z,\r
-              forwards.x, forwards.y, forwards.z,\r
-              up.x, up.y, up.z);\r
-}\r
-\r
\r
-bool Camera::PosInViewFrustum(Vector3 const &_pos)\r
-{\r
-       Vector3 dirToPos = (_pos - m_pos).Normalise();\r
-       float angle = dirToPos * m_front;\r
-       float fovInRadians = m_cosFov;\r
-    float tolerance = 0.2f;\r
-       if (angle < fovInRadians - tolerance)\r
-       {\r
-               return false;\r
-       }\r
-       return true;\r
-}\r
-\r
-\r
-bool Camera::SphereInViewFrustum(Vector3 const &_centre, float _radius )\r
-{\r
-    Vector3 dirToPos = _centre - m_pos;\r
-    float distance = dirToPos.Mag();\r
-    if( distance < _radius ) return true;\r
-\r
-    float angularSize = asinf(_radius / distance);\r
-    float angle = acosf( dirToPos.Normalise() * m_front );\r
-\r
-       return angle - angularSize <= m_maxFovRadians / 2;\r
-}\r
-\r
-\r
-Building *Camera::GetBestBuildingInView()\r
-{\r
-    static float s_recalculateTimer = 0;\r
-    static int s_buildingId = -1;\r
-\r
-    if( GetVel().Mag() > 5.0f )\r
-    {\r
-        // We are moving too fast to be focussing on a building\r
-        s_buildingId = -1;\r
-    }\r
-    else if( !g_app->m_location )\r
-    {\r
-        // We aren't in a location\r
-        s_buildingId = -1;\r
-    }\r
-    else\r
-    {\r
-        if( GetHighResTime() > s_recalculateTimer + 1.0f )\r
-        {\r
-               Vector3 rayStart;\r
-               Vector3 rayDir;\r
-               GetClickRay(g_app->m_renderer->ScreenW()/2, \r
-                                   g_app->m_renderer->ScreenH()/2, &rayStart, &rayDir);\r
-\r
-            float nearest = 200.0f;\r
-            s_buildingId = -1;         \r
-\r
-            for( int i = 0; i < g_app->m_location->m_buildings.Size(); ++i )\r
-            {\r
-                if( g_app->m_location->m_buildings.ValidIndex(i) )\r
-                {\r
-                    Building *building = g_app->m_location->m_buildings[i];\r
-                    if( building->DoesRayHit( rayStart, rayDir ) )\r
-                    {\r
-                        float distance = ( building->m_pos - m_pos ).Mag();\r
-                        if( distance < nearest )\r
-                        {\r
-                            nearest = distance;\r
-                            s_buildingId = building->m_id.GetUniqueId();\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-\r
-            s_recalculateTimer = GetHighResTime();\r
-        }\r
-    }\r
-    \r
-    return g_app->m_location->GetBuilding( s_buildingId );\r
-}\r
-\r
-\r
-void Camera::AdvanceComponentZoom()\r
-{\r
-       // No zoom inside the task manager \r
-    if( g_app->m_taskManagerInterface->m_visible ||\r
-        IsInMode( ModeEntityTrack ) )\r
-    {\r
-        return;\r
-    }\r
-\r
-    float change = 30.0f;    \r
-       float adjustedTargetFov = m_targetFov;\r
-\r
-       // JAMES CHECK:\r
-    if( g_inputManager->controlEvent( ControlCameraZoom ) )\r
-    {\r
-        adjustedTargetFov /= 4.0f;\r
-        change = 100.0f;\r
-        g_app->m_helpSystem->PlayerDoneAction( HelpSystem::CameraZoom );\r
-    }\r
-\r
-    if( m_mode == ModeSphereWorldScripted )\r
-    {\r
-        change = 10.0f;\r
-    }\r
-\r
-    if( m_mode == ModeMoveToTarget || \r
-        m_mode == ModeDoNothing ||\r
-        m_mode == ModeBuildingFocus )\r
-    {\r
-        change = 1.0f;\r
-    }\r
-    \r
-//    if( m_fov < adjustedTargetFov )\r
-//    {\r
-//        m_fov += change * g_advanceTime;\r
-//        if( m_fov > adjustedTargetFov )\r
-//        {\r
-//            m_fov = adjustedTargetFov;\r
-//        }\r
-//    }\r
-//    else if( m_fov > adjustedTargetFov )\r
-//    {\r
-//        m_fov -= change * g_advanceTime; \r
-//        if( m_fov < adjustedTargetFov )\r
-//        {\r
-//            m_fov = adjustedTargetFov;\r
-//        }\r
-//    }\r
-\r
-    float factor = g_advanceTime * change * 0.1f;\r
-    m_fov = m_fov * (1-factor) + adjustedTargetFov * factor;\r
-\r
-//    if( m_cameraShake > 0.0f )\r
-//    {\r
-//        m_fov += sfrand( m_cameraShake * 10.0f );\r
-//        m_cameraShake -= SERVER_ADVANCE_PERIOD;\r
-//    }\r
-}\r
-\r
-\r
-void Camera::AdvanceComponentMouseWheelHeight()\r
-{\r
-       float delta = g_target->dZ();\r
-\r
-    if( EclGetWindows()->Size() == 0 )\r
-    {\r
-        bool keyUp   = g_inputManager->controlEvent( ControlCameraUp );\r
-        bool keyDown = g_inputManager->controlEvent( ControlCameraDown );\r
-        if (keyUp)          delta += g_advanceTime * 7.0f;\r
-        if (keyDown)        delta -= g_advanceTime * 7.0f;\r
-        if( keyUp || keyDown )\r
-        {\r
-            g_app->m_helpSystem->PlayerDoneAction( HelpSystem::CameraHeight );\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraUp);\r
-                   g_app->m_controlHelpSystem->RecordCondUsed(ControlHelpSystem::CondCameraDown);\r
-        }\r
-    }\r
-       \r
-       if( g_app->m_location)\r
-    {\r
-               float landheight = g_app->m_location->m_landscape.m_heightMap->GetValue(m_pos.x, m_pos.z);\r
-               if (landheight < MIN_HEIGHT) landheight = MIN_HEIGHT;\r
-               float altitude = m_height - landheight;\r
-               m_height += delta * 2.0f * sqrtf(fabsf(altitude));\r
-        \r
-               if (m_mode == ModeTurretAim)\r
-        {\r
-            m_height = max( m_height, MIN_GROUND_CLEARANCE );\r
-        }\r
-        else\r
-        {\r
-            if(landheight + MIN_GROUND_CLEARANCE > m_height)           \r
-            {\r
-                           m_height = landheight + MIN_GROUND_CLEARANCE;\r
-            }\r
-               }\r
-\r
-               if (m_height > MAX_HEIGHT) m_height = MAX_HEIGHT;\r
-\r
-        g_app->m_helpSystem->PlayerDoneAction( HelpSystem::CameraHeight );\r
-    }\r
-    else\r
-    {\r
-        m_height += delta * (m_height * 0.1f + 5.0f);\r
-               if (m_height < 0.0f)                    m_height = 0.1f;\r
-               else if (m_height > 1000.0f)    m_height = 1000.0f;\r
-    }\r
-}\r
-\r
-\r
-void Camera::AdvanceAnim()\r
-{\r
-       CamAnimNode *node = m_anim->m_nodes[m_animCurrentNode];\r
-       float finishTime = m_animNodeStartTime + node->m_duration;\r
-       \r
-       if (g_gameTime > finishTime)\r
-       {\r
-               switch (node->m_transitionMode)\r
-               {\r
-               case CamAnimNode::TransitionMove:\r
-                       break;\r
-               case CamAnimNode::TransitionCut:\r
-                       CutToTarget();\r
-                       break;\r
-               }\r
-\r
-               m_animCurrentNode++;\r
-               if (m_animCurrentNode < m_anim->m_nodes.Size())\r
-               {\r
-                       node = m_anim->m_nodes[m_animCurrentNode];\r
-                       SetTarget(node->m_mountName);\r
-                       m_animNodeStartTime = g_gameTime;\r
-\r
-                       switch (node->m_transitionMode)\r
-                       {\r
-                       case CamAnimNode::TransitionMove:\r
-                               RequestMode(ModeMoveToTarget);\r
-                               SetMoveDuration(node->m_duration);\r
-                               break;\r
-                       case CamAnimNode::TransitionCut:\r
-                               RequestMode(ModeDoNothing);\r
-                               break;\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       RequestMode(m_modeBeforeAnim);\r
-                       m_anim = NULL;\r
-               }\r
-       }\r
-}\r
-\r
-void Camera::AdvanceMainMenuMode()\r
-{\r
-    m_pos.RotateAroundZ(0.0005f);\r
-    m_pos.RotateAroundY(0.0005f);\r
-    float factor1 = g_advanceTime * 2.0f;\r
-    float factor2 = 1.0f - factor1;\r
-\r
-    Vector3 targetFront(0,0,0);\r
-    //Vector3 targetFront(50000, 50000, 50000);\r
-    m_front = m_front * factor2 + targetFront * factor1;\r
-    m_up.Set( 0.0f, -1.0f, 0.0f );\r
-    Vector3 right = m_up ^ m_front;\r
-    m_up = right ^ m_front; \r
-}\r
-\r
-void Camera::Advance()\r
-{\r
-    START_PROFILE(g_app->m_profiler, "Advance Camera");\r
-    \r
-       if (m_anim)\r
-       {\r
-               AdvanceAnim();\r
-       }\r
-\r
-       // Toggle entity tracking\r
-       /*if (g_inputManager->controlEvent( ControlCameraSwitchMode ))\r
-               m_entityTrack = !m_entityTrack;*/\r
-\r
-//     switch (m_mode)\r
-//     {\r
-//             case ModeReplay:\r
-//             case ModeSphereWorld:   \r
-//             case ModeFreeMovement:  \r
-//             case ModeBuildingFocus: \r
-//             case ModeEntityTrack:   \r
-//             case ModeRadarAim:      \r
-//             case ModeFirstPerson:\r
-//             case ModeEntityFollow:\r
-//        case ModeTurretAim:\r
-//        case ModeMoveToTarget:\r
-//        case ModeSphereWorldScripted:\r
-                       AdvanceComponentZoom();\r
-//     }\r
-\r
-       switch (m_mode)\r
-       {\r
-               case ModeSphereWorld:   \r
-               case ModeFreeMovement:  \r
-               case ModeBuildingFocus: \r
-               case ModeEntityTrack:   \r
-               case ModeRadarAim:      \r
-               case ModeFirstPerson:  \r
-        case ModeTurretAim:\r
-                       AdvanceComponentMouseWheelHeight();\r
-       }\r
-\r
-       // \r
-       // Pick an advancer\r
-\r
-       if( m_anim == NULL &&\r
-                  (m_debugMode == DebugModeAlways ||\r
-                  (m_debugMode == DebugModeAuto && EclGetWindows()->Size() > 0) ||\r
-                  m_framesInThisMode < 2 ) )\r
-       {\r
-               g_windowManager->EnsureMouseUncaptured();\r
-               AdvanceDebugMode();\r
-       }\r
-       else\r
-       {\r
-               g_windowManager->EnsureMouseCaptured();\r
-               switch(m_mode)\r
-               {\r
-                       case ModeSphereWorld:               AdvanceSphereWorldMode();               break;\r
-                       case ModeFreeMovement:          AdvanceFreeMovementMode();          break;\r
-                       case ModeBuildingFocus:         AdvanceBuildingFocusMode();         break;\r
-                       case ModeEntityTrack:           AdvanceEntityTrackMode();           break;\r
-                       case ModeRadarAim:              AdvanceRadarAimMode();              break;\r
-                       case ModeFirstPerson:           AdvanceFirstPersonMode();           break;\r
-                       case ModeMoveToTarget:              AdvanceMoveToTargetMode();              break;\r
-                       case ModeEntityFollow:              AdvanceEntityFollowMode();              break;\r
-            case ModeTurretAim:             AdvanceTurretAimMode();             break;\r
-            case ModeSphereWorldScripted:   AdvanceSphereWorldScriptedMode();   break;\r
-            case ModeSphereWorldIntro:      AdvanceSphereWorldIntroMode();      break;\r
-            case ModeSphereWorldOutro:      AdvanceSphereWorldOutroMode();      break;\r
-            case ModeSphereWorldFocus:      AdvanceSphereWorldFocusMode();      break;\r
-            case ModeMainMenu:              AdvanceMainMenuMode();              break;\r
-               }\r
-       }\r
-\r
-    \r
-    if( m_cameraShake > 0.0f )\r
-    {\r
-        m_front.RotateAroundY( sfrand(m_cameraShake * 0.05f) );\r
-        Vector3 up = g_upVector;\r
-        up.RotateAround( m_front * sfrand(m_cameraShake) * 0.3f );\r
-        Vector3 right = m_front ^ up;\r
-        right.Normalise();\r
-               m_front.Normalise();\r
-        m_up = right ^ m_front;\r
-        m_cameraShake -= g_advanceTime;\r
-    }\r
-\r
-       Normalise();\r
-\r
-       ASSERT_VECTOR3_IS_SANE(m_pos);\r
-       float dot = m_front * m_up;\r
-       DarwiniaDebugAssert(NearlyEquals(dot, 0.0f));\r
-\r
-       g_app->m_userInput->RecalcMousePos3d();\r
-\r
-       m_framesInThisMode++;\r
-\r
-    END_PROFILE(g_app->m_profiler, "Advance Camera");\r
-}\r
-\r
-int Camera::GetDebugMode()\r
-{\r
-       return m_debugMode;\r
-}\r
-\r
-void Camera::SetDebugMode(int _mode)\r
-{\r
-       m_debugMode = _mode;\r
-}\r
-\r
-void Camera::SetNextDebugMode()\r
-{\r
-       m_debugMode++;\r
-       if (m_debugMode >= Camera::DebugModeNumStates)\r
-       {\r
-               m_debugMode = 0;\r
-       }\r
-}\r
-\r
-void Camera::RequestMode(int _mode)\r
-{\r
-       DarwiniaDebugAssert(_mode >= 0 && _mode < ModeNumModes);\r
-       int screenW = g_app->m_renderer->ScreenW();\r
-       int screenH = g_app->m_renderer->ScreenH();\r
-\r
-       //m_targetFov = 60.0f;\r
-       m_framesInThisMode = 0;\r
-       m_mode = _mode;\r
-\r
-       switch (_mode)\r
-       {\r
-               case ModeSphereWorld:\r
-                       g_target->SetMousePos(screenW/2, screenH/2);\r
-                       m_pos.Set(1000, 500, 15000);\r
-                       break;\r
-               case ModeFreeMovement:\r
-                       m_targetPos = m_pos;\r
-                       m_height = m_pos.y;\r
-            m_targetFov = 60.0f;\r
-                       g_target->SetMousePos(screenW/2, screenH/2);\r
-                       break;\r
-               case ModeMoveToTarget:\r
-                       m_startPos = m_pos;\r
-                       m_startFront = m_front;\r
-                       m_startUp = m_up;\r
-                       m_startTime = g_gameTime;\r
-                       break;\r
-       }\r
-}\r
-\r
-void Camera::RequestBuildingFocusMode( Building *_building, float _range, float _height )\r
-{\r
-       m_framesInThisMode = 0;\r
-    m_mode = ModeBuildingFocus;\r
-    m_targetPos = _building->m_centrePos;\r
-    m_trackRange = _range;\r
-    m_trackHeight = _height;\r
-    m_trackTimer = GetHighResTime();\r
-\r
-    m_trackVector = ( m_pos - _building->m_pos );\r
-    m_trackVector.y = 0.0f;\r
-    m_trackVector.Normalise();\r
-\r
-    m_targetFov = 60.0f;\r
-}\r
-\r
-\r
-void Camera::RequestRadarAimMode( Building *_building )\r
-{\r
-       m_framesInThisMode = 0;\r
-    m_mode = ModeRadarAim;\r
-    m_targetPos = _building->m_pos;\r
-\r
-    g_app->m_helpSystem->PlayerDoneAction( HelpSystem::UseRadarDish );\r
-}\r
-\r
-\r
-void Camera::RequestTurretAimMode(Building *_building)\r
-{\r
-    m_framesInThisMode = 0;\r
-    m_mode = ModeTurretAim;\r
-    m_objectId = _building->m_id;\r
-    m_targetPos = _building->m_pos;\r
-}\r
-\r
-\r
-void Camera::RequestEntityTrackMode( WorldObjectId const &_id )\r
-{\r
-       m_framesInThisMode = 0;\r
-    m_mode = ModeEntityTrack;\r
-\r
-    m_distFromEntity = 200.0f;\r
-    m_objectId = _id;\r
-    m_trackHeight = 0.0f;\r
-    m_cameraTarget = m_pos;\r
-\r
-       // Snap the camera to the look at the unit\r
-    Entity *entity = g_app->m_location->GetEntity( _id );\r
-    if( entity )\r
-    {\r
-        m_targetPos = entity->m_pos;\r
-    }\r
-}\r
-\r
-void Camera::RequestEntityFollowMode( WorldObjectId const &_id )\r
-{\r
-       m_framesInThisMode = 0;\r
-    m_mode = ModeEntityFollow;\r
-    m_objectId = _id;\r
-}\r
-\r
-\r
-bool Camera::IsMoving()\r
-{\r
-       return m_mode == ModeMoveToTarget;\r
-}\r
-\r
-\r
-bool Camera::IsInteractive()\r
-{\r
-    //if( g_app->m_script->IsRunningScript() ) return false;\r
-    \r
-    return ( m_mode == ModeSphereWorld ||\r
-             m_mode == ModeFreeMovement ||\r
-             m_mode == ModeRadarAim ||\r
-             m_mode == ModeTurretAim ||\r
-             m_mode == ModeEntityTrack );\r
-}\r
-\r
-\r
-bool Camera::IsInMode(int _mode)\r
-{\r
-    return( m_mode == _mode );\r
-}\r
-\r
-\r
-void Camera::SetTarget(Vector3 co