~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/company_cmd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman, Matthijs Kooijman
  • Date: 2009-10-01 22:52:59 UTC
  • mfrom: (1.1.8 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091001225259-5kpkp4sthbszpyif
[ Matthijs Kooijman ]
* New upstream release
* Use printf instead of echo -en in openttd-wrapper to make it POSIX
  compatible (Closes: #547758).
* Remove three patches that are now included in upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: company_cmd.cpp 16324 2009-05-16 20:29:53Z rubidium $ */
 
1
/* $Id: company_cmd.cpp 17629 2009-09-24 19:22:32Z rubidium $ */
2
2
 
3
3
/** @file company_cmd.cpp Handling of companies. */
4
4
 
59
59
        if (CleaningPool()) return;
60
60
 
61
61
        DeleteCompanyWindows(this->index);
62
 
        this->name_1 = 0;
 
62
 
 
63
        /* Zero the memory of the company; we might 'reuse' it later on.
 
64
         * This is more a hack than a proper fix, but... it's already
 
65
         * fixed in trunk by the new pool system and this is the only
 
66
         * troublesome case in 0.7, so we'll leave it at this fix. */
 
67
        CompanyID id = this->index;
 
68
        memset(this, 0, sizeof(*this));
 
69
        this->index = id;
63
70
}
64
71
 
65
72
/**
257
264
        StringID str;
258
265
        Company *cc;
259
266
        uint32 strp;
260
 
        char buffer[100];
 
267
        /* Reserve space for extra unicode character. We need to do this to be able
 
268
         * to detect too long company name. */
 
269
        char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH];
261
270
 
262
271
        if (c->name_1 != STR_SV_UNNAMED) return;
263
272
 
389
398
                c->president_name_2 = Random();
390
399
                c->president_name_1 = SPECSTR_PRESIDENT_NAME;
391
400
 
392
 
                char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + 1];
 
401
                /* Reserve space for extra unicode character. We need to do this to be able
 
402
                 * to detect too long president name. */
 
403
                char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
393
404
                SetDParam(0, c->index);
394
405
                GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
395
406
                if (strlen(buffer) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) continue;
397
408
                Company *cc;
398
409
                FOR_ALL_COMPANIES(cc) {
399
410
                        if (c != cc) {
400
 
                                char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + 2];
 
411
                                /* Reserve extra space so even overlength president names can be compared. */
 
412
                                char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
401
413
                                SetDParam(0, cc->index);
402
414
                                GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
403
415
                                if (strcmp(buffer2, buffer) == 0) goto restart;
420
432
 * Create a new company and sets all company variables default values
421
433
 *
422
434
 * @param is_ai is a ai company?
 
435
 * @param company CompanyID to use for the new company
423
436
 * @return the company struct
424
437
 */
425
 
Company *DoStartupNewCompany(bool is_ai)
 
438
Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
426
439
{
427
440
        if (ActiveCompanyCount() == MAX_COMPANIES || !Company::CanAllocateItem()) return NULL;
428
441
 
429
442
        /* we have to generate colour before this company is valid */
430
443
        Colours colour = GenerateCompanyColour();
431
444
 
432
 
        Company *c = new Company(STR_SV_UNNAMED, is_ai);
 
445
        Company *c;
 
446
        if (company == INVALID_COMPANY) {
 
447
                c = new Company(STR_SV_UNNAMED, is_ai);
 
448
        } else {
 
449
                if (IsValidCompanyID(company)) return NULL;
 
450
                c = new (company) Company(STR_SV_UNNAMED, is_ai);
 
451
        }
433
452
 
434
453
        c->colour = colour;
435
454
 
486
505
        if (n < (uint)_settings_game.difficulty.max_no_competitors) {
487
506
                /* Send a command to all clients to start up a new AI.
488
507
                 * Works fine for Multiplayer and Singleplayer */
489
 
                DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 
508
                DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
490
509
        }
491
510
}
492
511
 
700
719
 * - p1 = 3 - merge two companies together. merge #1 with #2. Identified by p2
701
720
 * @param p2 various functionality, dictated by p1
702
721
 * - p1 = 0 - ClientID of the newly created client
 
722
 * - p1 = 1 - CompanyID to start AI (INVALID_COMPANY for first available)
703
723
 * - p1 = 2 - CompanyID of the that is getting deleted
704
724
 * - p1 = 3 - #1 p2 = (bit  0-15) - company to merge (p2 & 0xFFFF)
705
725
 *          - #2 p2 = (bit 16-31) - company to be merged into ((p2>>16)&0xFFFF)
815
835
                case 1: // Make a new AI company
816
836
                        if (!(flags & DC_EXEC)) return CommandCost();
817
837
 
818
 
                        DoStartupNewCompany(true);
 
838
                        if (p2 != INVALID_COMPANY && (p2 >= MAX_COMPANIES || IsValidCompanyID((CompanyID)p2))) return CMD_ERROR;
 
839
                        DoStartupNewCompany(true, (CompanyID)p2);
819
840
                        break;
820
841
 
821
842
                case 2: { // Delete a company