Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.07 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "tile_base.h"
  4. #include "GameFramework/Actor.h"
  5. #include "Map_Controller.generated.h"
  6.  
  7. class Atile_base;
  8.  
  9. USTRUCT(BlueprintType)
  10. struct Fneighbour
  11. {
  12.     GENERATED_USTRUCT_BODY()
  13.  
  14.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  15.     int instance_index;
  16.  
  17.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  18.     int ISM_index;
  19.  
  20.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  21.     int matrix_position_x;
  22.  
  23.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  24.     int matrix_position_y;
  25.  
  26.     Fneighbour()
  27.     {
  28.         this->ISM_index         = 0;
  29.         this->instance_index    = 0;
  30.         this->matrix_position_x = 0;
  31.         this->matrix_position_y = 0;
  32.     };
  33.  
  34.     Fneighbour(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
  35.     {
  36.         this->ISM_index         = ISM_index;
  37.         this->instance_index    = instance_index;
  38.         this->matrix_position_x = matrix_position_x;
  39.         this->matrix_position_y = matrix_position_y;
  40.     };
  41. };
  42.  
  43. USTRUCT(BlueprintType)
  44. struct Ftile_indexer
  45. {
  46.     GENERATED_USTRUCT_BODY()
  47.  
  48.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  49.     int instance_index;
  50.  
  51.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  52.     int ISM_index;
  53.  
  54.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  55.     int matrix_position_x;
  56.  
  57.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
  58.     int matrix_position_y;
  59.  
  60.     TArray<Fneighbour> neighbours;
  61.  
  62.     Ftile_indexer()
  63.     {
  64.         this->ISM_index         = 0;
  65.         this->instance_index    = 0;
  66.         this->matrix_position_x = 0;
  67.         this->matrix_position_y = 0;
  68.     };
  69.  
  70.     Ftile_indexer(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
  71.     {
  72.         this->ISM_index         = ISM_index;
  73.         this->instance_index    = instance_index;
  74.         this->matrix_position_x = matrix_position_x;
  75.         this->matrix_position_y = matrix_position_y;
  76.  
  77.         this->neighbours = TArray<Fneighbour>();
  78.     };
  79.  
  80.     void add_neighbour(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
  81.     {
  82.         neighbours.Add(Fneighbour(ISM_index, instance_index, matrix_position_x, matrix_position_y));
  83.  
  84.         GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Red, FString::FromInt(neighbours[neighbours.Num() - 1].instance_index));
  85.     };
  86.  
  87.     TArray<Fneighbour> get_neighbours()
  88.     {
  89.         return neighbours;
  90.     };
  91. };
  92.  
  93. UCLASS()
  94. class ATHENA_API AMap_Controller : public AActor
  95. {
  96.     GENERATED_BODY()
  97.    
  98. public:
  99.  
  100.     AMap_Controller();
  101.     virtual void BeginPlay() override;
  102.     virtual void Tick( float DeltaSeconds ) override;
  103.  
  104.     void deselect_previous_tile(Atile_base* tile_selected);
  105.  
  106.     void generate_hex_grid();
  107.     void generate_graph();
  108.     void generate_cellular_automata();
  109.  
  110.     FVector2D find_tile_matrix_coordinate_from_index(int ISM_index, int instance_index);
  111.     Ftile_indexer find_tile_index_from_matrix_coordinate(int matrix_position_x, int matrix_position_y);
  112.     void debug_neighbours(int ISM_index, int instance_index);
  113.     TArray<Fneighbour> find_tile_index_neighbours(int ISM_index, int instance_index);
  114.  
  115.     Atile_base* spawn(UClass* object_class, FVector location, int tile_coordinate_x, int tile_coordinate_y);
  116.     void replace_tile(Atile_base* tile, int type_index);
  117.     Atile_base* get_tile_from_map(int _x, int _y);
  118.  
  119.     bool tiles_are_same_type(FString tile_type1, FString tile_type2);
  120.  
  121. public:
  122.     USceneComponent* game_controller_root;
  123.     UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* grass_ISM;
  124.     UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* water_ISM;
  125.     UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* dirt_ISM;
  126.     UPROPERTY(VisibleAnywhere) TArray<UInstancedStaticMeshComponent*> tiles_ISM;
  127.  
  128.     UPROPERTY(VisibleAnywhere) TArray<Ftile_indexer> tile_indexer;
  129.  
  130.     UPROPERTY(EditAnywhere) int map_max_row_count               = 13;
  131.     UPROPERTY(EditAnywhere) int map_tile_radius                 = 102;
  132.     UPROPERTY(EditAnywhere) int map_cellular_automata_max_depth = 5;
  133.  
  134. private:
  135.  
  136.     //Tile blueprints
  137.     TArray<TSubclassOf<AStaticMeshActor>> map_tile_classes;
  138.  
  139.     int map_row_height = abs(map_max_row_count / 2);
  140.    
  141.     //Array to store generated tiles
  142.     TArray<Atile_base*> map_tiles;
  143.    
  144. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement