Mafia II Bringing city to life Martin Brandstätter Jan Kratochvíl
Content Ideas for creating living city Filling city with elements Basics of artificial intelligence Specific examples: –Pedestrians –Traffic cars
Living city Full of life Variability No restrictions for player Seamless streaming
Filling city with elements Static geometry Grass, garbage, etc Translocated objects Pedestrians Cars
Empty street
Translocated objects Translocator Many types of objects –Lamps, chairs, benches –Billboards, neons, traffic signs, semaphores –Trees, shrubs –Action points, and more
Translocator Multiple grids Storing only GUID, position, rotation & scale High & Low range Spawn is not optional
Street with translocated objects
Pedestrian spawning Where to spawn? –Position –Visibility –Usability Spawn points –Kynapse nodes
Kynapse visualization
Pedestrian despawn When to despawn a Pedestrian? –Is too far away –Is not visible for too long –Is not in any action Line of death
Car Spawn Little bit more complicated Data from roadmap Three types –“Translocated” –Parked –Moving
Spawn in black area Annulus P
Egg P
Advanced Egg P
Spawn points example
Car despawn Reasons to get despawned: –Not visible and not moving towards player –Be too far away and out of sight Visible cars are never despawned Police has special rules
Empty street
Street with translocated objects
Final Street
ActionPoints Sidewalk graph with crossings Actionpoints Destructible Objects with ActionPoints
Basics of artificial intelligence Brain Hierarchy Black Board Messaging Basic Behaviours Behaviour tree Ai and Script Comunication
Brain Hierarchy Small Brain Base Brain Single Brain Human Brain Car Brain Boat Brain Train Brain Team Brain
Basic Behaviours brain object small parallel selector composite team behaviour
More Behaviours Desire Desire Commander Desire Composite Slave and mapping factory
selector commander Composite commander commander commander Parallel Slave Action 0 Action 1
Ai and Script Communication Designers demands –script running in parallel with AI –script running without AI –script running with some parts of AI
Script Configuration Alive Parallel ScriptParallel Action 0 Action 1 Main Selector Desire Script AI Desire 0 AI Desire 1
Script commands Lua Script Message New Command Move,Turn,Anim,.. Desire Script Parallel Script
Script wants Exclusive Control Lua Script Message Script Control TRUE Desire Script Parallel Script
Script Gains Exclusive Control Lua Script Message Script Control TRUE Desire Script
Script Returns Control to AI Lua Script Message Script Control FALSE Desire Script Parallel Script
AI Gains Exclusive Control Lua Script Message Script Control FALSE Desire Script
AI wants Exclusive Control Lua Script Message AI Control - Reason Selector Script
Civilian Archetype Archetype configuration Behavior sub-tree wander Action-Point scripts
Wander Configuration Wander Parallel Wander Selector Crossing AP Scan Get In car Special Desire Wander Around Wander Slave Wander Style
Driving Roadmap Wandering driver Hunter – police, gangster, … Escaper – taxi, gangster, mission car
Roadmap Catmull-Rom splines Whole city roadmap is about 400Kb –Including all necessary meta information No 3 rd party library Crossroads are defined using splines as well
Catmull-Rom spline Special case of cubic Hermit spline Relatively easy to compute Spline is going through its interpolation points Tangents are continuous over multiple segments
Roadmap
Basic driving 1.Interpolate some position before you 2.Set wheels to point at this position 3.Set speed to something 4.You are done
Speed Desired speed is influenced by –Behavior – traffic lights, crossings, follower, … –Obstacle –Curve Every “desire” can only lower the desired speed
Curve speed Iterative algorithm Input –Preferred deceleration –Centripetal acceleration –Expected braking distance –Max speed
Curve speed ca – centripetal acceleration cr – curve radius L – segment length
Behavior speed Example: stop before crossing d – distance to crossing a – preferred deceleration of car
Obstacle speed Obstacle detection –Subdivision queries – no static scene Detection ahead on desired path Avoid obstacle if possible and desirable Adjust speed to obstacle speed Aggressiveness playing its role
Navigation point Interpolation on spline Shift to fit correct lane Random shift Obstacle shift
Navigation points
Crossroad Team AI Priority for each car Main roads Traffic lights Aggression & green wave
Crossroad
Hunter Police & gangsters Need to go off roadmap Player drops info behind him Need of collision scene tests
Escaper Special case of wandering car May be aggressive Crossroad trespassing is not random Has to ensure that he will reach its destination
Special behaviors Avoiding special cars Jam detector Collision detector Horn reaction …
Q&A