1 #include "ent_region.h"
3 #include "network_common.h"
6 struct global_ent_region global_ent_region
;
8 u32
region_spark_colour( u32 flags
)
10 if( flags
& k_ent_route_flag_achieve_gold
)
12 else if( flags
& k_ent_route_flag_achieve_silver
)
18 entity_call_result
ent_region_call( world_instance
*world
, ent_call
*call
)
21 mdl_arritm( &world
->ent_region
, mdl_entity_id_id(call
->id
) );
23 if( !region
->zone_volume
)
24 return k_entity_call_result_invalid
;
27 mdl_arritm( &world
->ent_volume
, mdl_entity_id_id(region
->zone_volume
) );
29 if( call
->function
== 0 ) /* enter */
31 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ )
33 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
36 m4x3_mulv( volume
->to_local
, route
->board_transform
[3], local
);
37 if( (fabsf(local
[0]) <= 1.0f
) &&
38 (fabsf(local
[1]) <= 1.0f
) &&
39 (fabsf(local
[2]) <= 1.0f
) )
41 route
->flags
&= ~k_ent_route_flag_out_of_zone
;
45 route
->flags
|= k_ent_route_flag_out_of_zone
;
49 gui_location_print_ccmd( 1, (const char *[]){
50 mdl_pstr(&world
->meta
,region
->pstr_title
)} );
52 vg_strncpy( mdl_pstr(&world
->meta
,region
->pstr_title
),
53 global_ent_region
.location
, NETWORK_REGION_MAX
,
54 k_strncpy_always_add_null
);
55 global_ent_region
.flags
= region
->flags
;
56 network_send_region();
58 localplayer
.effect_data
.spark
.colour
= region_spark_colour(region
->flags
);
59 return k_entity_call_result_OK
;
61 else if( call
->function
== 1 ) /* leave */
63 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ )
65 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
66 route
->flags
|= k_ent_route_flag_out_of_zone
;
68 localplayer
.effect_data
.spark
.colour
= 0x00;
69 return k_entity_call_result_OK
;
72 return k_entity_call_result_unhandled
;
76 * reevaluate all achievements to calculate the compiled achievement
78 void ent_region_re_eval( world_instance
*world
)
80 u32 world_total
= k_ent_route_flag_achieve_gold
|
81 k_ent_route_flag_achieve_silver
;
83 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_region
); i
++ ){
84 ent_region
*region
= mdl_arritm(&world
->ent_region
, i
);
86 if( !region
->zone_volume
)
89 ent_volume
*volume
= mdl_arritm(&world
->ent_volume
,
90 mdl_entity_id_id(region
->zone_volume
));
92 u32 combined
= k_ent_route_flag_achieve_gold
|
93 k_ent_route_flag_achieve_silver
;
95 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_route
); j
++ ){
96 ent_route
*route
= mdl_arritm(&world
->ent_route
, j
);
99 m4x3_mulv( volume
->to_local
, route
->board_transform
[3], local
);
100 if( !((fabsf(local
[0]) <= 1.0f
) &&
101 (fabsf(local
[1]) <= 1.0f
) &&
102 (fabsf(local
[2]) <= 1.0f
)) ){
106 combined
&= route
->flags
;
109 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_challenge
); j
++ ){
110 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, j
);
113 m4x3_mulv( volume
->to_local
, challenge
->transform
.co
, local
);
114 if( !((fabsf(local
[0]) <= 1.0f
) &&
115 (fabsf(local
[1]) <= 1.0f
) &&
116 (fabsf(local
[2]) <= 1.0f
)) ){
121 if( challenge
->status
){
122 flags
|= k_ent_route_flag_achieve_gold
;
123 flags
|= k_ent_route_flag_achieve_silver
;
129 region
->flags
= combined
;
130 world_total
&= combined
;
132 /* run unlock triggers. v105+ */
133 if( world
->meta
.info
.version
>= 105 ){
134 if( region
->flags
& (k_ent_route_flag_achieve_gold
|
135 k_ent_route_flag_achieve_silver
) ){
136 if( region
->target0
[0] ){
139 call
.id
= region
->target0
[0];
140 call
.function
= region
->target0
[1];
141 entity_call( world
, &call
);
147 u32 instance_id
= world
- world_static
.instances
;
149 if( world_static
.instance_addons
[instance_id
]->flags
& ADDON_REG_MTZERO
){
150 if( world_total
& k_ent_route_flag_achieve_gold
){
151 steam_set_achievement( "MTZERO_GOLD" );
152 steam_store_achievements();
155 if( world_total
& k_ent_route_flag_achieve_silver
){
156 steam_set_achievement( "MTZERO_SILVER" );
157 steam_store_achievements();
161 if( world_static
.instance_addons
[instance_id
]->flags
& ADDON_REG_CITY
){
162 steam_set_achievement( "CITY_COMPLETE" );
163 steam_store_achievements();