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 void 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
)
27 mdl_arritm( &world
->ent_volume
, mdl_entity_id_id(region
->zone_volume
) );
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
);
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
;
41 route
->flags
|= k_ent_route_flag_out_of_zone
;
45 gui_location_print_ccmd( 1, (const char *[]){
46 mdl_pstr(&world
->meta
,region
->pstr_title
)} );
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();
54 localplayer
.effect_data
.spark
.colour
= region_spark_colour(region
->flags
);
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
;
61 localplayer
.effect_data
.spark
.colour
= 0x00;
66 * reevaluate all achievements to calculate the compiled achievement
68 void ent_region_re_eval( world_instance
*world
)
70 u32 world_total
= k_ent_route_flag_achieve_gold
|
71 k_ent_route_flag_achieve_silver
;
73 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_region
); i
++ ){
74 ent_region
*region
= mdl_arritm(&world
->ent_region
, i
);
76 if( !region
->zone_volume
)
79 ent_volume
*volume
= mdl_arritm(&world
->ent_volume
,
80 mdl_entity_id_id(region
->zone_volume
));
82 u32 combined
= k_ent_route_flag_achieve_gold
|
83 k_ent_route_flag_achieve_silver
;
85 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_route
); j
++ ){
86 ent_route
*route
= mdl_arritm(&world
->ent_route
, j
);
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
)) ){
96 combined
&= route
->flags
;
99 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_challenge
); j
++ ){
100 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, j
);
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
)) ){
111 if( challenge
->status
){
112 flags
|= k_ent_route_flag_achieve_gold
;
113 flags
|= k_ent_route_flag_achieve_silver
;
119 region
->flags
= combined
;
120 world_total
&= combined
;
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] ){
129 call
.id
= region
->target0
[0];
130 call
.function
= region
->target0
[1];
131 entity_call( world
, &call
);
137 u32 instance_id
= world
- world_static
.instances
;
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();
145 if( world_total
& k_ent_route_flag_achieve_silver
){
146 steam_set_achievement( "MTZERO_SILVER" );
147 steam_store_achievements();
151 if( world_static
.instance_addons
[instance_id
]->flags
& ADDON_REG_CITY
){
152 steam_set_achievement( "CITY_COMPLETE" );
153 steam_store_achievements();