void DAirCombatDice::RndClicked( wxCommandEvent& WXUNUSED(e) ) { char s[10]; #if 0 sprintf( s, "%d", dice( ) ); editDie1->SetValue( wxString::FromAscii( s ) ); if ( dice_ > 1 ) { sprintf( s, "%d", dice( ) ); editDie2->SetValue( wxString::FromAscii( s ) ); } #endif sprintf( s, "%d", rollDiceN( max_ ) ); editDie1->SetValue( wxString::FromAscii( s ) ); if ( dice_ > 1 ) { sprintf( s, "%d", rollDiceN( max_ ) ); editDie2->SetValue( wxString::FromAscii( s ) ); } // Disable the edit controls so the user cannot change the automatic die roll editDie1->Enable( false ); editDie2->Enable( false ); auto_roll_ = 1; }
bool is_chain(ht H, list l, int h) { while (l != NULL) { if (l->data == NULL) return false; if (H->key_hash(H->elem_key(l->data), H->size) != h) return false; l = l->next; } return true; }
void DViewColor::SetupDialog( ) { // edits editName->SetValue( wxS( ViewColorDlgData.editName ) ); editRed->SetValue( wxS( ViewColorDlgData.editRed ) ); editGreen->SetValue( wxS( ViewColorDlgData.editGreen ) ); editBlue->SetValue( wxS( ViewColorDlgData.editBlue ) ); NotInitialized = FALSE; return; }
/* ht_search(H, k) returns NULL if key k not present in H */ ht_elem ht_search(ht H, ht_key k) { REQUIRES(is_ht(H)); int h = H->key_hash(k, H->size); list l = H->A[h]; while (l != NULL) //@loop_invariant is_chain(H, l, h); { if (H->key_equal(H->elem_key(l->data), k)) return l->data; l = l->next; } return NULL; }
void DAirCombatDice::CloseDialog( ) { char bf[100]; #if 0 strncpy( bf, editDie1->GetValue().ToAscii(), 100 ); if (strlen( bf ) == 0) // empty string -> generate random value die1 = dice( ); else die1 = atoi( bf ); strncpy(bf, editDie2->GetValue().ToAscii(), 100); if ( strlen (bf) == 0 ) die2 = dice( ); else die2 = atoi( bf ); if ( die1 < 1 ) die1 = 1; if ( die1 > 6 ) die1 = 6; if ( die2 < 1 ) die2 = 1; if ( die2 > 6 ) die2 = 6; #endif strncpy( bf, editDie1->GetValue( ).ToAscii( ), 100 ); if ( strlen( bf ) == 0 ) // empty string -> generate random value die1_ = rollDiceN( max_ ); else die1_ = atoi( bf ); strncpy( bf, editDie2->GetValue( ).ToAscii( ), 100 ); if ( strlen( bf ) == 0 ) die2_ = rollDiceN( max_ ); else die2_ = atoi( bf ); if ( die1_ < 1 ) die1_ = 1; if ( die1_ > max_ ) die1_ = max_; if ( die2_ < 1 ) die2_ = 1; if ( die2_ > max_ ) die2_ = max_; strncpy( info_, editInfo->GetValue( ).ToAscii( ), 999 ); }
void DViewColor::btnColourClicked( wxCommandEvent& ) { wxColourData data; data.SetChooseFull( true ); wxColour colour( atoi( editRed->GetValue( ).ToAscii( ) ), atoi( editGreen->GetValue( ).ToAscii( ) ), atoi( editBlue->GetValue( ).ToAscii( ) ) ); data.SetCustomColour( 0, colour ); for ( int i = 1; i < 16; ++i ) { wxColour color( i * 16, i * 16, i * 16 ); data.SetCustomColour( i, color ); } wxColourDialog dialog( this, &data ); if ( dialog.ShowModal( ) == wxID_OK ) { char numstr[255]; wxColourData retData = dialog.GetColourData( ); wxColour col = retData.GetColour( ); strcpy( numstr, inttoa( col.Red( ) ) ); editRed->SetValue( wxS( numstr ) ); strcpy( numstr, inttoa( col.Green( ) ) ); editGreen->SetValue( wxS( numstr ) ); strcpy( numstr, inttoa( col.Blue( ) ) ); editBlue->SetValue( wxS( numstr ) ); } #if 0 ZOCDlg dlg( this ); dlg.SetZOCStr( ViewColorDlgData.zocstr ); if ( dlg.ShowModal() == wxID_OK ) { strcpy( ViewColorDlgData.zocstr, dlg.GetZOCStr( ) ); lblZOC->SetLabel( wxS( dlg.GetZOCStr( ) ) ); } #endif }
void ht_insert(ht H, ht_elem e) { REQUIRES(is_ht(H)); assert(e != NULL); /* cannot insert NULL element */ ht_key k = H->elem_key(e); int h = H->key_hash(k, H->size); list l = H->A[h]; while (l != NULL) //@loop_invariant is_chain(H, l, h); { if (H->key_equal(H->elem_key(l->data), k)) { l->data = e; /* modify in place if k already there */ return; } l = l->next; } /* k is not already in the hash table */ /* insert at the beginning of the chain at A[h] */ H->A[h] = list_new(e, H->A[h]); ENSURES(is_ht(H)); return; }
void Facility::drawSymbol( wxDC* hdc, int lft, int top, int rgt, int bot ) { wxPen hpen( *wxBLACK, 2, wxSOLID ); wxBrush bgbr( *wxWHITE, wxSOLID ), oldbr; wxMemoryDC memdc; // Draw background box, and switch to foreground GDI objects hdc->SetPen( *wxBLACK_PEN ); hdc->SetBrush( bgbr ); // background brush #if 0 Rectangle( hdc, lft, top, rgt, bot ); // Draw rectangle #endif // draw: hdc->SetPen( hpen ); int mid = ( lft + rgt ) / 2 - 1; int x = lft, y = top; switch ( type_ ) { case Facility::FIELDWORKS: memdc.SelectObject( *hbmFieldWorks ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; case Facility::ENTRENCHMENT: memdc.SelectObject( *hbmEntrenchent ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; case Facility::IMPR_FORT: memdc.SelectObject( *hbmImpFort ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; case Facility::ZEP_BASE: memdc.SelectObject( *hbmZepBase ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; case Facility::FORT: hdc->DrawLine( mid, top + 2, rgt - 7, top + 6 ); hdc->DrawLine( rgt - 7, top + 6, rgt - 7, bot - 7 ); hdc->DrawLine( rgt - 7, bot - 7, mid, bot - 3 ); hdc->DrawLine( mid, bot - 3, lft + 6, bot - 7 ); hdc->DrawLine( lft + 6, bot - 7, lft + 6, top + 6 ); hdc->DrawLine( lft + 6, top + 6, mid, top + 2 ); break; case Facility::PERMAF3: case Facility::PERMAF6: case Facility::PERMAF9: case Facility::PERMAF12: hdc->DrawLine( rgt - 6, top + 5, rgt - 6, bot - 1 ); hdc->DrawLine( rgt - 5, top + 6, lft + 8, bot - 1 ); hdc->DrawLine( rgt - 4, bot - 3, lft + 7, bot - 3 ); // draw box for capacity hdc->SetPen( *wxBLACK_PEN ); hdc->SetBrush( *wxWHITE_BRUSH ); hdc->SetFont( fnt ); hdc->DrawRectangle( x, y, 11, 11 ); hdc->SetTextForeground( *wxBLACK ); hdc->SetTextBackground( *wxWHITE ); if ( type_ == Facility::PERMAF3 ) drawStr( hdc, x + 4, y + 2, const_cast<char*>( "3" ) ); else if ( type_ == Facility::PERMAF6 ) drawStr( hdc, x + 4, y + 2, const_cast<char*>( "6" ) ); else if ( type_ == Facility::PERMAF9 ) drawStr( hdc, x + 4, y + 2, const_cast<char*>( "9" ) ); else if ( type_ == Facility::PERMAF12 ) drawStr( hdc, x + 2, y + 2, const_cast<char*>( "12" ) ); break; case Facility::TEMPAF: hdc->DrawLine( rgt - 8, top + 3, rgt - 8, bot - 3 ); hdc->DrawLine( rgt - 6, top + 5, lft + 6, bot - 3 ); break; case Facility::MULBERRY: memdc.SelectObject( *hbmMulberry ); hdc->Blit( x + 2, y + 4, 19, 16, &memdc, 0, 0 ); break; case Facility::BALLOON: memdc.SelectObject( *hbmBalloons ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; case Facility::CONTEST: memdc.SelectObject( *hbmContested ); hdc->Blit( x + 2, y + 1, 19, 19, &memdc, 0, 0 ); break; } }
pair < iterator, bool > insert (value_type obj) { pair < typename ht::iterator, bool > p = rep.insert (obj); }
size_type erase(const key_type& key) { return rep.erase(key); }
size_type count(const key_type& key) const { return rep.count(key); }
void set_deleted_key(const key_type& key) { rep.set_deleted_key(value_type(key, data_type())); }
pair<iterator, bool> insert(const value_type& obj) { return rep.insert(obj); }
iterator find(const key_type& key) { return rep.find(key); }
iterator end() { return rep.end(); }
void NavalUnit::drawCounter( wxDC* dc, int x, int y, bool border /* = true */ ) { wxColor bgnd = _naval_armed_force[getSide( )][getSubType( )].crBg; wxColor fgnd = _naval_armed_force[getSide( )][getSubType( )].crFg; wxColor bgndtop = *wxWHITE; dc->SetFont( fnt ); // draw counter #if 0 dc->SetPen( *wxBLACK_PEN ); dc->SetBrush( wxBrush( bgnd, wxSOLID ) ); dc->DrawRectangle( x, y, 28, 27 ); #endif if ( border ) { wxBrush bgnd_brush( bgnd, wxSOLID ); dc->SetPen( *wxBLACK_PEN ); // always black border on counter dc->SetBrush( bgnd_brush ); dc->DrawRectangle( x, y, 28, 27 ); } else { wxPen bgnd_pen( bgnd, 1, wxSOLID ); // EJW (new): top 2/3 is white wxBrush bgnd_brushtop( bgndtop, wxSOLID ); dc->SetPen( bgnd_pen ); // no border dc->SetBrush( bgnd_brushtop ); dc->DrawRectangle( x + 1, y + 1, 26, 18 ); // EJW: bottom 1/3 is background color wxBrush bgnd_brush( bgnd, wxSOLID ); dc->SetPen( bgnd_pen ); // no border dc->SetBrush( bgnd_brush ); dc->DrawRectangle( x + 1, y + 18, 26, 9 ); } char str[10]; // AA in similar way in both types // EJW: AA drawn first, same color as symbol dc->SetTextForeground( fgnd ); sprintf( str, "%d", aa_ ); drawStr( dc, x + 2, y + 2, str ); #if 0 dc->SetTextForeground( *wxBLACK ); #endif // draw symbol // old style (separate capital ships) if ( type_ < NavalUnitType::FIRST_FLEET ) { wxBitmap bmp( 20, 20 ); #if 0 dc.SetBkMode( OPAQUE ); #endif wxMemoryDC mem2dc; mem2dc.SelectObject( bmp ); // mem2dc = counter's color (16 bit) mem2dc.SetBrush( wxBrush( fgnd, wxSOLID ) ); mem2dc.SetPen( wxPen( fgnd, 1, wxSOLID ) ); mem2dc.DrawRectangle( 0, 0, 20, 20 ); #if 0 mem2dc.FillRect( 0, 0, 20, 20, TBrush( TColor( 0, 255, 0 ) ) ); #endif wxMemoryDC memdc; switch ( getShipType( ) ) { case NavalUnitType::Ship::V: case NavalUnitType::Ship::VE: case NavalUnitType::Ship::VL: case NavalUnitType::Ship::VS: memdc.SelectObject( *hbmCarrier ); break; case NavalUnitType::Ship::B: case NavalUnitType::Ship::BB: case NavalUnitType::Ship::BC: case NavalUnitType::Ship::BD: case NavalUnitType::Ship::BP: memdc.SelectObject( *hbmWarShip ); break; case NavalUnitType::Ship::CA: case NavalUnitType::Ship::CC: case NavalUnitType::Ship::CD: case NavalUnitType::Ship::CL: memdc.SelectObject( *hbmCruiser ); break; case NavalUnitType::Ship::DA: case NavalUnitType::Ship::DC: case NavalUnitType::Ship::DD: case NavalUnitType::Ship::DE: case NavalUnitType::Ship::DT: memdc.SelectObject( *hbmDestroyer ); break; case NavalUnitType::Ship::SC: case NavalUnitType::Ship::SS: case NavalUnitType::Ship::SO: memdc.SelectObject( *hbmSubmarine ); break; case NavalUnitType::Ship::LC: memdc.SelectObject( *hbmLC ); break; case NavalUnitType::Ship::NT: memdc.SelectObject( *hbmCargoShip ); break; default: memdc.SelectObject( *hbmAuxShip ); break; } dc->Blit( x + 7, y + 6, 17, 10, &mem2dc, 0, 0, wxXOR ); // don't draw borders dc->Blit( x + 7, y + 6, 17, 10, &memdc, 0, 0, wxAND ); dc->Blit( x + 7, y + 6, 17, 10, &mem2dc, 0, 0, wxXOR ); dc->SetTextBackground( bgnd ); dc->SetTextForeground( fgnd ); dc->SetFont( fnt ); // write str if ( getShipType( ) != NavalUnitType::Ship::NT && getShipType( ) != NavalUnitType::Ship::LC ) { sprintf( str, "%d-%d-%d", pri_, sec_, ter_ ); int szx = strLen( str ); int x_pos = x + 14 - ( szx / 2 ); drawStr( dc, x_pos, y + 17, str ); } } // new style task forces else { // name dc->SetFont( fnt2 ); #if 0 sprintf( str, "%s", FleetTypes[GetShipType( ) - NavalUnitType::FIRST_FLEET] ); #endif sprintf( str, "%s", name_ ); wxString ws = wxS( str ); int szx, szy; dc->GetTextExtent( ws, &szx, &szy ); dc->SetTextForeground( fgnd ); dc->SetTextBackground( bgnd ); int x_pos = x + 14 - ( szx / 2 ); // width=28 -> 14 = halfway dc->DrawText( ws, x_pos, y + 9 ); // EJW: switch to white for the type and strength on background color dc->SetTextForeground( *wxWHITE ); // str if ( type_ == NavalUnitType::Fleet::TF ) sprintf( str, "%d", getStrength( ) ); else if ( type_ == NavalUnitType::Fleet::CG ) sprintf( str, "(%d)", getStrength( ) ); else if ( type_ == NavalUnitType::Fleet::SS ) sprintf( str, "S%d", getStrength( ) ); else if ( type_ == NavalUnitType::Fleet::RF ) sprintf( str, "RF%d", getStrength( ) ); else if ( type_ == NavalUnitType::Fleet::LC || type_ == NavalUnitType::Fleet::NTP ) sprintf( str, "C%d", getStrength( ) ); else // SOS type: sprintf( str, "%s%d", _fleet_type[type_ - NavalUnitType::FIRST_FLEET], getStrength( ) ); szx = strLen( str ); x_pos = x + 14 - ( szx / 2 ); drawStr( dc, x_pos, y + 19, str ); } }