View Single Post
Show off your finest piece of code!
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Show off your finest piece of code! - 29-12-2004

Just was thinking about this; did you ever had a function or a piece of code you tihnk it was uber leet? By its simplicity, or by its uniqueness, or its stupidness, or the way its written, etc. Post it here!

Also, if you find some cool comments in ur code, i would like to see them (including the code when possible)... i love it when i see:

Code:
// why does this work?
line of code
Lemme begin, in my RTS (which you can find info about @ Fundynamic (link in my sig))... its HUGE, but i have this main function, which i am fond off:

Code:
/*
Function: main()
Purpose : make sure the darn thing works.
  */
int main()
{

 // Initialize game first
 game.init();
 
 // Install everything
 if (install()) 
   game.run(); // run 

 Profile.dumpprint(0);

 // Destroy font of Allegro FONT library
 alfont_destroy_font(game_font);

 logbook("\n--------");
 logbook("SHUTDOWN");
 logbook("--------");

 // Exit the font library (must be first)
 alfont_exit();
 logbook("Allegro FONT library shut down.");

 // Now we are all neatly closed, we exit Allegro and return to OS hell.
 allegro_exit();
 logbook("Allegro shut down.");
 logbook("\nThanks for playing!");
 return 0;
}
END_OF_MAIN();
as you can see i like it to code like that, aka in the CS2D project (which died horribly) (does anyone wants the source to try it out?)

Code:
int main()
{
 if (install())
  game.run();
 
 alfont_exit();
 logbook("Allegro FONT library shut down.");
 
 // Now we are all neatly closed, we exit Allegro and return to OS hell.
 allegro_exit();
 logbook("Allegro shut down.");
 logbook("\nThanks for playing!");
 return 0;
}
END_OF_MAIN();
... funny pieces:

Code:
// Scale this
  fScale = fDistance / 4096;
  // 20/06/04 - stefan - and then i wondered, why would i limit fScale that much?
  // (fScale > 0.9)
(yeah i saw the light)

Code:
 // * so you are asking yourself why i do == true all the time huh?
	// * i just love the blue color in my MSVC :)
i just love this

Code:
// CHECK FOR STEAM;
  // As lazy as i am i use pierre's code which is in our modified metamod dll.
  // Omg, why use so many comments? Sory pierre for ripping some pieces out.
  // Pierre-Marie Baty -- STEAM/NOSTEAM auto-adaptative fix -- START
  // to check whether Steam is installed or not, I test Steam-specific files.
  // if you know a more orthodox way of doing this, please tell me.
  // test file, if found = STEAM Linux/Win32 dedicated server
  fp = fopen ("valve/steam.inf", "rb");
  if (fp != NULL)
rofl:

Code:
// set wait time (stand still, looks like bot is thinking hehe)
 pBot->f_wait_time = pBot->fWanderTime;
and:

Code:
/*
	 EMPTY - BANNED - UNUSED - MUHAHAHA
	 SINCE METAMOD ;) BUILD 2053


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote