~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/logic/worker_program.cc

  • Committer: Nicolai Hähnle
  • Date: 2010-10-31 12:50:41 UTC
  • mto: (5614.3.1 campaigns)
  • mto: This revision was merged to the branch mainline in revision 5692.
  • Revision ID: prefect_@gmx.net-20101031125041-z0qh421qs7gjix50
Initial cut of ship construction, untested, without proper savegame support

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "worker_program.h"
21
21
 
22
 
#include "helper.h"
23
22
#include "profile/profile.h"
24
23
#include "findnode.h"
 
24
#include "game_data_error.h"
 
25
#include "helper.h"
25
26
#include "tribe.h"
26
27
 
27
28
namespace Widelands {
45
46
        {"geologist-find",    &WorkerProgram::parse_geologist_find},
46
47
        {"scout",             &WorkerProgram::parse_scout},
47
48
        {"playFX",            &WorkerProgram::parse_playFX},
 
49
        {"construct",         &WorkerProgram::parse_construct},
48
50
 
49
51
        {0, 0}
50
52
};
102
104
 *
103
105
 * The worker will create and carry an item of the given type.
104
106
 *
105
 
 * sparam1 = ware name
 
107
 * iparam1 = ware index
106
108
 */
107
109
void WorkerProgram::parse_createitem
108
110
        (Worker_Descr                   * descr,
392
394
 * Walk to a previously selected destination. where can be one of:
393
395
 * object  walk to a previously found and selected object
394
396
 * coords  walk to a previously found and selected field/coordinate
 
397
 * object-or-coords  walk to a previously found and selected object if
 
398
 *         present; otherwise to previously found and selected coordinate
395
399
 *
396
400
 * iparam1 = walkXXX
397
401
 */
410
414
                act->iparam1 = Worker::Action::walkObject;
411
415
        else if (cmd[1] == "coords")
412
416
                act->iparam1 = Worker::Action::walkCoords;
 
417
        else if (cmd[1] == "object-or-coords")
 
418
                act->iparam1 = Worker::Action::walkObject | Worker::Action::walkCoords;
413
419
        else
414
420
                throw wexception("Bad walk destination '%s'", cmd[1].c_str());
415
421
}
494
500
 
495
501
 
496
502
/**
497
 
 * plant \<immmovable type\> \<immovable type\> ...
 
503
 * plant \<immmovable type\> \<immovable type\> ... [unless object]
498
504
 *
499
505
 * Plant one of the given immovables on the current position.
500
506
 * Decision is made with inclusion of the terrain affinity.
 
507
 *
 
508
 * sparamv  list of object names
 
509
 * iparam1  one of plantXXX
501
510
 */
502
511
void WorkerProgram::parse_plant
503
512
        (Worker_Descr                   *,
506
515
         std::vector<std::string> const & cmd)
507
516
{
508
517
        if (cmd.size() < 2)
509
 
                throw wexception("Usage: plant <immovable type> <immovable type> ...");
 
518
                throw wexception("Usage: plant <immovable type> <immovable type> ... [unless object]");
510
519
 
511
520
        act->function = &Worker::run_plant;
512
 
        for (uint32_t i = 1; i < cmd.size(); ++i)
 
521
        act->iparam1 = Worker::Action::plantAlways;
 
522
        for (uint32_t i = 1; i < cmd.size(); ++i) {
 
523
                if (i >= 2 && cmd[i] == "unless") {
 
524
                        ++i;
 
525
                        if (i >= cmd.size())
 
526
                                throw game_data_error("plant: something expected after unless");
 
527
                        if (cmd[i] == "object")
 
528
                                act->iparam1 = Worker::Action::plantUnlessObject;
 
529
                        else
 
530
                                throw game_data_error("plant: 'unless %s' not understood", cmd[i].c_str());
 
531
 
 
532
                        continue;
 
533
                }
513
534
                act->sparamv.push_back(cmd[i]);
 
535
        }
514
536
}
515
537
 
516
538
 
631
653
                atoi(cmd[2].c_str());
632
654
}
633
655
 
 
656
/**
 
657
 * construct
 
658
 *
 
659
 * Give the currently held item of the worker to the \ref objvar1 immovable
 
660
 * for construction. This is used in ship building.
 
661
 */
 
662
void WorkerProgram::parse_construct
 
663
        (Worker_Descr                   *,
 
664
         Worker::Action                 * act,
 
665
         Parser                         *,
 
666
         std::vector<std::string> const & cmd)
 
667
{
 
668
        if (cmd.size() != 1)
 
669
                throw wexception("Usage: construct");
 
670
 
 
671
        act->function = &Worker::run_construct;
 
672
}
 
673
 
 
674
 
634
675
}