// Copyright (C) Call of Nil contributors
// SPDX-License-Identifier: AGPL-3.0-only

use crate::continent::coord::Coord;
use crate::continent::size::ContinentSize;
use crate::ethic::{EthicPowerAxis, EthicTruthAxis, Ethics};
use crate::npc::precursor::PrecursorId;
use crate::resources::Resources;
use crate::resources::influence::Influence;
use nil_core_macros::Precursor;
use serde::{Deserialize, Serialize};

#[derive(Precursor, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct A {
  origin: Coord,
  resources: Resources,
  influence: Influence,
}

impl A {
  pub const ID: PrecursorId = PrecursorId::A;
  pub const ETHICS: Ethics = Ethics::builder()
    .power(EthicPowerAxis::Militarist)
    .truth(EthicTruthAxis::FanaticMaterialist)
    .build();

  pub const fn new(size: ContinentSize) -> Self {
    Self {
      origin: origin(size),
      resources: Resources::PRECURSOR.clone(),
      influence: Influence::MAX,
    }
  }
}

const fn origin(size: ContinentSize) -> Coord {
  let size = u8::from(size);
  let radius = size.div_ceil(20).next_multiple_of(2);
  Coord::splat(0) + Coord::splat(radius)
}
