small refactor of model loading
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_region.c
1 #include "ent_region.h"
2 #include "gui.h"
3 #include "network_common.h"
4 #include "network.h"
5
6 struct global_ent_region global_ent_region;
7
8 u32 region_spark_colour( u32 flags )
9 {
10 if( flags & k_ent_route_flag_achieve_gold )
11 return 0xff8ce0fa;
12 else if( flags & k_ent_route_flag_achieve_silver )
13 return 0xffc2c2c2;
14 else
15 return 0x00;
16 }
17
18 void ent_region_call( world_instance *world, ent_call *call )
19 {
20 ent_region *region =
21 mdl_arritm( &world->ent_region, mdl_entity_id_id(call->id) );
22
23 if( !region->zone_volume )
24 return;
25
26 ent_volume *volume =
27 mdl_arritm( &world->ent_volume, mdl_entity_id_id(region->zone_volume) );
28
29 if( call->function == 0 ){ /* enter */
30 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
31 ent_route *route = mdl_arritm( &world->ent_route, i );
32
33 v3f local;
34 m4x3_mulv( volume->to_local, route->board_transform[3], local );
35 if( (fabsf(local[0]) <= 1.0f) &&
36 (fabsf(local[1]) <= 1.0f) &&
37 (fabsf(local[2]) <= 1.0f) ){
38 route->flags &= ~k_ent_route_flag_out_of_zone;
39 }
40 else {
41 route->flags |= k_ent_route_flag_out_of_zone;
42 }
43 }
44
45 gui_location_print_ccmd( 1, (const char *[]){
46 mdl_pstr(&world->meta,region->pstr_title)} );
47
48 vg_strncpy( mdl_pstr(&world->meta,region->pstr_title),
49 global_ent_region.location, NETWORK_REGION_MAX,
50 k_strncpy_always_add_null );
51 global_ent_region.flags = region->flags;
52 network_send_region();
53
54 localplayer.effect_data.spark.colour = region_spark_colour(region->flags);
55 }
56 else if( call->function == 1 ){ /* leave */
57 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
58 ent_route *route = mdl_arritm( &world->ent_route, i );
59 route->flags |= k_ent_route_flag_out_of_zone;
60 }
61 localplayer.effect_data.spark.colour = 0x00;
62 }
63 }
64
65 /*
66 * reevaluate all achievements to calculate the compiled achievement
67 */
68 void ent_region_re_eval( world_instance *world )
69 {
70 u32 world_total = k_ent_route_flag_achieve_gold |
71 k_ent_route_flag_achieve_silver;
72
73 for( u32 i=0; i<mdl_arrcount(&world->ent_region); i ++ ){
74 ent_region *region = mdl_arritm(&world->ent_region, i);
75
76 if( !region->zone_volume )
77 continue;
78
79 ent_volume *volume = mdl_arritm(&world->ent_volume,
80 mdl_entity_id_id(region->zone_volume));
81
82 u32 combined = k_ent_route_flag_achieve_gold |
83 k_ent_route_flag_achieve_silver;
84
85 for( u32 j=0; j<mdl_arrcount(&world->ent_route); j ++ ){
86 ent_route *route = mdl_arritm(&world->ent_route, j );
87
88 v3f local;
89 m4x3_mulv( volume->to_local, route->board_transform[3], local );
90 if( !((fabsf(local[0]) <= 1.0f) &&
91 (fabsf(local[1]) <= 1.0f) &&
92 (fabsf(local[2]) <= 1.0f)) ){
93 continue;
94 }
95
96 combined &= route->flags;
97 }
98
99 for( u32 j=0; j<mdl_arrcount(&world->ent_challenge); j ++ ){
100 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, j );
101
102 v3f local;
103 m4x3_mulv( volume->to_local, challenge->transform.co, local );
104 if( !((fabsf(local[0]) <= 1.0f) &&
105 (fabsf(local[1]) <= 1.0f) &&
106 (fabsf(local[2]) <= 1.0f)) ){
107 continue;
108 }
109
110 u32 flags = 0x00;
111 if( challenge->status ){
112 flags |= k_ent_route_flag_achieve_gold;
113 flags |= k_ent_route_flag_achieve_silver;
114 }
115
116 combined &= flags;
117 }
118
119 region->flags = combined;
120 world_total &= combined;
121
122 /* run unlock triggers. v105+ */
123 if( world->meta.info.version >= 105 ){
124 if( region->flags & (k_ent_route_flag_achieve_gold|
125 k_ent_route_flag_achieve_silver) ){
126 if( region->target0[0] ){
127 ent_call call;
128 call.data = NULL;
129 call.id = region->target0[0];
130 call.function = region->target0[1];
131 entity_call( world, &call );
132 }
133 }
134 }
135 }
136
137 u32 instance_id = world - world_static.instances;
138
139 if( world_static.instance_addons[instance_id]->flags & ADDON_REG_MTZERO ){
140 if( world_total & k_ent_route_flag_achieve_gold ){
141 steam_set_achievement( "MTZERO_GOLD" );
142 steam_store_achievements();
143 }
144
145 if( world_total & k_ent_route_flag_achieve_silver ){
146 steam_set_achievement( "MTZERO_SILVER" );
147 steam_store_achievements();
148 }
149 }
150
151 if( world_static.instance_addons[instance_id]->flags & ADDON_REG_CITY ){
152 steam_set_achievement( "CITY_COMPLETE" );
153 steam_store_achievements();
154 }
155 }