<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13019 >

Reopen to continue adding to the scripting API

These are "low hanging fruit" api_actions, and use server/unittools and
server/citytools
remove_unit to immediately remove a unit
upgrade_unit to upgrade a unit if possible (free)
remove_city to remove a city completely
transfer_city to transfer ownership of a city (and its units)

remove_city is a draft; it is an unsafe action in some callbacks (like
removing the city itself in it's city_growth callback)

diff to trunk r13086

Also attached is a savegame with a script that tests these actions.
Index: server/scripting/api_actions.h
===================================================================
--- server/scripting/api_actions.h	(revision 13086)
+++ server/scripting/api_actions.h	(arbetskopia)
@@ -19,7 +19,13 @@
 Unit *api_actions_create_unit(Player *pplayer, Tile *ptile, Unit_Type *ptype,
 		  	      int veteran_level, City *homecity,
 			      int moves_left);
+void api_actions_remove_unit(Unit *punit);
+void api_actions_upgrade_unit(Unit *punit);
+			      
 void api_actions_create_city(Player *pplayer, Tile *ptile, const char *name);
+void api_actions_remove_city(City *pcity);
+void api_actions_transfer_city(Player *ptaker, City *pcity);
+
 void api_actions_change_gold(Player *pplayer, int amount);
 Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech);
 
Index: server/scripting/api.pkg
===================================================================
--- server/scripting/api.pkg	(revision 13086)
+++ server/scripting/api.pkg	(arbetskopia)
@@ -397,8 +397,15 @@
 					     Unit_Type *ptype,
 					     int veteran_level,
 					     City *homecity, int moves_left);
+void api_actions_remove_unit @ remove_unit (Unit *punit);
+void api_actions_upgrade_unit @ upgrade_unit (Unit *punit);
+					     
 void api_actions_create_city @ create_city (Player *pplayer, Tile *ptile,
 					    const char *name);
+void api_actions_remove_city @ remove_city (City *pcity);
+void api_actions_transfer_city @ transfer_city (Player *ptaker, 
+					        City *pcity);
+
 void api_actions_change_gold @ change_gold (Player *pplayer, int amount);
 Tech_Type *api_actions_give_technology @ give_technology (Player *pplayer,
 						    Tech_Type *ptech);
Index: server/scripting/api_actions.c
===================================================================
--- server/scripting/api_actions.c	(revision 13086)
+++ server/scripting/api_actions.c	(arbetskopia)
@@ -37,6 +37,24 @@
 }
 
 /**************************************************************************
+  Remove a unit.
+**************************************************************************/
+void api_actions_remove_unit(Unit *punit)
+{
+  wipe_unit(punit);
+}
+
+/**************************************************************************
+  Upgrade a unit, for free.
+**************************************************************************/
+void api_actions_upgrade_unit(Unit *punit)
+{
+  Unit_Type *utype;
+  if ( (utype = can_upgrade_unittype(punit->owner, punit->utype)))
+    upgrade_unit(punit, utype, TRUE); 
+}
+
+/**************************************************************************
   Create a new city.
 **************************************************************************/
 void api_actions_create_city(Player *pplayer, Tile *ptile, const char *name)
@@ -48,6 +66,23 @@
 }
 
 /**************************************************************************
+  Remove a city.
+**************************************************************************/
+void api_actions_remove_city(City *pcity)
+{
+  remove_city(pcity);
+}
+
+/**************************************************************************
+  Transfer a city to a new owner.
+  Transfer all units, be verbose, resolve stack, no raze.
+**************************************************************************/
+void api_actions_transfer_city(Player *ptaker, City *pcity)
+{
+  transfer_city(ptaker, pcity, -1, TRUE, TRUE, FALSE); 
+}
+
+/**************************************************************************
   Change pplayer's gold by amount.
 **************************************************************************/
 void api_actions_change_gold(Player *pplayer, int amount)

Attachment: scengame-3800m.sav.gz
Description: GNU Zip compressed data

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to