### Build ENet on Unix-like Systems Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/install.dox Standard commands to configure, compile, and install the ENet library from a source distribution. This process assumes a Unix-like environment with standard build tools installed. ```bash ./configure && make && make install ``` -------------------------------- ### Generate Build System from GitHub Source Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/install.dox Command to generate the necessary build configuration files when using the ENet source code directly from a GitHub repository. Requires automake and autoconf to be installed. ```bash autoreconf -vfi ``` -------------------------------- ### AssaultCube Demo Recording and Playback Commands (CubeScript) Source: https://context7.com/assaultcube/ac/llms.txt Details commands for managing game demo recordings and playback within AssaultCube. Includes starting, stopping, clearing, listing, downloading, and playing demo files. ```cubescript // Demo recording (admin/server-side) recorddemo // Start recording stopdemo // Stop recording cleardemos // Clear stored demos // Demo playback listdemos // List available demos getdemo 1 // Download demo #1 demo mydemo // Play demo file // Demo file format (from protocol.h) // Header: DEMO_MAGIC "ASSAULTCUBE_DEMO" // Version: DEMO_VERSION 2 // Minimum length: DEMO_MINTIME 10000 (10 seconds) // Demo filename format (serverparameters.cfg) // demo_filenameformat:%w_%h_%n_%Mmin_%G // %w = timestamp, %h = server, %n = map name // %M = duration, %G = game mode ``` -------------------------------- ### Game Mode Identification and Setup in CubeScript Source: https://context7.com/assaultcube/ac/llms.txt Details the numeric IDs used to identify different game modes within AssaultCube's network protocol and scripting system. Provides examples of how to set the game mode and load a map using CubeScript commands, along with common mode aliases found in scripts.cfg. ```cubescript // Game mode IDs (from protocol.h GMODE_* enum) // -1: Demo playback // 0: Team Deathmatch (TDM) // 1: Co-operative Editing // 2: Deathmatch (DM) // 3: Survivor // 4: Team Survivor // 5: Capture the Flag (CTF) // 6: Pistol Frenzy (PF) // 7: Bot Team Deathmatch // 8: Bot Deathmatch // 9: Last Swiss Standing (LSS) // 10: One Shot One Kill (OSOK) // 11: Team One Shot One Kill (TOSOK) // 12: Bot One Shot One Kill // 13: Hunt the Flag (HTF) // 14: Team Keep the Flag (TKTF) // 15: Keep the Flag (KTF) // 16: Team Pistol Frenzy // 17: Team Last Swiss Standing // 18-21: Additional bot modes // Start a game with mode and map mode 0 // Set Team Deathmatch map ac_desert // Load map // Shorthand mode aliases (from scripts.cfg) tdm ac_desert // Team Deathmatch ctf ac_mines // Capture the Flag dm ac_complex // Free-for-all Deathmatch osok ac_arctic // One Shot One Kill htf ac_depot // Hunt the Flag ``` -------------------------------- ### Example Command: workworkwork (AssaultCube Script) Source: https://github.com/assaultcube/ac/blob/master/source/dev_tools/documentation.txt An example of a command in AssaultCube script that performs some work. It takes an energy value and an optional comment, returning the calculated energy. The example demonstrates its usage with 'echo'. ```plaintext echo (workworkwork 42) # Output: 41 # Example: echo the energy of 1kg of sugar is (workworkwork 123456 "sugar rush") ``` -------------------------------- ### Weapon System Commands and Information in CubeScript Source: https://context7.com/assaultcube/ac/llms.txt Explains the 9 weapon types available in AssaultCube, referencing their IDs from the entity.h file. Provides CubeScript commands for switching weapons and checking weapon status like current weapon, primary weapon, magazine content, and reserve ammo. Also includes example weapon stats. ```cubescript // Weapon IDs (GUN_* enum from entity.h) // 0: KNIFE - Melee weapon, always available // 1: PISTOL - Secondary weapon, 20 rounds per magazine // 2: CARBINE - TMP-M&A CB, 15 rounds, semi-auto // 3: SHOTGUN - V-19 CS, 7 shells, pump-action // 4: SUBGUN - A-ARD/10 SMG, 30 rounds, automatic // 5: SNIPER - AD-81 SR, 5 rounds, scope capable // 6: ASSAULT - MTP-57 AR, 20 rounds, automatic // 7: GRENADE - Throwable explosive, max 3 carried // 8: AKIMBO - Dual pistols, temporary powerup // Weapon switching commands weapon KNIFE weapon PISTOL primary // Switch to current primary weapon secondary // Switch to pistol melee // Switch to knife grenades // Switch to grenades // Check weapon status in scripts curweapon // Returns current weapon ID currentprimary // Returns primary weapon ID magcontent PISTOL // Ammo in current magazine magreserve PISTOL // Reserve ammo available // Weapon stats (from server.h guns[] array) // Example: Assault rifle stats // Damage: 22, Attack delay: 120ms, Reload time: 2000ms // Magazine: 20 rounds, Automatic fire: yes ``` -------------------------------- ### Connect to an ENet Host Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox This C code demonstrates how to initiate a connection to a foreign ENet host using enet_host_connect(). It specifies the target address, port, and the number of channels to allocate. The code also includes error handling for connection failures and a timeout mechanism. ```c ENetAddress address; ENetEvent event; ENetPeer *peer; /* Connect to some.server.net:1234. */ enet_address_set_host (& address, "some.server.net"); address.port = 1234; /* Initiate the connection, allocating the two channels 0 and 1. */ peer = enet_host_connect (client, & address, 2, 0); if (peer == NULL) { fprintf (stderr, "No available peers for initiating an ENet connection.\n"); exit (EXIT_FAILURE); } /* Wait up to 5 seconds for the connection attempt to succeed. */ if (enet_host_service (client, & event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) { puts ("Connection to some.server.net:1234 succeeded."); ... ... ... } else { /* Either the 5 seconds are up or a disconnect event was */ /* received. Reset the peer in the event the 5 seconds */ /* had run out without any significant event. */ enet_peer_reset (peer); puts ("Connection to some.server.net:1234 failed."); } ... ... ... ``` -------------------------------- ### Send and Resize ENet Packets (C) Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox This C code snippet illustrates how to create, resize, and send packets using the ENet library. It demonstrates setting packet flags for reliability, extending packet data, and sending packets to a specific peer or broadcasting to all peers. The code requires the ENet library and standard C string functions. ```c /* Create a reliable packet of size 7 containing "packet\0" */ ENetPacket * packet = enet_packet_create ("packet", strlen ("packet") + 1, ENET_PACKET_FLAG_RELIABLE); /* Extend the packet so and append the string "foo", so it now */ /* contains "packetfoo\0" */ enet_packet_resize (packet, strlen ("packetfoo") + 1); strcpy (& packet -> data [strlen ("packet")], "foo"); /* Send the packet to the peer over channel id 0. */ /* One could also broadcast the packet by */ /* enet_host_broadcast (host, 0, packet); */ enet_peer_send (peer, 0, packet); ... ... ... /* One could just use enet_host_service() instead. */ enet_host_flush (host); ``` -------------------------------- ### Create ENet Server Host Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox Creates an ENet server host using enet_host_create(). It binds the server to a specified address and port, sets the maximum number of clients, and optionally configures incoming and outgoing bandwidth. The host is destroyed using enet_host_destroy() when no longer needed. ```c ENetAddress address; ENetHost * server; /* Bind the server to the default localhost. */ /* A specific host address can be specified by */ /* enet_address_set_host (& address, "x.x.x.x"); */ address.host = ENET_HOST_ANY; /* Bind the server to port 1234. */ address.port = 1234; server = enet_host_create (& address /* the address to bind the server host to */, 32 /* allow up to 32 clients and/or outgoing connections */, 2 /* allow up to 2 channels to be used, 0 and 1 */, 0 /* assume any amount of incoming bandwidth */, 0 /* assume any amount of outgoing bandwidth */); if (server == NULL) { fprintf (stderr, "An error occurred while trying to create an ENet server host.\n"); exit (EXIT_FAILURE); } ... ... ... enet_host_destroy(server); ``` -------------------------------- ### Initialize and Deinitialize ENet Library Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox Initializes the ENet library using enet_initialize() and sets up a call to enet_deinitialize() using atexit() for cleanup upon program exit. This is a prerequisite for using any other ENet functions. ```c #include int main (int argc, char ** argv) { if (enet_initialize () != 0) { fprintf (stderr, "An error occurred while initializing ENet.\n"); return EXIT_FAILURE; } atexit (enet_deinitialize); ... ... ... } ``` -------------------------------- ### Create ENet Client Host Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox Creates an ENet client host using enet_host_create() without specifying an address. It configures the maximum number of outgoing connections and bandwidth for the client. The host is destroyed using enet_host_destroy() when no longer needed. ```c ENetHost * client; client = enet_host_create (NULL /* create a client host */, 1 /* only allow 1 outgoing connection */, 2 /* allow up 2 channels to be used, 0 and 1 */, 57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */, 14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */); if (client == NULL) { fprintf (stderr, "An error occurred while trying to create an ENet client host.\n"); exit (EXIT_FAILURE); } ... ... ... enet_host_destroy(client); ``` -------------------------------- ### AssaultCube Server Configuration Source: https://context7.com/assaultcube/ac/llms.txt Covers server initialization using command-line arguments and the definition of runtime parameters in serverparameters.cfg. These settings control server identity, networking, and administrative access. ```bash # Start a dedicated server ./assaultcube_server -n"My Server" -c8 -o"Welcome message" # Command-line options: # -n"name" Server description # -c8 Max clients (default 6, max 256) # -o"motd" Message of the day # -p28763 Server port (default 28763) # -m3 Master server mode # -xpassword Admin password # -ypassword Server password # serverparameters.cfg format (keyword:value, no spaces) auth_verify_ip:0 mandatory_auth:1 gamepenalty_cutoff:60 vitamaxage:12 demo_save:1 logthreshold_console:2 ``` -------------------------------- ### CubeScript Configuration and Scripting Source: https://context7.com/assaultcube/ac/llms.txt Demonstrates the use of CubeScript for defining aliases, managing variables, and implementing control flow logic. These scripts are typically executed via the in-game console or stored in configuration files like autoexec.cfg. ```cubescript // Execute commands via console (press ~ or T then /) /connect 192.168.1.1 28763 // Define aliases (functions) in autoexec.cfg const myfunc [ echo "Hello from CubeScript" if (> $numargs 0) [ echo "Argument 1:" $arg1 ] ] // Variable types: VAR (int), FVAR (float), SVAR (string) // Persistent vars (VARP, FVARP, SVARP) save to config sensitivity 3.5 // Set mouse sensitivity gamma 150 // Set gamma (30-300) name "PlayerName" // Set player name // Conditional logic and loops if (> $health 50) [ echo "Healthy" ] [ echo "Low health" ] loop i 5 [echo $i] // Prints 0-4 looplist [a b c] item [echo $item] // Iterate list ``` -------------------------------- ### Key Bindings Configuration in CubeScript Source: https://context7.com/assaultcube/ac/llms.txt Defines how keyboard and mouse inputs are mapped to in-game actions using CubeScript commands. These bindings are typically stored in configuration files and can be modified during gameplay. Includes bindings for movement, actions, weapon selection, and edit mode toggles. ```cubescript // Bind keys to actions bind W [forward] bind S [backward] bind A [left] bind D [right] bind SPACE [jump] bind LSHIFT [crouch] bind MOUSE1 [attack] bind MOUSE2 [altaction] // Context-sensitive alternate action bind R [reload] bind E [edittoggle] // Toggle edit mode bind TAB [showscores] // Weapon selection bindings bind 1 [primary] // Switch to primary weapon bind 2 [secondary] // Pistol bind 3 [melee] // Knife bind 4 [grenades] // Grenades // Edit mode specific bindings bind G [domodifier 0] // Height modification modifier bind F [domodifier 1] // Heightfield (vdelta) modifier bind Y [domodifier 2] // Floor/ceiling texture modifier bind T [domodifier 3] // Wall texture modifier // Mouse wheel with modifiers for editing // Hold modifier key + scroll to edit terrain // universaldelta handles context-aware scrolling ``` -------------------------------- ### Handle ENet Events: Connect, Receive, Disconnect (C) Source: https://github.com/assaultcube/ac/blob/master/source/enet/docs/tutorial.dox This C code snippet demonstrates how to process various ENet events, including client connections, packet reception, and disconnections. It shows how to store client data, process received packets, and clean up resources. The function relies on the ENet library. ```c ENetEvent event; /* Wait up to 1000 milliseconds for an event. */ while (enet_host_service (client, & event, 1000) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: printf ("A new client connected from %x:%u.\n", event.peer -> address.host, event.peer -> address.port); /* Store any relevant client information here. */ event.peer -> data = "Client information"; break; case ENET_EVENT_TYPE_RECEIVE: printf ("A packet of length %u containing %s was received from %s on channel %u.\n", event.packet -> dataLength, event.packet -> data, event.peer -> data, event.channelID); /* Clean up the packet now that we're done using it. */ enet_packet_destroy (event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: printf ("%s disconected.\n", event.peer -> data); /* Reset the peer's client information. */ event.peer -> data = NULL; } } ... ``` -------------------------------- ### Configure Bot Navigation Waypoints Source: https://context7.com/assaultcube/ac/llms.txt Commands for managing bot navigation paths, including manual waypoint placement, automatic generation, and path connection logic. ```cubescript wpvisible 1 wpinfo 1 addwp delwp wpsave wpload wpclear autowp 1 startflood setjumpwp setwpyaw setwptriggernr 1 addpath1way1 addpath1way2 addpath2way1 addpath2way2 addtelewps addtriggerwps ``` -------------------------------- ### Load Image from File using SDL_image Source: https://github.com/assaultcube/ac/blob/master/bin_win32/README-SDL_image.txt Loads an image from a specified file path into an SDL_Surface. This is a convenient wrapper function for loading images directly from disk. It returns a pointer to the loaded SDL_Surface or NULL if an error occurs. ```c #include "SDL_image.h" SDL_Surface *IMG_Load(const char *file); ``` -------------------------------- ### Manage Map Entities and Objects Source: https://context7.com/assaultcube/ac/llms.txt Commands for creating, deleting, and modifying game entities such as lights, player spawns, pickups, and map models. ```cubescript newent light 128 255 200 180 150 newent playerstart 90 1 newent playerstart 270 100 newent health 0 newent mapmodel 45 15 8 newent sound 0 64 32 200 newent clip 0 8 8 16 0 0 0 delent entset mapmodel 90 2 ``` -------------------------------- ### Compare Documentation References (Shell Script) Source: https://github.com/assaultcube/ac/blob/master/source/dev_tools/documentation.txt A shell script to compare autogenerated documentation names against an established reference XML file. It identifies names present in the autogenerated file but missing from the reference. ```bash while read begriff; do zahl=$(grep -c "name=\"${begriff}\"" docs/reference.xml); if [ $zahl -eq 0 ]; then echo $begriff; fi; done < <(grep name= docs/autogenerated_base_reference.xml|sed 's/^.*name=\"\([^\"\"\\\]*\)\".*$ /\1/') ``` -------------------------------- ### Utility Functions (CubeScript) Source: https://context7.com/assaultcube/ac/llms.txt Provides essential utility functions for scripting, including console output, timed command execution, key release triggers, random number generation, string concatenation, and list manipulation (length, indexing, finding items). ```cubescript // Utility functions echo "message" // Print to console sleep 1000 [command] // Execute after 1000ms delay onrelease [command] // Execute when key released rnd 100 // Random number 0-99 concat $a $b // Concatenate strings listlen $mylist // Get list length at $mylist 2 // Get item at index 2 findlist $list item // Find item index in list ```