This file is indexed.

/usr/share/games/minetest/mods/mobf/mobf/mob_state.lua is in minetest-mod-mobf-core 2.5.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
-------------------------------------------------------------------------------
-- Mob Framework Mod by Sapier
--
-- You may copy, use, modify or do nearly anything except removing this
-- copyright notice.
-- And of course you are NOT allow to pretend you have written it.
--
--! @file mob_state.lua
--! @brief component mob state transition handling
--! @copyright Sapier
--! @author Sapier
--! @date 2012-08-09
--
--! @defgroup mob_state State handling functions
--! @brief a component to do basic changes to mob on state change
--! @ingroup framework_int
--! @{
--
-- Contact sapier a t gmx net
-------------------------------------------------------------------------------
mobf_assert_backtrace(not core.global_exists("mob_state"))
--! @class mob_state
--! @brief state handling class
--! @}
mob_state = {}
mob_state.default_state_time = 30

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] initialize(entity,now)
--
--! @brief initialize state dynamic data
--! @memberof mob_state
--! @public
--
--! @param entity elemet to initialize state data
--! @param now current time
-------------------------------------------------------------------------------
function mob_state.initialize(entity,now)

	dbg_mobf.mob_state_lvl3("MOBF: " .. entity.data.name
		.. " initializing state dynamic data")

	local state = {
		current = "default",
		time_to_next_change = 30,
		locked = false,
		enabled = false,
	}

	local sum_chances = 0
	local state_count = 0

	if entity.data.states ~= nil then
		for s = 1, #entity.data.states , 1 do
			sum_chances = sum_chances + entity.data.states[s].chance

			if entity.data.states[s].name ~= "combat" and
				entity.data.states[s].name ~= "default" then
				state_count = state_count +1
			end
		end
	end

	--sanity check for state chances
	if sum_chances > 1 then
		minetest.log(LOGLEVEL_WARNING,"MOBF: Warning sum of state chances for mob "
			.. entity.data.name .. " > 1")
	end

	--only enable state changeing if there is at least one state
	if state_count > 0 then
		state.enabled = true
	end

	entity.dynamic_data.state = state
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] get_state_by_name(entity,name)
--
--! @brief get a state by its name
--! @memberof mob_state
--! @public
--
--! @param entity elemet to look for state data
--! @param name of state
--!
--! @return state data or nil
-------------------------------------------------------------------------------
function mob_state.get_state_by_name(entity,name)
	mobf_assert_backtrace(entity ~= nil and entity.data ~= nil)

	for i=1, #entity.data.states, 1 do
		if entity.data.states[i].name == name then
			return entity.data.states[i]
		end
	end

	return nil
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] lock(entity,value)
--
--! @brief disable random state changes for a mob
--! @memberof mob_state
--! @public
--
--! @param entity elemet to lock
--! @param value to set
-------------------------------------------------------------------------------
function mob_state.lock(entity,value)
	if value ~= false and value ~= true then
		return
	end
	if entity.dynamic_data.state == nil then
		dbg_mobf.mob_state_lvl1("MOBF: unable to lock state for: "
			.. entity.data.name .. " no state dynamic data present")
		return
	end

	entity.dynamic_data.state.locked = value
end


