💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.2 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "game/states/forage.hpp"
  20. #include "entity/archetype.hpp"
  21. #include "entity/commands.hpp"
  22. #include "entity/components/observer.hpp"
  23. #include "entity/components/camera-follow.hpp"
  24. #include "entity/components/terrain.hpp"
  25. #include "entity/components/transform.hpp"
  26. #include "entity/systems/astronomy.hpp"
  27. #include "entity/systems/control.hpp"
  28. #include "entity/systems/camera.hpp"
  29. #include "animation/screen-transition.hpp"
  30. #include "animation/ease.hpp"
  31. #include "resources/resource-manager.hpp"
  32. namespace game {
  33. namespace state {
  34. namespace forage {
  35. void enter(game::context* ctx)
  36. {
  37. // Switch to surface camera
  38. ctx->underground_camera->set_active(false);
  39. ctx->surface_camera->set_active(true);
  40. // Find planet EID by name
  41. entity::id planet_eid = entt::null;
  42. if (auto it = ctx->named_entities.find("planet"); it != ctx->named_entities.end())
  43. {
  44. planet_eid = it->second;
  45. }
  46. // Create biome terrain component
  47. entity::component::terrain biome_terrain;
  48. biome_terrain.max_lod = 18;
  49. biome_terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
  50. biome_terrain.elevation = [](double, double) -> double
  51. {
  52. return 0.0;
  53. };
  54. // Replace planet terrain component with biome terrain component
  55. ctx->entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
  56. // Create observer
  57. auto observer_eid = ctx->entity_registry->create();
  58. {
  59. entity::component::observer observer;
  60. observer.reference_body_eid = planet_eid;
  61. observer.elevation = 0.0;
  62. observer.latitude = 0.0;
  63. observer.longitude = 0.0;
  64. observer.camera = ctx->surface_camera;
  65. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  66. // Set reference location of astronomy system
  67. ctx->astronomy_system->set_reference_body(planet_eid);
  68. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  69. }
  70. // Create camera focal point
  71. {
  72. entity::component::transform focal_point_transform;
  73. focal_point_transform.local = math::identity_transform<float>;
  74. focal_point_transform.warp = true;
  75. ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
  76. entity::component::camera_follow focal_point_follow;
  77. ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
  78. }
  79. // Setup camera
  80. ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  81. ctx->surface_camera->set_exposure(-14.5f);
  82. ctx->camera_system->set_camera(ctx->surface_camera);
  83. entity::system::control* control_system = ctx->control_system;
  84. control_system->update(0.0, 0.0);
  85. control_system->set_nest(nullptr);
  86. // Create larva
  87. {
  88. entity::archetype* larva_archetype = ctx->resource_manager->load<entity::archetype>("ant-larva.ent");
  89. auto larva_eid = larva_archetype->create(*ctx->entity_registry);
  90. entity::command::warp_to(*ctx->entity_registry, larva_eid, {50, 0.1935f, 0});
  91. }
  92. // Create cocoon
  93. {
  94. entity::archetype* cocoon_archetype = ctx->resource_manager->load<entity::archetype>("ant-cocoon.ent");
  95. auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
  96. entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
  97. }
  98. ctx->surface_scene->update_tweens();
  99. // Start fade in
  100. ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
  101. }
  102. void exit(game::context* ctx)
  103. {}
  104. } // namespace forage
  105. } // namespace state
  106. } // namespace game