├── Buckland_Chapter2-State Machines ├── WestWorld1 │ ├── BaseGameEntity.cpp │ ├── BaseGameEntity.h │ ├── EntityNames.h │ ├── Locations.h │ ├── Miner.cpp │ ├── Miner.h │ ├── MinerOwnedStates.cpp │ ├── MinerOwnedStates.h │ ├── State.h │ ├── WestWorld1.dep │ ├── WestWorld1.dsp │ ├── WestWorld1.dsw │ ├── WestWorld1.mak │ └── main.cpp ├── WestWorldWithMessaging │ ├── BaseGameEntity.cpp │ ├── BaseGameEntity.h │ ├── EntityManager.cpp │ ├── EntityManager.h │ ├── EntityNames.h │ ├── Locations.h │ ├── MessageDispatcher.cpp │ ├── MessageDispatcher.h │ ├── MessageTypes.h │ ├── Miner.cpp │ ├── Miner.h │ ├── MinerOwnedStates.cpp │ ├── MinerOwnedStates.h │ ├── MinersWife.cpp │ ├── MinersWife.h │ ├── MinersWifeOwnedStates.cpp │ ├── MinersWifeOwnedStates.h │ ├── WestWorldWithMessaging.dep │ ├── WestWorldWithMessaging.dsp │ ├── WestWorldWithMessaging.dsw │ ├── WestWorldWithMessaging.mak │ └── main.cpp └── WestWorldWithWoman │ ├── BaseGameEntity.cpp │ ├── BaseGameEntity.h │ ├── EntityNames.h │ ├── Locations.h │ ├── Miner.cpp │ ├── Miner.h │ ├── MinerOwnedStates.cpp │ ├── MinerOwnedStates.h │ ├── MinersWife.cpp │ ├── MinersWife.h │ ├── MinersWifeOwnedStates.cpp │ ├── MinersWifeOwnedStates.h │ ├── State.h │ ├── StateMachine.h │ ├── WestWorldWithWomen.dep │ ├── WestWorldWithWomen.dsp │ ├── WestWorldWithWomen.dsw │ ├── WestWorldWithWomen.mak │ └── main.cpp ├── Buckland_Chapter3-Steering Behaviors ├── BaseGameEntity.h ├── EntityFunctionTemplates.h ├── GameWorld.cpp ├── GameWorld.h ├── MovingEntity.h ├── Obstacle.cpp ├── Obstacle.h ├── ParamLoader.cpp ├── ParamLoader.h ├── Path.cpp ├── Path.h ├── Script1.aps ├── Script1.rc ├── Steering.dep ├── Steering.dsp ├── Steering.dsw ├── Steering.mak ├── SteeringBehaviors.cpp ├── SteeringBehaviors.h ├── Vehicle.cpp ├── Vehicle.h ├── constants.h ├── main.cpp ├── params.ini └── resource.h ├── Buckland_Chapter4-SimpleSoccer ├── FieldPlayer.cpp ├── FieldPlayer.h ├── FieldPlayerStates.cpp ├── FieldPlayerStates.h ├── Goal.cpp ├── Goal.h ├── GoalKeeperStates.cpp ├── GoalKeeperStates.h ├── Goalkeeper.cpp ├── Goalkeeper.h ├── ParamLoader.cpp ├── ParamLoader.h ├── Params.ini ├── PlayerBase.cpp ├── PlayerBase.h ├── Script1.aps ├── Script1.rc ├── SimpleSoccer.dep ├── SimpleSoccer.dsp ├── SimpleSoccer.dsw ├── SimpleSoccer.mak ├── SoccerBall.cpp ├── SoccerBall.h ├── SoccerMessages.cpp ├── SoccerMessages.h ├── SoccerPitch.cpp ├── SoccerPitch.h ├── SoccerTeam.cpp ├── SoccerTeam.h ├── SteeringBehaviors.cpp ├── SteeringBehaviors.h ├── SupportSpotCalculator.cpp ├── SupportSpotCalculator.h ├── TeamStates.cpp ├── TeamStates.h ├── constants.h ├── icon1.ico ├── main.cpp └── resource.h ├── Buckland_Chapter5-Pathfinder ├── Pathfinder.cpp ├── Pathfinder.dep ├── Pathfinder.dsp ├── Pathfinder.dsw ├── Pathfinder.h ├── Pathfinder.mak ├── constants.h ├── icon1.ico ├── main.cpp ├── no_obstacles_source_target_close.map ├── resource.h ├── test_with_walls.map ├── toolbar.aps ├── toolbar.rc └── toolbar1.bmp ├── Buckland_Chapter6_Scripting_Source ├── CreatingClassesUsingLuabind │ ├── CreatingClassesUsingLuabind.dep │ ├── CreatingClassesUsingLuabind.dsp │ ├── CreatingClassesUsingLuabind.dsw │ ├── CreatingClassesUsingLuabind.mak │ ├── classes_in_lua.lua │ └── main.cpp ├── ExposingCPPClassesUsingLuabind │ ├── Animal.h │ ├── ExposingCPPClassesToLua.lua │ ├── ExposingCPPClassesUsingLuabind.dep │ ├── ExposingCPPClassesUsingLuabind.dsp │ ├── ExposingCPPClassesUsingLuabind.dsw │ ├── ExposingCPPClassesUsingLuabind.mak │ ├── Pet.h │ └── main.cpp ├── ExposingCPPFunctionsUsingLuabind │ ├── ExposingCPPFunctionsToLua.lua │ ├── ExposingCPPFunctionsUsingLuabind.dep │ ├── ExposingCPPFunctionsUsingLuabind.dsp │ ├── ExposingCPPFunctionsUsingLuabind.dsw │ ├── ExposingCPPFunctionsUsingLuabind.mak │ └── main.cpp ├── ScriptedStateMachine │ ├── Entity.h │ ├── Miner.cpp │ ├── Miner.h │ ├── ScriptedStateMachine.dep │ ├── ScriptedStateMachine.dsp │ ├── ScriptedStateMachine.dsw │ ├── ScriptedStateMachine.h │ ├── ScriptedStateMachine.mak │ ├── StateMachineScript.lua │ └── main.cpp ├── StartHere │ ├── StartHere.dep │ ├── StartHere.dsp │ ├── StartHere.dsw │ ├── StartHere.mak │ ├── StartHere.ncb │ ├── StartHere.opt │ ├── main.cpp │ └── your_first_lua_script.lua ├── cpp_using_lua │ ├── cpp_using_lua.dep │ ├── cpp_using_lua.dsp │ ├── cpp_using_lua.dsw │ ├── cpp_using_lua.lua │ ├── cpp_using_lua.mak │ ├── cpp_using_lua.suo │ └── main.cpp └── lua_using_cpp │ ├── RockPaperScissors.h │ ├── Rock_Paper_Scissors_Using_C++_Funcs.lua │ ├── lua_using_cpp.dep │ ├── lua_using_cpp.dsp │ ├── lua_using_cpp.dsw │ ├── lua_using_cpp.mak │ └── main.cpp ├── Buckland_Chapter7 to 10_Raven ├── GraveMarkers.cpp ├── GraveMarkers.h ├── Map Editor │ ├── MapEditor.exe │ └── MapEditorParams.ini ├── Params.lua ├── Raven.dep ├── Raven.dsp ├── Raven.dsw ├── Raven.mak ├── Raven_Bot.cpp ├── Raven_Bot.h ├── Raven_Door.cpp ├── Raven_Door.h ├── Raven_Game.cpp ├── Raven_Game.h ├── Raven_Map.cpp ├── Raven_Map.h ├── Raven_Messages.h ├── Raven_ObjectEnumerations.h ├── Raven_SensoryMemory.cpp ├── Raven_SensoryMemory.h ├── Raven_SteeringBehaviors.cpp ├── Raven_SteeringBehaviors.h ├── Raven_Target.h ├── Raven_TargetingSystem.cpp ├── Raven_TargetingSystem.h ├── Raven_UserOptions.cpp ├── Raven_UserOptions.h ├── Raven_WeaponSystem.cpp ├── Raven_WeaponSystem.h ├── Script1.aps ├── Script1.clw ├── Script1.rc ├── armory │ ├── Projectile_Bolt.cpp │ ├── Projectile_Bolt.h │ ├── Projectile_Pellet.cpp │ ├── Projectile_Pellet.h │ ├── Projectile_Rocket.cpp │ ├── Projectile_Rocket.h │ ├── Projectile_Slug.cpp │ ├── Projectile_Slug.h │ ├── Raven_Projectile.cpp │ ├── Raven_Projectile.h │ ├── Raven_Weapon.cpp │ ├── Raven_Weapon.h │ ├── Weapon_Blaster.cpp │ ├── Weapon_Blaster.h │ ├── Weapon_RailGun.cpp │ ├── Weapon_RailGun.h │ ├── Weapon_RocketLauncher.cpp │ ├── Weapon_RocketLauncher.h │ ├── Weapon_ShotGun.cpp │ └── Weapon_ShotGun.h ├── constants.h ├── goals │ ├── AttackTargetGoal_Evaluator.cpp │ ├── AttackTargetGoal_Evaluator.h │ ├── ExploreGoal_Evaluator.cpp │ ├── ExploreGoal_Evaluator.h │ ├── GetHealthGoal_Evaluator.cpp │ ├── GetHealthGoal_Evaluator.h │ ├── GetWeaponGoal_Evaluator.cpp │ ├── GetWeaponGoal_Evaluator.h │ ├── Goal_AdjustRange.cpp │ ├── Goal_AdjustRange.h │ ├── Goal_AttackTarget.cpp │ ├── Goal_AttackTarget.h │ ├── Goal_DodgeSideToSide.cpp │ ├── Goal_DodgeSideToSide.h │ ├── Goal_Evaluator.h │ ├── Goal_Explore.cpp │ ├── Goal_Explore.h │ ├── Goal_FindTarget.cpp │ ├── Goal_FindTarget.h │ ├── Goal_FollowPath.cpp │ ├── Goal_FollowPath.h │ ├── Goal_GetItem.cpp │ ├── Goal_GetItem.h │ ├── Goal_HuntTarget.cpp │ ├── Goal_HuntTarget.h │ ├── Goal_MoveToItem.cpp │ ├── Goal_MoveToItem.h │ ├── Goal_MoveToPosition.cpp │ ├── Goal_MoveToPosition.h │ ├── Goal_NegotiateDoor.cpp │ ├── Goal_NegotiateDoor.h │ ├── Goal_SayPhrase.cpp │ ├── Goal_SeekToPosition.cpp │ ├── Goal_SeekToPosition.h │ ├── Goal_Think.cpp │ ├── Goal_Think.h │ ├── Goal_TraverseEdge.cpp │ ├── Goal_TraverseEdge.h │ ├── Goal_Wander.cpp │ ├── Goal_Wander.h │ ├── Raven_Feature.cpp │ ├── Raven_Feature.h │ ├── Raven_Goal_Types.cpp │ ├── Raven_Goal_Types.h │ ├── Script1.rc │ └── resource.h ├── lua │ ├── Raven_Scriptor.cpp │ └── Raven_Scriptor.h ├── main.cpp ├── maps │ ├── Raven_DM1.map │ └── Raven_DM1_With_Doors.map ├── navigation │ ├── PathEdge.h │ ├── PathManager.h │ ├── PathTarget.h │ ├── Raven_PathPlanner.cpp │ ├── Raven_PathPlanner.h │ ├── SearchTerminationPolicies.h │ └── TimeSlicedGraphAlgorithms.h ├── resource.h └── triggers │ ├── Trigger_HealthGiver.cpp │ ├── Trigger_HealthGiver.h │ ├── Trigger_OnButtonSendMsg.h │ ├── Trigger_SoundNotify.cpp │ ├── Trigger_SoundNotify.h │ ├── Trigger_WeaponGiver.cpp │ └── Trigger_WeaponGiver.h ├── Common ├── 2D │ ├── C2DMatrix.h │ ├── InvertedAABBox2D.h │ ├── Transformations.h │ ├── Vector2D.h │ ├── Vector2d.cpp │ ├── Wall2D.h │ ├── WallIntersectionTests.h │ └── geometry.h ├── Debug │ ├── DebugConsole.cpp │ └── DebugConsole.h ├── FSM │ ├── State.h │ └── StateMachine.h ├── Game │ ├── BaseGameEntity.cpp │ ├── BaseGameEntity.h │ ├── EntityFunctionTemplates.h │ ├── EntityManager.cpp │ ├── EntityManager.h │ ├── MovingEntity.h │ └── Region.h ├── Goals │ ├── Goal.h │ └── Goal_Composite.h ├── Graph │ ├── AStarHeuristicPolicies.h │ ├── GraphAlgorithms.h │ ├── GraphEdgeTypes.h │ ├── GraphNodeTypes.h │ ├── HandyGraphFunctions.h │ ├── NodeTypeEnumerations.h │ └── SparseGraph.h ├── Messaging │ ├── MessageDispatcher.cpp │ ├── MessageDispatcher.h │ └── Telegram.h ├── Time │ ├── CrudeTimer.cpp │ ├── CrudeTimer.h │ ├── PrecisionTimer.cpp │ ├── PrecisionTimer.h │ └── Regulator.h ├── Triggers │ ├── Trigger.h │ ├── TriggerRegion.h │ ├── TriggerSystem.h │ ├── Trigger_LimitedLifeTime.h │ └── Trigger_Respawning.h ├── fuzzy │ ├── FuzzyHedges.h │ ├── FuzzyModule.cpp │ ├── FuzzyModule.h │ ├── FuzzyOperators.cpp │ ├── FuzzyOperators.h │ ├── FuzzyRule.h │ ├── FuzzySet.h │ ├── FuzzySet_LeftShoulder.cpp │ ├── FuzzySet_LeftShoulder.h │ ├── FuzzySet_RightShoulder.cpp │ ├── FuzzySet_RightShoulder.h │ ├── FuzzySet_Shoulder.h │ ├── FuzzySet_Singleton.cpp │ ├── FuzzySet_Singleton.h │ ├── FuzzySet_Triangle.cpp │ ├── FuzzySet_Triangle.h │ ├── FuzzyTerm.h │ ├── FuzzyVariable.cpp │ ├── FuzzyVariable.h │ └── FzSet.h ├── lua-5.0 │ ├── COPYRIGHT │ ├── HISTORY │ ├── INSTALL │ ├── MANIFEST │ ├── Makefile │ ├── README │ ├── bin │ │ ├── Lua.exe │ │ ├── Luac.exe │ │ └── readme.txt │ ├── build │ ├── config │ ├── configure │ ├── doc │ │ ├── logo.gif │ │ ├── lua.1 │ │ ├── lua.html │ │ ├── luac.1 │ │ ├── luac.html │ │ ├── manual.html │ │ └── readme.html │ ├── etc │ │ ├── Makefile │ │ ├── README │ │ ├── bin2c.c │ │ ├── compat.lua │ │ ├── doall.lua │ │ ├── lua.ico │ │ ├── lua.magic │ │ ├── lua.xpm │ │ ├── luser_number.h │ │ ├── luser_number.h.backup │ │ ├── luser_tests.h │ │ ├── luser_tests.h.backup │ │ ├── min.c │ │ ├── noparser.c │ │ ├── saconfig.c │ │ └── trace.c │ ├── include │ │ ├── LuaHelperFunctions.h │ │ ├── Makefile │ │ ├── OpenLuaStates.h │ │ ├── lauxlib.h │ │ ├── lauxlib.h.backup │ │ ├── lua.h │ │ ├── lua.h.backup │ │ ├── lualib.h │ │ └── lualib.h.backup │ ├── lib │ │ ├── lua.lib │ │ ├── lualib.lib │ │ └── readme.txt │ ├── src │ │ ├── LuaHelperFunctions.cpp │ │ ├── Makefile │ │ ├── README │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── lib │ │ │ ├── Makefile │ │ │ ├── README │ │ │ ├── lauxlib.c │ │ │ ├── lbaselib.c │ │ │ ├── ldblib.c │ │ │ ├── liolib.c │ │ │ ├── lmathlib.c │ │ │ ├── loadlib.c │ │ │ ├── lstrlib.c │ │ │ ├── ltablib.c │ │ │ └── vssver.scc │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltests.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua │ │ │ ├── Makefile │ │ │ ├── README │ │ │ ├── lua.c │ │ │ └── vssver.scc │ │ ├── luac │ │ │ ├── Makefile │ │ │ ├── README │ │ │ ├── luac.c │ │ │ ├── print.c │ │ │ └── vssver.scc │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ └── test │ │ ├── README │ │ ├── bisect.lua │ │ ├── cf.lua │ │ ├── compat.lua │ │ ├── echo.lua │ │ ├── env.lua │ │ ├── factorial.lua │ │ ├── fib.lua │ │ ├── fibfor.lua │ │ ├── globals.lua │ │ ├── hello.lua │ │ ├── life.lua │ │ ├── luac.lua │ │ ├── printf.lua │ │ ├── readonly.lua │ │ ├── sieve.lua │ │ ├── sort.lua │ │ ├── table.lua │ │ ├── trace-calls.lua │ │ ├── trace-globals.lua │ │ ├── undefined.lua │ │ └── xd.lua ├── luabind │ ├── LICENSE │ ├── config │ ├── doc │ │ ├── docs.html │ │ ├── index.html │ │ ├── luabind-logo-label.ps │ │ ├── style.css │ │ └── vssver.scc │ ├── examples │ │ ├── any_converter │ │ │ ├── any_converter.cpp │ │ │ ├── makefile │ │ │ └── vssver.scc │ │ ├── cln │ │ │ ├── README │ │ │ ├── cln_test.cpp │ │ │ ├── cln_test.lua │ │ │ ├── makefile │ │ │ └── vssver.scc │ │ ├── filesystem │ │ │ ├── directory_iterator.hpp │ │ │ ├── filesystem.cpp │ │ │ ├── inspect.lua │ │ │ ├── makefile │ │ │ └── vssver.scc │ │ ├── glut │ │ │ ├── glut_bind.cpp │ │ │ ├── glut_bindings.lua │ │ │ ├── makefile │ │ │ └── vssver.scc │ │ ├── intrusive_ptr │ │ │ ├── intrusive_ptr.cpp │ │ │ ├── makefile │ │ │ └── vssver.scc │ │ ├── makefile │ │ ├── regexp │ │ │ ├── makefile │ │ │ ├── regex.lua │ │ │ ├── regex_wrap.cpp │ │ │ └── vssver.scc │ │ └── vssver.scc │ ├── luabind │ │ ├── adopt_policy.hpp │ │ ├── class.hpp │ │ ├── com_policy.hpp │ │ ├── config.hpp │ │ ├── container_policy.hpp │ │ ├── copy_policy.hpp │ │ ├── dependency_policy.hpp │ │ ├── detail │ │ │ ├── calc_arity.hpp │ │ │ ├── call.hpp │ │ │ ├── call_function.hpp │ │ │ ├── call_member.hpp │ │ │ ├── class_registry.hpp │ │ │ ├── class_rep.hpp │ │ │ ├── class_rep_scope.hpp │ │ │ ├── construct_rep.hpp │ │ │ ├── constructor.hpp │ │ │ ├── convert_to_lua.hpp │ │ │ ├── decorate_type.hpp │ │ │ ├── enum_maker.hpp │ │ │ ├── error.hpp │ │ │ ├── find_best_match.hpp │ │ │ ├── garbage_collector.hpp │ │ │ ├── get_overload_signature.hpp │ │ │ ├── get_signature.hpp │ │ │ ├── implicit_cast.hpp │ │ │ ├── method_rep.hpp │ │ │ ├── object_funs.hpp │ │ │ ├── object_rep.hpp │ │ │ ├── open.hpp │ │ │ ├── operator_id.hpp │ │ │ ├── operators.hpp │ │ │ ├── other.hpp │ │ │ ├── overload_rep.hpp │ │ │ ├── overload_rep_base.hpp │ │ │ ├── overload_rep_impl.hpp │ │ │ ├── policy.hpp │ │ │ ├── primitives.hpp │ │ │ ├── property.hpp │ │ │ ├── ref.hpp │ │ │ ├── signature_match.hpp │ │ │ ├── typetraits.hpp │ │ │ └── vssver.scc │ │ ├── discard_result_policy.hpp │ │ ├── function.hpp │ │ ├── functor.hpp │ │ ├── iterator_policy.hpp │ │ ├── luabind.hpp │ │ ├── object.hpp │ │ ├── out_value_policy.hpp │ │ ├── return_reference_to_policy.hpp │ │ ├── scope.hpp │ │ ├── vssver.scc │ │ └── yield_policy.hpp │ ├── makefile │ ├── src │ │ ├── class_rep.cpp │ │ ├── create_class.cpp │ │ ├── find_best_match.cpp │ │ ├── function.cpp │ │ ├── implicit_cast.cpp │ │ ├── makefile │ │ ├── object.cpp │ │ ├── open.cpp │ │ ├── stack_content_by_name.cpp │ │ └── vssver.scc │ └── test │ │ ├── benchmark.cpp │ │ ├── main.cpp │ │ ├── makefile │ │ ├── test.h │ │ ├── test_attributes.cpp │ │ ├── test_const.cpp │ │ ├── test_construction.cpp │ │ ├── test_exceptions.cpp │ │ ├── test_free_functions.cpp │ │ ├── test_held_type.cpp │ │ ├── test_implicit_cast.cpp │ │ ├── test_iterator.cpp │ │ ├── test_lua_classes.cpp │ │ ├── test_null_pointer.cpp │ │ ├── test_object.cpp │ │ ├── test_operators.cpp │ │ ├── test_policies.cpp │ │ ├── test_scope.cpp │ │ ├── test_typetraits.cpp │ │ ├── test_yield.cpp │ │ └── vssver.scc ├── misc │ ├── CellSpacePartition.h │ ├── Cgdi.cpp │ ├── Cgdi.h │ ├── ConsoleUtils.h │ ├── FrameCounter.cpp │ ├── FrameCounter.h │ ├── PriorityQueue.h │ ├── Smoother.h │ ├── Stream_Utility_Functions.h │ ├── TypeToString.h │ ├── WindowUtils.cpp │ ├── WindowUtils.h │ ├── autolist.h │ ├── iniFileLoaderBase.cpp │ ├── iniFileLoaderBase.h │ └── utils.h └── script │ └── Scriptor.h └── README.md /Buckland_Chapter2-State Machines/WestWorld1/BaseGameEntity.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseGameEntity.h" 2 | #include 3 | 4 | 5 | 6 | int BaseGameEntity::m_iNextValidID = 0; 7 | 8 | 9 | 10 | //----------------------------- SetID ----------------------------------------- 11 | // 12 | // this must be called within each constructor to make sure the ID is set 13 | // correctly. It verifies that the value passed to the method is greater 14 | // or equal to the next valid ID, before setting the ID and incrementing 15 | // the next valid ID 16 | //----------------------------------------------------------------------------- 17 | void BaseGameEntity::SetID(int val) 18 | { 19 | //make sure the val is equal to or greater than the next available ID 20 | assert ( (val >= m_iNextValidID) && ": invalid ID"); 21 | 22 | m_ID = val; 23 | 24 | m_iNextValidID = m_ID + 1; 25 | } 26 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/BaseGameEntity.h: -------------------------------------------------------------------------------- 1 | #ifndef ENTITY_H 2 | #define ENTITY_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: BaseGameEntity.h 6 | // 7 | // Desc: Base class for a game object 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | 13 | 14 | class BaseGameEntity 15 | { 16 | 17 | private: 18 | 19 | //every entity must have a unique identifying number 20 | int m_ID; 21 | 22 | //this is the next valid ID. Each time a BaseGameEntity is instantiated 23 | //this value is updated 24 | static int m_iNextValidID; 25 | 26 | //this must be called within the constructor to make sure the ID is set 27 | //correctly. It verifies that the value passed to the method is greater 28 | //or equal to the next valid ID, before setting the ID and incrementing 29 | //the next valid ID 30 | void SetID(int val); 31 | 32 | public: 33 | 34 | BaseGameEntity(int id) 35 | { 36 | SetID(id); 37 | } 38 | 39 | virtual ~BaseGameEntity(){} 40 | 41 | //all entities must implement an update function 42 | virtual void Update()=0; 43 | 44 | int ID()const{return m_ID;} 45 | }; 46 | 47 | 48 | 49 | #endif 50 | 51 | 52 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/EntityNames.h: -------------------------------------------------------------------------------- 1 | #ifndef NAMES_H 2 | #define NAMES_H 3 | 4 | #include 5 | 6 | enum 7 | { 8 | ent_Miner_Bob, 9 | 10 | ent_Elsa 11 | }; 12 | 13 | inline std::string GetNameOfEntity(int n) 14 | { 15 | switch(n) 16 | { 17 | case ent_Miner_Bob: 18 | 19 | return "Miner Bob"; 20 | 21 | case ent_Elsa: 22 | 23 | return "Elsa"; 24 | 25 | default: 26 | 27 | return "UNKNOWN!"; 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/Locations.h: -------------------------------------------------------------------------------- 1 | #ifndef LOCATIONS_H 2 | #define LOCATIONS_H 3 | 4 | 5 | enum location_type 6 | { 7 | shack, 8 | goldmine, 9 | bank, 10 | saloon 11 | }; 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/State.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_H 2 | #define STATE_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: State.h 6 | // 7 | // Desc: abstract base class to define an interface for a state 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | 13 | class Miner; 14 | 15 | class State 16 | { 17 | public: 18 | 19 | virtual ~State(){} 20 | 21 | //this will execute when the state is entered 22 | virtual void Enter(Miner*)=0; 23 | 24 | //this is the state's normal update function 25 | virtual void Execute(Miner*)=0; 26 | 27 | //this will execute when the state is exited. (My word, isn't 28 | //life full of surprises... ;o)) 29 | virtual void Exit(Miner*)=0; 30 | 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/WestWorld1.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by WestWorld1.mak 2 | 3 | .\main.cpp : \ 4 | "..\..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ 5 | "..\..\common\consoleutils.h"\ 6 | ".\Entity.h"\ 7 | ".\Locations.h"\ 8 | ".\Miner.h"\ 9 | 10 | 11 | .\Miner.cpp : \ 12 | ".\Entity.h"\ 13 | ".\Locations.h"\ 14 | ".\Miner.h"\ 15 | ".\MinerOwnedStates.h"\ 16 | ".\State.h"\ 17 | 18 | 19 | .\MinerOwnedStates.cpp : \ 20 | "..\..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ 21 | "..\..\common\consoleutils.h"\ 22 | ".\Entity.h"\ 23 | ".\Locations.h"\ 24 | ".\Miner.h"\ 25 | ".\MinerOwnedStates.h"\ 26 | ".\State.h"\ 27 | 28 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/WestWorld1.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "WestWorld1"=".\WestWorld1.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorld1/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Locations.h" 2 | #include "Miner.h" 3 | #include "misc/ConsoleUtils.h" 4 | #include "EntityNames.h" 5 | 6 | 7 | int main() 8 | { 9 | //create a miner 10 | Miner miner(ent_Miner_Bob); 11 | 12 | //simply run the miner through a few Update calls 13 | for (int i=0; i<20; ++i) 14 | { 15 | miner.Update(); 16 | 17 | Sleep(800); 18 | } 19 | 20 | //wait for a keypress before exiting 21 | PressAnyKeyToContinue(); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/BaseGameEntity.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseGameEntity.h" 2 | #include 3 | 4 | 5 | 6 | int BaseGameEntity::m_iNextValidID = 0; 7 | 8 | 9 | 10 | //----------------------------- SetID ----------------------------------------- 11 | // 12 | // this must be called within each constructor to make sure the ID is set 13 | // correctly. It verifies that the value passed to the method is greater 14 | // or equal to the next valid ID, before setting the ID and incrementing 15 | // the next valid ID 16 | //----------------------------------------------------------------------------- 17 | void BaseGameEntity::SetID(int val) 18 | { 19 | //make sure the val is equal to or greater than the next available ID 20 | assert ( (val >= m_iNextValidID) && ": invalid ID"); 21 | 22 | m_ID = val; 23 | 24 | m_iNextValidID = m_ID + 1; 25 | } 26 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/BaseGameEntity.h: -------------------------------------------------------------------------------- 1 | #ifndef ENTITY_H 2 | #define ENTITY_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: BaseGameEntity.h 6 | // 7 | // Desc: Base class for a game object 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | #include 13 | 14 | #include "messaging/Telegram.h" 15 | 16 | 17 | class BaseGameEntity 18 | { 19 | 20 | private: 21 | 22 | //every entity must have a unique identifying number 23 | int m_ID; 24 | 25 | //this is the next valid ID. Each time a BaseGameEntity is instantiated 26 | //this value is updated 27 | static int m_iNextValidID; 28 | 29 | //this must be called within the constructor to make sure the ID is set 30 | //correctly. It verifies that the value passed to the method is greater 31 | //or equal to the next valid ID, before setting the ID and incrementing 32 | //the next valid ID 33 | void SetID(int val); 34 | 35 | public: 36 | 37 | BaseGameEntity(int id) 38 | { 39 | SetID(id); 40 | } 41 | 42 | virtual ~BaseGameEntity(){} 43 | 44 | //all entities must implement an update function 45 | virtual void Update()=0; 46 | 47 | //all entities can communicate using messages. They are sent 48 | //using the MessageDispatcher singleton class 49 | virtual bool HandleMessage(const Telegram& msg)=0; 50 | 51 | int ID()const{return m_ID;} 52 | }; 53 | 54 | 55 | 56 | #endif 57 | 58 | 59 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/EntityNames.h: -------------------------------------------------------------------------------- 1 | #ifndef NAMES_H 2 | #define NAMES_H 3 | 4 | #include 5 | 6 | enum 7 | { 8 | ent_Miner_Bob, 9 | 10 | ent_Elsa 11 | }; 12 | 13 | inline std::string GetNameOfEntity(int n) 14 | { 15 | switch(n) 16 | { 17 | case ent_Miner_Bob: 18 | 19 | return "Miner Bob"; 20 | 21 | case ent_Elsa: 22 | 23 | return "Elsa"; 24 | 25 | default: 26 | 27 | return "UNKNOWN!"; 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/Locations.h: -------------------------------------------------------------------------------- 1 | #ifndef LOCATIONS_H 2 | #define LOCATIONS_H 3 | 4 | 5 | enum location_type 6 | { 7 | shack, 8 | goldmine, 9 | bank, 10 | saloon 11 | }; 12 | 13 | 14 | 15 | 16 | //uncomment this to send the output to a text file 17 | //#define TEXTOUTPUT 18 | 19 | 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/MessageTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef MESSAGE_TYPES 2 | #define MESSAGE_TYPES 3 | 4 | #include 5 | 6 | enum message_type 7 | { 8 | Msg_HiHoneyImHome, 9 | Msg_StewReady, 10 | }; 11 | 12 | 13 | inline std::string MsgToStr(int msg) 14 | { 15 | switch (msg) 16 | { 17 | case 1: 18 | 19 | return "HiHoneyImHome"; 20 | 21 | case 2: 22 | 23 | return "StewReady"; 24 | 25 | default: 26 | 27 | return "Not recognized!"; 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/Miner.cpp: -------------------------------------------------------------------------------- 1 | #include "Miner.h" 2 | 3 | bool Miner::HandleMessage(const Telegram& msg) 4 | { 5 | return m_pStateMachine->HandleMessage(msg); 6 | } 7 | 8 | 9 | void Miner::Update() 10 | { 11 | SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY); 12 | 13 | m_iThirst += 1; 14 | 15 | m_pStateMachine->Update(); 16 | } 17 | 18 | 19 | 20 | void Miner::AddToGoldCarried(const int val) 21 | { 22 | m_iGoldCarried += val; 23 | 24 | if (m_iGoldCarried < 0) m_iGoldCarried = 0; 25 | } 26 | 27 | void Miner::AddToWealth(const int val) 28 | { 29 | m_iMoneyInBank += val; 30 | 31 | if (m_iMoneyInBank < 0) m_iMoneyInBank = 0; 32 | } 33 | 34 | bool Miner::Thirsty()const 35 | { 36 | if (m_iThirst >= ThirstLevel){return true;} 37 | 38 | return false; 39 | } 40 | 41 | bool Miner::Fatigued()const 42 | { 43 | if (m_iFatigue > TirednessThreshold) 44 | { 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/MinersWife.cpp: -------------------------------------------------------------------------------- 1 | #include "MinersWife.h" 2 | 3 | bool MinersWife::HandleMessage(const Telegram& msg) 4 | { 5 | return m_pStateMachine->HandleMessage(msg); 6 | } 7 | 8 | 9 | void MinersWife::Update() 10 | { 11 | //set text color to green 12 | SetTextColor(FOREGROUND_GREEN | FOREGROUND_INTENSITY); 13 | 14 | m_pStateMachine->Update(); 15 | } -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/WestWorldWithMessaging.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "WestWorldWithMessaging"=".\WestWorldWithMessaging.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithMessaging/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Locations.h" 5 | #include "Miner.h" 6 | #include "MinersWife.h" 7 | #include "EntityManager.h" 8 | #include "MessageDispatcher.h" 9 | #include "misc/ConsoleUtils.h" 10 | #include "EntityNames.h" 11 | 12 | 13 | std::ofstream os; 14 | 15 | int main() 16 | { 17 | //define this to send output to a text file (see locations.h) 18 | #ifdef TEXTOUTPUT 19 | os.open("output.txt"); 20 | #endif 21 | 22 | //seed random number generator 23 | srand((unsigned) time(NULL)); 24 | 25 | //create a miner 26 | Miner* Bob = new Miner(ent_Miner_Bob); 27 | 28 | //create his wife 29 | MinersWife* Elsa = new MinersWife(ent_Elsa); 30 | 31 | //register them with the entity manager 32 | EntityMgr->RegisterEntity(Bob); 33 | EntityMgr->RegisterEntity(Elsa); 34 | 35 | //run Bob and Elsa through a few Update calls 36 | for (int i=0; i<30; ++i) 37 | { 38 | Bob->Update(); 39 | Elsa->Update(); 40 | 41 | //dispatch any delayed messages 42 | Dispatch->DispatchDelayedMessages(); 43 | 44 | Sleep(800); 45 | } 46 | 47 | //tidy up 48 | delete Bob; 49 | delete Elsa; 50 | 51 | //wait for a keypress before exiting 52 | PressAnyKeyToContinue(); 53 | 54 | 55 | return 0; 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/BaseGameEntity.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseGameEntity.h" 2 | #include 3 | 4 | 5 | 6 | int BaseGameEntity::m_iNextValidID = 0; 7 | 8 | 9 | 10 | //----------------------------- SetID ----------------------------------------- 11 | // 12 | // this must be called within each constructor to make sure the ID is set 13 | // correctly. It verifies that the value passed to the method is greater 14 | // or equal to the next valid ID, before setting the ID and incrementing 15 | // the next valid ID 16 | //----------------------------------------------------------------------------- 17 | void BaseGameEntity::SetID(int val) 18 | { 19 | //make sure the val is equal to or greater than the next available ID 20 | assert ( (val >= m_iNextValidID) && ": invalid ID"); 21 | 22 | m_ID = val; 23 | 24 | m_iNextValidID = m_ID + 1; 25 | } 26 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/BaseGameEntity.h: -------------------------------------------------------------------------------- 1 | #ifndef ENTITY_H 2 | #define ENTITY_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: BaseGameEntity.h 6 | // 7 | // Desc: Base class for a game object 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | 13 | class BaseGameEntity 14 | { 15 | 16 | private: 17 | 18 | //every entity must have a unique identifying number 19 | int m_ID; 20 | 21 | //this is the next valid ID. Each time a BaseGameEntity is instantiated 22 | //this value is updated 23 | static int m_iNextValidID; 24 | 25 | //this must be called within the constructor to make sure the ID is set 26 | //correctly. It verifies that the value passed to the method is greater 27 | //or equal to the next valid ID, before setting the ID and incrementing 28 | //the next valid ID 29 | void SetID(int val); 30 | 31 | public: 32 | 33 | BaseGameEntity(int id) 34 | { 35 | SetID(id); 36 | } 37 | 38 | virtual ~BaseGameEntity(){} 39 | 40 | //all entities must implement an update function 41 | virtual void Update()=0; 42 | 43 | int ID()const{return m_ID;} 44 | }; 45 | 46 | 47 | 48 | #endif 49 | 50 | 51 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/EntityNames.h: -------------------------------------------------------------------------------- 1 | #ifndef NAMES_H 2 | #define NAMES_H 3 | 4 | #include 5 | 6 | enum 7 | { 8 | ent_Miner_Bob, 9 | 10 | ent_Elsa 11 | }; 12 | 13 | inline std::string GetNameOfEntity(int n) 14 | { 15 | switch(n) 16 | { 17 | case ent_Miner_Bob: 18 | 19 | return "Miner Bob"; 20 | 21 | case ent_Elsa: 22 | 23 | return "Elsa"; 24 | 25 | default: 26 | 27 | return "UNKNOWN!"; 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/Locations.h: -------------------------------------------------------------------------------- 1 | #ifndef LOCATIONS_H 2 | #define LOCATIONS_H 3 | 4 | 5 | enum location_type 6 | { 7 | shack, 8 | goldmine, 9 | bank, 10 | saloon 11 | }; 12 | 13 | 14 | 15 | 16 | //uncomment to send output to 'output.txt' 17 | //#define TEXTOUTPUT 18 | 19 | 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/Miner.cpp: -------------------------------------------------------------------------------- 1 | #include "Miner.h" 2 | #include "misc/ConsoleUtils.h" 3 | 4 | 5 | //----------------------------------------------------------------------------- 6 | void Miner::Update() 7 | { 8 | SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY); 9 | 10 | m_iThirst += 1; 11 | 12 | m_pStateMachine->Update(); 13 | } 14 | 15 | //----------------------------------------------------------------------------- 16 | void Miner::AddToGoldCarried(const int val) 17 | { 18 | m_iGoldCarried += val; 19 | 20 | if (m_iGoldCarried < 0) m_iGoldCarried = 0; 21 | } 22 | 23 | //----------------------------------------------------------------------------- 24 | void Miner::AddToWealth(const int val) 25 | { 26 | m_iMoneyInBank += val; 27 | 28 | if (m_iMoneyInBank < 0) m_iMoneyInBank = 0; 29 | } 30 | 31 | //----------------------------------------------------------------------------- 32 | bool Miner::Thirsty()const 33 | { 34 | if (m_iThirst >= ThirstLevel){return true;} 35 | 36 | return false; 37 | } 38 | 39 | 40 | //----------------------------------------------------------------------------- 41 | bool Miner::Fatigued()const 42 | { 43 | if (m_iFatigue > TirednessThreshold) 44 | { 45 | return true; 46 | } 47 | 48 | return false; 49 | } -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/MinersWife.cpp: -------------------------------------------------------------------------------- 1 | #include "MinersWife.h" 2 | 3 | 4 | void MinersWife::Update() 5 | { 6 | //set text color to green 7 | SetTextColor(FOREGROUND_GREEN | FOREGROUND_INTENSITY); 8 | 9 | m_pStateMachine->Update(); 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/MinersWife.h: -------------------------------------------------------------------------------- 1 | #ifndef MINERSWIFE_H 2 | #define MINERSWIFE_H 3 | 4 | #include 5 | 6 | #include "State.h" 7 | #include "BaseGameEntity.h" 8 | #include "Locations.h" 9 | #include "MinersWifeOwnedStates.h" 10 | #include "misc/ConsoleUtils.h" 11 | #include "Miner.h" 12 | #include "StateMachine.h" 13 | #include "misc/Utils.h" 14 | 15 | 16 | 17 | class MinersWife : public BaseGameEntity 18 | { 19 | private: 20 | 21 | //an instance of the state machine class 22 | StateMachine* m_pStateMachine; 23 | 24 | location_type m_Location; 25 | 26 | 27 | public: 28 | 29 | MinersWife(int id):BaseGameEntity(id), 30 | m_Location(shack) 31 | 32 | { 33 | m_pStateMachine = new StateMachine(this); 34 | 35 | m_pStateMachine->SetCurrentState(DoHouseWork::Instance()); 36 | 37 | m_pStateMachine->SetGlobalState(WifesGlobalState::Instance()); 38 | } 39 | 40 | ~MinersWife(){delete m_pStateMachine;} 41 | 42 | 43 | void Update(); 44 | 45 | StateMachine* GetFSM()const{return m_pStateMachine;} 46 | 47 | //----------------------------------------------------accessors 48 | location_type Location()const{return m_Location;} 49 | void ChangeLocation(const location_type loc){m_Location=loc;} 50 | 51 | }; 52 | 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/State.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_H 2 | #define STATE_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: State.h 6 | // 7 | // Desc: abstract base class to define an interface for a state 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | 13 | 14 | template 15 | class State 16 | { 17 | public: 18 | 19 | virtual ~State(){} 20 | 21 | //this will execute when the state is entered 22 | virtual void Enter(entity_type*)=0; 23 | 24 | //this is the states normal update function 25 | virtual void Execute(entity_type*)=0; 26 | 27 | //this will execute when the state is exited. (My word, isn't 28 | //life full of surprises... ;o)) 29 | virtual void Exit(entity_type*)=0; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/WestWorldWithWomen.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "WestWorldWithWomen"=".\WestWorldWithWomen.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter2-State Machines/WestWorldWithWoman/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Locations.h" 3 | #include "Miner.h" 4 | #include "MinersWife.h" 5 | #include "misc/ConsoleUtils.h" 6 | #include "EntityNames.h" 7 | 8 | 9 | 10 | std::ofstream os; 11 | 12 | int main() 13 | { 14 | //define this to send output to a text file (see locations.h) 15 | #ifdef TEXTOUTPUT 16 | os.open("output.txt"); 17 | #endif 18 | 19 | //create a miner 20 | Miner Bob(ent_Miner_Bob); 21 | 22 | //create his wife 23 | MinersWife Elsa(ent_Elsa); 24 | 25 | //run Bob and Elsa through a few Update calls 26 | for (int i=0; i<20; ++i) 27 | { 28 | Bob.Update(); 29 | Elsa.Update(); 30 | 31 | Sleep(800); 32 | } 33 | 34 | //wait for a keypress before exiting 35 | PressAnyKeyToContinue(); 36 | 37 | return 0; 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/Obstacle.cpp: -------------------------------------------------------------------------------- 1 | #include "Obstacle.h" 2 | #include 3 | 4 | 5 | void Obstacle::Write(std::ostream& os)const 6 | { 7 | os << std::endl; 8 | os << EntityType() << ","; 9 | os << Pos() << ","; 10 | os << BRadius(); 11 | } 12 | 13 | void Obstacle::Read(std::ifstream& in) 14 | { 15 | double x, y, r; 16 | 17 | in >> x >> y >> r; 18 | 19 | SetPos(Vector2D(x,y)); 20 | 21 | SetBRadius(r); 22 | } -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/Obstacle.h: -------------------------------------------------------------------------------- 1 | #ifndef OBSTACLE_H 2 | #define OBSTACLE_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: Obstacle.h 6 | // 7 | // Desc: Simple obstacle class 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | #include "2d/Vector2D.h" 13 | #include "BaseGameEntity.h" 14 | #include "misc/Cgdi.h" 15 | 16 | 17 | #include 18 | 19 | 20 | class Obstacle : public BaseGameEntity 21 | { 22 | public: 23 | 24 | Obstacle(double x, 25 | double y, 26 | double r):BaseGameEntity(0, Vector2D(x,y), r) 27 | {} 28 | 29 | Obstacle(Vector2D pos, double radius):BaseGameEntity(0, pos, radius) 30 | {} 31 | 32 | Obstacle(std::ifstream& in){Read(in);} 33 | 34 | virtual ~Obstacle(){} 35 | 36 | //this is defined as a pure virtual function in BasegameEntity so 37 | //it must be implemented 38 | void Update(double time_elapsed){} 39 | 40 | void Render(){gdi->BlackPen();gdi->Circle(Pos(), BRadius());} 41 | 42 | void Write(std::ostream& os)const; 43 | void Read(std::ifstream& in); 44 | }; 45 | 46 | 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/ParamLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "ParamLoader.h" 2 | 3 | ParamLoader* ParamLoader::Instance() 4 | { 5 | static ParamLoader instance; 6 | 7 | return &instance; 8 | } -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/Path.cpp: -------------------------------------------------------------------------------- 1 | #include "Path.h" 2 | #include "misc/utils.h" 3 | #include "misc/Cgdi.h" 4 | #include "2d/transformations.h" 5 | 6 | std::list Path::CreateRandomPath(int NumWaypoints, 7 | double MinX, 8 | double MinY, 9 | double MaxX, 10 | double MaxY) 11 | { 12 | m_WayPoints.clear(); 13 | 14 | double midX = (MaxX+MinX)/2.0; 15 | double midY = (MaxY+MinY)/2.0; 16 | 17 | double smaller = min(midX, midY); 18 | 19 | double spacing = TwoPi/(double)NumWaypoints; 20 | 21 | for (int i=0; iOrangePen(); 44 | 45 | std::list::const_iterator it = m_WayPoints.begin(); 46 | 47 | Vector2D wp = *it++; 48 | 49 | while (it != m_WayPoints.end()) 50 | { 51 | gdi->Line(wp, *it); 52 | 53 | wp = *it++; 54 | } 55 | 56 | if (m_bLooped) gdi->Line(*(--it), *m_WayPoints.begin()); 57 | } 58 | -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/Script1.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter3-Steering Behaviors/Script1.aps -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/Steering.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Steering"=".\Steering.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | //change these values at your peril! 5 | const int constWindowWidth = 500; 6 | const int constWindowHeight = 500; 7 | 8 | 9 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter3-Steering Behaviors/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Script1.rc 4 | // 5 | #define IDR_MENU1 101 6 | #define ID_AID_WANDER 40001 7 | #define ID_AID_STEERINGFORCE 40002 8 | #define ID_AID_WALLFEELERS 40003 9 | #define ID_OB_WALLS 40004 10 | #define ID_OB_OBSTACLES 40005 11 | #define ID_OB_PATH 40006 12 | #define ID_AID_DETECTIONBOX 40007 13 | #define IDR_PARTITIONING 40008 14 | #define IDR_WEIGHTED_SUM 40009 15 | #define IDR_PRIORITIZED 40010 16 | #define IDR_DITHERED 40011 17 | #define ID_VIEW_KEYS 40012 18 | #define ID_VIEW_FPS 40013 19 | #define ID_MENU_SMOOTHING 40014 20 | #define IDM_PARTITION_VIEW_NEIGHBORS 40015 21 | 22 | // Next default values for new objects 23 | // 24 | #ifdef APSTUDIO_INVOKED 25 | #ifndef APSTUDIO_READONLY_SYMBOLS 26 | #define _APS_NEXT_RESOURCE_VALUE 102 27 | #define _APS_NEXT_COMMAND_VALUE 40016 28 | #define _APS_NEXT_CONTROL_VALUE 1000 29 | #define _APS_NEXT_SYMED_VALUE 101 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/Goal.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter4-SimpleSoccer/Goal.cpp -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/ParamLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "ParamLoader.h" 2 | 3 | ParamLoader* ParamLoader::Instance() 4 | { 5 | static ParamLoader instance; 6 | 7 | return &instance; 8 | } -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/Script1.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter4-SimpleSoccer/Script1.aps -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/SimpleSoccer.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "SimpleSoccer"=".\SimpleSoccer.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/SoccerMessages.cpp: -------------------------------------------------------------------------------- 1 | #include "SoccerMessages.h" 2 | 3 | 4 | inline std::string MessageToString(int msg) 5 | { 6 | switch (msg) 7 | { 8 | case Msg_ReceiveBall: 9 | 10 | return "Msg_ReceiveBall"; 11 | 12 | case Msg_PassToMe: 13 | 14 | return "Msg_PassToMe"; 15 | 16 | case Msg_SupportAttacker: 17 | 18 | return "Msg_SupportAttacker"; 19 | 20 | case Msg_GoHome: 21 | 22 | return "Msg_GoHome"; 23 | 24 | case Msg_Wait: 25 | 26 | return "Msg_Wait"; 27 | 28 | default: 29 | 30 | return "INVALID MESSAGE!!"; 31 | } 32 | } -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/SoccerMessages.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCCER_MESSAGES_H 2 | #define SOCCER_MESSAGES_H 3 | 4 | #include 5 | 6 | enum MessageType 7 | { 8 | Msg_ReceiveBall, 9 | Msg_PassToMe, 10 | Msg_SupportAttacker, 11 | Msg_GoHome, 12 | Msg_Wait 13 | }; 14 | 15 | //converts an enumerated value to a string 16 | inline std::string MessageToString(int msg); 17 | 18 | 19 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | const int WindowWidth = 700; 5 | const int WindowHeight = 400; 6 | 7 | 8 | //defines the size of a team -- do not adjust 9 | const int TeamSize = 5; 10 | 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/icon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter4-SimpleSoccer/icon1.ico -------------------------------------------------------------------------------- /Buckland_Chapter4-SimpleSoccer/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Script1.rc 4 | // 5 | #define IDR_MENU1 101 6 | #define IDI_ICON1 102 7 | #define IDM_SHOW_IDS 40001 8 | #define IDM_SHOW_STATES 40002 9 | #define IDM_SHOW_REGIONS 40003 10 | #define IDM_AIDS_SUPPORTSPOTS 40005 11 | #define ID_AIDS_SHOWTARGETS 40006 12 | #define ID_AIDS_NOAIDS 40007 13 | #define IDM_AIDS_HIGHLITE 40008 14 | 15 | // Next default values for new objects 16 | // 17 | #ifdef APSTUDIO_INVOKED 18 | #ifndef APSTUDIO_READONLY_SYMBOLS 19 | #define _APS_NEXT_RESOURCE_VALUE 104 20 | #define _APS_NEXT_COMMAND_VALUE 40009 21 | #define _APS_NEXT_CONTROL_VALUE 1000 22 | #define _APS_NEXT_SYMED_VALUE 101 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/Pathfinder.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Pathfinder"=".\Pathfinder.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | 5 | const int WindowWidth = 600; 6 | const int WindowHeight = 600; 7 | 8 | const int ClientWidth = 500; 9 | const int ClientHeight = 500; 10 | 11 | 12 | const int NumCellsX = 19; 13 | const int NumCellsY = 19; 14 | 15 | 16 | //blank space required to print timing info 17 | const int InfoWindowHeight = 20; 18 | 19 | 20 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/icon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter5-Pathfinder/icon1.ico -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by toolbar.rc 4 | // 5 | #define IDR_TOOLBAR1 101 6 | #define IDR_MENU1 103 7 | #define IDI_ICON1 104 8 | #define ID_BUTTON_STOP 40001 9 | #define ID_BUTTON_START 40002 10 | #define ID_BUTTON_OBSTACLE 40003 11 | #define ID_BUTTON_WATER 40004 12 | #define ID_BUTTON_MUD 40005 13 | #define ID_BUTTON_END 40006 14 | #define ID_BUTTON_NORMAL 40007 15 | #define ID_BUTTON_DFS 40008 16 | #define ID_BUTTON_BFS 40009 17 | #define ID_BUTTON_DIJKSTRA 40010 18 | #define ID_BUTTON_ASTAR 40011 19 | #define IDM_VIEW_GRAPH 40013 20 | #define IDM_VIEW_TILES 40014 21 | #define ID_MENU_SAVEAS 40019 22 | #define ID_MENU_LOAD 40020 23 | #define ID_MENU_NEW 40021 24 | 25 | // Next default values for new objects 26 | // 27 | #ifdef APSTUDIO_INVOKED 28 | #ifndef APSTUDIO_READONLY_SYMBOLS 29 | #define _APS_NEXT_RESOURCE_VALUE 105 30 | #define _APS_NEXT_COMMAND_VALUE 40015 31 | #define _APS_NEXT_CONTROL_VALUE 1000 32 | #define _APS_NEXT_SYMED_VALUE 101 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/toolbar.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter5-Pathfinder/toolbar.aps -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/toolbar.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter5-Pathfinder/toolbar.rc -------------------------------------------------------------------------------- /Buckland_Chapter5-Pathfinder/toolbar1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter5-Pathfinder/toolbar1.bmp -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/CreatingClassesUsingLuabind/CreatingClassesUsingLuabind.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by CreatingClassesUsingLuabind.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/CreatingClassesUsingLuabind/CreatingClassesUsingLuabind.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "CreatingClassesUsingLuabind"=".\CreatingClassesUsingLuabind.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/CreatingClassesUsingLuabind/classes_in_lua.lua: -------------------------------------------------------------------------------- 1 | 2 | -----------------------------Lua script to define the class: Animal 3 | 4 | class 'Animal' 5 | 6 | function Animal:__init(num_legs, noise_made) 7 | 8 | self.NoiseMade = noise_made 9 | self.NumLegs = num_legs 10 | 11 | end 12 | 13 | function Animal:Speak() 14 | 15 | print(self.NoiseMade) 16 | 17 | end 18 | 19 | function Animal:GetNumLegs() 20 | 21 | return self.NumLegs 22 | 23 | end 24 | 25 | 26 | -------------------------------- example of use 27 | 28 | cat = Animal(4, "meow") 29 | 30 | cat:Speak() 31 | 32 | print ("a cat has "..cat:GetNumLegs().." legs") 33 | 34 | 35 | 36 | ------------------------------- an example of a derived class 37 | 38 | class 'Pet' (Animal) 39 | 40 | function Pet:__init(name, num_legs, noise_made) super(num_legs, noise_made) 41 | 42 | self.Name = name 43 | 44 | end 45 | 46 | function Pet:GetName() 47 | 48 | return self.Name 49 | 50 | end 51 | 52 | ---------------------------------and an example of use 53 | 54 | dog = Pet("Albert", 4, "woof") 55 | 56 | dog:Speak() 57 | 58 | print ("my dogs name is "..dog:GetName()) -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/CreatingClassesUsingLuabind/main.cpp: -------------------------------------------------------------------------------- 1 | //include the libraries 2 | #pragma comment(lib, "lua.lib") 3 | #pragma comment(lib, "lualib.lib") 4 | #pragma warning (disable : 4786) 5 | 6 | extern "C" 7 | { 8 | #include 9 | #include 10 | #include 11 | } 12 | 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | //include the luabind headers. Make sure you have the paths set correctly 18 | //to the lua, luabind and Boost files. 19 | #include 20 | using namespace luabind; 21 | 22 | #include "LuaHelperFunctions.h" 23 | 24 | 25 | 26 | int main() 27 | { 28 | //create a lua state 29 | lua_State* pLua = lua_open(); 30 | 31 | //open the libraries 32 | OpenLuaLibraries(pLua); 33 | 34 | //open luabind 35 | open(pLua); 36 | 37 | //load and run the script 38 | RunLuaScript(pLua, "classes_in_lua.lua"); 39 | 40 | lua_close(pLua); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPClassesUsingLuabind/Animal.h: -------------------------------------------------------------------------------- 1 | #ifndef ANIMAL_H 2 | #define ANIMAL_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | 9 | class Animal 10 | { 11 | private: 12 | 13 | int m_iNumLegs; 14 | 15 | std::string m_NoiseEmitted; 16 | 17 | public: 18 | 19 | Animal(std::string NoiseEmitted, 20 | int NumLegs):m_iNumLegs(NumLegs), 21 | m_NoiseEmitted(NoiseEmitted) 22 | {} 23 | 24 | virtual ~Animal(){} 25 | 26 | virtual void Speak()const 27 | {std::cout << "\n[C++]: " << m_NoiseEmitted << std::endl;} 28 | 29 | int NumLegs()const{return m_iNumLegs;} 30 | 31 | }; 32 | 33 | 34 | 35 | 36 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPClassesUsingLuabind/ExposingCPPClassesToLua.lua: -------------------------------------------------------------------------------- 1 | -- ExposingCPPClassesToLua.lua 2 | 3 | --create an animal object and call its methods 4 | 5 | cat = Animal("Meow", 4); 6 | 7 | print ("\n[Lua]: A cat has "..cat:NumLegs().. " legs."); 8 | 9 | cat:Speak(); 10 | 11 | 12 | print ("\n\n----------------------------------------------------"); 13 | 14 | MyPet = Pet("Scooter", "Meow", 4); 15 | 16 | print ("\n[Lua]: My pet is called "..MyPet:GetName()); 17 | 18 | MyPet:Speak(); -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPClassesUsingLuabind/ExposingCPPClassesUsingLuabind.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by ExposingCPPClassesUsingLuabind.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPClassesUsingLuabind/ExposingCPPClassesUsingLuabind.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "ExposingCPPClassesUsingLuabind"=".\ExposingCPPClassesUsingLuabind.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPClassesUsingLuabind/Pet.h: -------------------------------------------------------------------------------- 1 | #ifndef PET_H 2 | #define PET_H 3 | 4 | 5 | #include 6 | #include 7 | #include "Animal.h" 8 | 9 | 10 | 11 | class Pet : public Animal 12 | { 13 | private: 14 | 15 | std::string m_Name; 16 | 17 | public: 18 | 19 | Pet(std::string name, 20 | std::string noise, 21 | int NumLegs):Animal(noise, NumLegs), 22 | m_Name(name) 23 | {} 24 | 25 | std::string GetName()const{return m_Name;} 26 | }; 27 | 28 | 29 | 30 | 31 | 32 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPFunctionsUsingLuabind/ExposingCPPFunctionsToLua.lua: -------------------------------------------------------------------------------- 1 | -- lua script to demonstrate exposing C++ functions to Lua using luaBind 2 | 3 | -- Mat Buckland 2003 4 | 5 | print("[lua]: About to call the C++ HelloWorld() function") 6 | 7 | HelloWorld() 8 | 9 | 10 | print("\n[lua]: About to call the C++ add() function") 11 | 12 | a = 10 13 | b = 5 14 | 15 | print ("\n[lua]: "..a.." + "..b.." = "..add(a,b)) -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPFunctionsUsingLuabind/ExposingCPPFunctionsUsingLuabind.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by ExposingCPPFunctionsUsingLuabind.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPFunctionsUsingLuabind/ExposingCPPFunctionsUsingLuabind.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "ExposingCPPFunctionsUsingLuabind"=".\ExposingCPPFunctionsUsingLuabind.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ExposingCPPFunctionsUsingLuabind/main.cpp: -------------------------------------------------------------------------------- 1 | //include the libraries 2 | #pragma comment(lib, "lua.lib") 3 | #pragma comment(lib, "lualib.lib") 4 | 5 | //turn off the inevitable warnings 6 | #pragma warning (disable : 4786) 7 | 8 | extern "C" 9 | { 10 | #include 11 | #include 12 | #include 13 | } 14 | 15 | #include 16 | using namespace std; 17 | 18 | //include the luabind headers. Make sure you have the paths set correctly 19 | //to the lua, luabind and Boost files. 20 | #include 21 | using namespace luabind; 22 | 23 | //include the helper functions 24 | #include "LuaHelperFunctions.h" 25 | 26 | 27 | //define a couple of simple functions 28 | void HelloWorld() 29 | { 30 | cout << "\n[C++]: Hello World!" << endl; 31 | } 32 | 33 | int add(int a, int b) 34 | { 35 | return a + b; 36 | } 37 | 38 | 39 | 40 | int main() 41 | { 42 | //create a lua state 43 | lua_State* pLua = lua_open(); 44 | 45 | //open the lua std libraries 46 | OpenLuaLibraries(pLua); 47 | 48 | //open luabind 49 | open(pLua); 50 | 51 | module(pLua) 52 | [ 53 | def("HelloWorld", &HelloWorld), 54 | def("add", &add) 55 | ]; 56 | 57 | //load and run the script 58 | RunLuaScript(pLua, "ExposingCPPFunctionsToLua.lua"); 59 | 60 | 61 | //tidy up 62 | lua_close(pLua); 63 | 64 | 65 | return 0; 66 | } -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ScriptedStateMachine/Entity.h: -------------------------------------------------------------------------------- 1 | #ifndef ENTITY_H 2 | #define ENTITY_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: Entity.h 6 | // 7 | // Desc: Base class for a game object 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | #include 13 | 14 | 15 | class Entity 16 | { 17 | 18 | private: 19 | 20 | int m_ID; 21 | 22 | std::string m_Name; 23 | 24 | //used by the constructor to give each entity a unique ID 25 | int NextValidID(){static int NextID = 0; return NextID++;} 26 | 27 | public: 28 | 29 | Entity(std::string name = "NoName"):m_ID(NextValidID()), m_Name(name) 30 | {} 31 | 32 | virtual ~Entity() 33 | {} 34 | 35 | //all entities must implement an update function 36 | virtual void Update()=0; 37 | 38 | //accessors 39 | int ID()const{return m_ID;} 40 | std::string Name()const{return m_Name;} 41 | 42 | }; 43 | 44 | 45 | 46 | 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ScriptedStateMachine/Miner.cpp: -------------------------------------------------------------------------------- 1 | #include "Miner.h" 2 | 3 | 4 | Miner::Miner(std::string name):m_iGoldCarried(0), 5 | m_iFatigue(0), 6 | Entity(name) 7 | 8 | { 9 | m_pStateMachine = new ScriptedStateMachine(this); 10 | } 11 | 12 | void Miner::AddToGoldCarried(int val) 13 | { 14 | m_iGoldCarried += val; 15 | 16 | if (m_iGoldCarried < 0) m_iGoldCarried = 0; 17 | } 18 | 19 | 20 | void Miner::Update() 21 | { 22 | m_pStateMachine->Update(); 23 | } 24 | 25 | bool Miner::Fatigued()const 26 | { 27 | if (m_iFatigue > TirednessThreshold) 28 | { 29 | return true; 30 | } 31 | 32 | return false; 33 | } -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ScriptedStateMachine/ScriptedStateMachine.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by ScriptedStateMachine.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/ScriptedStateMachine/ScriptedStateMachine.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "ScriptedStateMachine"=".\ScriptedStateMachine.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/StartHere.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by StartHere.mak 2 | 3 | .\main.cpp : \ 4 | "..\..\common\lua-5.0\include\lauxlib.h"\ 5 | "..\..\common\lua-5.0\include\lua.h"\ 6 | "..\..\common\lua-5.0\include\lualib.h"\ 7 | 8 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/StartHere.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "StartHere"=.\StartHere.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/StartHere.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter6_Scripting_Source/StartHere/StartHere.ncb -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/StartHere.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter6_Scripting_Source/StartHere/StartHere.opt -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/main.cpp: -------------------------------------------------------------------------------- 1 | extern "C" 2 | { 3 | #include 4 | #include 5 | #include 6 | } 7 | 8 | //include the lua libraries. If your compiler doesn't support this pragma 9 | //then don't forget to add the libraries in your project settings! 10 | #pragma comment(lib, "lua.lib") 11 | #pragma comment(lib, "lualib.lib") 12 | 13 | #include 14 | 15 | int main() 16 | { 17 | //create a lua state 18 | lua_State* pL = lua_open(); 19 | 20 | //enable access to the standard libraries 21 | luaopen_base(pL); 22 | luaopen_string(pL); 23 | luaopen_table(pL); 24 | luaopen_math(pL); 25 | luaopen_io(pL); 26 | 27 | if (int error = lua_dofile(pL, "your_first_lua_script.lua") != 0) 28 | { 29 | std::cout << "\n[C++]: ERROR(" << error << "): Problem with lua script file!\n\n" << std::endl; 30 | 31 | return 0; 32 | } 33 | 34 | //tidy up 35 | lua_close(pL); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/StartHere/your_first_lua_script.lua: -------------------------------------------------------------------------------- 1 | print ("Hello World!") 2 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/cpp_using_lua/cpp_using_lua.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by cpp_using_lua.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/cpp_using_lua/cpp_using_lua.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "cpp_using_lua"=".\cpp_using_lua.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/cpp_using_lua/cpp_using_lua.lua: -------------------------------------------------------------------------------- 1 | -- lua script to demonstrate global variables 2 | 3 | --global string and number types 4 | 5 | name = "Spiderman"; 6 | age = 29; 7 | 8 | 9 | --global table creation 10 | 11 | simple_table = {name="Dan Dare", age=20}; 12 | 13 | 14 | --a simple function to add two numbers 15 | 16 | function add(a,b) 17 | 18 | return (a+b); 19 | 20 | end; 21 | 22 | 23 | print("[lua]: Finished running script \"cpp_using_lua.lua\""); -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/cpp_using_lua/cpp_using_lua.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter6_Scripting_Source/cpp_using_lua/cpp_using_lua.suo -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/lua_using_cpp/lua_using_cpp.dep: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Generated Dependency File, included by lua_using_cpp.mak 2 | 3 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/lua_using_cpp/lua_using_cpp.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "lua_using_cpp"=".\lua_using_cpp.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter6_Scripting_Source/lua_using_cpp/main.cpp: -------------------------------------------------------------------------------- 1 | extern "C" 2 | { 3 | #include 4 | #include 5 | #include 6 | } 7 | 8 | #pragma comment(lib, "lua.lib") 9 | #pragma comment(lib, "lualib.lib") 10 | 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | #include "LuaHelperFunctions.h" 16 | #include "RockPaperScissors.h" 17 | 18 | 19 | 20 | 21 | int main() 22 | { 23 | //create a lua state 24 | lua_State* pL = lua_open(); 25 | 26 | OpenLuaLibraries(pL); 27 | 28 | //register the functions with lua 29 | lua_register(pL, "cpp_GetAIMove", cpp_GetAIMove); 30 | lua_register(pL, "cpp_EvaluateTheGuesses", cpp_EvaluateTheGuesses); 31 | 32 | //run the script 33 | RunLuaScript(pL, "Rock_Paper_Scissors_Using_C++_Funcs.lua"); 34 | 35 | //tidy up 36 | lua_close(pL); 37 | 38 | cout << "\n\n\n"; 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/GraveMarkers.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAVE_MARKERS_H 2 | #define GRAVE_MARKERS_H 3 | #pragma warning (disable : 4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: GraveMarkers.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: Class to record and render graves at the site of a bot's death 11 | // 12 | //----------------------------------------------------------------------------- 13 | #include 14 | #include 15 | #include "2d/vector2d.h" 16 | #include "time/crudetimer.h" 17 | 18 | class GraveMarkers 19 | { 20 | private: 21 | 22 | struct GraveRecord 23 | { 24 | Vector2D Position; 25 | double TimeCreated; 26 | 27 | GraveRecord(Vector2D pos):Position(pos), 28 | TimeCreated(Clock->GetCurrentTime()) 29 | {} 30 | }; 31 | 32 | private: 33 | 34 | typedef std::list GraveList; 35 | 36 | private: 37 | 38 | //how long a grave remains on screen 39 | double m_dLifeTime; 40 | 41 | //when a bot dies, a grave is rendered to mark the spot. 42 | std::vector m_vecRIPVB; 43 | std::vector m_vecRIPVBTrans; 44 | GraveList m_GraveList; 45 | 46 | 47 | public: 48 | 49 | GraveMarkers(double lifetime); 50 | 51 | void Update(); 52 | void Render(); 53 | void AddGrave(Vector2D pos); 54 | 55 | }; 56 | 57 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Map Editor/MapEditor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter7 to 10_Raven/Map Editor/MapEditor.exe -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Map Editor/MapEditorParams.ini: -------------------------------------------------------------------------------- 1 | 2 | DefaultNodeSpacing = 20 3 | 4 | -- edges will only be added if two nodes are less than this length apart 5 | DefaultMaxEdgeLength = math.sqrt(2) * DefaultNodeSpacing 6 | 7 | 8 | --a node must be at least this far away from a wall or obstacle. To prevent 9 | -- your agents bumping into walls it's wise to set this to a value slightly 10 | --larger than their bounding radius (in raven BRadius is 10 * scale found in params.lua) 11 | NodeMargin = 10 12 | 13 | -- default bounding radius of a walkover object (for selection) 14 | DefaultWalkoverRadius = 7 15 | 16 | --how close the mouse cursor has to be to an object to select it 17 | SelectionTolerance = 3 18 | 19 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Raven.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Raven"=".\Raven.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Raven_Messages.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_MESSAGES_H 2 | #define RAVEN_MESSAGES_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: Raven_Messages.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: file to enumerate the messages a Raven_Bot must be able to handle 10 | //----------------------------------------------------------------------------- 11 | #include 12 | 13 | enum message_type 14 | { 15 | Msg_Blank, 16 | Msg_PathReady, 17 | Msg_NoPathAvailable, 18 | Msg_TakeThatMF, 19 | Msg_YouGotMeYouSOB, 20 | Msg_GoalQueueEmpty, 21 | Msg_OpenSesame, 22 | Msg_GunshotSound, 23 | Msg_UserHasRemovedBot 24 | }; 25 | 26 | //used for outputting debug info 27 | inline std::string MessageToString(int msg) 28 | { 29 | switch(msg) 30 | { 31 | case Msg_PathReady: 32 | 33 | return "Msg_PathReady"; 34 | 35 | case Msg_NoPathAvailable: 36 | 37 | return "Msg_NoPathAvailable"; 38 | 39 | case Msg_TakeThatMF: 40 | 41 | return "Msg_TakeThatMF"; 42 | 43 | case Msg_YouGotMeYouSOB: 44 | 45 | return "Msg_YouGotMeYouSOB"; 46 | 47 | case Msg_GoalQueueEmpty: 48 | 49 | return "Msg_GoalQueueEmpty"; 50 | 51 | case Msg_OpenSesame: 52 | 53 | return "Msg_OpenSesame"; 54 | 55 | case Msg_GunshotSound: 56 | 57 | return "Msg_GunshotSound"; 58 | 59 | case Msg_UserHasRemovedBot: 60 | 61 | return "Msg_UserHasRemovedBot"; 62 | 63 | default: 64 | 65 | return "Undefined message!"; 66 | } 67 | } 68 | 69 | 70 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Raven_Target.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_TARGET_H 2 | #define RAVEN_TARGET_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: Raven_Target 6 | // 7 | // Author: Mat Buckland (ai-junkie.com) 8 | // 9 | // Desc: struct to hold data about a target 10 | // 11 | //----------------------------------------------------------------------------- 12 | 13 | struct Raven_Target 14 | { 15 | //the current target (this will be null if there is no target assigned) 16 | Raven_Bot* Instance; 17 | 18 | //a vector marking the last visible position of the target. 19 | Vector2D LastVisiblePosition; 20 | 21 | //true if target is within the field of view of the owner 22 | bool isWithinFOV; 23 | 24 | //true if there is no obstruction between the target and the owner, 25 | //permitting a shot. (for example, a the target may be behind the owner 26 | //but in the open. In this situation m_bWithinFOV is false but m_bShootable 27 | //is true). This value is utilized by the owner to determine whether or not 28 | //to turn around and face the target when approached from behind 29 | bool isShootable; 30 | 31 | Raven_Target():Instance(0), isWithinFOV(false), isShootable(false){} 32 | 33 | void Reset(){Instance = 0; isWithinFOV = false; isShootable = false;} 34 | }; 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Raven_UserOptions.cpp: -------------------------------------------------------------------------------- 1 | #include "Raven_UserOptions.h" 2 | 3 | 4 | Raven_UserOptions* Raven_UserOptions::Instance() 5 | { 6 | static Raven_UserOptions instance; 7 | return &instance; 8 | } 9 | 10 | Raven_UserOptions::Raven_UserOptions():m_bShowGraph(false), 11 | m_bShowPathOfSelectedBot(true), 12 | m_bSmoothPathsQuick(false), 13 | m_bSmoothPathsPrecise(false), 14 | m_bShowBotIDs(false), 15 | m_bShowBotHealth(true), 16 | m_bShowTargetOfSelectedBot(false), 17 | m_bOnlyShowBotsInTargetsFOV(false), 18 | m_bShowScore(false), 19 | m_bShowGoalsOfSelectedBot(true), 20 | m_bShowGoalAppraisals(true), 21 | m_bShowNodeIndices(false), 22 | m_bShowOpponentsSensedBySelectedBot(true), 23 | m_bShowWeaponAppraisals(false) 24 | {} 25 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Raven_UserOptions.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_OPTIONS 2 | #define USER_OPTIONS 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: Raven_UserOptions.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: singleton class to control a number of menu options 10 | //----------------------------------------------------------------------------- 11 | 12 | 13 | #define UserOptions Raven_UserOptions::Instance() 14 | 15 | class Raven_UserOptions 16 | { 17 | private: 18 | 19 | Raven_UserOptions(); 20 | 21 | //copy ctor and assignment should be private 22 | Raven_UserOptions(const Raven_UserOptions&); 23 | Raven_UserOptions& operator=(const Raven_UserOptions&); 24 | 25 | 26 | public: 27 | 28 | static Raven_UserOptions* Instance(); 29 | 30 | bool m_bShowGraph; 31 | 32 | bool m_bShowNodeIndices; 33 | 34 | bool m_bShowPathOfSelectedBot; 35 | 36 | bool m_bShowTargetOfSelectedBot; 37 | 38 | bool m_bShowOpponentsSensedBySelectedBot; 39 | 40 | bool m_bOnlyShowBotsInTargetsFOV; 41 | 42 | bool m_bShowGoalsOfSelectedBot; 43 | 44 | bool m_bShowGoalAppraisals; 45 | 46 | bool m_bShowWeaponAppraisals; 47 | 48 | bool m_bSmoothPathsQuick; 49 | bool m_bSmoothPathsPrecise; 50 | 51 | bool m_bShowBotIDs; 52 | 53 | bool m_bShowBotHealth; 54 | 55 | bool m_bShowScore; 56 | }; 57 | 58 | 59 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Script1.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter7 to 10_Raven/Script1.aps -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/Script1.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter7 to 10_Raven/Script1.rc -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Projectile_Bolt.h: -------------------------------------------------------------------------------- 1 | #ifndef BOLT_H 2 | #define BOLT_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Bolt.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: class to implement a bolt type projectile 11 | // 12 | //----------------------------------------------------------------------------- 13 | #include "Raven_Projectile.h" 14 | 15 | class Raven_Bot; 16 | 17 | 18 | 19 | class Bolt : public Raven_Projectile 20 | { 21 | private: 22 | 23 | //tests the trajectory of the shell for an impact 24 | void TestForImpact(); 25 | 26 | public: 27 | 28 | Bolt(Raven_Bot* shooter, Vector2D target); 29 | 30 | void Render(); 31 | 32 | void Update(); 33 | 34 | }; 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Projectile_Pellet.h: -------------------------------------------------------------------------------- 1 | #ifndef PELLET_H 2 | #define PELLET_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Pellet.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: class to implement a pellet type projectile 11 | // 12 | //----------------------------------------------------------------------------- 13 | 14 | #include "Raven_Projectile.h" 15 | 16 | class Raven_Bot; 17 | class Raven_Environment; 18 | 19 | class Pellet : public Raven_Projectile 20 | { 21 | private: 22 | 23 | //when this projectile hits something it's trajectory is rendered 24 | //for this amount of time 25 | double m_dTimeShotIsVisible; 26 | 27 | //tests the trajectory of the pellet for an impact 28 | void TestForImpact(); 29 | 30 | //returns true if the shot is still to be rendered 31 | bool isVisibleToPlayer()const{return Clock->GetCurrentTime() < m_dTimeOfCreation + m_dTimeShotIsVisible;} 32 | 33 | public: 34 | 35 | Pellet(Raven_Bot* shooter, Vector2D target); 36 | 37 | void Render(); 38 | 39 | void Update(); 40 | 41 | }; 42 | 43 | 44 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Projectile_Rocket.h: -------------------------------------------------------------------------------- 1 | #ifndef ROCKET_H 2 | #define ROCKET_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Rocket.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: class to implement a rocket 11 | // 12 | //----------------------------------------------------------------------------- 13 | 14 | #include "Raven_Projectile.h" 15 | 16 | class Raven_Bot; 17 | 18 | class Rocket : public Raven_Projectile 19 | { 20 | private: 21 | 22 | //the radius of damage, once the rocket has impacted 23 | double m_dBlastRadius; 24 | 25 | //this is used to render the splash when the rocket impacts 26 | double m_dCurrentBlastRadius; 27 | 28 | //If the rocket has impacted we test all bots to see if they are within the 29 | //blast radius and reduce their health accordingly 30 | void InflictDamageOnBotsWithinBlastRadius(); 31 | 32 | //tests the trajectory of the shell for an impact 33 | void TestForImpact(); 34 | 35 | public: 36 | 37 | Rocket(Raven_Bot* shooter, Vector2D target); 38 | 39 | void Render(); 40 | 41 | void Update(); 42 | 43 | }; 44 | 45 | 46 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Projectile_Slug.h: -------------------------------------------------------------------------------- 1 | #ifndef SLUG_H 2 | #define SLUG_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Slug.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to implement a railgun slug 11 | //----------------------------------------------------------------------------- 12 | 13 | #include "Raven_Projectile.h" 14 | 15 | class Raven_Bot; 16 | class Raven_Environment; 17 | 18 | class Slug : public Raven_Projectile 19 | { 20 | private: 21 | 22 | //when this projectile hits something it's trajectory is rendered 23 | //for this amount of time 24 | double m_dTimeShotIsVisible; 25 | 26 | //tests the trajectory of the shell for an impact 27 | void TestForImpact(); 28 | 29 | //returns true if the shot is still to be rendered 30 | bool isVisibleToPlayer()const{return Clock->GetCurrentTime() < m_dTimeOfCreation + m_dTimeShotIsVisible;} 31 | 32 | public: 33 | 34 | Slug(Raven_Bot* shooter, Vector2D target); 35 | 36 | void Render(); 37 | 38 | void Update(); 39 | 40 | }; 41 | 42 | 43 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Raven_Weapon.cpp: -------------------------------------------------------------------------------- 1 | #include "Raven_Weapon.h" 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Weapon_Blaster.h: -------------------------------------------------------------------------------- 1 | #ifndef BLASTER_H 2 | #define BLASTER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Weapon_Blaster.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: 11 | //----------------------------------------------------------------------------- 12 | #include "Raven_Weapon.h" 13 | 14 | 15 | class Raven_Bot; 16 | 17 | 18 | 19 | class Blaster : public Raven_Weapon 20 | { 21 | private: 22 | 23 | void InitializeFuzzyModule(); 24 | 25 | public: 26 | 27 | Blaster(Raven_Bot* owner); 28 | 29 | 30 | void Render(); 31 | 32 | void ShootAt(Vector2D pos); 33 | 34 | double GetDesirability(double DistToTarget); 35 | }; 36 | 37 | 38 | 39 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Weapon_RailGun.h: -------------------------------------------------------------------------------- 1 | #ifndef RAILGUN_H 2 | #define RAILGUN_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Weapon_RailGun.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to implement a rail gun 11 | //----------------------------------------------------------------------------- 12 | #include "Raven_Weapon.h" 13 | 14 | 15 | class Raven_Bot; 16 | 17 | 18 | 19 | class RailGun : public Raven_Weapon 20 | { 21 | private: 22 | 23 | void InitializeFuzzyModule(); 24 | 25 | public: 26 | 27 | RailGun(Raven_Bot* owner); 28 | 29 | void Render(); 30 | 31 | void ShootAt(Vector2D pos); 32 | 33 | double GetDesirability(double DistToTarget); 34 | }; 35 | 36 | 37 | 38 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Weapon_RocketLauncher.h: -------------------------------------------------------------------------------- 1 | #ifndef ROCKETLAUNCHER_H 2 | #define ROCKETLAUNCHER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: RocketLauncher 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to implement a rocket launcher 11 | //----------------------------------------------------------------------------- 12 | #include "Raven_Weapon.h" 13 | 14 | 15 | 16 | class Raven_Bot; 17 | 18 | class RocketLauncher : public Raven_Weapon 19 | { 20 | private: 21 | 22 | void InitializeFuzzyModule(); 23 | 24 | public: 25 | 26 | RocketLauncher(Raven_Bot* owner); 27 | 28 | 29 | void Render(); 30 | 31 | void ShootAt(Vector2D pos); 32 | 33 | double GetDesirability(double DistToTarget); 34 | }; 35 | 36 | 37 | 38 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/armory/Weapon_ShotGun.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOTGUN_H 2 | #define SHOTGUN_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Weapon_ShotGun.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to implement a shot gun 11 | //----------------------------------------------------------------------------- 12 | #include "Raven_Weapon.h" 13 | 14 | 15 | class Raven_Bot; 16 | 17 | 18 | 19 | class ShotGun : public Raven_Weapon 20 | { 21 | private: 22 | 23 | void InitializeFuzzyModule(); 24 | 25 | //how much shot the each shell contains 26 | int m_iNumBallsInShell; 27 | 28 | //how much the shot spreads out when a cartridge is discharged 29 | double m_dSpread; 30 | 31 | public: 32 | 33 | ShotGun(Raven_Bot* owner); 34 | 35 | void Render(); 36 | 37 | void ShootAt(Vector2D pos); 38 | 39 | double GetDesirability(double DistToTarget); 40 | }; 41 | 42 | 43 | 44 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | 5 | 6 | const int WindowWidth = 500; 7 | const int WindowHeight = 500; 8 | const int FrameRate = 60; 9 | 10 | 11 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/AttackTargetGoal_Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_ATTACK_GOAL_EVALUATOR 2 | #define RAVEN_ATTACK_GOAL_EVALUATOR 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: AttackTargetGoal_Evaluator.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to calculate how desirable the goal of attacking the bot's 11 | // current target is 12 | //----------------------------------------------------------------------------- 13 | 14 | #include "Goal_Evaluator.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | class AttackTargetGoal_Evaluator : public Goal_Evaluator 19 | { 20 | public: 21 | 22 | AttackTargetGoal_Evaluator(double bias):Goal_Evaluator(bias){} 23 | 24 | double CalculateDesirability(Raven_Bot* pBot); 25 | 26 | void SetGoal(Raven_Bot* pEnt); 27 | 28 | void RenderInfo(Vector2D Position, Raven_Bot* pBot); 29 | }; 30 | 31 | 32 | 33 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/ExploreGoal_Evaluator.cpp: -------------------------------------------------------------------------------- 1 | #include "ExploreGoal_Evaluator.h" 2 | #include "../navigation/Raven_PathPlanner.h" 3 | #include "../Raven_ObjectEnumerations.h" 4 | #include "../lua/Raven_Scriptor.h" 5 | #include "misc/Stream_Utility_Functions.h" 6 | #include "Raven_Feature.h" 7 | 8 | #include "Goal_Think.h" 9 | #include "Raven_Goal_Types.h" 10 | 11 | 12 | 13 | 14 | //---------------- CalculateDesirability ------------------------------------- 15 | //----------------------------------------------------------------------------- 16 | double ExploreGoal_Evaluator::CalculateDesirability(Raven_Bot* pBot) 17 | { 18 | double Desirability = 0.05; 19 | 20 | Desirability *= m_dCharacterBias; 21 | 22 | return Desirability; 23 | } 24 | 25 | //----------------------------- SetGoal --------------------------------------- 26 | //----------------------------------------------------------------------------- 27 | void ExploreGoal_Evaluator::SetGoal(Raven_Bot* pBot) 28 | { 29 | pBot->GetBrain()->AddGoal_Explore(); 30 | } 31 | 32 | //-------------------------- RenderInfo --------------------------------------- 33 | //----------------------------------------------------------------------------- 34 | void ExploreGoal_Evaluator::RenderInfo(Vector2D Position, Raven_Bot* pBot) 35 | { 36 | gdi->TextAtPos(Position, "EX: " + ttos(CalculateDesirability(pBot), 2)); 37 | } -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/ExploreGoal_Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_EXPLORE_GOAL_EVALUATOR 2 | #define RAVEN_EXPLORE_GOAL_EVALUATOR 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: ExploreGoal_Evaluator.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to calculate how desirable the goal of exploring is 11 | //----------------------------------------------------------------------------- 12 | 13 | #include "Goal_Evaluator.h" 14 | #include "../Raven_Bot.h" 15 | 16 | 17 | class ExploreGoal_Evaluator : public Goal_Evaluator 18 | { 19 | public: 20 | 21 | ExploreGoal_Evaluator(double bias):Goal_Evaluator(bias){} 22 | 23 | double CalculateDesirability(Raven_Bot* pBot); 24 | 25 | void SetGoal(Raven_Bot* pEnt); 26 | 27 | void RenderInfo(Vector2D Position, Raven_Bot* pBot); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/GetHealthGoal_Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_HEALTH_EVALUATOR 2 | #define RAVEN_HEALTH_EVALUATOR 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: GetHealthGoal_Evaluator.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to calculate how desirable the goal of fetching a health item 11 | // is 12 | //----------------------------------------------------------------------------- 13 | 14 | #include "Goal_Evaluator.h" 15 | #include "../Raven_Bot.h" 16 | 17 | class GetHealthGoal_Evaluator : public Goal_Evaluator 18 | { 19 | public: 20 | 21 | GetHealthGoal_Evaluator(double bias):Goal_Evaluator(bias){} 22 | 23 | double CalculateDesirability(Raven_Bot* pBot); 24 | 25 | void SetGoal(Raven_Bot* pEnt); 26 | 27 | void RenderInfo(Vector2D Position, Raven_Bot* pBot); 28 | }; 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/GetWeaponGoal_Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_WEAPON_EVALUATOR 2 | #define RAVEN_WEAPON_EVALUATOR 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: GetWeaponGoal_Evaluator.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class to calculate how desirable the goal of fetching a weapon item 11 | // is 12 | //----------------------------------------------------------------------------- 13 | 14 | #include "Goal_Evaluator.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | class GetWeaponGoal_Evaluator : public Goal_Evaluator 19 | { 20 | int m_iWeaponType; 21 | 22 | public: 23 | 24 | GetWeaponGoal_Evaluator(double bias, 25 | int WeaponType):Goal_Evaluator(bias), 26 | m_iWeaponType(WeaponType) 27 | {} 28 | 29 | double CalculateDesirability(Raven_Bot* pBot); 30 | 31 | void SetGoal(Raven_Bot* pEnt); 32 | 33 | void RenderInfo(Vector2D Position, Raven_Bot* pBot); 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_AdjustRange.cpp: -------------------------------------------------------------------------------- 1 | #include "Goal_AdjustRange.h" 2 | #include "..\Raven_Bot.h" 3 | #include "..\Raven_SteeringBehaviors.h" 4 | #include "../armory/Raven_Weapon.h" 5 | 6 | 7 | 8 | Goal_AdjustRange::Goal_AdjustRange(Raven_Bot* pBot):Goal(pBot, goal_adjust_range), 9 | m_dIdealRange(0) 10 | {} 11 | 12 | //---------------------------- Initialize ------------------------------------- 13 | //----------------------------------------------------------------------------- 14 | void Goal_AdjustRange::Activate() 15 | { 16 | m_pOwner->GetSteering()->SetTarget(m_pOwner->GetTargetBot()->Pos()); 17 | 18 | 19 | } 20 | 21 | //------------------------------ Process -------------------------------------- 22 | //----------------------------------------------------------------------------- 23 | int Goal_AdjustRange::Process() 24 | { 25 | //if status is inactive, call Activate() 26 | ActivateIfInactive(); 27 | 28 | /* 29 | if (m_pOwner->GetCurrentWeapon()->isInIdealWeaponRange()) 30 | { 31 | m_iStatus = completed; 32 | } 33 | */ 34 | return m_iStatus; 35 | } 36 | 37 | //---------------------------- Terminate -------------------------------------- 38 | //----------------------------------------------------------------------------- 39 | void Goal_AdjustRange::Terminate() 40 | { 41 | 42 | 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_AdjustRange.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_ADJUST_RANGE_H 2 | #define GOAL_ADJUST_RANGE_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_AdjustRange.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: 11 | // 12 | //----------------------------------------------------------------------------- 13 | #include "goals/Goal.h" 14 | #include "Raven_Goal_Types.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | 19 | 20 | 21 | class Goal_AdjustRange : public Goal 22 | { 23 | private: 24 | 25 | Raven_Bot* m_pTarget; 26 | 27 | double m_dIdealRange; 28 | 29 | public: 30 | 31 | Goal_AdjustRange(Raven_Bot* pBot); 32 | 33 | void Activate(); 34 | 35 | int Process(); 36 | 37 | void Terminate(); 38 | 39 | }; 40 | 41 | 42 | 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_AttackTarget.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_ATTACKTARGET_H 2 | #define GOAL_ATTACKTARGET_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_AttackTarget.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: 11 | // 12 | //----------------------------------------------------------------------------- 13 | #include "Goals/Goal_Composite.h" 14 | #include "Raven_Goal_Types.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | 19 | 20 | 21 | class Goal_AttackTarget : public Goal_Composite 22 | { 23 | public: 24 | 25 | Goal_AttackTarget(Raven_Bot* pOwner):Goal_Composite(pOwner, goal_attack_target) 26 | {} 27 | 28 | void Activate(); 29 | 30 | int Process(); 31 | 32 | void Terminate(){m_iStatus = completed;} 33 | 34 | }; 35 | 36 | 37 | 38 | 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_DodgeSideToSide.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_DODGE_SIDE_H 2 | #define GOAL_DODGE_SIDE_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_DodgeSideToSide.h 7 | // 8 | // Author: Mat Buckland (ai-junkie.com) 9 | // 10 | // Desc: this goal makes the bot dodge from side to side 11 | // 12 | //----------------------------------------------------------------------------- 13 | #include "Goals/Goal.h" 14 | #include "Raven_Goal_Types.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | 19 | 20 | 21 | class Goal_DodgeSideToSide : public Goal 22 | { 23 | private: 24 | 25 | Vector2D m_vStrafeTarget; 26 | 27 | bool m_bClockwise; 28 | 29 | Vector2D GetStrafeTarget()const; 30 | 31 | 32 | public: 33 | 34 | Goal_DodgeSideToSide(Raven_Bot* pBot):Goal(pBot, goal_strafe), 35 | m_bClockwise(RandBool()) 36 | {} 37 | 38 | 39 | void Activate(); 40 | 41 | int Process(); 42 | 43 | void Render(); 44 | 45 | void Terminate(); 46 | 47 | }; 48 | 49 | 50 | 51 | 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_EVALUATOR_H 2 | #define GOAL_EVALUATOR_H 3 | #pragma warning (disable : 4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_Evaluator.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: class template that defines an interface for objects that are 11 | // able to evaluate the desirability of a specific strategy level goal 12 | //----------------------------------------------------------------------------- 13 | class Raven_Bot; 14 | struct Vector2D; 15 | 16 | 17 | class Goal_Evaluator 18 | { 19 | protected: 20 | 21 | //when the desirability score for a goal has been evaluated it is multiplied 22 | //by this value. It can be used to create bots with preferences based upon 23 | //their personality 24 | double m_dCharacterBias; 25 | 26 | public: 27 | 28 | Goal_Evaluator(double CharacterBias):m_dCharacterBias(CharacterBias){} 29 | 30 | virtual ~Goal_Evaluator(){} 31 | 32 | //returns a score between 0 and 1 representing the desirability of the 33 | //strategy the concrete subclass represents 34 | virtual double CalculateDesirability(Raven_Bot* pBot)=0; 35 | 36 | //adds the appropriate goal to the given bot's brain 37 | virtual void SetGoal(Raven_Bot* pBot) = 0; 38 | 39 | //used to provide debugging/tweaking support 40 | virtual void RenderInfo(Vector2D Position, Raven_Bot* pBot) = 0; 41 | }; 42 | 43 | 44 | 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_Explore.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_EXPLORE_H 2 | #define GOAL_EXPLORE_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal_Composite.h" 6 | #include "Raven_Goal_Types.h" 7 | 8 | 9 | class Raven_Bot; 10 | 11 | 12 | class Goal_Explore : public Goal_Composite 13 | { 14 | private: 15 | 16 | Vector2D m_CurrentDestination; 17 | 18 | //set to true when the destination for the exploration has been established 19 | bool m_bDestinationIsSet; 20 | 21 | public: 22 | 23 | Goal_Explore(Raven_Bot* pOwner):Goal_Composite(pOwner, 24 | goal_explore), 25 | m_bDestinationIsSet(false) 26 | {} 27 | 28 | 29 | void Activate(); 30 | 31 | int Process(); 32 | 33 | void Terminate(){} 34 | 35 | bool HandleMessage(const Telegram& msg); 36 | }; 37 | 38 | 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_FindTarget.cpp: -------------------------------------------------------------------------------- 1 | #include "Goal_Wander.h" 2 | #include "..\Raven_Bot.h" 3 | #include "..\Raven_SteeringBehaviors.h" 4 | 5 | 6 | 7 | 8 | 9 | //---------------------------- Initialize ------------------------------------- 10 | //----------------------------------------------------------------------------- 11 | void Goal_Wander::Activate() 12 | { 13 | m_pOwner->GetSteering()->WanderOn(); 14 | } 15 | 16 | //------------------------------ Process -------------------------------------- 17 | //----------------------------------------------------------------------------- 18 | int Goal_Wander::Process() 19 | { 20 | if (m_Status == inactive) 21 | { 22 | Activate(); 23 | m_Status = active; 24 | } 25 | 26 | return m_Status; 27 | } 28 | 29 | //---------------------------- Terminate -------------------------------------- 30 | //----------------------------------------------------------------------------- 31 | void Goal_Wander::Terminate() 32 | { 33 | m_pOwner->GetSteering()->WanderOff(); 34 | 35 | m_Status = completed; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_FindTarget.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_WANDER_H 2 | #define GOAL_WANDER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_Wander.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: Causes a bot to wander until terminated 11 | //----------------------------------------------------------------------------- 12 | #include "ai/Goal.h" 13 | #include "Raven_Goal_Types.h" 14 | #include "../Raven_Bot.h" 15 | 16 | 17 | class Goal_Wander : public Goal 18 | { 19 | private: 20 | 21 | public: 22 | 23 | Goal_Wander(Raven_Bot* pBot):Goal(pBot,goal_wander) 24 | {} 25 | 26 | void Activate(); 27 | 28 | int Process(); 29 | 30 | void Terminate(); 31 | }; 32 | 33 | 34 | 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_FollowPath.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_FOLLOWPATH_H 2 | #define GOAL_FOLLOWPATH_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_FollowPath.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: 11 | //----------------------------------------------------------------------------- 12 | #include "Goals/Goal_Composite.h" 13 | #include "Raven_Goal_Types.h" 14 | #include "../Raven_Bot.h" 15 | #include "../navigation/Raven_PathPlanner.h" 16 | #include "../navigation/PathEdge.h" 17 | 18 | 19 | 20 | class Goal_FollowPath : public Goal_Composite 21 | { 22 | private: 23 | 24 | //a local copy of the path returned by the path planner 25 | std::list m_Path; 26 | 27 | public: 28 | 29 | Goal_FollowPath(Raven_Bot* pBot, std::list path); 30 | 31 | //the usual suspects 32 | void Activate(); 33 | int Process(); 34 | void Render(); 35 | void Terminate(){} 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_GetItem.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_GET_ITEM_H 2 | #define GOAL_GET_ITEM_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal_Composite.h" 6 | #include "Raven_Goal_Types.h" 7 | #include "../Raven_Bot.h" 8 | #include "triggers/trigger.h" 9 | 10 | 11 | //helper function to change an item type enumeration into a goal type 12 | int ItemTypeToGoalType(int gt); 13 | 14 | 15 | class Goal_GetItem : public Goal_Composite 16 | { 17 | private: 18 | 19 | int m_iItemToGet; 20 | 21 | Trigger* m_pGiverTrigger; 22 | 23 | //true if a path to the item has been formulated 24 | bool m_bFollowingPath; 25 | 26 | //returns true if the bot sees that the item it is heading for has been 27 | //picked up by an opponent 28 | bool hasItemBeenStolen()const; 29 | 30 | public: 31 | 32 | Goal_GetItem(Raven_Bot* pBot, 33 | int item):Goal_Composite(pBot, 34 | ItemTypeToGoalType(item)), 35 | m_iItemToGet(item), 36 | m_pGiverTrigger(0), 37 | m_bFollowingPath(false) 38 | {} 39 | 40 | 41 | void Activate(); 42 | 43 | int Process(); 44 | 45 | bool HandleMessage(const Telegram& msg); 46 | 47 | void Terminate(){m_iStatus = completed;} 48 | }; 49 | 50 | 51 | 52 | 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_HuntTarget.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_FIND_TARGET_H 2 | #define GOAL_FIND_TARGET_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_HuntTarget.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: Causes a bot to search for its current target. Exits when target 11 | // is in view 12 | //----------------------------------------------------------------------------- 13 | #include "Goals/Goal_Composite.h" 14 | #include "Raven_Goal_Types.h" 15 | #include "../Raven_Bot.h" 16 | 17 | 18 | class Goal_HuntTarget : public Goal_Composite 19 | { 20 | private: 21 | 22 | //this value is set to true if the last visible position of the target 23 | //bot has been searched without success 24 | bool m_bLVPTried; 25 | 26 | public: 27 | 28 | Goal_HuntTarget(Raven_Bot* pBot):Goal_Composite(pBot, goal_hunt_target), 29 | m_bLVPTried(false) 30 | {} 31 | 32 | //the usual suspects 33 | void Activate(); 34 | int Process(); 35 | void Terminate(){} 36 | 37 | void Render(); 38 | 39 | 40 | }; 41 | 42 | 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_MoveToItem.cpp: -------------------------------------------------------------------------------- 1 | #include "Goal_MoveToItem.h" 2 | 3 | #include "..\Raven_Bot.h" 4 | #include "..\Raven_NavModule.h" 5 | 6 | #include "Raven_GoalQ.h" 7 | 8 | 9 | 10 | void Goal_MoveToItem::Initialize() 11 | { 12 | //request a path to the item 13 | m_pOwner->NavModule()->CreatePathToItem(m_iItemType); 14 | 15 | //the bot may have to wait a few update cycles before a path is calculated 16 | //so for appearances sake it just moves forward a little 17 | m_pOwner->GoalQ()->AddGoal_SeekToPosition(m_pOwner->Pos() + m_pOwner->Facing()*20); 18 | 19 | //this goal is now satisfied 20 | m_bSatisfied = true; 21 | } 22 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_MoveToItem.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_MOVE_TO_ITEM_H 2 | #define GOAL_MOVE_TO_ITEM_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Raven_Goal.h" 6 | 7 | 8 | class Raven_Bot; 9 | 10 | 11 | class Goal_MoveToItem : public Raven_Goal 12 | { 13 | private: 14 | 15 | int m_iItemType; 16 | 17 | public: 18 | 19 | Goal_MoveToItem(Raven_Bot* pBot, 20 | int type):Raven_Goal(pBot, goal_explore), 21 | m_iItemType(type) 22 | {} 23 | 24 | void Initialize(); 25 | 26 | void Process(){} 27 | 28 | void Terminate(){} 29 | }; 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_MoveToPosition.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_MOVE_POS_H 2 | #define GOAL_MOVE_POS_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal_Composite.h" 6 | #include "2D/Vector2D.h" 7 | #include "../Raven_Bot.h" 8 | #include "Raven_Goal_Types.h" 9 | 10 | 11 | 12 | class Goal_MoveToPosition : public Goal_Composite 13 | { 14 | private: 15 | 16 | //the position the bot wants to reach 17 | Vector2D m_vDestination; 18 | 19 | public: 20 | 21 | Goal_MoveToPosition(Raven_Bot* pBot, 22 | Vector2D pos): 23 | 24 | Goal_Composite(pBot, 25 | goal_move_to_position), 26 | m_vDestination(pos) 27 | {} 28 | 29 | //the usual suspects 30 | void Activate(); 31 | int Process(); 32 | void Terminate(){} 33 | 34 | //this goal is able to accept messages 35 | bool HandleMessage(const Telegram& msg); 36 | 37 | void Render(); 38 | }; 39 | 40 | 41 | 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_NegotiateDoor.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_NEGOTIATE_DOOR_H 2 | #define GOAL_NEGOTIATE_DOOR_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal_Composite.h" 6 | #include "Raven_Goal_Types.h" 7 | #include "../Raven_Bot.h" 8 | #include "../navigation/PathEdge.h" 9 | 10 | 11 | class Goal_NegotiateDoor : public Goal_Composite 12 | { 13 | private: 14 | 15 | PathEdge m_PathEdge; 16 | 17 | bool m_bLastEdgeInPath; 18 | 19 | public: 20 | 21 | Goal_NegotiateDoor(Raven_Bot* pBot, PathEdge edge, bool LastEdge); 22 | 23 | //the usual suspects 24 | void Activate(); 25 | int Process(); 26 | void Terminate(){} 27 | }; 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_SayPhrase.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Buckland_Chapter7 to 10_Raven/goals/Goal_SayPhrase.cpp -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_SeekToPosition.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_SEEK_TO_POSITION_H 2 | #define GOAL_SEEK_TO_POSITION_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal.h" 6 | #include "2d/Vector2D.h" 7 | #include "Raven_Goal_Types.h" 8 | #include "../Raven_Bot.h" 9 | 10 | 11 | class Goal_SeekToPosition : public Goal 12 | { 13 | private: 14 | 15 | //the position the bot is moving to 16 | Vector2D m_vPosition; 17 | 18 | //the approximate time the bot should take to travel the target location 19 | double m_dTimeToReachPos; 20 | 21 | //this records the time this goal was activated 22 | double m_dStartTime; 23 | 24 | //returns true if a bot gets stuck 25 | bool isStuck()const; 26 | 27 | public: 28 | 29 | Goal_SeekToPosition(Raven_Bot* pBot, Vector2D target); 30 | 31 | //the usual suspects 32 | void Activate(); 33 | int Process(); 34 | void Terminate(); 35 | 36 | void Render(); 37 | }; 38 | 39 | 40 | 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_TraverseEdge.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_TRAVERSE_EDGE_H 2 | #define GOAL_TRAVERSE_EDGE_H 3 | #pragma warning (disable:4786) 4 | 5 | #include "Goals/Goal.h" 6 | #include "2d/Vector2D.h" 7 | #include "../navigation/Raven_PathPlanner.h" 8 | #include "../navigation/PathEdge.h" 9 | 10 | 11 | class Goal_TraverseEdge : public Goal 12 | { 13 | private: 14 | 15 | //the edge the bot will follow 16 | PathEdge m_Edge; 17 | 18 | //true if m_Edge is the last in the path. 19 | bool m_bLastEdgeInPath; 20 | 21 | //the estimated time the bot should take to traverse the edge 22 | double m_dTimeExpected; 23 | 24 | //this records the time this goal was activated 25 | double m_dStartTime; 26 | 27 | //returns true if the bot gets stuck 28 | bool isStuck()const; 29 | 30 | public: 31 | 32 | Goal_TraverseEdge(Raven_Bot* pBot, 33 | PathEdge edge, 34 | bool LastEdge); 35 | 36 | //the usual suspects 37 | void Activate(); 38 | int Process(); 39 | void Terminate(); 40 | void Render(); 41 | }; 42 | 43 | 44 | 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_Wander.cpp: -------------------------------------------------------------------------------- 1 | #include "Goal_Wander.h" 2 | #include "..\Raven_Bot.h" 3 | #include "..\Raven_SteeringBehaviors.h" 4 | 5 | 6 | 7 | 8 | 9 | //---------------------------- Initialize ------------------------------------- 10 | //----------------------------------------------------------------------------- 11 | void Goal_Wander::Activate() 12 | { 13 | m_iStatus = active; 14 | 15 | m_pOwner->GetSteering()->WanderOn(); 16 | } 17 | 18 | //------------------------------ Process -------------------------------------- 19 | //----------------------------------------------------------------------------- 20 | int Goal_Wander::Process() 21 | { 22 | //if status is inactive, call Activate() 23 | ActivateIfInactive(); 24 | 25 | return m_iStatus; 26 | } 27 | 28 | //---------------------------- Terminate -------------------------------------- 29 | //----------------------------------------------------------------------------- 30 | void Goal_Wander::Terminate() 31 | { 32 | m_pOwner->GetSteering()->WanderOff(); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Goal_Wander.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_WANDER_H 2 | #define GOAL_WANDER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Goal_Wander.h 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: Causes a bot to wander until terminated 11 | //----------------------------------------------------------------------------- 12 | #include "Goals/Goal.h" 13 | #include "Raven_Goal_Types.h" 14 | #include "../Raven_Bot.h" 15 | 16 | 17 | class Goal_Wander : public Goal 18 | { 19 | private: 20 | 21 | public: 22 | 23 | Goal_Wander(Raven_Bot* pBot):Goal(pBot,goal_wander) 24 | {} 25 | 26 | void Activate(); 27 | 28 | int Process(); 29 | 30 | void Terminate(); 31 | }; 32 | 33 | 34 | 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/Raven_Goal_Types.h: -------------------------------------------------------------------------------- 1 | #ifndef GOAL_ENUMERATIONS_H 2 | #define GOAL_ENUMERATIONS_H 3 | 4 | #include 5 | #include "misc/TypeToString.h" 6 | 7 | enum 8 | { 9 | goal_think, 10 | goal_explore, 11 | goal_arrive_at_position, 12 | goal_seek_to_position, 13 | goal_follow_path, 14 | goal_traverse_edge, 15 | goal_move_to_position, 16 | goal_get_health, 17 | goal_get_shotgun, 18 | goal_get_rocket_launcher, 19 | goal_get_railgun, 20 | goal_wander, 21 | goal_negotiate_door, 22 | goal_attack_target, 23 | goal_hunt_target, 24 | goal_strafe, 25 | goal_adjust_range, 26 | goal_say_phrase 27 | 28 | }; 29 | 30 | class GoalTypeToString : public TypeToString 31 | { 32 | 33 | GoalTypeToString(){} 34 | 35 | public: 36 | 37 | static GoalTypeToString* Instance(); 38 | 39 | std::string Convert(int gt); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/goals/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Script1.rc 4 | // 5 | #define IDB_BITMAP1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/lua/Raven_Scriptor.cpp: -------------------------------------------------------------------------------- 1 | #include "Raven_Scriptor.h" 2 | 3 | Raven_Scriptor* Raven_Scriptor::Instance() 4 | { 5 | static Raven_Scriptor instance; 6 | 7 | return &instance; 8 | } 9 | 10 | 11 | 12 | Raven_Scriptor::Raven_Scriptor():Scriptor() 13 | { 14 | RunScriptFile("Params.lua"); 15 | } -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/lua/Raven_Scriptor.h: -------------------------------------------------------------------------------- 1 | #ifndef RAVEN_SCRIPTOR_H 2 | #define RAVEN_SCRIPTOR_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Raven_Scriptor 7 | // 8 | // Author: Mat Buckland (www.ai-junkie.com) 9 | // 10 | // Desc: A Singleton Scriptor class for use with the Raven project 11 | //----------------------------------------------------------------------------- 12 | #include "Script/scriptor.h" 13 | 14 | 15 | 16 | #define script Raven_Scriptor::Instance() 17 | 18 | class Raven_Scriptor : public Scriptor 19 | { 20 | private: 21 | 22 | Raven_Scriptor(); 23 | 24 | //copy ctor and assignment should be private 25 | Raven_Scriptor(const Raven_Scriptor&); 26 | Raven_Scriptor& operator=(const Raven_Scriptor&); 27 | 28 | public: 29 | 30 | static Raven_Scriptor* Instance(); 31 | 32 | }; 33 | 34 | #endif 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/navigation/PathTarget.h: -------------------------------------------------------------------------------- 1 | #ifndef PATH_TARGET_H 2 | #define PATH_TARGET_H 3 | 4 | 5 | class PathTarget 6 | { 7 | public: 8 | 9 | enum target_type {item, position, invalid}; 10 | 11 | private: 12 | 13 | int m_iTargetItemType; 14 | 15 | Vector2D m_vTargetPosition; 16 | 17 | target_type m_Type; 18 | 19 | public: 20 | 21 | PathTarget():m_iTargetItemType(-1), m_Type(invalid){} 22 | 23 | void SetTargetAsItem(int ItemType); 24 | void SetTargetAsPosition(Vector2D TargetPosition); 25 | 26 | bool isTargetAnItem()const{return m_Type == item;} 27 | bool isTargetAPosition()const{return m_Type == position;} 28 | bool isTargetValid()const{return !(m_Type == invalid);} 29 | 30 | Vector2D GetTargetPosition()const; 31 | int GetTargetType()const; 32 | 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Script1.rc 4 | // 5 | #define IDR_MENU1 101 6 | #define ID_MENU_LOAD 40001 7 | #define IDM_MAP_LOAD 40001 8 | #define IDM_GAME_LOAD 40001 9 | #define IDM_NAVIGATION_SHOW_NAVGRAPH 40002 10 | #define IDM_NAVIGATION_SHOW_PATH 40004 11 | #define IDM_NAVIGATION_SMOOTH_PATHS_QUICK 40005 12 | #define IDM_BOTS_SHOW_IDS 40006 13 | #define IDM_BOTS_SHOW_HEALTH 40007 14 | #define IDM_BOTS_SHOW_TARGET 40008 15 | #define IDM_BOTS_SHOW_FOV 40009 16 | #define IDM_BOTS_SHOW_SCORES 40010 17 | #define IDM_BOTS_SHOW_GOAL_Q 40011 18 | #define IDM_NAVIGATION_SHOW_INDICES 40012 19 | #define IDM_MAP_ADDBOT 40013 20 | #define IDM_GAME_ADDBOT 40013 21 | #define IDM_MAP_REMOVEBOT 40014 22 | #define IDM_GAME_REMOVEBOT 40014 23 | #define IDM_NAVIGATION_SMOOTH_PATHS_PRECISE 40015 24 | #define IDM_BOTS_SHOW_SENSED 40016 25 | #define IDM_GAME_PAUSE 40017 26 | 27 | // Next default values for new objects 28 | // 29 | #ifdef APSTUDIO_INVOKED 30 | #ifndef APSTUDIO_READONLY_SYMBOLS 31 | #define _APS_NEXT_RESOURCE_VALUE 111 32 | #define _APS_NEXT_COMMAND_VALUE 40018 33 | #define _APS_NEXT_CONTROL_VALUE 1000 34 | #define _APS_NEXT_SYMED_VALUE 101 35 | #endif 36 | #endif 37 | -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/triggers/Trigger_HealthGiver.h: -------------------------------------------------------------------------------- 1 | #ifndef HEALTH_GIVER_H 2 | #define HEALTH_GIVER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Trigger_HealthGiver.h 7 | // 8 | // Author: Mat Buckland 9 | // 10 | // Desc: If a bot runs over an instance of this class its health is 11 | // increased. 12 | // 13 | //----------------------------------------------------------------------------- 14 | #include "Triggers/Trigger_Respawning.h" 15 | #include "Triggers/TriggerRegion.h" 16 | #include 17 | #include "../Raven_Bot.h" 18 | 19 | 20 | 21 | class Trigger_HealthGiver : public Trigger_Respawning 22 | { 23 | private: 24 | 25 | //the amount of health an entity receives when it runs over this trigger 26 | int m_iHealthGiven; 27 | 28 | public: 29 | 30 | Trigger_HealthGiver(std::ifstream& datafile); 31 | 32 | //if triggered, the bot's health will be incremented 33 | void Try(Raven_Bot* pBot); 34 | 35 | //draws a box with a red cross at the trigger's location 36 | void Render(); 37 | 38 | void Read (std::ifstream& is); 39 | }; 40 | 41 | 42 | 43 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/triggers/Trigger_SoundNotify.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIGGER_SOUNDNOTIFY_H 2 | #define TRIGGER_SOUNDNOTIFY_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Trigger_SoundNotify.h 7 | // 8 | // Author: Mat Buckland 9 | // 10 | // Desc: whenever an agent makes a sound -- such as when a weapon fires -- 11 | // this trigger can be used to notify other bots of the event. 12 | // 13 | // This type of trigger has a circular trigger region and a lifetime 14 | // of 1 update-step 15 | // 16 | //----------------------------------------------------------------------------- 17 | #include "Triggers/Trigger_LimitedLifetime.h" 18 | #include "../Raven_Bot.h" 19 | 20 | 21 | 22 | class Trigger_SoundNotify : public Trigger_LimitedLifetime 23 | { 24 | private: 25 | 26 | //a pointer to the bot that has made the sound 27 | Raven_Bot* m_pSoundSource; 28 | 29 | public: 30 | 31 | Trigger_SoundNotify(Raven_Bot* source, double range); 32 | 33 | 34 | void Try(Raven_Bot*); 35 | 36 | void Render(){} 37 | 38 | }; 39 | 40 | 41 | 42 | 43 | #endif -------------------------------------------------------------------------------- /Buckland_Chapter7 to 10_Raven/triggers/Trigger_WeaponGiver.h: -------------------------------------------------------------------------------- 1 | #ifndef WEAPON_GIVER_H 2 | #define WEAPON_GIVER_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Trigger_WeaponGiver.h 7 | // 8 | // Author: Mat Buckland 9 | // 10 | // Desc: This trigger 'gives' the triggering bot a weapon of the 11 | // specified type 12 | // 13 | //----------------------------------------------------------------------------- 14 | #include "Triggers/Trigger_Respawning.h" 15 | #include "../Raven_Bot.h" 16 | #include 17 | 18 | 19 | 20 | 21 | class Trigger_WeaponGiver : public Trigger_Respawning 22 | { 23 | private: 24 | 25 | //vrtex buffers for rocket shape 26 | std::vector m_vecRLVB; 27 | std::vector m_vecRLVBTrans; 28 | 29 | public: 30 | 31 | //this type of trigger is created when reading a map file 32 | Trigger_WeaponGiver(std::ifstream& datafile); 33 | 34 | //if triggered, this trigger will call the PickupWeapon method of the 35 | //bot. PickupWeapon will instantiate a weapon of the appropriate type. 36 | void Try(Raven_Bot*); 37 | 38 | //draws a symbol representing the weapon type at the trigger's location 39 | void Render(); 40 | 41 | void Read (std::ifstream& is); 42 | }; 43 | 44 | 45 | 46 | 47 | #endif -------------------------------------------------------------------------------- /Common/2D/Vector2d.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2D.h" 2 | #include 3 | 4 | std::ostream& operator<<(std::ostream& os, const Vector2D& rhs) 5 | { 6 | os << " " << rhs.x << " " << rhs.y; 7 | 8 | return os; 9 | } 10 | 11 | 12 | std::ifstream& operator>>(std::ifstream& is, Vector2D& lhs) 13 | { 14 | is >> lhs.x >> lhs.y; 15 | 16 | return is; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Common/FSM/State.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_H 2 | #define STATE_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: State.h 6 | // 7 | // Desc: abstract base class to define an interface for a state 8 | // 9 | // Author: Mat Buckland (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | struct Telegram; 13 | 14 | template 15 | class State 16 | { 17 | public: 18 | 19 | virtual ~State(){} 20 | 21 | //this will execute when the state is entered 22 | virtual void Enter(entity_type*)=0; 23 | 24 | //this is the states normal update function 25 | virtual void Execute(entity_type*)=0; 26 | 27 | //this will execute when the state is exited. 28 | virtual void Exit(entity_type*)=0; 29 | 30 | //this executes if the agent receives a message from the 31 | //message dispatcher 32 | virtual bool OnMessage(entity_type*, const Telegram&)=0; 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /Common/Game/BaseGameEntity.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseGameEntity.h" 2 | 3 | 4 | int BaseGameEntity::m_iNextValidID = 0; 5 | 6 | //------------------------------ ctor ----------------------------------------- 7 | //----------------------------------------------------------------------------- 8 | BaseGameEntity::BaseGameEntity(int ID):m_dBoundingRadius(0.0), 9 | m_vScale(Vector2D(1.0,1.0)), 10 | m_iType(default_entity_type), 11 | m_bTag(false) 12 | { 13 | SetID(ID); 14 | } 15 | 16 | //----------------------------- SetID ----------------------------------------- 17 | // 18 | // this must be called within each constructor to make sure the ID is set 19 | // correctly. It verifies that the value passed to the method is greater 20 | // or equal to the next valid ID, before setting the ID and incrementing 21 | // the next valid ID 22 | //----------------------------------------------------------------------------- 23 | void BaseGameEntity::SetID(int val) 24 | { 25 | //make sure the val is equal to or greater than the next available ID 26 | assert ( (val >= m_iNextValidID) && ": invalid ID"); 27 | 28 | m_ID = val; 29 | 30 | m_iNextValidID = m_ID + 1; 31 | } 32 | -------------------------------------------------------------------------------- /Common/Game/EntityManager.cpp: -------------------------------------------------------------------------------- 1 | #include "game/EntityManager.h" 2 | #include "game/BaseGameEntity.h" 3 | 4 | 5 | //--------------------------- Instance ---------------------------------------- 6 | // 7 | // this class is a singleton 8 | //----------------------------------------------------------------------------- 9 | EntityManager* EntityManager::Instance() 10 | { 11 | static EntityManager instance; 12 | 13 | return &instance; 14 | } 15 | 16 | //------------------------- GetEntityFromID ----------------------------------- 17 | //----------------------------------------------------------------------------- 18 | BaseGameEntity* EntityManager::GetEntityFromID(int id)const 19 | { 20 | //find the entity 21 | EntityMap::const_iterator ent = m_EntityMap.find(id); 22 | 23 | //assert that the entity is a member of the map 24 | assert ( (ent != m_EntityMap.end()) && ": invalid ID"); 25 | 26 | return ent->second; 27 | } 28 | 29 | //--------------------------- RemoveEntity ------------------------------------ 30 | //----------------------------------------------------------------------------- 31 | void EntityManager::RemoveEntity(BaseGameEntity* pEntity) 32 | { 33 | m_EntityMap.erase(m_EntityMap.find(pEntity->ID())); 34 | } 35 | 36 | //---------------------------- RegisterEntity --------------------------------- 37 | //----------------------------------------------------------------------------- 38 | void EntityManager::RegisterEntity(BaseGameEntity* NewEntity) 39 | { 40 | m_EntityMap.insert(std::make_pair(NewEntity->ID(), NewEntity)); 41 | } 42 | -------------------------------------------------------------------------------- /Common/Graph/NodeTypeEnumerations.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_TYPE_ENUMS 2 | #define NODE_TYPE_ENUMS 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: NodeTypeEnumerations.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: enumerates some dummy node values that can be assigned to graph 10 | // edges and nodes 11 | //----------------------------------------------------------------------------- 12 | enum 13 | { 14 | invalid_node_index = -1 15 | }; 16 | 17 | 18 | #endif -------------------------------------------------------------------------------- /Common/Time/CrudeTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "CrudeTimer.h" 2 | 3 | 4 | CrudeTimer* CrudeTimer::Instance() 5 | { 6 | static CrudeTimer instance; 7 | 8 | return &instance; 9 | } -------------------------------------------------------------------------------- /Common/Time/CrudeTimer.h: -------------------------------------------------------------------------------- 1 | #ifndef CRUDETIMER_H 2 | #define CRUDETIMER_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: CrudeTimer.h 6 | // 7 | // Desc: timer to measure time in seconds 8 | // 9 | // Author: Mat Buckland 2002 (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | 13 | //this library must be included 14 | #pragma comment(lib, "winmm.lib") 15 | 16 | #include 17 | 18 | 19 | 20 | #define Clock CrudeTimer::Instance() 21 | 22 | class CrudeTimer 23 | { 24 | private: 25 | 26 | 27 | //set to the time (in seconds) when class is instantiated 28 | double m_dStartTime; 29 | 30 | //set the start time 31 | CrudeTimer(){m_dStartTime = timeGetTime() * 0.001;} 32 | 33 | //copy ctor and assignment should be private 34 | CrudeTimer(const CrudeTimer&); 35 | CrudeTimer& operator=(const CrudeTimer&); 36 | 37 | public: 38 | 39 | static CrudeTimer* Instance(); 40 | 41 | //returns how much time has elapsed since the timer was started 42 | double GetCurrentTime(){return timeGetTime() * 0.001 - m_dStartTime;} 43 | 44 | }; 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | #endif -------------------------------------------------------------------------------- /Common/Triggers/Trigger_LimitedLifeTime.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIGGER_LIMITEDLIFETIME_H 2 | #define TRIGGER_LIMITEDLIFETIME_H 3 | #pragma warning (disable:4786) 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Name: Trigger_LimitedLifetime.h 7 | // 8 | // Author: Mat Buckland 9 | // 10 | // Desc: defines a trigger that only remains in the game for a specified 11 | // number of update steps 12 | // 13 | //----------------------------------------------------------------------------- 14 | #include "Trigger.h" 15 | 16 | 17 | template 18 | class Trigger_LimitedLifetime : public Trigger 19 | { 20 | protected: 21 | 22 | //the lifetime of this trigger in update-steps 23 | int m_iLifetime; 24 | 25 | public: 26 | 27 | Trigger_LimitedLifetime(int lifetime):Trigger(BaseGameEntity::GetNextValidID()), 28 | m_iLifetime(lifetime) 29 | {} 30 | 31 | virtual ~Trigger_LimitedLifetime(){} 32 | 33 | //children of this class should always make sure this is called from within 34 | //their own update method 35 | virtual void Update() 36 | { 37 | //if the lifetime counter expires set this trigger to be removed from 38 | //the game 39 | if (--m_iLifetime <= 0) 40 | { 41 | SetToBeRemovedFromGame(); 42 | } 43 | } 44 | 45 | //to be implemented by child classes 46 | virtual void Try(entity_type*) = 0; 47 | }; 48 | 49 | 50 | 51 | 52 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_LeftShoulder.cpp: -------------------------------------------------------------------------------- 1 | #include "FuzzySet_LeftShoulder.h" 2 | #include 3 | 4 | 5 | double FuzzySet_LeftShoulder::CalculateDOM(double val)const 6 | { 7 | //test for the case where the left or right offsets are zero 8 | //(to prevent divide by zero errors below) 9 | if ( (isEqual(m_dRightOffset, 0.0) && (isEqual(m_dPeakPoint, val))) || 10 | (isEqual(m_dLeftOffset, 0.0) && (isEqual(m_dPeakPoint, val))) ) 11 | { 12 | return 1.0; 13 | } 14 | 15 | //find DOM if right of center 16 | else if ( (val >= m_dPeakPoint) && (val < (m_dPeakPoint + m_dRightOffset)) ) 17 | { 18 | double grad = 1.0 / -m_dRightOffset; 19 | 20 | return grad * (val - m_dPeakPoint) + 1.0; 21 | } 22 | 23 | //find DOM if left of center 24 | else if ( (val < m_dPeakPoint) && (val >= m_dPeakPoint-m_dLeftOffset) ) 25 | { 26 | return 1.0; 27 | } 28 | 29 | //out of range of this FLV, return zero 30 | else 31 | { 32 | return 0.0; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_LeftShoulder.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZYSET_LEFTSHOULDER_H 2 | #define FUZZYSET_LEFTSHOULDER_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FuzzySet_LeftShoulder.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: definition of a fuzzy set that has a left shoulder shape. (the 10 | // minimum value this variable can accept is *any* value less than the 11 | // midpoint. 12 | //----------------------------------------------------------------------------- 13 | #include "fuzzy/FuzzySet.h" 14 | #include "misc/utils.h" 15 | 16 | 17 | 18 | class FuzzySet_LeftShoulder : public FuzzySet 19 | { 20 | private: 21 | 22 | //the values that define the shape of this FLV 23 | double m_dPeakPoint; 24 | double m_dRightOffset; 25 | double m_dLeftOffset; 26 | 27 | public: 28 | 29 | FuzzySet_LeftShoulder(double peak, 30 | double LeftOffset, 31 | double RightOffset): 32 | 33 | FuzzySet( ((peak - LeftOffset) + peak) / 2), 34 | m_dPeakPoint(peak), 35 | m_dLeftOffset(LeftOffset), 36 | m_dRightOffset(RightOffset) 37 | {} 38 | 39 | //this method calculates the degree of membership for a particular value 40 | double CalculateDOM(double val)const; 41 | }; 42 | 43 | 44 | 45 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_RightShoulder.cpp: -------------------------------------------------------------------------------- 1 | #include "FuzzySet_RightShoulder.h" 2 | #include 3 | 4 | 5 | double FuzzySet_RightShoulder::CalculateDOM(double val)const 6 | { 7 | //test for the case where the left or right offsets are zero 8 | //(to prevent divide by zero errors below) 9 | if ( (isEqual(m_dRightOffset, 0.0) && (isEqual(m_dPeakPoint, val))) || 10 | (isEqual(m_dLeftOffset, 0.0) && (isEqual(m_dPeakPoint, val))) ) 11 | { 12 | return 1.0; 13 | } 14 | 15 | //find DOM if left of center 16 | else if ( (val <= m_dPeakPoint) && (val > (m_dPeakPoint - m_dLeftOffset)) ) 17 | { 18 | double grad = 1.0 / m_dLeftOffset; 19 | 20 | return grad * (val - (m_dPeakPoint - m_dLeftOffset)); 21 | } 22 | //find DOM if right of center and less than center + right offset 23 | else if ( (val > m_dPeakPoint) && (val <= m_dPeakPoint+m_dRightOffset) ) 24 | { 25 | return 1.0; 26 | } 27 | 28 | else 29 | { 30 | return 0; 31 | } 32 | } -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_RightShoulder.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZYSET_RIGHTSHOULDER_H 2 | #define FUZZYSET_RIGHTSHOULDER_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FuzzySet_RightShoulder.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: definition of a fuzzy set that has a right shoulder shape. (the 10 | // maximum value this variable can accept is *any* value greater than 11 | // the midpoint. 12 | //----------------------------------------------------------------------------- 13 | #include "fuzzy/FuzzySet.h" 14 | #include "misc/utils.h" 15 | 16 | 17 | 18 | class FuzzySet_RightShoulder : public FuzzySet 19 | { 20 | private: 21 | 22 | //the values that define the shape of this FLV 23 | double m_dPeakPoint; 24 | double m_dLeftOffset; 25 | double m_dRightOffset; 26 | 27 | public: 28 | 29 | FuzzySet_RightShoulder(double peak, 30 | double LeftOffset, 31 | double RightOffset): 32 | 33 | FuzzySet( ((peak + RightOffset) + peak) / 2), 34 | m_dPeakPoint(peak), 35 | m_dLeftOffset(LeftOffset), 36 | m_dRightOffset(RightOffset) 37 | 38 | {} 39 | 40 | //this method calculates the degree of membership for a particular value 41 | double CalculateDOM(double val)const; 42 | }; 43 | 44 | 45 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_Singleton.cpp: -------------------------------------------------------------------------------- 1 | #include "FuzzySet_Singleton.h" 2 | 3 | double FuzzySet_Singleton::CalculateDOM(double val)const 4 | { 5 | if ( (val >= m_dMidPoint-m_dLeftOffset) && 6 | (val <= m_dMidPoint+m_dRightOffset) ) 7 | { 8 | return 1.0; 9 | } 10 | 11 | //out of range of this FLV, return zero 12 | else 13 | { 14 | return 0.0; 15 | } 16 | } -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_Singleton.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZYSET_SINGLETON_H 2 | #define FUZZYSET_SINGLETON_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FuzzySet_Singleton.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: This defines a fuzzy set that is a singleton (a range 10 | // over which the DOM is always 1.0) 11 | //----------------------------------------------------------------------------- 12 | #include "fuzzy/FuzzySet.h" 13 | #include "misc/utils.h" 14 | 15 | 16 | 17 | class FuzzySet_Singleton : public FuzzySet 18 | { 19 | private: 20 | 21 | //the values that define the shape of this FLV 22 | double m_dMidPoint; 23 | double m_dLeftOffset; 24 | double m_dRightOffset; 25 | 26 | public: 27 | 28 | FuzzySet_Singleton(double mid, 29 | double lft, 30 | double rgt):FuzzySet(mid), 31 | m_dMidPoint(mid), 32 | m_dLeftOffset(lft), 33 | m_dRightOffset(rgt) 34 | {} 35 | 36 | //this method calculates the degree of membership for a particular value 37 | double CalculateDOM(double val)const; 38 | }; 39 | 40 | 41 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "FuzzySet_Triangle.h" 2 | 3 | 4 | double FuzzySet_Triangle::CalculateDOM(double val)const 5 | { 6 | //test for the case where the triangle's left or right offsets are zero 7 | //(to prevent divide by zero errors below) 8 | if ( (isEqual(m_dRightOffset, 0.0) && (isEqual(m_dPeakPoint, val))) || 9 | (isEqual(m_dLeftOffset, 0.0) && (isEqual(m_dPeakPoint, val))) ) 10 | { 11 | return 1.0; 12 | } 13 | 14 | //find DOM if left of center 15 | if ( (val <= m_dPeakPoint) && (val >= (m_dPeakPoint - m_dLeftOffset)) ) 16 | { 17 | double grad = 1.0 / m_dLeftOffset; 18 | 19 | return grad * (val - (m_dPeakPoint - m_dLeftOffset)); 20 | } 21 | //find DOM if right of center 22 | else if ( (val > m_dPeakPoint) && (val < (m_dPeakPoint + m_dRightOffset)) ) 23 | { 24 | double grad = 1.0 / -m_dRightOffset; 25 | 26 | return grad * (val - m_dPeakPoint) + 1.0; 27 | } 28 | //out of range of this FLV, return zero 29 | else 30 | { 31 | return 0.0; 32 | } 33 | } -------------------------------------------------------------------------------- /Common/fuzzy/FuzzySet_Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZYSET_TRIANGLE_H 2 | #define FUZZYSET_TRIANGLE_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FuzzySetTriangle.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: This is a simple class to define fuzzy sets that have a triangular 10 | // shape and can be defined by a mid point, a left displacement and a 11 | // right displacement. 12 | //----------------------------------------------------------------------------- 13 | #include "fuzzy/FuzzySet.h" 14 | #include "misc/utils.h" 15 | 16 | 17 | 18 | class FuzzySet_Triangle : public FuzzySet 19 | { 20 | private: 21 | 22 | //the values that define the shape of this FLV 23 | double m_dPeakPoint; 24 | double m_dLeftOffset; 25 | double m_dRightOffset; 26 | 27 | public: 28 | 29 | FuzzySet_Triangle(double mid, 30 | double lft, 31 | double rgt):FuzzySet(mid), 32 | m_dPeakPoint(mid), 33 | m_dLeftOffset(lft), 34 | m_dRightOffset(rgt) 35 | {} 36 | 37 | //this method calculates the degree of membership for a particular value 38 | double CalculateDOM(double val)const; 39 | }; 40 | 41 | 42 | 43 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FuzzyTerm.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZYTERM_H 2 | #define FUZZYTERM_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FuzzyTerm.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: abstract class to provide an interface for classes able to be 10 | // used as terms in a fuzzy if-then rule base. 11 | //----------------------------------------------------------------------------- 12 | 13 | class FuzzyTerm 14 | { 15 | public: 16 | 17 | virtual ~FuzzyTerm(){} 18 | 19 | //all terms must implement a virtual constructor 20 | virtual FuzzyTerm* Clone()const = 0; 21 | 22 | //retrieves the degree of membership of the term 23 | virtual double GetDOM()const=0; 24 | 25 | //clears the degree of membership of the term 26 | virtual void ClearDOM()=0; 27 | 28 | //method for updating the DOM of a consequent when a rule fires 29 | virtual void ORwithDOM(double val)=0; 30 | 31 | 32 | }; 33 | 34 | 35 | 36 | #endif -------------------------------------------------------------------------------- /Common/fuzzy/FzSet.h: -------------------------------------------------------------------------------- 1 | #ifndef PROXY_FUZZY_SET 2 | #define PROXY_FUZZY_SET 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: FzSet.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: class to provide a proxy for a fuzzy set. The proxy inherits from 10 | // FuzzyTerm and therefore can be used to create fuzzy rules 11 | //----------------------------------------------------------------------------- 12 | #include "FuzzyTerm.h" 13 | #include "FuzzySet.h" 14 | 15 | class FzAND; 16 | 17 | class FzSet : public FuzzyTerm 18 | { 19 | private: 20 | 21 | //let the hedge classes be friends 22 | friend class FzVery; 23 | friend class FzFairly; 24 | 25 | private: 26 | 27 | //a reference to the fuzzy set this proxy represents 28 | FuzzySet& m_Set; 29 | 30 | public: 31 | 32 | FzSet(FuzzySet& fs):m_Set(fs){} 33 | 34 | FuzzyTerm* Clone()const{return new FzSet(*this);} 35 | double GetDOM()const {return m_Set.GetDOM();} 36 | void ClearDOM(){m_Set.ClearDOM();} 37 | void ORwithDOM(double val){m_Set.ORwithDOM(val);} 38 | }; 39 | 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /Common/lua-5.0/bin/Lua.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/bin/Lua.exe -------------------------------------------------------------------------------- /Common/lua-5.0/bin/Luac.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/bin/Luac.exe -------------------------------------------------------------------------------- /Common/lua-5.0/bin/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | Lua binaries go in here. 3 | -------------------------------------------------------------------------------- /Common/lua-5.0/build: -------------------------------------------------------------------------------- 1 | # If you don't want to use make, run this script. 2 | # But make sure you read config to see what can be customized. 3 | 4 | 5 | # Easiest way to build bin/lua: 6 | # cc -O2 -o bin/lua -Iinclude -Isrc src/*.c src/lib/*.c src/lua/*.c -lm -ldl 7 | 8 | 9 | # Easiest way to build Lua libraries and executables: 10 | echo -n 'building core library... ' 11 | cd src 12 | cc -O2 -c -I../include *.c 13 | ar rc ../lib/liblua.a *.o 14 | rm -f *.o 15 | 16 | echo -n 'standard library... ' 17 | cd lib 18 | cc -O2 -c -I../../include *.c 19 | ar rc ../../lib/liblualib.a *.o 20 | rm -f *.o 21 | 22 | echo -n 'lua... ' 23 | cd ../lua 24 | cc -O2 -o ../../bin/lua -I../../include *.c ../../lib/*.a -lm -ldl 25 | 26 | echo -n 'luac... ' 27 | cd ../luac 28 | cc -O2 -o ../../bin/luac -I../../include -I.. *.c -DLUA_OPNAMES ../lopcodes.c ../../lib/*.a 29 | 30 | echo 'done' 31 | 32 | cd ../.. 33 | bin/lua test/hello.lua 34 | -------------------------------------------------------------------------------- /Common/lua-5.0/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Lua does not use GNU autoconf; just edit ./config if needed to suit your 4 | # platform and then run make. 5 | 6 | # This shows the parameters currently set in ./config: 7 | make echo 8 | 9 | # If you want config as a Lua program, run "make lecho". 10 | -------------------------------------------------------------------------------- /Common/lua-5.0/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/doc/logo.gif -------------------------------------------------------------------------------- /Common/lua-5.0/doc/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua documentation 4 | 5 | 6 | 7 | 8 |
9 |