-------------------------------------------------------------------------------
-- @function [parent=#mob_state] callback(entity,now,dstep)
--
--! @brief callback handling state changes
--! @memberof mob_state
--! @public
--
--! @param entity elemet to look for state data
--! @param now current time
--! @param dstep time passed since last call
--
--! @return
-------------------------------------------------------------------------------
function mob_state.callback(entity,now,dstep)

--TODO find out if this needs to be replaced
--	if entity.dynamic_data.state == nil then
--		minetest.log(LOGLEVEL_ERRROR,"MOBF BUG: " .. entity.data.name
--			.. " mob state callback without mob dynamic data!")
--		mob_state.initialize(entity,now)
--		local default_state = mob_state.get_state_by_name(self,"default")
--		entity.dynamic_data.current_movement_gen = getMovementGen(default_state.movgen)
--		entity.dynamic_data.current_movement_gen.init_dynamic_data(entity,mobf_get_current_time())
--		entity = spawning.replace_entity(entity,entity.data.modname .. ":"..entity.data.name,true)
--		return true
--	end

	--abort state change if current state is locked
	if entity.dynamic_data.state.locked or
		entity.dynamic_data.state.enabled == false then
		dbg_mobf.mob_state_lvl3("MOBF: " .. entity.data.name
			.. " state locked or no custom states definded ")
		return true
	end

	entity.dynamic_data.state.time_to_next_change = entity.dynamic_data.state.time_to_next_change -dstep

	--do only change if last state timed out
	if entity.dynamic_data.state.time_to_next_change < 0 then

		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
			.. " time to change state: " .. entity.dynamic_data.state.time_to_next_change
			.. " , " .. dstep .. " entity=" .. tostring(entity))

		local rand = math.random()

		local maxvalue = 0

		local state_table = {}

		--fill table with available states
		for i=1, #entity.data.states, 1 do
			if (entity.data.states[i].HANDLER_precondition == nil or
				entity.data.states[i].HANDLER_precondition(entity,entity.data.states[i])) and
				--ignore states that are not supposed to be switched to
				--by automatic state change handling e.g. fighting states or
				--manual set states
				( entity.data.states[i].state_mode == nil or
				  entity.data.states[i].state_mode == "auto") then
				table.insert(state_table,entity.data.states[i])
			end
		end

		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name .. " "
			.. dump(#state_table) .. " states do pass pecondition check ")

		--try to get a random state to change to
		for i=1, #state_table, 1 do

			local rand_state = math.random(#state_table)
			local current_chance = 0

			if type (state_table[rand_state].chance) == "function" then
				current_chance = state_table[rand_state].chance(entity,now,dstep)
			else
				if state_table[rand_state].chance ~= nil then
					current_chance = state_table[rand_state].chance
				end
			end

			local random_value = math.random()

			if random_value < current_chance then
				dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
					.. " switching to state " .. state_table[rand_state].name)
				mob_state.change_state(entity,state_table[rand_state])
				return true
			else
				dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
					.. " not switching to state " .. state_table[rand_state].name
					.. " rand was: " .. random_value)
				table.remove(state_table,rand_state)
			end
		end
		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
			.. " no specific state selected switching to default state ")
		--switch to default state (only reached if no change has been done
		mob_state.change_state(entity,mob_state.get_state_by_name(entity,"default"))
	else
		dbg_mobf.mob_state_lvl3("MOBF: " .. entity.data.name
			.. " is not ready for state change ")
		return true
	end

	return true
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] switch_switch_movgenentity(entity,state)
--
--! @brief helper function to swich a movement based on new state
--! @memberof mob_state
--! @private
--
--! @param entity to change movement gen
--! @param state to take new entity
-------------------------------------------------------------------------------
function mob_state.switch_movgen(entity,state)
	mobf_assert_backtrace(entity ~= nil)
	mobf_assert_backtrace(state ~= nil)
	local mov_to_set = nil

	--determine new movement gen
	if state.movgen ~= nil then
		mov_to_set = getMovementGen(state.movgen)
	else
		local default_state = mob_state.get_state_by_name(entity,"default")
		mov_to_set = getMovementGen(default_state.movgen)
	end

	--check if new mov gen differs from old one
	if mov_to_set ~= nil and
		mov_to_set ~= entity.dynamic_data.current_movement_gen then
		entity.dynamic_data.current_movement_gen = mov_to_set

		--TODO initialize new movement gen
		entity.dynamic_data.current_movement_gen.init_dynamic_data(entity,mobf_get_current_time())
	end
end


