/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on the * source. * */ /** * @file * The code in here is just for bookeeping, allocating AI slots and linking them to ships. * See AiCode.cpp for the actual AI code. */ #include "ai/ai.h" #include "object/object.h" #include "ship/ship.h" #include "utils/string_utils.h" // heap-allocated rather than SCP_string, so that the pointers held by ai goals stay valid when the vector grows SCP_vector> Goal_target_names; ai_info Ai_info[MAX_AI_INFO]; ai_info *Player_ai; /** * @brief Returns index of free AI slot. * @return Return -1 if no free slot. */ int ai_get_slot(int shipnum) { int i; for (i=0; i= 0) && (ai_index < MAX_AI_INFO) ); Ai_info[ai_index].shipnum = -1; } const char *ai_get_goal_target_name(const char *name, int *index) { Assertion(name != nullptr && index != nullptr, "Arguments cannot be null!"); for (int i = 0; i < static_cast(Goal_target_names.size()); ++i) { if (!stricmp(name, Goal_target_names[i].get())) { *index = i; return Goal_target_names[i].get(); } } *index = static_cast(Goal_target_names.size()); Goal_target_names.push_back(util::vm_unique_copy(name, false)); return Goal_target_names.back().get(); }