10 | Lua 11 | Documentation 12 |

13 | 14 | 27 | 28 |
29 | 30 | Last update: 31 | Tue Apr 1 14:35:18 EST 2003 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua etc 2 | 3 | LUA= .. 4 | 5 | include $(LUA)/config 6 | 7 | LIBLUA=$(LIB)/liblua.a 8 | ALL= bin2c min trace noparser luab 9 | 10 | all: 11 | @echo 'choose a target:' $(ALL) 12 | 13 | bin2c: bin2c.c 14 | $(CC) $(CFLAGS) -o $@ $@.c 15 | 16 | min: min.c $(LIBLUA) 17 | $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua 18 | 19 | trace: trace.c $(LIBLUA) 20 | $(CC) -g $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib $(EXTRA_LIBS) 21 | 22 | noparser: noparser.c 23 | $(CC) $(CFLAGS) -I$(LUA)/src -o $@.o -c $@.c 24 | 25 | luab: noparser $(LIBLUA) 26 | cc -o $@ noparser.o $(LUA)/src/lua/lua.o -L$(LIB) -llua -llualib $(EXTRA_LIBS) 27 | $(BIN)/luac $(LUA)/test/hello.lua 28 | $@ luac.out 29 | -$@ -e'a=1' 30 | 31 | flat: 32 | cd ..; mkdir flat; mv include/*.h src/*.[ch] src/*/*.[ch] flat 33 | 34 | $(LIBLUA): 35 | cd ../src; $(MAKE) 36 | 37 | clean: 38 | rm -f $(ALL) a.out core *.o luac.out 39 | 40 | luser_tests.h: RCS/ltests.h,v 41 | co -q -M ltests.h 42 | mv -f ltests.h $@ 43 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/doall.lua: -------------------------------------------------------------------------------- 1 | -- emulate the command line behaviour of Lua 4.0 2 | -- usage: lua doall.lua f1.lua f2.lua f3.lua ... 3 | 4 | for i=1,table.getn(arg) do 5 | dofile(arg[i]) 6 | end 7 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/lua.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/etc/lua.ico -------------------------------------------------------------------------------- /Common/lua-5.0/etc/lua.magic: -------------------------------------------------------------------------------- 1 | 2 | # Lua precompiled files. Versions 2.3 and 4.1 were never officially released. 3 | 0 string \33Lua precompiled chunk for Lua 4 | >4 byte 0x23 2.3* 5 | >4 byte 0x24 2.4 6 | >4 byte 0x25 2.5 7 | >4 byte 0x30 3.0 8 | >4 byte 0x31 3.1 9 | >4 byte 0x32 3.2 10 | >4 byte 0x40 4.0 11 | >4 byte 0x41 4.1* 12 | >4 byte 0x50 5.0 13 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/lua.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *magick[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "32 32 6 1", 5 | " c Gray0", 6 | ". c #000000008080", 7 | "X c #808080808080", 8 | "o c #c0c0c0c0c0c0", 9 | "O c Gray100", 10 | "+ c None", 11 | /* pixels */ 12 | "++++++++++++++++++++++++++ooo+++", 13 | "++++++++++++++++++++++++oX...Xo+", 14 | "++++++++++++++++++++++++X.....X+", 15 | "+++++++++++++++++++++++o.......o", 16 | "+++++++++XX......XX++++o.......o", 17 | "+++++++X............X++o.......o", 18 | "+++++o................o+X.....X+", 19 | "++++X..................XoX...Xo+", 20 | "+++X..............XXX...X+ooo+++", 21 | "++o.............XoOOOoX..o++++++", 22 | "++..............oOOOOOo...++++++", 23 | "+X.............XOOOOOOOX..X+++++", 24 | "+..............XOOOOOOOX...+++++", 25 | "X..............XOOOOOOOX...X++++", 26 | "X...............oOOOOOo....X++++", 27 | "................XoOOOoX.....++++", 28 | "....XO............XXX.......++++", 29 | "....XO......................++++", 30 | "....XO.....OX..OX.XOOOo.....++++", 31 | "....XO.....OX..OX.OoXXOX....++++", 32 | "....XO.....OX..OX....XOX....++++", 33 | "X...XO.....OX..OX..OOoOX...X++++", 34 | "X...XO.....OX..OX.OX..OX...X++++", 35 | "+...XOXXXX.OoXoOX.OXXXOX...+++++", 36 | "+X..XOOOOO.XOOXOX.XOOOXo..X+++++", 37 | "++........................++++++", 38 | "++o......................o++++++", 39 | "+++X....................X+++++++", 40 | "++++X..................X++++++++", 41 | "+++++o................o+++++++++", 42 | "+++++++X............X+++++++++++", 43 | "+++++++++XX......XX+++++++++++++" 44 | }; 45 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/luser_number.h: -------------------------------------------------------------------------------- 1 | /* luser_number.h -- number type configuration for Lua core 2 | * 3 | * #define LUA_USER_H to this file and #define one of USE_* below 4 | */ 5 | 6 | #ifdef USE_DOUBLE 7 | #define LUA_NUMBER double 8 | #define LUA_NUMBER_SCAN "%lf" 9 | #define LUA_NUMBER_FMT "%.14g" 10 | #endif 11 | 12 | #ifdef USE_FLOAT 13 | #define LUA_NUMBER float 14 | #define LUA_NUMBER_SCAN "%f" 15 | #define LUA_NUMBER_FMT "%.5g" 16 | #endif 17 | 18 | #ifdef USE_LONG 19 | #define LUA_NUMBER long 20 | #define LUA_NUMBER_SCAN "%ld" 21 | #define LUA_NUMBER_FMT "%ld" 22 | #define lua_str2number(s,p) strtol((s), (p), 10) 23 | #endif 24 | 25 | #ifdef USE_INT 26 | #define LUA_NUMBER int 27 | #define LUA_NUMBER_SCAN "%d" 28 | #define LUA_NUMBER_FMT "%d" 29 | #define lua_str2number(s,p) ((int) strtol((s), (p), 10)) 30 | #endif 31 | 32 | #ifdef USE_FASTROUND 33 | #define lua_number2int(i,d) __asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d)) 34 | #endif 35 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/luser_number.h.backup: -------------------------------------------------------------------------------- 1 | /* luser_number.h -- number type configuration for Lua core 2 | * 3 | * #define LUA_USER_H to this file and #define one of USE_* below 4 | */ 5 | 6 | #ifdef USE_DOUBLE 7 | #define LUA_NUMBER double 8 | #define LUA_NUMBER_SCAN "%lf" 9 | #define LUA_NUMBER_FMT "%.14g" 10 | #endif 11 | 12 | #ifdef USE_FLOAT 13 | #define LUA_NUMBER float 14 | #define LUA_NUMBER_SCAN "%f" 15 | #define LUA_NUMBER_FMT "%.5g" 16 | #endif 17 | 18 | #ifdef USE_LONG 19 | #define LUA_NUMBER long 20 | #define LUA_NUMBER_SCAN "%ld" 21 | #define LUA_NUMBER_FMT "%ld" 22 | #define lua_str2number(s,p) strtol((s), (p), 10) 23 | #endif 24 | 25 | #ifdef USE_INT 26 | #define LUA_NUMBER int 27 | #define LUA_NUMBER_SCAN "%d" 28 | #define LUA_NUMBER_FMT "%d" 29 | #define lua_str2number(s,p) ((int) strtol((s), (p), 10)) 30 | #endif 31 | 32 | #ifdef USE_FASTROUND 33 | #define lua_number2int(i,d) __asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d)) 34 | #endif 35 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/min.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | #include "lua.h" 9 | 10 | static int print(lua_State *L) 11 | { 12 | int n=lua_gettop(L); 13 | int i; 14 | for (i=1; i<=n; i++) 15 | { 16 | if (i>1) printf("\t"); 17 | if (lua_isstring(L,i)) 18 | printf("%s",lua_tostring(L,i)); 19 | else if (lua_isnil(L,i)) 20 | printf("%s","nil"); 21 | else if (lua_isboolean(L,i)) 22 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 23 | else 24 | printf("%s:%p",lua_typename(L,lua_type(L,i)),lua_topointer(L,i)); 25 | } 26 | printf("\n"); 27 | return 0; 28 | } 29 | 30 | static const char *getF(lua_State *L, void *ud, size_t *size) 31 | { 32 | FILE *f=(FILE *)ud; 33 | static char buff[512]; 34 | if (feof(f)) return NULL; 35 | *size=fread(buff,1,sizeof(buff),f); 36 | return (*size>0) ? buff : NULL; 37 | } 38 | 39 | int main(void) 40 | { 41 | lua_State *L=lua_open(); 42 | lua_register(L,"print",print); 43 | if (lua_load(L,getF,stdin,"=stdin") || lua_pcall(L,0,0,0)) 44 | fprintf(stderr,"%s\n",lua_tostring(L,-1)); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/noparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The code below can be used to make a Lua core that does not contain the 3 | * parsing modules (lcode, llex, lparser), which represent 35% of the total core. 4 | * You'll only be able to load binary files and strings, precompiled with luac. 5 | * (Of course, you'll have to build luac with the original parsing modules!) 6 | * 7 | * To use this module, simply compile it ("make noparser" does that) and 8 | * list its object file before the Lua libraries. The linker should then not 9 | * load the parsing modules. To try it, do "make luab". 10 | */ 11 | 12 | #include "llex.h" 13 | #include "lparser.h" 14 | #include "lzio.h" 15 | 16 | void luaX_init (lua_State *L) { 17 | UNUSED(L); 18 | } 19 | 20 | Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) { 21 | UNUSED(z); 22 | UNUSED(buff); 23 | lua_pushstring(L,"parser not loaded"); 24 | lua_error(L); 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /Common/lua-5.0/etc/trace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * trace.c -- a simple execution tracer for Lua 3 | */ 4 | 5 | #include 6 | #include 7 | #include "lua.h" 8 | #include "lualib.h" 9 | #include "lauxlib.h" 10 | 11 | static FILE* LOG; /* log file */ 12 | static int I=0; /* indentation level */ 13 | 14 | static void hook(lua_State *L, lua_Debug *ar) 15 | { 16 | const char* s=""; 17 | switch (ar->event) 18 | { 19 | case LUA_HOOKTAILRET: ar->event=LUA_HOOKRET; 20 | case LUA_HOOKRET: s="return"; break; 21 | case LUA_HOOKCALL: s="call"; break; 22 | case LUA_HOOKLINE: s="line"; break; 23 | default: break; 24 | } 25 | fprintf(LOG,"[%d]\t%*s%s\t-- %d\n",I,I,"",s,ar->currentline); 26 | if (ar->event==LUA_HOOKCALL) ++I; else if (ar->event==LUA_HOOKRET) --I; 27 | } 28 | 29 | static void start_trace(lua_State *L, FILE* logfile) 30 | { 31 | lua_sethook(L,hook,LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE, 0); 32 | LOG=logfile; 33 | } 34 | 35 | static void stop_trace(lua_State *L) 36 | { 37 | lua_sethook(L,NULL,0,0); 38 | fclose(LOG); 39 | } 40 | 41 | int main(void) 42 | { 43 | int rc; 44 | lua_State *L=lua_open(); 45 | lua_baselibopen(L); 46 | lua_tablibopen(L); 47 | lua_iolibopen(L); 48 | lua_strlibopen(L); 49 | lua_mathlibopen(L); 50 | lua_dblibopen(L); 51 | start_trace(L,stderr); 52 | rc=lua_dofile(L,NULL); 53 | stop_trace(L); 54 | return rc; 55 | } 56 | -------------------------------------------------------------------------------- /Common/lua-5.0/include/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua distribution (includes) 2 | 3 | LUA= .. 4 | 5 | include $(LUA)/config 6 | 7 | SRCS= lua.h lualib.h lauxlib.h 8 | 9 | all: 10 | 11 | clean: 12 | 13 | co: 14 | co -q -f -M $(SRCS) 15 | 16 | klean: clean 17 | rm -f $(SRCS) 18 | -------------------------------------------------------------------------------- /Common/lua-5.0/include/OpenLuaStates.h: -------------------------------------------------------------------------------- 1 | #ifndef OPEN_LUA_STATES 2 | #define OPEN_LUA_STATES 3 | 4 | extern "C" 5 | { 6 | #include 7 | #include 8 | #include 9 | } 10 | 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /Common/lua-5.0/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | #ifndef LUALIB_API 15 | #define LUALIB_API LUA_API 16 | #endif 17 | 18 | 19 | #define LUA_COLIBNAME "coroutine" 20 | LUALIB_API int luaopen_base (lua_State *L); 21 | 22 | #define LUA_TABLIBNAME "table" 23 | LUALIB_API int luaopen_table (lua_State *L); 24 | 25 | #define LUA_IOLIBNAME "io" 26 | #define LUA_OSLIBNAME "os" 27 | LUALIB_API int luaopen_io (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUALIB_API int luaopen_string (lua_State *L); 31 | 32 | #define LUA_MATHLIBNAME "math" 33 | LUALIB_API int luaopen_math (lua_State *L); 34 | 35 | #define LUA_DBLIBNAME "debug" 36 | LUALIB_API int luaopen_debug (lua_State *L); 37 | 38 | 39 | LUALIB_API int luaopen_loadlib (lua_State *L); 40 | 41 | 42 | /* to help testing the libraries */ 43 | #ifndef lua_assert 44 | #define lua_assert(c) /* empty */ 45 | #endif 46 | 47 | 48 | /* compatibility code */ 49 | #define lua_baselibopen luaopen_base 50 | #define lua_tablibopen luaopen_table 51 | #define lua_iolibopen luaopen_io 52 | #define lua_strlibopen luaopen_string 53 | #define lua_mathlibopen luaopen_math 54 | #define lua_dblibopen luaopen_debug 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Common/lua-5.0/include/lualib.h.backup: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | #ifndef LUALIB_API 15 | #define LUALIB_API LUA_API 16 | #endif 17 | 18 | 19 | #define LUA_COLIBNAME "coroutine" 20 | LUALIB_API int luaopen_base (lua_State *L); 21 | 22 | #define LUA_TABLIBNAME "table" 23 | LUALIB_API int luaopen_table (lua_State *L); 24 | 25 | #define LUA_IOLIBNAME "io" 26 | #define LUA_OSLIBNAME "os" 27 | LUALIB_API int luaopen_io (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUALIB_API int luaopen_string (lua_State *L); 31 | 32 | #define LUA_MATHLIBNAME "math" 33 | LUALIB_API int luaopen_math (lua_State *L); 34 | 35 | #define LUA_DBLIBNAME "debug" 36 | LUALIB_API int luaopen_debug (lua_State *L); 37 | 38 | 39 | LUALIB_API int luaopen_loadlib (lua_State *L); 40 | 41 | 42 | /* to help testing the libraries */ 43 | #ifndef lua_assert 44 | #define lua_assert(c) /* empty */ 45 | #endif 46 | 47 | 48 | /* compatibility code */ 49 | #define lua_baselibopen luaopen_base 50 | #define lua_tablibopen luaopen_table 51 | #define lua_iolibopen luaopen_io 52 | #define lua_strlibopen luaopen_string 53 | #define lua_mathlibopen luaopen_math 54 | #define lua_dblibopen luaopen_debug 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Common/lua-5.0/lib/lua.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/lib/lua.lib -------------------------------------------------------------------------------- /Common/lua-5.0/lib/lualib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/lib/lualib.lib -------------------------------------------------------------------------------- /Common/lua-5.0/lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | Lua libraries go in here. 3 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/LuaHelperFunctions.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua core library 2 | 3 | LUA= .. 4 | 5 | include $(LUA)/config 6 | 7 | OBJS= \ 8 | lapi.o \ 9 | lcode.o \ 10 | ldebug.o \ 11 | ldo.o \ 12 | ldump.o \ 13 | lfunc.o \ 14 | lgc.o \ 15 | llex.o \ 16 | lmem.o \ 17 | lobject.o \ 18 | lopcodes.o \ 19 | lparser.o \ 20 | lstate.o \ 21 | lstring.o \ 22 | ltable.o \ 23 | ltests.o \ 24 | ltm.o \ 25 | lundump.o \ 26 | lvm.o \ 27 | lzio.o 28 | 29 | SRCS= \ 30 | lapi.c \ 31 | lcode.c \ 32 | ldebug.c \ 33 | ldo.c \ 34 | ldump.c \ 35 | lfunc.c \ 36 | lgc.c \ 37 | llex.c \ 38 | lmem.c \ 39 | lobject.c \ 40 | lopcodes.c \ 41 | lparser.c \ 42 | lstate.c \ 43 | lstring.c \ 44 | ltable.c \ 45 | ltests.c \ 46 | ltm.c \ 47 | lundump.c \ 48 | lvm.c \ 49 | lzio.c \ 50 | lapi.h \ 51 | lcode.h \ 52 | ldebug.h \ 53 | ldo.h \ 54 | lfunc.h \ 55 | lgc.h \ 56 | llex.h \ 57 | llimits.h \ 58 | lmem.h \ 59 | lobject.h \ 60 | lopcodes.h \ 61 | lparser.h \ 62 | lstate.h \ 63 | lstring.h \ 64 | ltable.h \ 65 | ltm.h \ 66 | lundump.h \ 67 | lvm.h \ 68 | lzio.h 69 | 70 | T= $(LIB)/liblua.a 71 | 72 | all: $T 73 | 74 | $T: $(OBJS) 75 | $(AR) $@ $(OBJS) 76 | $(RANLIB) $@ 77 | 78 | clean: 79 | rm -f $(OBJS) $T 80 | 81 | co: 82 | co -q -f -M $(SRCS) 83 | 84 | klean: clean 85 | rm -f $(SRCS) 86 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/README: -------------------------------------------------------------------------------- 1 | This is the Lua core. 2 | 3 | The standard Lua library are in lib/. 4 | A sample interpreter is in lua/. 5 | A standalone compiler is in luac/. 6 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 1.21 2002/03/04 21:29:41 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | void luaA_pushobject (lua_State *L, const TObject *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 1.32 2002/11/18 11:01:55 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | void luaG_inithooks (lua_State *L); 22 | void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); 23 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2); 25 | int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); 26 | void luaG_runerror (lua_State *L, const char *fmt, ...); 27 | void luaG_errormsg (lua_State *L); 28 | int luaG_checkcode (const Proto *pt); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | Proto *luaF_newproto (lua_State *L); 15 | Closure *luaF_newCclosure (lua_State *L, int nelems); 16 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); 17 | UpVal *luaF_findupval (lua_State *L, StkId level); 18 | void luaF_close (lua_State *L, StkId level); 19 | void luaF_freeproto (lua_State *L, Proto *f); 20 | void luaF_freeclosure (lua_State *L, Closure *c); 21 | 22 | const char *luaF_getlocalname (const Proto *func, int local_number, int pc); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define luaC_checkGC(L) { lua_assert(!(L->ci->state & CI_CALLING)); \ 15 | if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); } 16 | 17 | 18 | void luaC_separateudata (lua_State *L); 19 | void luaC_callGCTM (lua_State *L); 20 | void luaC_sweep (lua_State *L, int all); 21 | void luaC_collectgarbage (lua_State *L); 22 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lib/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua standard library 2 | 3 | LUA= ../.. 4 | 5 | include $(LUA)/config 6 | 7 | EXTRA_DEFS= $(POPEN) $(TMPNAM) $(DEGREES) $(LOADLIB) 8 | 9 | OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o ltablib.o lstrlib.o loadlib.o 10 | SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c ltablib.c lstrlib.c loadlib.c 11 | 12 | T= $(LIB)/liblualib.a 13 | 14 | all: $T 15 | 16 | $T: $(OBJS) 17 | $(AR) $@ $(OBJS) 18 | $(RANLIB) $@ 19 | 20 | clean: 21 | rm -f $(OBJS) $T 22 | 23 | co: 24 | co -q -f -M $(SRCS) 25 | 26 | klean: clean 27 | rm -f $(SRCS) 28 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lib/README: -------------------------------------------------------------------------------- 1 | This is the standard Lua library. 2 | 3 | The code of the standard library can be read as an example of how to export 4 | C functions to Lua. The easiest library to read is lmathlib.c. 5 | 6 | The library is implemented entirely on top of the official Lua API as declared 7 | in lua.h, using lauxlib.c, which contains several useful functions for writing 8 | libraries. We encourage developers to use lauxlib.c in their own libraries. 9 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lib/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/src/lib/vssver.scc -------------------------------------------------------------------------------- /Common/lua-5.0/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.26 2002/05/01 20:40:42 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); 20 | 21 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, 22 | int limit, const char *errormsg); 23 | 24 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) 25 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ 27 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0) 28 | 29 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) 30 | #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) 31 | #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ 32 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)))) 33 | 34 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 35 | if (((nelems)+1) > (size)) \ 36 | ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) 37 | 38 | #define luaM_reallocvector(L, v,oldn,n,t) \ 39 | ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ 40 | cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) 41 | 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.37 2002/08/16 14:45:55 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | 16 | #define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ 17 | (cast(lu_mem, l)+1)*sizeof(char)) 18 | 19 | #define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) 20 | 21 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 23 | (sizeof(s)/sizeof(char))-1)) 24 | 25 | #define luaS_fix(s) ((s)->tsv.marked |= (1<<4)) 26 | 27 | void luaS_resize (lua_State *L, int newsize); 28 | Udata *luaS_newudata (lua_State *L, size_t s); 29 | void luaS_freeall (lua_State *L); 30 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 1.44 2003/03/18 12:50:04 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key) 15 | #define gval(n) (&(n)->i_val) 16 | 17 | 18 | const TObject *luaH_getnum (Table *t, int key); 19 | TObject *luaH_setnum (lua_State *L, Table *t, int key); 20 | const TObject *luaH_getstr (Table *t, TString *key); 21 | const TObject *luaH_get (Table *t, const TObject *key); 22 | TObject *luaH_set (lua_State *L, Table *t, const TObject *key); 23 | Table *luaH_new (lua_State *L, int narray, int lnhash); 24 | void luaH_free (lua_State *L, Table *t); 25 | int luaH_next (lua_State *L, Table *t, StkId key); 26 | 27 | /* exported only for debugging */ 28 | Node *luaH_mainposition (const Table *t, const TObject *key); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 1.41 2002/11/14 11:51:50 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_POW, 29 | TM_UNM, 30 | TM_LT, 31 | TM_LE, 32 | TM_CONCAT, 33 | TM_CALL, 34 | TM_N /* number of elements in the enum */ 35 | } TMS; 36 | 37 | 38 | 39 | #define gfasttm(g,et,e) \ 40 | (((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 41 | 42 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 43 | 44 | 45 | const TObject *luaT_gettm (Table *events, TMS event, TString *ename); 46 | const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event); 47 | void luaT_init (lua_State *L); 48 | 49 | extern const char *const luaT_typenames[]; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lua/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua interpreter 2 | 3 | LUA= ../.. 4 | 5 | include $(LUA)/config 6 | 7 | EXTRA_DEFS= $(USERCONF) 8 | OBJS= lua.o 9 | SRCS= lua.c 10 | 11 | T= $(BIN)/lua 12 | 13 | all: $T 14 | 15 | $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a 16 | $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) 17 | 18 | $(LIB)/liblua.a: 19 | cd ..; $(MAKE) 20 | 21 | $(LIB)/liblualib.a: 22 | cd ../lib; $(MAKE) 23 | 24 | clean: 25 | rm -f $(OBJS) $T 26 | 27 | co: 28 | co -q -f -M $(SRCS) 29 | 30 | klean: clean 31 | rm -f $(SRCS) 32 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lua/README: -------------------------------------------------------------------------------- 1 | This is lua, a sample Lua interpreter. 2 | It can be used as a batch interpreter and also interactively. 3 | There are man pages for it in both nroff and html in ../../doc. 4 | 5 | Usage: ./lua [options] [script [args]]. Available options are: 6 | - execute stdin as a file 7 | -e stat execute string `stat' 8 | -i enter interactive mode after executing `script' 9 | -l name load and run library `name' 10 | -v show version information 11 | -- stop handling options 12 | 13 | This interpreter is suitable for using Lua as a standalone language; it loads 14 | all standard libraries. For a minimal interpreter, see ../../etc/min.c. 15 | 16 | If your application simply exports new functions to Lua (which is common), 17 | then you can use this interpreter (almost) unmodified, as follows: 18 | 19 | * First, define a function 20 | void myinit (lua_State *L) 21 | in your own code. In this function, you should do whatever initializations 22 | are needed by your application, typically exporting your functions to Lua. 23 | (Of course, you can use any name instead of "myinit".) 24 | 25 | * Then, #define lua_userinit(L) to be "openstdlibs(L)+myinit(L)". 26 | Here, openstdlibs is a function in lua.c that opens all standard libraries. 27 | If you don't need them, just don't call openstdlibs and open any standard 28 | libraries that you do need in myinit. 29 | 30 | * Finally, remember to link your C code when building lua. 31 | 32 | For other customizations, see ../../etc/config.c. 33 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lua/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/src/lua/vssver.scc -------------------------------------------------------------------------------- /Common/lua-5.0/src/luac/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua compiler 2 | 3 | LUA= ../.. 4 | 5 | include $(LUA)/config 6 | 7 | INCS= -I$(INC) -I.. $(EXTRA_INCS) 8 | OBJS= luac.o print.o lopcodes.o 9 | SRCS= luac.c print.c 10 | 11 | T= $(BIN)/luac 12 | 13 | all: $T 14 | 15 | $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a 16 | $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) 17 | 18 | # print.c needs opcode names from lopcodes.c 19 | lopcodes.o: ../lopcodes.c ../lopcodes.h 20 | $(CC) -o $@ -c $(CFLAGS) -DLUA_OPNAMES ../lopcodes.c 21 | 22 | $(LIB)/liblua.a: 23 | cd ..; $(MAKE) 24 | 25 | $(LIB)/liblualib.a: 26 | cd ../lib; $(MAKE) 27 | 28 | clean: 29 | rm -f $(OBJS) $T 30 | 31 | co: 32 | co -q -f -M $(SRCS) 33 | 34 | klean: clean 35 | rm -f $(SRCS) 36 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/luac/README: -------------------------------------------------------------------------------- 1 | This is luac, the Lua compiler. 2 | There are man pages for it in both nroff and html in ../../doc. 3 | 4 | luac translates Lua programs into binary files that can be loaded latter. 5 | The main advantages of pre-compiling chunks are: faster loading, protecting 6 | source code from user changes, and off-line syntax error detection. 7 | luac can also be used to learn about the Lua virtual machine. 8 | 9 | Usage: /l/luac/luac [options] [filenames]. Available options are: 10 | - process stdin 11 | -l list 12 | -o name output to file `name' (default is "luac.out") 13 | -p parse only 14 | -s strip debug information 15 | -v show version information 16 | -- stop handling options 17 | 18 | luac is also an example of how to use the internals of Lua (politely). 19 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/luac/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/lua-5.0/src/luac/vssver.scc -------------------------------------------------------------------------------- /Common/lua-5.0/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.30 2003/04/07 20:34:20 lhf Exp $ 3 | ** load pre-compiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff); 15 | 16 | /* find byte order; from lundump.c */ 17 | int luaU_endianness (void); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data); 21 | 22 | /* print one chunk; from print.c */ 23 | void luaU_print (const Proto* Main); 24 | 25 | /* definitions for headers of binary files */ 26 | #define LUA_SIGNATURE "\033Lua" /* binary files start with "Lua" */ 27 | #define VERSION 0x50 /* last format change was in 5.0 */ 28 | #define VERSION0 0x50 /* last major change was in 5.0 */ 29 | 30 | /* a multiple of PI for testing native format */ 31 | /* multiplying by 1E7 gives non-trivial integer values */ 32 | #define TEST_NUMBER ((lua_Number)3.14159265358979323846E7) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Common/lua-5.0/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 1.47 2002/11/14 16:16:21 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r); 26 | int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2); 27 | const TObject *luaV_tonumber (const TObject *obj, TObject *n); 28 | int luaV_tostring (lua_State *L, StkId obj); 29 | const TObject *luaV_gettable (lua_State *L, const TObject *t, TObject *key, 30 | int loop); 31 | void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val); 32 | StkId luaV_execute (lua_State *L); 33 | void luaV_concat (lua_State *L, int total, int last); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Common/lua-5.0/test/README: -------------------------------------------------------------------------------- 1 | These are simple tests for Lua. Some of them contain useful code. 2 | They are meant to be run to make sure Lua is built correctly and also 3 | to be read, to see how Lua programs look. 4 | 5 | Here is a one-line summary of each program: 6 | 7 | bisect.lua bisection method for solving non-linear equations 8 | cf.lua temperature conversion table (celsius to farenheit) 9 | echo.lua echo command line arguments 10 | env.lua environment variables as automatic global variables 11 | factorial.lua factorial without recursion 12 | fib.lua fibonacci function with cache 13 | fibfor.lua fibonacci numbers with coroutines and generators 14 | globals.lua report global variable usage 15 | hello.lua the first program in every language 16 | life.lua Conway's Game of Life 17 | luac.lua bare-bones luac 18 | printf.lua an implementation of printf 19 | readonly.lua make global variables readonly 20 | sieve.lua the sieve of of Eratosthenes programmed with coroutines 21 | sort.lua two implementations of a sort function 22 | table.lua make table, grouping all data for the same item 23 | trace-calls.lua trace calls 24 | trace-globals.lua trace assigments to global variables 25 | undefined.lua catch "undefined" global variables 26 | xd.lua hex dump 27 | 28 | -------------------------------------------------------------------------------- /Common/lua-5.0/test/bisect.lua: -------------------------------------------------------------------------------- 1 | -- bisection method for solving non-linear equations 2 | 3 | delta=1e-6 -- tolerance 4 | 5 | function bisect(f,a,b,fa,fb) 6 | local c=(a+b)/2 7 | io.write(n," c=",c," a=",a," b=",b,"\n") 8 | if c==a or c==b or math.abs(a-b)>> ",string.rep(" ",level)) 9 | if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end 10 | t=debug.getinfo(2) 11 | if event=="call" then 12 | level=level+1 13 | else 14 | level=level-1 if level<0 then level=0 end 15 | end 16 | if t.what=="main" then 17 | if event=="call" then 18 | io.write("begin ",t.short_src) 19 | else 20 | io.write("end ",t.short_src) 21 | end 22 | elseif t.what=="Lua" then 23 | -- table.foreach(t,print) 24 | io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") 25 | else 26 | io.write(event," ",t.name or "(C)"," [",t.what,"] ") 27 | end 28 | io.write("\n") 29 | end 30 | 31 | debug.sethook(hook,"cr") 32 | level=0 33 | -------------------------------------------------------------------------------- /Common/lua-5.0/test/trace-globals.lua: -------------------------------------------------------------------------------- 1 | -- trace assigments to global variables 2 | 3 | do 4 | -- a tostring that quotes strings. note the use of the original tostring. 5 | local _tostring=tostring 6 | local tostring=function(a) 7 | if type(a)=="string" then 8 | return string.format("%q",a) 9 | else 10 | return _tostring(a) 11 | end 12 | end 13 | 14 | local log=function (name,old,new) 15 | local t=debug.getinfo(3,"Sl") 16 | local line=t.currentline 17 | io.write(t.short_src) 18 | if line>=0 then io.write(":",line) end 19 | io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") 20 | end 21 | 22 | local g={} 23 | local set=function (t,name,value) 24 | log(name,g[name],value) 25 | g[name]=value 26 | end 27 | setmetatable(getfenv(),{__index=g,__newindex=set}) 28 | end 29 | 30 | -- an example 31 | 32 | a=1 33 | b=2 34 | a=10 35 | b=20 36 | b=nil 37 | b=200 38 | print(a,b,c) 39 | -------------------------------------------------------------------------------- /Common/lua-5.0/test/undefined.lua: -------------------------------------------------------------------------------- 1 | -- catch "undefined" global variables 2 | 3 | local f=function (t,i) error("undefined global variable `"..i.."'",2) end 4 | setmetatable(getfenv(),{__index=f}) 5 | 6 | -- an example 7 | a=1 8 | c=3 9 | print(a,b,c) -- `b' is undefined 10 | -------------------------------------------------------------------------------- /Common/lua-5.0/test/xd.lua: -------------------------------------------------------------------------------- 1 | -- hex dump 2 | -- usage: lua xd.lua < file 3 | 4 | local offset=0 5 | 6 | while 1 do 7 | local s=io.read(16) 8 | if s==nil then return end 9 | io.write(string.format("%08X ",offset)) 10 | string.gsub(s,"(.)",function (c) io.write(string.format("%02X ",string.byte(c))) end) 11 | io.write(string.rep(" ",3*(16-string.len(s)))) 12 | io.write(" ",string.gsub(s,"%c","."),"\n") 13 | offset=offset+16 14 | end 15 | -------------------------------------------------------------------------------- /Common/luabind/LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003 Daniel Wallin and Arvid Norberg 2 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | 10 | // The above copyright notice and this permission notice shall be included 11 | // in all copies or substantial portions of the Software. 12 | 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 14 | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 15 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17 | // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 18 | // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 21 | // OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Common/luabind/config: -------------------------------------------------------------------------------- 1 | # the library's configuration is 2 | # controlled through the CONFIG variable 3 | 4 | #CONFIG = \ 5 | # -DLUABIND_DONT_COPY_STRINGS \ 6 | # -DLUABIND_NO_EXCEPTIONS \ 7 | # -DLUABIND_NO_ERROR_CHECKING \ 8 | # -DNDEBUG 9 | 10 | # if boost and lua are installed in system 11 | # include paths, you don't have to set these 12 | # variables 13 | 14 | #BOOST_PATH = -I/scratch/boost_1_30_0 15 | #LUA_PATH = -I/scratch/lua-5.0/include 16 | 17 | #lua lib path is used for the test program 18 | 19 | #LUA_LIB_PATH = -L/scratch/lua-5.0/lib 20 | LUA_LIB_PATH = -L/usr/local/lib 21 | 22 | CXX = g++ 23 | 24 | -------------------------------------------------------------------------------- /Common/luabind/doc/style.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | background-color: white; 4 | color: black; 5 | margin: 1em 2em 1em 2em; 6 | } 7 | 8 | h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; font-size: 140%; } 9 | h2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; font-size: 110%; } 10 | h3 { font-family: "courier new", courier, monospace; font-weight: bold; text-align: left; font-size: 100%; } 11 | 12 | pre 13 | { 14 | border: gray 1pt solid; 15 | padding: 2pt; 16 | 17 | display: block; 18 | font-family: "courier new", courier, monospace; 19 | background-color: #eeeeee; 20 | color: black; 21 | font-size: small 22 | } 23 | 24 | tt 25 | { 26 | display: inline; 27 | font-family: "Courier New", Courier, monospace; 28 | } 29 | 30 | p 31 | { 32 | text-align: justify; 33 | font-family: Georgia, "Times New Roman", Times, serif 34 | } 35 | 36 | ul 37 | { 38 | font-family: Georgia, "Times New Roman", Times, serif 39 | } 40 | 41 | ol 42 | { 43 | font-family: Georgia, "Times New Roman", Times, serif 44 | } 45 | 46 | a 47 | { 48 | font-weight: bold; 49 | color: #003366; 50 | text-decoration: none; 51 | } 52 | 53 | table 54 | { 55 | border: 1px solid black 56 | } 57 | 58 | td 59 | { 60 | border: 1px solid black 61 | } 62 | 63 | a:hover 64 | { 65 | color: #8080FF; 66 | } 67 | -------------------------------------------------------------------------------- /Common/luabind/doc/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/doc/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/any_converter/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: any_converter 4 | 5 | any_converter: any_converter.cpp 6 | $(CXX) any_converter.cpp -O3 -o any_converter $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -llua -llualib 7 | 8 | clean: 9 | rm -f any_converter.o 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/any_converter/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/any_converter/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/cln/README: -------------------------------------------------------------------------------- 1 | To build this example you need to have CLN installed. It can be found at 2 | 3 | http://www.ginac.de/CLN/ 4 | 5 | -------------------------------------------------------------------------------- /Common/luabind/examples/cln/cln_test.lua: -------------------------------------------------------------------------------- 1 | 2 | a = factorial(41) 3 | b = factorial(42) 4 | 5 | print('a = fac(41) = ' .. tostring(a)) 6 | print('b = fac(42) = ' .. tostring(b)) 7 | print('b / a = ' .. tostring(b / a)) 8 | 9 | c = a * 42 10 | 11 | if c == b then print('equality operator test: ok') else print('equality operator test: failed') end 12 | 13 | -- prints 14 | -- a = fac(41) = 33452526613163807108170062053440751665152000000000 15 | -- b = fac(42) = 1405006117752879898543142606244511569936384000000000 16 | -- b / a = 42 17 | 18 | -------------------------------------------------------------------------------- /Common/luabind/examples/cln/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: cln_test 4 | 5 | cln_test: cln_test.cpp 6 | $(CXX) cln_test.cpp -o cln_test $(LUA_PATH) -I- $(BOOST_PATH) -I../../ $(LUA_LIB_PATH) -L../../lib -lluabind -llua -llualib -lcln 7 | 8 | clean: 9 | rm -f cln_test.o 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/cln/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/cln/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/filesystem/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: filesystem 4 | 5 | filesystem: filesystem.cpp 6 | $(CXX) filesystem.cpp -O3 -o filesystem $(LUA_PATH) -I./ -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -llua -llualib -L./ -lboost_filesystem 7 | 8 | clean: 9 | rm -f filesystem.o 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/filesystem/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/filesystem/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/glut/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: glut_test 4 | 5 | glut_test: glut_bind.cpp 6 | $(CXX) glut_bind.cpp -o glut_bind $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -I/usr/X11R6/include -L/usr/X11R6/lib $(LUA_LIB_PATH) -L../../lib -lluabind -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib 7 | 8 | clean: 9 | rm -f glut_bind.o 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/glut/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/glut/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/intrusive_ptr/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: intrusive_ptr 4 | 5 | intrusive_ptr: intrusive_ptr.cpp 6 | $(CXX) intrusive_ptr.cpp -o intrusive_ptr $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -llua -llualib 7 | 8 | clean: 9 | rm -f intrusive_ptr 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/intrusive_ptr/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/intrusive_ptr/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/makefile: -------------------------------------------------------------------------------- 1 | 2 | all clean: 3 | cd cln; $(MAKE) $@ 4 | cd intrusive_ptr; $(MAKE) $@ 5 | cd any_converter; $(MAKE) $@ 6 | cd glut; $(MAKE) $@ 7 | cd regexp; $(MAKE) $@ 8 | 9 | -------------------------------------------------------------------------------- /Common/luabind/examples/regexp/makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | all: regexp 4 | 5 | regexp: regex_wrap.cpp 6 | $(CXX) regex_wrap.cpp -o regex_wrap $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -lboost_regex -llua -llualib 7 | 8 | clean: 9 | rm -f regex_wrap.o 10 | 11 | -------------------------------------------------------------------------------- /Common/luabind/examples/regexp/regex.lua: -------------------------------------------------------------------------------- 1 | 2 | html_tag = regex("<(.*?)>") 3 | src = 'dadasdsa' 4 | 5 | while html_tag:search(src, regex.match_default) do 6 | print('tag: ' .. html_tag:what(1)) 7 | src = string.sub(src, html_tag:position(0) + html_tag:length(0)) 8 | end 9 | 10 | print('-------------') 11 | 12 | 13 | -------------------------------------------------------------------------------- /Common/luabind/examples/regexp/regex_wrap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" 4 | { 5 | #include "lua.h" 6 | #include "lauxlib.h" 7 | #include "lualib.h" 8 | } 9 | 10 | #include 11 | 12 | 13 | void wrap_regex(lua_State* L) 14 | { 15 | using boost::RegEx; 16 | using namespace luabind; 17 | 18 | class_(L, "regex") 19 | .def(constructor()) 20 | .def(constructor()) 21 | .def("match", (bool(RegEx::*)(const char*, unsigned int))&RegEx::Match) 22 | .def("search", (bool(RegEx::*)(const char*, unsigned int))&RegEx::Search) 23 | .def("what", &RegEx::What) 24 | .def("matched", &RegEx::Matched) 25 | .def("length", &RegEx::Length) 26 | .def("position", &RegEx::Position) 27 | .enum_("flags") 28 | [ 29 | value("match_default", boost::match_default), 30 | value("match_prev_avail", boost::match_prev_avail), 31 | value("match_not_bob", boost::match_not_bob) 32 | ] 33 | ; 34 | } 35 | 36 | void test_wrap_regex() 37 | { 38 | lua_State* L = lua_open(); 39 | lua_baselibopen(L); 40 | lua_strlibopen(L); 41 | 42 | wrap_regex(L); 43 | 44 | lua_dofile(L, "regex.lua"); 45 | 46 | lua_close(L); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Common/luabind/examples/regexp/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/regexp/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/examples/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/examples/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/luabind/detail/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/luabind/detail/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/luabind/luabind.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003 Daniel Wallin and Arvid Norberg 2 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | 10 | // The above copyright notice and this permission notice shall be included 11 | // in all copies or substantial portions of the Software. 12 | 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 14 | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 15 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17 | // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 18 | // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 21 | // OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | 24 | #ifndef LUABIND_BIND_HPP_INCLUDED 25 | #define LUABIND_BIND_HPP_INCLUDED 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #endif // LUABIND_BIND_HPP_INCLUDED 34 | -------------------------------------------------------------------------------- /Common/luabind/luabind/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/luabind/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/makefile: -------------------------------------------------------------------------------- 1 | 2 | all clean: lib 3 | cd src; $(MAKE) $@ 4 | cd test; $(MAKE) $@ 5 | 6 | lib: 7 | mkdir -p $@ 8 | 9 | -------------------------------------------------------------------------------- /Common/luabind/src/makefile: -------------------------------------------------------------------------------- 1 | include ../config 2 | 3 | SOURCES = \ 4 | class_rep.cpp \ 5 | function.cpp \ 6 | find_best_match.cpp \ 7 | implicit_cast.cpp \ 8 | open.cpp \ 9 | create_class.cpp \ 10 | stack_content_by_name.cpp \ 11 | object.cpp 12 | 13 | OBJECTS = $(SOURCES:.cpp=.o) 14 | 15 | TARGET = ../lib/libluabind.a 16 | 17 | 18 | 19 | 20 | 21 | all: $(TARGET) 22 | 23 | $(TARGET): $(OBJECTS) 24 | $(AR) rcu $@ $(OBJECTS) 25 | ranlib $@ 26 | 27 | %.o:%.cpp 28 | $(CXX) -O3 -Wall -c $? -o $@ $(LUA_PATH) -I- -I.. $(BOOST_PATH) $(CONFIG) 29 | 30 | clean: 31 | rm -f $(OBJECTS) $(TARGET) 32 | 33 | -------------------------------------------------------------------------------- /Common/luabind/src/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/src/vssver.scc -------------------------------------------------------------------------------- /Common/luabind/test/makefile: -------------------------------------------------------------------------------- 1 | include ../config 2 | 3 | SOURCES = \ 4 | main.cpp \ 5 | test_iterator.cpp \ 6 | test_lua_classes.cpp \ 7 | test_typetraits.cpp \ 8 | test_construction.cpp \ 9 | test_operators.cpp \ 10 | test_attributes.cpp \ 11 | test_exceptions.cpp \ 12 | test_const.cpp \ 13 | test_null_pointer.cpp \ 14 | test_implicit_cast.cpp \ 15 | test_policies.cpp \ 16 | test_free_functions.cpp \ 17 | test_object.cpp \ 18 | test_held_type.cpp \ 19 | test_scope.cpp \ 20 | test_yield.cpp 21 | 22 | TARGET = test_luabind 23 | 24 | 25 | 26 | 27 | OBJECTS = $(SOURCES:.cpp=.o) 28 | 29 | all: $(TARGET) 30 | 31 | $(TARGET): $(OBJECTS) 32 | $(CXX) -O3 $(OBJECTS) $(LUA_LIB_PATH) -L../lib -lluabind -llua -llualib -o $@ 33 | 34 | %.o:%.cpp 35 | $(CXX) -Wall -ftemplate-depth-50 -O3 $(CONFIG) $(LUA_PATH) -I. -I- -I../ $(BOOST_PATH) -c $? -o $@ 36 | 37 | relink: 38 | rm -f $(TARGET) 39 | make 40 | 41 | clean: 42 | rm -f $(OBJECTS) $(TARGET) core 43 | 44 | -------------------------------------------------------------------------------- /Common/luabind/test/test.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_H_INCLUDED 2 | #define TEST_H_INCLUDED 3 | 4 | extern "C" 5 | { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | } 9 | 10 | //#define LUABIND_NO_ERROR_CHECKING 11 | //#define LUABIND_DONT_COPY_STRINGS 12 | //#define LUABIND_NO_EXCEPTIONS 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | bool dostring(lua_State* L, const char* str); 23 | int dostring2(lua_State* L, const char* str); 24 | 25 | struct lua_closer 26 | { 27 | lua_State* L; 28 | lua_closer(lua_State* L_): L(L_) {} 29 | void release() { if (L) {lua_close(L); L = 0; } } 30 | ~lua_closer() { if (L != 0) lua_close(L); } 31 | }; 32 | 33 | 34 | bool test_operators(); 35 | bool test_attributes(); 36 | bool test_construction(); 37 | bool test_implicit_cast(); 38 | bool test_const(); 39 | bool test_exceptions(); 40 | bool test_null_pointer(); 41 | bool test_policies(); 42 | bool test_lua_classes(); 43 | bool test_free_functions(); 44 | bool test_object(); 45 | bool test_held_type(); 46 | bool test_iterator(); 47 | bool test_scope(); 48 | bool test_yield(); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Common/luabind/test/test_const.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | namespace 4 | { 5 | LUABIND_ANONYMOUS_FIX int feedback = 0; 6 | 7 | struct A 8 | { 9 | const A* f() { return this; } 10 | 11 | void g() const { feedback = 1; } 12 | void g() { feedback = 2; } 13 | }; 14 | 15 | } // anonymous namespace 16 | 17 | bool test_const() 18 | { 19 | using namespace luabind; 20 | 21 | lua_State* L = lua_open(); 22 | lua_closer c(L); 23 | int top = lua_gettop(L); 24 | 25 | open(L); 26 | 27 | typedef void(A::*g1_t)(); 28 | typedef void(A::*g2_t)() const; 29 | 30 | g1_t g1 = &A::g; 31 | g2_t g2 = &A::g; 32 | 33 | module(L) 34 | [ 35 | class_("A") 36 | .def(constructor<>()) 37 | .def("f", &A::f) 38 | .def("g", /*(void(A::*)() const) &A::g*/ g1) 39 | .def("g", /*(void(A::*)()) &A::g*/ g2) 40 | ]; 41 | 42 | if (dostring(L, "a = A()")) return false; 43 | if (dostring(L, "a:g()")) return false; 44 | if (feedback != 2) return false; 45 | 46 | if (dostring(L, "a2 = a:f()")) return false; 47 | if (dostring(L, "a2:g()")) return false; 48 | if (feedback != 1) return false; 49 | 50 | if (top != lua_gettop(L)) return false; 51 | 52 | return true; 53 | } 54 | -------------------------------------------------------------------------------- /Common/luabind/test/test_implicit_cast.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | namespace 4 | { 5 | LUABIND_ANONYMOUS_FIX int feedback = 0; 6 | 7 | struct A {}; 8 | struct B: public A {}; 9 | 10 | struct test_implicit 11 | { 12 | void f(A*) { feedback = 1; } 13 | void f(B*) { feedback = 2; } 14 | }; 15 | 16 | } // anonymous namespace 17 | 18 | bool test_implicit_cast() 19 | { 20 | using namespace luabind; 21 | 22 | lua_State* L = lua_open(); 23 | lua_closer c(L); 24 | int top = lua_gettop(L); 25 | 26 | open(L); 27 | 28 | typedef void (test_implicit::*f1)(A*); 29 | typedef void (test_implicit::*f2)(B*); 30 | 31 | module(L) 32 | [ 33 | class_("A") 34 | .def(constructor<>()), 35 | 36 | class_("B") 37 | .def(constructor<>()), 38 | 39 | class_("test") 40 | .def(constructor<>()) 41 | .def("f", (f1) &test_implicit::f) 42 | .def("f", (f2) &test_implicit::f) 43 | ]; 44 | 45 | if (dostring(L, "a = A()")) return false; 46 | if (dostring(L, "b = B()")) return false; 47 | if (dostring(L, "t = test()")) return false; 48 | 49 | if (dostring(L, "t:f(a)")) return false; 50 | if (feedback != 1) return false; 51 | 52 | if (dostring(L, "t:f(b)")) return false; 53 | if (feedback != 2) return false; 54 | 55 | if (top != lua_gettop(L)) return false; 56 | 57 | return true; 58 | } 59 | -------------------------------------------------------------------------------- /Common/luabind/test/test_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | extern "C" 4 | { 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | } 8 | 9 | #include 10 | #include 11 | 12 | namespace 13 | { 14 | LUABIND_ANONYMOUS_FIX int feedback = 0; 15 | 16 | struct IteratorTest 17 | { 18 | IteratorTest() 19 | { 20 | names.push_back("first one"); 21 | names.push_back("foobar"); 22 | names.push_back("last one"); 23 | } 24 | 25 | std::vector names; 26 | }; 27 | 28 | } // anonymous namespace 29 | 30 | bool test_iterator() 31 | { 32 | using namespace luabind; 33 | 34 | lua_State* L = lua_open(); 35 | lua_baselibopen(L); 36 | lua_closer c(L); 37 | 38 | open(L); 39 | 40 | module(L) 41 | [ 42 | class_("A") 43 | .def(constructor<>()) 44 | .def_readonly("names", &IteratorTest::names, return_stl_iterator) 45 | ]; 46 | 47 | dostring(L, "a = A()"); 48 | dostring(L, "b = ''"); 49 | dostring(L, "for name in a.names do b = b .. name end"); 50 | 51 | if (object_cast(get_globals(L)["b"]) != "first onefoobarlast one") return false; 52 | 53 | return true; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Common/luabind/test/test_null_pointer.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | namespace 4 | { 5 | 6 | struct A 7 | { 8 | A* f() { return 0; } 9 | }; 10 | 11 | A* get_pointer() 12 | { 13 | return 0; 14 | } 15 | 16 | } // anonymous namespace 17 | 18 | 19 | bool test_null_pointer() 20 | { 21 | using namespace luabind; 22 | 23 | lua_State* L = lua_open(); 24 | lua_closer c(L); 25 | int top = lua_gettop(L); 26 | 27 | open(L); 28 | 29 | module(L) 30 | [ 31 | class_("A") 32 | .def(constructor<>()) 33 | .def("f", &A::f), 34 | 35 | def("get_pointer", get_pointer) 36 | ]; 37 | if (dostring(L, "e = get_pointer()")) return false; 38 | 39 | lua_pushstring(L, "e"); 40 | lua_gettable(L, LUA_GLOBALSINDEX); 41 | if (!lua_isnil(L, -1)) return false; 42 | lua_pop(L, 1); 43 | 44 | if (dostring(L, "a = A() e = a:f()")) return false; 45 | lua_pushstring(L, "e"); 46 | lua_gettable(L, LUA_GLOBALSINDEX); 47 | if (!lua_isnil(L, -1)) return false; 48 | lua_pop(L, 1); 49 | 50 | if (top != lua_gettop(L)) return false; 51 | 52 | return true; 53 | } 54 | -------------------------------------------------------------------------------- /Common/luabind/test/test_typetraits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace luabind::detail; 5 | 6 | struct tester {}; 7 | 8 | void test_type_traits() 9 | { 10 | BOOST_STATIC_ASSERT(is_nonconst_reference::value); 11 | BOOST_STATIC_ASSERT(!is_nonconst_reference::value); 12 | BOOST_STATIC_ASSERT(is_nonconst_reference::value); 13 | BOOST_STATIC_ASSERT(!is_nonconst_reference::value); 14 | 15 | BOOST_STATIC_ASSERT(!is_const_reference::value); 16 | BOOST_STATIC_ASSERT(is_const_reference::value); 17 | BOOST_STATIC_ASSERT(!is_const_reference::value); 18 | BOOST_STATIC_ASSERT(is_const_reference::value); 19 | 20 | BOOST_STATIC_ASSERT(!is_const_pointer::value); 21 | BOOST_STATIC_ASSERT(is_const_pointer::value); 22 | BOOST_STATIC_ASSERT(!is_const_pointer::value); 23 | BOOST_STATIC_ASSERT(is_const_pointer::value); 24 | 25 | BOOST_STATIC_ASSERT(is_nonconst_pointer::value); 26 | BOOST_STATIC_ASSERT(!is_nonconst_pointer::value); 27 | BOOST_STATIC_ASSERT(is_nonconst_pointer::value); 28 | BOOST_STATIC_ASSERT(!is_nonconst_pointer::value); 29 | 30 | BOOST_STATIC_ASSERT(!is_const_reference::value); 31 | } 32 | -------------------------------------------------------------------------------- /Common/luabind/test/test_yield.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | 5 | namespace 6 | { 7 | LUABIND_ANONYMOUS_FIX int feedback = 0; 8 | 9 | struct test_class 10 | { 11 | test_class(): n(0) {} 12 | 13 | int f() const 14 | { 15 | return const_cast(n)++; 16 | } 17 | 18 | int n; 19 | }; 20 | 21 | int f(int a) 22 | { 23 | return 9; 24 | } 25 | 26 | int j(lua_State* L) 27 | { 28 | lua_pushnumber(L, 9); 29 | return lua_yield(L, 1); 30 | } 31 | 32 | void f() {} 33 | } 34 | 35 | #include 36 | 37 | bool test_yield() 38 | { 39 | using namespace luabind; 40 | { 41 | lua_State* L = lua_open(); 42 | lua_baselibopen(L); 43 | lua_closer c(L); 44 | 45 | open(L); 46 | 47 | module(L) 48 | [ 49 | class_("test") 50 | .def(constructor<>()) 51 | .def("f", &test_class::f, yield) 52 | ]; 53 | /* 54 | dostring(L, "function g() a = test() for i = 1, 10 do print(a:f()) end end"); 55 | 56 | lua_pushstring(L, "j"); 57 | lua_pushcclosure(L, j, 0); 58 | lua_settable(L, LUA_GLOBALSINDEX); 59 | 60 | lua_State* thread = lua_newthread(L); 61 | lua_pushstring(thread, "g"); 62 | lua_gettable(thread, LUA_GLOBALSINDEX); 63 | 64 | if (lua_resume(thread, 0)) 65 | { 66 | std::cout << "error: " << lua_tostring(thread, -1) << '\n'; 67 | } 68 | 69 | for (int i = 0; i < 10; ++i) 70 | { 71 | std::cout << "iteration: " << i << ", top: " << lua_gettop(thread) << '\n'; 72 | 73 | lua_resume(thread, lua_gettop(thread)); 74 | }*/ 75 | } 76 | 77 | return true; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /Common/luabind/test/vssver.scc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchen/Programming-Game-AI-by-Example-src/aa5379f3c4dc142577c7f010ebfb705e78754c5c/Common/luabind/test/vssver.scc -------------------------------------------------------------------------------- /Common/misc/ConsoleUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLE_UTILS_H 2 | #define CONSOLE_UTILS_H 3 | //------------------------------------------------------------------------ 4 | // 5 | // Name: ConsoleUtils.h 6 | // 7 | // Desc: Just a few handy utilities for dealing with consoles 8 | // 9 | // Author: Mat Buckland (fup@ai-junkie.com) 10 | // 11 | //------------------------------------------------------------------------ 12 | #include 13 | #include 14 | #include 15 | 16 | //default text colors can be found in wincon.h 17 | inline void SetTextColor(WORD colors) 18 | { 19 | HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE); 20 | 21 | SetConsoleTextAttribute(hConsole, colors); 22 | } 23 | 24 | inline void PressAnyKeyToContinue() 25 | { 26 | //change text color to white 27 | SetTextColor(FOREGROUND_BLUE| FOREGROUND_RED | FOREGROUND_GREEN); 28 | 29 | std::cout << "\n\nPress any key to continue" << std::endl; 30 | 31 | while (!kbhit()){} 32 | 33 | return; 34 | } 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /Common/misc/FrameCounter.cpp: -------------------------------------------------------------------------------- 1 | #include "framecounter.h" 2 | 3 | 4 | FrameCounter* FrameCounter::Instance() 5 | { 6 | static FrameCounter instance; 7 | 8 | return &instance; 9 | } -------------------------------------------------------------------------------- /Common/misc/FrameCounter.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMECOUNTER_H 2 | #define FRAMECOUNTER_H 3 | 4 | 5 | #define TickCounter FrameCounter::Instance() 6 | 7 | class FrameCounter 8 | { 9 | private: 10 | 11 | long m_lCount; 12 | 13 | int m_iFramesElapsed; 14 | 15 | FrameCounter():m_lCount(0), m_iFramesElapsed(0){} 16 | 17 | //copy ctor and assignment should be private 18 | FrameCounter(const FrameCounter&); 19 | FrameCounter& operator=(const FrameCounter&); 20 | 21 | public: 22 | 23 | static FrameCounter* Instance(); 24 | 25 | void Update(){++m_lCount; ++m_iFramesElapsed;} 26 | 27 | long GetCurrentFrame(){return m_lCount;} 28 | 29 | void Reset(){m_lCount = 0;} 30 | 31 | void Start(){m_iFramesElapsed = 0;} 32 | int FramesElapsedSinceStartCalled()const{return m_iFramesElapsed;} 33 | 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /Common/misc/TypeToString.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPE_TO_STRING_H 2 | #define TYPE_TO_STRING_H 3 | //----------------------------------------------------------------------------- 4 | // 5 | // Name: TypeToString.h 6 | // 7 | // Author: Mat Buckland (www.ai-junkie.com) 8 | // 9 | // Desc: an interface for a class that has a static 10 | // method for converting an int into a string. (useful when debugging 11 | // to convert enumerations) 12 | //----------------------------------------------------------------------------- 13 | #include 14 | 15 | class TypeToString 16 | { 17 | public: 18 | 19 | virtual std::string Convert(int enumeration)=0; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /Common/misc/autolist.h: -------------------------------------------------------------------------------- 1 | #ifndef AUTOLIST_H 2 | #define AUTOLIST_H 3 | 4 | //------------------------------------------------------------------------ 5 | // 6 | //Name: Autolist.h 7 | // 8 | //Desc: Inherit from this class to automatically create lists of 9 | // similar objects. Whenever an object is created it will 10 | // automatically be added to the list. Whenever it is destroyed 11 | // it will automatically be removed. 12 | // 13 | //Author: Mat Buckland (fup@ai-junkie.com) 14 | // 15 | //------------------------------------------------------------------------ 16 | #include 17 | 18 | 19 | template 20 | class AutoList 21 | { 22 | public: 23 | 24 | typedef std::list ObjectList; 25 | 26 | private: 27 | 28 | static ObjectList m_Members; 29 | 30 | protected: 31 | 32 | AutoList() 33 | { 34 | //cast this object to type T* and add it to the list 35 | m_Members.push_back(static_cast(this)); 36 | } 37 | 38 | ~AutoList() 39 | { 40 | m_Members.remove(static_cast(this)); 41 | } 42 | 43 | public: 44 | 45 | 46 | static ObjectList& GetAllMembers(){return m_Members;} 47 | }; 48 | 49 | 50 | template 51 | std::list AutoList::m_Members; 52 | 53 | 54 | 55 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming Game AI by Example 2 | 3 | The download link in the was broke. 4 | 5 | I found it from a torrent and share it here. 6 | --------------------------------------------------------------------------------