wrong world display
[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 static u32 region_spark_colour( u32 flags ){
7 if( flags & k_ent_route_flag_achieve_gold )
8 return 0xff8ce0fa;
9 else if( flags & k_ent_route_flag_achieve_silver )
10 return 0xffc2c2c2;
11 else
12 return 0x00;
13 }
14
15 static void ent_region_call( world_instance *world, ent_call *call ){
16 ent_region *region =
17 mdl_arritm( &world->ent_region, mdl_entity_id_id(call->id) );
18
19 if( !region->zone_volume )
20 return;
21
22 ent_volume *volume =
23 mdl_arritm( &world->ent_volume, mdl_entity_id_id(region->zone_volume) );
24
25 if( call->function == 0 ){ /* enter */
26 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
27 ent_route *route = mdl_arritm( &world->ent_route, i );
28
29 v3f local;
30 m4x3_mulv( volume->to_local, route->board_transform[3], local );
31 if( (fabsf(local[0]) <= 1.0f) &&
32 (fabsf(local[1]) <= 1.0f) &&
33 (fabsf(local[2]) <= 1.0f) ){
34 route->flags &= ~k_ent_route_flag_out_of_zone;
35 }
36 else {
37 route->flags |= k_ent_route_flag_out_of_zone;
38 }
39 }
40
41 gui_location_print_ccmd( 1, (const char *[]){
42 mdl_pstr(&world->meta,region->pstr_title)} );
43
44 vg_strncpy( mdl_pstr(&world->meta,region->pstr_title),
45 global_ent_region.location, NETWORK_REGION_MAX,
46 k_strncpy_always_add_null );
47 global_ent_region.flags = region->flags;
48 network_send_region();
49
50 localplayer.effect_data.spark.colour = region_spark_colour(region->flags);
51 }
52 else if( call->function == 1 ){ /* leave */
53 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
54 ent_route *route = mdl_arritm( &world->ent_route, i );
55 route->flags |= k_ent_route_flag_out_of_zone;
56 }
57 localplayer.effect_data.spark.colour = 0x00;
58 }
59 }
60
61 /*
62 * reevaluate all achievements to calculate the compiled achievement
63 */
64 static void ent_region_re_eval( world_instance *world ){
65 for( u32 i=0; i<mdl_arrcount(&world->ent_region); i ++ ){
66 ent_region *region = mdl_arritm(&world->ent_region, i);
67
68 if( !region->zone_volume )
69 continue;
70
71 ent_volume *volume = mdl_arritm(&world->ent_volume,
72 mdl_entity_id_id(region->zone_volume));
73
74 u32 combined = k_ent_route_flag_achieve_gold |
75 k_ent_route_flag_achieve_silver;
76
77 for( u32 j=0; j<mdl_arrcount(&world->ent_route); j ++ ){
78 ent_route *route = mdl_arritm(&world->ent_route, j );
79
80 v3f local;
81 m4x3_mulv( volume->to_local, route->board_transform[3], local );
82 if( !((fabsf(local[0]) <= 1.0f) &&
83 (fabsf(local[1]) <= 1.0f) &&
84 (fabsf(local[2]) <= 1.0f)) ){
85 continue;
86 }
87
88 combined &= route->flags;
89 }
90
91 region->flags = combined;
92
93 /* TODO: Challenges */
94 }
95 }