/** ** Unit upgrades unit! ** ** @param unit Pointer to unit. */ global void HandleActionUpgradeTo(Unit* unit) { Player* player; UnitType* type; const UnitStats* stats; DebugLevel3Fn(" %d\n" _C_ UnitNumber(unit)); player=unit->Player; if( !unit->SubAction ) { // first entry unit->Data.UpgradeTo.Ticks=0; unit->SubAction=1; } type=unit->Orders[0].Type; stats=&type->Stats[player->Player]; UnitMarkSeen(unit); // FIXME: Should count down here unit->Data.UpgradeTo.Ticks+=SpeedUpgrade; if( unit->Data.UpgradeTo.Ticks>=stats->Costs[TimeCost] ) { unit->HP+=stats->HitPoints-unit->Type->Stats[player->Player].HitPoints; // don't have such unit now player->UnitTypesCount[unit->Type->Type]--; unit->Type=type; unit->Stats=(UnitStats*)stats; // and we have new one... player->UnitTypesCount[unit->Type->Type]++; UpdateForNewUnit(unit,1); NotifyPlayer(player,NotifyGreen,unit->X,unit->Y, "Upgrade to %s complete",unit->Type->Name ); if( unit->Player->Ai ) { AiUpgradeToComplete(unit,type); } unit->Reset=unit->Wait=1; unit->Orders[0].Action=UnitActionStill; unit->SubAction=0; // // Update possible changed buttons. // if( IsOnlySelected(unit) ) { UpdateButtonPanel(); MustRedraw|=RedrawPanels; } else if( player==ThisPlayer ) { UpdateButtonPanel(); MustRedraw|=RedrawInfoPanel; } return; } if( IsOnlySelected(unit) ) { MustRedraw|=RedrawInfoPanel; } unit->Reset=1; unit->Wait=CYCLES_PER_SECOND/6; }
/* * * Add a list of directory entries buttons to a RC widget. * * */ int AddButtonsToPanel ( ButtonParentObjectType *bpo, void (*func)(), int metObjectType, char *fulldirectorypath ) { int cnt, i, j, count; ButtonObject *bo; int argc; char **argv; int returnStatus; if ( GetVerboseLevel() > VERBOSE_0 ) printf("AddButtonsToPanel\n"); /* * Get the sorted directory listing... */ argc = readdirectory ( fulldirectorypath, &argv , NULL, NULL); if( argc <= 0 ) return ( 1 ); returnStatus = UpdateButtonPanel( bpo, func, metObjectType, fulldirectorypath, argc, argv); free ( argv ); return ( returnStatus ); }
/** ** Enter the transporter. ** ** @param unit Pointer to unit. */ local void EnterTransporter(Unit* unit) { Unit* transporter; int i; unit->Wait=1; unit->Orders[0].Action=UnitActionStill; unit->SubAction=0; transporter=unit->Orders[0].Goal; if( transporter->Destroyed ) { DebugLevel0Fn("Destroyed transporter\n"); RefsDebugCheck( !transporter->Refs ); if( !--transporter->Refs ) { ReleaseUnit(transporter); } unit->Orders[0].Goal=NoUnitP; return; } else if( transporter->Removed || !transporter->HP || transporter->Orders[0].Action==UnitActionDie ) { DebugLevel0Fn("Unuseable transporter\n"); RefsDebugCheck( !transporter->Refs ); --transporter->Refs; RefsDebugCheck( !transporter->Refs ); unit->Orders[0].Goal=NoUnitP; return; } RefsDebugCheck( !transporter->Refs ); --transporter->Refs; RefsDebugCheck( !transporter->Refs ); unit->Orders[0].Goal=NoUnitP; // // Find free slot in transporter. // for( i=0; i<(int)(sizeof(unit->OnBoard)/sizeof(*unit->OnBoard)); ++i ) { if( transporter->OnBoard[i]==NoUnitP ) { transporter->OnBoard[i]=unit; // FIXME: reference counts? transporter->Value++; RemoveUnit(unit,transporter); if( IsOnlySelected(transporter) ) { UpdateButtonPanel(); MustRedraw|=RedrawPanels; } return; } } DebugLevel0Fn("No free slot in transporter\n"); }
/** ** Unit researches! ** ** @param unit Pointer of researching unit. */ global void HandleActionResearch(Unit* unit) { const Upgrade* upgrade; if( !unit->SubAction ) { // first entry upgrade=unit->Data.Research.Upgrade=unit->Orders[0].Arg1; #if 0 // FIXME: I want to support both, but with network we need this check // but if want combined upgrades this is worse // // Check if an other building has already started? // if( unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades] ) { DebugLevel0Fn("Two researches running\n"); PlayerAddCosts(unit->Player,upgrade->Costs); unit->Reset=unit->Wait=1; unit->Orders[0].Action=UnitActionStill; unit->SubAction=0; if( IsOnlySelected(unit) ) { MustRedraw|=RedrawInfoPanel; } return; } #endif unit->SubAction=1; } else { upgrade=unit->Data.Research.Upgrade; } unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades]+=SpeedResearch; if( unit->Player->UpgradeTimers.Upgrades[upgrade-Upgrades] >=upgrade->Costs[TimeCost] ) { NotifyPlayer(unit->Player,NotifyGreen,unit->X,unit->Y, "%s: complete",unit->Type->Name); if( unit->Player->Ai ) { AiResearchComplete(unit,upgrade); } UpgradeAcquire(unit->Player,upgrade); unit->Reset=unit->Wait=1; unit->Orders[0].Action=UnitActionStill; unit->SubAction=0; // Upgrade can change all UpdateButtonPanel(); MustRedraw|=RedrawPanels; return; } if( IsOnlySelected(unit) ) { MustRedraw|=RedrawInfoPanel; } unit->Reset=1; unit->Wait=CYCLES_PER_SECOND/6; // FIXME: should be animations here? }
void BuildImageSource ( ButtonParentObjectType *bpo ) { char *ptr, *tmpargv[1]; char **pathComponents; DefaultDirectory *p; int i, cnt; if ( GetVerboseLevel() > VERBOSE_0 ) printf("BuildImageSource\n"); for ( p = ImageSourcePaths; p->imageSource ; p++ ) { p->path = (char *) GetConfigValue( p->imageSource ); if ( GetVerboseLevel() > VERBOSE_1 ) { printf(" imageSource is %s,", p->imageSource ); printf(" path is %s\n", p->path ? p->path : "" ); } if( ! p->path ) continue; pathComponents = SplitByDelimeter ( p->path, " ", &cnt ); for( i = 0; i < cnt; i++ ) { char *ptr; /* * Skip it, if it isn't a directory. */ if( ! DirExists( pathComponents[i] ) ) { if( GetVerboseLevel() > 1 ) { printf(" Can't find directory %s\n", pathComponents[i]); } continue; } /* * Skip it, if it doesn't look like a full path. */ if( ! ( ptr = strrchr( pathComponents[i], '/' ) ) ) continue; /* * Munge the string around so that the path name * is broken up into a directory path and * file name. The tricky part here, is that * memory is deallocated by the RemoveButton * function for the path and label portions of * it's data structure, but not the path component. */ *ptr = '\0'; tmpargv[0] = strdup( ++ptr ); /* * * Put the components into the GUI. */ UpdateButtonPanel( bpo, SourcePanelCB, p->metObjectType, pathComponents[i], 1, tmpargv ); } StringListFree ( cnt, pathComponents); } }