Do actual domain resolution
[carveJwlIkooP6JGAAIwe30JlM.git] / entity.c
1 #include "world.h"
2 #include "entity.h"
3 #include "world_entity.h"
4
5 #include "ent_objective.h"
6 #include "ent_skateshop.h"
7 #include "ent_relay.h"
8 #include "ent_challenge.h"
9 #include "ent_route.h"
10 #include "ent_miniworld.h"
11 #include "ent_region.h"
12 #include "ent_glider.h"
13 #include "ent_npc.h"
14 #include "world_water.h"
15
16 #include <string.h>
17
18 void entity_call( world_instance *world, ent_call *call )
19 {
20 u32 type = mdl_entity_id_type( call->id ),
21 index = mdl_entity_id_id( call->id );
22
23 fn_entity_call_handler table[] = {
24 [k_ent_volume] = ent_volume_call,
25 [k_ent_audio] = ent_audio_call,
26 [k_ent_skateshop] = ent_skateshop_call,
27 [k_ent_objective] = ent_objective_call,
28 [k_ent_ccmd] = ent_ccmd_call,
29 [k_ent_gate] = ent_gate_call,
30 [k_ent_relay] = ent_relay_call,
31 [k_ent_challenge] = ent_challenge_call,
32 [k_ent_route] = ent_route_call,
33 [k_ent_miniworld] = ent_miniworld_call,
34 [k_ent_region] = ent_region_call,
35 [k_ent_glider] = ent_glider_call,
36 [k_ent_npc] = ent_npc_call,
37 [k_ent_water] = ent_water_call,
38 };
39
40 if( type >= vg_list_size(table) ){
41 vg_error( "call to entity type: %u is out of range\n", type );
42 return;
43 }
44
45 fn_entity_call_handler fn = table[ type ];
46
47 if( !fn )
48 {
49 vg_error( "Entity type %u does not have a call handler, "
50 "but was called anyway\n", type );
51 return;
52 }
53
54 enum entity_call_result res = fn( world, call );
55
56 if( res == k_entity_call_result_unhandled )
57 {
58 vg_warn( "Call to entity %u#%u was unhandled.\n", type, index );
59 }
60 }
61
62 ent_marker *ent_find_marker( mdl_context *mdl, mdl_array_ptr *arr,
63 const char *alias )
64 {
65 for( u32 i=0; i<mdl_arrcount(arr); i++ )
66 {
67 ent_marker *marker = mdl_arritm( arr, i );
68
69 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) )
70 {
71 return marker;
72 }
73 }
74
75 return NULL;
76 }
77