Obsolete Script Fun Cs
Obsolete Script Fun Cs
//---------------------------------------------------------------------------------
--------
//////////////////////////////////////////////////////
// SCRIPT FUNCTIONS
// This library of script-accessable functions can
// only be called from 'user' scripts. User scripts
// are written in a 'script' block and can can only
// get information or perform actions that pertain to
// the player sitting at the machine that the script is
// executing on.
//
// eg. A player can write a user script that gives waypoints
// to a scout
class ScriptData;
/////////////////////////
//display functions
/////////////////////////
//FUNC_LIB_CATEGORY(SCRIPT_GAME) //don't export these, they're not being used
static void ScriptFuncs::init_class(void);
static void ScriptFuncs::close_class(void);
/////////////////////////////////////////////////////////////
//information functions- return data values or -1 for failed
/////////////////////////////////////////////////////////////
static int ScriptFuncs::player_pop(void);
static int ScriptFuncs::player_pop_cap(void);
static int ScriptFuncs::player_age(void);
static int ScriptFuncs::player_settlements(void);
static int ScriptFuncs::player_points(void);
static int ScriptFuncs::player_num_type(const String &type);
static int ScriptFuncs::player_num_domain(const String &domain);
static int ScriptFuncs::time(void);
static int ScriptFuncs::object_position_x(const int &object_o);
static int ScriptFuncs::object_position_y(const int &object_o);
static int ScriptFuncs::find_idle_peasant(void);
static int ScriptFuncs::find_idle_military(void);
static int ScriptFuncs::find_capital(void);
static int ScriptFuncs::find_settlement(void);
static int ScriptFuncs::find_unit(const String &type);
static int ScriptFuncs::find_build(const String &type);
static int ScriptFuncs::find_wall(void);
////////////////////////////////////////////////////////
//action functions- return 1 if successful, -1 if error
//////////////////////////////////////////////////////////
static int ScriptFuncs::train_peasant(void);
static int ScriptFuncs::train_peasant_at(const int &where_o);
static int ScriptFuncs::train_unit(const String &type);
static int ScriptFuncs::train_unit_at(const String &type, const int &where_o);
static int ScriptFuncs::research_tech(const String &type);
///////////////////////////////////////////////
//system functions
///////////////////////////////////////////////
//zoom_in();
//moves camera to full zoom
//pass in -1's for x and y to not specify a location
static int ScriptFuncs::zoom_in(const int &x, const int &y);
//zoom_out();
//moves camera to full zoom out
//pass in -1's for x and y to not specify a location
static int ScriptFuncs::zoom_out(const int &x, const int &y);
//set_camera_pos(23, 34);
//sets camera to specified position at current zoom
static int ScriptFuncs::move_camera(const int &x, const int &y);
//center_camera_on(300)
//sets camera to center on your own object with id 300 at current zoom level
static int ScriptFuncs::center_camera_on(const int &object_o);
//zoom_in_on(300)
//sets camera to zoom in and center on your own object with id 300
static int ScriptFuncs::zoom_in_on(const int &object_o);
//******************************************
////////////////////////////////////////////
// ScriptFuncs
////////////////////////////////////////////
//******************************************
//===========================================================
void ScriptFuncs::init_class(void)
{
user_color = WHITE;
user_time = 10000;
user_align = MSG_ALIGN_LEFT;
}
//===========================================================
void ScriptFuncs::close_class(void)
{
}
//===========================================================
do {
copy.copy(&sub, PRINT_MAX);
copy.add_offset(PRINT_MAX);
MESSAGE_WIN.set_message_color(user_color);
MESSAGE_WIN.add_message(sub,-1, -1, user_time);
} while( copy.length());
//===========================================================
//===========================================================
//===========================================================
//===========================================================
LEADER2.issue_chat(str);//, PLAYER.chat_play);
}
//===========================================================
//===========================================================
int ScriptFuncs::ping(const int &who, const int &x, const int &y)
{
int whom = WHO;
if (ScriptUtils::active_who(whom) && WORLD.is_valid((TCoord)x, (TCoord)y )) {
LEADER2.issue_ping((TCoord)x, (TCoord)y );
return 1;
} else {
return -1;
}
}
//===========================================================
int ScriptFuncs::player_pop()
{
return MYLEADER.control;
}
//===========================================================
int ScriptFuncs::player_pop_cap(void)
{
return MYLEADER.pop_cap;
}
//===========================================================
int ScriptFuncs::player_age()
{
int whom = WHO;
return LEADER2.ages;
}
//===========================================================
int ScriptFuncs::player_settlements()
{
return MYLEADER.city_num;
}
//===========================================================
int ScriptFuncs::player_points()
{
return MYLEADER.score;
}
//===========================================================
//===========================================================
//===========================================================
int ScriptFuncs::time()
{
return GAME.tick / 60;
}
//=================================================================
//=================================================================
//=================================================================
int ScriptFuncs::find_idle_peasant()
{
int whom = WHO;
static int last_o = BASE_UNITS;
if (!ScriptUtils::active_who( whom )) return -1;
int t = LEADER2.current_upgrade(PEASANTS);
int ox = last_o+1;
do {
if (ox >= OBJECTS.unit_mark[whom] ) {
ox = BASE_UNITS;
}
if (OBJECTX.is_map_unit() && UNITX.is(t) && UNITX.order_type() == NONE) {
last_o = ox;
return ox;
}
ox++;
} while( ox != last_o + 1 );
last_o = BASE_UNITS;
return -1;
//=================================================================
int ScriptFuncs::find_idle_military()
{
int whom = WHO;
static int last_o = BASE_UNITS;
if (!ScriptUtils::active_who( whom )) return -1;
int ox = last_o+1;
do {
if (ox >= OBJECTS.unit_mark[whom] ) {
ox = BASE_UNITS;
}
if (OBJECTX.is_map_unit() && UNITX.is_military() && UNITX.order_type() ==
NONE ) {
last_o = ox;
return ox;
}
ox++;
} while( ox != last_o + 1 );
last_o = BASE_UNITS;
return -1;
//=================================================================
int ScriptFuncs::find_capital()
{
int whom = WHO;
int city2;
return -1;
}
//=================================================================
int ScriptFuncs::find_settlement()
{
int who = WHO;
static int last_o = 0;
if (ScriptUtils::valid_who(who)) {
int city = last_o+1;
do {
if (city >= LEADER.city_mark ) {
city = 0;
}
if (CITY.is_valid()) {
last_o = city;
return CITY.o;
}
city++;
} while( city != last_o+1 );
last_o = 0;
return -1;
} else {
return -1;
}
}
//=================================================================
return -1;
}
//=================================================================
return -1;
}
//=================================================================
int ScriptFuncs::find_wall()
{
int whom = WHO;
static int last_o = BASE_WALLS;
int t = WALL_CHUNK;
return -1;
}
//=================================================================
int ScriptFuncs::train_peasant()
{
static int last_build = BASE_BUILDS;
int whom = WHO;
if (!ScriptUtils::active_who( whom )) return -1;
int t = LEADER2.current_upgrade(PEASANTS);
int t2 = LEADER2.current_upgrade(BASETYPE.where);
int ox = ScriptUtils::find_build(whom, t2, last_build);
Group group;
if (ox >= 0 ) {
last_build = ox;
group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return -1;
}
}
//=================================================================
int ox = where_id;
Group group;
int t = LEADER2.current_upgrade(PEASANTS);
//=================================================================
int t2 = LEADER2.current_upgrade(BASETYPE.where);
int ox = ScriptUtils::find_build(whom, t2, last_build);
Group group;
if (ox >= 0 ) {
last_build = ox;
group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return 0;
}
}
//=================================================================
//=================================================================
//=================================================================
int ScriptFuncs::unit_move_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;
//=================================================================
int ScriptFuncs::unit_waypoint_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;
//=================================================================
int ScriptFuncs::unit_explore_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;
//=================================================================
int ScriptFuncs::unit_flee_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;
//=================================================================
//=================================================================
int t = ScriptUtils::get_type_index(good);
//=================================================================
int t = ScriptUtils::get_type_index(good);
//=================================================================
if (x < 0) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
} else if (WORLD.is_valid(tx, ty)) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
camera.pan_to(cx, cy);
} else {
return -1;
}
return 1;
}
//=================================================================
if (x < 0) {
camera.zoom_to_level(0);
} else if (WORLD.is_valid(tx, ty)) {
camera.zoom_to_level(0);
camera.pan_to(cx , cy);
} else {
return -1;
}
return 1;
}
//=================================================================
TCoord tx = x;
TCoord ty = y;
Coord cx = tx;
Coord cy = ty;
if (WORLD.is_valid((TCoord)x, (TCoord)y)) {
camera.pan_to(cx, cy);
} else {
return -1;
}
return 1;
}
//=================================================================
if (valid_object_o(whom, ox)) {
camera.pan_to(XX, YY);
} else {
return -1;
}
return 1;
}
//=================================================================
if (valid_object_o(whom, ox)) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
camera.pan_to(XX, YY);
} else {
return -1;
}
return 1;
}
//=================================================================
int ScriptFuncs::get_sound_x(void)
{
return SoundRef::current_x;
}
//=================================================================
int ScriptFuncs::get_sound_y(void)
{
return SoundRef::current_y;
}
//=================================================================
//=================================================================
//=================================================================
int ScriptFuncs::get_near_zoom(void)
{
return FTOL(CAMERA.get_near_point());
}
//=================================================================
int ScriptFuncs::get_current_zoom(void)
{
return FTOL(CAMERA.zoom_distance);
}
//=================================================================
int ScriptFuncs::get_camera_x(void)
{
return FTOL(CAMERA.loc_x);
}
//=================================================================
int ScriptFuncs::get_camera_y(void)
{
return FTOL(CAMERA.loc_y);
}
//=================================================================
int ScriptFuncs::get_mouse_x(void)
{
int mx, my;
graphsys->get_cursor_pos(&mx, &my);
return mx;
}
//=================================================================
int ScriptFuncs::get_mouse_y(void)
{
int mx, my;
graphsys->get_cursor_pos(&mx, &my);
return my;
}