-------------------------------------------------------------------------------
-- @function [parent=#mob_state] change_state(entity,state)
--
--! @brief change state for an entity
--! @memberof mob_state
--! @public
--
--! @param entity to change state
--! @param state to change to
-------------------------------------------------------------------------------
function mob_state.change_state(entity,state)

	dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
		.. " state change called entity=" .. tostring(entity) .. " state:"
		.. dump(state))

	--check if custom precondition handler tells us to stop state change
	if state ~= nil and
		type(state.HANDLER_precondition) == "function" then
		if not state.HANDLER_precondition(entity,state) then
			dbg_mobf.mob_state_lvl1("MOBF: " .. entity.data.name
				.. " custom precondition handler didn't meet ")
			--don't assert but switch to default in this case
			state = mob_state.get_state_by_name(entity,"default")
		end
	end

	--switch to default state if no state given
	if state == nil then
		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
			.. " invalid state switch, switching to default instead of: "
			.. dump(state))
		state = mob_state.get_state_by_name(entity,"default")
	end

	local entityname = entity.data.name
	local statename = state.name

	dbg_mobf.mob_state_lvl2("MOBF: " .. entityname .. " switching state to "
		.. statename)

	if entity.dynamic_data.state == nil then
		mobf_bug_warning(LOGLEVEL_WARNING,"MOBF BUG!!! mob_state no state dynamic data")
	end

	if entity.dynamic_data.state.current.name ~= state.name then
		--call leave state handler for old state
		if entity.dynamic_data.state.current.HANDLER_leave_state ~= nil and
			type(entity.dynamic_data.state.current.HANDLER_leave_state) == "function" then
			entity.dynamic_data.state.current.HANDLER_leave_state(entity,state)
		end

		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
			.. " different states now really changeing to " .. state.name)

		mob_state.switch_movgen(entity,state)

		entity.dynamic_data.state.time_to_next_change =
			mob_state.getTimeToNextState(state.typical_state_time)
		entity.dynamic_data.state.current = state

		graphics.set_animation(entity,state.animation)

		if state.HANDLER_enter_state ~= nil and
			type(state.HANDLER_enter_state) == "function" then
			state.HANDLER_enter_state(entity)
		end
	else
		dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
			.. " switching to same state as before")
		entity.dynamic_data.state.time_to_next_change = mob_state.getTimeToNextState(state.typical_state_time)

		if state.HANDLER_enter_state ~= nil and
			type(state.HANDLER_enter_state) == "function" then
			state.HANDLER_enter_state(entity)
		end
	end
	
	--update model on each state change
	mob_state.switch_model(entity,state)

	dbg_mobf.mob_state_lvl2("MOBF:  time to next change = "
			.. entity.dynamic_data.state.time_to_next_change)
end


-------------------------------------------------------------------------------
-- @function [parent=#mob_state] getTimeToNextState(typical_state_time)
--
--! @brief helper function to calculate a gauss distributed random value
--! @memberof mob_state
--! @private
--
--! @param typical_state_time center of gauss
--!
--! @return a random value around typical_state_time
-------------------------------------------------------------------------------
function mob_state.getTimeToNextState(typical_state_time)

	if typical_state_time == nil then
		mobf_bug_warning(LOGLEVEL_WARNING,"MOBF MOB BUG!!! missing typical state time!")
		typical_state_time = mob_state.default_state_time
	end

	local u1 = 2 * math.random() -1
	local u2 = 2 * math.random() -1

	local q = u1*u1 + u2*u2

	local maxtries = 0

	while (q == 0 or q >= 1) and maxtries < 10 do
		u1 = math.random()
		u2 = math.random() * -1
		q = u1*u1 + u2*u2

		maxtries = maxtries +1
	end

	--abort random generation
	if maxtries >= 10 then
		return typical_state_time
	end

	local p = math.sqrt( (-2*math.log(q))/q )

	local retval = 2
	--calculate normalized state time with maximum error or half typical time up and down
	if math.random() < 0.5 then
		retval = typical_state_time + ( u1*p * (typical_state_time/2))
	else
		retval = typical_state_time + ( u2*p * (typical_state_time/2))
	end

	-- ensure minimum state time of 2 seconds
	if retval > 2 then
		return retval
	else
		return 2
	end
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] prepare_states(mob)
--
--! @brief prepare mobs states upon registration
--! @memberof mob_state
--! @public
--
--! @param mob a mob declaration
-------------------------------------------------------------------------------
function mob_state.prepare_states(mob)
	local builtin_state_overrides = {}

	--scan for states overriding mobf internal state definitions
	if mob.states ~= nil then
		for s = 1, #mob.states , 1 do
			if mob.states[s].name == "combat" then
				builtin_state_overrides["combat"] = true
			end

			--TODO patrol state

			--hunger state
			if mob.states[s].name == "RSVD_hunger" then
				builtin_state_overrides["RSVD_hunger"] = true
			end

		end
	else
		mob.states = {}
	end

	--add a default combat state if no custom state is defined
	if mob.combat ~= nil and builtin_state_overrides["combat"] ~= true then
		table.insert(mob.states,
				{
				name = "combat",
				HANDLER_precondition = nil,
				movgen = "follow_mov_gen",
				typical_state_time = -1,
				chance = 0,
				})
	end

	if mob.hunger ~= nil and builtin_state_overrides["RSVD_hunger"] ~= true then
		table.insert(mob.states,
					{
					name = "RSVD_hunger",
					HANDLER_precondition = mob_state.BuiltinHungerPrecondition(mob),
					HANDLER_leave_state  = mob_state.BuiltinHungerLeave(mob),
					HANDLER_enter_state  = mob_state.BuiltinHungerEnter(mob),
					movgen = "mgen_path",
					typical_state_time = mob.hunger.typical_walk_time or 45,
					chance             = mob.hunger.chance or 0.1,
					animation          = mob.hunger.animation or "walk"
				})
	end

end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] switch_model(entity,state)
--
--! @brief switch model used for a entity
--! @memberof mob_state
--! @public
--
--! @param entity to switch model
--! @param state to change to
-------------------------------------------------------------------------------
function mob_state.switch_model(entity, state)

	
	local new_graphics = graphics.graphics_by_statename(entity.data, state.name)
	
	if type(new_graphics.texturelist) == "table" then
		if entity.dynamic_data.textureidx ~= nil and 
			entity.dynamic_data.textureidx < #new_graphics.texturelist then
			new_graphics.textures = new_graphics.texturelist[entity.dynamic_data.textureidx]
		else
			new_graphics.textures = new_graphics.texturelist[1]
		end
	end
	
	local new_props = { 
		automatic_face_movement_dir = true,
		textures = new_graphics.textures
		}
	
	if new_graphics.model_orientation_fix ~= nil then
		new_props.automatic_face_movement_dir =
			(new_graphics.model_orientation_fix / math.pi) * 360  + 90
	end
	
	--TODO apply new model too
	
	entity.object:set_properties(new_props)
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] BuiltinHungerPrecondition(mob)
--
--! @brief prepare builtin hunger precondition handler
--! @memberof mob_state
--! @public
--
--! @param mob definition of mob
--! @return function to be called as precondition handler
-------------------------------------------------------------------------------
function mob_state.BuiltinHungerPrecondition(mob)

	mobf_assert_backtrace(
		(mob.hunger.target_nodes ~= nil) or
		(mob.hunger.target_entities ~= nil))
	mobf_assert_backtrace(mob.hunger.range ~= nil)

	return function(entity,state)
			mobf_assert_backtrace(state ~= nil)
			mobf_assert_backtrace(state.name == "RSVD_hunger")

			local pos = entity.object:getpos()
			--mobf_print("MOBF: trying to find " ..
			--				dump(mob.hunger.target_nodes) .. " or " ..
			--				dump(mob.hunger.target_entities) ..
			--				" around: " .. printpos(pos))

			local lower_pos = {x=pos.x-mob.hunger.range,
								y=pos.y-mob.hunger.range,
								z=pos.z-mob.hunger.range}
			local upper_pos = {x=pos.x+mob.hunger.range,
								y=pos.y+mob.hunger.range,
								z=pos.z+mob.hunger.range}

			local target_nodes = nil
			local target_entities = nil

			if mob.hunger.target_nodes ~= nil then
				target_nodes = minetest.find_nodes_in_area(lower_pos,
											upper_pos,
											 mob.hunger.target_nodes)
			end

			if mob.hunger.target_entities ~= nil then
				local objectlist = minetest.get_objects_inside_radius(pos,mob.hunger.range)
				--mobf_print("MOBF: found: " .. #objectlist .. " objects around")
				if objectlist ~= nil and #objectlist > 0 then
					target_entities = {}
					for i=1,#objectlist,1 do
						local luaentity = objectlist[i]:get_luaentity()
						if luaentity ~= nil and
							mobf_contains(mob.hunger.target_entities,luaentity.name) then
							table.insert(target_entities,objectlist[i])
						end
					end
				end
			end

			local targets = {}

			if target_nodes ~= nil then
				for i=1,#target_nodes,1 do
					table.insert(targets,target_nodes[i])
				end
			end

			if target_entities ~= nil then
				for i=1,#target_entities,1 do
					table.insert(targets,target_entities[i])
				end
			end

			if targets ~= nil then
				dbg_mobf.mob_state_lvl3("MOBF: Hunger found " .. #targets .. " targets")
				for i=1,5,1 do
					if #targets == 0 then
						break
					end

					local index = math.floor(math.random(1,#targets) + 0.5)

					local target = targets[index]
					table.remove(targets,index)

					--target is a entity
					if type(target) == "userdata" then
						entity.dynamic_data.hunger = {}
						entity.dynamic_data.hunger.target = target
						--mobf_print("MOBF: saving hungerdata: " .. dump(entity.dynamic_data.hunger))
						return true
					else
						local targetpos = target
						targetpos.y = targetpos.y +1

						--if mob is not in air try 1 above for pathfinding
						local current_node = minetest.get_node(pos)
						if current_node ~= nil and
							current_node.name ~= "air" then
							pos.y = pos.y+1
						end

						local path = mobf_path.find_path(pos,targetpos,5,1,1,"A*_noprefetch")

						if path ~= nil then
							entity.dynamic_data.hunger = {}
							entity.dynamic_data.hunger.target = { x=targetpos.x,y=targetpos.y-1,z=targetpos.z}
							entity.dynamic_data.hunger.path = path
							--mobf_print("MOBF: Found new target: " .. printpos(targetpos) .. " Path: " .. dump(path))
							--mobf_print("MOBF: saving hungerdata: " .. dump(entity.dynamic_data.hunger))
							return true
						else
							dbg_mobf.mob_state_lvl2("MOBF: hunger no path to: " .. printpos(targetpos))
						end
					end
				end
			end
			return false
		end --end of handler
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] BuiltinHungerLeave(mob)
--
--! @brief prepare builtin hunger leave handler
--! @memberof mob_state
--! @public
--
--! @param mob definition of mob
--! @return function to be called as leave handler
-------------------------------------------------------------------------------
function mob_state.BuiltinHungerLeave(mob)

	return function(entity,state)
		--restore old stepheight
		entity.object:set_properties({stepheight=entity.dynamic_data.hunger.old_stepheight})
		entity.dynamic_data.hunger = nil
		p_mov_gen.set_cycle_path(entity,nil)
		p_mov_gen.set_path(entity,nil)
		p_mov_gen.set_end_of_path_handler(entity,nil)

	end
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] BuiltinHungerEnter(mob)
--
--! @brief prepare builtin hunger enter handler
--! @memberof mob_state
--! @public
--
--! @param mob definition of mob
--! @return function to be called as enter handler
-------------------------------------------------------------------------------
function mob_state.BuiltinHungerEnter(mob)

	return function(entity)
		mobf_assert_backtrace(entity.dynamic_data.state.current.name == "RSVD_hunger")
		mobf_assert_backtrace(entity.dynamic_data.hunger ~= nil)

		--use stepheight 1 as we did look for a path by using this
		entity.dynamic_data.hunger.old_stepheight = entity.stepheight

		if (type(entity.dynamic_data.hunger.target) == "userdata") then
			if not p_mov_gen.set_target(entity,entity.dynamic_data.hunger.target) then
				dbg_mobf.mob_state_lvl1("MOBF: EnterHungerState, failed to set target")
			end
		else
			entity.object:set_properties({stepheight=1})
			p_mov_gen.set_path(entity,entity.dynamic_data.hunger.path)
		end
		--p_mov_gen.set_cycle_path(entity,handler)
		p_mov_gen.set_cycle_path(entity,false)
		p_mov_gen.set_end_of_path_handler(entity,mob_state.BuiltinHungerTargetReached)

	end
end

-------------------------------------------------------------------------------
-- @function [parent=#mob_state] BuiltinHungerTargetReached(entity)
--
--! @brief handle target reached
--! @memberof mob_state
--! @public
--
--! @param entity that reached the target
-------------------------------------------------------------------------------
function mob_state.BuiltinHungerTargetReached(entity)
	--consume original target
	if (entity.dynamic_data.hunger.target ~= nil) and
		(entity.data.hunger.keep_food == nil or
		entity.data.hunger.keep_food == false) then
		if type(entity.dynamic_data.hunger.target) ~= "userdata" then
			dbg_mobf.mob_state_lvl2("MOBF: consuming targetnode: " ..
				printpos(entity.dynamic_data.hunger.target))
			minetest.remove_node(entity.dynamic_data.hunger.target)
		else
			local targetentity = entity.dynamic_data.hunger.target:get_luaentity()

			if targetentity ~= nil and
				type(targetentity.mobf_hunger_interface) == "function" then
				targetentity.mobf_hunger_interface(entity,"HUNGER_CONSUME")
				dbg_mobf.mob_state_lvl2("MOBF: consuming targetentity")
			end
		end
	end

	local eating_state = mob_state.get_state_by_name(entity,"eating")

	if eating_state ~= nil then
		mob_state.change_state(entity,eating_state)
	else
		local default_state = mob_state.get_state_by_name(entity,"default")
		mob_state.change_state(entity,default_state)
	end
end