SHARE_DATA *create_share( CORP_DATA *corp, char * buyer, int amount, int profit )
{
SHARE_DATA *share;
CREATE( share, SHARE_DATA, 1);
share->buyer = STRALLOC(buyer);
share->numowned = amount;
LINK( share, first_share, last_share, next, prev );
LINK( share, corp->first_corp_share, corp->last_corp_share, next, prev );
corp->numshares -= amount;
corp->funds += profit;
return share;
}
fprintf( fp, "NumShares %d\n", corp->numshares );
fprintf( fp, "SharePrice %d\n", corp->shareprice );
if( corp->first_corp_share )
{
for( share = corp->first_corp_share; share; share = share->next )
{
fprintf( fp, "#SHARE\n" );
fprintf( fp, "Buyer %s~\n", share->buyer );
fprintf( fp, "Numowned %d\n", share->numowned );
fprintf( fp, "End\n\n" );
}
}
if( corp->maincorp )
fprintf( fp, "MainCorp %s~\n", corp->maincorp->name );
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
}
word = fread_word( fp );
if( !str_cmp( word, "CORPORATION" ) )
{
fread_corp( corp, fp );
break;
}
else if( !str_cmp( word, "SHARE" ) )
{
fread_share( corp, fp );
continue;
}
else if( !str_cmp( word, "END" ) )
break;
void fread_share( CORP_DATA * corp, FILE * fp )
{
SHARE_DATA *share;
char buf[MAX_STRING_LENGTH];
char *word;
bool fMatch;
CREATE( share, SHARE_DATA, 1 );
for( ;; )
{
word = feof( fp ) ? "END" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER( word[0] ) )
{
case '*':
fread_to_eol( fp );
fMatch = TRUE;
break;
case 'B':
KEY( "Buyer", share->buyer, fread_string( fp ) );
break;
case 'E':
if( !str_cmp( word, "End" ) )
{
if( !share->buyer )
share->buyer = STRALLOC( "" );
LINK( share, first_share, last_share, next, prev );
LINK( share, corp->first_corp_share, corp->last_corp_share, next, prev );
return;
}
break;
case 'N':
KEY( "Numowned", share->numowned, fread_number( fp ) );
break;
}
if( !fMatch )
{
sprintf( buf, "No Match: fread_share: %s", word );
bug( buf, 0 );
}
}
}
Fri May 15 04:30:35 2009 :: Loading Corporations
Fri May 15 04:30:35 2009 :: Loading corporations…
Fri May 15 04:30:35 2009 :: banner.corp
Fri May 15 04:30:35 2009 :: banner2.corp
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: #SHARE
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Buyer
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Banner~
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Numowned
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: 1
Fri May 15 04:30:35 2009 :: $
Fri May 15 04:30:35 2009 :: Done corporations
Sorting Corporations
Fri May 15 04:30:35 2009 :: Done sorting
Fri May 15 04:30:35 2009 :: Reading in Vendors
int x, y;
float percent;
x = share->numowned/corp->numshares;
percent = x*100;
bug( "%s: %s: %d %d", share->buyer, corp->name, share->numowned, corp->numshares );
ch_printf( ch, "&CBuyer&B: &W%-15s &CNumber Bought&B: &Y%-3d &B(&W%.1f% &Cownership&B)\n\r", share->buyer, share->numowned, percent );
float percent = (share->numowned/corp->numshares)*100;
bug( "%s: %s: %d %d", share->buyer, corp->name, share->numowned, corp->numshares );
ch_printf( ch, "&CBuyer&B: &W%-15s &CNumber Bought&B: &Y%-3d &B(&W%.1f% &Cownership&B)\n\r", share->buyer, share->numowned, percent );
I think one reason this is likely to be hard to track down is that it's a pretty hard problem to begin with. The code here is probably going to be relatively simple; the design is the interesting part. You might have better luck looking at economic simulation games, although the ones I know of do not actually have stock markets but instead focus on managing a companies revenue streams.