1 #include "ent_region.h"
3 #include "network_common.h"
6 static u32
region_spark_colour( u32 flags
){
7 if( flags
& k_ent_route_flag_achieve_gold
)
9 else if( flags
& k_ent_route_flag_achieve_silver
)
15 static void ent_region_call( world_instance
*world
, ent_call
*call
){
17 mdl_arritm( &world
->ent_region
, mdl_entity_id_id(call
->id
) );
19 if( !region
->zone_volume
)
23 mdl_arritm( &world
->ent_volume
, mdl_entity_id_id(region
->zone_volume
) );
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
);
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
;
37 route
->flags
|= k_ent_route_flag_out_of_zone
;
41 gui_location_print_ccmd( 1, (const char *[]){
42 mdl_pstr(&world
->meta
,region
->pstr_title
)} );
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();
50 localplayer
.effect_data
.spark
.colour
= region_spark_colour(region
->flags
);
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
;
57 localplayer
.effect_data
.spark
.colour
= 0x00;
62 * reevaluate all achievements to calculate the compiled achievement
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
);
68 if( !region
->zone_volume
)
71 ent_volume
*volume
= mdl_arritm(&world
->ent_volume
,
72 mdl_entity_id_id(region
->zone_volume
));
74 u32 combined
= k_ent_route_flag_achieve_gold
|
75 k_ent_route_flag_achieve_silver
;
77 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_route
); j
++ ){
78 ent_route
*route
= mdl_arritm(&world
->ent_route
, j
);
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
)) ){
88 combined
&= route
->flags
;
91 region
->flags
= combined
;
93 /* TODO: Challenges */