(50c0271)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_region.c
index 4d835b8ff632e89f6dff158b5118c659eb88aaea..5e0ec03dd2349891f09ee00bfca3c07aa3a19081 100644 (file)
@@ -3,7 +3,10 @@
 #include "network_common.h"
 #include "network.h"
 
-static u32 region_spark_colour( u32 flags ){
+struct global_ent_region global_ent_region;
+
+u32 region_spark_colour( u32 flags )
+{
    if( flags & k_ent_route_flag_achieve_gold )
       return 0xff8ce0fa;
    else if( flags & k_ent_route_flag_achieve_silver )
@@ -12,28 +15,33 @@ static u32 region_spark_colour( u32 flags ){
       return 0x00;
 }
 
-static void ent_region_call( world_instance *world, ent_call *call ){
+entity_call_result ent_region_call( world_instance *world, ent_call *call )
+{
    ent_region *region = 
       mdl_arritm( &world->ent_region, mdl_entity_id_id(call->id) );
 
    if( !region->zone_volume )
-      return;
+      return k_entity_call_result_invalid;
 
    ent_volume *volume = 
       mdl_arritm( &world->ent_volume, mdl_entity_id_id(region->zone_volume) );
 
-   if( call->function == 0 ){ /* enter */
-      for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
+   if( call->function == 0 ) /* enter */
+   {
+      for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ )
+      {
          ent_route *route = mdl_arritm( &world->ent_route, i );
 
          v3f local;
          m4x3_mulv( volume->to_local, route->board_transform[3], local );
          if( (fabsf(local[0]) <= 1.0f) &&
              (fabsf(local[1]) <= 1.0f) &&
-             (fabsf(local[2]) <= 1.0f) ){
+             (fabsf(local[2]) <= 1.0f) )
+         {
             route->flags &= ~k_ent_route_flag_out_of_zone;
          }
-         else {
+         else 
+         {
             route->flags |= k_ent_route_flag_out_of_zone;
          }
       }
@@ -48,20 +56,30 @@ static void ent_region_call( world_instance *world, ent_call *call ){
       network_send_region();
 
       localplayer.effect_data.spark.colour = region_spark_colour(region->flags);
+      return k_entity_call_result_OK;
    }
-   else if( call->function == 1 ){ /* leave */
-      for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
+   else if( call->function == 1 ) /* leave */
+   {
+      for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ )
+      {
          ent_route *route = mdl_arritm( &world->ent_route, i );
          route->flags |= k_ent_route_flag_out_of_zone;
       }
       localplayer.effect_data.spark.colour = 0x00;
+      return k_entity_call_result_OK;
    }
+   else
+      return k_entity_call_result_unhandled;
 }
 
 /* 
  * reevaluate all achievements to calculate the compiled achievement
  */
-static void ent_region_re_eval( world_instance *world ){
+void ent_region_re_eval( world_instance *world )
+{
+   u32 world_total = k_ent_route_flag_achieve_gold | 
+                     k_ent_route_flag_achieve_silver;
+
    for( u32 i=0; i<mdl_arrcount(&world->ent_region); i ++ ){
       ent_region *region = mdl_arritm(&world->ent_region, i);
 
@@ -88,8 +106,60 @@ static void ent_region_re_eval( world_instance *world ){
          combined &= route->flags;
       }
 
+      for( u32 j=0; j<mdl_arrcount(&world->ent_challenge); j ++ ){
+         ent_challenge *challenge = mdl_arritm( &world->ent_challenge, j );
+
+         v3f local;
+         m4x3_mulv( volume->to_local, challenge->transform.co, local );
+         if( !((fabsf(local[0]) <= 1.0f) &&
+               (fabsf(local[1]) <= 1.0f) &&
+               (fabsf(local[2]) <= 1.0f)) ){
+            continue;
+         }
+
+         u32 flags = 0x00;
+         if( challenge->status ){
+            flags |= k_ent_route_flag_achieve_gold;
+            flags |= k_ent_route_flag_achieve_silver;
+         }
+
+         combined &= flags;
+      }
+
       region->flags = combined;
+      world_total &= combined;
+
+      /* run unlock triggers. v105+ */
+      if( world->meta.info.version >= 105 ){
+         if( region->flags & (k_ent_route_flag_achieve_gold|
+                              k_ent_route_flag_achieve_silver) ){
+            if( region->target0[0] ){
+               ent_call call;
+               call.data = NULL;
+               call.id = region->target0[0];
+               call.function = region->target0[1];
+               entity_call( world, &call );
+            }
+         }
+      }
+   }
+
+   u32 instance_id = world - world_static.instances;
+
+   if( world_static.instance_addons[instance_id]->flags & ADDON_REG_MTZERO ){
+      if( world_total & k_ent_route_flag_achieve_gold ){
+         steam_set_achievement( "MTZERO_GOLD" );
+         steam_store_achievements();
+      }
+
+      if( world_total & k_ent_route_flag_achieve_silver ){
+         steam_set_achievement( "MTZERO_SILVER" );
+         steam_store_achievements();
+      }
+   }
 
-      /* TODO: Challenges */
+   if( world_static.instance_addons[instance_id]->flags & ADDON_REG_CITY ){
+      steam_set_achievement( "CITY_COMPLETE" );
+      steam_store_achievements();
    }
 }